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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
int main(){
  int n,u,v,m;
  cin>>n>>u>>v>>m;
  int usa[2000]={};
  int neko[2000]={};
  map<int,pair<int,int> >hoge;
  map<int,pair<int,int> >hoge2;
  int uu=0,nn=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int a;cin>>a;
      hoge[a]=mp(i+1,j+1);
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int a;cin>>a;
      hoge2[a]=mp(i+1,j+1);
    }
  }
  bool hoho[2000]={};
  bool gege[2000]={};
  bool ho=false,ge=false;
  for(int i=0;i<m;i++){
    int a;cin>>a;
    if(ho||ge)continue;
    if(hoge[a].F!=0&&hoge[a].S!=0){
      usa[hoge[a].F]++;
      usa[hoge[a].S+510]++;
      if(usa[hoge[a].F]>=n&&!hoho[hoge[a].F]){
	if(n!=1)
	uu++;
	hoho[hoge[a].F]=true;
      }
      if(usa[hoge[a].S+510]>=n&&!hoho[hoge[a].S+510]){
	uu++;
	hoho[hoge[a].S+510]=true;
      }
      if(hoge[a].F==hoge[a].S){
	usa[1500]++;
      }
      if(usa[1500]>=n&&!hoho[1500]){
	if(n!=1)
	uu++;
	hoho[1500]=true;
      }
      if(hoge[a].F==abs(n-hoge[a].S+1))
	usa[1501]++;
      if(usa[1501]>=n&&!hoho[1501]){
	if(n!=1)
	uu++;
	hoho[1501]=true;
      }
    }
    if(hoge2[a].F!=0&&hoge2[a].S!=0){
      neko[hoge2[a].F]++;
      neko[hoge2[a].S+510]++;
      if(neko[hoge2[a].F]>=n&&!gege[hoge2[a].F]){
	nn++;
	gege[hoge2[a].F]=true;
      }
      if(neko[hoge2[a].S+510]>=n&&!gege[hoge2[a].S+510]){
	if(n!=1)
	nn++;
	gege[hoge2[a].S+510]=true;
      }
      if(hoge2[a].F==hoge2[a].S){
	neko[1500]++;
      }
      if(neko[1500]>=n&&!gege[1500]){
	gege[1500]=true;
	if(n!=1)
	nn++;
      }
      if(hoge2[a].F==abs(n-hoge2[a].S+1))
	neko[1501]++;
      if(neko[1501]>=n&&!gege[1501]){
	if(n!=1)
	  nn++;
	gege[1501]=true;
      }
    }
    // cout<<uu<<" "<<nn<<endl;
    if(uu>=u)ho=true;
    if(nn>=v)ge=true;
  }
  
  if(ho&&ge)cout<<"DRAW"<<endl;
  else if(ho)cout<<"USAGI"<<endl;
  else if(ge)cout<<"NEKO"<<endl;
  else
    cout<<"DRAW"<<endl;
  return 0;
}



Measured memory_bytes: 22500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  map<pair<int,string>,int>m;
  cin>>n;
  while(n--){
    string s;
    int p;
    cin>>s>>p;
    pair<int,string>pp=make_pair(s.size(),s);
    m[pp]+=p;
  }
  for(map<pair<int,string>,int>::iterator it=m.begin();it!=m.end();it++)
    cout<<(*it).first.second<<' '<<(*it).second<<endl;
}

Measured memory_bytes: 3196
#include <stdio.h>
int main(void)
{
	int a,b,i;
	int q,w,e,r,t,y=0;
	scanf("%d%d",&a,&b);
	for(i=a; i<=b; i++){
		q=i/10000; w=i/1000%10; e=i/100%10; r=i/10%10; t=i%10;
		if(q==t && w==r){
			y=y+1;
		}
	}
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine((p[0] + p[1] + 1) / 2);
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll gcd(ll a, ll b) {
    ll d = 1;
    if (b != 0) {
        d = gcd(b, a % b);
    } else {
        return a;
    }
    return d;
}

vector<ll> divisor(ll n) {
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) res.push_back(n / i);
        }
    }
    return res;
}
bool is_prime(ll n) {
    if (n == 1) return true;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0) return false;
    }
    return true; 
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    ll max;
    if ( a > b) {
        max = gcd(a, b);
    } else {
        max = gcd(b, a);
    }
    auto divs = divisor(max);
    ll res = 0;
    
    rep(i, divs.size()) {
        if (is_prime(divs[i])) res++;
    }
    cout << res << "\n";
    
}

Measured memory_bytes: 384
using System;
using System.Linq;

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] input = Console.ReadLine().Split(' ');

            long[] intAry = Array.ConvertAll(input, long.Parse);
            Console.WriteLine("{0} {1} {2}", intAry.Min(), intAry.Max(), intAry.Sum());
        }
    }
}

Measured memory_bytes: 10236
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) cout << (x) << endl;
#define outs(x) for(auto i : x) cout << i << " ";
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main() {
  int n;cin >> n;
  getchar();
  str line;getline(cin,line);
  int i0 = 0,i2 = 0,i4 = 0,t,t2;
  split_str(line,' '){
    t2 = 0;
    t = i_str(res);

    while(t % 2 == 0){
      t /= 2;
      t2++;
    }

    if(t2 == 0) i0++;
    else if(t2 == 1) i2++;
    else if(t2 >= 2) i4++;
  }

  if(i2) i0++;

  cout << (i0 <= i4 + 1 ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 2308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int M = max(max(A, B), C);
    int tmp = M;
    
    for (int i=0; i<K; i++) {
        M *= 2;
    }
    
    cout << M+A+B+C-tmp << endl;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

s = input()
left, right = [], []
for i in range(len(s)):
    if s[i] == 'L': left += [i]
    else: right += [i]
ans = [0]*len(s)
for i in range(len(s)):
    if s[i] == 'R':
        next = left[bisect_right(left, i)]
        if (next-i) % 2 == 0:
            ans[next] += 1
        else: ans[next-1] += 1
    if s[i] == 'L':
        next = right[bisect_left(right, i) - 1]
        if (i - next) % 2 == 0:
            ans[next] += 1
        else: ans[next+1] += 1
print(" ".join(str(k) for k in ans))

Measured memory_bytes: 14524
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

ll memo[100005][3];
ll h[100005][3];
int init(){
    for(int yi = 0; yi < 100005; yi++){
        for(int xi = 0; xi < 3; xi++){
            memo[yi][xi] = -1;
            h[yi][xi] = 0;
        }
    }
}
ll solve(ll day,ll last){
    if(memo[day][last] != -1){
        return memo[day][last];
    }
    switch (last){
        case 0:
            memo[day][last] = max(solve(day - 1,1) + h[day][0],solve(day - 1,2) + h[day][0]);
            break;
        case 1:
            memo[day][last] = max(solve(day - 1,0) + h[day][1],solve(day - 1,2) + h[day][1]);
            break;
        case 2:
            memo[day][last] = max(solve(day - 1,0) + h[day][2],solve(day - 1,1) + h[day][2]);
            break;
    }
    return memo[day][last];
}
int main() {
    ll N;
    cin >> N;
    init();
    for(int i = 0; i < N; i++){
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    }
    memo[0][0] = h[0][0];
    memo[0][1] = h[0][1];
    memo[0][2] = h[0][2];
    cout << max(solve(N - 1,0),max(solve(N - 1,1),solve(N - 1,2))) << endl;
}


Measured memory_bytes: 11136
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int dp[3001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N, S;
	scanf("%d %d", &N, &S);

	int A[3001] = {};
	rep(i, N) {
		int a;
		scanf("%d", &a);
		A[a]++;
	}

	ll k2 = modpow(2, mod - 2);
	dp[0] = modpow(2, N);
	int s = 0;
	ll kotae = 0;
	rep1(a, S) {
		rep(k, A[a]) {
			s = min(S - a, s + a);

			if (S >= a) kotae += dp[S - a];
			for (int j = s; j >= a; j--) {
				dp[j] = (dp[j] + dp[j - a] * k2) % mod;
			}
		}
	}

	printf("%lld\n", kotae % mod * k2 % mod);

	Would you please return 0;
}

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

list<P>E[1500];
int d[1500][1500];
list<int>pre[1500][1500];
bool b[1500];
int main() {
	int n, r; scanf("%d%d", &n, &r);
	rep(i, r) {
		int s, t, d; scanf("%d%d%d", &s, &t, &d); s--; t--;
		E[s].push_back(P(d, t));
		E[t].push_back(P(d, s));
	}
	priority_queue<P, vector<P>, greater<P>>que;
	memset(d, 0x3f, sizeof(d));
	rep(i, n) {
		d[i][i] = 0;
		que.push(P(0, i));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (p.first != d[i][p.second])continue;
			for (P v : E[p.second]) {
				if (d[i][v.second] == p.first + v.first)
					pre[i][v.second].push_back(p.second);
				if (d[i][v.second] > p.first + v.first) {
					pre[i][v.second].clear();
					pre[i][v.second].push_back(p.second);
					d[i][v.second] = p.first + v.first;
					que.push(P(d[i][v.second], v.second));
				}
			}
		}
	}
	int Max = 0;
	rep(i, n)rep(j, n)Max = max(Max, d[i][j]);
	rep(i, n)rep(j, n) {
		if (d[i][j] != Max)continue;
		queue<int>que;
		que.push(j);
		while (!que.empty()) {
			int d = que.front(); que.pop();
			b[d] = true;
			for (int j : pre[i][d])que.push(j);
		}
	}
	list<int>v;
	rep(i, n) {
		if (!b[i])v.push_back(i + 1);
	}
	printf("%d\n", v.size());
	for (int i : v)printf("%d\n", i);
}

Measured memory_bytes: 187856
import Data.List
import qualified Data.ByteString.Char8 as BC
import Data.Maybe

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: Int -> Int -> [Int] -> [Int]
solve _ _ [a] = []
solve curr total (a:as) = res : solve next total as
  where next = curr + a
        res = abs $ total - next * 2

main :: IO ()
main = do
  getLine
  as <- readIntsLine
  print . minimum $ solve 0 (sum as) as

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

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

string s;
cin >> s;
for(int i=0;i<(int)s.size();i++){
int kijun=(int)('A');
int temp=((int)s[i]+n)-kijun;

int kotae=temp%26;
cout << (char)(kijun+kotae);

}

//cout << "No";



}


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


ll X[200002];
ll L;
int N;


template <typename T>
class BIT {
public:
	vector<T> data;
	int n;
	BIT() {}
	BIT(int n_) {
		n = n_;
		data.assign(n, T(0));
	}
	// v[a] += w
	void add(int a, T w) {
		for (int x = a; x < n; x |= x + 1) data[x] += w;
	}
	// sum of v[i] for i in [0, a)
	T sum(int a) {
		T ret = 0;
		for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
			ret += data[x];
		}
		return ret;
	}
};


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

	BIT<ll> bit(N), bit_rev(N);
	for(int i=0;i<N;i++) {
		cin >> X[i];
		bit.add(i, X[i]);
		bit_rev.add(N - i - 1, L - X[i]);
	}

	if (N == 1) {
		cout << max(X[0], L - X[0]) << endl;
		return 0;
	}

	ll ans = 0;
	{
		// i = 0
		ans = max(ans, X[0] + 2 * (L - X[1]));
		// i = N - 1
		ans = max(ans, L - X[N - 1] + 2 * X[N - 2]);
	}

	// end i as left
	for (int i = 1; i < N - 1; i++) {
		int left_n = i;
		int right_n = N - i - 1;
		ll s;
		if (left_n >= right_n) {
			s = 2 * bit.sum(i) + 2 * bit_rev.sum(N - i - 1) + X[i];
			if (left_n > right_n) {
				s -= 2 * bit.sum(i - right_n);
			}
		}else {
			s = 2 * bit.sum(i) + 2 * bit_rev.sum(N - i - 1) + X[i];
			if (left_n + 1 < right_n) {
				s -= 2 * bit_rev.sum(N - i - 1 - (left_n + 1));
			}
		}
		ans = max(ans, s);
	}
	// end i as right
	for (int i = 1; i < N - 1; i++) {
		int left_n = i;
		int right_n = N - i - 1;
		ll s;
		if (left_n <= right_n) {
			s = 2 * bit.sum(i) + 2 * bit_rev.sum(N - i - 1) + L - X[i];
			if (left_n < right_n) {
				s -= 2 * bit_rev.sum(N - i - 1 - left_n);
			}
		} else {
			s = 2 * bit.sum(i) + 2 * bit_rev.sum(N - i - 1) + L - X[i];
			if (left_n > right_n + 1) {
				s -= 2 * bit.sum(i - (right_n + 1));
			}
		}
		ans = max(ans, s);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
N, M = map(int, input().split())
S = input()
T = input()

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x // gcd(x, y) * y

L = lcm(N, M)
N_ = L // N
M_ = L // M

X = dict()
for i in range(N):
    X[i * N_] = S[i]

for i in range(M):
    j = i * M_
    if j in X and X[j] != T[i]:
        L = -1
        break

print(L)

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

int main() {
  int N;
  vector<int> x(100), y(100), h(100);
  int xForH, yForH, hForH;  //総当たり時に各マスのHを決めるための組
  int tempH;                //総当たり時のしかるべき頂点の高さ
  int ansX, ansY, ansH;
  bool isAnswer = false;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] != 0) {
      xForH = x[i];
      yForH = y[i];
      hForH = h[i];
    }
  }

  for (int posY = 0; posY < 101 && !(isAnswer); posY++) {
    for (int posX = 0; posX < 101 && !(isAnswer); posX++) {
      isAnswer = true;

      tempH = abs(posX - xForH) + abs(posY - yForH) + hForH;

      for (int i = 0; i < N; i++) {
        int temp = max(tempH - abs(x[i] - posX) - abs(y[i] - posY), 0);
        if (temp != h[i]) isAnswer = false;
      }

      if (isAnswer == true) {
        ansX = posX;
        ansY = posY;
        ansH = tempH;
      }
    }
  }

  cout << ansX << " " << ansY << " " << ansH;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
///#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
if(n==m)
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
    return 0;
}


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

int main(){

    vector<int> a(3);
    rep(i,3) cin >> a[i];

    sort(a.begin(),a.end());

    cout << abs(a[0]-a[1])+abs(a[1]-a[2]) << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.to_i

if n == s then
    puts n+1
else
    m = Math.sqrt(n)
    2.upto(m) do |b|
        x = n
        sum = 0
        while x != 0 do
            y = x % b
            sum += y
            x = (x - y) / b
        end

        if sum == s then
            puts b
            exit
        end
    end

    (m-1).ceil.downto(1) do |r|
        b = ((n - s) / r).to_r + 1
        next if b != b.floor
        next if b == 0
        q = n % b
        if r + q == s then
            puts b.to_i
            exit
        end
    end

    puts -1
end

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::vector<int> v(3);
std::cin >> x>>y;
if(x%2==0||y%2==0)std::cout << "No" << '\n';
else std::cout << "Yes" << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

//ll bit[200010];
ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t = max(bit[i], t);
		i -= i & -i;
	}
	return t;
}

void update(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] = max(bit[i], x);
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}

void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}

ll N;
ll a[16][16];
ll group[70000];
ll dp[70000];

void solve() {
	cin >> N;
	rep(i, N)rep(j, N) cin >> a[i][j];
	rep(i, (1 << N)) {
		vector<ll> bi;
		rep(j, N)if ((i & (1 << j)) != 0) bi.push_back(j);
		if (bi.size()) group[i] = group[i - (1 << bi[0])];
		for (ll j = 1; j < bi.size(); j++) {
			group[i] += a[bi[0]][bi[j]];
		}
	}
	rep(i, (1 << N)) {
		dp[i] = group[i];
		for (ll j = i; ; j = (j - 1) & i) {
			dp[i] = max(dp[i], dp[j] + dp[i - j]);
			if (j == 0) break;
		}
	}
	cout << dp[(1 << N) - 1] << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 1280
N=int(input())
S=[''.join(sorted(input())) for _ in range(N)]
ans=0
num=1
S.sort()
for i in range(1,N):
    if S[i-1]==S[i]:
        num+=1
    else:
        ans+=num*(num-1)//2
        num=1
ans+=num*(num-1)//2
print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N;
ll flag[100005];
ll idx;
ll l,r;
ll mod = 1e9+7;
ll fac[100005];
ll rec_fac[100005];

ll mod_pow(ll a, ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1) ret = ret*a%mod;
        a = a*a%mod;
        n >>= 1;
    }
    return ret%mod;
}

ll comb(ll n, ll r){
    if(r > n) return 0;
    //cout << fac[n] << " " << rec_fac[r] << endl; 
    return (fac[n]*rec_fac[r]%mod)*rec_fac[n-r]%mod;
}

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

    cin >> N;

    memset(flag,-1,sizeof(flag));
    ll a;
    for (int i = 1;i <= N+1;i++){
        cin >> a;
        if(flag[a] != -1){l = flag[a]; r = i;};
        flag[a] = i;
    }

    fac[0] = 1;
    rec_fac[0] = 1;
    for (int i = 1;i <= 100003;i++){
        fac[i] = fac[i-1]*i%mod;
        rec_fac[i] = mod_pow(fac[i],mod-2);
    }

    for (int i = 1;i <= N+1;i++){
        cout << (comb(N+1,i)+mod-comb(l+N-r,i-1))%mod << endl;
    }

    return 0;

}

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

using namespace std;



int main() {

    string s,t;
    int cnt=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3900
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
long long n,k;
long long s[20];
long long sum,cost;
void dfs(long long a,long long b,long long c)
{
	if(a==n)
	{
		if(b>=k)
		sum=min(sum,cost);
		return;
	}
	if(s[a]>c)
	{
		dfs(a+1,b+1,s[a]);
	}
	else{
		dfs(a+1,b,c);
		cost+=(c+1-s[a]);
		dfs(a+1,b+1,c+1);
		cost-=(c+1-s[a]);
	}
}
int main(){
	while(scanf("%lld%lld",&n,&k)==2)
	{
		sum=20000000000;
		//printf("%lld\n",sum); 
		cost=0;
		for(long long i=0;i<n;i++)
		scanf("%lld",&s[i]);
		dfs(1,1,s[0]); 
		printf("%lld\n",sum);
	}
	return 0;
} 

Measured memory_bytes: 256
/*B - Roller Coaster*/

#include <bits/stdc++.h>

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int friends;
	int ans = 0;
	int heigh;
	int h;

	cin >> friends >> heigh;

	for (int i = 0; i < friends; ++i)
	{
		cin >> h;
		if(h >= heigh)
			ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int A, B;

	cin >> A >> B;

	if (B % A == 0) {
		cout << A + B << endl;
	}
	else
	{
		cout << B - A << endl;
	}

	return 0;
}

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

main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  auto b=a;
  sort(b.begin(),b.end(),greater<>());
  ll mx=b[0],smx=b[1];
  rep(i,n){
    if(a[i]==mx)cout<<smx<<endl;
    else cout<<mx<<endl;
  }

}

Measured memory_bytes: 4736
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8"))},function(e,t){e.exports=function(e){for(var t=e.split("\n")[0],n=["","KIH","","B","","R",""],r=[{fl:[0,0,0,0],dep:0}];r.length>0;){var o=r.shift();if(4==o.dep){for(var u=n.concat(),f=0;f<4;f++)1==o.fl[f]&&(u[2*f]="A");if(t==u.join(""))return void console.log("YES")}if(o.dep<4){var i=o.fl.concat();i[o.dep]=1,r.push({fl:i,dep:o.dep+1}),r.push({fl:o.fl.concat(),dep:o.dep+1})}}console.log("NO")}},function(e,t){e.exports=require("fs")}]);

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while (!(line = br.readLine()).equals("0 0")) {
            String[] input = line.split(" ");
            int x = Integer.parseInt(input[0]);
            int y = Integer.parseInt(input[1]);
            if (x < y) {
                int tmp = x;
                x = y;
                y = tmp;
            }

            int step = 0;
            do {
                x = x % y;
                int tmp = x;
                x = y;
                y = tmp;
                step++;
            } while (y != 0);

            System.out.println(x + " " + step);
        }
    }
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int k;
  cin >> k;
  int a = k / 2;
  int ans;
  if(k % 2) ans = a * (a + 1);
  else ans = a * a;
  cout << ans << endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

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

  llong ans = 0;
  llong left = 0, right = N-1;
  while (left <= right) {
    while (S[left] == 'R') {
      left++;
    }
    while (S[right] == 'W') {
      right--;
    }
    if (left > right) break;
    ans++;
    S[left] = 'R';
    S[right] = 'W';
  }

  cout << ans << endl;

  return 0;
}

/*

R を左に寄せる or W に変える

W を右に寄せる or R に変える

*/

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

int main(){
  int n;cin>>n;
  n %= 1000;
  if (n != 0)
  cout << 1000 - n << endl;
  else 
  cout << 0 << endl;
}

Measured memory_bytes: 3632
from collections import deque
n,m = map(int,input().split())
a=[list(map(int, input().split())) for i in range(m)]
b=[[] for j in range(n)] 

michi=[-1]*(n)
michi[0]=0
heya=[]


for i in range(m):
    b[a[i][0]-1].append(a[i][1])
    b[a[i][1]-1].append(a[i][0])



heya.append(1)


while len(heya):
    now=heya.pop(0)-1
    
    for i in range(len(b[now])):
        if michi[b[now][i]-1] == -1:
            heya.append(b[now][i])
            michi[b[now][i]-1] = now+1
print("Yes")
for i in range(1,n):
    print(michi[i])
    
    

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, sum = 0;
    priority_queue<int> l;
    cin >> n;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        l.push(tmp);
        sum += tmp;
    }

    int longest = l.top();
    sum -= longest;
    if (longest >= sum) {
            cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<bitset>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
    double a, b, c;
    cin >> a >> b >> c;
    double s, l, h;
    h = b * sin(c/180.0 * 3.1415926535);
    s = a * h / 2.0;
    l = a + b + sqrt(pow(a-b*cos(c/180.0 * 3.1415926535), 2)+h*h);
    cout << setprecision(12) << s << endl;
    cout << setprecision(12) << l << endl;
    cout << setprecision(12) << h << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <climits>


using namespace std;


int main()
{
    long N;
    vector<long> nums;
    cin >> N;
    for (long i = 0; i < N; i++){
        long tmp;
        cin >> tmp;
        nums.push_back(tmp);
    }

    vector<long> even, odd;
    for (long i = 0; i < N; i += 2)
        even.push_back(nums[i]);
    for (long i = 1; i < N; i += 2)
        odd.push_back(nums[i]);

    vector<long> counts_even(10e5+1);
    for (auto e : even)
        counts_even[e]++;

    vector<long> counts_odd(10e5+1);
    for (auto e : odd)
        counts_odd[e]++;

    long even_freq[4] = { 0 };
    long odd_freq[4] = { 0 };

    for (long i = 1; i <= 10e5; i++) {
        if (counts_even[i] > even_freq[1]) {
            even_freq[2] = even_freq[0];
            even_freq[3] = even_freq[1];
            even_freq[0] = i;
            even_freq[1] = counts_even[i];
        } else if (counts_even[i] > even_freq[3]) {
            even_freq[2] = i;
            even_freq[3] = counts_even[i];
        }
        if (counts_odd[i] > odd_freq[1]) {
            odd_freq[2] = odd_freq[0];
            odd_freq[3] = odd_freq[1];
            odd_freq[0] = i;
            odd_freq[1] = counts_odd[i];
        } else if (counts_odd[i] > odd_freq[3]) {
            odd_freq[2] = i;
            odd_freq[3] = counts_odd[i];
        }
    }

    long ans = 0;
    if (even_freq[0] == odd_freq[0]) {
        long x, y;
        x = y = 0;
        x += N / 2 - even_freq[1];
        x += N / 2 - odd_freq[3];
        y += N / 2 - even_freq[3];
        y += N / 2 - odd_freq[1];

        ans = min(x, y);
    } else {
        ans += N / 2 - even_freq[1];
        ans += N / 2 - odd_freq[1];
    }

    cout << ans << endl;
}


Measured memory_bytes: 17908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int d[11];
	d[0]=c;
	for(int i=1;i<=10;i++){
	d[i]=d[i-1]*a-b;
	cout<<d[i]<<endl;
	}
	return 0;
}

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

vector<pair<int, pair<int, int>>> act;
int dp[100005][4] = {-1};

int solve(int index, int sum, int prev, int n){
    if(index == n-1){
        if(prev == 1){
            if(dp[index][1] == -1){
                dp[index][1] = sum + max(act[index].second.first, act[index].second.second);
                return dp[index][1];
            } else {
                return dp[index][1];
            }
        } else if (prev == 2){
            if(dp[index][2] == -1){
                dp[index][2] = sum + max(act[index].first, act[index].second.second);
                return dp[index][2];
            } else {
                return dp[index][2];
            }
        } else if (prev == 3){
            if(dp[index][3] == -1){
                dp[index][3] = sum +  max(act[index].first, act[index].second.first);
                return dp[index][3];
            } else {
                return dp[index][3];
            }
        }
    } else {
        if(prev == 1){
            if(dp[index][1] == -1){
                dp[index][1] = sum + max(solve(index + 1, act[index].second.first, 2, n), solve(index + 1, act[index].second.second, 3, n));
                return dp[index][1];
            } else {
                return dp[index][1];
            }
        } else if (prev == 2){
            if(dp[index][2] == -1){
                dp[index][2] = sum + max(solve(index + 1, act[index].first, 1, n), solve(index + 1, act[index].second.second, 3, n));
                return dp[index][2];
            } else {
                return dp[index][2];
            }
        } else if (prev == 3){
            if(dp[index][3] == -1){
                dp[index][3] = sum + max(solve(index + 1, act[index].first, 1, n), solve(index + 1, act[index].second.first, 2, n));
                return dp[index][3];
            } else {
                return dp[index][3];
            }
        }
    }
}
int main(){
    memset(dp, -1, sizeof(dp));
    int n;
    cin>>n;
    int t1, t2, t3;
    for(int i = 0;i<n;i++){
        cin>>t1>>t2>>t3;
        act.push_back({t1, {t2, t3}});
    }
    cout<<max(solve(0, 0, 3, n), max(solve(0, 0, 1, n),solve(0, 0, 2, n)))<<endl;
}

Measured memory_bytes: 9332
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
reps(i,n+1,1){
    if(i%3==0){
        continue;
    }
    else if(i%5==0){
        continue;
    }
    ans += i;
}
cout << ans << endl;
//system("pause");
return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;
using namespace std;

void Main()
{
   int A, B;
   cin >> A >> B;
   int ans = 0;

   if (A >= B)
   {
      ans += A;
      if (A - 1 >= B)
         ans += A - 1;
      else
         ans += B;
      cout
          << ans << endl;
      return;
   }

   ans += B;
   if (A <= B - 1)
      ans += B - 1;
   else
      ans += A;
   cout << ans << endl;
   return;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y;
    cin>>x>>y;
    int ans=0;
    if(x==1){ans+=300000;}
    if(x==2){ans+=200000;}
    if(x==3){ans+=100000;}
    if(y==1){ans+=300000;}
    if(y==2){ans+=200000;}
    if(y==3){ans+=100000;}
    if(x==1&&y==1){ans+=400000;}
    cout<<ans<<endl;
    // Your code here!
}


Measured memory_bytes: 256
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    MOD = 10**9 + 7
    t = 0
    k = max(A)
    while k>0:
        k=k//2
        t+=1

    bisu = [0]*(t+1)
    zerobi = [0]*(t+1)
    res = 0
    for i in range(n):
        for j in range(t+1):
            if A[i]&(1<<j):
                bisu[j]+=1

    for i in range(t+1):
        res = res + (bisu[i]*(n-bisu[i])*(2**i))%MOD
    print(res%MOD)

if __name__ == '__main__':
    main()


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

int main(){
    int N, i, j, find = 0;

    cin >> N;
    for(i = 1; i < 10; i++){
        for(j = 1; j < 10; j++){
            if(N == i * j){
                find = 1;
                break;
            }
        }
        if(find)break;
    }
    if(i == 10)cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i, sum=0, num;
  char N[16];
  scanf("%s", N);
  for (i=0; N[i]!='\0'; i++) sum+=N[i]-48;
  if (atoi(N)%sum==0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

using namespace std;

using ull = unsigned long long;

int main() {
    int N, L;
    cin >> N >> L;
    int origin = N * L + N * (N - 1) / 2;
    if(L < 1 && L + N - 1 > -1) {
        cout << origin << endl;
    } else {
        if(L < 0) {
            cout << origin - (L + N - 1) << endl;
        } else {
            cout << origin - L << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 ll n,k;
  cin>>n>>k;
  ll val[n+1];
  rep(i, n){
    cin>>val[i+1];}
  ll sum=0;
  rep(i, n){
    sum+=val[i+1];}
  
  vector <ll> vec{};
  for(int i=1;i*i<=sum;i++){
    if(sum%i==0){
      vec.push_back(i);
      vec.push_back(sum/i);
    }
  }
  
  sort(ALL(vec));
  reverse(ALL(vec));
  
  ll ans=0;
  
  
  for(int j=0;j<=vec.size();j++){
  
  ll mod[n+1];
  rep(i, n){
    mod[i+1]=0;}
    
    ll mo=vec[j];
    
    rep(i, n){
      ll an=val[i+1]%mo;
      mod[i+1]=an;
    }
   
    sort(mod, mod+n+1, greater<ll>());
    
    ll wa=0;
    rep(i, n){
      wa+=mod[i+1];}
    ll ks=wa/mo;
    
    wa=0;
    for(int h=ks+1;h<=n;h++){
      wa+=mod[h];}
    
    if(wa<=k){
      ans=mo;
      break;}
    
    
    
    
    
  }
  
  cout<<ans<<endl;
    
  
  
 
}

Measured memory_bytes: 256
n, q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(q)]
INF = 10 ** 9

ver = [-1] * (n + 1)
hor = [-1] * (n + 1)
ver[-1] = INF
hor[-1] = INF
ver_base = n - 1
hor_base = n - 1

white = 2 * n - 1
for num, x in query:
    if num == 1:
        if ver[x] == -1:
            white += ver_base
            i = x
            while ver[i] == -1:
                ver[i] = ver_base
                i += 1

        else:
            white += ver[x]

        hor_base = min(hor_base, x - 1)

    else:
        if hor[x] == -1:
            white += hor_base
            i = x
            while hor[i] == -1:
                hor[i] = hor_base
                i += 1

        else:
            white += hor[x]

        ver_base = min(ver_base, x - 1)

stone_sum = (n - 2) * (n - 2) + 2 * n - 1 + q
ans = stone_sum - white
print(ans)


Measured memory_bytes: 43444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
int main() {
	int n,m,k;
	bool ans[200000];
	int a[200000];
	int q[1000];
	int bfr[200000];
	int nxt[200000];
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<m;i++)scanf("%d",&a[i]);
	for(int i=0;i<k;i++)scanf("%d",&q[i]);
	for(int i=0;i<n;i++){
		bfr[i]=(i-1+n)%n;
		nxt[i]=(i+1)%n;
		ans[i]=true;
	}
	int p=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<a[i];j++){
			if(a[i]%2==0)p=nxt[p];
			else p=bfr[p];
		}
		ans[p]=false;
		nxt[bfr[p]]=nxt[p];
		bfr[nxt[p]]=bfr[p];
		p=nxt[p];
	}
	for(int i=0;i<k;i++)printf("%d\n",ans[q[i]]?1:0);
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    
    vector<int> p(N+1);
    for(int i=1;i<=N;i++) cin>>p[i];
    
    int count=0;
    for(int i=1;i<=N;i++){
        if(i==N&&p[i]==i){
            swap(p[i],p[i-1]);
            count++;
            break;
        }
        if(p[i]==i){
            swap(p[i],p[i+1]);
            count++;
        }
    }
    
    cout<<count<<endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;
const int INT_INF = 1e9;
long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}


char A[100][100], B[100][100];
int N, M;
bool check(int x, int y) {
	REP(i, M) {
		REP(j, M) {
			if (A[i + x][j + y] != B[i][j])return false;
		}
	}
	return true;
}
void solve() {
	string S; cin >> S;
	int N = S.size();
	int a = 0, b = 0;
	REP(i, N) {
		if (S[i] == 'A') {
			a = i; break;
		}
	}
	REPR(i, N) {
		if (S[i] == 'Z') {
			b = i; break;
		}
	}
	print(b - a + 1);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

int main(){
    string S;
    cin >> S;
    int a;
    a = S.size();
    int ans = 0;
    for (int i = 0;i < a/2; i++){
        if (S.at(i) != S.at(a-1-i)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void func(int n,vector<int> k){
	int c=accumulate(k.begin(),k.end(),0);
	if((n-c)<-1)
		cout<<"-1";
	else
		cout<<(n-c);
}
int main(){
	int n,m;
	cin>>n;
	cin>>m;
	vector<int> k(m);
	for(int i=0;i<m;i++){
		cin>>k[i];
	}
	func(n,k);
}

Measured memory_bytes: 3684
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main (String [] args){
		List <Integer> list = new ArrayList<Integer>();
		HashMap <Integer, Integer>hm = new HashMap<Integer, Integer>();
		int v1 = Integer.parseInt(sc.next());
		int v2 = Integer.parseInt(sc.next());
//		String s2 = sc.next();		
		String ans_str = "";
		int ans_int = 0;
		
		
		if(v1 * v2 > v1-v2){
			if(v1*v2> v1+v2){
				ans_int = v1*v2; 
			}else{
				ans_int = v1 + v2;
			}
		}else{
			if(v1-v2> v1+v2){
				ans_int = v1 - v2;
			}else{
				ans_int = v1 + v2;
			}
		}
		System.out.println(ans_int);
		System.out.flush();
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}




long mod = 998244353;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;

ll intpow(mint_t m, int n)
{
    if (n == 0) return 1;
    mint_t ans(1);
    while (n >= 1)
    {
        if ((n % 2) == 0){
            m *= m.x;
            n /= 2;
        }else {
            ans *= m.x;
            n -= 1;
        }
    }
    return ans.x;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
 
    mint ans = m; 
    ans = ans.pow(n);

    mint ans_ = 0;

    combination cb(n);

    for (int kumi = n-1; kumi > k; kumi--)
    {
        //kumi >= k+1 余事象をもとめる
        mint tans = cb(n-1, (n-1)-kumi);
        tans *= m;
        mint mp = m-1;
        tans *= mp.pow((n-1)-kumi);

        //cout << tans.x << endl;
        ans_ += tans;
    }
    

    cout << (ans-ans_).x << endl;

}




Measured memory_bytes: 6376
N = int(input())
A = [int(i) for i in input().split()]
 
absA = []
for i in range(N):
    absA.append(abs(A[i]))

cnt = 0
for i in range(N):
    if A[i] < 0:
        cnt += 1
    
if cnt % 2 == 0:
    ans = sum(absA)
else:
    ans = sum(absA) - min(absA) * 2

print(ans)

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

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

	int ans = 0;

	for (int a = 1; a <= 10; ++a) {
		for (int b = 1; a + b <= 10; ++b) {
			for (int c = 1; a + b + c <= 10; ++c) {
				string s;
				s.append(a, '3');
				s.append(b, '5');
				s.append(c, '7');
				do {
					auto x=stoll(s);
					if (x<=n) {
						++ans;
					}
				} while (next_permutation(s.begin(), s.end()));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256