akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] a = new int[3][3];
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                a[i][j]=sc.nextInt();
            }
        }
        boolean[][] b = new boolean[3][3];
        int n = sc.nextInt();
        for (int i=0;i<n;i++){
            int l = sc.nextInt();
            for (int j=0;j<3;j++){
                for (int k=0;k<3;k++){
                    if (a[j][k]==l)b[j][k]=true;
                }
            }
        }
        boolean bool = false;
        for (int i=0;i<3;i++) {
            if (b[i][0]&&b[i][1]&&b[i][2])bool=true;
            if (b[0][i]&&b[1][i]&&b[2][i])bool=true;
        }
        if (b[0][0]&&b[1][1]&&b[2][2])bool=true;
        if (b[0][2]&&b[1][1]&&b[2][0])bool=true;
        if (bool)System.out.println("Yes");
        else System.out.println("No");
    }
    static long factorial(long num){
        if (num<2)return 1;
        else return num*factorial(num-1);
    }
    static int arraySum(int[] array){
        int ans = 0;
        for (int value : array) ans += value;
        return ans;
    }
    static long combination(long a, long b){
        long data = 1;
        for (int i=0;i<b;i++){
            data*=a-i;
        }
        return data/factorial(b);
    }
    static double log(double base,double antilogarithm){
        return Math.log(antilogarithm)/Math.log(base);
    }

    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
    static HashMap<Long,Long> factorization(long num){
        HashMap<Long,Long> hash = new HashMap<>();
        long n = num;
        long count = 2;
        while (n>1){
            while (n%count==0){
                n/=count;
                if (hash.containsKey(count))hash.put(count,hash.get(count)+1);
                else hash.put(count,1L);
            }
            count++;
        }
        return hash;
    }

}


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

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

  int temp = pow(100, D);
  if (N <= 99) {
    cout << temp * N << endl;
  } else {
    cout << temp * 101 << endl;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int n[200];
ll dp[200][201];
ll C[201][201];
vector<int> G[200];
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
void dfs(int v){
	for(int u:G[v]) dfs(u);
	ll tmp[201][201]={};
	tmp[0][0]=1;
	int sum=0;
	rep(i,G[v].size()){
		int u=G[v][i];
		rep(j,sum+1){
			rep1(k,n[u]){
				for(int nj=max(j,k);nj<=j+k;nj++){
					add(tmp[i+1][nj],tmp[i][j]*dp[u][k]%mod*C[j][j+k-nj]%mod*C[nj][j]);
				}
			}
		}
		sum+=n[u];
	}
	n[v]=sum+1;
	rep(j,n[v]) dp[v][j+1]=tmp[G[v].size()][j];
}
int indeg[200];
int main(){
	rep(i,201){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	int N;
	cin>>N;
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		G[a].pb(b);
		indeg[b]++;
	}
	int s=-1;
	rep(i,N) if(indeg[i]==0) s=i;
	dfs(s);
	ll ans=0;
	rep(i,N+1) add(ans,dp[s][i]);
	cout<<ans<<endl;
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin>>N;
  int A[N+2];
  memset(A,0,sizeof(A));
  int total=0;
  for (int i=1; i<=N; i++) {
    cin>>A[i];
    total+=abs(A[i]-A[i-1]);
  }
  total+=abs(A[0]-A[N]);
  for (int i=1; i<=N; i++) {
    cout<<total-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])<<endl;
  }
  return 0;
}


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

long long f(long long a[],long long x)
{
    if(x==a[x]);
    else a[x]=f(a,a[x]);
    return a[x];
}
long long a[200010];
long long b[200010];
long long c[200010];
long long d[200010];
int e[200010];
int main()
{

    long long n,m,k;
    long long x,y,i;
    scanf("%lld%lld%lld",&n,&m,&k);
    for(i=1; i<=n; i++)
    {
        a[i]=i;
        b[i]=i;
    }
    while(m--)
    {
        scanf("%lld%lld",&x,&y);
        x=f(a,x);
        y=f(a,y);
        a[x]=y;
    }
    while(k--)
    {
        scanf("%lld%lld",&x,&y);
        x=f(b,x);
        y=f(b,y);
        b[x]=y;
    }
    for(i=1; i<=n; i++)
    {
        c[i]=f(a,i)+(n+1)*f(b,i);
        d[i]=c[i];
    }
    sort(d+1,d+n+1);
    memset(e,0,sizeof(e));
    for(i=1; i<=n; i++)
    {
        y=lower_bound(d+1,d+n+1,c[i])-d;
        e[y]++;
    }
    for(i=1; i<=n; i++)
    {
        y=lower_bound(d+1,d+n+1,c[i])-d;
        if(i==n)printf("%d\n",e[y]);
        else printf("%d ",e[y]);
    }
    return 0;
}


Measured memory_bytes: 7808
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string S, T;
    in2(S, T);

    int count = 0;

    rep(i, S.size())
    {
        if (S[i] != T[i]) count++;
    }

    outl(count);
    return 0;
}

Measured memory_bytes: 3716
from itertools import permutations as p

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
a=0
b=0
for i,value in enumerate(sorted(list(p(P,N)))):
    if list(value)==P:
        a=i
    if list(value)==Q:
        b=i
print(abs(a-b))

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

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count)


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

typedef long long ll;
const ll mod = 1000*1000*1000+7;

ll po(ll x, ll n) {
    ll ret = 1;
    while(n) {
        if(n & 1) ret = ret * x % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ret;
}
ll modInv(ll x) { return po(x, mod - 2); }

int N;
vector<int> arr;
vector<ll> fact, invf;

ll comb(int n, int k) {
    return fact[n] * invf[k] % mod * invf[n - k] % mod;
}

vector<int> chk;
int pos1, pos2;

int main() {
    scanf("%d", &N);
    arr.resize(N + 1);
    chk = vector<int>(N + 1, -1);
    for(int i = 0; i < N + 1; i++) {
        scanf("%d", &arr[i]);

        if(chk[ arr[i] ] != -1) {
            pos1 = chk[ arr[i] ];
            pos2 = i;
        }
        else chk[ arr[i] ] = i;
    }

    fact.resize(100002);
    fact[0] = 1;
    for(int i = 1; i < 100002; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
    invf.resize(100002);
    for(int i = 0; i < 100002; i++) {
        invf[i] = modInv(fact[i]);
    }

    for(int i = 1; i <= N + 1; i++) {
        ll tmp = comb(N + 1, i);
        if(N + 1 - pos2 + pos1 >= i) {
            tmp -= comb(N + 1 - pos2 + pos1 - 1, i - 1);
            tmp = (tmp % mod + mod) % mod;
        }
        printf("%lld\n", tmp);
    }
}


Measured memory_bytes: 3584
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(1+2+3-A-B);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			if (N < 105) {
				System.out.print(0);
				return;
			}
			int sum = 1;
			for (int i = 107; i <= N; i += 2) {
				int yakusuu = 2;
				for (int j = 3; j < i; j += 2) {
					if (i % j == 0)
						yakusuu++;
					if (yakusuu > 8)
						break;
				}
				if (yakusuu == 8)
					sum++;
			}
			System.out.print(sum);
		}
	}
}


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

//定数
const int MAX_M=10;
//入力
int N;
int balls[MAX_M];

bool dfs(int i, int A, int B){
    if (i == 10){
        return true;
    }

    int value = balls[i];

    if (A >= value && B >= value){
        return false;
    }else if (A < value){
        return dfs(i+1, value, B);
    }else if (B < value){
        return dfs(i+1, A, value);
    }
}

string solve(){
    if (dfs(0, 0, 0)) return (string)"YES";
    else return (string)"NO"; 
}

int main(){
    queue<string> res;
    cin >> N;
    for (int i=0; i<N; i++){
        for (int j=0; j<10; j++){
            cin >> balls[j];
        }
        res.push(solve());
    }

    while (res.size()){
        cout << res.front() << endl;
        res.pop();
    }
    
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int ans;
    cin >> s;
    while(s.length() != 1){
        s.pop_back();
        ans = s.length();
        if(s.substr(0,s.length()/2) == s.substr(s.length()/2)) break;
    }
    cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	ll n, m;
	cin >> n >> m;
	if (n == 1 && m == 1) {
		cout << 1 << endl;
	} else if (n == 1) {
		cout << m - 2 << endl;
	} else if (m == 1) {
		cout << n - 2 << endl;
	} else {
		cout << (m - 2) * (n - 2) << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int A, B = 0;
	cin >> A >> B;
	int count = 0;
	while (1) {
		if (count >= 10 * B && count >= (A / 0.08)) {
			break;
		}
		count++;
	}
	if (count >= (10 * B + 10) || count >= ((A + 1) / 0.08)) {
		cout << -1 << endl;
	}
	else {
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        char s[] = sc.next().toCharArray();
        char t[] = sc.next().toCharArray();
        int n = s.length;

        for (int i = 0; i < n; i++) {
            if (s[0] == t[i]) {
                boolean isOk = true;
                for (int j = 0; j < n; j++) {
                    if (s[j] != t[(i + j) % n]) {
                        isOk = false;
                        break;
                    }
                }

                if (isOk) {
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int judge(int n){
    int sum=0;
    while(n>0){
        sum += n % 10;
        n /= 10;
    }
    return sum; 
}
int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int ans = 0;
  for(int i=1;i<=N;i++){
      int sum;
      sum = judge(i);
      if (sum >= A && sum <= B){
          ans += i;
      }
  }
  cout << ans << endl;
}

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

bool isSquare(int n) {
    for (int i = 1; i * i <= n; ++i) {
        if (i * i == n) return true;
    }
    return false;
}

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> points(n, vector<int>(d));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> points[i][j];
        }
    }
    
    auto dist = [&](int a, int b) {
        int ans = 0;
        for (int i = 0; i < d; ++i) {
            ans += (points[a][i] - points[b][i]) * (points[a][i] - points[b][i]);
        }
        return ans;
    };
    
    int ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (isSquare(dist(i, j))) ans++;
        }
    }
    cout << ans << endl;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  ll acc = 0;
  ll ans = LLONG_MAX;
  for (ll i = 0; i < N-1; i++) {
    acc += A.at(i);
    ll y = sum - acc;
    ans = min(ans, abs(acc - y));
  }
  cout << ans << endl;

  return 0;
}



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

int main() {
    int tmp=0, ans=0, N;
    string S;
    bool left=false, right=false;
    
    cin >> N;
    cin >> S;
    for(int i=0; i<S.size(); i++){
	for(int j='a'; j<='z'; j++){
	    for(int k=0; k<=i; k++){
		if(S[k]==j)
		    left=true;
	    }
	    for(int k=i+1; k<S.size(); k++){
		if(S[k]==j)
		    right=true;
	    }
	    if(left && right)
		tmp++;
	    left=false;
	    right=false;
	}
	ans = max(ans, tmp);
	tmp =0;
    }
    cout << ans<< endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int t = n % 10;
		int k = n / 100;
		if(k == t)
			printf("Yes\n");
		else
			printf("No\n");}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
template <typename T>
bool isPrime(T n){
  
  for(T i = 2; n >= i*i; i++){
    if(!(n%i)){return false;}
  }
  return true;
}
int main(){
    int n;cin>>n;
    int ans  = 0;
    for(int i = 0; n > i; i++){
        int a;cin>>a;
        if(isPrime(a))ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3096
n,m = map(int,input().split())
s = input()

now = n
ans_rev = []
while(now != 0):
    for i in range( max(0,now-m),now+1):
        if(i == now):
            print(-1)
            exit()
        if(s[i] == '1'):
            continue

        ans_rev.append(now - i)
        now = i
        break

print(' '.join(map(str, ans_rev[::-1])))

Measured memory_bytes: 50740
n, m = gets.chomp.split.map(&:to_i)

js = []
m.times do
  js.push gets.chomp.split.map(&:to_i)
end

ng = true
0.upto(999) do |x|
  f = true
  xs = x.to_s
  next if xs.size != n

  js.each do |s, c|
    if xs.size < s
      f = false
      break
    end
    if xs[s-1] != c.to_s
      f = false
      break
    end
  end

  if f
    ng = false
    puts x
    break
  end
end

if ng
  puts -1
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main(){
  lli n;
  cin >> n;
  
  vector<lli> a(5);
  for(int i = 0; i < 5; i++)
    cin >> a[i];
  
  lli min_a = *min_element(a.begin(), a.end());
  if(n % min_a == 0)
    cout << 4 + n / min_a << endl;
  else
    cout << 5 + n / min_a << endl;
}

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

typedef long long ll;

int H, W;

void load() {
  scanf("%d%d", &H, &W);
}

ll f(ll a, ll b, ll c) {
  return max(max(a, b), c) - min(min(a, b), c);
}

ll solve(int N, int M) {
  ll ans = (ll)1e18;
  for (int i = 1; i < M; i++) {
    ll a = (ll)N * (M - i);
    ll b = (ll)N / 2 * i;
    ll c = (ll)(N + 1) / 2 * i;
    ans = min(ans, f(a, b, c));
    if (i == 1)
      continue;
    b = (ll)i / 2 * N;
    c = (ll)(i + 1) / 2 * N;
    ans = min(ans, f(a, b, c));
  }
  return ans;
}

int main() {
  load();
  printf("%lld\n", min(solve(H, W), solve(W, H)));
  return 0;
}

Measured memory_bytes: 128
N, Y = map(int, input().split())

found = False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            ex_x, ex_y, ex_z = i, j, N-i-j
            found = True
            break
            
if not found:
    print(-1, -1, -1)
else:
    print(ex_x, ex_y, ex_z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w;
  cin >> h >> w;
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int ans[h][w];
  int cur = 0;

  const auto d = [&]() {
    if (a[cur] <= 0) cur++;
    a[cur]--;
    return cur+1;
  };

  REP(i,h) {
    if (i%2) {
      for (int j = w-1; j >= 0; j--) {
        ans[i][j] = d();
      }
    } else {
      REP(j,w) {
        ans[i][j] = d();
      }
    }
  }

  REP(i,h) {
    REP(j,w) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int ans = a / 0.08;
  int temp;
  bool flag = false;
  while(ans * 0.08 < a + 1){
    temp = ans * 0.1;
    if(temp == b){
      temp = ans * 0.08;
      if(temp == a){
        cout << ans << endl;
        flag = true;
        break;
      }
    }
    ans++;
  }
  if(!flag) cout << "-1" << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int r[6][6] = {
	{-1, 2, 4, 1, 3,-1},
	{ 3,-1, 0, 5,-1, 2},
	{ 1, 5,-1,-1, 0, 4},
	{ 4, 0,-1,-1, 5, 1},
	{ 2,-1, 5, 0,-1, 3},
	{-1, 3, 1, 4, 2,-1}
};

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

	int d[6];
	cin>>d[0]>>d[1]>>d[2]>>d[3]>>d[4]>>d[5];
	int n, t, f;
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>t>>f;
		for(int j=0; j<6; j++) {
			if(t==d[j]) {
				t=j;
				break;
			}
		}
		for(int j=0; j<6; j++) {
			if(f==d[j]) {
				f=j;
				break;
			}
		}
		cout<<d[r[t][f]]<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        a[i]=t-1;
    }
    int l=0;
    int i;
    for(i=0;i<n;i++){
        l=a[l];
        if(l==1)break;
    }
    if(l!=1){
        cout << "-1" << endl;
        return 0;
    }
    cout << i+1 << endl;

    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException{


		// 読み込み
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] temp;

		line=br.readLine();
		temp=line.split(" ");

		String s = temp[0]+temp[1]+temp[2];
		int i = Integer.valueOf(s);

		if (i%4==0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 21460
#include <deque>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  long long K;
  cin >> K;
  deque<long long> q;
  for (int i = 1; i <= 9; i++)
    q.push_back(i);
  while (1) {
    auto x = q.front();
    q.pop_front();
    K--;
    if (K == 0) {
      cout << x << endl;
      return 0;
    }

    auto l = x % 10;
    if (l != 0)
      q.push_back(x * 10 + (l - 1));
    q.push_back(x * 10 + l);
    if (l != 9)
      q.push_back(x * 10 + (l + 1));
  }
  return 0;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


ll substep(ll stairs);

int main()
{
    string S;
    cin >> S;
    int y,m,d;
    y = stoi(S.substr(0,4));
    m = stoi(S.substr(5,2));
    d = stoi(S.substr(8,2));
    
    int time = y*10000 + m*100 + d;
    
    if(time <= 20190430){
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 256
# include <cstdio>
# include <cmath>

int main()
{
    int d, n;
    scanf("%d%d", &d, &n);
    if (n != 100) {
        printf("%d\n", (int)(std::pow(100, d) * n));
    } else {
        printf("%d\n", (int)(std::pow(100, d) * (n+1)));
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include "sstream"
#define EPS 1e-9
using namespace std;
const int N=1e5,INF=0x3f3f3f3f;
typedef long long ll;
int arr[N],dp[N],n;
int solve(int idx){
    if(idx==n-2)
        return abs(arr[idx]-arr[idx+1]);
    if(idx==n-1)
        return 0;
    int &ret=dp[idx],c1,c2;
    if(ret!=-1)
        return ret;
        c1=abs(arr[idx]-arr[idx+1])+solve(idx+1);
        c2=abs(arr[idx]-arr[idx+2])+solve(idx+2);
    return ret=min(c1,c2);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
 for(int i=0;i<n;i++)
     cin>>arr[i];
 memset(dp,-1, sizeof(dp));
 cout<<solve(0);
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

string str;
ll n,ans,place;

ll check(int l, int r, vector<ll> &v,vector<char> op){
    ll ret = 0;
    ll tmp = 0;
     
    for(int i = l;i <= r;i++) {
        if(i == l){
            tmp = v[i];
        }
        else {
            if(op[i-1] == '+'){
                ret += tmp;
                tmp = v[i];
            }
            else{
                tmp *= v[i];
            }
        }
        if(ret + tmp > INF)return INF + 1;
    }
    return ret + tmp;
}

ll dfs(){
	place++;
	vector<ll> v;
	vector<char> op;
	vector<ll> mul;
	vector<ll> it;
	vector<ll> sum(1,0);
	while(1){
		if(str[place] == '('){
			ll tmp = dfs();
			if(tmp == 1 && op.size() > 0 && op.back() == '*' && v.back() == 1){
				op.pop_back();
				mul.back()++;
			}
			else{
				v.EB(tmp);
				it.EB(sum.size()-1);
				mul.EB(1);
			}
		}
		if(isdigit(str[place])){
			if(str[place] == '1' && op.size() > 0 && op.back() == '*' && v.back() == 1){
				op.pop_back();
				mul.back()++;
			}
			else{
				v.EB(str[place] - '0');
				it.EB(sum.size()-1);
				mul.EB(1);
			}
		}
		else if(str[place] == '*'){
			op.EB(str[place]);
		}
		else if(str[place] == '+'){
			op.EB(str[place]);
			sum.EB(0);
		}
		else {
			break;
		}
		place++;
	}
	place++;
	int r = 1;
	ll now = v[0];
	sum[0] = v[0];
	//cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
	//SHOW1d(v,v.size());
	//SHOW1d(op,op.size());
	//SHOW1d(mul,mul.size());
	//cout << "now " << now << endl;

	REP(i,v.size()){
		if(i > r){
			now = v[i];
			sum[it[i]] = v[i];
			r = i + 1;
		}
		//cout << "now " << now << endl;
		while(now < n && r < v.size() && now + max(sum[it[r]] * v[r], v[r]) - sum[it[r]] <= n){
			now -= sum[it[r]];
			sum[it[r]] = max(sum[it[r]] * v[r], v[r]);
			now += sum[it[r]];
			r++;
			if(now == n)break;
		}
		//cout << " " << i << " " << sum[it[i]] << " " << r << " " << sum[it[r-1]] << " " << now << endl;
		//SHOW1d(sum,sum.size());
		if(now == n){
			if(n == 1)ans += max(mul[i] * (mul[i] + 1) / 2,(ll)1);
			else if(it[i] == it[r - 1])ans += mul[i];
			else ans += mul[i] * mul[r-1];
			if(r < v.size() && op[r-1] == '*' && v[r] == 1)ans += mul[i] * mul[r];
		}
		now -= sum[it[i]];
		if(it[i] != it[i+1] || i + 1 == r)sum[it[i]] = 0;
		else sum[it[i]] /= v[i];
		now += sum[it[i]];
		//cout << "ans " << ans << endl;
	}
	return check(0,v.size() - 1,v,op);
}

int main(){
	
	while(cin >> n,n){
		ans = 0;
		place = 0;
		cin >> str;
		str = "(" + str + ")";
		dfs();
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 50804
#include <bits/stdc++.h>
#define MAX 105
using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    int n, m;

    cin>>n>>m;

    vector<int> div;

    if(n == 1){
        cout<<m<<endl;
        return 0;
    }
    for(int i = 1; i * i <= m; i++){
        if(m % i == 0){
            div.push_back(i);
            if((m / i) != i)
                div.push_back(m/i);
        }
    }

    sort(div.begin(), div.end());
    reverse(div.begin(), div.end());

    for(int i = 0; i < div.size(); i++){
        ll temp = (n - 1) * 1LL * div[i];
        if(temp >= m)
            continue;
        if((m - temp) % div[i] == 0){
            cout<<div[i]<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
public class Main {

	private final java.util.Scanner sc;
	private final java.io.PrintStream out;
	
	public Main(java.io.InputStream in, java.io.PrintStream out) {
		this.sc = new java.util.Scanner(in);
		this.out = out;
	}
	
	public void run() {
		final int a = sc.nextInt();
		final int b = sc.nextInt();
		final int c = sc.nextInt();
		
		final boolean[] d = new boolean[60];
		int rval = 0;
		for (int s = 0;;) {
			if (d[s]) {
				rval = -1;
				break ;
			}
			d[s] = true;
			if (s <= c && c <= s + a) {
				rval += c;
				break ;
			}
			s += a;
			if (60 <= s) {
				rval += 60;
				s -= 60;
				if (c <= s) {
					rval += c;
					break ;
				}
			}
			s += b;
			if (60 <= s) {
				s -= 60;
				rval += 60;
			}
		}
		out.println(rval);
	}
	
	public static void main(String[] args) {
		(new Main(System.in, System.out)).run();
	}

}

Measured memory_bytes: 26252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=200005,Inf=1e15;
inline ll _R(){
	ll d=0;bool b=1;char t=getchar();
	while(t<'0'||t>'9'){if(t=='-')b=0;t=getchar();}
	for(;t>='0'&&t<='9';t=getchar())d=(d<<3)+(d<<1)+t-'0';
	return b?d:-d;
}
ll n,sum[N],Ans=Inf;
int main(){
	n=_R();
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+_R();
	for(int i=1;i<n;i++)Ans=min(Ans,abs(sum[n]-(sum[i]<<1)));
	cout<<Ans;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(int argc, char const *argv[]) {
    long long int n;
    long long int sum=0;
    cin >> n;
    vector<int> v;
    while(n){
        v.push_back(n%10);
        n /= 10;
    }
    reverse(v.begin(),v.end());
    for(int bit=0;bit<1<<(v.size()-1);bit++){
        //cout << bitset<2>(bit) << endl;
        long long int tmp=v[0];
        for(int i=0;i<(v.size()-1);i++){
            if(bit & 1<<i){
                sum +=  tmp;
                tmp  =  0;
                tmp += v[i+1];
            }else{
                tmp *= 10;
                tmp += v[i+1];
            }
        }
        sum += tmp;

    }
    cout << sum << endl;
    // for(int i=0;i<v.size();i++){
    //     cout << v[i] << " ";
    // }
    // cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    map<ll, ll> a;
    rep(i, 0, n){
        ll tmp;
        cin >> tmp;
        a[tmp]++;
    }

    ll sum = 0;
    ll d = 0;
    fore(t, a){
        if(t.second > 1){
            d += t.second - 1;
        }
        sum++;
    }
    if(d % 2 == 0){
        cout << sum << endl;
    }else{
        cout << sum - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 6528
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    int a=read(),b=read(),c=read(),k=read();
    int tot=0;
    while(b<=a) b<<=1,tot++;
    while(c<=b) c<<=1,tot++;
    puts(tot<=k?"Yes":"No");

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int h,w,n;
  cin>>h>>w>>n;
  vector<int> v;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    for(int j=0;j<a[i];j++)
      v.push_back(i+1);
    }
  vector<int> c[h];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      c[i].push_back(v[i*w+j]);
  for(int i=0;2*i<h;i++)
    reverse(c[2*i].begin(),c[2*i].end());
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) 
      cout<<c[i][j]<<" ";
    cout<<endl;
    }
  return 0;
  }


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

int main()
{
	string s, t;
	vector<int> a(26, -1), b(26, -1);
	bool f = 1;

	cin >> s >> t;

	for (unsigned int i = 0; i < s.size(); i++) {
		int j = s[i] - 'a';
		int k = t[i] - 'a';

		if (a[j] < 0)
			a[j] = k;
		else if (a[j] != k) {
			f = 0;
			break;
		}

		if (b[k] < 0)
			b[k] = j;
		else if (b[k] != j) {
			f = 0;
			break;
		}
	}

	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 776
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

using LL = long long;


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

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

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

int main(){
    int n, u, k, v;
    cin >> n;
    bool a[n + 1][n + 1] = {0};
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v;
            a[u][v] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << a[i][j];
            if(j != n)
                cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
a,b=map(int,input().split())
if a<0:
    if b>=0:
        print("Zero")
    else:
        num=int(b-a+1) #偶数なら正
        print("Positive" if num%2==0 else "Negative")
elif a==0:
    print("Zero")
else:
    print("Positive")

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type bit []int

func (p *bit) init(n int) {
	*p = make([]int, n+1)
}
func (p bit) sum(i int) int {
	if i == 0 {
		return 0
	}
	return p[i] + p.sum(i-(i&-i))
}
func (p bit) add(i, x int) {
	if i >= len(p) {
		return
	}
	p[i] += x
	p.add(i+(i&-i), x)
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt() - K
	}

	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + a[i]
	}

	b := make([]int, N+1)
	for i := 1; i <= N; i++ {
		b[i] = s[i]
	}
	sort.Ints(b)
	bm := make(map[int]int)
	for i := 0; i <= N; i++ {
		bm[b[i]] = i + 1
	}
	var tree bit
	tree.init(N + 2)
	for i := 0; i < N+1; i++ {
		tree.add(bm[b[i]], 1)
	}
	tree.add(bm[0], -1)

	ans := 0
	for i := 1; i <= N; i++ {
		pos := lowerBound(b, s[i-1])
		ans += tree.sum(N+1) - tree.sum(pos)
		tree.add(bm[s[i]], -1)
	}
	out(ans)
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 1000000000;
int A[MAXN], dp[MAXN][3];
int DP(int pos, int used)
{
	if(used > A[pos])
		return -INF;
	if(pos == 0)
		return 0;
	if(dp[pos][used] != -1)
		return dp[pos][used];
	int rem = A[pos] - used;
	int ret = -INF;
	if(rem == 2)
		ret = max(ret, 1 + DP(pos-1, 0));
	for (int i = 0; i <= rem; ++i)
		ret = max(ret, i + DP(pos-1, i));
	dp[pos][used] = ret;
	return dp[pos][used];
}
int main()
{
	int n;
	scanf("%d", &n);
	long long int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &A[i]);
		if(A[i])
		{
			if(A[i]%2)
			{
				ans+=(A[i]/2);
				A[i] = 1;
			}
			else
			{
				ans+=((A[i]/2)-1);
				A[i] = 2;
			}
		}
	}
	memset(dp, -1, sizeof dp);
	ans+=DP(n,0);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 0;

  for(int num = a; num <= b; num++){
    if (num % 10 == num / 10000 && (num / 10) % 10 == (num / 1000) % 10){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
var
	ans,n,a,b,mo:int64;
function p(a,b:int64):int64;
begin
	if b=0 then p:=1 else if b mod 2=0 then p:=p(a*a mod mo,b div 2) else p:=p(a,b-1)*a mod mo;
end;
function C(k:int64):int64;
var x,y:int64;i:Longint;
begin
	x:=1;
	y:=1;
	for i:=1 to k do begin
		x:=x*(n-i+1)mod mo;
		y:=y*i mod mo;
	end;
	C:=x*p(y,mo-2)mod mo;
end;
begin
	read(n,a,b);
	mo:=1000000007;
	ans:=p(2,n)-1-c(a)-c(b);
	ans:=(ans mod mo+mo)mod mo;
	writeln(ans);
end.


Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, L int
	fmt.Scan(&N, &L)

	a := make([]string, N)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Strings(a)
	for _, x := range a {
		fmt.Printf("%s", x)
	}
	fmt.Printf("\n")
}


Measured memory_bytes: 512
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w, a, b = sc.nextInt()
  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  def pow(a: Long, n: Int, res: Long = 1): Long = {
    if (n == 0) {
      res
    } else if ((n&1) == 0) {
      pow(times(a,a), n >> 1, res)
    } else {
      pow(times(a,a), n >> 1, times(res,a))
    }
  }

  def inv(a: Long): Long = pow(a, mod-2)

  def initFactTable(n: Int): Array[Long] = {
    (1 to n).scanLeft(1L)(times(_,_)).toArray
  }

  val fact = initFactTable(h + w)

  def initInvFactTable(n: Int): Array[Long] = {
    (1 to n).scanRight(inv(fact(n)))(times(_,_)).toArray
  }

  val invFact = initInvFactTable(h + w)

  def comb(n: Int, k: Int): Long = {
    times(times(fact(n), invFact(k)), invFact(n-k))
  }

  val ans = (0 until (h - a).min(w - b)).map( i =>
    times(comb(b + h - a - 1, b + i), comb(a + w - b - 1, a + i))
  ).reduceLeft(plus)

  println(ans)
}


Measured memory_bytes: 73040
#include <bits/stdc++.h>
using namespace std;
int main(){
int D;cin>>D;
if(D==25){cout<<"Christmas"<<endl;
}else if(D==24){cout<<"Christmas Eve"<<endl;
}else if(D==23){cout<<"Christmas Eve Eve"<<endl;
}else if(D==22){cout<<"Christmas Eve Eve Eve"<<endl;
}
}

Measured memory_bytes: 256
def cantwaitforholiday(s):

    days = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}
    return days[s]

def main():
    s = str(input())
    print(cantwaitforholiday(s))

if __name__ == '__main__':
    main()

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

typedef long long ll;

int main()
{
    ll i,j;
    
    int n;
    cin >> n;
    vector<int> temp_x(n);
    vector<int> temp_y(n);
    for(i = 0;i < n;++i){
        cin >> temp_x.at(i) >> temp_y.at(i);
    }
    vector<int> v(8);
    for(i = 0;i < 8;++i){
        v.at(i) = i;
    }

    do{
        bool flag = true;
        for(i = 0;i < n;++i){
            if(v.at(temp_x.at(i)) != temp_y.at(i)){
                flag = false;
            }
        }
        if(!flag){
            continue;
        }
        vector<vector<int>> ban(8,vector<int>(8,0));
        for(i = 0;i < 8;++i){
            int zx = i;
            int zy = v.at(i);

            for(j = 1;j < 8;++j){
                if(zx-j < 0){
                    break;
                }else{
                    ban.at(zx-j).at(zy) = 1;
                }
            }
            for(j = 1;j < 8;++j){
                if(zx+j > 7){
                    break;
                }else{
                    ban.at(zx+j).at(zy) = 1;
                }
            }

            for(j = 1;j < 8;++j){
                if(zy-j < 0){
                    break;
                }else{
                    ban.at(zx).at(zy-j) = 1;
                }
            }
            for(j = 1;j < 8;++j){
                if(zy+j > 7){
                    break;
                }else{
                    ban.at(zx).at(zy+j) = 1;
                }
            }

            for(j = 1;j < 8;++j){
                if(zx-j < 0 || zy-j < 0){
                    break;
                }else{
                    ban.at(zx-j).at(zy-j) = 1;
                }
            }
            for(j = 1;j < 8;++j){
                if(zx+j > 7 || zy+j > 7){
                    break;
                }else{
                    ban.at(zx+j).at(zy+j) = 1;
                }
            }

            for(j = 1;j < 8;++j){
                if(zx-j < 0 || zy+j > 7){
                    break;
                }else{
                    ban.at(zx-j).at(zy+j) = 1;
                }
            }
            for(j = 1;j < 8;++j){
                if(zx+j > 7 || zy-j < 0){
                    break;
                }else{
                    ban.at(zx+j).at(zy-j) = 1;
                }
            }
        }

        for(i = 0;i < 8;++i){
            if(ban.at(i).at(v.at(i))){
                flag = false;
                break;
            }
        }

        if(flag){
            string first = "........";
            vector<string> ans(8,first);
            for(i = 0;i < 8;++i){
                ans.at(i).at(v.at(i)) = 'Q';
            }
            for(i = 0;i < 8;++i){
                cout << ans.at(i) << endl;
            }
            return 0;
        }
    }while(next_permutation(v.begin(),v.end()));

    return 0;
}


Measured memory_bytes: 3224
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


a, b = map(int, input().split())

a_divsrs = set(make_divisors(a))
b_divsrs = set(make_divisors(b))

# print("a_divsrs:", *a_divsrs)
# print("b_divsrs:", *b_divsrs)

comm_divsrs = sorted(a_divsrs & b_divsrs)

# print("comm_divsrs:", *comm_divsrs)

ans = []
for i in range(len(comm_divsrs)):
    if not (comm_divsrs[i] % 2 == 0 and comm_divsrs[i] != 2):
        ans.append(comm_divsrs[i])

# print("ans:", *ans)

final_ans = ans[0:2]
# ct = 0

"""
    ans[i] に対して、すべての ans[j] (j: range[1:i]) が gcd(ans[i], ans[j]) == 1
    ならば final_ans に追加。ひとつでも違えば追加しない
"""
for i in range(2, len(ans)):
    is_ok = True
    for j in range(1, i):
        if gcd(ans[i], ans[j]) != 1:
            is_ok = False
            break
    if is_ok:
        final_ans.append(ans[i])

# print("final_ans:", *final_ans)
print(len(final_ans))
# print(ct)


Measured memory_bytes: 5064
//cool
#include <iostream>
#include <fstream>
#include <set>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for(int i=a; i<b; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define clean(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pb push_back

ll n, a[100012];

ll main(){
	IOS;
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	cout << (a[n/2]-a[(n/2)-1]);
	return 0;
}
	


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

using namespace std;

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

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

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


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




vector<ll> s;

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

  int p;
  cin >> p;
  int n = pow(2,p);

  rep(i,n) {
    ll a;
    cin >> a;
    s.push_back(a);
  }

  priority_queue<ll> powerlist;
  
  queue<ll> nextgen;

  sort(s.begin(), s.end(), std::greater<int>() );

  int b = 0;


  if(s[0] == s[1]){cout << "No" << endl; return 0;}

  nextgen.push(p);
  bool flag = true;
  rep1(i,n-1){
    if(s[i] != b){
      b = s[i];
      while(!nextgen.empty()){
        powerlist.push(nextgen.front());
        nextgen.pop();
      }
    }
    if(powerlist.empty()){
      flag = false;
      break;
    }

    ll tmp = powerlist.top();
    powerlist.pop();
    if(tmp != 1){
      powerlist.push(tmp-1);
      nextgen.push(tmp-1);
    }
  }

  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }






  return 0;

}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(y==0)return x;
    return gcd(y,x%y);
}
ll LCM(ll a, ll b){
    return a/gcd(a,b)*b;
}

int main(void)
{
    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll> x(n+1);
    rep(i,0,n)cin>>x[i];
    ll ans=0;
    rep(i,0,n-1){
        ans+=min(abs(x[i+1]-x[i])*a,b);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long

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

    int a, b;
    cin >> a >> b;

    string c = to_string(a) + to_string(b);

    stringstream ss(c);
    int n = 0;
    ss >> n;

    for (int i = 1; i <= sqrt(n) ; i++){
        if (i*i == n){
        cout << "Yes" << endl;
        return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256