akhauriyash/Code-Regression huggingface dataset:
N, Q = map(int, input().split())
S = input()

ac = [0 for _ in range(N+1)]

for i in range(1,N):
  if S[i-1:i+1]=='AC':
    ac[i] = 1

for i in range(1,N):
  ac[i]+=ac[i-1]

for i in range(Q):
  l,r = map(int, input().split())
  print(ac[r-1]-ac[l-1])

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int x, n, p[105] = {0}, tmp;
	cin >> x >> n;
	rep (i, n) cin >> tmp, p[tmp] = 1;
	if (p[x] == 0) {cout << x << endl; return 0;}
	reps (i, 1, inf)
	{
		if (x - i < 0) {cout << x - i << endl; return 0;}
		if (p[x - i] == 0) {cout << x - i << endl; return 0;}
		if (p[x + i] == 0) {cout << x + i << endl; return 0;}
	}
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll a, b ;
    cin >> a >> b ;
    cout << (a * b) ;

    return 0 ;
}


Measured memory_bytes: 3676
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#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++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int a,b;cin>>a>>b;a--;b--;
   cout<<a*b;
}



Measured memory_bytes: 256
//2019/3/14
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int b = sc.nextInt();

		int c = b-a;

		int d = 0;

		for(int i=1;i<c;i++) d += i;

		int ans = d-a;

		System.out.println(ans);
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int n;
struct edge{
	int to, cost;
};

vector<edge> graph[100001]; 
vector<int> dis(100001);
vector<bool> visited(100001); 

void dfs(int next, int dist){
	visited[next] = true;
	dis[next] = dist%2;
	for (int i = 0; i < graph[next].size(); i++){
		if (visited[graph[next][i].to] == false){
			dfs(graph[next][i].to, (dist + graph[next][i].cost)%2);
		}
	}
	return;
}


int main(){
 	cin >> n;
 	for (int i = 1; i < n; i++){
 		int u, v, w;
 		cin >> u >> v >> w;
 		edge e1 = {v, w};
 		edge e2 = {u, w};
 		graph[u].push_back(e1);
 		graph[v].push_back(e2);
 	}
 	dfs(1, 0);
 	for (int i = 1; i <= n; i++){
 		cout << dis[i] << endl;
 	}
 	return 0;
}


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

int main(void){
  int x,k;
  std::cin >> x;
  
  for(int i=1;;i++){
    if((360*i)%x==0){
      k=(360*i)/x;
      std::cout << k;
      exit(0);
    }
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-9;
struct dot{
	double x,y;
	double len(){return sqrt(x*x+y*y);}
	dot(double a=0.0,double b=0.0){x=a,y=b;}
	dot operator +(const dot&b)const {return dot(x+b.x,y+b.y);}
	dot operator -(const dot&b)const {return dot(x-b.x,y-b.y);}
	dot operator *(const double&z)const {return dot(x*z,y*z);}
	bool operator <(const dot&b)const {return (x<b.x)||(x==b.x&&y<b.y);}
	void read(){scanf("%lf%lf",&x,&y);} 
};
struct line{
	dot x1,x2;
	void read(){x1.read();x2.read();};
	dot getdot(){return x2-x1;}
};
double chaji(dot x,dot y){
	return x.x*y.y-x.y*y.x;
}
double neiji(dot x,dot y){
	return x.x*y.x+x.y*y.y;
}
double cos(dot x,dot y){
	if (!x.len()||!y.len())return 0;
	return neiji(x,y)/x.len()/y.len();
}
dot Projection(dot x,line y){//求x关于直线y的投影点（垂足） 
	y.x2=y.x2-y.x1;
	x=x-y.x1;
	double len=cos(x,y.x2)*x.len()/y.x2.len();
	y.x2=y.x2*len;
	return y.x2+y.x1;
}
dot Reflection(dot x,line y){//求x关于直线y的对称点 
	dot z=Projection(x,y);
	return z*2-x;
}
int Counter_Clockwise(dot x,line y){//求两个向量的五种关系 
	x=x-y.x1;y.x2=y.x2-y.x1;
	if (chaji(y.x2,x)!=0){
		if (chaji(y.x2,x)>0)return 1;
		return 2;
	} 
	if (fabs(cos(x,y.x2)+1)<eps)return 3;
	if (x.len()>y.x2.len())return 4;
	return 5;
} 
int Parallel_Orthogonal(line x,line y){//求两个直线是垂直还是平行还是其他 
	dot a=x.getdot(),b=y.getdot();
	if (chaji(a,b)==0)return 2;
	if (neiji(a,b)==0)return 1;
	return 0;
}
int Intersection(line x,line y){//求两条直线是否相交 
	int Minx1=min(x.x1.x,x.x2.x),Maxx1=max(x.x1.x,x.x2.x);
	int Minx2=min(y.x1.x,y.x2.x),Maxx2=max(y.x1.x,y.x2.x);
	int Miny1=min(x.x1.y,x.x2.y),Maxy1=max(x.x1.y,x.x2.y);
	int Miny2=min(y.x1.y,y.x2.y),Maxy2=max(y.x1.y,y.x2.y);
	if (Minx1>Maxx2||Minx2>Maxx1)return 0;
	if (Miny1>Maxy2||Miny2>Maxy1)return 0;
	if (chaji(x.getdot(),y.x1-x.x1)*chaji(x.getdot(),y.x2-x.x1)>0)return 0;
	if (chaji(y.getdot(),x.x1-y.x1)*chaji(y.getdot(),x.x2-y.x1)>0)return 0;
	return 1;
}
int main(){
	int T;
	scanf("%d",&T);
	while (T--){
		line x,y;
		x.read();y.read();
		printf("%d\n",Intersection(x,y));
	}
	return 0;
}



Measured memory_bytes: 3256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll max_k_tuple(vector<ll> g, int k) {
  int n = g.size();
  if (n < k) {
    return 0;
  }
  sort(g.begin(), g.end());
  vector<ll> sum(n + 1), mx(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + g[i];
    mx[i + 1] = max(mx[i], g[i]);
  }
  while (k > 1) {
    if (sum[n] >= mx[n] * k) {
      return sum[n] / k;
    }
    --k;
    --n;
  }
  return sum[n];
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    vector<ll> g(N, 0);
    for (int x : A) ++g[x - 1];
    sort(g.begin(), g.end());
    vector<ll> sum(N + 1), mx(N + 1);
    for (int i = 0; i < N; i++) {
      sum[i + 1] = sum[i] + g[i];
      mx[i + 1] = max(mx[i], g[i]);
    }
    int n = N;
    for (int k = 1; k <= N; k++) {
      while (n > N - k + 1 && sum[n] < mx[n] * (k - (N - n))) --n;
      cout << sum[n] / (k - (N - n)) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include <string>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  rep(i, m){
    int a, b; cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n){
    ans = max(ans, uf.size(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4040
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  //1, 1, 1, 2, 1,** 2, 1, 5, 2, 2,**1, 5, 1, 2, 1,** 14, 1, 5, 1, 5,** 2, 2, 1, 15, 2**, 2, 5, 4, 1, 4**, 1, 51
	  int n = sc.nextInt();
	  if(n == 4 ||  n ==6 || n==9 || n==10 || n == 14 || n == 21 || n == 22 || n == 25 || n == 26)
		  out.println(2);
	  else if (n == 8 || n == 12 || n ==18 || n == 20 || n == 27)
		  out.println(5);
	  else if(n == 16)
		  out.println(14);
	  else if(n == 24)
		  out.println(15);
	  else if(n ==28 || n == 30 )
		  out.println(4);
	  else if(n == 32)
		  out.println(51);
		  else
			  out.println(1);

  	}
  }	

Measured memory_bytes: 21716
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	if((a==1 && b==2) || (a==2 && b==1))
	printf("3");
	else if((a==1 && b==3)||(a==3 && b==1))
	printf("2");
	else 
	printf("1");
	
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2020/03/22.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {
	ll ans = 0;


	ll n,m;
	cin >> n >> m;

	vector<ll> point(100);
	
	point[0] = 0;
	FOR(i, 1, 100) {
		point[i] = point[i-1] + i;
	}

	
	if (n != 0) {
		ans = point[n-1];
	}

	if (m != 0) {
		ans += point[m-1];
	}

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


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
    // #pragma GCC target("avx,avx2,fma")
    // #pragma GCC optimization ("unroll-loops")

    #include<bits/stdc++.h>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    #define clr clear()
    #define ins insert
    #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
    #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
    #define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
    #define mem(x,val) memset((x),(val),sizeof(x));
    #define cusmem(x,val) for(auto &i:x) i=val;
    #define all(x) x.begin(),x.end()
    #define fastio ios_base::sync_with_stdio(false);\
                cin.tie(NULL);\
                cout.tie(NULL);
    using namespace std;
    typedef pair<int,int> pii;
    typedef pair<ll,ll>pll;
    typedef pair<ll,int>pli;
    typedef vector<ll> vl;
    typedef vector<pll> vpll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<pii> vpii;
    string impossible;

    mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
    // const int N=6;
    const int N=1e5+5;
    const int L=31;
    ll mod=1e9+7;
    ll n,i,j,k,x,m,b,a,da,db,u,v;
    bool f0,f1,f2;
    const int MAXN=1e6+5;
    string s;
    ll powmodp(ll a,ll b,ll mod){//log a
        a=a%mod;
        if(b==1)
            return a;
        ll res=1;
        while(b){
            if(b&1){
                res=res*a;
                res%=mod;
            }
            b=b>>1;
            a=a*a;
            a%=mod;
        }
        return res; 
    }
    int main(){
        #ifndef ONLINE_JUDGE
                freopen("input.txt","r",stdin); 
                freopen("output.txt","w",stdout);
        #endif
        fastio
        cout<<fixed<<setprecision(11);
        int tests=1;    
        // cin>>tests;
        for(int te=1;te<=tests;te++){
            cin>>n;
            if(n<2) cout<<0;
            else{
                // ll a2=powmodp(9,n,mod);
                ll ans=powmodp(10,n,mod)-2*powmodp(9,n,mod)+powmodp(8,n,mod);
                while(ans<0)    ans+=mod;
                ans%=mod;
                cout<<ans;
            }
        }
        return 0;
    }





Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

string S;
long long cur[1 << 18], power[1 << 18];
long long cnt[1 << 18];

int main() {
	cin >> S;
	power[0] = 1;
	for (int i = 1; i <= 250000; i++) power[i] = (10LL * power[i - 1]) % 2019LL;
	
	cur[S.size()] = 0;
	for (int i = S.size() - 1; i >= 0; i--) {
		cur[i] = (cur[i + 1] + 1LL * (S[i] - '0') * power[S.size() - 1 - i]) % 2019LL;
	}

	long long ret = 0;
	for (int i = 0; i <= S.size(); i++) {
		ret += cnt[cur[i]];
		cnt[cur[i]]++;
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
  string a,b;
  cin>>a>>b;
  if(a.size()==b.size()) {
    for(int i=0;i<a.size();i++) {
      cout<<a.at(i)<<b.at(i);
    }
  }
  if(a.size()>b.size()) {
    for(int i=0;i<b.size();i++) {
      cout<<a.at(i)<<b.at(i);
    }
    cout<<a.at(a.size()-1);
  }
  if(a.size()<b.size()) {
    for(int i=0;i<a.size();i++) {
      cout<<a.at(i)<<b.at(i);
    }
    cout<<b.at(b.size()-1);
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string s, st; cin >> s >> st;
	if (s == st) {
		cout << "Yes\n";
		return 0;
	}
	for (int i = 1; i < s.size(); i++) {
		if (st.substr(i, s.size() - i) + st.substr(0, i) == s) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int r,c,i,j;
    long long int sumt=0,sum1=0,sum2=0;
    long long int arr[1000][1000];
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            scanf("%lld",&arr[i][j]);
        }
    }
    for(i=0;i<r;i++)
        {
        for(j=0;j<c;j++)
        {
            printf("%lld ",arr[i][j]);
            sum1 = sum1+arr[i][j];
        }
        arr[i][j+1] = sum1;
        printf("%lld\n",arr[i][j+1]);
        arr[i][c] = sum1;
        sum1 = 0;
        }

        for(j=0;j<c;j++)
        {
        for(i=0;i<r;i++)
        {
            sum2 = sum2+arr[i][j];
        }
        arr[i+1][j] = sum2;
        printf("%lld ",arr[i+1][j]);
        sum2 = 0;
        }
        for(j=0;j<c;j++)
        {
             sum2 = 0;
        for(i=0;i<r;i++)
        {
            sum2 = sum2+arr[i][j];
        }
        sumt = sumt+sum2;
        }
        printf("%lld\n",sumt);
return 0;
}



Measured memory_bytes: 2204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b,c,ans=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)
				{
					ans++;
				}
			} 
		}
	}
	cout<<ans;
    return 0;	
} 	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N, W;
	cin >> N >> W;

	vector<vector<ll>> dp(N+1, vector <ll> (W+1, 0));
	for (int idx = 1; idx <= N; ++idx){
		ll w, v;
		cin >> w >> v;

		for (int weight = 0; weight <= W; ++weight){
			if (weight < w){
				dp[idx][weight] = dp[idx-1][weight];
			} else {
				dp[idx][weight] = max(dp[idx-1][weight], dp[idx-1][weight-w] + v);
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}


Measured memory_bytes: 80256
#include <iostream>

auto max_bit(int n){
  for(int i = 31; i >= 0; i--) if(n>>i) return i+1;
  return 0;
}

auto bit_count(int n){
  int ans = 0;
  for(int i = 0; i < 32; i++){
    if((n>>i)&1) ans++;
  }
  return ans;
}

int main(){
  int L;
  std::cin >> L;

  int mn = max_bit(L)-1;
  std::cout << mn+1 << " " << bit_count(L)-1+2*mn << std::endl;
  int add_cum = 0;
  for(int i = 0; i < mn; i++){
    if((L>>i)&1){
      std::cout << i+1 << " " << mn+1 << " " << (1<<mn)+add_cum << "\n";
      add_cum += (1<<i);
    }
    std::cout << i+1 << " " << i+2 << " " << (1<<i) << "\n";
    std::cout << i+1 << " " << i+2 << " " << 0 << "\n";
  }


  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            
            if(H==0 && W==0) return;
            for(int y=0; y<H; y++){
                for(int x=0; x<W; x++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



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

int main() {
    int n;
    double d;
    cin >> n >> d;
    int answer = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        double z = sqrt(x*x + y*y);
        if(z <= d) answer++;
    }
    cout << answer << endl;
}


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

using Lint=long long;
const int mod=1e9+7;

int main()
{
    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    Lint ans=1;
    vector<int> cnt(N+1);
    cnt[0]=3;
    for(int i=0;i<N;i++){
        ans=ans*cnt[a[i]]%mod;
        cnt[a[i]]--;
        cnt[a[i]+1]++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	double low = 1000000.0, high = 0.0;
	double n;
	while (cin >> n) {
		if (n < low) {
			low = n;
		}
		if (high < n) {
			high = n;
		}
	}
	cout << high - low << endl;
}

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

string s[301];

signed main () {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) 
        cin >> s[i];
    int ans = 0;
    for (int iter = 0; iter < n; ++iter) {
        for (int i = 0; i < n; ++i) 
            rotate(s[i].begin(), s[i].begin() + 1, s[i].end());
        bool fl = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) 
                fl &= (s[i][j] == s[j][i]);
        }
        ans += fl;
    }
    cout << ans * n << "\n";
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
typedef long long int lli;
const int inf = 1e9;

vector<lli> shortest_path(int from, vector<vector<pair<int,lli>>> &graph){
    int n = graph.size();
    vector<lli> mincost(n, inf);
    mincost[from] = 0;
    priority_queue<pair<lli,int>> wait;
    wait.push({0LL, from});
    while(!wait.empty()){
        lli cost = -wait.top().first;
        int pos = wait.top().second;
        wait.pop();
        if(cost > mincost[pos]) continue;
        for(auto next: graph[pos]){
            lli ncost = cost + next.second;
            int npos = next.first;
            if(ncost < mincost[npos]){
                mincost[npos] = ncost;
                wait.push({-ncost, npos});
            }
        }
    }
    return mincost;
}

int main(){
    int n,s[3];
    cin >> n >> s[0] >> s[1] >> s[2];
    vector<int> sh(3, inf);
    vector<int> col(n, -1);
    for(int i=0; i<3; i++){
        for(int j=0; j<s[i]; j++){
            int a;
            cin >> a;
            a--;
            col[a] = i;
            sh[i] = min(sh[i], a);
        }
    }
    int m;
    cin >> m;
    vector<vector<pair<int, lli>>> g(n);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(col[a] != -1) a = sh[col[a]];
        if(col[b] != -1) b = sh[col[b]];
        g[a].emplace_back(b, 1);
        g[b].emplace_back(a, 1);
    }
    vector<vector<lli>> mincost(3);
    for(int i=0; i<3; i++){
        mincost[i] = shortest_path(sh[i], g);
    }

    pair<lli, int> ans(inf, n);
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<2; k++){
                lli tmpcost = mincost[j][i] +mincost[(j+1)%3][i] +mincost[(j+2)%3][sh[(j+k)%3]];
                ans = min(ans, {tmpcost, i});
            }
        }
        lli tmpcost = mincost[0][i] +mincost[1][i] +mincost[2][i];
        ans = min(ans, {tmpcost, i});
    }
    for(int i=0; i<n; i++){
        lli tmpcost = mincost[0][i] +mincost[1][i] +mincost[2][i];
        if(tmpcost > ans.first) continue;
        auto from_i = shortest_path(i, g);
        for(int j=0; j<ans.second; j++){
            for(int k=0; k<3; k++){
                if(mincost[k][i] == mincost[k][j] +from_i[j]){
                    ans.second = j;
                    break;
                }
            }
        }
    }
    cout << ans.first << " " << ans.second +1 << endl;
    return 0;
}



Measured memory_bytes: 29324
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;

vector<lli> fac(2000010);
vector<lli> inv(2000010);

lli rep_pow(lli x, lli p, lli m = 1000000007)
{
	lli res = 1;
	while (p > 0)
	{
		if ((p & 1) == 1) res = (res * x) % m;
		x = (x * x) % m;
		p >>= 1;
	}
	return res % m;
}

lli conb(lli n, lli r) {
	lli ret = (fac[n] * inv[r]) % inf;
	ret = (ret * inv[n - r]) % inf;
	return ret;
}

lli g(int r, int c) {
	return conb(r + c + 2, c + 1) - 1;
}

void solve() {
	int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	// パスカルの気持ち
	r1 -= 1;
	c1 -= 1;

	// 階乗とその逆元を前計算
	inv[0] = inv[1] = fac[0] = fac[1] = 1;
	for (int i = 2; i <= 2000005; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= inf;
		inv[i] = rep_pow(fac[i], inf - 2);
	}

	lli ans = g(r2, c2) - g(r1, c2) - g(r2, c1) + g(r1, c1);
	while (ans < 0) { ans += inf; }
	cout << (ans % inf) << endl;

}

int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main(){
    int N,K,ans=0; cin >> N >> K;
    int A[N+10];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }N-=K;
    ans+=1;
    if(N%(K-1)==0) ans+=N/(K-1);
    else ans +=N/(K-1)+1;
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}


int main(){
	int n;
	ll a[100100];
	ll min=INFl;
	ll ans=0;
	int count=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<0)count++;
		ll t=abs(a[i]);
		ans+=t;
		if(t<min)min=t;
	}
	if(count%2==1){
		ans=ans-(2*min);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
n,m = list(map(int,input().split()))
V=[[] for _ in range(n)]
for _ in range(m):
    a,b=list(map(int,input().split()))
    V[a-1].append(b-1)
    V[b-1].append(a-1)

def solve(path,i,cnt):
    if cnt==n:return 1
    path=list(path)
    path[i]=True
    ans=0
    for v in V[i]:
        if path[v]:continue        
        ans+=solve(tuple(path),v,cnt+1)
    return ans

print(solve([False]*n,0,1))



Measured memory_bytes: 3064
a,b,k=map(int,input().split())
s=set()
x=1
while(x*x<=a):
  if(a%x==0):
    s.add(x)
  if(a//x!=x and a%(a//x)==0):
    s.add(a//x)
  x+=1
x=1
while(x*x<=b):
  if(b%x==0):
    s.add(x)
  if(b//x!=x and b%(b//x)==0):
    s.add(b//x)
  x+=1
s=list(sorted(s))
s.sort(reverse=True)
count=0
for i in range(len(s)):
    if(a%s[i]==0 and b%s[i]==0):
        count+=1
    if(count==k):
        print(s[i])
        exit()

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX_N 100 + 2
#define MAX_T 40000

int t[MAX_N];
double v[MAX_N], f[MAX_T];

double min(double a, double b)
{
    return a < b? a: b;
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &t[i]);
    for (int i = 0; i < n; i++)
        scanf("%lf", &v[i]);
    for (int i = 0; i < MAX_T; i++)
        f[i] = 1.E8;
    int tot = 0;
    for (int i = 0; i < n; i++) {
        t[i] *= 2;
        for (int j = tot; j <= tot + t[i]; j++)
            f[j] = min(f[j], v[i]);
        tot += t[i];
    }
    f[0] = f[tot] = 0.;
    for (int i = 1; i <= tot; i++)
        f[i] = min(f[i], f[i - 1] + .5);
    for (int i = tot - 1; i >= 0; i--)
        f[i] = min(f[i], f[i + 1] + .5);
    double ans = 0.;
    for (int i = 0; i < tot; i++)
        ans += .25 * (f[i] + f[i + 1]);
    printf("%f\n", ans);
    return 0;
}


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

int main(){
	string s, t;
	getline(cin, s);
	getline(cin, t);
	int count = 0;
	for(int i=0; i<s.length();i++){
		if(s[i]!=t[i]){
			count++;
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3852
#include<stdio.h>
int main()
{
	int a,b,c,k,d=0,i=0,e=0;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	if(a>=k) printf("%d\n",k);
	else if(a+b>=k) printf("%d\n",a);
	else printf("%d\n",a-(k-a-b));
	return 0;
}

Measured memory_bytes: 1708
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int count = int.Parse(ReadLine());
        int[] input = MyUtil.ReadIntArray();

        int max = input.Max();
        int sum = input.Sum() - max;

        WriteLine(max < sum ? "Yes" : "No");

        ReadKey();
    }
}


static class MyUtil
{
    public static int[] ReadIntArray()
    {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int L = 111;
const int N = 26;

ll inf = 1e18;
ll d[N][L][N];
ll g[N][N];


void mul(ll a[N][N], ll b[N][N]){
	static ll t[N][N];
	
	for(int i=0;i<N;++i)
	for(int j=0;j<N;++j){
		ll s = inf;
		for(int k=0;k<N;++k) s = min(s, a[i][k]+b[k][j]);
		t[i][j] = s;
	}
	
	for(int i=0;i<N;++i) for(int j=0;j<N;++j) a[i][j]=t[i][j];
}

void mpow(ll a[N][N], ll n){
	static ll r[N][N];
	for(int i=0;i<N;++i) for(int j=0;j<N;++j) r[i][j] = i==j ? 0 : inf;
	while(n>0){
		if(n&1) mul(r,a);
		n>>=1;
		mul(a,a);
	}
	for(int i=0;i<N;++i) for(int j=0;j<N;++j) a[i][j]=r[i][j];
}


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, K;
	
	string s;
	cin>>s>>K;
	
	n = s.size();
	
	for(int f=0;f<N;++f){
		for(int x=0;x<N;++x) d[f][0][x] = inf;
		d[f][0][f] = (s[0]==f+'a' ? 0 : 1);
		for(int i=1;i<n;++i){
			for(int x=0;x<N;++x){
				ll res = inf, add = (s[i]==x+'a'?0:1);
				for(int y=0;y<N;++y) if(x!=y){
					res = min(res, d[f][i-1][y]+add);
				}
				d[f][i][x] = res;
			}
		}
	}
	
	for(int x=0;x<N;++x)
	for(int y=0;y<N;++y){
		g[x][y] = inf;
		for(int z=0;z<N;++z) if(z!=x){
			g[x][y] = min(g[x][y], d[z][n-1][y]);
		}
	}
	
	
	mpow(g, K-1);
	
	/*for(int i=0;i<N;++i){
		for(int j=0;j<N;++j) cout<<g[i][j]<< ' ';
		cout<<endl;
	}*/
	
	ll ans = inf;
	for(int f=0;f<N;++f)
	for(int x=0;x<N;++x)
	for(int y=0;y<N;++y){
		ll cur = d[f][n-1][x];
		cur+=g[x][y];
		ans = min(ans, cur);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        a[i]--;
        if(ans==a[i]){
            ans++;
        }
    }
    if(ans==0){
    cout<<"-1"<<endl;
    return 0;
    }
    cout<<n-ans<<endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> p(n);
    for (int i = 0; i < n; i++) std::cin >> p[i];
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            std::swap(p[i], p[j]);
            bool flag = true;
            for (int k = 0; k < n - 1; k++) flag &= p[k] < p[k + 1];
            if (flag) {
                std::cout << "YES" << std::endl;
                return 0;
            }
            std::swap(p[i], p[j]);
        }
    }
    bool flag = true;
    for (int k = 0; k < n - 1; k++) flag &= p[k] < p[k + 1];
    if (flag) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n,k;cin>>n>>k;
    V<ll>b(n);
    for(ll i=0;i<n;i++){
        cin>>b[i];
        b[i]--;
    }
    ll cnt=1;
    V<ll>loop;
    ll a=0;
    loop.pb(a);
    map<ll,ll>m;
    m[a]++;
    ll now=b[a];
    ll alr=0;
    while(m[now]==0){
        cnt++;
        m[now]=cnt;
        loop.pb(now);
        //cout<<now<<endl;
        now=b[now];
        if(m[now]){
            alr = m[now]-1;
        }
    }
    //cout<<cnt<<" "<<alr<<Endl;
    if(k<=alr)cout<<loop[k]+1<<endl;
    else{
        k-=alr;
        k%=(cnt-alr);
        cout<<loop[alr+k]+1<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 18568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		if(n == 1){
			System.out.println(1);
		}else if(2 <= n && n < 4){
			System.out.println(2);
		}else if(4 <= n && n < 8){
			System.out.println(4);
		}else if(8 <= n && n < 16){
			System.out.println(8);
		}else if(16 <= n && n < 32){
			System.out.println(16);
		}else if(32 <= n && n < 64){
			System.out.println(32);
		}else{
			System.out.println(64);
		}
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

template <class Iterator>
long long inversion_number(Iterator from, Iterator to) {
    if (to - from < 2) {
        return 0;
    }
    const auto mid = from + (to - from) / 2;
    long long ans = 0;
    ans += inversion_number(from, mid);
    ans += inversion_number(mid, to);
    auto fp = from;
    auto sp = mid;
    while (fp < mid && sp < to) {
        if (*sp < *fp) {
            ans += mid - fp;
            sp++;
        } else {
            fp++;
        }
    }
    sort(from, to);
    return ans;
}

template <class T>
long long inversion_number(const vector<T>& arr) {
    vector<T> copy(arr);
    return inversion_number(copy.begin(), copy.end());
}

li pow(li x, li n) {
    if (n == 0) {
        return 1;
    }
    li sq = pow(x, n / 2);
    li ans = sq * sq % mod;
    if (n & 1) {
        ans = ans * x % mod;
    }
    return ans;
}

li inv(li x) {
    return pow(x, mod - 2);
}

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

    li n, k;
    cin >> n >> k;
    vector<li> xs(n);
    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }

    li inv_count = inversion_number(xs);
    reverse(xs.begin(), xs.end());
    li ord_count = inversion_number(xs);
    li ans = inv_count * k % mod * (k + 1) % mod * inv(2) % mod;
    ans += ord_count * k % mod * (k - 1) % mod * inv(2) % mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int matrix[10][10] = {};
int flag[10] = {};
int n;
int ans = 0;

int check(int num)
{
    int i;
    int flagb = 1;
    for (i = 1; i <= n; i++)
    {
        if (flag[i] == 0)
        {
            flagb = 0;
        }
        else if (flag[i] > num)
        {
            //flag[i] = 0;
        }
    }
    return flagb;
}

void route(int j, int i, int num)
{
    int k;
    if (matrix[j][i] == 1 && flag[i] == 0)
    {
        flag[i] = num;
        int a = check(num);
        ans += a;
        for (k = 2; k <= n; k++)
        {
            route(i, k, num + 1);
        }
        flag[i] = 0;
    }
}

int main()
{
    int m;
    scanf("%d %d", &n, &m);
    int i, j, k;
    for (k = 0; k < m; k++)
    {
        scanf("%d %d", &i, &j);
        matrix[i][j] = 1;
        matrix[j][i] = 1;
    }
    for (i = 2; i <= n; i++)
    {
        flag[1] = 1;
        route(1, i, 2);
        for (j = 1; j <= n; j++)
        {
            flag[j] = 0;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define pb push_back
#define pop pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define arrin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define arrout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
//ll mod = 1000000007;
int s[1000001] = {0};
int check[1000001] = {0};
void sieve() {
	int maxn = 1000000;
	for (int i = 1; i <= maxn; i++)s[i] = -1;
	for (int i = 2; i <= maxn; i++) {
		if (s[i] == -1) {
			for (int j = i; j <= maxn; j += i) {
				if (s[j] == -1)s[j] = i;
			}
		}
	}

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	sieve();
	int n; cin >> n; int a[n]; arrin(a, n, 0);
	int setg = a[0], flag = 1;
	//bitset <1000001> f[n];
	FOR(i, 1, n)setg = __gcd(setg, a[i]);
	FOR(i, 0, n) {
		vec <int> v;
		while (a[i] != 1) {
			if (binary_search(all(v), s[a[i]]) == false)v.pb(s[a[i]]);
			a[i] /= s[a[i]];
		}// gcd =1 means no common factor -> start from 1th element store its factors and visit or check[fact]=1
		// now move forward and find factors if check[fact]is already one means they share common factor-> flag =0 br; else
		// mark that fact as check[fact]=1;
		FOR(k, 0, v.size()) {
			if (check[v[k]] == 0)check[v[k]] = 1;
			else flag = 0;

		}
		if (flag == 0)br;

	}
	if (flag == 1)cout << "pairwise coprime\n";
	elif(flag == 0 && setg == 1)cout << "setwise coprime\n";
	else cout << "not coprime\n";

}


Measured memory_bytes: 11772
// ボトルネックのところにすべてが依存するのはわかったが 立式できなかった

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

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

  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  cout << ll(ceil(double(n) / min(a, min(min(b, c), min(d, e))))) + 4 << endl;
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

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

	int N=in();
	auto P=vecin(N);
	sort(ALL(P));
	if(N%2){
		if(P[0]){
			out(0);
			return 0;
		}
		int v=2,k=0;
		for(int i=1;i<N;i+=2){
			if(P[i]!=v || P[i+1]!=v){
				out(0);
				return 0;
			}
			k++;
			v+=2;
		}
		out(powermod(2,k,atcoder_mod));
	}
	else{
		int v=1,k=0;
		for(int i=0;i<N;i+=2){
			if(P[i]!=v || P[i+1]!=v){
				out(0);
				return 0;
			}
			k++;
			v+=2;
		}
		out(powermod(2,k,atcoder_mod));
	}
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int judge = 0;
        for(int i = 1; i <= n ; i++)
        {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
            }
            while(x > 0)
            {
                if(x % 10 == 3)
                {
                    System.out.print(" " + i);
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 28940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	int x,a,b;
	cin>>x>>a>>b;
	int y=x;
	y=y-a+b;
	if(y<=x) puts("delicious");
	else if(y<=2*x) puts("safe");
	else puts("dangerous"); 
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct UF{
    vector<int > par,sz;

    UF(int n){
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i]=i;
            sz[i]=1;
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    bool unit(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y) return false;
        if(sz[x]>sz[y]){
            par[y]=x;
            sz[x]+=sz[y];
        }
        else{
            par[x]=y;
            sz[y]+=sz[x];
        }
        return true;
    }

    bool same(int x, int y){return find(x)==find(y);}
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m,k,a,b;
    in>>n>>m>>k;
    UF uf(n);
    vector<int> ans(n,-1);
    fr(i,m){
        in>>a>>b;
        uf.unit(--a,--b);
        --ans[a];
        --ans[b];
    }
    fr(i,n) ans[i]+=uf.sz[uf.find(i)];
    fr(i,k){
        in>>a>>b;
        if(uf.same(--a,--b)){
            --ans[a];
            --ans[b];
        }
    }
    fr(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}

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

int main(){

    int a;
    cin >> a;
    int total=0;
    
    for(int i=0; i<a; i++){
        int y, m, d;
        cin >> y >> m >> d;
        total = 0;
        
        for(int j=1; j<y; j++){
            
            if(j%3 == 0){
                total = total + 200;
            }else{
                total = total + 195;
            }
        }//ここまで年
        
        if(y%3 == 0){
            total = total + ((m-1)*20);
        }else{
            for(int j=1; j<m; j++){
                if(j%2 == 0){
                    total = total + 19;
                }else{
                    total = total + 20;
                }
            }
        }//ここまで月
        
        total = total + d;//ここ日
        
      total = 196471 - total;
      cout << total << endl;
      }         
}


Measured memory_bytes: 3108
// https://atcoder.jp/contests/abc054/tasks/abc054_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  VVL edge_mat(N, VL(N));
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    edge_mat[a][b] = 1;
    edge_mat[b][a] = 1;
  }

  ll res = 0;
  VL nodes(N);
  rep(i, N) nodes[i] = i;

  do {
    unless(nodes.front() == 0) continue;

    ll ok = true;

    rep(i, N - 1) { unless(edge_mat[nodes[i]][nodes[i + 1]]) ok = false; }

    if (ok) res++;
  } while (next_permutation(all(nodes)));

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;cin>>a>>b;
bool odd=true;

for (int i = 1; i < 4; i++)
{
    /* code */
    if (a*b*i%2!=0)
    {
        /* code */
        odd=false;
        cout<<"Yes"<<endl;
        break;
    }
    

}

if (odd)
{
    /* code */
    cout<<"No"<<endl;
}

}

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

int N;
map<int,int> mp;

int main(){
	cin>>N;
	REP(i,N){
		int a;
		cin>>a;
		mp[a]++;
	}
	int ans=0;
	for(auto i:mp){
		if (i.first!=i.second){
			if (i.first<i.second){
				ans+=i.second-i.first;
			}else{
				ans+=i.second;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout<<(max({a+b,a-b,a*b}))<<endl;
	return 0;
}


Measured memory_bytes: 256