akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
A = []
for i in range(M):
    p,y = map(int,input().split())
    A.append([p,y,i])
A.sort(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
    if p!=a[0]:
        y = 1
        p = a[0]
    b = str(a[0]).rjust(6,"0")+str(y).rjust(6,"0")
    ans[a[2]] = b
    y+=1
for i in ans:
    print(i)

Measured memory_bytes: 32028
function sum_of_n(n){
    var ret = 0;
    while(n > 0){
        ret += (n%10);
        n /= 10;
        n = Math.floor(n);
    }
    return ret;
}

function Main(input){
    input = input.split(" ");
    var N = input[0], A = input[1], B = input[2], ans = 0, tmp;
    for(var i = 1; i <= N; ++i){
        tmp = sum_of_n(i);
        if(tmp >= A && tmp <= B) ans += i;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

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

	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

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

  string s;
  cin >> s;

  ll res = 0;
  int n = s.size();

  for (int i = 0; i < (1 << (n - 1)); ++i) {
    vector<int> nums = {0};

    for (int j = 0; j < n - 1; ++j) {
      if (i & (1 << j)) nums.push_back(j + 1);
    }

    nums.push_back(n);

    for (int j = 0; j < nums.size() - 1; ++j) {
      res += stoll(s.substr(nums[j], nums[j + 1] - nums[j]));
    }
  }

  cout << res << "\n";
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;


bool f[100000001];

int v(int x) {
  int ret = 0;
  while(x > 0) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}

int main() {
  int A, N, M;
  cin >> A >> N >> M;
  for(int y = 1;; y++) {
    int64 real = y + A;
    if(real > M) break;
    int64 sum = 1;
    for(int j = 0; j < N; j++) {
      sum *= real;
      if(sum > M) break;
    }
    if(sum <= M && v(sum) == y) f[sum] = true;
  }
  int ret = 0;
  for(int i = 1; i <= M; i++) ret += f[i];
  cout << ret << endl;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int x;
  cin >> x;
  x -= 400;
  int a = x/200;
  a = 8 - a;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000 
#define M 1000000007
#define PI 2 * acos(0.0)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
    fast_io 
    long double n;
    cin>>n;
    long double r = pow(n,3);
    long double ans = r/27;
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}

int main(){


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

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len, a, b, c;
	ll A, B, C, D, N, M, K, num_R, num_G, num_B, ans;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, W, X;
	ll **dp;
	char S[200000];



	cin >> X;

	i = 0;
	sum = 100;
	while (sum<X){
		sum *= 1.01;
		i++;
	}

		cout << i << endl;


	return 0;

}
    

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

int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    long long int dp[n]={0};
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<min(n,k);i++){
        dp[i]=100000000000;
        for(int j=1;j<=i;j++){
           dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j])); 
        }
    }
    long long int ans=0;
    for(int i=k;i<n;i++){
        dp[i]=100000000000;
        for(int j=1;j<=min(n,k);j++){
       dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
    }
    // for(int i=0;i<n;i++){
    //     cout<<dp[i]<<" ";
    // }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1408
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int toINT(string s){
    int ret=0;
    
    rep(i,s.size()){
        if(s[i]=='m'){
            if(i-1>=0 && isdigit(s[i-1])){
                ret+=(s[i-1]-'0')*1000;
            }
            else{
                ret+=1000;
            }
        }
        else if(s[i]=='c'){
            if(i-1>=0 && isdigit(s[i-1])){
                ret+=(s[i-1]-'0')*100;
            }
            else{
                ret+=100;
            }
        }
        else if(s[i]=='x'){
            if(i-1>=0 && isdigit(s[i-1])){
                ret+=(s[i-1]-'0')*10;
            }
            else{
                ret+=10;
            }
        }
        else if(s[i]=='i'){
            if(i-1>=0 && isdigit(s[i-1])){
                ret+=(s[i-1]-'0');
            }
            else{
                ret+=1;
            }
        }
    }
    return ret;
}


string toSTR(int a){
    string ret="";
    
    if(a/1000>1){
        ret+=(int)(a/1000)+'0';
        ret+='m';
    }
    else if(a/1000==1){
        ret+='m';
    }
    a-=(int)(a/1000)*1000;
    
    if(a/100>1){
        ret+=(int)(a/100)+'0';
        ret+='c';
    }
    else if(a/100==1){
        ret+='c';
    }
    a-=(int)(a/100)*100;
    
    if(a/10>1){
        ret+=(int)(a/10)+'0';
        ret+='x';
    }
    else if(a/10==1){
        ret+='x';
    }
    a-=(int)(a/10)*10;
    
    if(a>1){
        ret+=(int)(a)+'0';
        ret+='i';
    }
    else if(a==1){
        ret+='i';
    }
    
    
    return ret;
}


int main() {
    int n;
    cin>>n;
    
    rep(i,n){
        string a,b;
        cin>>a>>b;
        int ans=toINT(a)+toINT(b);
        cout<<toSTR(ans)<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int INF=(1<<30)-233;
const int N=55;
struct node{
	int v,sz,lim;
	bool operator <(const node &a)const{
		return 1ll*v*a.sz<1ll*sz*a.v;
	}
}a[N];
int n,X,D,S,ans,f[N*N*N];
int m[N],sz[N],fa[N],lim[N];
void insert(int x,int y){
	Rep(i,S,0) f[i+x]=min(f[i+x],f[i]+y);
	S+=x;
}
int main(){
	scanf("%d%d%d%d",&n,&X,&D,&m[1]);
	For(i,2,n) scanf("%d%d",&m[i],&fa[i]);
	For(i,1,n) sz[i]=1;
	Rep(i,n,2){
		sz[fa[i]]+=sz[i];
		m[fa[i]]+=m[i];
		m[fa[i]]=min(m[fa[i]],INF);
	}
	For(i,1,n) lim[i]=(i==1?INF:D);
	//For(i,1,n) printf("%d %d %d\n",sz[i],m[i],lim[i]);
	For(i,1,n) a[i]=(node){m[i],sz[i],lim[i]};
	sort(a+1,a+n+1);
	For(i,0,n*n*n) f[i]=INF;
	f[0]=S=0;
	For(i,1,n){
		//printf("%d %d %d\n",a[i].lim,a[i].v,a[i].sz);
		int ins=min(a[i].lim,n);
		a[i].lim-=ins;
		for (int v=1;v<=ins;ins-=v,v<<=1)
			insert(a[i].sz*v,min((ll)INF,1ll*a[i].v*v));
		insert(a[i].sz*ins,min((ll)INF,1ll*a[i].v*ins));
	}
	Rep(i,S,0) if (f[i]<=X){
		int rest=X-f[i],sum=i;
		//printf("%d %d %d\n",i,rest,sum);
		For(j,1,n){
			int t=min(a[j].lim,rest/a[j].v);
			rest-=t*a[j].v; sum+=t*a[j].sz;
		}
		ans=max(ans,sum);
	}
	printf("%d\n",ans);
}
/*
前i个数字选和为j的方案数（
*/

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define  mod 1000000007;


using namespace std;
 int dp[109][100009];
int main()
{

    int n,k,a[109];
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
        dp[i][0]=1;

    for(int i=1;i<=k;i++)
        dp[0][i]=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=k;j++)
    {
        dp[i][j]=dp[i-1][j]+dp[i][j-1];
        if(j-1-a[i]>=0)
            dp[i][j]-=dp[i-1][j-1-a[i]];
           if(dp[i][j]<0)
            dp[i][j]+=mod;
            dp[i][j]=dp[i][j]%mod;



    }
    cout<<dp[n][k]<<endl;
    //for(int i=0;i<)


}


Measured memory_bytes: 41216
//*****************************believer******************************//
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef map<ll,ll> mi;
 
#define f first
#define ss second
#define ins insert
#define pb push_back
#define lb lower_bound 
#define ub upper_bound 
#define pq priority_queue
#define sqr(n) floor(sqrt(n))
#define sz(v) ((ll)(v.size()))
#define trav(a,x) for (auto& a: x)
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define mem(a) memset(a, -1, sizeof (a))
#define ssort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).rbegin(),(v).rend())
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define vmn(a) (*min_element(a.begin(),a.end()))
#define vmx(a) (*max_element(a.begin(),a.end()))
#define foo(i,a,b) for (ll i = (a); i < (b); ++i)
#define foor(i,a,b) for (ll i = (a); i >= (b); --i)

const ll N=2e6+100;
ll c[N];
vi a(N);
ll solve(ll x)
{
    
    if(x==0)
    return c[0]=0;
    
    if(x==1)
    return c[0]=abs(a[1]-a[0]);
    
    if(c[x]!=-1)
    return c[x];
    
    c[x]=min(solve(x-1)+abs(a[x]-a[x-1]),solve(x-2)+abs(a[x]-a[x-2]));
    //cout<<c[x]<<" "<<x<<"\n";
    return c[x];
    
}

int main()
{
        ll n;
        cin>>n;
        mem(c);
        foo(i,0,n)
        cin>>a[i];
        
        ll ans=solve(n-1);
        cout<<ans<<"\n";
    
    return 0;
}


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

using namespace std;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int i, n;
    cin >> n;
    vector<int> v(n);
    for(i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());

    long long ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = i + 1; j < n; j++)
            for(int k = j + 1; k < n; k++)
                if(v[i] != v[j] && v[j] != v[k] && v[i] + v[j] > v[k])
                    ans++;
            
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

class UnionFind {
  public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    reverse(all(A));
    reverse(all(B));
    UnionFind tree(N);
    ll cnt = N * (N - 1) / 2;
    vector<ll> res;
    rep(i, M) {
        res.push_back(cnt);
        ll a = A[i], b = B[i];
        if (tree.issame(a, b))
            continue;

        ll sa = tree.size(a), sb = tree.size(b);
        cnt -= sa * sb;
        tree.merge(a, b);
    }

    reverse(all(res));

    for (auto r : res) {
        cout << r << endl;
    }
}


Measured memory_bytes: 5364
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n; cin >> n;
  if(n%2)
  {
    cout << "0\n";
    return 0;
  }
  int a[n];
  for(int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a+n);
  cout << a[n/2]-a[n/2-1] << '\n';
}
                                              

Measured memory_bytes: 640
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
}


Measured memory_bytes: 32736
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;};
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) calcDepth(T[u].r,p);
  if(T[u].l != NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i = 0; i < n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j < k; j++){
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child;
      else T[sib].r = child;
      sib = child;
    }
  }

  for(i = 0; i < n; i++){
    if(T[i].p == -1) root = i;
  }
  
  calcDepth(root, 0);

  for(i = 0; i < n; i++) print(i);
  
  return 0;
}


    



Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int,int> P;

int bit[100001][2] = {},n;

int sum(int i,int num){
	int s = 0;
	while(i > 0){
		s += bit[i][num];
		i -= i & -i;
	}
	return s;
}

void add(int i,int x,int num){
	while(i <= 100000){
		bit[i][num] += x;
		i += i & -i;
	}
}

bool C(int x,int ok){
	return sum(x,0) * ok >= sum(x,1);
}

signed main(){
	int ma = 0;
	vector<P> bug;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		bug.push_back(P(b,a));
	}
	sort(bug.begin(),bug.end(),greater<P>());
	for(int i = 0;i < n;i++){
		int ok = bug[i].first,foo = bug[i].second,low = 0,up = 100001;
		add(foo,1,0);
		add(foo,foo,1);
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(C(mid,ok)) low = mid;
			else up = mid;
		}
		int s = sum(low,0);
		if(low < 100000 && sum(low + 1,0) - sum(low,0) >= 2){
			int ss = sum(low,1);
			int j = 1;
			for(;j <= sum(low + 1,0) - sum(low,0);j++){
				if(ss + (low + 1) * j > ok * (sum(low,0) + j)) break;
			}
			s += j - 1;
		}
		ma = max(ma,s);
	}
	cout << ma << endl;
	return 0;
}

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

int sum(int n) {
    int result = 0;
    do {
        result += n % 10;
        n /= 10;
    } while (n > 0);
    return result;
}

int main() {
    int n, result = INT_MAX;
    cin >> n;
    for (int i = 1; i <= n /2; i++) {
        result = min(result, sum(i) + sum(n - i));
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define Y {cout<<"YES"<<endl;return 0;}
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f,maxn=2e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
int n,m,a[maxn]; 
int main()
{
	string s;
	cin>>s;
	sort(all(s));
	if(s[1]==s[0]&&s[3]==s[2]&&s[2]!=s[1]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 10;
const int oo = 1e18;
const int mod = 1e9 + 7;

int n, k;
int a[N], BIT[N];
map<int, int> mp;

void upd(int pos, int val)  {
    for(int i = pos; i < N; i += (i & (-i)))
        BIT[i] += val;
}
int get(int pos)    {
    int res = 0;
    for(int i = pos; i > 0; i -= (i & (-i)))
        res += BIT[i];
    return res;
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);

    cin >> n >> k;
    vector<int> tmp; tmp.pb(0);
    FOR(i, 1, n) cin >> a[i], a[i] = (a[i] - k + a[i - 1]), tmp.pb(a[i]);
    sort(tmp.begin(), tmp.end());
    int cnt = 0;
    FOR(i, 0, tmp.size() - 1) if(i == tmp.size() - 1 || tmp[i] < tmp[i + 1])
        mp[ tmp[i] ] = ++cnt;

    int ans = 0; upd(mp[0], 1);
    FOR(i, 1, n)    {
        ans += get(mp[ a[i] ]);
        upd(mp[a[i]], 1);
    }

    return cout << ans, 0;
}


Measured memory_bytes: 17520
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] read = ReadLine().Split(' ');
//        int read_leng = read.Length;
//        int[] readR = new int[mochinum];
//        int a = int.Parse(ReadLine());
        int b = int.Parse(read[0]);
        int c = int.Parse(read[1]);
//        int d = int.Parse(read[3]);
        long ans=c;
        for(int i=1;i<b;i++){
            ans *= c-1;
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
 
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 123, K = 18;
int n, p[N], a[2][N], mn[2][K][N], lg[N];
int ans[N], k;

int getmin(int c, int x, int y) {
	if (a[c][x] < a[c][y]) {
		return x;
	}
	return y;
}

int get(int c, int l, int r) {
	int len = lg[r - l + 1];
	return getmin(c, mn[c][len][l], mn[c][len][r - (1 << len) + 1]);
}

int m;
pii seg[3 * N];

pii getpos(int x) {
	int l = seg[x].F, r = seg[x].S;
	int p1 = get(l & 1, l, r);
	int p2 = get((l & 1) ^ 1, p1 + 1, r);
	return {p1, p2};
}

int getans(int x) {
	int l = seg[x].F, r = seg[x].S;
	int p1 = get(l & 1, l, r);
	return p[p1];
}

void dijkstra(int L, int R) {
	seg[++m] = {L, R};
	priority_queue <pii, vector <pii>, greater <pii> > pq;
	pq.push({getans(m), m});
	while (!pq.empty()) {
		pii cur = pq.top();
		pq.pop();
		
		int l = seg[cur.S].F, r = seg[cur.S].S;
		if (r - l + 1 >= 2) {
			pii pos = getpos(cur.S);
			ans[++k] = p[pos.F];
			ans[++k] = p[pos.S];
			
			seg[++m] = {l, pos.F - 1};
			pq.push({getans(m), m});
			seg[++m] = {pos.F + 1, pos.S - 1};
			pq.push({getans(m), m});
			seg[++m] = {pos.S + 1, r};
			pq.push({getans(m), m});
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	p[N - 1] = N;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		a[i & 1][i] = p[i];
		a[(i & 1) ^ 1][i] = N;
		mn[0][0][i] = mn[1][0][i] = i;
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 1; j < K; j++) {
			for (int k = 1; k + (1 << j) - 1 <= n; k++) {
				mn[i][j][k] = getmin(i, mn[i][j - 1][k], mn[i][j - 1][k + (1 << (j - 1))]);
			}
		}
	}
	for (int i = 2; i < N; i++) {
		lg[i] = lg[i / 2] + 1;
	}
	dijkstra(1, n);
	for (int i = 1; i <= k; i++) {
		cout << ans[i] << ' ';
	}
}


Measured memory_bytes: 38456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;

int n,Ans,A[maxn];
bool vis[maxn];

void Check(int k)
{
	int a,b; a = b = 1;
	for (int i = k + 1; i <= n; i++)
	{
		if (A[i] > A[i - 1]) {a = i - k; break;}
		if (i == n) a = n + 1 - k;
	}
	for (int i = k + 1; i <= n; i++)
	{
		if (A[i] < A[i - 1]) {b = i - k; break;}
		if (i == n) b = n + 1 - k;
	}
	int c = max(a,b);
	for (int i = 0; i < c; i++)
		vis[k + i] = 1;
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) scanf("%d",&A[i]);
	for (int i = 1; i <= n; i++)
		if (!vis[i]) Check(i),++Ans;
	cout << Ans << endl;
	return 0;
}

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

int main(){

    string s, t;
    cin >> s >> t;
    int S = (int)s.size(), T = (int)t.size();
    vector<vector<int> > dp(S + 1, vector<int> (T + 1, 1000000000));
    
	//test
    //dp初期化
    for(int i = 0; i < S + 1; i++) dp[i][0] = i;
    for(int j = 0; j < T + 1; j++) dp[0][j] = j;    
    for(int i = 1; i < S + 1; i++){
        for(int j = 1; j < T + 1; j++){
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
            if(s[i - 1] == t[j - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
            else dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
		}
    }

    cout << dp[S][T] << endl;
    return 0;

}



Measured memory_bytes: 6820
def gcd(a,b):
    while b:a,b=b,a%b
    return a
 
def lcm(a,b):
    return a//gcd(a,b)*b
 
input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)


Measured memory_bytes: 5600
/* beginner 81 */
/* Shubham Jain */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll c=0,i,n,f=0;
    string s;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    label:
    for(i=0;i<n;i++){
        if(a[i]%2==0){
            a[i]=a[i]/2;
        }
        else
            f=1;
    }
    if(f==0){
        c++;
        goto label;
    }
    cout<<c<<'\n';
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N), A(M), B(M), tmp(N);
    REP(i, N) {
        cin >> H[i];
        tmp[i] = 0;
    }
    REP(i, M) {
        cin >> A[i] >> B[i];
    }
    REP(i, M) {
        if (H[A[i]-1] <= H[B[i]-1]) {
            tmp[A[i]-1] = 1;
        }
        if (H[B[i]-1] <= H[A[i]-1]) {
            tmp[B[i]-1] = 1;
        }
    }
    int result = N;
    REP(i, N) {
        if (tmp[i]) {
            result--;
        }
    }
    cout << result << endl;
    return 0;
}


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

#include <algorithm>

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  map<int, ll> cmb;
  ll ans = 0;
  for (auto m : cnt) {
    ll tmp = cnt[m.first];
    cmb[m.first] = (tmp * (tmp - 1)) / 2;
    ans += cmb[m.first];
  }
  for (int i = 0; i < N; i++) {
    ll ans_i = ans - cmb[A[i]];
    ll tmp = cnt[A[i]];
    if (cnt[A[i]] > 2) ans_i += ((tmp - 1) * (tmp - 2)) / 2;
    cout << ans_i << endl;
  }
}

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

  solve();

  return 0;
}


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

int ch[4][4];

int ac(){
	for(int i=0;i<3;i++){
		if(ch[0][i]+ch[1][i]+ch[2][i]==3)return 1;
	}
	
	for(int i=0;i<3;i++){
		if(ch[i][0]+ch[i][1]+ch[i][2]==3)return 1;
	}
	
	if(ch[0][0]+ch[1][1]+ch[2][2]==3)return 1;
	
	if(ch[0][2]+ch[1][1]+ch[2][0]==3)return 1;
	
	return 0;
	
}

int main() {
  
  int a[4][4],n,b[101];
  
  for(int i=0;i<3;i++){
  	for(int j=0;j<3;j++){
  		cin >> a[i][j];
  		}
  	}
  
  cin >> n;
  
  for(int i=0;i<3;i++){
  	for(int j=0;j<3;j++){
  		ch[i][j]=0;
  		}
  	}
  
  
  for(int i=0;i<n;i++){
  	cin >> b[i];
  	for(int j=0;j<3;j++){
  		for(int k=0;k<3;k++){
  			if(b[i]==a[j][k])ch[j][k]=1;
  		}
  	}
  }
  
  if(ac())cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

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

int main() { 
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	//int cnt = 0;
	string p = "0123456789";
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '.') {
				int cnt = 0;
				if (i + 1 < n && s[i + 1][j] == '#') cnt++;
				if (j + 1 < m && s[i][j + 1] == '#') cnt++;
				if (i - 1 >= 0 && s[i - 1][j] == '#') cnt++;
				if (j - 1 >= 0 && s[i][j - 1] == '#') cnt++;
				if (i + 1 < n && j + 1 < m && s[i + 1][j + 1] == '#') cnt++;
				if (i + 1 < n && j - 1 >= 0 && s[i + 1][j - 1] == '#') cnt++;
				if (i - 1 >= 0 && j + 1 < m && s[i - 1][j + 1] == '#') cnt++;
				if (i - 1 >= 0 && j - 1 >= 0 && s[i - 1][j - 1] == '#') cnt++;
				s[i][j] = p[cnt]; 
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << s[i] << endl;
	}
	return 0; 
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const string yes = "Yes";
const string no = "No";

int main()
{
  string s;
  cin >> s;
  if (s[2]==s[3]&&s[4]==s[5]) cout << yes << endl;
  else cout << no << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 110
using namespace std;
long long f[N][10],p[N][11],op[10];
long long n,i,j,k,t,ans=-1e18,sum,num;
int main(){
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<10;j++)
		{
			cin>>f[i][j];
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<11;j++)
		{
			cin>>p[i][j];
		}
	}
	for(i=1;i<1024;i++)
	{
		t=i;
		for(j=0;j<10;j++)
		{
			op[j]=t%2;
			t/=2;
		}
		sum=0;
		for(j=0;j<n;j++)
		{
			num=0;
			for(k=0;k<10;k++)
			{
				num+=f[j][k]&&op[k];
			}
			sum+=p[j][num];
		}
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = []
for k, v in city_list_grouped:
  ans += [[v[2],format(k,'0>6')+format(i+1,'0>6')] for i,v in enumerate(v)]

for x in sorted(ans):
  print(x[1])

Measured memory_bytes: 101976
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[50], b[50], c[50], d[50];
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for (int j = 0; j < m; j++) cin >> c[j] >> d[j];
  for (int i = 0; i < n; i++) {
	int s = 1e9, k;
	for (int j = 0; j < m; j++) {
			int t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (s > t) s = t, k = j + 1;
	}
	cout << k << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>

int main() {
	int N=0;
	int K=0;
	int X=0;
	int Y=0;
	std::cin >>N>>K>>X>>Y;

	int total=0;

if (N>=K)
{
		total=K*X+(N-K)*Y;
	
}else
{
	total=N*X;
		
}


std::cout << total << std::endl;

return 0;


}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define frr(i,s,n) for(int i=s;i<=n;i++)
#define fr(i,s,n) for(int i=s;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

void loop()
{
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));

}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    //fast;
    int t = 1;
    //cin>>t;
    while(t--)
        loop();
}   

Measured memory_bytes: 3644
H, W = map(int, input().split())
a_mp = [list(map(int, input().split())) for _ in range(H)]
b_mp = [list(map(int, input().split())) for _ in range(H)]
h, w = map(int, input().split())
c_mp = [list(map(int, input().split())) for _ in range(h)]
INF = 10 ** 20


def check(x, y):
  ret = 0
  for dy in range(h):
    for dx in range(w):
      if b_mp[y + dy][x + dx] != c_mp[dy][dx]:
        return -INF
      ret += a_mp[y + dy][x + dx]
  return ret


ans = -INF
for y in range(H - h + 1):
  for x in range(W - w + 1):
    ans = max(ans, check(x, y))
if ans == -INF:
  print("NA")
else:
  print(ans)
 


Measured memory_bytes: 5720
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    string s,s1="";
    cin>>s;

    int lens=s.size();
    for(int i=0; i<lens; i++) s1+=tolower(s[i]);
    string ss;
    int cnt=0;
    while(1){
        string s2="";
        cin>>ss;
        if(ss=="END_OF_TEXT") break;

        int lenss=ss.size();
        for(int i=0; i<lenss; i++) s2+=tolower(ss[i]);
        if(s1==s2) cnt++;
    }
    pf("%d\n",cnt);

    return 0;
}



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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll n, k, ans = 0, i, j;
	cin >> n >> k;
	vector<ll>v(n);
	for(i = 0; i < n; i++)cin >> v[i];
	for(i = 0; i <= n; i++){
		for(j = 0; j <= n; j++){
			vector<ll>A;
			if( (i + j) <= k and i + j <= n){
				for(ll k1 = 1; k1 <= i; k1++){
					A.pb(v[k1 - 1]);
				}
				ll bi = n - 1;
				for(ll k1 = 1; k1 <= j; k1++){
					A.pb(v[bi]);
					bi--;
				}
				sort(all(A));
				ll s = accumulate(all(A),0);
				for(ll k1 = 0; k1 < min((ll)A.size(),k - (i + j)); k1++){
					if(A[k1] < 0){
						s += abs(A[k1]);
					}
				}
				//cout << i << " " << j << " " << s << nl;
				ans = max(ans,s);
			}
		}
	}
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input1.txt","r",stdin);
//    freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t = 1;
//	 cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3644
S = int(input())
arr = [0]*(S+1)
MOD = 10**9 + 7

arr[0] = 1
for i in range(3,S+1):
    for j in range(i-3+1):
        arr[i] += arr[j]
        arr[i] = arr[i]%MOD

print(arr[S])

Measured memory_bytes: 64628
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,j,i,c,a,b;

    cin>>a>>b>>c;
    if(a==b)
        cout<<c<<endl;
    else if(b==c)
        cout<<a<<endl;
    else
        cout<<b<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * author @sahil
 */
class edge{
    int v;
    long w;
    edge(int uu,long ww){
        v=uu;
        w=ww;
    }
}
public class Main {
    static ArrayList<edge> adj[];
    static int n;
    static boolean vis[];
    static long dist[];
    public static void add(int u,int v,long w){
        adj[u].add(new edge(v,w));
        adj[v].add(new edge(u,w));
    }
    public static void bfs(int k){
        Queue<Integer> q=new LinkedList<>();
        vis[k]=true;
        q.add(k);
        while(!q.isEmpty()){
            int u=q.poll();
            for(edge e:adj[u]){
                if(!vis[e.v]){
                    dist[e.v]=dist[u]+e.w;
                    vis[e.v]=true;
                    q.add(e.v);
                }
            }
        }

    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        adj=(ArrayList<edge>[])new ArrayList[n];
        vis=new boolean[n];
        dist=new long[n];
        for(int i=0;i<n;++i){
            adj[i]=new ArrayList<edge>();
            vis[i]=false;
        }
        for(int i=1;i<n;++i){
            String s[]=br.readLine().split(" ");
            int u=Integer.parseInt(s[0])-1;
            int v=Integer.parseInt(s[1])-1;
            long w=Long.parseLong(s[2]);
            add(u,v,w);
        }
        String s[]=br.readLine().split(" ");
        int q=Integer.parseInt(s[0]);
        int k=Integer.parseInt(s[1])-1;
        bfs(k);
        for(int i=0;i<q;++i){
            s=br.readLine().split(" ");
            int u=Integer.parseInt(s[0])-1;
            int v=Integer.parseInt(s[1])-1;
            System.out.println(dist[u]+dist[v]);
        }
    }
}


Measured memory_bytes: 80340
H , W = gets.split(' ').map(&:to_i)
ss = Array.new(H){Array.new(W)}
H.times do |i|
    ss[i] = gets.chomp.split('')
end

# make pair patterns by DFS
def make_pair_patterns(pool)
    return [[]] if pool.length == 0

    perms = []
    visited = {}
    stack = [pool.min]
    pool.delete(pool.min)
    visited[stack.dup] = true

    while stack.length > 0 do
        if pool.length == 0
            perms.push(stack.dup)
            pool.push(stack.pop)
            next
        end
        if stack.length % 2 == 0
            use = pool.min
            if visited[stack + [use]]
                pool.push(stack.pop)
                next
            end
        else
            use = pool.reject{|i| visited[stack + [i]]}.min
            unless use
                pool.push(stack.pop)
                next
            end
        end
        stack.push(use)
        visited[stack.dup] = true
        pool.delete(use)
    end
    return perms
end

if H % 2 == 0
    perms = make_pair_patterns((0...H).to_a)
else
    perms = []
    (0...H).each do |rest|
        pool = (0...H).to_a
        pool.delete(rest)
        patterns = make_pair_patterns(pool)
        patterns.each do |arr|
            arr.push(rest)
        end
        perms.concat(patterns)
    end
end

perms.each do |perm|
    pss = Array.new(H){Array.new(W)}
    (0...(H/2)).each do |i|
        pss[i] = ss[perm[2 * i]]
        pss[H - 1 - i] = ss[perm[2 * i + 1]]
    end
    pss[H/2] = ss[perm[-1]] if H % 2 == 1

    tss = Array.new(W){Array.new(H)}
    W.times do |i|
        H.times do |j|
            tss[i][j] = pss[j][i]
        end
    end

    center_available = (W % 2 == 1)
    success = true
    while tss.length > 0 do
        reverse = tss[0].reverse
        tss.delete_at(0)
        i_rev = tss.find_index(reverse)
        if i_rev
            tss.delete_at(i_rev)
        else
            if center_available && reverse.reverse == reverse
                center_available = false
            else
                success = false
                break
            end
        end
    end
    if success
        print 'YES'
        exit
    end
end

print 'NO'

Measured memory_bytes: 28668
import math
A,B,H,M = map(int,input().split())

rad2=360*(M/60)
rad1=((H*30+M*0.5))
if (180<=abs(rad1-rad2)):
    C=(A**2)+(B**2)-(2*A*B*math.cos(math.radians(360-abs(rad1-rad2))))
else:
    C=(A**2)+(B**2)-(2*A*B*math.cos(math.radians(abs(rad1-rad2))))
print(math.sqrt(C))


Measured memory_bytes: 9544
s = input()
if not s[0] == "A":
  print("WA")
  exit()
elif not "C" in s[2:-1]:
  print("WA")
  exit()
ig = 2+s[2:-1].index("C")
for i in range(1,len(s)):
  if i == ig:
    continue
  if s[i].isupper():
    print("WA")
    exit()
print("AC")

Measured memory_bytes: 3064
#BFSにdpを乗っける
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[[0]*w for i in range(h)] 
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
dp=[[0]*w for i in range(h)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        if lis[i][j]==1:
            continue
        else:
            if i==j==0:
                continue
            if i==0:
                dp[i][j]=dp[i][j-1]
            elif j==0:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod
#print(dp)
print(dp[-1][-1]%mod)
            
    

        

Measured memory_bytes: 89012
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
typedef long long int lli;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define JUGAD freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
using namespace std;

int main(){
    FAST;
    int ar[3];
    for(int i=0;i<3;i++){cin>>ar[i];}
    sort(ar,ar+3);
    if(ar[0]==5 && ar[1]==5 && ar[2]==7){cout<<"YES\n";}
    else{cout<<"NO\n";}
}




Measured memory_bytes: 3644
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	ll i,n,c=0;
	cin>>n;
	map<string,ll>m;
	for0(i,n){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		m[s]++;
		c+= m[s]-1;
		}
	cout<<c<<nw;
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
const int inf=1e9+7;
const ll INF=1e18;


int main() {
  int n;
  cin>>n;
  vin a(n);
  rep(i,n) cin>>a[i];
  //////////
  int ans=0;
  map<int,int> mp;
  rep(i,n){
    
   if(mp[a[i]]==1){//1なら書かれている
     
     mp[a[i]]--; 
   }
   else{//0 or nothing
    mp[a[i]]++; 
   }
  }
  for(auto v :mp){
    //cout<<v.first<<endl;
    if(mp.count(v.first)&&mp[v.first]==1) ans++; 
  }
  cout<<ans<<endl;
}

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

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

  int now = 0;
  int cnt = 0;
  while(true) {
    if ( now == 1 ) {
      std::cout << cnt << std::endl;
      break;
    } else if ( cnt >= N ) {
      std::cout << -1 << std::endl;
      break;
    }
    now = a[now] - 1;
    ++cnt;
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
    int n;
    unsigned long long int lcm_, input_, a, b, r;
    cin >> n;
    cin >> lcm_;
    for(int i = 0; i < n - 1; i++){
        cin >> input_;
        a = input_;
        b = lcm_;
       if(a < b){
           r = a;
           a = b;
           b = r;
       }
       r = a % b;
        while(r != 0){
            a = b;
            b = r;
            r = a % b;
        }
        lcm_ =  input_ /b * lcm_;
    }
    cout << lcm_ << endl;
    return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, w; cin >> n >> w; vector<pair<int, int>>item; item.push_back(make_pair(0, 0));
	rep(i, 0, n) {
		int v, w; cin >> v >> w; item.push_back(make_pair(v, w));
	}
	vector<vector<int>>dp(n + 1, vector<int>(w + 1, 0));
	rep(i, 1, n + 1) {
		rep(j, 0, w + 1) {
			dp[i][j] = dp[i - 1][j];
			if (j - item[i].second >= 0) {
				dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - item[i].second] + item[i].first);
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 6776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();

		sc.close();

		int answer = 0;

		for(int i = A ; i < T + 0.5 ;i += A) {
			answer += B;
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 23892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}

template<class Type>
Type solve(Type res = Type()){
    ll H,N; cin >> H >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    ll sumA = accumulate(A.begin(),A.end(),0LL);
    if(sumA >= H) return "Yes"; else return "No";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 1024