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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll res1 = a[n-1];
    ll res2;
    ll min_dist = 1e10;
    REP(i, n-1){
        if(abs(a[i]-(res1+1)/2)<min_dist){
            min_dist = abs(a[i]-(res1+1)/2);
            res2 = a[i];
        }
    }
    cout << res1 << " " << res2 << endl;
    return 0;
}

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

typedef long long int lli;
typedef pair<lli,lli> PII;

#define M 100005
#define ep emplace_back
#define mp make_pair

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

//	freopen("input.txt","rt",stdin);
	
	set<lli> s;
	
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		lli x;
		cin>>x;
		s.insert(x);
	}
	
	if(n == (int)s.size())
		cout<<"YES";
	else
		cout<<"NO";
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> d(n);rep(i,n)cin>>d[i];
    if(n>=24){
        cout<<0<<endl;
        return 0;
    }
    int ans = 0;
    for(int i=0; i<1<<(n-1); i++){
        vector<int> D(24,0);
        D[0]++;
        D[d[0]]++;
        for(int j=0; j<n-1; j++){
            if(d[j+1]==0)D[0]++;
            else if(i>>j&1)D[d[j+1]]++;
            else D[24-d[j+1]]++;
        }
        int now = 0, M = 12;
        for(int j:D)if(j>=2)M=0;
        for(int j=1; j<24; j++){
            if(D[j]){M=min(M,j-now);now=j;}
        }
        M=min(M,24-now);
        ans=max(ans,M);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  
  if(((A < C) && (C < B)) || ((B < C) && (C < A)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main()
{
	int a,b,c,d,sum=0;
	char s[100];

	cin>>a>>b>>c;

	if(a+b>=c)
		cout<<"Yes";
	else
	{
		cout<<"No";
	}
	
	
	
	return 0;
}
	
	
	

	

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

int main()
{
  int a, b;
  cin >> a >> b;
    
  if (0 == (a * b) % 2)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
map<int,bool> mp;
vi p;
bool isprime(int x){
	if(x<2)
	re false;
	for(int i=2;i*i<=x;i++){
		if(x%i==0)
		re false;
	}
	re true;
}
int n;
int a[1000001];
int main(){
	ios::sync_with_stdio(0);
	forn(i,2,1001)
	if(isprime(i))
	p.pb(i);
	cin>>n;
	rep(i,n)
	cin>>a[i];
	sort(a,a+n);
	int gd=a[0];
	forn(i,1,n)
	gd=__gcd(gd,a[i]);
	if(gd!=1){
		cout<<"not coprime";
		re 0;
	}
	rep(i,n){
		int now=0;
		while(a[i]>1){
			if(isprime(a[i])){
				if(mp[a[i]]){
					cout<<"setwise coprime";
					re 0;
				}
				mp[a[i]]=true;;
				break;
			}
			while(now<sz(p)&&a[i]%p[now])
			now++;
			if(mp[p[now]]){
				cout<<"setwise coprime";
				re 0;
			}
			mp[p[now]]=true;;
			while(a[i]%p[now]==0)
			a[i]/=p[now];
		}
	}
	cout<<"pairwise coprime";
	re 0;
}


Measured memory_bytes: 7612
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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 namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  vector<char> t(q);
  vector<char> d(q);

  rep(i,q) {cin>>t[i]; cin>>d[i];}
  
  vector< vector<ll> > num_pos(26,vector<ll>(0));

  map<ll,ll> uni;
  rep(i,n){
    //uni.insert( make_pair(i,1) );
    uni[i]=1;
  }

  ll ans=0;

  
  rep(lr,2){
    //cout << "lr:" << lr << endl;
    ll l,r;
    l=0;
    r=n-1;
    ll cand;
    ll last;
    last=0;

    if(lr==0) cand=-1;
    else cand=n;
    
    while(l<=r && !last){
      //cout << l << "," << r << endl;
      ll comp;
      ll piv;

      if(l==r) last=1;
      
      comp=0;
      piv=(l+r)/2;

      ll cur;
      cur=piv;

      rep(i,q){

        if( t[i] == s[cur] ){

          if( d[i]=='L' ){
            if(cur==0){
              if(lr==0) comp=1;
              break;
            }
            else{
              cur--;
            }
          }
          else{
            if(cur==n-1){
              if(lr==1) comp=1;
              break;
            }
            else{
              cur++;
            }
          }

        }

      }
      if(lr==0){
        if(comp==1){
          //cout<< "0:" << piv << ",Hit!" << endl;
          cand=piv;
          l=piv+1;
        }
        else{
          //cout<< "0:" << piv << ",No hit" << endl;
          r=piv;
        }
      }
      else{
        if(comp==1){
          //cout<< "1:" << piv << ",Hit!" << endl;
          cand=piv;
          r=piv;
        }
        else{
          //cout<< "1:" << piv << ",No hit" << endl;
          l=piv+1;
        }
      }
      

    }
    //cout<< "cand:" << cand << endl;
    if(lr==0) ans+=cand+1;
    else ans+=n-cand;
    
  }
  //ans+=l;

  cout << n-ans << endl;

  return 0;

}


Measured memory_bytes: 13316
function Main(input){
  input = input.split('\n');
  var N = Number(input[0]);
  var a = input[1].split(' ').map((a)=>Number(a)).sort((a,b)=>b-a);
  var max = 0;
  for(var i=0;i<2*N;i++){
    if((i+1)%2==0){
      max+=a[i];
    }
  }
  console.log(max);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37588
def run(n, a):
    a = [a[i]-i-1 for i in range(len(a))]
    a.sort()
    m = a[int((n-1)/2)]
    ret = 0
    for ai in a:
        ret += abs(ai - m)
    return ret


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 26836
n = int(input())
s = input()
now = 0
for i in range(1, n):
    if s[i] == "E":
        now += 1
ans = now
for i in range(1, n):
    if s[i] == "E":
        now -= 1
    if s[i-1] == "W":
        now += 1
    ans = min(ans, now)
print(ans)

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n-2; i++) {
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
			++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
S_SEQUENCE = gets.chomp.to_i
S_ARRAY = gets.chomp.split(" ").map(&:to_i).sort
T_SEQUENCE = gets.chomp.to_i
T_ARRAY = gets.chomp.split(" ").map(&:to_i).sort

ans = 0

T_ARRAY.each do |val|
  left = 0
  right = S_ARRAY.count
  while left < right do
    mid = (left + right) / 2
    if S_ARRAY[mid] == val
      ans += 1
      break
    elsif val < S_ARRAY[mid]
      right = mid
    else # val < S_ARRAY[mid]
      left = mid + 1
    end
  end
end

p ans

Measured memory_bytes: 19820
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  string a,b;
  cin >> a >> b;
  int sz=a.size();
  map<int,int> mp;
  map<int,int> mpc;
  rep(i,sz){
    if(mpc.find(b[i]-'a')==mpc.end()){
      mpc.insert(make_pair(b[i]-'a',a[i]-'a'));
    } else {
      if(mpc.at(b[i]-'a')!=a[i]-'a'){cout << "No" << endl; return 0;}
    }
    
    if(mp.find(a[i]-'a')==mp.end()){
      mp.insert(make_pair(a[i]-'a',b[i]-'a'));
    } else {
      if(mp.at(a[i]-'a')!=b[i]-'a'){cout << "No" << endl; return 0;}
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    while( cin >> s ) {
        int jsum = 0, isum = 0;
        for( size_t i=0; i<s.size(); ++i ) {
            if ( s.compare( i, 3, "JOI" ) == 0 )
                ++jsum;
            if ( s.compare( i, 3, "IOI" ) == 0 )
                ++isum;
        }
        cout << jsum << endl << isum << endl;
    }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
typedef long long int ll;
int main()
{
    ll n,k,sum=0,sum1=0;
    string s;
    int a,b,c,d;
    cin>>n>>a>>b;
    k=a/n;
    if(n*k>=a&&n*k<=b||(n*(k+1))>=a&&(n*(k+1))<=b)
        cout<<"OK\n";
    else
        cout<<"NG\n";

}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, M; cin >> N >> M;
    vi X(M); REP(i, M) cin >> X[i];
    sort(ALL(X));
    if(N >= M)
    {
        cout << 0 << endl;
        return;
    }
    vi Y(M-1);
    for(int i = 0; i < M-1; i++)
    {
        Y[i] = X[i+1] - X[i];
    }
    sort(ALL(Y));
    int ans = 0;
    for(int i = 0; i < M-N; i++)
    {
        ans += Y[i];
    }
    cout << ans << endl;
}
    
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

int main() {
    int H, W;

    for ( ;; ) {
        cin >> H >> W;

        if ( H == 0 && W == 0 ) break;

        for (int i = 0; i < H; i++) {
            // cout << "Debug : " << i;
            for (int j = 0; j < W; j++ ) {
                if ( (i + j) % 2 == 0 ) {
                    cout << "#" ;
                } else {
                    cout << "." ;
                }
            }
            cout << '\n';
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
int main(){
  int n,k;
  std::cin >> n >> k;
  std::vector<long long>v(n),sum(n + 1);
  for(int i = 0; i < n; i++){
    std::cin >> v[i];
    v[i]--;
  }
  for(int i = 0; i < n; i++)sum[i + 1] = sum[i] + v[i];
  for(int i = 0; i <= n; i++)sum[i] %= k;
  std::map<long long,int>m;
  long long ans = 0;
  for(int i = 0; i <= n; i++){
    if(i >= k)m[sum[i - k]]--;
    ans += m[sum[i]];
    m[sum[i]]++;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}
int grid[110][110];

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> A(H*W);
  for(int i=0, j=0; i<N; ++i) {
    int a; cin >> a;
    for(int k=0; k<a; ++k) {
      A[j++] = i+1;
    }
  }
  int n = 0;
  rep(h,H) {
    rep(w, W) {
      if(h%2) grid[h][W-w-1] = A[n++];
      else grid[h][w] = A[n++];
    }
  }
  rep(h,H) {
    rep(w, W) {
      cout << grid[h][w] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LEN 100005


typedef struct {
  char name[11];
  int t;
}P;

void enqueue(P);
P dequeue(void);

P queue[LEN+1];
int head = 0;
int tail;



int main() {
  int n, q, i, time = 0;
  P data;

  scanf("%d%d", &n, &q);

  for (i = 0; i < n; i++) {
    scanf("%s", queue[i].name);
    scanf("%d", &queue[i].t);
  }

  tail = n;

  while (head != tail) {
    data = dequeue();
    if (data.t <= q) {
      time += data.t;
      printf("%s %d\n", data.name, time);
    }
    else if (data.t > q) {
      time += q;
      data.t -= q;
      enqueue(data);
    }
  }


  return 0;

}


void enqueue(P q) {
int next = (tail+1) % (LEN+1);

  if (next == head) {
    printf("Queue overflow!\n");
    exit(2);
  }
  strcpy(queue[tail].name, q.name);
  queue[tail].t = q.t;
  tail = next;
}


P dequeue(void) {
  P q;

  if (head == tail) {
    printf("Queue is empty!\n");
    exit(3);
  }
  q.t = queue[head].t;
  strcpy(q.name, queue[head].name);

  head = (head+1) % (LEN+1);
  return q;
}



Measured memory_bytes: 3240
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

using namespace std;

#define MAX_V 1000

struct edge{
	long long int to, cap, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
bool used[MAX_V];

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size() - 1}); // 有向辺
	// G[to].push_back((edge){from, cap, G[from].size() - 1}); // 無向辺
}

// 増加パスを dfs で探す
long long int dfs(int v, int t, long long int f){
	if(v == t){
		return f;
	}
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			long long int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// s から t への最大流を求める
long long int max_flow(int s, int t){
	long long int flow = 0;
	while(true){
		fill(used, used + MAX_V, 0);
		long long int f = dfs(s, t, INF);
		if(f == 0){
			return flow;
		}
		flow += f;
	}
}

int main(){
	
	int X, Y, E;
	cin >> X >> Y >> E;
	
	for(int i = 0; i < X; i++){
		add_edge(0, i + 1, 1);
	}
	
	for(int i = 0; i < Y; i++){
		add_edge(X + i + 1, X + Y + 1, 1);
	}
	
	for(int i = 0; i < E; i++){
		int u, v;
		cin >> u >> v;
		add_edge(u + 1, X + v + 1, 1);
	}
	
	cout << max_flow(0, X + Y + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 3616
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut cnt = 0;
    let mut flag = false;
    for i in s {
        if flag==false && i=='R' {
            cnt = 1;
            flag = true;
        } else if flag==true && i=='R' {
            cnt += 1;
        } else {
            flag = false;
        }
    }

    println!("{}", cnt);

}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

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

  const int N = 55555+1;
  bool prime[N];
  fill(prime, prime + N, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < N; ++i) {
    for (int j = 2; i * j < N; ++j) {
      prime[i * j] = false;
    }
  }
  vector<int> p;
  for (int i = 0; i < N; ++i) {
    if (prime[i]) p.push_back(i);
  }

  int n;
  while (cin >> n) {
    vector<int> v;
    for (int i = 0; i < p.size() && v.size() < n; ++i) {
      if (p[i] % 10 == 3) {
        v.push_back(p[i]);
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << v[i] << ' ';
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 384
n=int(input())
count=0
l=list(map(int,input().split()))
for i in range(n-1):
    if(l[i]-l[i+1]>0):
        count=count+(l[i]-l[i+1])
        l[i+1]=l[i+1]+(l[i]-l[i+1])
    
print(count)

Measured memory_bytes: 32064
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;

const LL M=1e9+7;
const int L=5001;
vector<int> ps[L];
int ww[L];
int N;
LL C[L][L];
LL F[L];
vector<int> cs;
int dfs(int i,int r){
	int s=1;
	bool center=true;
	for(auto p:ps[i]){
		if(p==r)continue;
		int v=dfs(p,i);
		if(v>N/2){
			center=false;
		}
		s+=v;
	}
	ww[i]=s;
	if(N-s>N/2){
		center=false;
	}
	if(center){
		cs.push_back(i);
	}
	//cerr << i << ", " << ww[i] << endl;
	return s;
}
LL dp[L][L];
int main() {
	cin >> N;
	for(int i=1;i<N;i++){
		int x,y;
		cin >> x >> y;
		ps[x].push_back(y);
		ps[y].push_back(x);
	}
	dfs(1,0);
	for(int i=0;i<L;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
		}
	}
	F[0]=1;
	for(int i=1;i<L;i++){
		F[i]=F[i-1]*i%M;
	}
	//cerr << cs.size() << endl;
	if(cs.size()==2){
		cout << F[N/2]*F[N/2]%M << endl;
		return 0;
	}
	int c=cs[0];
	for(auto p:ps[c]){
		if(ww[p]>ww[c]){
			ww[p]=N-ww[c];
		}
	}
	dp[0][0]=1;
	int sum=0;
	for(int i=0;i<ps[c].size();i++){
		auto w=ww[ps[c][i]];
		for(int j=0;j<=sum;j++){
			for(int k=0;k<=w;k++){
				dp[i+1][j+k]+=dp[i][j]*C[w][k]%M*C[w][k]%M*F[k]%M;
				dp[i+1][j+k]%=M;
			}
		}
		sum+=w;
	}
	int sg=1;
	LL ret=0;
	for(int i=0;i<=N;i++){
		//cerr << F[N-i] << ", " << dp[ps[c].size()][i] << endl;
		ret+=(M+sg)*F[N-i]%M*dp[ps[c].size()][i]%M;
		ret%=M;
		sg*=-1;
		//cerr << ret << endl;
	}
	cout << ret << endl;

	return 0;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,z,w;
  cin >> n >> z >> w;

  vll a(n);
  REP(i, n)
    cin >> a[i];

  if(n>=2)
  cout << max(abs(a[n-1]-w), abs(a[n-2]-a[n-1])) << endl;
  else
    cout << abs(a[0]-w) << endl;

}


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


int main(){
  int d, t, s;
  cin>>d>>t>>s;
  int meter=t*s;
  if(meter>=d)cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
}


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

string compress(string s, char c) {
  int n = s.size();
  string t = "";
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == c || s[i + 1] == c) {
      t += c;
    } else {
      t += s[i];
    }
  }
  return t;
}

bool isfinish(string s) {
  for (char c: s) {
    if (c != s.front()) return false;
  }
  return true;
}

int main() {
  int ans = 1e9;
  string s, t;
  cin >> s;
  for (char c = 'a'; c <= 'z'; c++) {
    t = string(s);
    int cnt = 0;
    while (1) {
      if (isfinish(t)) {
        ans = min(ans, cnt);
        break;
      }

      t = compress(t, c);
      cnt++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{ 
        
    public static void main(String[] args){
      
        Scanner sc = new Scanner(System.in);
                                               
        int N = sc.nextInt();
        
        int[] sticks = new int[N];
        
        for(int i = 0;i < N;i++){
            sticks[i] = sc.nextInt();
        }
        
        Arrays.sort(sticks);
                
        System.out.println(makeRectangle(sticks));
        
    }    
    
    static long makeRectangle(int[] sticks){
         
        int a = 0;
        int b = 0;
        int prev = -1; 
       
        for(int i = sticks.length - 1;i >= 0;i--){
            if(prev == sticks[i]){
                  if(a == 0){
                      a = sticks[i];
                      prev = -1;
                      continue;
                  }else{
                     b = sticks[i];
                     break;
                  }                
            }            
            prev = sticks[i];
        }
        
        return (long) a*b;
    }    
    
}       


Measured memory_bytes: 50324
import java.io.*;
import java.util.*;

class Main{
  static int count = 0;
  static int a = 1;
  static int[] list;

  final static int INF = 100;

  public static void main(String[] args)throws IOException{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(bf.readLine());
    int[][] G = new int[n+1][n];
    int[] d = new int[n+1];

    list = new int[n+1];

    for(int i=0 ; i<n ; i++){
      String[] str = bf.readLine().split(" ");
      int x = Integer.parseInt(str[0]);
      int y = Integer.parseInt(str[1]);
      d[x] = -1;

      for(int j=0 ; j<y ; j++){
        G[x][j] = Integer.parseInt(str[j+2]);
      }
    }

    d[1] = 0;
    list[0] = 1;

    search(G, d);

    for(int i=1 ; i<=n ; i++){
      System.out.println(i + " " + d[i]);
    }

  }

  static void search(int[][] G, int[] d){
    for(;count<a ; count++){
      int fr = list[count];

      for(int i=0 ; i<G[fr].length ; i++){
        int v = G[fr][i];
        if(d[v] == -1){
          d[v] = d[fr] + 1;
          list[a++] = v;
        }
      }
    }
  }
}



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

bool solve() {
    ll N;
    cin >> N;
    ll m = 0, h;
    for ( int i = 0; i < N; i++ ) {
        cin >> h;
        if ( h > m ) h--;
        if ( h < m ) return false;
        m = h;
    }
    return true;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, a, N) for(int i = a; i < N; i++)

int A, B, C, X, Y;

ll dfs(int x, int y, ll z){
    if (x >= X && y >= Y) return z;
    ll ret = 5000000000;

    if (x < X) {
        ret = min(ret, dfs(X, y, z + A * (X - x)));
        ret = min(ret, dfs(X, y + (X - x), z + C * (X - x) * 2));
    }

    if (y < Y) {
        ret = min(ret, dfs(x, Y, z + B * (Y - y)));
        ret = min(ret, dfs(x + (Y - y), Y, z + C * (Y - y) * 2));
    }

    return ret;
}

int main() {
    cin >> A >> B >> C >> X >> Y;
    cout << dfs(0, 0, 0) << endl;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  if(A > B){
    ans +=  A;
    A--;
  }
  else {
    ans +=  B;
    B--;
  }

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


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll T1, T2, A1, A2, B1, B2;
  std::cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

  ll P, Q;
  P = T1 * (A1 - B1);
  Q = T2 * (A2 - B2);
  if(P > 0) {
    P = -P;
    Q = -Q;
  }

  if(P + Q < 0) {
    std::cout << "0" << '\n';
    return 0;
  }
  if(P + Q == 0) {
    std::cout << "infinity" << '\n';
    return 0;
  }

  ll S = - P / (P + Q);
  ll T = - P % (P + Q);

  ll ans = 2 * S;
  if(T > 0) {
    ++ans;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(input())

p = [[0] * (w + 2) for i in range(h + 2)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            p[i][j] += 1
            p[i][j+1] += 1
            p[i][j+2] += 1
            p[i+1][j] += 1
            p[i+1][j+2] += 1
            p[i+2][j] += 1
            p[i+2][j+1] += 1
            p[i+2][j+2] += 1

for m in range(1, h+1):
    for n in range(1, w+1):
        i = m - 1
        j = n - 1
        if s[i][j] == '#':
            p[m][n] ='#'

for m in range(1, h+1):
    print(''.join(map(str, p[m][1:w+1])))

Measured memory_bytes: 9268
#include<bits/stdc++.h>
using namespace std;
int h,w,m;
vector<vector<int> >adj;
vector<int>height;
multiset<int>ms;
void add(int column)
{
	ms.erase(ms.find(height[column]));
	height[column]++;
	ms.insert(height[column]);
}
void sub(int column)
{
	ms.erase(ms.find(height[column]));
	height[column]--;
	ms.insert(height[column]);
}
int main()
{
	cin>>h>>w>>m;
	adj.resize(h);
	height.resize(w);
	for(int i=0; i<w; i++)
	 ms.insert(0);
	for(int i=0; i<m; i++){
		int r,c;
		cin>>r>>c;
		r--,c--;
		adj[r].push_back(c);
		add(c);
	}
	int ans=0;
	for(int i=0; i<h; i++)
	{
		int cnt=adj[i].size();
		for(auto var : adj[i]){
			sub(var);
		}
        auto it=ms.end();
        it--;
		cnt=cnt+*(it);
		ans=max(ans,cnt);
		for(auto var : adj[i]){
			add(var);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 34900
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
count = 0
for a in A:
    ans = 0
    for i in range(M):
        ans += a[i] * B[i]
    if ans + C > 0:
        count += 1
print(count)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long X, long long Y){
    cout << X + Y/2 << endl;
}

int main(){

    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}



Measured memory_bytes: 256
st = input()
N = len(st)
ans = 0
cnt = 0
i = 0
while i < N-1:
  if st[N-2-i:N-i] == "BC":
    cnt += 1
    i += 2
  elif st[N-1-i] ==  'A':
    ans += cnt
    i += 1
  else:
    cnt = 0
    i +=1
else:
  if st[0] == 'A':
    ans += cnt
  
print(ans)

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

using namespace std;
int main() {
  int x;
  cin >> x;
  vector<int> exp(x + 1);
  exp[1] = 1;
  for (int i = 2; i < x; i++) {
    int v = pow(i, 2);
    while (v <= x) {
      exp[v] = 1;
      v *= i;
    }
  }

  for (int i = x; i >= 1; i--) {
    if (exp[i]) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int i = 1;

		do {
			String num = br.readLine();

			if(Integer.parseInt(num) == 0){
				break;

			}else {
				System.out.println("Case"+" "+i+":"+" "+num);
				i++;
			}



		} while (i !=0);




	}

}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  char a, b, c;
  a = A.at(0);
  b = B.at(0);
  c = C.at(0);
  
  cout << a << b << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

bool v[10];
int ans;
int n,m;
vector<vector<int>> g;

void dfs(int from){
    bool ok = 1;
    rep(i,n){
        if(v[i]);
        else ok = 0;
    }
    if(ok){
        ans++;
        return;
    }
    for(auto x:g[from]){
        if(v[x])continue;
        v[x] = 1;
        dfs(x);
        v[x] = 0;
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n >> m;
    g.resize(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    v[0] = 1;
    dfs(0);
    v[0] = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
k = int(input())
s = input()
n = len(s)

MOD = 10**9+7
d = pow(26, -1, MOD)
ans = val = pow(26, k, MOD)
for i in range(1, k+1):
    val *= (i+n-1) * 25 * pow(i, -1, MOD) * d % MOD
    val %= MOD
    ans += val
    ans %= MOD
print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  int ans=0;
  while(1){
    int co=0;
    bool can = true;
    for(int i=0; i<n; i++){
      if(h[i] != 0){
        h[i]--;
        if(can){
          ans++;
          can = false;
        }
      }else{
        can = true;
        co++;
        continue;
      }
    }
    if(co == n){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int u[200010], v[200010];
ll ans;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n-1;i++) cin >> u[i] >> v[i];

    ans = 1LL*n*(n+1)*(n+2)/6;
    for (int i=0;i<n-1;i++) {
        if (u[i]>v[i]) swap(u[i], v[i]);
        ans -= 1LL*u[i]*(n-v[i]+1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5172
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n;
	cin>>n;
	vi a(4);
	REP(i,4){
		cin>>a[i];
	}
	int answidth=0;
	int ansval=INT_MAX;
	FOR(width,1,n+1){
		vvi f(width,vi(n/width+1));
		vector<pii> factories(4);
		int x=0,y=0;
		REP(i,n){
			REP(j,4){
				if(a[j]==i+1){
					factories[j].first=x;
					factories[j].second=y;
				}
			}
			x++;
			if(x==width){
				y++;
				x=0;
			}
		}
		int val=abs(factories[0].first-factories[1].first)+abs(factories[0].second-factories[1].second)+abs(factories[2].first-factories[3].first)+abs(factories[2].second-factories[3].second);
		if(ansval>val){
			ansval=val;
			answidth=width;
		}
	}
	cout<<ansval<<endl;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,C[10][10],ans=0;
  cin>>N;
  REP(i,10){
    REP(j,10){
      C[i][j]=0;
    }
  }
  
  RREP(i,N){
    ll A=i,B=i%10;
    while(A>=10) A/=10;
    C[A][B]++;
  }
  
  REP(i,10){
    REP(j,10){
      ans+=C[i][j]*C[j][i];
    }
  }
  co(ans);
  return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
  int h,m,s;
  scanf("%d",&s);
  h=s/3600;
  m=(s-h*3600)/60;
  s=s-h*3600-m*60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#define ll long long int
using namespace std;

int main(int argc, char const* argv[])
{
	int a, b, c, k;
	cin >> a >> b >> c;
	cin >> k;
	int max = a;
	int current = 0;
	if(max < b){
			max = b;
			current = 1;
	}
	if(max < c){
			max = c;
			current = 2;
	}
	if(current == 0){
			cout << a * (1 << k) + b + c << endl;
	}else if(current == 1){
			cout << a + b * (1 << k) + c << endl;
	}else{
			cout << a + b + (1 << k) * c << endl;
	}
	return 0;
}


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

#ifdef LOCAL
    #include "debug.h"
    #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    #define debug(...) 4
    #define input 4
#endif

using ll = long long;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;


int spf[N]; 
void sieve()  { 
    spf[1] = 1; 
    for (int i = 2; i < N; i++) 
        spf[i] = i; 
    for (int i = 4; i < N; i += 2) 
        spf[i] = 2; 
  
    for (int i = 3; 1LL * i * i < N; i++) { 
        if (spf[i] == i) { 
            for (int j = 1LL * i * i; j < N; j += i) 
                if (spf[j] == j) 
                    spf[j] = i; 
        } 
    } 
}
//optimized by logn of map;
vector<pair<int,int>> get(int x)  { 
    vector<pair<int, int>> ret;
    while (x != 1) { 
        if(ret.size() == 0) {
            ret.push_back(make_pair(spf[x], 1));
        
        }
        else {
            if(ret.back().first == spf[x]) {
                ret.back().second++;
            }
            else {
                ret.push_back(make_pair(spf[x], 1));
            }

        }
        
        x = x / spf[x]; 
    } 

    return ret;
    
} 


using T = int;
vector<T> BuildDivisorsFromFactors(const vector<pair<T, int>>& factors) {
    vector<T> divisors = {1};
    for (auto& p : factors) {
        int sz = (int) divisors.size();
        for (int i = 0; i < sz; i++) {
            T cur = divisors[i];
            for (int j = 0; j < p.second; j++) {
                cur *= p.first;
                divisors.push_back(cur);
            }
        }
    }
    sort(divisors.begin(), divisors.end());
    return divisors;
}
int f[N];
signed main() {
    input;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    sieve();
    int n;
    cin >> n;
    vector<int> a(n);
    int flag = 0;
    int g = 0;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        g = __gcd(g, a[i]);
    }
    if(g != 1) {
        cout << "not coprime";
        return 0;
    }
    map<int, vector<int>> cache;
    for(int i = 0; i < a.size(); i++) {
        if(cache.count(a[i])) {
            auto d = cache[a[i]];
            for(int i = 1; i < d.size(); i++) {
                if(f[d[i]] > 0) {
                    flag = 1;
                }
                f[d[i]]++;
            }
        }
        else {
            auto fac = get(a[i]);
            auto d = BuildDivisorsFromFactors(fac);
            cache[a[i]] = d;
            for(int i = 1; i < d.size(); i++) {
                if(f[d[i]] > 0) {
                    flag = 1;
                }
                f[d[i]]++;
            }
        }

    }
    if(flag == 0) {
        cout << "pairwise coprime";
    }
    else if(g == 1) {
        cout << "setwise coprime\n";
    }
    else {
        cout << "not coprime\n";
    }

}
  



Measured memory_bytes: 163208
#include <iostream>
#include<set>
#include<math.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    set <int> s;
    int tmp;
    
    rep(i, N){
        cin >> tmp;
        s.insert(tmp);
    }
    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string tcard, hcard;
	int tcount = 0, hcount = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tcard >> hcard;
		if (tcard == hcard) {
			tcount++;
			hcount++;
		} else if (tcard > hcard) {
			tcount += 3;
		} else {
			hcount += 3;
		}
	}
	cout << tcount << " " << hcount << endl;
	return 0;
}

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

int modPow(int x,int y,int q){
    if(y==1) return x%q;
    if(y%2!=0)return (x*modPow(x,y-1,q))%q;
    else return (x*modPow(x,y/2,q))%q;
}

int main(int argc,char* argv[]){
    int x;
    cin>>x;
    cout<<modPow(x,3,1e9+7)<<endl;
}


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

int main() {
    string N;
    cin >> N;
    bool ans = false;
    for (int i = 0; i < 3; i++) {
        if (N.at(i) == '7') {
            ans = true;
        }
    }

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

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=3;i++){
		if((a*b*i)%2==1){
			cout<<"Yes\n";
			return 0;
		}
	}cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		
		while(true){
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			
			if(h == 0 && w == 0){
				break;
			}

			for(int i = 0; i < h; i++){
				if(i == 0 || i % 2 == 0){
					for(int j = 0; j < w; j++){
						if(j == 0 || j % 2 == 0){
							sb.append("#");
						}else{
							sb.append(".");
						}
					}
					sb.append("\n");
				}else{
					for(int j = 0; j < w; j++){
						if(j == 0 || j % 2 == 0){
							sb.append(".");
						}else{
							sb.append("#");
						}
					}
					sb.append("\n");
				}
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27760
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include<iomanip>
#include<limits>
using namespace std;
int main(void){
   string s;
   cin>>s;
   int count=0;
   if(s.length()%2==0){
       string t=s.substr(0,s.length()/2);
       string u=s.substr(s.length()/2,s.length());
       for(int i=0;i<s.length()/2;i++){
           if(t[i]!=u[s.length()/2-i-1]){
               count++;
           }
       }
       cout<<count<<endl;
   }
   else{
       string t=s.substr(0,s.length()/2);
       string u=s.substr(s.length()/2+1,s.length());
       for(int i=0;i<s.length()/2;i++){
           if(t[i]!=u[s.length()/2-i-1]){
               count++;
           }
       }
       cout<<count<<endl;
   }
}


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

int main() {
	int N{};
	cin >> N;
	bool flg = false;
	string kind{};
	for (size_t i = 0;i < N;++i) {
		cin >> kind;
		if (kind.compare("Y")==0)
		{
			flg = true;
		}
	}

	if (flg) {
		cout << "Four";
	}
	else
	{
		cout << "Three";
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

int main(void){
    
    ll n,m;cin>>n>>m;
    vector<vector<ll>>v(8,vector<ll>(n));
    ll x,y,z;
    rep(i,n){
        cin>>x>>y>>z;
        v[0][i]=x+y+z;
        v[1][i]=x+y-z;
        v[2][i]=x-y+z;
        v[3][i]=x-y-z;
        v[4][i]=-x+y+z;
        v[5][i]=-x+y-z;
        v[6][i]=-x-y+z;
        v[7][i]=-x-y-z;
    }
    rep(i,8)sort(all(v[i]),greater<ll>());
    ll ans=0;ll com;
    rep(i,8){
        com=0;
        rep(j,m){
            com+=v[i][j];
        }
        ans=max(ans,com);
    }
    cout<<ans;
}

Measured memory_bytes: 256