akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> P(N);
    rep(i, N) { 
        cin >> P[i];
    }
    vector<ll> Q(N);
    rep(i, N) { 
        cin >> Q[i];
    }
    vector<ll> indices(N);
    iota(indices.begin(), indices.end(), 1);
    ll a = 0;
    ll b = 0;
    ll cnt = 0;
    do {
        cnt++;
        bool flag = false;
        rep(i, N) {
            if (indices[i] != P[i]) {
                flag = true;
            }
        }
        if (!flag) {
            a = cnt;
        }
        flag = false;
        rep(i, N) {
            if (indices[i] != Q[i]) {
                flag = true;
            }
        }
        if (!flag) {
            b = cnt;
        }
    } while (std::next_permutation(indices.begin(), indices.end()));
    print(abs(a-b));
    return 0;
}

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

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);

	int p[1001];
	int i;

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

	sort(p, p+n);

	int sum = 0;
	for (i = 0; i < k; i++) {
		sum += p[i];
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 1708
N = int(input())
buttons = [int(input()) for _ in range(N)]
counter = 1
now_button = buttons[0]
for _ in range(N):
    if now_button == 2:
        print(counter)
        break
    counter += 1
    now_button = buttons[now_button - 1]
else:
    print(-1)


Measured memory_bytes: 7084
#include <stdio.h>

int main()
{
	int i,j,k,n,x,flag;
	
	for(;;){
		flag = 0;
		scanf("%d %d",&n,&x);
		
		if(n == 0 && x == 0){
			return 0; 
		}
		
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					if(x == i+j+k){
						if(i!=j && j!=k && i!=k){
							flag++;
						}
					}
				}
			}
		}
	printf("%d\n",flag/6);
	}
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli h, w,n;
    cin >> h >> w>>n;
    h = max(h, w);
    lli ans = n / h;
    n %= h;
    if(n!=0){
        ans += 1;
    }
    out(ans);
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    map<ll,int>mp;
    int n;
    cin >> n;
    f(n){
        int add;
        cin >> add;
        mp[-add]++;
    }
    vector<ll>v;
    for(auto i:mp){
        if(i.S<2)continue;
        while(i.S >= 2){
            v.pb(i.F);
            i.S -= 2;
        }
        if(v.size() >= 2)break;
    }
    if(v.size() < 2){
        cout << 0 << endl;
    }
    else{
        cout << v[0] * v[1] << '\n';
    }
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string s;
  cin >> s;
  char pre = s.at(0);
  int ans = 0;
  for (auto c : s) {
    if (pre != c)ans++;
    pre = c;
  }
//   for (int i = 0; i < SZ(s);i++) {
//     int now = s.at(i);
//     if (now != pre){
// ans ++;
//     }
//     pre = s.at(i);
//     }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
// B - Trick or Treat
#include <bits/stdc++.h>
using namespace std;
int in(){int x;cin>>x;return x;}

int main(){
	int N,K; cin>>N>>K;
	set<int> ok;
	int ng = N;
	for(int i=0; i<K; ++i)
		for(int d=in(), j=0; j<d; ++j) ok.insert(in());
	cout<< ng-ok.size() <<endl;
}

Measured memory_bytes: 3616
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a[int(str(i)[0])][i%10]+=1
ans=0
for x in range(1,10):
    ans+=a[x][x]**2
    for y in range(x+1,10):
        ans+=a[y][x]*a[x][y]*2
print(ans)

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

int main(){
    int N;
    vector<int> n(4);
    cin >> N;
    n.at(0) = N / 1000;
    N %= 1000;
    n.at(1) = N / 100;
    N %= 100;
    n.at(2) = N / 10;
    N %= 10;
    n.at(3) = N;

    for(int i = 0; i < (1 << 3); i++){
        int ans = n.at(0);
        for(int j = 0; j < 3; j++){
            if(i & (1 << j)) ans += n.at(j + 1);
            else ans -= n.at(j + 1);
        }
        if(ans == 7){
            cout << n.at(0);
            for(int k = 0; k < 3; k++){
                if(i & (1 << k)) cout << '+' << n.at(k+1);
                else cout << '-' << n.at(k+1);
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}



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

#define bll long long
#define clr(a) memset(a,0,sizeof(a));

int n;

int main()
{
    while (scanf("%d",&n)!=EOF)
    {
        int x,a,b,c;
        a = b = c = 0;
        for (int i=0;i<n;i++)
        {
            scanf("%d",&x);
            if (x % 4 == 0) a++;
            else
               if (x % 2 == 0) b++;
               else
                  c++; 
        }

        if ((c-a==1 && b==0)||(c<=a)) printf("Yes\n");
        else 
          printf("No\n");  

    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

signed main(void)
{
	#define ll long long int
	ll ans = 0;
	ll n,temp;
	cin>>n;

	temp = (n/500);

	n  = n-temp*500;

	ans+= 1000*temp;

	temp = (n/5);

    n  = n-temp*5;

	ans+=5*temp;	
  
   cout<<ans<<endl;
}	

Measured memory_bytes: 256
from heapq import heappop,heappush
q=int(input())
queries=[list(map(int,input().split()))for _ in range(q)]
l=[]
r=[]
ans=0
quecount=0
for query in queries:
  if query[0]==1:
    quecount+=1
    _,a,b=query
    ans+=b
    if quecount==1:
      mid=a
    elif quecount%2==1:
      if a<-l[0]:
        mid=-heappop(l)
        heappush(l,-a)
      elif r[0]<a:
        mid=heappop(r)
        heappush(r,a)
      else:
        mid=a
      ans+=abs(a-mid)
    else:
      ans+=abs(a-mid)
      heappush(l,-min(a,mid))
      heappush(r,max(a,mid))
  if query[0]==2:
    if quecount%2==1:
      ansind=mid
    else:
      ansind=-l[0]
    print(ansind,ans)

Measured memory_bytes: 56768
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=998244353;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define lb(x,a) lower_bound(all(x),a)
#define ub(x,a) upper_bound(all(x),a)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 


void solve(){
 ll n,k;
  cin >> n >> k;
 vll l(k),r(k);
 rep(i,0,k) cin >> l[i] >> r[i]; 

  
  
vector<mint> dp(n+5,0);
dp[0]=1;
dp[1]=-1;
  
 rep(i,0,n+1){
   if(i>0) dp[i]+=dp[i-1];
  rep(j,0,k){
   if(i+l[j]<n) dp[i+l[j]]+=dp[i];
   if(i+r[j]+1<n) dp[i+r[j]+1]-=dp[i]; 
  }
   
 }
  cout << dp[n] << endl;
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#include <cmath>
#define ll long long

using namespace std;

ll f(ll n) {

	ll count = 0;

	for (ll x = 1; x <= n; x++) {

		for (ll y = 1; y <= n; y++) {

			for (ll z = 1; z <= n; z++) {
				if (pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x == n) {
					count++;
				}
			}
		}
	}
	return count;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N;

	cin >> N;

	map<ll, ll> occur;
	for (ll x = 1; x <= N; x++) {
		for (ll y = 1; y <= N - x; y++) {
			for (ll z = 1; z <= N - y; z++) {
				ll value = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x;

				if (value > N) {
					break;
				}

				occur[value]++;
			}
		}
	}

	for (ll i = 1; i <= N; i++) {
		cout << occur[i] << endl;
	}

	
	return 0;
}

Measured memory_bytes: 4244
#include<stdio.h>

int main(void)
{
        int n, m[1000000], i, tmp=0, r=0;

        scanf("%d", &n);

        for(i = 0; i < n; i++) {
                scanf("%d", &m[i]);
                if(m[i] >= tmp) {
                        tmp = m[i];
                }
                r += m[i];
        }
        r -= tmp;

        if(tmp < r) {
                printf("Yes");
        } else {
                printf("No");
        }

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// vectorの要素を検索
bool vector_exist(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index!=vec.size()) {
    return true;
  }
  else {
    return false;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  int ans = 0;
  if (vector_exist(a, 1)) {
    int num = 1; // 探す数字
    for (int i=0; i<N; i++) {
      if (a[i]==num) num++;
      else ans++;
    }
  }
  else ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;int A[N];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=N-1;i>=0;i-=2){
    cout<<A[i];
    if(N!=1)cout<<" ";
  }
  for(int i=N%2;i<N;i+=2){
    cout<<A[i];
    if(i+2<N)cout<<" ";
  }
  cout<<endl;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    int n , m , q;
    cin >> n >> m >> q;
    vector<vector<int>>accum(n+1,vector<int>(n+1)),board(n,vector<int>(n));
    vector<pii>query(q);
    rep(i, 0, m){
        int l, r;
        cin >> l >> r;
        l--,r--;
        board[l][r]++;
    }
    rep(i, 0, n){
        rep(j, 0, n){
            accum[i+1][j+1] = board[i][j];
        }
    }
    rep(i, 0, n){
        rep(j, 0, n+1){
            accum[i+1][j] += accum[i][j];
        }
    }
    rep(j, 0, n){
        rep(i, 0, n+1){
            accum[i][j+1] += accum[i][j];
        }
    }
    
    rep(i, 0, q){
        cin >> query[i].first >> query[i].second;
        query[i].first--;
        //query[i].second--;
    }
    rep(i, 0, q){
        int temp = accum[query[i].second][query[i].second]
        +accum[query[i].first][query[i].first]
        -accum[query[i].first][query[i].second]
        -accum[query[i].second][query[i].first];
        cout << temp << endl;
    }
    //rep(i, 0, n+1)cout << imos[i] << " ";
    //cout << endl;
}

Measured memory_bytes: 6140
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        string s;
        cin >> s;
        int n = s.size();
        int ans = n;
        for (int i = 1; i < n; i ++) {
                if (s[i] != s[i - 1]) {
                        ans = min(ans, max(i, n - i));
                }
        }
        printf("%d\n", ans);
        return 0;
}



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

using namespace std;

int main(int argc, char** argv){
    int N = 0;
    cin >> N;
    vector<double> p(N);
    vector<vector<double>> dp(N + 1, vector<double>(N+1));
    for(int i = 0; i < N;++i){
        cin >> p[i];
    }

    dp[0][0] = 1;
    for(int i = 1; i <= N; ++i){
        for(int j = 0; j <= i; ++j){
            if(j == 0){
                dp[i][j] = dp[i-1][j] * (1.0 - p[i-1]);
            }else{
                dp[i][j] = dp[i-1][j] * (1.0 - p[i-1]) + dp[i-1][j-1] * p[i-1];
            }
        }
    }

    double ans = 0;
    for (int i = (N + 1) / 2; i <= N; i += 1) 
        ans += dp[N][i]; 
    cout <<   std::setprecision(10) << ans << "\n";
    //print(dp, N+1, N+1);
    return 0;
}

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

int main(){
	int n;
  	cin>>n;
  	long long l[max(n+1,2)];
  	l[0]=2;
  	l[1]=1;
  	for(int i=2;i<=n;i++)
      l[i]=l[i-1]+l[i-2];
  	cout<<l[n];
}

Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vi a(n), b(n);
  for(int& x : a){
    cin >> x;
  }
  for(int& x : b){
    cin >> x;
  }
  vi l;
  for(int i = 1; i <= n; i++){
    l.push_back(i);
  }
  vi l2 = l;
  int f[2] = {};
  do{
    if(l2 == a){
      break;
    }
    f[0]++;
  } while(next_permutation(all(l2)));
  l2 = l;
  do{
    if(l2 == b){
      break;
    }
    f[1]++;
  } while(next_permutation(all(l2)));
  cout << abs(f[0] - f[1]);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

//-----------------------------------------
//-----------------------------------------

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

  while(1){
    ll h, w;
    cin >> h >> w;
    if(h == 0 && w == 0) return 0;
    REP(i,h){
      REP(j,w){
        if((j+i)%2==0) cout << "#";
        else cout << ".";
      }
      cout <<endl;
    }
    cout <<endl;
  }


  return 0;
}






Measured memory_bytes: 3180
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    n=I()
    trans=[I(),I(),I(),I(),I()]
    trans.sort()
    print(n//trans[0]+5 if n/trans[0]%1!=0 else n//trans[0]+4)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 9256
def modpow(a, b, m):
	if b == 0:
		return 1
	else:
		c = modpow(a, b//2, m)
		c = (c*c)%m
		return c if b%2 == 0 else (c*a)%m

MOD = 1000000007
n = int(input())
print((modpow(10, n, MOD)-2*modpow(9, n, MOD)+modpow(8, n, MOD)+3*MOD)%MOD)

Measured memory_bytes: 9092
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


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

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count

	if i == 0:	
		sum = get_sum(dic)
	else:
		sum += (c - b) * count
	
	print(sum)

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

typedef long long int ll;

const int MAX_N = 205;
const int MAX_W = 10005;
const ll MOD = 1000000007;
int N,W;

ll dp[MAX_N][MAX_W];

ll func(vector<ll>&vec,int sum,int id){
  for(int i = 0 ; i <= N ; i++)for(int j = 0 ; j <= W ; j++)dp[i][j] = 0;
  dp[id+1][sum] = 1;  

  ll ret = 0;
  for(int i = id+1 ; i < N ; i++){
    for(int j = 0 ; j <= W ; j++){
      if(dp[i][j] == 0)continue;
      dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
      if(j+vec[i] > W)continue;
      dp[i+1][j+vec[i]] = (dp[i+1][j+vec[i]]+dp[i][j])%MOD;      
    }
  }

  for(int i = 0 ; i <= W ; i++){
    if(W-i < vec[id]){
      ret = (ret + dp[N][i])%MOD;
    }
  }
  return ret;
}

int main(){
  cin >> N >> W;
  vector<ll>vec(N);

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

  sort(vec.begin(),vec.end());
  int sum = 0;
  ll res = 0;

  for(int i = 0 ; i < N ; i++){
    if(sum > W)continue;
    res = (res+func(vec,sum,i))%MOD;    
    sum += vec[i];
  }
  if(sum <= W)res = (res+1LL)%MOD;    
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 16920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n+1){
        if(i%5 != 0 && i%3 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll dp[N][2],arr[N];
void solve()
{
	int n;
	cin >> n;

	for (int i = 1; i < n + 1; i++)
		cin >> arr[i];
	memset(dp, 0, sizeof(dp));
	dp[2][1] = arr[2];
	dp[2][0] = arr[1];
	for (int i = 3; i < n + 1; i++)
	{
		if (i & 1)
		{
			ll temp = max({dp[i-3][1],dp[i-3][0],dp[i-2][1],dp[i-2][0]});
			//i为奇数 i要选x个  x=i/2
			//i-1 位置已经维护好 x个  那么只能从 选了x-1的 地方进行转移，很明显i-2   i-3  是维护好了x-1个
			dp[i][1] = arr[i] + temp;

			dp[i][0]=max({dp[i-1][1],dp[i-1][0],arr[i-2]+dp[i-3][0]});
			//该位置不选，从x继承dp[i-1]
			//从 x-1 的一个位置：i-3不选  选i-2  转移
		}
		else
		{
			dp[i][1]=arr[i]+max({dp[i-2][1],dp[i-2][0],dp[i-1][0]});
			///偶数位置 i  选当前位置 
			///1、要选 i/2个 dp[i-2]的位置已经维护好了（i/2-1）个
			///2、前一个不选
			dp[i][0] = arr[i-1]+dp[i-2][0];
			///i不选，
			///1、一定选i-1  维护前i个必须选i/2个的特性
		}
	}
	cout << max(dp[n][1], dp[n][0]) << endl;
	return;
}

int main()
{
	solve();
	return 0;
}
/*
没有两个相邻的被选上
8
1 2 3 4 -1 -2 -3 -4
*/


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

using namespace std;

int main(){
  int N,a,b,c;
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> a >> b >> c;
    if(a*a + b*b == c*c||a*a + c*c == b*b||b*b + c*c == a*a){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3084
# D - Line++
N,X,Y = map(int,input().split())
k = [0]*N
for i in range(1,N):
    for j in range(i+1,N+1):
        t = min(j-i, abs(i-X)+1+abs(j-Y))
        k[t] += 1
for i in range(1,N):
    print(k[i])

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

int main(int argc, char** argv){
	int n;
	cin >> n;
	ll h[n];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	ll ret = 0;
	ll tmp_ret = 0;
	for(int i = 1; i < n; i++){
		if(h[i-1] < h[i]){
			ret = max(ret,tmp_ret);
			tmp_ret = 0;
		}else{
			tmp_ret++;
		}
	}
	ret = max(ret,tmp_ret);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int a[1000];
	int N;
	
	int max, min;
	scanf("%d",&N);
	for(int i=0; i<N; i++){
		scanf("%d",&a[i]);
	}
	max = a[0];
	min = a[0];
	
	for(int i=0; i<N; i++){
		if( max<a[i] ) max=a[i];
		if( min>a[i] ) min=a[i];
	}
	printf("%d\n",max-min);
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>
#include <iterator>
#include <set>

using namespace std;

int main()
{
	int N;
	cin >> N;
	set<int> s;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		s.insert(A);
	}
	int M = s.size();
	M -= (N - M) % 2;
	cout << M << endl;
}


Measured memory_bytes: 4864
#include <iostream>

using namespace std;

int main(){
    int x,y;
    cin >> x >> y;

    int t = (y- 2*x);
    int k = (4*x - y)*2;

    //cout << t << " " << k << endl;

    if(t%2 == 0 && k%4 == 0 && t>=0 && k >= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll C[112345][123];

char S[112345];

int main() {

	scanf("%s", S);
	int N = strlen(S);

	int b = 1;
	rep(i, N) {
		char c = S[N - i - 1];
		if (i == 0) {
			if (c == '?') {
				rep(k, 10) {
					rep(j, 13) {
						C[i][(j + b * k) % 13] += j ? 0 : 1;
					}
				}
			}
			else {
				rep(j, 13) {
					C[i][(j + b * (c - '0')) % 13] = j ? 0 : 1;
				}
			}
		}
		else {
			if (c == '?') {
				rep(k, 10) {
					rep(j, 13) {
						C[i][(j + b * k) % 13] += C[i - 1][j];
					}
				}
			}
			else {
				rep(j, 13) {
					C[i][(j + b * (c - '0')) % 13] = C[i - 1][j];
				}
			}
		}
		rep(j, 13) {
			C[i][j] %= 1000000007;
		}
		b *= 10;
		b %= 13;
	}

	printf("%lld\n", C[N - 1][5]);

	return 0;
}


Measured memory_bytes: 96512
W, H, N = map(int, input().split())
bl_x, tr_x, bl_y, tr_y = 0, W, 0, H
for i in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		bl_x = max(bl_x, x)
	elif a == 2:
		tr_x = min(tr_x, x)
	elif a == 3:
		bl_y = max(bl_y, y)
	elif a == 4:
		tr_y = min(tr_y, y)
print(max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0))


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

int main() {
    int x; cin >> x;
    vector<int> d(x);
    for (int i = 0;i < x; i++) cin >> d.at(i);
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());

    int ans = 0 , mi = 1e9;
    for (int i = 0;i < x; i++) {
        if (mi > d.at(i)) {
            ans++;
            mi = min(mi, d.at(i));
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char A = sc.next().charAt(0);
		char B = sc.next().charAt(0);
		char ans = 0;
		if(A == B) {
			ans = '=';
		} else if(A > B) {
			ans = '>';
		} else if(A <B) {
			ans = '<';
		}
		System.out.println(ans);
	}
}


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

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

//#define doutnl(args...) cout<<args
#define doutnl(...)
#define dout(args...) doutnl(args<<endl;)
#define dprintl(args...) dout("D:"<<__LINE__<<": " args)
#define dv(v) <<#v<<"="<<(v)<<"; "


int ds[2][101];
int a[2][101];

int n;
const int INF=1000000;
int dfs(int t,int f,int d){
	dprintl(dv(t)dv(f)dv(d));
	if(f<1)return INF;
	if(f>n)return INF;
	if(d>=ds[t][f]){dprintl(dv(t)dv(f)dv(ds[t][f]));return INF;}
	ds[t][f]=d;
	
	dprintl(dv(a[t][f]));
	if(a[t][f]==1&&a[t][f+1]==1){
		if(f==n){dprintl(dv(t)dv(f)dv(d));return d;}
		return dfs(t,f+1,d);
	}else if(a[t][f]==2){
		return dfs(t,f-1,d);
	}else{
	
		if(f==n){dprintl(dv(t)dv(f)dv(d));return d;}
		return min(min(dfs(t^1,f+2,d+1),dfs(t^1,f+1,d+1)),dfs(t^1,f,d+1));
	}
		
} 
int main(){
	while(true){
		cin>>n;
		if(n==0) break;
		
		REP(j,2)REP(i, n) cin>>a[j][i+1];
		REP(j,2)REP(i,n+1)ds[j][i]=INF;
		
		int ans=min(dfs(0,1,0),dfs(1,1,0));
		if(ans>=INF){
			cout<<"NA"<<endl;
		}
		else{
			cout<<ans<<endl;
		}
	}
		
	return 0;
}

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

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int[] L=new int[N*2];
	    int c=0;
	    for (int i=0; i<2*N;i++) {
	    	L[i]=gi();
	    }
	    Arrays.parallelSort(L);
	    for (int i=0; i<N;i++) {
	    	c+=Math.min(L[2*i],L[2*i+1]);
	    }
        System.out.print(c);

//        if (2*X<=Y&& Y<=4*X && Y%2==0) {
//        	System.out.println("Yes");
//        }else{
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35704
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		Map<String, Integer> S = new HashMap<String, Integer>(N);
		for(int i=0; i<N; i++) {
			String s = sc.next();
			if(S.containsKey(s)) {
				int n = S.get(s) + 1;
				S.put(s, n);
			}else {
				S.put(s, 1);
			}
		}

		List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(S.entrySet());

        Collections.sort(list_entries, new Comparator<Entry<String, Integer>>() {
            //compareを使用して値を比較する
            public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2)
            {
                if(obj2.getValue().intValue() == obj1.getValue().intValue()) {
                	//文字列の昇順
                	return obj1.getKey().compareTo(obj2.getKey());
                }
                else {
                	//数値の降順
                	return obj2.getValue().compareTo(obj1.getValue());
                }
            }
        });

        int max = 0;
        int count = 0;
        List<String> ans = new ArrayList<String>();
        for(Entry<String, Integer> entry : list_entries) {
        	String s = entry.getKey();
        	int value = entry.getValue();

            if(count == 0) {
            	max = value;
            	ans.add(s);
            }else {
            	if(value == max) {
            		ans.add(s);
            	}else {
            		break;
            	}
            }

            count++;
        }

        for(String s: ans) {
        	System.out.println(s);
        }
	}

}

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

using namespace std;

int main(){
	char b;
	cin >> b;
	
	if(b == 'A'){
		cout << 'T' << endl;
	}else if(b == 'C'){
		cout << 'G' << endl;
	}else if(b == 'G'){
		cout << 'C' << endl;
	}else if(b == 'T'){
		cout << 'A' << endl;
	}
	
	return 0;
}


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

using namespace std;

typedef long long ll;

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

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

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

const int N = 100010;

bool mark[N];
ll cnt[N];

int main(){
    ll n, m;
    cin >> n >> m;
    ll i;
    mark[1] = true;
    for ( i = 1 ; i <= n + 1 ; i ++ ){
    	cnt[i] = 1;
    }
    for ( i = 0 ;i < m ;  i ++ ){
    	ll u , v;
    	cin >> u >> v;
    	if ( mark[u] == true ){
    		mark[v] = true;
    	}
    	cnt[v] ++;
    	cnt[u] --;
    	if ( cnt[u] == 0 ){
    		mark[u] = false;
    	}
    }
    ll ans = 0;
    for ( i = 1 ; i <= n ; i ++ ){
    	if ( mark[i] == true ){
    		if ( cnt [i] > 0 ){
    			ans ++;
    		}
    	} 
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

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

  vector<int> w(N), e(N);
  w[0] = 0, e[N-1] = 0;
  for (int i = 1; i < N; ++i) {
    w[i] = w[i-1];
    if (S[i-1] == 'W') w[i] = w[i-1] + 1;

    e[N-i-1] = e[N-i];
    if (S[N-i] == 'E') e[N-i-1] = e[N-i] + 1;
  }

  int ans = 1e9;
  for (int i = 0; i < N; ++i) {
    ans = min(ans, w[i] + e[i]);
  }

  cout << ans << endl;
}

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

using namespace std;

const int MAXN = 1.5E5;
long long o[MAXN];
long long ans[MAXN];
long long seq[MAXN];
int top, n, q;
long long a;

void getAns(long long len, long long value)
{
	int bestPos = upper_bound(seq + 1, seq + 1 + top, len) - seq - 1;
	if (!bestPos)
		return ans[1] += value, ans[len + 1] -= value, void();
	o[bestPos] += value * (len / seq[bestPos]), getAns(len % seq[bestPos], value);
}

int main(void)
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> q;
	seq[++top] = n;
	for (int i = 1;i <= q; ++i)
	{
		cin >> a;
		while (top && seq[top] >= a)
			--top;
		seq[++top] = a;
	}
	
	o[top] = 1;
	for (int i = top - 1; i; --i)
		o[i] += o[i + 1] * (seq[i + 1] / seq[i]), getAns(seq[i + 1] % seq[i], o[i + 1]);
	
	ans[1] += o[1], ans[seq[1] + 1] -= o[1];
	for (int i = 1;i <= n; ++i)
		ans[i] += ans[i - 1], cout << ans[i] << '\n';
		
	return 0;
}

Measured memory_bytes: 6008
use std::io;
use std::io::Read;

fn main() {
    let mut stdin = io::stdin();
    let mut lines = String::new();
    let _ = stdin.read_to_string(&mut lines);
    let vec = lines.lines().collect::<Vec<&str>>();
    let firstline = vec[0].split(' ').collect::<Vec<&str>>();
    let n :usize = firstline[0].trim().parse().unwrap();
    let m :usize = firstline[1].trim().parse().unwrap();
    let mut hens :Vec<(usize,usize)> = Vec::new();
    for i in 0..m {
        let thisline = vec[i+1].split(' ').collect::<Vec<&str>>();
        let a :usize = thisline[0].trim().parse().unwrap();
        let b :usize = thisline[1].trim().parse().unwrap();
        hens.push((a-1,b-1));
    }
    let hens = hens;
    let mut dp : Vec<usize> = vec![0;n*(1<<n)];
    dp[1*n+0] = 1;
    for i in 2..(1<<n) {
        for j in 0..n {
            if (1<<j) & i == 0 {continue;}
            for &(a,b) in &hens {
                let tail = if a == j {
                    b
                } else if b == j {
                    a
                } else {
                    n
                };
                if tail == n {continue;}
                dp[i*n+j] += dp[(i^(1<<j))*n+tail];
            }
        }
    }
    let mut fin = 0;
    for i in 0..n {
        fin += dp[((1<<n)-1)*n+i];
    }
    println!("{}",fin);
}



Measured memory_bytes: 4352
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        f = True
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                f = False
                break
        if f:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()

    len_n = len(str(n))
    
    if str(n)[len_n-1] == '3':
        print('bon')
    elif str(n)[len_n-1] == '0' or str(n)[len_n-1] == '1' or str(n)[len_n-1] == '6' or str(n)[len_n-1] == '8':
        print('pon')
    else:
        print('hon')

    

if __name__ == '__main__':
    main()


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

int H,W;
vector<string> s;

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


signed
main(){
		cin >> H >> W;
		s = vector<string>(H);
		for(int i=0;i<H;i++)
		{
				cin >> s[i];
		}
		vector<vector<int>> up(H,vector<int>(W,0));
		vector<vector<int>> down(H,vector<int>(W,0));
		vector<vector<int>> left(H,vector<int>(W,0));
		vector<vector<int>> right(H,vector<int>(W,0));

		for(int x=0;x<W;x++){
				for(int y=1;y<H;y++)
				{
						if(s[y][x]=='.')
						{
								if(s[y-1][x]=='.')
										up[y][x] = up[y-1][x] + 1;
								else
										up[y][x] = 0;
						}else{
								up[y][x] = 0;
						}
				}
		}

		for(int x=0;x<W;x++){
				for(int y=H-2;y>=0;y--)
				{
						if(s[y][x]=='.')
						{
								if(s[y+1][x]=='.')
										down[y][x] = down[y+1][x] + 1;
								else
										down[y][x] = 0;
						}else{
								down[y][x] = 0;
						}
				}
		}

		for(int y=0;y<H;y++){
				for(int x=1;x<W;x++)
				{
						if(s[y][x]=='.')
						{
								if(s[y][x-1]=='.')
										left[y][x] = left[y][x-1] + 1;
								else
										left[y][x] = 0;
						}else{
								left[y][x] = 0;
						}
				}
		}

		for(int y=0;y<H;y++){
				for(int x=W-2;x>=0;x--)
				{
						if(s[y][x]=='.')
						{
								if(s[y][x+1]=='.')
										right[y][x] = right[y][x+1] + 1;
								else
										right[y][x] = 0;
						}else{
								right[y][x] = 0;
						}
				}
		}




		int ans = 0;
		for(int y=0;y<H;y++){
				for(int x=0;x<W;x++)
				{
						if(s[y][x]=='#') continue;
						//cout << bfs(y,x) << endl;
						//cout << up[y][x] << " " << down[y][x] << " " << left[y][x] << " " << right[y][x] << endl;

						ans = max(ans, 1+up[y][x]+down[y][x]+left[y][x]+right[y][x]);
				}
		}
		cout << ans << endl;
}

Measured memory_bytes: 67200
#include<iostream>
class dice
{
private:
	int _top, _botom, _front, _back, _right, _left;
public:
	dice(int top, int botom, int front, int back, int right, int left): _top(top), _botom(botom), _front(front), _back(back), _right(right), _left(left) {};
	void roll(char dir)
	{
		int temp;
		switch(dir)
		{
			case 'E':
				temp = _top;
				_top = _left;
				_left = _botom;
				_botom = _right;
				_right = temp;
				break;
			case 'W':
				temp = _top;
				_top = _right;
				_right = _botom;
				_botom = _left;
				_left = temp;
				break;
			case 'S':
				temp = _top;
				_top = _front;
				_front = _botom;
				_botom = _back;
				_back = temp;
				break;
			case 'N':
				temp = _top;
				_top = _back;
				_back = _botom;
				_botom = _front;
				_front = temp;
				break;
			case 'R':
				temp = _front;
				_front = _left;
				_left = _back;
				_back = _right;
				_right = temp;
				break;
			case 'L':
				temp = _front;
				_front = _right;
				_right = _back;
				_back = _left;
				_left = temp;
				break;
		}
	}
	int top()const
	{
		return _top;
	}
	int botom()const
	{
		return _botom;
	}
	int front()const
	{
		return _front;
	}
	int back()const
	{
		return _back;
	}
	int right()const
	{
		return _right;
	}
	int left()const
	{
		return _left;
	}
	bool operator==(const dice&d)const
	{
		return _top == d.top() && _botom == d.botom() && _front == d.front() && _back == d.back() && _right == d.right() && _left == d.left();
	}
	bool operator!=(const dice&d)const
	{
		return !operator==(d);
	}

};
int main()
{
	int N;
	std::cin >> N;
	dice**d = new dice*[N];
	for(int i = 0; i < N; i++)
	{
		int top, botom, front, back, right, left;
		std::cin >> top >> back >> right >> left >> front >> botom;
		d[i] = new dice(top, botom, front, back, right, left);
	}
	for(int i = 0; i < N; i++)
	{
		const int top_i = 1, back_i = 2;
		if(top_i == d[i]->botom())
		{
			d[i]->roll('N');
			d[i]->roll('N');
		}
		else if(top_i == d[i]->front())
		{
			d[i]->roll('S');
		}
		else if(top_i == d[i]->back())
		{
			d[i]->roll('N');
		}
		else if(top_i == d[i]->right())
		{
			d[i]->roll('W');
		}
		else if(top_i == d[i]->left())
		{
			d[i]->roll('E');
		}
		if(back_i == d[i]->front())
		{
			d[i]->roll('R');
			d[i]->roll('R');
		}
		else if(back_i == d[i]->right())
		{
			d[i]->roll('R');
		}
		else if(back_i == d[i]->left())
		{
			d[i]->roll('L');
		}
	}
	bool is_OK = true;
	for(int i = 0; i < N - 1; i++)
	{
		for(int j = i + 1; j < N; j++)
		{
			is_OK &= *d[i] != *d[j];
		}
	}
	std::cout << (is_OK ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
  int N, x;
  cin >> N >> x;
  VI A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.PB(a);
  }
  sort(ALL(A));
  int id = 0;
  while (id < SZ(A) && x > 0)
    x -= A[id++];
  if (x == 0)
    printf("%d\n", id);
  else
    printf("%d\n", id - 1);
  return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=998244353;
const llint big=1e18+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
map<string,llint>memo;
llint solve(string& str){//合成をえいする
	if(memo.count(str)==1){return memo[str];}
	//cerr<<"    str="<<str<<endl;
	int i,j,k,L,n=str.size();
	vector<vector<llint>>dp(n+1);
	for(i=0;i<=n;i++){dp[i].res(n+1);}//半閉区間
	for(i=1;i<=n;i++){
		for(j=0;j+i<=n;j++){
			//cerr<<"de j="<<j<<"j+i="<<j+i;
			if(i==1){dp[j][j+i]=1;if(str[j]=='1'){dp[j][j+i]=2;}}
			else{
				//for(k=j+1;k<j+i;k++){dp[j][j+i]+=dp[j][k]*dp[k][j+i];dp[j][j+i]%=mod;}
				//約数
				for(L=1;L<i;L++){
					if(i%L!=0){continue;}
					string sub;for(k=0;k<L;k++){sub.pub('1');}
					for(k=0;k<i;k++){mineq(sub[k%L],str[j+k]);}
					dp[j][j+i]+=solve(sub);
					dp[j][j+i]%=mod;
				}
			}
			//cerr<<"ans="<<dp[j][j+i]<<endl;
		}
	}
	vector<llint>ddp(n+1);ddp[0]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){ddp[i]+=ddp[j]*dp[j][i];ddp[i]%=mod;}
	}
	memo[str]=ddp[n];return ddp[n];
}
int main(void){
	string str;cin>>str;
	cout<<solve(str)<<endl;RE;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define ld long double
using namespace std;

ll mod = 1000000007;


void solve()
{
ll x;
cin>>x;
if(x==0 ) cout<<1<<endl;
else cout<<0<<endl;
}


int main()
{

#ifndef ONLINE_JUDGE

	freopen("inputs.txt", "r", stdin);

	freopen("outputs.txt", "w", stdout);
#endif
	fast;
	
	//for (int i = 0; i < t; i++)
		solve();

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	ll a[200010],b[200010];
	for(ll i=0;i<n;i++){
		cin>>a[i];
		a[i]-=1;
	}
	b[0]=0;
	for(ll i=1;i<=n;i++){
		b[i]=b[i-1]+a[i-1];
		b[i]%=k;
   // 	cout <<b[i];
	}
//	cout <<endl;
	map<ll,ll>ch;
	ll ans=0;
	for(ll i=0;i<=n;i++){
		if(i-k>=0){
		ll mae=b[i-k];
		ch[mae]--;
		}		
		ll now=b[i];
		ans+=ch[now];
		ch[now]++;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>

using namespace std;

int main(){
  string S;
  cin>>S;
  bool a=true;
  for(int i=1;i<S.length()+1;i++){
    if((i%2==1 && (S[i-1]=='R' || S[i-1]=='U' || S[i-1]=='D'))||
        (i%2==0 && (S[i-1]=='L' || S[i-1]=='U' || S[i-1]=='D'))){
    }else{
      a=false;
      break;
    }
  }
  a ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
struct edge{
    int from, to;
    T cost;
    edge(int from, int to, T cost = 1) : from(from), to(to), cost(cost){}
    bool operator < (const edge & e) const{
        return cost < e.cost;
    }
};

/*
    sからたどりつける負の閉路を検出したとき、空の vector を返す
    頂点数 V, 始点 s, 辺の集合 es, INF として LINF を使うとき : 
    vector<ll> dist = BellmanFord(V, s, es, LINF);
*/
template <typename T>
vector<T> BellmanFord(int V, int s, vector<edge<T>> & es, const T INF = 1e9){
    int E = es.size();
    vector<T> dist(V, INF);
    dist[s] = 0;
    for(int i = 0; i < 2 * V; i++){
        for(edge<T> & e : es){
            if(dist[e.from] == INF) continue;
            if(dist[e.from] + e.cost < dist[e.to]){
                dist[e.to] = dist[e.from] + e.cost;
                if(i >= V && e.to == V - 1) return vector<T>();
            }
        }
    }
    return dist;
}

//グラフ全体をみて、負の閉路が存在するとき true を返す
template <typename T>
bool FindNegativeLoop(int V, vector<edge<T>> & es){
    vector<T> dist(V, 0);
    for(int i = 0; i < V; i++){
        for(edge<T> & e : es){
            if(dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(i == V - 1) return true;
            }
        }
    }
    return false;
}

signed main(){
    int n,m;
    cin >> n >> m;
    int a,b;
    ll c;
    vector<edge<ll>> es;
    REP(i,m){
        cin >> a >> b >> c;
        a--;
        b--;
        es.emplace_back(a, b, -c);
    }
    vector<ll> dist = BellmanFord(n, 0, es, LINF);
    if(dist.size()) cout << -dist[n - 1] << endl;
    else cout << "inf" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
bool isPrime(ll n){
  for(ll i=2;i*i<=n;i++) if(n%i==0) return false;
  return true;
}
int main(){
  ll ans = 2;
  ll n;
  vector<ll> p;
  vector<ll> v;
  for(ll i=2;i<1000000;i++) if(isPrime(i)) p.push_back(i);
  //cout << p.size() << endl;
  while(1){
    ans=2;
    v.clear();
    cin >> n;
    if(n == 0)break;
    if(n==1) {
      cout << 1 << endl;
      continue;
    }
    //cout << n << endl;
    for(ll i = 0;p[i] <= n;i++){
      //cout << i << n << endl;
      if(i==p.size()) break;
      if(n%p[i] == 0){
        ll c=0;
        while(n%p[i]==0) {
          n/=p[i];
          c++;
        }
        //cout << p[i] << ":" << c << endl;
        v.push_back(c);
	
	if(n==1) break;
      }
       
    }
    if(n!=1) v.push_back(1);
    ll m = 0;
    ans = 1;
    for(ll i=0;i<v.size();i++){
      ans*=2*v[i]+1;
    }
    cout << (1+ans)/2 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1984