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

typedef long long ll;
constexpr ll m = 998244353LL;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

int main(){
  ll N; cin>>N;
  int s=0;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    s+=a[i];
  }
  
  vector<vector<ll>> dp0(N+1,vector<ll>(s+1,0));
  vector<vector<ll>> dp1(N+1,vector<ll>(s+1,0));
  
  dp0[0][0]=1;
  dp1[0][0]=1;
  
  for(int i=1;i<=N;i++){
    for(int j=0;j<=s;j++){
      dp0[i][j] = 2*dp0[i-1][j];
      if(j>=a[i-1]){
        dp0[i][j] += dp0[i-1][j-a[i-1]];
      }
      dp0[i][j] = dp0[i][j]%m;
    }
  }
  
  if(s%2==0){
    for(int i=1;i<=N;i++){
      for(int j=0;j<=s;j++){
        dp1[i][j] = dp1[i-1][j];
        if(j>=a[i-1]){
          dp1[i][j] += dp1[i-1][j-a[i-1]];
        }
      	dp1[i][j] = dp1[i][j]%m;
      }
    }
  }
  
  long long ans=modpow(3LL, N, m);
  
  for(int i=(s+1)/2;i<=s;i++){
    ans = (ans - dp0[N][i]*3 % m + m) % m;
  }
  if(s%2==0){
    ans = (ans + dp1[N][s/2]*3) % m;
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 423744
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L
 
int main() {
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double deg = max((30.0L*H + 30.0L*M/60.0L)-6.0L*M, 6.0L*M-(30.0L*H + 30.0L*M/60.0L));
    if(deg > 180.0L) {
        deg = 360.0L - deg;
    }
    
    long double deg_r, pi, unit, unit_r;
    //pi     = 2.0L * asin(1.0L);            /* πの値 */
	unit   = PI / 180.0L;                 /* 度 → ラジアン */

	deg_r  = deg * PI/180.0L;

    long double rsq;
    rsq = A*A + B*B -2.0L*A*B*cos(deg_r);
    
    printf("%20.20Lf\n", sqrtl(rsq));
    return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int a, p; cin >> a >> p;
	p += 3 * a;
	cout << p / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define t1(a) cout << #a << ":" << a << endl;
#define t2(a, b) cout << #a << ":" << a << " | " << #b << ":" << b << endl;
#define t3(a, b, c) cout << #a << ":" << a << " | " << #b << ":" << b << " | " << #c << ":" << c << endl;

using namespace std;
void minCost(int dp[],int H[],int n)
{
    dp[0]=0;
     dp[1]=abs(H[1]-H[0]);
    for(int i=2;i<n;i++)
    {
       // cout<<dp[i-2]+abs(H[i]-H[i-2])<<endl;
        dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]));
       // cout<<<<endl;
       // cout<<i<<" "<<dp[i-2]<<endl;
    }
}
int32_t main()
{
   IOS;
   
      int n,m,k,x,y,z,a,b,c,count=0,ans=0,temp=0,flag=0,od=0,ev=0,curr=0,prev=0,left,right,h,g,f;
     cin >> n;
     int H[n];
     int dp[n]={0};
     
     for(int i=0;i<n;i++)
        {
          cin>> H[i];   
        }
      minCost(dp,H,n);
      cout<<dp[n-1];
   
  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii pp[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d%d", &pp[i]._1, &pp[i]._2);
		pp[i]._1 += pp[i]._2;
	}
	sort(pp, pp + n);
	reverse(pp, pp + n);
	ll ans = 0ll;
	REP(i, 0, n) {
		if (i & 1) {
			ans -= pp[i]._2;
		} else {
			ans += pp[i]._1 - pp[i]._2;
		}
	}
	cout << ans << endl;
}   


int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

vector <vi> adj;
vi val, ans;
int n, q;

void input()
{
	int x, y;
	cin >> n >> q;
	adj.resize(n + 1);
	val.resize(n + 1);
	ans.resize(n + 1);
	
	for (int i = 1; i < n; i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	FOR (i, 1, q)
	{
	    cin >> x >> y;
	    val[x] += y;
	}
}

int sum = 0;
void dfs(int cur = 1, int prev = 0)
{
    sum += val[cur];
    ans[cur] = sum;
	for (int i: adj[cur])
		if (i != prev)
			dfs(i, cur);
	sum -= val[cur];
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	dfs();
	FOR (i, 1, n) cout << ans[i] << " ";
}

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

using namespace std;

int upper_bound(vector<int>& v, int istart, int iend, int value) {
  int n = v.size();
  int ng = -1;
  int ok = v.size();

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (v[mid] > value) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

int lower_bound(vector<int>& v, int istart, int iend, int value) {
  int n = v.size();
  int ng = -1;
  int ok = v.size();

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (v[mid] >= value) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  int num_query;
  cin >> num_query;

  int query;
  for (int i = 0; i < num_query; i++) {
    cin >> query;
    cout << lower_bound(v, 0, v.size(), query) << " " << upper_bound(v, 0, v.size(), query) << endl;
  }
}




Measured memory_bytes: 3368
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

template <typename T>
struct RMQ {//遅延評価
    const T INF = numeric_limits<T>::max();
    int n;
    vector<T> dat, lazy;
    RMQ(int n_) : n(), dat(n_ * 4, INF), lazy(n_ * 4, INF) {
        int x = 1;
        while (n_ > x) x *= 2;
        n = x;
    }
 
    /* lazy eval */
    void eval(int k) {
        if (lazy[k] == INF) return;  
        if (k < n - 1) {
            lazy[k * 2 + 1] = lazy[k];
            lazy[k * 2 + 2] = lazy[k];
        }
        dat[k] = lazy[k];
        lazy[k] = INF;
    }
 
    void update(int a, int b, T x, int k, int l, int r) {
        eval(k);
        if (a <= l && r <= b) {
            lazy[k] = x;
            eval(k);
        } else if (a < r && l < b) {                     // 一部区間が被る時
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);  // 左の子
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);  // 右の子
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
 
    T query_sub(int a, int b, int k, int l, int r) {
        eval(k);
        if (r <= a || b <= l) { 
            return INF;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {  // 一部区間が被る時
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};

int main() {
  ll N,Q;
  cin>>N>>Q;
  vector<vector<ll>> v(N,vector<ll>(3));
  rep(i,N) cin>>v[i][1]>>v[i][2]>>v[i][0];
  vector<ll> D(Q);
  rep(i,Q) cin>>D[i];
  rep(i,N) {
    v[i][1]-=v[i][0];
    v[i][2]-=v[i][0];
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  RMQ<ll> R(Q);
  R.update(0,Q,-1);
  rep(i,N){
    ll s = lower_bound(D.begin(),D.end(),v[i][1])-D.begin(),t = lower_bound(D.begin(),D.end(),v[i][2])-D.begin();
    R.update(s,t,v[i][0]);
  }
  rep(i,Q){
    cout<<R.query(i,i+1)<<endl;
  }
}

Measured memory_bytes: 28336
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    
    int l = 0, ans = 0;
    for(int i=0;i<S.size();i++){
        char tmp = S.at(i);
        if(tmp == 'A' || tmp == 'C' || tmp == 'G' || tmp == 'T'){
            l++;
        }else{
            if(l > ans)
                ans = l;
            l = 0;
        }
    }

    if(l > ans)
        ans = l;
    
    cout << ans << endl;

}

Measured memory_bytes: 256
def main():
    from bisect import bisect_right

    N = int(input())
    *e, = map(int, input().split())

    e.sort()

    ans = 0
    for j in range(N):
        for i in range(j):
            d = e[j] - e[i]
            ans += i - bisect_right(e, d, lo=0, hi=i)

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


Measured memory_bytes: 3188
/******* VIVEK PAl *******/
/*************************/
#include <bits/stdc++.h>
#define prime 1000000007
#define mod 998244353
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
/****** END OF HEADER ******/
/***************************/
int maxN=2e+3 + 8;
void solve()
{
    int K, N; cin>>K>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++)
      cin>>A[i];
    int maxt=0;
    for(int i=1;i<N;i++){
      maxt=max(maxt, A[i]-A[i-1]);
    }
    maxt=max(maxt, K-A[N-1]+A[0]);
    printf("%d\n", K-maxt);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T=1, t; 
  //cin>>T;
  t = T;
  while(T--)
  {
      //printf("Case #%d: ", t-T);
      solve();
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N= 1000001;
vector<int> p;
bitset<10000001> b;

void sevie() {
	b[0] = b[1] = 1;
	for (int i = 2; (i * i) <= N; i++) {
		if (!b[i]) {
			for (int j = i * 2; j <= N; j += i) b[j] = 1;
		}
	}
	for (int i = 2; i <= N; i++) if (!b[i]) p.push_back(i);
}

map<int, int> mp;

bool prime_factor(int nm) {
	int pf = p[0], c = 0;
	while (pf * pf <= nm) {
                if (nm% pf== 0&& mp.count(pf)) return 1;
                else if (nm% pf== 0) {
                        mp[pf]++;
                }
		while (nm % pf == 0) { nm/= pf; }
		pf = p[++c];
	}
	if (nm > 1) {
		if (mp.count(nm)) return 1;
                else mp[nm]++;
	}
	return 0;
}

void solve() {
        sevie();

        int n; cin >> n;
        int gc= 0;

        vector<int> v(n);

        for (int i= 0; i< n; i++) {
                cin >> v[i];
                gc= __gcd(gc, v[i]);
        }

        if (gc!= 1) {
                cout << "not coprime\n";
        } else {
                for (int i= 0; i< n; i++) {
                        if (prime_factor(v[i])) {
                                cout << "setwise coprime\n";
                                return;
                        }
                }
                cout << "pairwise coprime\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 12044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int N;
    string s;
    cin >> N;
    cin >> s;
    int count = 0;
    int min = N;
    int i, j;

    //0番目の範囲を求める
    for(i=1; i<N; i++){
        if(s[i] == 'E') count++;
    }

    min = count;

    for(i=1; i<N; i++){
        if(s[i]=='E' && i<N){ //左側
            count--;
        }
        if(s[i-1]=='W'){ //左側
            count++;
        }

        if(count<min){
            min=count;
        }
    }
    cout << min << endl;
    return 0;
}

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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e5;

void dfs(int u,vector<int>& vis,vector<vector<int>>& adj,vector<int>& ans){
    vis[u]=1;
    for(auto it:adj[u]){
        if(!vis[it]){
            dfs(it,vis,adj,ans);
        }
        ans[u]=max(ans[u],ans[it]+1);
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n+5);
    vector<int> vis(n+5,0),ans(n+5,0);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[y].push_back(x);
    }
    int fin=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            ans[i]=0;
            dfs(i,vis,adj,ans);
        }
        fin=max(fin,ans[i]);
    }
    cout<<fin;
    return 0;
}

Measured memory_bytes: 16840
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    string s = "",t = "";
    for(int i = 0;i < b;i++)
    {
        s += to_string(a);
    }
    for(int i = 0;i < a;i++)
    {
        t += to_string(b);
    }
    cout << min(s,t) << "\n";

    return 0;
}

Measured memory_bytes: 256
a, b, x = map(int, input().split())
import math
if x == (a**2 * b)/2:
    print(45)
elif x > (a**2 * b)/2:
    print(math.degrees(math.atan((2 * b - 2 * x/(a**2))/a)))
else:
    print(90 - math.degrees(math.atan(2 * x / (a * b**2))))

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

int main(){
    int n; cin>>n;
    for(int i=0;i<n;i++){
        char c; cin>>c;
        if(c=='Y'){
            cout<<"Four"<<endl;
            return 0;
        }
    }
    cout<<"Three"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b string

	fmt.Scan(&a, &b)

	if a == "H" || a == "D" && b == "H" || b == "D" {
		if a == "H" && b == "H" {
			fmt.Print("H")
		} else if a == "H" && b == "D" {
			fmt.Print("D")
		} else if a == "D" && b == "H" {
			fmt.Print("D")
		} else {
			fmt.Print("H")
		}

	} else {
		fmt.Print("HかDを入力してください")
	}

}


Measured memory_bytes: 1836
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n,m,a,b;
	cin >> n >> m;
	vector<long> height(n);
	vector<bool> ok(n);
	rep(i, n){
      	ok[i] = true;
		cin >> height[i];
	}
  	rep(i, m) {
    	cin >> a >> b;
      	if(height[a-1] <= height[b-1]) {
        	 ok[a-1] = false;
        }
      	if(height[a-1] >= height[b-1]){
  			ok[b-1] = false; 
        }
    }
  	int cnt=0;
  	rep(i, n){
      	if(ok[i])
          	cnt++;
	}
	cout << cnt << endl;
	
}

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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define maxn 101
#define maxh 1001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
typedef std::pair<int, int> P;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

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

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

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    int N;
    cin >> N;
    cout << 800 * N - 200 * (N / 15) << endl;
}



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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,A,B; cin >> N >> A >> B;
	cout << min(A,B) << ' ' << max(0,A+B-N) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n;
	cin >> n;
	hei(llint) a(n);
	map<int, int> S;
	rep(i, 0, n) {
		cin >> a[i];
		for (int j = 0;; j++) {
			if (pow(2, j) > a[i])break;
			if (a[i] & (1 << j))S[j]++;
			S[j] %= 2;
		}
	}
	llint ans = 0;
	for (auto x : S) {
		ans += pow(2, x.first) * x.second;
	}
	rep(i, 0, n) {
		llint Ans = ans ^ a[i];
		cout << Ans << endl;
	}
	return 0;

}

Measured memory_bytes: 4840
#include <iostream>
using namespace std;
int main (){
 int a,b,c,d,e,k;
 cin >> a;
 cin >> b;
 cin >> c;
 cin >> d;
 cin >> e;
 cin >> k;
 if (e - a <= k)
   cout << "Yay!" << endl;
  else 
    cout << ":(" << endl;

 
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int p=sc.nextInt();
        a=a*p;
        if(p>c) b=b+d*(p-c);
        System.out.println(Math.min(a, b));  
    }
}

Measured memory_bytes: 26416
#include <stdio.h>

int main() {
	int N;
	int a, b, c;
	int i, temp;
	scanf("%d", &N);
	for(i = 0; i < N; i++) {
		scanf("%d %d %d", &a, &b, &c);
		if(a < b) {
			temp = b;
			b = a;
			a = temp;
		}
		if(b < c) {
			temp = c;
			c = b;
			b = temp;
		}
		if(a < b) {
			temp = b;
			b = a;
			a = temp;
		}
		if((a*a) == b*b + c*c) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

namespace Prac
{
    class Program
    {
        static void Main(string[] args)
        {
            var Hs = new List<int>();
            var Ws = new List<int>();
            var temp = new int[2];
            while (true)
            {
                temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (temp[0] == 0 && temp[1] == 0)
                    break;
                Hs.Add(temp[0]);
                Ws.Add(temp[1]);
            }
            for (var i = 0; i < Hs.Count; i++)
            {
                for (var h = 0; h < Hs[i]; h++)
                {
                    for (var w = 0; w < Ws[i]; w++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            
        }


    }
}
    

Measured memory_bytes: 5652
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,x;
    while(1){
        cin>>n>>x;
        if(n+x==0) break;
        int cnt=0;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                int k=x-i-j;
                if(k>j && k<n+1) cnt ++;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n;cin>>n;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	bool can = true;
	v[0]--;
	for(int i = 1; i < n; i++){
	if(v[i] > v[i-1]){
			v[i]--;
		}
		if(v[i] < v[i-1]){
			can = false;
			break;
		}
	}
	cout << (can? "Yes": "No") << endl;
}



Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    char s[30];
    int ans=0;
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        for(int j=1;i+j<strlen(s);j++){
            if(s[i]==s[i+j])ans++;
        }
    }
    if(ans==0)printf("yes\n");
    else printf("no\n");
    return 0;
}


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

int main() {
    int Q;
    cin >> Q;
    
    deque<int> deq;
    
    for (int q = 0; q < Q; q++) {
        int c;
        cin >> c;
        
        if (c == 0) {
            int d, x;
            cin >> d >> x;
            if (d == 0) {
                deq.push_front(x);
            } else {
                deq.push_back(x);
            }
        } else if (c == 1) {
            int a;
            cin >> a;
            cout << deq[a] << endl;
        } else {
            int d;
            cin >> d;
            if (d == 0) {
                deq.pop_front();
            } else {
                deq.pop_back();
            }
        }
    }
}


Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;

int n, m;
v2<int> adj;

void solve(){
    cin >> n >> m;
    adj = v2<int>(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    vector<int> signs(n, -1);
    queue<int> next;
    next.push(0);
    signs[0] = 0;
    while(!next.empty()){
        int parent = next.front();
        next.pop();
        for(int node : adj[parent]){
            if(signs[node] == -1){
                next.push(node);
                signs[node] = parent;
            }
        }
    }

    for(int i = 1; i < n; i++){
        if(signs[i] == -1){
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";
    for(int i = 1; i < n; i++){
        cout << signs[i]+1 << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 10128
N = int(input())
S = input()

same_num = -1

for i in range(N):
    s1 = set(S[:i+1])
    s2 = set(S[i+1:])
    if len(s1 & s2) > same_num:
        same_num = len(s1 & s2)

print(same_num)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  char t = 'a' - 'A';
  cout << (char)(s1[0] - t) << (char)(s2[0] - t) << (char)(s3[0] - t) << endl;
}

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

int main() {
  int64_t N;
  cin >> N;
  
  int64_t Y, X = 100;
  int cnt = 0;
  
  while(X <= 1000000000000000000){
    if(X >= N){
      break;
    }
    cnt++;
      Y = X / 100;
      X += Y;
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n-->0){
		double xa,ya,ra,xb,yb,rb;
		cin >>xa>>ya>>ra>>xb>>yb>>rb;
		double d = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		if(ra>d+rb) cout << 2 << endl;
		else if(rb>d+ra) cout << -2 << endl;
		else if(d<=ra+rb) cout << 1 << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 1232
import java.util.Scanner;

//Magic Square
public class Main{

	static int n;
	static int[][] m;
	
	static void put(int i, int j, int k){
		if(k>n*n)return;
		if(j==n){
			put(i,0,k);return;
		}
		if(j<0){
			put(i,n-1,k);return;
		}
		if(i==n){
			put(0,j,k);return;
		}
		if(m[i][j]==0){
			m[i][j]=k;
			put(i+1,j+1,k+1);
		}
		else put(i+1,j-1,k);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n==0)break;
			m = new int[n][n];
			put(n/2+1,n/2,1);
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					System.out.printf("%4d", m[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 12000
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

int main()
{
    int h , w , n;
    cin >> h >> w >> n;

    for(int i = 0; ; i++){
        int cur = max(h,w)*i;
        if(cur >= n){
            cout << i << endl;
            return 0;
        }
    }

}
/*



*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef double D;     
typedef complex<D> P;  
typedef pair<P, P> L; 
typedef vector<P> VP;
const D EPS = 1e-9;  
#define X real()
#define Y imag()
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1; 
  if (cross(b,c) < -EPS) return -1; 
  if (dot(b,c)   < -EPS) return +2; 
  if (norm(b) < norm(c)) return -2; 
  return 0;                      
}
bool isecSS(P &a1, P &a2, P &b1, P &b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
bool isecSP(P &a1, P &a2, P &b) {
  return !ccw(a1, a2, b);
  //return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;  //Perfective
}
P proj(P &a1, P &a2, P &p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}
D distSP(P &a1, P &a2, P &p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}
 
D distSS(P &a1, P &a2, P &b1, P &b2) {
  if (isecSS(a1, a2, b1, b2)) return 0;
  return min(min(distSP(a1, a2, b1), distSP(a1, a2, b2)),
             min(distSP(b1, b2, a1), distSP(b1, b2, a2)));
}
std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;
D ans=1e19,x[10000],y[10000],xx[10000],yy[10000];
vector<P>v1,v2;
int main(){
  start = std::chrono::system_clock::now();
  int n;
  cin>>n;
  if(n>=5200){
    cout<<0<<endl;
    return 0;
  }
  r(i,n){
    cin>>x[i]>>y[i]>>xx[i]>>yy[i];
    v1.push_back(P(x[i],y[i]));
    v2.push_back(P(xx[i],yy[i]));
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans=min(ans,distSS(v1[i],v2[i],v1[j],v2[j]));
    }
    if(i%10==0){
      owari = std::chrono::system_clock::now();
      double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(owari-start).count();
      if(elapsed>970)break;
    }
  }
  printf("%.9f\n",ans);
}


Measured memory_bytes: 3524
base = [i+1 for i in range(50)]

k = int(input())
if(k < 50):
    ans = list(map(lambda x: x if x > 50 - k else 0, base))
else:
    baseup = k // 50 - 1
    partup = k % 50
    ans = list(map(lambda x: x + baseup + (x>50-partup), base))

print(50)
print(" ".join(map(str, ans)))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			long A = scn.nextLong();
			long B = scn.nextLong();
			long N = scn.nextLong();

			N = Math.min(B-1, N);

			System.out.println((long)(Math.floor(A*N/B) - A * (Math.floor(N/B))));
		}
	}
}



Measured memory_bytes: 27004
#include <stdio.h>

struct time
{
	int h;
	int m;
	int s;
};

void scan(struct time *t)
{
	scanf("%d %d %d", &t->h, &t->m, &t->s);
}

int main(void)
{
	int i;
	
	for (i = 0; i < 3; i++){
		struct time attend;
		struct time leave;
		struct time work;
		
		scan(&attend);
		scan(&leave);
		
		work.h = leave.h - attend.h;
		work.m = leave.m - attend.m;
		work.s = leave.s - attend.s;
		
		if (work.s < 0){
			work.m--;
			work.s += 60;
		}
		if (work.m < 0){
			work.h--;
			work.m += 60;
		}
		printf("%d %d %d\n", work.h, work.m, work.s);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

string solve(int N, ll A, ll B, ll C, ll D){
    for(int k=0;k<=N;k++){
        ll low = A + k*C - (N-k)*D;
        ll high = A + k*D - (N-k)*C;
        if(low <= B && B <= high) return "YES";
    }
    return "NO";
}

int main(){
    int N;
    ll A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    N--;
    
    cout << solve(N, A, B, C, D) << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import copy

def Reach(A, T, K):
    for i in range(K):
        T = A[T]-1
    return T + 1


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    ac = [0 for j in range(N)]
    T = 0
    ac[0] = 1
    for i in range(1,N):
        T = A[T]-1
        if ac[T] == 0:
            ac[T] = 1
        else:
            pos_from_F = T
            cnt_from_F = i
            break

    T = pos_from_F
    for i in range(1,N):
        T = A[T]-1
        if T == pos_from_F:
            cnt_from_S = i
            break


    T = 0
    if K < cnt_from_F:
        for i in range(K):
            T = A[T]-1
    else:
        K = (K-cnt_from_F) % cnt_from_S
        T = pos_from_F
        for i in range(K):
            T = A[T]-1

    print(T+1)

if __name__ == '__main__':
    main()


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


int main(){
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0; is_prime[1] = 0;
  
  for(int i=2; i<MAX; ++i){
    if(!is_prime[i]) continue;
    for(int j=i*2; j<MAX; j+=i) is_prime[j]=0;
  }
  
  vector<int> a(MAX, 0);
  
  for(int i=0; i<MAX; ++i){
    if(i%2==0) continue;
    if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
  }
  
  vector<int> s(MAX+1, 0);
  for(int i=0; i<MAX; ++i) s[i+1] =s[i] + a[i];
  
  int Q; cin >> Q;
  
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r;
    ++r;
    cout << s[r] - s[l] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    string S;
    cin>>N>>Q>>S;
    vector<ll> sum(N+1);
    for(int i=1;i<=N;i++){
        if(S[i]=='C'&&S[i-1]=='A') sum[i]++;
        sum[i]+=sum[i-1];
    }
    REP(i,Q){
        ll r,l;
        cin>>r>>l;
        r--;l--;
        cout<<sum[l]-sum[r]<<endl;
    }
}

Measured memory_bytes: 1872
"""

https://atcoder.jp/contests/arc075/tasks/arc075_d

桁数を決め打ちする？
 abcd
-dcba
 ABCD

999a+90b-90c-999d = ABCD

みたいな感じになる
これをいい感じに満たせばおk
aとd,bとcをまとめる
-9～9の19通り


19**4 = 2476099通り
aとdの分配の仕方の通り数をあらかじめ数えておけばおｋ
ただし、a != 0
差は、9999109999
      9999019999
差があるとDを超える場合は探索を打ち切ればおｋ

"""
import sys

def dfs(dig,nd,nsum):

    P = 10**((dig-1)-nd) - 10**nd #この桁の寄与の基準
    maxc = 10**((dig-1)-nd)
    
    if nd == dig//2:
        if nsum == D:
            if dig % 2 == 0:
                return 1
            else:
                return 10
        return 0
    elif nd != 0:
        ret = 0
        for i in range(-9,10):
            if nsum+P*i < D-maxc or nsum+P*i > D+maxc:
                continue
            ret += dfs(dig,nd+1,nsum+P*i) * sums[i]
        #print (ret,"y")
        return ret
    else:
        ret = 0
        for i in range(-9,10):
            if nsum+P*i < D-maxc or nsum+P*i > D+maxc:
                continue
            tmp = dfs(dig,nd+1,nsum+P*i) * sums_z[i]
            #if tmp > 0:
            #    print (dig,nd+1,i,"is 1",tmp)
            ret += tmp
        return ret
            

D = int(input())
ans = 0
sums = [0] * 30
for i in range(-9,10):
    for x in range(-9,1):
        for y in range(0,10):
            if x+y == i:
                sums[i] += 1
print (sums , file=sys.stderr)
sums_z = [0] * 30
for i in range(-9,10):
    for x in range(-9,0):
        for y in range(1,10):
            if x+y == i:
                sums_z[i] += 1
print (sums_z , file=sys.stderr)

for dig in range(1,20):

    now = dfs(dig,0,0)
    #print (dig,now)
    ans += now

print (ans)


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

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

using namespace std;

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

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

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

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


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


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

    i32 n; cin >> n;
    vi perm(n); rep(i,n) perm[i] = i+1;
    vi p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    i32 num = 1, pp, qq;
    do {
        bool can1 = 1, can2 = 1;
        for(i32 i = 0; i < n; ++i) {
            if(p[i] != perm[i]) can1 = 0;
            if(q[i] != perm[i]) can2 = 0;
        }
        if(can1) {
            pp = num;
        }
        if(can2) {
            qq = num;
        }
        ++num;
    } while (next_permutation(all(perm)));

    cout << abs(pp-qq) << '\n';

//     printf("ElapsedTime: %5.3f ms\n",1000*((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main(){
  int N,X;
  cin >> N;
  bool found = false;
  for(int i=(int)N/1.1;i<N;i++){
    if((int)(i*1.08) == N){
      cout << i << endl;
      found = true;
      break;
    }
  }
  if(N <= 12){
    cout << N << endl;
  }else if(!found){
    cout << ":(" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().rstrip().split())
before = X

if abs(X)//D>=K:
  print(abs(X)-D*K)
else:
  for i in range(K):
    buf = X
    if X<0:
      X += D
    else:
      X -= D
    if X == before:
      if (K-i)%2 == 0:
        if X<0:
          X += D
        else:
          X -= D
      else:
        X = before
      break
    before=buf
  print(abs(X))

Measured memory_bytes: 62984
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n, k, q, cnt=0;
	cin >> n >> k >> q;
	vector<ll>a(q),p(n,k-q);
	rep(i, q)cin >> a[i];
	for (ll i = 0; i < q; i++) {
		p[a[i]-1]++;
	}
	for (ll i = 0; i < p.size(); i++) {
		cout << (p[i] <= 0 ? "No" : "Yes") << endl;
	}
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
ll findans(ll s,ll k)
{
    if(s==0)
    return 0;
    ll r=10,res=s;
    while(r<=s)
    {
        res=res+s%r+findans(s/r,s%r+k)+k;
        r=r*10;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        ll ans=0,s;
        cin>>s;
        cout<<findans(s,0)<<"\n";
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(A.begin(), A.end());
  sort(C.begin(), C.end(), greater<int>());

  long ans = 0;
  auto comp = [](int x, int y){ return y < x; };
  for (int b : B) {
    auto it1 = lower_bound(A.begin(), A.end(), b);
    long na = it1 - A.begin();
    auto it2 = lower_bound(C.begin(), C.end(), b, comp);
    long nc = it2 - C.begin();
    ans += na * nc;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcount(x);};
const int mod = 1e9 + 7;
//const int mod = 998244353;

void ch(int &y, int &x, int h, int w){
    y = (y + h) % h;
    x = (x + w) % w;
}

int main(){
    while(1){
        int h,w; cin >> h >> w;
        if(h+w == 0) break;
        vs s(h); rep(i,h) cin >> s[i];
        map<string,int> mp;
        rep(i,h){
            rep(j,w){
                rep(k,8){
                    vb v(26,false);
                    v[s[i][j]-'A'] = true;
                    int y = i;
                    int x = j;
                    string t;
                    while(1){
                        t += s[y][x];
                        mp[t]++;
                        y += dy[k];
                        x += dx[k];
                        ch(y,x,h,w);
                        if(y == i && x == j) break;
                    }
                }
            }
        }
        ll num = 1;
        string ans;
        for(auto i : mp){
            if(i.second >= 2){
                if(num < i.first.size()){
                    num = i.first.size();
                    ans = i.first;
                }
            }
        }
        if(num == 1) cout << 0 << "\n";
        else cout << ans << "\n";
    }
}


Measured memory_bytes: 37972
import java.util.*;

import java.io.*;

public class Main {
	class Edge {
		int to, cost;

		public Edge(int to, int cost) {
			super();
			this.to = to;
			this.cost = cost;
		}

	}

	List<Edge>[] graph;
	boolean[] used;
	long[] pos;
	
	void dfs(int u, long p) {
		used[u] = true;
		pos[u] = p;
		for (int t = 0; t < graph[u].size(); t++) {
			Edge e = graph[u].get(t);
			if (!used[e.to]) {
				dfs(e.to, p + e.cost);
			} else if (pos[e.to] != p + e.cost){
				fail = true;
			}
		}
	}
	boolean fail = false;
	
	void solve() {
		int n = in.nextInt(), m = in.nextInt();
		graph = new List[n];
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<>();
		}
		for (int i =0; i < m; i++) {
			int from = in.nextInt() - 1, to =in.nextInt() - 1, len = in.nextInt();
			graph[from].add(new Edge(to, len));
			graph[to].add(new Edge(from, -len));
		}
		used = new boolean[n];
		pos = new long[n];
		for (int i = 0; i < n; i++) {
			if (!used[i]) {
				dfs(i, 0);
			}
		}
		out.println(fail ? "No" : "Yes");
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


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

using namespace std;

int n,m;
int f[100];

int main(){
        cin >> n >> m;
        for(int i=0; i<n; i++){
                int k;
                cin >> k;
                for(int j=0; j<k; j++) {
                        int t;
                        cin >> t;
                        t--;
                        f[t]++;
                }
        }

        int r = 0;
        for(int i=0; i<m; i++)
                r += f[i] == n ? 1 : 0;
        cout << r << endl;


        return 0;
}


Measured memory_bytes: 256