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

int N, L, T, ori[100005], d[100005];
vector<int> l, r, even;
set<int> S;

int main() {
	scanf("%d%d%d", &N, &L, &T);
	for (int i = 0; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ori[i] = a;
		d[i] = b;
		if (b == 1) even.push_back((a + T) % L);
		else even.push_back((((a - T) % L) + L) % L);
		if (b == 1) r.push_back(a);
		else l.push_back(a);
		S.insert(d[i]);
	}
	if (S.size() == 1) {
		for (int i = 0; i < N; i++) {
			if (d[i] == 1) printf("%d\n", (ori[i] + T) % L);
			else printf("%d\n", ((((ori[i] - T) % L) + L) % L));
		}
		return 0;
	}
	sort(even.begin(), even.end());
	pair<int, int> res = make_pair(-1, -1);
	T *= 2;
	int oriT = T;
	if (d[0] == 1) {
		if (T <= l[0] - r[0]) {
			res = make_pair(1, 0);
		} else {
			T -= l[0] - r[0];
			long long bot = 0, top = 20000000005ll, mid;
			while (bot + 1 < top) {
				mid = (bot + top) / 2;
				long long val = 0;
				long long ls = mid / 2, rs = mid - ls;
				val += (ls / l.size()) * L;
				for (int i = 0; i < rs % r.size(); i++) {
					val += (((r[(r.size() - i) % r.size()] - r[(r.size() - i - 1)]) + L) % L) * 1;
				}
				val += ((rs / r.size()) * L) * 1;
				for (int i = 0; i < ls % l.size(); i++) {
					//val += (((l[(l.size() - i) % l.size()] - l[(l.size() - i - 1)]) + L) % L) * 1;
					val += (((l[(i + 1) % l.size()] - l[i]) + L) % L) * 1;
				}
				if (val > T) top = mid;
				else if (val == T && mid % 2 == 1) top = mid;
				else bot = mid;
			}
			if (bot % 2 == 0) res = make_pair(2, (bot/2) % l.size());
			else res = make_pair(1, (r.size() - (bot/2+1) % r.size()) % r.size());
		}
	} else {
		if (T <= L - (r[r.size() - 1] - l[0])) {
			res = make_pair(2, 0);
		} else {
			T -= L - (r[r.size() - 1] - l[0]);
			long long bot = 0, top = 20000000005ll, mid;
			while (bot + 1 < top) {
				mid = (bot + top) / 2;
				long long val = 0;
				long long rs = mid / 2, ls = mid - rs;
				val += (ls / l.size()) * L;
				for (int i = 0; i < rs % r.size(); i++) {
					val += (((r[(r.size() - i - 1) % r.size()] - r[(((int)r.size() - i - 2) + 4ll * r.size()) % r.size()]) + L) % L) * 1;
				}
				val += ((rs / r.size()) * L) * 1;
				for (int i = 0; i < ls % l.size(); i++) {
					val += (((l[(i + 1) % l.size()] - l[i]) + L) % L) * 1;
					//val += (((l[(l.size() - i) % l.size()] - l[(l.size() - i - 1)]) + L) % L) * 1;
				}
				if (val > T) top = mid;
				//else if (val == T && mid % 2 == 0) top = mid;
				else bot = mid;
			}
			if (bot % 2 == 1) res = make_pair(2, (bot/2) % l.size());
			else res = make_pair(1, (r.size() - (bot/2+1) % r.size()) % r.size());
		}
	}
	int t = -1;
	if (res.first == 1) t = (r[res.second] + oriT/2) % L;
	else t = ((l[res.second] - oriT/2) % L + L) % L;
	int f = -1;
	for (int i = 0; i < even.size(); i++) {
		if (even[i] == t) {
			f = i;
		}
	}
	for (int i = 0; i < N; i++) printf("%d\n", even[(f + i) % even.size()]);
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

void solve(){
    int X; cin>>X;
    vector<bool> b(1000000,false);
    vi prime;
    rrep(i,2,1000){
        bool flag=true;
        for(auto p:prime){
            if(i%p==0) flag=false;
        }
        if(flag) prime.emplace_back(i);
    }
    
    // for(auto p:prime) cout<<p<<" ";
    // cout<<"\n\n";

    int i=0;
    while(1)
    {    
        bool flag=true;
        for(auto p:prime) {
            // cout<<p<<"\n";
            if((X+i)<=p) break;
            if((X+i)%p==0) {
                flag=false;
                break;
            }
            else continue;
            // else cout<<"! ";
        }
        if(flag){
            cout<<(X+i)<<endl;
            break;
        }
        ++i;
    }

    // cout<<"done"<<"\n";

    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h> 

int main(){
  int i,j,n,m;

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

  int A[n][m],b[m],c[n];

  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      A[i][j] = 0;
    }
  }
 
  for(i=0; i<m; i++) b[i] = 0;

  for(i=0; i<n; i++) c[i] = 0;

  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&A[i][j]);
    }
  }

  for(i=0; i<m; i++) scanf("%d",&b[i]);

  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      c[i] += A[i][j]*b[j];
    }
  }

  for(i=0; i<n; i++) printf("%d\n",c[i]);

  return 0;
}

  

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
double dp[21][200001];
const double INF=(1LL<<50);
int a[21];
int n;
double dfs(int idx,int lastNum){
    if(idx==-1)
        return 0.0;
    if(!EQ(INF,dp[idx][lastNum]))
        return dp[idx][lastNum];
    double minCost=INF;
    if(idx==n-1)
        for(int i = 1; i <= 200000; i++){
            minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
        }
    else
        // lastNumðèØéÅJÚ
        for(int i = 1; i*i <= lastNum; i++){
            if(lastNum%i==0){
                minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
                minCost=min(minCost,max(dfs(idx-1,(lastNum/i)),(double)abs(a[idx]-(lastNum/i))/a[idx]));
            }
        }
    return dp[idx][lastNum]=minCost;
}

int main(){
    for(int i = 0; i < 21; i++)
        for(int j = 0; j < 200001; j++)
            dp[i][j]=INF;
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i];
    double res=dfs(n-1,0);
    printf("%.9f\n",res);
    return 0;
}

Measured memory_bytes: 32000
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int W,H,x,y;
	cin>>W>>H>>x>>y;
	long double S=(long double)W * H / 2;
	cout<<fixed;
	cout<<setprecision(12)<<S<<" ";
	
	if(W==2*x && H==2*y){
		cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int N,A=0;
    cin >>N;
    vector <int> vec(N);
    REP(i,N) cin >> vec[i];

    SORT(vec);

    vec[vec.size()-1] = vec[vec.size()-1]/2;

    REP(i,N)  A+=vec[i];

    cout << A << endl;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n >> x;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int bnc = 1, ind = 0;
    for(int i = 0; i < n; i++)
    {
        ind += a[i];
        if(ind > x)
        {
            break;
        }
        bnc++;
    }
    cout << bnc << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
word_list = {}

for i in range(n):
    s = input()
    if s not in word_list :
        word_list[s] = 1
    else:
        word_list[s] += 1

m = int(input())

for j in range(m):
    s = input()
    if s not in word_list:
        word_list[s] = -1
    else:
        word_list[s] -= 1
if max(word_list.values()) < 0:
    print(0)
else:
    print(max(word_list.values()))


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

using namespace std;

int main()
{
    int n; cin >> n;
    while (n--) {
        int a[3]; cin >> a[0] >> a[1] >> a[2];

        sort(a, a + 3);

        if (a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) cout << "YES\n";
        else cout << "NO\n";
    }
}

Measured memory_bytes: 1136
#include<stdio.h>
int main(){
    int N,x;
    x=0;
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            x=x+a[i]*a[j];
        }
    }
    printf("%d\n",x);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



int main() {
    ll n, a, b, c, d, dd;
    cin >> n >> a >> b >> c >> d;
    dd = abs(b - a);
    REP(i, n){
        if(i * c - (n - 1 - i) * d <= dd && dd <= i * d - (n - 1 - i) * c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

for i in range(len(a)):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j]>v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(" ".join([str(i) for i in a]))

Measured memory_bytes: 7692
function main()
  
  S = split(chomp(readline()),"")
  T = split(chomp(readline()),"")
  
  check = false
  tmp = ""
  
  for i in 1:length(S)
    
    if S == T
      check = true
      println("Yes")
      break
    else
      tmp = S[end]
      pop!(S)
      insert!(S,1,tmp)
    end
    
  end
  
  if check == false
    println("No")
  end
  
end

main()

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

int main()
{
  int T, X;
  cin >> T >> X;
  cout << std::setprecision(10) << (double)T / X << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <functional>
#include <list>
#include <iomanip>
#include <cctype>
#include <math.h>

#define rep(i,first,end) for(int i = first; i < end; i++)

using namespace std;


int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    long long  n,ans = 0;
    cin >> n;
    
    map<string, int> mp;
    string s;
    
    rep(i,0,n){
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        n = iter->second;
        if(n >= 2) {
            ans += n*(n-1)/2;
            
        }
    }
    cout << ans << endl;


}
    



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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

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

  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vector<int> costs;

  for (int i = *min_element(all(a)); i <= *max_element(all(a)); ++i) {
    int sum = 0;
    rep(j, n) {
      sum += pow(a[j] - i, 2);
    }
    costs.push_back(sum);
  }

  cout << *min_element(all(costs)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define len(arr) (int)(sizeof(arr)/sizeof((arr)[0]))
#define Sort(arr) sort(arr,arr+len(arr))
#define For(i,s,n) for(int i=s;i<n;i++)	
#define Rep(i,n) for(int i=0;i<n;i++)
#define Per(i,n) for(int i=n;i>=0;i--)
#define All(x) (x).begin(),(x).end()
#define in(arr,n) Rep(i,n) cin >> arr[i];
#define in2(arr1,arr2,n) Rep(i,n) cin >> arr1[i] >> arr2[i];
#define in3(arr1,arr2,arr3,n) Rep(i,n) cin >> arr1[i] >> arr2[i] >> arr3[i];
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define MOD 1000000007
#define MOD9 1000000009

//{ ライブラリ

// 標準出力の高速化
#define endl "\n"

// 出力
template<typename Type>
void print(Type a[],int n){
	Rep(i,n) cout << a[i] << endl;
}
template<typename Type1,typename Type2>
void print(Type1 a[],Type2 b[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << endl;
}
template<typename Type1,typename Type2,typename Type3>
void print(Type1 a[],Type2 b[],Type3 c[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << " " << c[i] << endl;
}

// 配列の最大値
template<typename Type>
Type max(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=max(ret,a[i]);
	return ret;
}

// 配列の最小値
template<typename Type>
Type min(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=min(ret,a[i]);
	return ret;
}

// 最大公約数
template<typename Type>
Type gcd(Type a,Type b){return(b==0)?a:gcd(b,a%b);}
template<typename Type>
Type gcd(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=gcd(ret,a[i]);
	return ret;
}

// 最小公倍数
template<typename Type>
Type lcm(Type a,Type b){return (a/gcd(a,b))*b;}
template<typename Type>
Type lcm(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=lcm(ret,a[i]);
	return ret;
}

// aを元にしてペアでソート
template<typename Type1,typename Type2>
void PairSort(Type1 a[],Type2 b[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,left,i-1);
	if(j+1<right) PairSort(a,b,j+1,right);
}
template<typename Type1,typename Type2,typename Type3>
void PairSort(Type1 a[],Type2 b[],Type3 c[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		swap(c[i],c[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,c,left,i-1);
	if(j+1<right) PairSort(a,b,c,j+1,right);
}

// 配列を逆順にする
template<typename Type>
void Reverse(Type a[],int n){Rep(i,n/2) swap(a[i],a[n-i-1]);}

// 文字列を逆順にする
// reverse(All(str));

//}

int main(){
	ll N;
	cin >> N;
	ll A[N];
	in(A,N);
	
	ll R[N];
	R[0]=A[N-1];
	ll diff=2*R[0]-A[0];
	For(i,1,N){
		R[i]=A[i-1]-R[i-1];
		//cout << "diff=" << diff << endl;
		diff+=2*R[i]-A[i];
	}
	//Rep(i,N) cout << R[i]*2 << endl;
	//cout << "diff=" << diff << endl;
	Rep(i,N) cout << R[i]*2+diff*(i%2?1:-1) << " ";
}

Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   string s;
   string t;
   cin>>s>>t;
   int sz1=s.length();
   int sz2=t.length();
   int dp[sz1+1][sz2+1];
   for(int i=0;i<=sz2;i++)
   {
       dp[0][i]=0;
   }
   for(int i=0 ; i<=sz1;i++)
   {
       dp[i][0]=0;
   }
   for(int i=1 ; i<=sz1 ; i++)
   {
       for(int j=1 ; j<=sz2 ; j++)
       {
           if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1] + 1;
           else
             dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
   }
   int mx = dp[sz1][sz2];
   vector<char>ans;
   int i=sz1,j=sz2;
   while(i>0 && j>0)
   {
       if(s[i-1]==t[j-1])
       {
           ans.pb(s[i-1]);
           i--;j--;
       }
       else if(dp[i-1][j]>dp[i][j-1])
        i--;
       else
        j--;
   }
   reverse(all(ans));
   for(auto x:ans)
    cout<<x;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define db long double
#define up upper_bound
#define lb lower_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define int long long
#define mod 1000000007
#define MAX 100005
using namespace std;
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
 
    ll cur = 0;
    ll n;
    cin >> n;
    vll v(n);
    rep(i,0,n) {
    	cin >> v[i];
    	if(v[i] == cur+1) cur++;
    }
    if(cur == 0) cout << "-1\n";
    else cout << n-cur;
    
    return 0;
 
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}


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



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

    int  N,A,B;
    cin>>N>>A>>B;
    if(N*A<B)cout<<N*A<<endl;
    else cout<<B<<endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {  
    int n, k; cin >> n >> k;
    int cnt = 0;
    while(n>0){
        n /= k;
        cnt++;
    }
    cout << cnt << ln;
}

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();

			long ans = k;
			for (int i = 0; i < n - 1; i++) {
				ans *= k - 1;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 11092
def fact(n)
  mod = 10 ** 9 + 7
  ret = 1
  (1..n).each do |i|
    ret = ret * i % mod
  end
  ret
end

n, m = gets.strip.split.map(&:to_i)

small, large = [n, m].sort
fact_l = fact(large)
fact_s = fact(small)

mod = 10 ** 9 + 7

if large - small > 1
  puts 0
elsif large == small
  puts (fact_l * fact_s * 2) % mod
else
  puts (fact_l * fact_s) % mod
end


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

int x, y, w, h;
bool check( int nx, int ny ) {
  if ( nx >= x && nx <= w ) {
    if ( ny >= y && ny <= h ) {
      return true;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> x >> y >> w >> h;
    w += x;
    h += y;
    
    int answer = 0;
    int k;
    cin >> k;
    for ( int j = 0; j < k; j++ ) {
      int nx, ny;
      cin >> nx >> ny;
      if ( check( nx, ny ) ) answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

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

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

    int counter = 0;
    rep(i, N-2){
        if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i+2) == 'C')counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b;cin>>n>>a>>b;
  if(a+b>n+1||a*b<n){
    cout<<-1<<endl;
    return 0;
  }
  vector<ll> ans;
  for(ll i=b;i>=1;i--){
    ans.push_back(i);
  }
  ll nb=n-b;
  ll na=a-1;
  ll now=b;
  for(;;){
    if(na==0)break;
    ll g=ceil((double)nb/na);
    for(ll i=now+g;i>now;i--){
      ans.push_back(i);
    }
    now+=g;
    nb-=g;
    na--;
  }
  for(ll i=0;i<n;i++)cout<<ans[i]<<" ";
}

Measured memory_bytes: 6128
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;

int main(){
    
    int A, B , C, X, Y;
    cin >>A >>  B >> C >> X >> Y;
    long long ans = A * X + B *Y;

    int N1  = min(X, Y);
    int N2  = max(X, Y);

    rep(i, N1){
        ans = min(ans, ans + 2 * C- A -B);
    }
    int z;
    if(X > Y) z=A;
    else z=B;
    rep(i, N2 - N1){

        ans = min(ans, ans + 2 * C- z); 
    } 

    cout << ans << endl;


    return 0;
}

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

ll p[60], a[60];

long long dfs(int level, long long x) {
  if(a[level] <= x) return p[level];
  if(x <= 1) return 0;
  if(a[level-1] + 1 >= x) return dfs(level-1, x - 1);
  return p[level-1] + 1 + dfs(level-1, x - a[level-1] - 2);
}

int main(){
  long long n, x;
  
  cin >> n >> x;
  
  p[0] = 1;
  a[0] = 1;
  for(int i=0;i<59;i++) p[i+1] = p[i] * 2 + 1;
  for(int i=0;i<59;i++) a[i+1] = a[i] * 2 + 3;
  
  cout << dfs(n, x) << endl;
}






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

using namespace std;

void solve(void)
{
	int n, m;
	cin >> n >> m;
	m += n * 3;
	cout << m / 2 << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
n = input()
xs = map(float, input().split())
ys = map(float, input().split())
abs_d = [abs(x - y) for (x, y) in zip(xs, ys)]
d = [sum([i ** p for i in abs_d]) ** (1 / p) for p in range(1, 4)]
d.append(max(abs_d))

print(*d, sep='\n')


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
ほどくとして端からかな
どこか2本がL以上ならいけるか
*/
int main(){
  ll N,L; cin>>N>>L;
  vector<ll> A(N+1,0);
  for(ll i=1; i<=N; i++) cin>>A[i];
  for(ll i=1; i<N; i++){
    ll n=A[i]+A[i+1];
    if(n>=L){
      ll asz=A.size()-1;
      //頭から
      cout<<"Possible"<<endl;
      for(ll j=1; j<i; j++) cout<<j<<endl;
      for(ll j=asz-1; j>=i; j--) cout<<j<<endl;      
      return 0;
    }
  }
  cout<<"Impossible"<<endl;
}

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

int main(){
	int n;
	cin>>n;
	
	int a[n];
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=1;i<n-1;i++){
		dp[i+1]=min((dp[i]+abs(a[i]-a[i+1])),dp[i-1]+abs(a[i-1]-a[i+1]));
	}
	cout<<dp[n-1];
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 071_arc_b / Link: https://arc071.contest.atcoder.jp/tasks/arc071_b  ----- */
/* ------問題------


-----問題ここまで----- */
/* -----解説等-----

なんかほんとは簡単にできた気がする

----解説ここまで---- */

LL W, H;

LL ans = 0LL;

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

	cin >> W >> H;
	VL x(W);
	FOR(i, 0, W) {
		cin >> x[i];
	}
	VL y(H);
	FOR(i, 0, H) {
		cin >> y[i];
	}

	LL xsum = 0, bef;
	FOR(i, 1, W) {
		(xsum += bef) %= MOD;
		(xsum += (x[i] - x[i - 1])*i % MOD) %= MOD;
		(bef += (x[i] - x[i - 1])*i % MOD) %= MOD;
	}
	bef = 0;
	LL ysum = 0;
	FOR(i, 1, H) {
		(ysum += bef) %= MOD;
		(ysum += (y[i] - y[i - 1])*i % MOD) %= MOD;
		(bef += (y[i] - y[i - 1])*i % MOD) %= MOD;
	}
	ans = (xsum*ysum) % MOD;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) { string r = "["; for (int i = 0; i < (int)v.size() - 1; i++) r += to_string(v[i]) + ", ";
	if (!v.empty()) r += to_string(v.back()); return r + "]"; }

int main () { 
#ifdef XVENOM
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n, m, k;
	scanf("%lld%lld", &n, &m);
	k = min(m / 2, n);
	m -= 2 * k;
	k += m / 4;
	printf("%lld", k);
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORD(i, m, n) for (int i = m; i >= n; i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	double n,d;
	cin>>n>>d;
	double x,y;
	int sum=0;
	REP(i,n){
		cin>>x>>y;
		double k=sqrt(x*x+y*y);
		if(k<=d)sum++;
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3860
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <list>


constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr long long LONGINF = 1005000000000000000;
using namespace std;

using ll = long long;
/*    UnionFind
*/

class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};

/*
*/

int main() {
	int x, y, z, k; cin >> x >> y >> z >> k;

	ll a[1005], b[1005], c[1005];

	for (int i = 0; i < x; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < y; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < z; i++) {
		cin >> c[i];
	}

	priority_queue<ll> q;

	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			q.push(a[i] + b[j]);
		}
	}
	int n = k;

	priority_queue<ll> qq;

	while (!q.empty() && n) {
		n--;
		ll w = q.top(); q.pop();
		for (int i = 0; i < z; i++) {
			qq.push(w+c[i]);
		}
	}

	while (!qq.empty() && k) {
		k--;
		cout << qq.top() << endl;
		qq.pop();
	}

	return 0;
}

Measured memory_bytes: 43236
import sys
sys.setrecursionlimit(10**6)
n = int(input())
v = 10**5+2
e = [[] for i in range(2*v)]
for i in range(n):
    x,y = map(int,input().split())
    y += v
    e[x].append(y)
    e[y].append(x)
visit = [0]*(2*v)
def dfs(x):
    if not visit[x]:
        visit[x] = 1
        count[x//v] += 1
        for nex in e[x]:
            dfs(nex)
ans = 0
for i in range(v):
    if not visit[i]:
        count = [0]*2
        dfs(i)
        ans += count[0]*count[1]
print(ans-n)
    


Measured memory_bytes: 85040
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0){
        cout<<a-b<<endl;
    }
    else{
        cout<<b-a<<endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0;
    cin>>n;
    if(n&1)
        cout<<n/2+1;
    else cout<<n/2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
 
using namespace std;
 
typedef long long ll;
 
int main() {
  int n;
  scanf("%d", &n);
 
  int a[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  int c = 0;
  int small;
  for(int i = 0; i < n-1; i++){
    small = i;
    for(int j = i; j < n; j++){
      if(a[j] < a[small]){
        small = j;
      } 
    }
    swap(a[i],a[small]);
    if(i != small) c++;    
  }

  for(int i  = 0; i < n; i++){
    if(i != 0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
  printf("%d\n",c);
    return 0;
}

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

using namespace std;

#define endl '\n'


int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  char c;
  cin >> c;

  if(c >= 'A' && c <= 'Z')
    cout << "A" << endl;
  else
    cout << "a" << endl;
 
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int A[MC];
int S;

int main(){
	cin >> N;
	repp(i,1,N+1){
		cin >> A[i];
		S += abs(A[i-1]-A[i]);
	}
	S += abs(A[N]);
	repp(i,1,N+1){
		cout << S-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]) << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;
const ll mod=998244353;

int main(){
  bool flag=true;
  ll n,ans=1;
  cin >> n;
  map<int,int> mp;
  mp[0]=0;
  r(i,n){
    int a;
    cin >> a;
    mp[a]++;
    if(i==0&&a!=0)flag=false;
    if(i!=0&&a==0)flag=false;
  }
  if(!flag)cout<<0<<endl;
  else{
    int m=1,p=1;
    for(auto it=mp.begin();it!=mp.end();it++){
      if(it==mp.begin())continue;
      if((*it).first!=m)ans=0;
      else {
        r(i,(*it).second){
          ans*=p;
          ans%=mod;
        }
        m++;
        p=(*it).second;
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		
		if(N%3==0) {
			if(a[0]==a[N/3-1] && a[N/3]==a[N*2/3-1] && a[N*2/3]==a[N-1] && (a[0]^a[N/3])==a[N*2/3]) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println(a[N-1]==0 ? "Yes" : "No");
		}
		
		sc.close();
	}
}



Measured memory_bytes: 50060
#include<stdio.h>
int main(void)
{
	int n,p[200][3],t[200],i,j,k,flg;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&p[i][0],&p[i][1],&p[i][2]);
		t[i]=0;
	}
	for(i=0;i<3;i++){
		for(j=0;j<n;j++){
			flg=1;
			for(k=0;k<n;k++){
				if(p[j][i]==p[k][i]&&j!=k){
					flg=0;
					break;
				}
			}
			if(flg==1){
				t[j]+=p[j][i];
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",t[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#include <unordered_set>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;

//==============================================

#define NIL -2000000050

struct node {
	int key;
	int left = NIL;
	int right = NIL;
};

node T[500050];

void insert(int z) {
	int y = NIL;
	int x = 0;

	while (x != NIL) {
		y = x;
		if (T[z].key < T[x].key) {
			x = T[x].left;
		} else {
			x = T[x].right;
		}
	}

	if (z == 0) return;

	if (T[z].key < T[y].key ) {
		T[y].left = z;
	} else {
		T[y].right = z;
	}
}

void inorder(int v) {
	if (v == NIL) return;
	inorder(T[v].left);
	cout << " " << T[v].key;
	inorder(T[v].right);
}

void preorder(int v) {
	if (v == NIL) return;
	cout << " " << T[v].key;
	preorder(T[v].left);
	preorder(T[v].right);
}


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

	int n;
	cin >> n;

	string s;
	int v;

	REP(i, n) {
		cin >> s;
		if (s == "insert") {
			cin >> v;
			T[i].key = v;
			insert(i);
		} else {
			inorder(0);
			cout << "\n";
			preorder(0);
			cout << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 9076
N=int(input())
t=1
a=1
for i in range(1,N+1):
    tk,ao=input().split()
    T=int(tk)
    A=int(ao)
    n=max((-1*t//T)*-1,(-1*a//A)*-1)
    a=n*A
    t=n*T
print(a+t)   
    

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
	using namespace std;
	int main() {
		int N,K,ans=0;
		cin >> N >> K;
		vector<int> h(N);
		for (int i = 0; i < N; i++){
			cin >> h[i];
			
		}
		for (int i = 0; i < N; i++){
			if (h[i] >= K)ans++;

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
    #define REP(i,n) for(int i=0;i<n;i++)
    #define LOOP(i,x,n) for(int i=x;i<n;i++)
    #define ALL(v) (v).begin(),(v).end()
    #define PB push_back
    #define MP make_pair
    #define FIR first
    #define SEC second
    #define int long long
    using namespace std;
    const int MOD=1000000007;
    const int INF=1000000009;
     
    signed main(){
      int n;
      cin>>n;
      vector<int> a(n),b(n),c(n);
      REP(i,n)cin>>a[i];
      REP(i,n)cin>>b[i];
      REP(i,n)cin>>c[i];
      sort(ALL(a));
      sort(ALL(b));
      sort(ALL(c));
      int ans=0;
      REP(i,n){
        auto x=lower_bound(ALL(a),b[i])-a.begin();
        auto y=c.end()-upper_bound(ALL(c),b[i]);
        //cout<<x<<' '<<y<<endl;
        ans+=x*y;
      }
      cout<<ans<<endl;
      return 0;
    }

Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
  int n,k;
  scanf("%d %d",&n,&k);
  int a[300000];
  int tmp[300000];

  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }


  while(k-->0){
    int flag=0;
    for(int i=0;i<n;i++){
      tmp[i]=0;
    }

    for(int i=0;i<n;i++){
      int min=i-a[i]<0?0:i-a[i];
      // if(i-a[i]<0){
      //   min=0;
      // }
      tmp[min]++;
      int max=i+a[i]>n-1?n-1:i+a[i];
      // if(max>n-1){
      //   max=n-1;
      // }
      if(max+1<n){
        tmp[max+1]--;
      }
    }
    for(int i=0;i<n;i++){
      if(i!=0){
        tmp[i]+=tmp[i-1];
      }
      if(a[i]!=tmp[i]){
        flag=1;
      }
      a[i]=tmp[i];
    }
    if(flag==0)break;
  }


  for(int i=0;i<n;i++){
    printf("%d ",a[i]);
  }
  puts(" ");

  return 0;
}


Measured memory_bytes: 3292
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    vector<int> v(n, 0);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        v[i] = l + i;
        sum += v[i];
    }
    vector<int> aji(n, sum);
    for (int i = 0; i < n; i++)
    {
        aji[i] -= v[i];
    }
    int max = 100 * 2000;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(abs(aji[i]-sum)<max)
        {
            ans = i;
            max = abs(aji[i] - sum);
        }
    }
    cout << aji[ans] << endl;
    return 0;
}

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

template<Int MOD = 1000000007>
struct Mod{
  Int prev=0;
  vector<Int> fact,inv,finv;
  Mod(){}
  Mod(Int n){init(n);}
  
  Int pow(Int x,Int n){
    Int res=1;
    while(n){
      if(n&1) (res*=x)%=MOD;
      (x*=x)%=MOD;
      n>>=1;
    }
    return res;
  }
  
  Int inverse(Int a){
    return pow(a,MOD-2);
  }
  
  void init(Int n){
    if(prev>=n) return;
    prev=n;
    fact=inv=finv=vector<Int>(n);
    
    fact[0]=1;
    for(Int i=1;i<n;i++)
      fact[i]=(fact[i-1]*i)%MOD;
    
    inv[1]=1;
    for(Int i=2;i<n;i++)
      inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    
    finv[0]=1;
    for(Int i=1;i<n;i++)
      finv[i]=finv[i-1]*inv[i]%MOD;
  }
  
  Int comb(Int n,Int k){
    Int res=1;
    for(Int i=0;i<k;i++){
      res*=(n-i)%MOD;
      res%=MOD;
      res*=inverse(i+1);
      res%=MOD;
    }
    return res;
  }
  
  //only for prime MOD
  Int C(Int n,Int k){
    if(k<0||k>n) return 0;
    return fact[n]*finv[k]%MOD*finv[n-k]%MOD;
  }

  Int H(Int n,Int k){
    return C(n+k-1,n);
  }

  Int S(Int n,Int k){
    Int res=0;
    for(Int i=1;i<=k;i++){
      Int tmp=C(k,i)*pow(i,n)%MOD;
      if((k-i)&1) res+=MOD-tmp;
      else res+=tmp;
      res%=MOD;
    }
    res=res*finv[k]%MOD;
    return res;
  }
  
  Int B(Int n,Int k){
    Int res=0;
    for(Int j=1;j<=k;j++){
      res+=S(n,j);
      res%=MOD;
    }
    return res;
  }
  
  Int montmort(Int n){
    Int res=0,rinv=1;
    for(Int k=2;k<=n;k++){
      rinv=rinv*inverse(k)%MOD;
      if(k%2) res+MOD-rinv;
      else res+=rinv;
      res%=MOD;
    }
    for(Int i=1;i<=n;i++) res=res*i%MOD;
    return res;
  }
  
  // calculate P(t) from given points in [0,N]
  Int LagrangePolynomial(vector<Int> &y,Int t){
    Int n=y.size()-1;
    init(n+1);
    Int num=1;
    for(Int i=0;i<=n;i++)
      num=num*((t-i)%MOD)%MOD;
    Int res=0;
    for(Int i=0;i<=n;i++){
      Int tmp=(y[i]*num%MOD)*inverse((t-i)%MOD)%MOD;
      tmp=tmp*finv[i]%MOD;
      tmp=tmp*finv[n-i]%MOD;
      if((n-i)&1) tmp=MOD-tmp;
      res=(res+tmp)%MOD;
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  const Int MOD = 1e9+7;
  Mod<MOD> mod(2e5);
  Int n,k;
  cin>>n>>k;
  cout<<mod.B(n,k)<<endl;
  return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    int min_n = 10000007;
    for(int i = 0; i < S.size() - 1; ++i) {
        string target = "000";
        target[0] = S[i];
        target[1] = S[i + 1];
        target[2] = S[i + 2];

        if(abs(stoi(target) - 753) < min_n) {
            min_n = abs(stoi(target) - 753);
        }
    }

    cout << min_n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{
	int ans=0;
	string s,t,a,b;
	cin >> s;
	cin >> t;
	for (int i = 0; i < 3; i++) {
		a = s.substr(i, 1);
		b = t.substr(i, 1);
		if (a == b) {
			ans += 1;
		}
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    S = input()
    T = input()

    num = len(S) - len(T)+1

    ans = len(T)
    for i in range(num):
        tmp = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                tmp += 1
        ans = min(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67728
import Data.Bool

main :: IO ()
main = do
  [w, h, x, y] <- map read . words <$> getLine :: IO [Double]
  let res = show $ w * h / 2
  let flg = bool "0" "1" $ w / 2 == x && h / 2 == y
  putStrLn $ unwords [res, flg]

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

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

int main(){
	ll n,m;
	cin >> n >> m;
	if(n == 1 || m == 1){
		if(n+m == 2)cout << 1 << endl;
		else if(n+m == 3)cout << 0 << endl;
		else if(n+m == 4)cout << 1 << endl;
		else cout << n+m-3 << endl;
	}
	else {
		cout << (n-2)*(m-2) << endl;
	}
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  auto s=readln.chomp.to!(char[]);
  auto t=readln.chomp.to!(char[]);

  if(s.length<t.length){writeln("UNRESTORABLE"); return;}

  auto mn=new char[](s.length);
  foreach(ref e; mn) e='z';
  bool none=true;
  for(auto i=0; i<=s.length-t.length; i++){
    bool ok=true;
    for(auto j=0; j<t.length; j++){
      ok&=(s[i+j]==t[j] || s[i+j]=='?');
    }
    if(ok){
      none=false;
      auto u=new char[](s.length);
      foreach(k; 0..i) u[k]=(s[k]=='?' ? 'a' : s[k]);
      foreach(k; 0..(t.length)) u[i+k]=t[k];
      foreach(k; (i+t.length)..(s.length)) u[k]=(s[k]=='?' ? 'a' : s[k]);
      if(u<mn) mn=u;
    }
  }
  
  if(none){
    writeln("UNRESTORABLE");
  }else{
    writeln(mn);
  }

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, a, b, c, d = map(int, readline().split())
    diff = a - b

    for i in range(n - 1):
        l = i * c - (n - 1 - i) * d
        r = i * d - (n - 1 - i) * c
        if l <= diff <= r:
            return print("YES")

    print("NO")


if __name__ == '__main__':
    main()


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

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

int main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    vector< vector< ll > > dp(100001, vector< ll >(13, 0)); //先頭i文字で考えられる、13で割った時の余りがjであるようなものの個数

    vector< vector< ll > > Num(7, vector< ll >(10, 0));
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j <= 9; j++) {
            Num[i][j] = j * static_cast< ll >(pow(10, i)) % 13;
        }
    }
    // cout << endl;
    // for (int i = 0; i < 6; i++) {
    //     for (int j = 0; j <= 9; j++) {
    //         cout << setw(2) << Num[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;
    if (s[0] == '?') {
        for (int i = 0; i < 10; i++) {
            dp[0][i] = 1;
        }
    } else {
        dp[0][s[0] - '0'] = 1;
    }
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i + 1] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[i + 1][(j + Num[(i + 1) % 6][k]) % 13] = (dp[i + 1][(j + Num[(i + 1) % 6][k]) % 13] + dp[i][j]) % MOD;
                }
            }
        } else {
            for (int j = 0; j < 13; j++) {
                dp[i + 1][(j + Num[(i + 1) % 6][s[i + 1] - '0']) % 13] = (dp[i + 1][(j + Num[(i + 1) % 6][s[i + 1] - '0']) % 13] + dp[i][j]) % MOD;
            }
        }
    }
    // for (int i = 0; i < s.size(); i++) {
    //     for (int j = 0; j < 13; j++) {
    //         cout << setw(3) << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[s.size() - 1][5] % MOD << endl;
    return 0;
}


Measured memory_bytes: 13696
#include <iostream>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int a[n];
  double s=0.0;
  int c=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    s += a[i];
  }
  for(int i=0; i<n; i++){
  	if(a[i]>=s/(4*m)) c++;
  }
  if(c>=m) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<math.h>
using namespace std;

 int main(){
   int x1,y1,x2,y2;
   cin >> x1 >> y1 >> x2 >> y2;
   int x3,y3,x4,y4;
   x3=x2+(y1-y2);
   y3=y2+(x2-x1);
   x4=x3+(y2-y3);
   y4=y3+(x3-x2);
   
   cout << x3 <<" "<< y3 <<" "<< x4 <<" "<< y4 <<endl;
 }
   

Measured memory_bytes: 256