akhauriyash/Code-Regression huggingface dataset:
/************
< 주소 >      :
*************
< 해결방안 >   :


*************
< 오답노트 >   :

*************/

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL_BOOKNU
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// ........................macro.......................... //
#define FOR(i, f, n) for(int (i) = (f); (i) < (int)(n); ++(i))
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (int)(n); --(i))
#define pb push_back
#define emb emplace_back
#define fi first
#define se second
#define ENDL '\n'
#define sz(A) (int)(A).size()
#define ALL(A) A.begin(), A.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define next next9876
#define prev prev1234
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef long long i64;
typedef unsigned long long ui64;
// inline i64 GCD(i64 a, i64 b) { if(b == 0) return a; return GCD(b, a % b); }
inline int getidx(const vi& ar, int x) { return lower_bound(ALL(ar), x) - ar.begin(); } // 좌표 압축에 사용: 정렬된 ar에서 x의 idx를 찾음
inline i64 GCD(i64 a, i64 b) { i64 n; if(a < b) swap(a, b); while(b != 0) { n = a % b; a = b; b = n; } return a; }
inline i64 LCM(i64 a, i64 b) { if(a == 0 || b == 0) return GCD(a, b); return a / GCD(a, b) * b; }
inline i64 CEIL(i64 n, i64 d) { return n / d + (i64)(n % d != 0); } // 음수일 때 이상하게 작동할 수 있음.
inline i64 ROUND(i64 n, i64 d) { return n / d + (i64)((n % d) * 2 >= d); }
inline i64 POW(i64 a, i64 n) {
	assert(0 <= n);
	i64 ret;
	for(ret = 1; n; a = a*a, n /= 2) { if(n%2) ret *= a; }
	return ret;
}
template <class T> ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class T> ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> p) { return os << "(" << p.fi << "," << p.se << ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H, debug_out(T...); }
// ....................................................... //

int vis[4];
void input() {
	int x, y;
	FOR(i, 0, 3) cin >> x >> y, vis[--x]++, vis[--y]++; 
}

int solve() {
	int cnt[4] = { 0 };
	FOR(i, 0, 4) ++cnt[vis[i]];
	if(cnt[2] == 2 && cnt[1] == 2) {
		cout << "YES" << ENDL;
		return 0;
	}
	cout << "NO" << ENDL;
	return 0;
}

// ................. main .................. //
void execute() {
	input(), solve();
}

int main(void) {
#ifdef LOCAL_BOOKNU
	freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	cin.tie(0), ios_base::sync_with_stdio(false);
	execute();
	return 0;
}
// ......................................... //

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int s = 0;
  for (auto &e : a) {
    cin >> e;
    s += e;
  }

  set<int> d;
  for (int i = 1; i * i <= s; i++) {
    if (s % i == 0) {
      d.insert(i);
      d.insert(s / i);
    }
  }

  int m = 1;
  for (auto e : d) {
    vector<int> v(n);
    for (int i = 0; i < n; i++) v[i] = a[i] % e;
    sort(begin(v), end(v));

    // for (auto ve : v) cerr << ve << ' ';
    // cerr << endl;

    int kt = k;
    for (int l = 0, r = n - 1; l < r;) {
      if (v[l] == 0) {
        l++;
      } else if (v[r] == e) {
        r--;
      } else {
        int t = min(v[l], e - v[r]);
        kt -= t;
        v[l] -= t;
        v[r] += t;
      }
    }

    // for (auto ve : v) cerr << ve << ' ';
    // cerr << endl;

    if (kt >= 0) m = e;
  }
  cout << m << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

lli gcd(lli a, lli b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main () {
    lli p, q;
    cin >> p >> q;
    lli t = gcd(p, q);
    q /= t;
    set<int> sl;
    lli num = q;
    for (int i = 2; i <= ceil(sqrt(q) + 1e-9); i++) {
        if (num % i == 0) {
            sl.insert(i);
            while (num % i == 0) num /= i;
        }
    }
    sl.insert(num);
    lli ans = 1;
    for (auto it : sl) ans *= it;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3096
#include<stdio.h>
#include<string.h>
int main(void){
  int i;
  int A[26]={0};
  char S[100001]={'\0'};
  scanf("%s",S);
  for(i=0;i<strlen(S);i++){
    A[S[i]-97]++;
  }
  for(i=0;i<26;i++){
    if(A[i]==0){
      printf("%c\n",97+i);
      return 0;
    }
  }
  printf("None\n");
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(int N, std::vector<int> P, std::vector<int> Q){
    vector <int> arr;
    string p;
    string q;
    REP(i, N){
        arr.PB(i+1);
        p+=to_string(P[i]);
        q+=to_string(Q[i]);
    }
    SORT(arr);
    string s;
    REP(i, N){
        s += to_string(arr[i]);
    }
    // cout<<s<<endl;
    vector <string > lists;
    do{
        lists.PB(s);
    }while(next_permutation(ALL(s)));
    SORT(lists);
    int idx1=0;
    int idx2=0;
    REP(i, lists.size()){
        if(lists[i]==p)idx1=i;
        if(lists[i]==q)idx2=i;
    }
    cout<<abs(idx1-idx2)<<endl;
}

int main(){
    int N;
    scanf("%d",&N);
    std::vector<int> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&P[i]);
    }
    std::vector<int> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    ll n;
    cin >> n;
    ll a[n], b[n];

    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    set<ll> st;
    rep2(i, 50) st.insert(i);

    REPM(s, 50, 1) {
        st.erase(s);
        ll d[51][51];

        rep3(i, 50) rep3(j, 50) {
            if (i == j) d[i][j] = 0;
            else d[i][j] = LINF;
        }
        for (auto a : st) {
            rep3(i, 50) d[i][i % a] = 1;
        }

        rep3(k, 50) rep3(i, 50) rep3(j, 50) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

        rep(i, n) {
            if (d[a[i]][b[i]] == LINF) {
                st.insert(s);
                break;
            }
        }

    }

    if (st.size() == 50) printf("-1\n");
    else {
        ll ans = 0;
        for (auto s : st) {
            ans += (ll) pow(2, s);
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=500100,P=998244353;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
ll m,k;
int i,n,a,b,fac[N],inv[N],ans;
inline int C(int n,int m){return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=read();a=read();b=read();scanf("%lld",&m);
	fac[0]=fac[1]=inv[1]=inv[0]=1;
	for(i=2;i<=n;i++)
		inv[i]=1ll*(P-P/i)*inv[P%i]%P;
	for(i=2;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%P,
		inv[i]=1ll*inv[i-1]*inv[i]%P;
	for(i=0;i<=n;i++){
		k=m-1ll*i*a;
		if(k<0||k%b)continue;
		k=k/b;if(k>n)continue;
		(ans+=1ll*C(n,i)*C(n,k)%P)%=P;
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

const int MAX_V=10001;
const int INF=1000000000;


class UnionFindTree{
public:
  // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う)
  vector<int> par;
  // indexを根とする木のランク
  vector<int> rank;
  // 木の最大値
  int treeSize;
  vector<bool> isBase;
  UnionFindTree(int initTreeSize = 1000){
    // 引数で与えられた値を最大格納数とするUnionFindTreeの作成
    treeSize = initTreeSize;
    init();
  }
  void init(){
    for(int i = 0; i < treeSize; i++){
      par.push_back(i);
      rank.push_back(0);
      isBase.push_back(false);
    }
  }
  // 与えられた数が格納されている木のルートを探索
  int find(int x){  
    if(par[x]==x)return x;
    else return par[x] = find(par[x]);
  }
  // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)
      return;
    if(rank[x] < rank[y]){
      par[x] = y;
      if(isBase[find(x)]||isBase[find(y)])
	isBase[find(x)]=true;
    }
    else{
      par[y] = x;
      if(isBase[find(x)]||isBase[find(y)])
	isBase[find(x)]=true;
      if(rank[y] == rank[x])rank[x]++;
    }
  }
  bool same(int x,int y){
    return find(x) == find(y);
  }
};

struct edge{
  int to;
  int cost;
  int idx;
};

vector<edge> G[MAX_V];
vector<int> bases;
bool used[MAX_V];
int n,t,k;
void prim(int V){
  priority_queue<int> cand;
  UnionFindTree uft(V+1);
  for(int i=0;i<MAX_V;i++)used[i]=false;
  for(int i=0;i<bases.size();i++)uft.isBase[bases[i]]=true;
  priority_queue<pair<pii,pii> > pq;
  for(int i=0;i<bases.size();i++){
    // 次の場所をコストとともに登録
    for(int j=0;j<G[bases[i]].size();j++){
      edge &e=G[bases[i]][j];
      if(used[e.idx])continue;
      used[e.idx]=true;
      pq.push(make_pair(pii(e.cost,e.idx),pii(e.to,bases[i])));
    }
  }
  while(pq.size()){
    pair<pii,pii> p=pq.top();pq.pop();
    int cost=p.first.first;
    int idx=p.first.second;
    int node=p.second.first;
    int from=p.second.second;
    // 今回のエッジを採用
    if(uft.isBase[uft.find(from)]
       &&uft.isBase[uft.find(node)])cand.push(-cost);
    uft.unite(from,node);
    // 今回登録したノードからいける場所を登録
    for(int i=0;i<G[node].size();i++){
      edge &e=G[node][i];
      if(used[e.idx])continue;
      used[e.idx]=true;
      pq.push(make_pair(pii(e.cost,e.idx),pii(e.to,node)));
    }
  }
  int res=0;
  for(int i=0;i<k;i++){
    res+=-cand.top();cand.pop();
  }
  cout<<res<<endl;
  cout<<flush;
}

int main(){
  int cnt=1;
  while(cin>>n>>t>>k&&(n|t|k)){
    for(int i=0;i<MAX_V;i++)G[i].clear();
    for(int i=0;i<n-1;i++){
      edge e;
      int a,b,c;
      cin>>a>>b>>c;
      e.to=a;
      e.cost=c;
      e.idx=i;
      G[b].push_back(e);
      e.to=b;
      G[a].push_back(e);
    }
    bases.clear();
    for(int i=0;i<t;i++){
      int a;
      cin>>a;
      bases.push_back(a);
    }
    cout<<"Case "<<cnt<<": ";
    prim(n);
    cnt++;
  }

  return 0;
}

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#include <string> 
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mid 2019
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
 
 
int main()
{
    fastio;
   
        ll count=0,abs=0,sum=0,index=-1,c=0;
       ll n,k,i,j,d;
       cin>>n>>k;
       ll h[n+1]={0};
       for(i=0;i<k;i++)
       {
           cin>>d;
           ll a[d];
           for(j=0;j<d;j++)
           cin>>a[j];
           
           for(j=0;j<d;j++)
           h[a[j]]++;
           
           
           
       }
       for(i=1;i<n+1;i++)
       {
           if(h[i]==0)
           count++;
       }
       cout<<count<<endl;
    
    
  

}

Measured memory_bytes: 3616
#include "stdio.h"
int main(void)
{
	int num[10000],tmp,i,count;
	for(i=0;;i++){
		scanf("%d",&num[i]);
		if(i%2 != 0 && i != 0){
			if(num[i-1] == 0 && num[i] == 0){
				count = i;
				break;
			}
			else if(num[i-1] > num[i]){
				tmp = num[i-1];
				num[i-1] = num[i];
				num[i] = tmp;
			}
		}
	}

	for(i=0;i<count-1;i++){
		printf("%d",num[i]);
		if(i%2==0)
			printf(" ");
		else
			printf("\n");
	}
	return 0;
	
}


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

int main(){
    int n ;
    cin >> n ;
    vector<int> a(n) ;
    vector<int> ans(n) ;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int sum = 0 ;
    for (int i = 0; i < n; i++)
    {
        sum += a.at(i) ;
    }
    ans.at(n-1) = sum ;
    for (int i = 0; i < n-1; i += 2)
    {
        ans.at(n-1) -= a.at(i)*2 ;
    }
    for (int i = n-2; i >= 0; i--)
    {
        ans.at(i) = 2 * a.at(i) - ans.at(i+1) ;
    }
    for (int i = 0; i < n-1; i++)
    {
        cout << ans.at(i) << " " ;
    }
    cout << ans.at(n-1) << endl;
    
    
    
    
    
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s,t;
    cin >> s >> t;
    ll ans = 0;
    for(i = 0;i < s.size();++i){
        if(s.at(i) != t.at(i)) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

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

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

double dist(vector<int> x, vector<int> y, int i, int j)
{
	return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
}

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

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

	int a = 0;
	int b = 0;
	int cnt = 1;
	do
	{
		int pCnt = 0;
		int qCnt = 0;
		for (int i = 0; i < n; i++)
		{
			if (vec[i] == p[i]) pCnt++;
			if (vec[i] == q[i]) qCnt++;
		}
		if (pCnt == n) a = cnt;
		if (qCnt == n) b = cnt;
		cnt++;
	} while (next_permutation(vec.begin(), vec.end()));

	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class ABC169C
    {
        const string FILE = @"..\..\data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            var line = Console.ReadLine();
            var sa = line.Split(' ');
            long a = long.Parse(sa[0]);
            string b = sa[1];
            var ba = b.Split('.');
            int b0 = int.Parse(ba[0]);

            char[] bpoint = ba[1].ToCharArray();


            int b1 = 0;
            int b2 = 0;
            if (bpoint.Length == 1)
            {
                b1 = int.Parse(bpoint[0].ToString());
            }
            if (bpoint.Length == 2)
            {
                b1 = int.Parse(bpoint[0].ToString());
                b2 = int.Parse(bpoint[1].ToString());
            }

//            long result = a * b0 + (a / 10) * b1 + (a / 100) * b2;
            long result = (a * b0 * 100) + (a * 10) * b1 + (a) * b2;
            result /= 100;
            Console.WriteLine(result);



#if DEBUG
            Console.WriteLine("end");
            Console.SetIn(Console.In);
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 27316
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    string color;
    int ans = 0;

    cin >> N >> color;

    for(int i=0; i<N; i++){
        if(color[i] != color[i+1]){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var m = o.a();
  var k = o.a();
  if(k >= (1 << m))return -1;
  if(k && m === 1)return -1;
  if(k === 0)return f0(m);
  var ans = [];
  var t = 1 << m;
  for(var i = 0, x = 0; i < t-1; i++, x++){
    if(x === k)x++;
    ans.push(x);
  }
  ans.push(k);
  for(var i = 0; i < t-1; i++){
    x--
    if(x === k)x--;
    ans.push(x);
  }
  ans.push(k);
  return ans.join(" ");
}
function f0(m){
  var t = 1 << m+1;
  var ans = [];
  for(var i = 0; i < t; i++){
    ans[i] = i >> 1;
  }
  return ans.join(" ");
}

Measured memory_bytes: 35532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            int N = IO.ReadLineToInt();
            var d = IO.ReadLineToIntList();

            d = d.OrderBy(o=>o).ToList();

            var ans = d[N / 2] - d[N / 2-1];

            //ここまで
            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(int n,int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 22112
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++i)

using namespace std;

vector<vector<int>> to;
vector<int> ans;

void dfs(int cur, int parent=-1) {
    for (int child: to[cur]) {
        if (child == parent) continue;
        ans[child] += ans[cur];
        dfs(child, cur);
    }
}


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

    to = vector<vector<int>>(n);
    int a, b;
    rep(i,n-1) {
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans = vector<int>(n);
    int p, x;
    rep(i,q) {
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);
    rep(i,n) cout << ans[i] << " ";

    return 0;
}

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

int main(){
int n;
  cin>>n;
	for(int a=1;a<=9;a++)for(int b=1;b<=9;b++){
	if(a*b==n){
	puts("Yes");
	return 0;
 	}
 }
 puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

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

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

	int x=0;

	rep(i, S.size()){
		if(S[i]=='x') x+=1;
	}

	if(x>=8) cout << "NO" << endl;
	else cout << "YES" << endl;


}


Measured memory_bytes: 256
#include <cassert>
#include "limits.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long double, long double>;

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

  ll n;
  std::cin>>n;

  std::vector<ll> inv(n+1,0);

  rep(i,1,n+1){
    inv[i]=(inv[i-1]+pow_mod(i,MOD-2,MOD))%MOD;
  }

  ll ans=0;

  rep(i,0,n){
    ll a;
    std::cin>>a;

    ll sum=(inv[i+1]+inv[n-i]+MOD-1)%MOD;
    ans=(ans+(a*sum)%MOD)%MOD;
  }

  rep(i,1,n+1){
    ans=(ans*i)%MOD;
  }

  std::cout<<ans<<"\n";

  return 0;
}




Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){
  int n; cin>>n;
  long long h[110000];

  for(int i=0; i<n; i++)
  cin>>h[i];
  int boo=0;
  for(int i=0; i<n-1;i++){
    if(h[i]==h[i+1]) continue;
    else if(h[i]<h[i+1]+1) h[i+1]--;
    else boo=1;
  }
  if(boo==1) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N;
ll A[200001];
ll s[30];

int main() {

	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	ll sum = 0;
	FOR(i,0,N){
		cin >> A[i];
		sum ^= A[i];
	}
	FOR(i, 0, 30) {
		s[i] = sum % 2;
		sum /= 2;
	}

	FOR(i, 0, N) {
		ll cur = 0;
		FOR(j, 0, 30) {
			if (A[i] % 2 != s[j]) {
				cur |= (1 << j);
			}
			A[i] /= 2;
		}
		cout << cur << endl;
	}



	return 0;
}


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

using namespace std;

#define N 300000

int main() {
	bool mpr[N] = {0};
	for(int i = 0; i < N; i++) {
		if(i%7 == 1 or i%7 == 6) {
			mpr[i] = 1;
		}
	}
	for(int i = 2; i < N; i++) {
		if(mpr[i]) {
			for(int j = i*2; j < N; j += i)
				mpr[j] = 0;
		}
	}

	int n;
	while(cin >> n && n != 1) {
		cout << n << ":";
		for(int i = 2; i < N; i++) {
			if(mpr[i] && n%i == 0)
				cout << " " << i;
		}
		cout << endl;
	}
	return 0;
}

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

class UnionFind
{
public:
    vector<long long> root;

    UnionFind(long long N)
    {
        this->root = vector<long long>(N + 1, -1);
    }

    long long find_root(long long A)
    {
        if (this->root[A] < 0)
        {
            return A;
        }
        else
        {
            this->root[A] = find_root(this->root[A]);
        }
        return this->root[A];
    }

    long long size(long long A)
    {
        return -this->root[find_root(A)];
    }

    bool unite(long long A, long long B)
    {
        A = find_root(A);
        B = find_root(B);
        if (A == B)
        {
            return false;
        }

        if (size(A) < size(B))
        {
            swap(A, B);
        }

        this->root[A] += this->root[B];
        this->root[B] = A;

        return true;
    }

    bool has_same_root(long long A, long long B)
    {
        return find_root(A) == find_root(B);
    }
};

int main()
{
    size_t N, M;
    cin >> N >> M;

    UnionFind uf(N);
    long long A, B;
    for (size_t i = 0; i < M; i++)
    {
        cin >> A >> B;
        uf.unite(A, B);
    }

    long long ans = 0;
    for (long long i = 1; i <= N; i++)
    {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4788
import Data.Bool
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
main=print.solve.map(unfoldr$B.readInt.B.dropWhile isSpace).B.lines=<<B.getContents
solve([n,k]:ab)=if odd k then r1 else r2 where
  d=k`div`2
  es=map(\[a,b]->(a-1,b-1))ab
  g=V.accum(flip(:))(V.replicate n[])$concatMap(\(a,b)->[(a,b),(b,a)])es
  r1=minimum$map(\(a,b)->f 0 a b+f 0 b a)es
  r2=minimum$map(\i->f 0 i i)[0..n-1]
  f i p v=foldr(+)(bool 0 1(i>d)).map(f(i+1)v).filter(/=p)$g V.! v

Measured memory_bytes: 6612
#-------最強ライブラリSCC(Python) ver25252------

import copy
import sys
sys.setrecursionlimit(1000000)

class csr:
  # start 頂点iまでの頂点が、矢元として現れた回数
  # elist 矢先のリストを矢元の昇順にしたもの
  def __init__(s, n, edges):
    s.start = [0] * (n + 1)
    s.elist = [[] for _ in range(len(edges))]
    for e in edges:
      s.start[e.frm + 1] += 1
    for i in range(1, n + 1):
      s.start[i] += s.start[i - 1]
    counter = copy.deepcopy(s.start)
    for e in edges:
      s.elist[counter[e.frm]] = e.to
      counter[e.frm] += 1

class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.edges = []
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): s.edges.append(s.edge(frm, to))

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    g = csr(s._n, s.edges)
    now_ord = group_num = 0
    visited = []
    low = [0] * s._n
    ord = [-1] * s._n
    ids = [0] * s._n
    # 再帰関数 
    def dfs(self, v, now_ord, group_num):
      low[v] = ord[v] = now_ord
      now_ord += 1
      visited.append(v)
      for i in range(g.start[v], g.start[v + 1]):
        to = g.elist[i]
        if ord[to] == -1:
          now_ord, group_num = self(self, to, now_ord, group_num)
          low[v] = min(low[v], low[to])
        else:
          low[v] = min(low[v], ord[to])
      if low[v] == ord[v]:
        while True:
          u = visited.pop()
          ord[u] = s._n
          ids[u] = group_num
          if u == v: break
        group_num += 1
      return now_ord, group_num

    for i in range(s._n):
      if ord[i] == -1: now_ord, group_num = dfs(dfs, i, now_ord, group_num)
    for i in range(s._n):
      ids[i] = group_num - 1 - ids[i]
    return [group_num, ids]

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

  class edge:
    def __init__(s, frm, to):
      s.frm = frm
      s.to = to


#-------最強ライブラリここまで------

def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()


Measured memory_bytes: 285520
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int N;
   cin >>N;
	int max=1;
   int min=1000000000;
   for(int i=0;i<N;i++){
     int A;
     cin >>A;
    if(A >max){
      max=A;
    }
     if(A < min){
       min=A;
      }
   }
   cout<< max - min << endl;
 }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*  scan  */
#define sd(a) scanf("%d",&a)
#define sc(a) scanf("%c",&a), getchar()
#define sf(a) scanf("%f",&a)
#define ss(a) scanf("%s",a)
#define sld(a) scanf("%lld",&a)
/*  print  */
#define odn(a) printf("%d\n",a)
#define oldn(a) printf("%lld\n",a)
#define ocn(a) printf("%c\n",a)
#define ofn(a) printf("%f\n",a)
#define osn(a) printf("%s\n",a)
#define od(a) printf("%d ",a)
#define old(a) printf("%lld\n",a)
#define oc(a) printf("%c ",a)
#define of(a) printf("%f ",a)
#define os(a) printf("%s ",a)
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	char s[4], t[4];
	int i, k=0;
	ss(s); ss(t);
	rep(i,3) if(s[i] == t[i]) k++;
	od(k);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll len[51];
ll p[51];
ll solve(ll n,ll x){
    if(n==0)return 1;
    if(x == 1)return 0;
    if(x<=1+len[n-1])return solve(n-1,x-1);
    if(x<=len[n-1]+2)return p[n-1]+1;
    return p[n-1]+1+solve(n-1,x-len[n-1]-2);
}
int main(){
    ll n,x;
    cin >> n >> x;
    len[0] = 1;
    rep(i,50){
        len[i+1] = 2*len[i] + 3;
    }
    p[0] = 1;
    rep(i,50){
        p[i+1] = 2*p[i] + 1;
    }
    cout << solve(n,x) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
    	string x = ReadLine();
    	int input = 0;

        for(var i = 0;i < x.Length;i++)
        {
          string num = x[i].ToString();
          input += int.Parse(num);
        }
    
    
    	if(input%9 == 0)
           {
             Write("Yes");
           }else{
           	 Write("No");
           }
    
  }
}


Measured memory_bytes: 21612
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
ans = 1
for i in range(1, N + 1):
    ans = ans * i % mod
for i in range(1, M + 1):
    ans = ans * i % mod
print(ans * 2 % mod if N == M else ans)

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

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

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

    std::vector<int> ans;
    for (int i = 1; i < n; i++)  {
        int s1 = 0;
        int s2 = 0;

        for (int j = 0; j < i; j++) {
            s1 += w[j];
        }

        for (int k = i; k < n;k++) {
            s2 += w[k];
        }

        ans.push_back(std::abs(s1 - s2));
    }

    int minans = *min_element(ans.begin(), ans.end());

    std::cout << minans << std::endl;
}

Measured memory_bytes: 256
#encoding:utf-8
def fact(n)
 if n != 1
  return n*fact(n-1)
 else
  return 1
 end
end

numbers = []
while gets
 numbers.push $_.to_i
end

i = 0
while i < numbers.length
 puts fact(numbers[i])
 i += 1
end

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

bool f(int x){
  int keta=0;
  while(x){
    x/=10;
    keta++;
  }
  return keta%2==1;
}

int main(){
  int n,num=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    if(f(i)){
      num++;
    }
  }
  cout<<num<<endl;
}


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

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;	//線路の情報の数n, 駅の数m
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		int C[100][100];	//costのグラフ
		int T[100][100];	//timeのグラフ
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;		//対角線は0
				}
				else{
					C[i][j] = T[i][j] = INF;    
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;		//線路の情報a,bとcost,time
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}

		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if(C[j][k]>C[j][i]+C[i][k])
						C[j][k] = C[j][i]+C[i][k];
					if(T[j][k]>T[j][i]+T[i][k])
						T[j][k] = T[j][i]+T[i][k];
				}
			}
		}

		int k;	//問い合わせの数
		cin >> k;
		for(int i=0;i<k;i++){
			int p, q, r;	//出発駅p, 到着駅q, 値の種類r
			cin >> p >> q >> r;
			if(r)	//r==1なら最短時間
				cout << T[p-1][q-1] << endl;
			else
				cout << C[p-1][q-1] << endl;
		}	
	}

	return 0;
}



Measured memory_bytes: 3144
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let n=nrin(4)
  out(min(n[0],n[1])+min(n[2],n[3]))
}
main()

Measured memory_bytes: 7372
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt0=0
cnt1=0
for i in range(N):
  for j in range(N):
    if A[i]>A[j] and j>=i:
      cnt0+=1
    if A[i]>A[j]:
      cnt1+=1
print((cnt1*(K-1)*K//2+cnt0*K)%(10**9+7))

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

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

bool check(int x, int y){
    return (x >= 0) && (x<H) && (y >= 0) && (y < W);
}

int main(){
    // 白マスの総数 - 最短距離が答え
    cin >> H >> W;
    vector<string> s(H);
    for(int i = 0; i < H; i++){
        cin >> s.at(i);
    }    

    int all = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s.at(i).at(j) == '.') all++;
        }
    }

    queue<pair<int,int>> q;
    vector<vector<int>> dic(H, vector<int>(W,-1));
    q.push(make_pair(0,0));
    dic.at(0).at(0) = 0;

    while(!q.empty()){
        pair<int,int> p = q.front();
        q.pop();
        int nowx = p.first;
        int nowy = p.second;

        bool flg = false;
        for(int i = 0; i < 4; i++){
            int nextx = nowx + dx[i];
            int nexty = nowy + dy[i];

            if(nextx == H-1 && nexty == W-1){
                dic.at(nextx).at(nexty) = dic.at(nowx).at(nowy) + 1;
                flg = true;
                break;
            }
            if(check(nextx,nexty) && dic.at(nextx).at(nexty) == -1 && s.at(nextx).at(nexty) == '.'){
                dic.at(nextx).at(nexty) = dic.at(nowx).at(nowy) + 1;
                q.push(make_pair(nextx,nexty));
            }
        }
        if(flg) break;
    }
    if(dic.at(H-1).at(W-1) == -1){
        cout << -1  << endl;
    } else { 
        cout << all - dic.at(H-1).at(W-1) -1 << endl;
    }

}


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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll a,b,k;
    cin>>a>>b>>k;
    int c = 0;
    int i;
    for(i=min(a,b);i>=1;i--)
    {
        if(a%i==0 && b%i==0)c++;

        if(c==k)break;
    }

    cout << i << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	while(true) {
		int n;
		int k;
		cin >> n >> k;
		if ( n == 0 ) break;
		vector<int> a;
		int c;
		for ( int i = 0; i < n ; i++ ) {
			cin >> c;
			a.push_back(c);
		}
		c = 0;
		for ( int i = 0; i < k; i++ ) {
			c += a[i];
		}
		int s = c;
		for ( int i = 0; i < n - k; i++ ) {
			c -= a[i];
			c += a[i+k];
			s = max(s,c);
		}
		cout << s << endl;
	}
	return 0;
}

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

const long LIM = 1e9;

long long n, T, res;

int main() {
  cin >> n >> T;
  cin.ignore();
  string s;
  getline(cin, s);
  for(int i=0; i<s.size(); ) {
    if(s[i]=='n') {
      long long temp;
      for(int j=0; j<=(s[i+2]-'0'); j++) {
	temp = res + pow((double)n, j);
	if(temp>LIM) goto bad;
      }
      res = temp;
    }
    i+=4;
  }
  
  res*=T;
  if(res<=LIM) {
    cout << res << endl;
    return 0;
  }
  
 bad:
  cout << "TLE" << endl;
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
#include<typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 
lli pmod(lli x,lli y){lli res=1;while(y>0){if(y&1)res = ((res%mod)*(x%mod))%mod;y>>=1;x= ((x%mod)*(x%mod))%mod;}return res;} 
lli power(lli x,lli y){lli res=1;while(y>0){if(y&1)res=res*x;y>>=1;x=x*x;}return res;}




int main()
{
    
         

    fio
    
    lli n,k;
    cin>>n>>k;

     lli a[n];
     fr(i,0,n)cin>>a[i];

     lli len = 1000;
     //cout<<len<<'\n';

     lli sd[len]={0},maxi=-1e18,p[400000]={0};

     fr(i,0,n)
     {

         lli l=max(a[i]-k,0LL),r=a[i];
         maxi=-1e18;
         //cout<<l<<" "<<r<<'\n';

         for (int j=l; j<=r; )
        if (j % len == 0 && j + len - 1 <= r) {
            maxi= max(sd[j/len],maxi);
            j+= len;
        }
        else {
            maxi=max(p[j],maxi);
            j++;
        }

        r=min(a[i]+k,300100LL),l=a[i];

         for (int j=l; j<=r; )
        if (j % len == 0 && j + len - 1 <= r) {
            maxi= max(sd[j/len],maxi);
            j+= len;
        }
        else {
            maxi=max(p[j],maxi);
            j++;
        }
        //cout<<maxi<<'\n';

        p[a[i]]=maxi+1;
        sd[a[i]/len]=max(maxi+1,sd[a[i]/len]);




     }


    
      maxi=-1e18;
     fr(i,0,300100)maxi=max(p[i],maxi);
     cout<<maxi;


   






  
     

    


     

     


    
      




 

return 0;}

Measured memory_bytes: 9120