akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int main()
{
	int i, N, x[100002], L;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(x[i]));
	scanf("%d", &L);
	x[0] = x[1] - L - 1;
	x[N+1] = x[N] + L + 1;
	
	int j, l, r, skip[2][100001][18] = {};
	for (j = 0; j < 18; j++) {
		skip[0][N][j] = N + 1;
		skip[1][1][j] = 0;
	}
	for (i = N - 1; i >= 1; i--) {
		l = i + 1;
		r = N;
		while (l < r) {
			if (x[(l+r+1)/2] <= x[i] + L) l = (l + r + 1) / 2;
			else r = (l + r - 1) / 2;
		}
		skip[0][i][0] = l;
		for (j = 0; skip[0][skip[0][i][j]][j] < N + 1; j++) skip[0][i][j+1] = skip[0][skip[0][i][j]][j];
		for (j++; j < 18; j++) skip[0][i][j] = N + 1;
	}
	for (i = 2; i <= N; i++) {
		l = 1;
		r = i - 1;
		while (l < r) {
			if (x[(l+r)/2] >= x[i] - L) r = (l + r) / 2;
			else l = (l + r) / 2 + 1;
		}
		skip[1][i][0] = l;
		for (j = 0; skip[1][skip[1][i][j]][j] > 0; j++) skip[1][i][j+1] = skip[1][skip[1][i][j]][j];
		for (j++; j < 18; j++) skip[1][i][j] = 0;
	}

	
	const int bit[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};
	int q, Q, ans;
	scanf("%d", &Q);
	for (q = 1; q <= Q; q++) {
		scanf("%d %d", &l, &r);
		ans = 0;
		if (l < r) {
			while (l < r) {
				for (j = 1; skip[0][l][j] <= r; j++);
				ans += bit[--j];
				l = skip[0][l][j];
			}
		} else {
			l ^= r;
			r ^= l;
			l ^= r;
			while (l < r) {
				for (j = 1; skip[1][r][j] >= l; j++);
				ans += bit[--j];
				r = skip[1][r][j];
			}
		}
		printf("%d\n", ans);
	}
	fflush(stdout);
	return 0;
}

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

#define MAX_N 100000
vector<int> G[MAX_N+1];
int color[MAX_N+1];

bool dfs(int v, int c) {
    color[v] = c;
    for (int i = 0; i < G[v].size(); i++) {
        if (color[G[v][i]] == c) return false;
        if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }
    return true;
}


int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        G[u-1].push_back(v-1);
        G[v-1].push_back(u-1);
    }

    long long res = 0;
    if (dfs(0, 1)) {            // 2部グラフのとき
        // res = 1LL * N/2 * (N/2 + N%2) - M;
        // 2部グラフの2つ集合が均等に別れる保証はない
        long long  s1 = 0, s2 = 0;
        for (int i = 0; i < N; i++) if (color[i] > 0) s1++;
        s2 = N - s1;
        res = s1 * s2 - M;
    } else {
        res = 1LL * N * (N-1) / 2 - M;
    }
    cout << res << endl;

    return 0;
}


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

int main(){
	
	int a, b, c;
	int tmp;
	cin >> a >> b >> c;
	
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}
	
	if(b > c){
		tmp = b;
		b = c;
		c = tmp;
	}
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}
	cout << a << " " << b << " " << c << endl;
	
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    ll n;
    cin>>n;
    string s;
    while(n--){
        s=char(97+n%26)+s;
        n/=26;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n, m, l, fx=0;
      cin >> n;     
      l = n;
      
      for (int i=0; i < 8; i++){
        m = l % 10;
        fx += m;
        l = (l-m)/10;
      }
      
      if (n % fx == 0){
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
      
    }

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,i,j;
  int a[200000],tmp[200000]={0};
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  j=0;
  for(i=n-1;i>=(n-1)%2;i=i-2){
    tmp[j]=a[i];
    j++;
  }
  for(i=n%2;i<n;i=i+2){
    tmp[j]=a[i];
    j++;
  }
  
  for(i=0;i<n;i++){
    printf("%d ",tmp[i]);
  }
}
  

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if ((A+D-1)/D >= (C+B-1)/B)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
K, Q = map(int, input("").split())
d_ = list(map(int, input("").split()))
for _ in range(Q):
    n,x,m = map(int, input("").split())
    d = [0]*K;zeroes = [0]*(K+1);sum = [0]*(K+1)
    for i in range(K):d[i] = d_[i] % m
    for i in range(K):zeroes[i+1] = zeroes[i] + (d[i] == 0)
    for i in range(K):sum[i+1] = sum[i] + d[i]
    #print(zeroes, sum)  
    s = (n-1)//K*sum[K] + sum[(n-1)%K]
    s += x%m
    #print(s)
    num0 = (n-1)//K*zeroes[K] + zeroes[(n-1)%K]
    print(n-1-s//m-num0)


Measured memory_bytes: 69724
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

template<class T>
void dcomb(T n,T m, string s){
    if(n==0) cout << s << endl;
    else {
        for(T i=0; i<m; ++i){
            dcomb(n-1,m,s+to_string(i));
        }
    }
}

int  INF = 1e9+7;

int main(){
    ll n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> wv(n);
    rep(i,n) cin >> wv[i].first >> wv[i].second;
    vector<vector<ll>> dp(n+1,vector<ll>(w+1));
    rep(i,n+1){
        rep(j,w+1){
            dp[i][j] = 0;
        }
    }
    for(ll i=0; i<n; ++i){
        for(ll sum_weight = 0; sum_weight<=w; ++sum_weight){
            if(sum_weight-wv[i].first>=0){
                chmax(dp[i+1][sum_weight],dp[i][sum_weight-wv[i].first]+wv[i].second);
            }
            chmax(dp[i+1][sum_weight],dp[i][sum_weight]);
        }
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
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++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  ll sum = 0, ans_p = 0;
  rep(i, n) {
    sum += a[i];
    if (i % 2 == 0 & sum < 1) {
      ans_p += 1 - sum;
      sum = 1;
    }
    else if (i % 2 == 1 && sum > -1) {
      ans_p += sum + 1;
      sum = -1;
    }
  }

  ll ans_m = 0;
  sum = 0;
  rep(i, n) {
    sum += a[i];
    if (i % 2 == 1 & sum < 1) {
      ans_m += 1 - sum;
      sum = 1;
    }
    else if (i % 2 == 0 && sum > -1) {
      ans_m += sum + 1;
      sum = -1;
    }
  }
  cout << min(ans_p, ans_m) << endl;
}

Measured memory_bytes: 1024
//ABC109D

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int H,W;
    cin>>H>>W;
    VII A(H,VI(W));
    rep(i,H){rep(j,W)cin>>A[i][j];}

    vector<pair<int,int>> P;

    rep(i,H){
        rep(j,W-1){
            if(A[i][j]&1){
                --A[i][j];
                ++A[i][j+1];
                P.pb(MP(i+1,j+1));
                P.pb(MP(i+1,j+2));
            }
        }
        if(A[i][W-1]&1&&i!=H-1){
            --A[i][W-1];
            ++A[i+1][W-1];
            P.pb(MP(i+1,W));
            P.pb(MP(i+2,W));
        }
    }

    put(P.size()/2);
    rep(i,P.size()) cout<<P[i].first<<" "<<P[i].second<<(i%2?"\n":" ");
}

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

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

  int n, d=1;
  cin >> n;

  int ans;
  if(n<10)ans=n;
  else if(n<100)ans=9;
  else if(n<1000)ans=9+(n-99);
  else if(n<10000)ans=909;
  else if(n<100000)ans=909+(n-9999);
  else ans=90909;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#ダブリングを使う、２進数
N,K = gets.strip.split.map(&:to_i)
num = gets.strip.split.map(&:to_i)
t = Math.log2(K).ceil

#数表を作っていく、そしてそこに記録して後々使う
db = Array.new(t+1){Array.new(N+1,0)} #二次元配列の初期化に注意
for i in 1..N #初期条件
  db[0][i] = num[i-1]
end
for k in 1..t
  for i in 1..N
    db[k][i] = db[k-1][db[k-1][i]]
  end
end

m = K.to_s(2) #２進数に直した,ただしmの各数字は文字メソッド（.to_s)だよ
now = 1
for j in 0..m.size-1
  if m[j] == "1"
    now = db[m.size-1-j][now]
  end
end
puts now

Measured memory_bytes: 124052
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
int main() {
	char str[1024], *pt = str;
	int x,flg=0;
	fgets(str, sizeof(str), stdin);
	pt = strtok(str, " ,.\n");
	while (pt != NULL) {
		x = strlen(pt);
		if (3 <= x&&x <= 6) {
			if (flg)putchar(' ');
			else flg = 1;
			printf("%s", pt);
		}
		pt = strtok(NULL, " ,.\n");
	}putchar('\n');
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
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; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

ll compst(string A,string B){
  ll cnt = 0;
  for (int i = 0; i < A.size(); i++)
  {
    if(A[i]!=B[i]){
      cnt++;
    }
  }
  return cnt;
}

int main ()
{
  string S;cin>>S;
  string A = "";
  string B = "";
  REP(i,S.size()){
    if(i%2==0){
      A += "0";
      B += "1";
    }
    else{
      A += "1";
      B += "0";
    }
  }
  cout<<min(compst(A,S),compst(B,S))<<endl;
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  for(int i=0; i<N-1; i++){
    if(A.at(i)==A.at(i+1)){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 3940
S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] // 2
    result *= K

    result += s[1] // 2
    result += e[1] // 2
    x = (s[1] + e[1]) // 2
    result += x * (K - 1)
    print(result)
else:
    print(sum([x[1] // 2 for x in X]) * K)



Measured memory_bytes: 3064
main = do
    n <- readLn :: IO Int
    let a = floor $ sqrt $ fromIntegral n
    let b = foldr (\a -> \b ->min a b) (n + 2) $ map (\x -> x + (n `div` x)) [x|x <- [1..a], n `mod` x == 0]
    putStrLn $ show (b - 2)

Measured memory_bytes: 508
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    vector<int> b(a);
    sort(b.begin(), b.end());

    int c = 0;
    for(int i=0;i<n;++i) {
        if(a[i] != b[i]) ++c;
    }

    cout << ((c==0||c==2)?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); 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<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll x;
    cin >> x;
    ll cnt = 0;
    cnt += (x/500)*1000;
    ll rest = x%500;
    cnt += (rest/5) * 5;
    cout << cnt << endl;


}

Measured memory_bytes: 256
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]
dp = [-1] * N
dp[N-1] = A[0]

ans = 0
for i in range(1, N):
    target_index = bisect.bisect_left(dp, A[i])
    dp[target_index-1] = A[i]

print(N - dp.count(-1))

Measured memory_bytes: 13692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const ll MOD = 1000000007;
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll k){
    ll com=finv[k];
    for(ll i=n;i>n-k;i--){
        com*=i;
        com%=MOD;
    }
    return com;
}
ll modpow(ll a,ll n,ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void Main(){
    COMinit();
    ll n;cin>>n;
    ll a;cin>>a;
    ll b;cin>>b;
    ans=modpow(2,n,MOD)-1;
    ans-=COM(n,a);
    ans+=MOD;
    ans%=MOD;
    ans-=COM(n,b);
    ans+=MOD;
    ans%=MOD;
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 12160
#ifndef DEBUG
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;

#ifdef DEBUG
#define IO
#else
#define IO ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
#define All(v) v.begin(),v.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
// template<typename T> using rkt = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main() {
    IO;

    char c;
    list<char> s{};
    while ((c = cin.get()) != '\n')
        s.emplace_back(c);
    int o, r = 0;
    int q; cin >> q; while (q--) {
        cin >> o;
        if (o == 1) r ^= 1;
        else {
            cin >> o >> c;
          	if (o-1 != r) s.emplace_back(c);
          	else s.emplace_front(c);
        }
    }
    if (r == 1) reverse(All(s));
    for(char x: s) cout << x;
    cout << endl;

}

Measured memory_bytes: 9984
N=int(input())
kazu=[0 for i in range(N)]
A=[int(x) for x in input().rstrip().split()]

for i in A:
  kazu[i-1]+=1

cnt=0
ans=[]
for i in kazu:
  ans.append((i*(i-1))//2)

cnt=sum(ans)
for i in range(N):
  now=kazu[A[i]-1]-1
  print(cnt-ans[A[i]-1]+(now*(now-1))//2)

Measured memory_bytes: 27336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC155B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            string ans = "APPROVED";
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(input[i]);
                if (A[i] % 2 == 0)
                {
                    if (A[i] % 3 != 0 & A[i] % 5 != 0)
                    {
                        ans = "DENIED";
                    }
                }
            }
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 27376
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX_N (int)1e5
int N;
int A[MAX_N + 1];

int gcd(int, int);
int solve();

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

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

    return 0;
}


int gcd(int a, int b){
    int c;
    if(a < b){
        c = b;
        b = a;
        a = c;
    }
    int r;
    while(a % b){
        r = a % b;
        a = b;
        b = r;
    }

    return b;
}


int solve(){
    int L[N], R[N], M[N];
    L[0] = A[0];
    for(int i = 1; i < N; i++){
        L[i] = gcd(L[i - 1], A[i]);
    }


    R[N - 1] = A[N - 1];
    for(int i = N - 2; i >= 0; i--){
        R[i] = gcd(R[i + 1], A[i]);
    }

    M[0] = R[1];
    M[N - 1] = L[N - 2];
    for(int i = 1; i < N - 1; i++){
        M[i] = gcd(L[i - 1], R[i + 1]);
    }

    int ans = M[0];
    for(int i = 0; i < N; i++){
        ans = max(ans, M[i]);
    }

    return ans;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int i, i1, i2;
    char x;
    for (i1 = 0; i1 < t.size(); i1++)
    {
        x = t[t.size() - 1];
        for (i = t.size() - 1; i >= 0; i--)
        {
            t[i + 1] = t[i];
        }
        t[0] = x;
        if (t == s)
        {
            cout << "Yes";
            return 0;;
        }
    }
    cout << "No";
    return 0;
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int n;
    cin >> n;
    string s;
    bool flg=false;
    REP(i,n){
        cin >> s;
        if(s=="Y")flg=true;
    }
    if(flg)cout << "Four" << endl;
    else cout << "Three" << endl;
}


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

int main(void){

	int sum,out;
	int runner[3];
	char act[8];
	int n;
	int i,j;

	scanf("%d",&n);

	for(i=0;i<n;i++){

		sum = 0;
		out = 0;
		runner[0] = runner[1] = runner[2] = 0;

		while(out < 3){

			scanf("%s",act);

			if(strcmp("HIT",act) == 0){
				if(runner[2] == 1)
					runner[2] = 0,sum++;
				if(runner[1] == 1)
					runner[1] = 0,runner[2] = 1;
				if(runner[0] == 1)
					runner[0] = 0,runner[1] = 1;

				runner[0] = 1;

			}
			else if(strcmp("HOMERUN",act)==0){
				sum++;

				for(j=0;j<3;j++){
					if(runner[j] == 1){
						runner[j] = 0;
						sum++;
					}
				}
			}
			else if(strcmp("OUT",act)==0){

				out++;
			}
		}

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

	}

	return 0;
}

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

int main(){
  unsigned long long int n;
  unsigned long long int p;
  cin >> n >> p;
  if (n == 1) {cout << p; return 0;}
  //cout << p << endl;
  unsigned long long int ans = 1;
  unsigned long long int max = sqrt(p);
  //cout << max <<endl;
  //cout << 'x';
  bool* sosu;
  //sosu = new bool[max+1];
  //cout << 'a';
  //for (unsigned long long int i = 0; i < max+1; i++) sosu[i] = true;
  //cout << 'b';
  for (unsigned long long int i = 2; i < max+1; i++){
     // cout << sosu[i] << " ";
    //if (!sosu[i]) continue;
    //cout << i <<" " << sosu[i] << endl;
    //unsigned long long int mod = pow(i, n)+0.5;
    unsigned long long int check = p;
    bool hantei = true;
    //cout << 'c';
    for (unsigned long long int j = 0; j < n; j++){
      //cout << 'd';
      if(check%i == 0) check = check/i;
      else {hantei = false; break;}
    }
    if(hantei){
       ans = i;
    }
    //else {for(unsigned int k = 1; k<=(max/i); k++) sosu[k*i] = false;}
  }
  //delete[] sosu;
    cout << ans;
    return 0;
}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	if (a<=8&&b<=8) cout<<"Yay!\n";
	else cout<<":("<<endl;
	return 0;
}


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

using namespace std;

#define ll long long

int main(){
	int N, M;
	cin >> N >> M;
	set<pair<int,int>> s;
	for(int i=0;i<M;i++) {
		int a, b;
		cin >> a >> b;
		s.insert({a,b});
	}
	for(int i=2;i<N;i++) {
		if(s.count({1,i})&&s.count({i,N})) {
			puts("POSSIBLE");return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}




Measured memory_bytes: 12888
#include <stdio.h>

int main(){
  int i,n,k,a[200005],m=0,c=0;
  scanf("%d",&n);
  scanf("%d",&k);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    c+=a[i];
    if(i>=k) c-=a[i-k];
    if(c>m){
      m=c;
    }
  }
  m+=k;
  printf("%d.",m/2);
  printf("%d",(m&1)*5);
  return 0;
}


Measured memory_bytes: 896
a,b,h,m= list(map(int, input().split()))
hh=30*(h+m/60)
mm=6*m
sa=min(abs(hh-mm),360-abs(hh-mm))
from math import cos,pi
print((a**2+b**2-2*a*b*cos(sa/180*pi))**0.5)

Measured memory_bytes: 9512
#DFS
N = int(input())
UVW = [list(map(int,input().split())) for _ in [0]*(N-1)]

E = [{} for _ in [0]*N]
for u,v,c in UVW:
    E[u-1][v-1] = c
    E[v-1][u-1] = c

def dist_dfs_tree(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        i = q.pop()
        ci = d[i]
        for j,cj in E[i].items():
            if d[j] !=-1:continue
            d[j] = ci+cj
            q.append(j)
    return d

d = dist_dfs_tree(N,E,0)
print(*[l%2 for l in d],sep="\n")

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

int main(){
    int n; cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    int ans=0;
    rep(i,n) ans+=s[i];
    if(ans%10!=0){
        cout << ans << endl;
        return 0;
    } else {
        rep(i,n){
            if(s[i]%10!=0){
                ans-=s[i];
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
s = input()
i,j=1,0
from collections import defaultdict
d = defaultdict(lambda:0)
d[s[0]]+=1
d[s[1]]+=1
ans = '-1 -1'
while True:
    if 2*d[s[j]]>i-j+1:
        ans = str(j+1)+' '+str(i+1)
        break
    if 2*d[s[j]]==i-j+1 and i < len(s)-1:
        i+=1
        d[s[i]]+=1
    else:
        d[s[j]]-=1
        j+=1
        if j == len(s)-1:
            break
print(ans)

Measured memory_bytes: 3444
def main():
  a,b = map(int, input().split())
  
  if b == 1:
    print(0)
    return
  
  result = 0
  count = 0
  
  while(result < b):
    if count == 0:
      result += 1
    result -= 1
    result += a
    count += 1
  print(count)
  
main()

Measured memory_bytes: 38256
/*
	0045:Sum and Average
*/
#include	<iostream>
#include	<cstdio>

using namespace std;

int round(double);

int main(void) {
	int sum_sale = 0, sum_count = 0, c = 0, buf_sale, buf_count;
	
	while(scanf("%d,%d", &buf_sale, &buf_count) != EOF) {
		sum_sale += buf_sale * buf_count;
		sum_count += buf_count;
		c++;
	}
	cout << sum_sale << endl << round((double)sum_count / c) << endl;
}

int round(double x) {
	return (int)(x+0.5);
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define LL long long


int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    int pizzaC = c * 2;
//    int pizzaAB = a + b;
    int pizzaMax = max(x, y);
    int pizzaMin = min(x, y);
    vector<int> price(3, 0);
    
//    if (pizzaAB <= pizzaC){
        price.at(0) =  (a * x) + (b * y);
//    }else if (pizzaAB > pizzaC){
        
//       if (a > c && b > c){
            while (pizzaMax > 0){
                price.at(1) = price.at(1) + pizzaC;
                pizzaMax --;
            }
//        }else{
             while (pizzaMin > 0){
                price.at(2) = price.at(2) + pizzaC;
                pizzaMin --;
                x --;
                y --;
            }
            price.at(2) = price.at(2) + (a * x) + (b * y);
            
         //   for (int i = 0; i < 3; i++) cout << price.at(i) << endl;
        sort(price.begin(), price.end());
        cout << price.at(0) << endl;
//        }
//    }
    
//    cout << price << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

#include <bits/stdc++.h>

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

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

	char a;
	cin >> a ;
	cout << (char)(a+1);

	return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class Task{
public:
    void solve(istream& in, ostream& out){
        int a, b;
        in>>a>>b;
        out<<a*b<<'\n';
    }
};

int main(){
    istream& in(cin);
    ostream& out(cout);
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    Task solver;
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main ( void )
{
  bool id[31] = { false };
  
  for ( int i = 0, x; (cin >> x) && i < 28; ++i )
    id[x] = true;
  for ( int i = 1; i < 31; ++i )
    if ( !id[i] ) cout << i << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int A, B, C;
  cin >> A >> B >> C;
  for (auto i = 1; i < 100010; ++i) {
    if (A*i%B==C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

char win(char c){
	if(c == 'r') return 'p';
	else if(c == 's') return 'r';
	else if(c == 'p') return 's';
}

int main(){
	int n, k;
	int r, s, p;
	string t;

	cin >> n >> k >> r >> s >> p >> t;
	vector<char> ans;

	for(int i = 0; i <= k - 1; i++){
		char p = t[i];
		ans.push_back(win(p));

		int con = 1;
		for(int j = i + k; j < n; j += k){
			if(p == t[j]){
				con++;

				if(con % 2 == 0){
					continue;
				}
				else{
					ans.push_back(win(p));
				}
			}
			else{
				con = 1;
				p = t[j];
				ans.push_back(win(p));
			}
		}
	}

	long long int point = 0;

	rep(i, ans.size()){
		// cout << ans[i];

		if(ans[i] == 'p') point += p;
		else if(ans[i] == 's') point += s;
		else if(ans[i] == 'r') point += r;
	}

	cout << point;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(3*n);
    inc(i, 0, 3*n){
        cin >> a[i];
    }
    priority_queue<int, vector<int>, greater<int>> bp;
    priority_queue<int> cp;
    vector<LL> b(n+1), c(n+1);
    b[0] = 0;
    c[0] = 0;
    //cout << "OK" << endl;
    inc(i, 0, n){
        bp.push(a[i]);
        b[0] += a[i];
        cp.push(a[2*n+i]);
        c[0] += a[2*n+i];
    }
    inc(i, 0, n){
        if(bp.top() < a[n+i]){
            b[i+1] = b[i]-bp.top()+a[n+i];
            bp.pop();
            bp.push(a[n+i]);
        }else{
            b[i+1] = b[i];
        }
        if(cp.top() > a[2*n-i-1]){
            c[i+1] = c[i]-cp.top()+a[2*n-i-1];
            cp.pop();
            cp.push(a[2*n-i-1]);
        }else{
            c[i+1] = c[i];
        }
    }
    LL ans = LLONG_MIN;
    inc(i, 0, n+1){
        ans = max(ans, b[i]-c[n-i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
	int row, col;
	cin >> row >> col;
	
	int matrix[row+1][col+1];
	
	for(int i=0; i<row; i++){
		for(int j=0; j<col; j++){
			cin >> matrix[i][j];
			matrix[row][j] = 0;
		}
		matrix[i][col]=0;
	}
	matrix[row][col]=0;
	
	for(int i=0; i<row; i++){
		for(int j=0; j<col; j++){
			matrix[row][col] += matrix[i][j];
			matrix[i][col] += matrix[i][j];
			matrix[row][j] += matrix[i][j];
			
			cout << matrix[i][j] << ' ';
			
		}
		cout << matrix[i][col] << endl;
	}
	
	for(int i=0; i<col; i++){
		cout << matrix[row][i] << ' ';
	}
	
	cout << matrix[row][col] << endl;
}

Measured memory_bytes: 3036
#include <iostream>
#include <fstream>
#include <ctime>
#include <climits>
#include <functional>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <set>
using namespace std;
struct UnionFind {
    vector<int> par, sz;
    int n_tree;

    explicit UnionFind(int n) : par(n), sz(n, 1), n_tree(n) { //0-indexed
        iota(par.begin(), par.end(), 0);
    }

    int n_cluster() const {
        return n_tree;
    }

    int size(int x) {
        return sz[root(x)];
    }

    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx != ry) {
            par[rx] = ry;
            --n_tree;
            sz[ry] += sz[rx];
            return true;
        }
        return false;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool is_root(int x) const {
        return par[x] == x;
    }
};
int main() {
#ifdef LOCAL
    ifstream in("in.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //仿tourist的做法
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> c(n);
    iota(c.begin(), c.end(), 0);
    sort(c.begin(), c.end(), [&](int x, int y) {return a[x] - b[x] < a[y] - b[y]; });
    vector<long long> sum_b(n);
    // ans[i]：子树i的最优解
    vector<bool> done(n, false);
    vector<long long> ans(n);
    for (int i = 0; i < n; ++i) {
        ans[i] = max(a[i], b[i]);
        sum_b[i] = b[i];
    }
    //vector<bool> added(n, false);
    UnionFind uf(n);
    for (auto v : c) {
        set<int> s;
        for (auto u : g[v]) {
            if (done[u]) {
                //并查集用来查找子树的根
                s.insert(uf.root(u));
            }
        }
        for (auto u : s) {
            sum_b[v] += sum_b[u];
            uf.unite(u, v);
        }
        //cout << v << ' ' << sum_b[v] << endl;
        if (!s.empty()) {
            long long best = LLONG_MAX;
            for (auto u : s) {
                long long sum_b_without = sum_b[v] - sum_b[u];
                long long cur = max(sum_b_without + ans[u], sum_b_without + a[v] - b[v]);
                best = min(best, cur);
                uf.unite(u, v);
            }
            ans[v] = best;
        }
        done[v] = true;
        //assert(uf.root(v) == v);
    }
    //for (int i = 0; i < n; ++i) {
    //    cout << c[i] << ' ' << sum_b[c[i]] << ' ' << ans[c[i]] << endl;
    //}
    cout << ans[c[n - 1]] << '\n';
#ifdef LOCAL
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

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

using ll=long long;
using ld=long double;

void solve(){
	int n;
	cin>>n;
	vector<int> L(n);
	for(int i=0;i<n;i++){
		cin>>L[i];
	}
	sort(L.begin(),L.end());
	ll ans=0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			if(L[i]==L[j]) continue;
			for(int k=j+1;k<n;k++){
				if(L[i]==L[k] || L[j]==L[k]){
					continue;
				}
				if(L[i]+L[j] > L[k]) ans++;
			}
		}
	}
	cout<<ans<<'\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int t,x; cin>>t>>x;
  double ans=double(t)/x;
  //浮動小数点型に出力するときに全て小数部10桁にできる
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt();
		int[] c = new int[n+1];
		int a, b;
		
		Arrays.fill(c, 0);
		for (int i=0; i<m; ++i) {
			a = in.nextInt();
			b = in.nextInt();
			++c[a];
			++c[b];
		}
		
		for (int i=1; i<=n; ++i)
			out.println(c[i]);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21460
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder bd = new StringBuilder();
        int[] dice = new int[6];
        int a = 0;
        int b = 0;
        for (int i=0; i<6; i++) {
            dice[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        Dice d = new Dice();
        for (int i=0; i<q; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();

            for (int j=0; j<6; j++) {
                if (x == dice[j]) {
                    a = j+1;
                }
                else if (y == dice[j]) {
                    b = j+1;
                }
            }

            bd.append(dice[d.Roll(a, b) - 1] + "\n");
        }
        System.out.print(bd);
    }
}

class Dice {

    public int Roll(int a, int b) {
        switch (a) {
            case 1: {
                switch (b) {
                    case 2: return 3;
                    case 3: return 5;
                    case 4: return 2;
                    case 5: return 4;
                }
            }
            case 2: {
                switch (b) {
                    case 1: return 4;
                    case 3: return 1;
                    case 4: return 6;
                    case 6: return 3;
                }
            }
            case 3: {
                switch (b) {
                    case 1: return 2;
                    case 2: return 6;
                    case 5: return 1;
                    case 6: return 5;
                }
            }
            case 4: {
                switch (b) {
                    case 1: return 5;
                    case 2: return 1;
                    case 5: return 6;
                    case 6: return 2;
                }
            }
            case 5: {
                switch (b) {
                    case 1: return 3;
                    case 3: return 6;
                    case 4: return 1;
                    case 6: return 4;
                }
            }
            case 6: {
                switch (b) {
                    case 2: return 4;
                    case 3: return 2;
                    case 4: return 5;
                    case 5: return 3;
                }
            }
        }
        return 0;
    }
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;cin >> n;
    int tmp = 0;
    if (n%1000==0){
        tmp = n/1000;
    }else{
        tmp = n/1000+1;
    }
    cout << 1000*tmp-n << endl;
    return 0;
}

Measured memory_bytes: 3664
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextLong()
    println((1 + (n-1)) * (n-1) / 2)
}

fun next() = readLine()!!
fun nextLong() = next().toLong()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33728
#include <cstdio>
#include <algorithm>
int n, a[105], b[105], sum;
int main(){
	scanf("%d", &n);
	for (register int i = 1; i < n; ++i) scanf("%d", b + i);
	sum += a[1] = b[1], sum += a[n] = b[n - 1];
	for (register int i = 2; i < n; ++i) a[i] = std :: min(b[i - 1], b[i]), sum += a[i];
	printf("%d\n", sum);
}

Measured memory_bytes: 128
// D.cpp
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAX_N = 20, INF = 0x3f3f3f3f3f3f3f3f;

int n;
ll ai[MAX_N];

ll solve(int l, int r, ll cL, ll cR)
{
    if (l + 1 > r - 1)
        return 0;
    ll ret = INF;
    for (int i = l + 1; i <= r - 1; i++)
        ret = min(ret, solve(l, i, cL + cR, cR) + solve(i, r, cL, cL + cR) + 1LL * (cL + cR) * ai[i]);
    return ret;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &ai[i]);
    printf("%lld\n", solve(1, n, 1, 1) + ai[1] + ai[n]);
    return 0;
}

Measured memory_bytes: 3724
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

class BookIndex
{
   private SortedDictionary<string, List<int>> bookIndexList = new SortedDictionary<string, List<int>>();

   public void Add(string word, int page)
   {
      if (!bookIndexList.ContainsKey(word))
      {
         bookIndexList.Add(word, new List<int>());
      }

      bookIndexList[word].Add(page);
   }

   public override string ToString()
   {
      var stringbuilder = new StringBuilder();

      foreach (var word in bookIndexList.Keys)
      {
         stringbuilder.AppendLine(word);

         bookIndexList[word].Sort();
         bookIndexList[word].Aggregate(stringbuilder, (sb, page) => sb.AppendFormat("{0} ", page));
         stringbuilder.Remove(stringbuilder.Length - 1, 1);
         stringbuilder.AppendLine();
      }

      return stringbuilder.ToString();
   }
}

class MainClass
{
   static void Main(string[] args)
   {
      var bookIndex = new BookIndex();

      while (true)
      {
         string line = Console.ReadLine();
         if (line == null) { break; }

         string[] datas = line.Split(' ');
         string word = datas[0];
         int page = int.Parse(datas[1]);

         bookIndex.Add(word, page);
      }

      Console.Write(bookIndex.ToString());
   }
}


Measured memory_bytes: 11524
#include <stdio.h>

int main(void){
	while(1){
		int n, i, ans=0; 
		int count=0;//１個以下しかない商品の種類の数
		int a[10000];
		
		scanf(" %d", &n);
		if(n==0) break;
		for(i=0; i<n; i++) {
			scanf(" %d", &a[i]);
			if(a[i] <=1) count++;
		}
		
		if(count == n) {
			printf("NA\n");
			continue;
		}
		
		for(i=0; i<n; i++) { //１個以下のものを全て出し尽くす
			if(a[i] <=1) {
				ans += a[i];
				a[i] = 0;
			}
		}
		
		ans += n-count+1;

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

	return 0;
}

Measured memory_bytes: 652
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int NN, AA, BB;

  std::cin >> NN>>AA>>BB;

  std::cout << min(AA, BB) << " " << max(-NN + AA + BB, 0) ;


  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

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





























































































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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const ull mod = 1e9 + 7;

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A,B,C;	cin>>A>>B>>C;
	if(A==B&&A==C)	No();
	else if(A==B||B==C||C==A) Yes();
	else	No();

    return 0;
}




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

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 1e3 + 15;
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1);
const double E = 2.718281828459045;
const int BLOCK = 2000;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod(x, m) ((x) % m + (x < 0 ? m: 0))

inline void IO() {
#ifdef buyolitsez
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}


template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}


inline void solve() {
    vector <int> a(3);
    cin >> a;
    swap(a[0], a[1]);
    swap(a[0], a[2]);
    cout << a;
}

signed main() {
    IO();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])


Measured memory_bytes: 51800