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

int abs(int a, int b) {
  if (a >= b) return a - b;
  if (b > a) return b - a;
}

int dis(int a, int b, int x, int y) {
  int mina = abs(b - a);
  int minb;
  minb = abs(a, x) + abs(b, y) + 1;
  if (mina >= minb) return minb;
  if (minb > mina) return mina;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a.at(i).at(j) = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (i + 1 == j) a.at(i).at(j) = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a.at(i).at(j) != 1) {
        a.at(i).at(j) = dis(i, j, x - 1, y - 1);
      }
    }
  }

  vector<int> k(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      k.at(a.at(i).at(j))++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << k.at(i) << endl;
  }
}


Measured memory_bytes: 16000
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

d = {}
l = []
for a in A:
  if a in d:
    d[a] += 1
    if d[a] % 2 == 0:
      l.append(a)
  else:
    d[a] = 1
  
  if len(l) == 2:
    print(l[0] * l[1])
    quit()

print(0)

Measured memory_bytes: 19916
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
LL f[900015], r[900015];
LL th[900015];
LL inv(LL a){
    LL ans = 1;
    LL b = mod-2;
    while(b){
        if(b%2) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
LL C(int a, int b){
    return f[a]*r[b]%mod*r[a-b]%mod;
}
int main(){
    f[0] = r[0] = th[0] = 1;
    for(int i=1;i<=900010;i++){
        f[i] = f[i-1]*i%mod;
        r[i] = inv(f[i]);
        th[i] = th[i-1]*3%mod;
    }
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    LL ans = 0, sum = 1, ll = 0, rr = 0;
    for(int i=0;i<=m+k;i++){
        int l = max(0, i-k), r = min(i, m);
        if(ll < l) sum = (sum - C(i, ll) + mod)%mod, ll++;
        if(rr > r) sum = (sum - C(i, rr) + mod)%mod, rr--;

        LL res = C(i+n-1, n-1)*th[n+m+k-i-n]%mod*sum%mod;
        ans = (ans + res)%mod;

        sum = sum*2%mod;
        if(ll != 0) sum = (sum + C(i, ll-1))%mod;
        if(rr != i) sum = (sum + C(i, rr+1))%mod;
        rr++;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 21376
while True:
    n=int(input())
    if n==0:
        break
    else:
        A=[]
        i=1
        while i <=n:
            a=int(input())
            A.append(a)
            i=i+1
        b=(sum(A)-max(A)-min(A))//(n-2)
        print(b)


Measured memory_bytes: 5596
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,K;
char s[1048580];
int *p0[21],*p1[21],*cnt[21];
int *dp[21][21];
int main()
{
	scanf("%d %d",&n,&K);
	for(int i=0;i<=n;++i)
		for(int j=0;i+j<=n;++j)
			dp[i][j]=new int[1<<i+j]{0};
//	printf("!!!");
	for(int i=0;i<=n;++i)
	{
		p0[i]=new int[1<<i],p1[i]=new int[1<<i],cnt[i]=new int[1<<i]{0};
		p0[i][0]=i-1,p1[i][0]=-1;
		for(int j=1;j<1<<i;++j)
		{
			if((j>>i-1)&1)p1[i][j]=i-1,p0[i][j]=p0[i-1][j^(1<<i-1)];
			else p0[i][j]=i-1,p1[i][j]=p1[i-1][j];
		}
	}
/*	for(int i=0;i<=n;++i)
	{
		printf("%d:\n",i);
		for(int j=0;j<1<<i;++j)printf("%d %d\n",p0[i][j],p1[i][j]);
	}*/
	for(int i=0;i<=n;++i)
	{
		scanf("%s",s);
		for(int j=0;j<1<<i;++j)if(s[j]=='1')dp[0][i][j]=1;
	}
	int x;
	for(int i=0;i<=n;++i)
		for(int j=1;i+j<=n;++j)
			for(int k=0;k<1<<i+j;++k)
			{
				if(~(x=p0[j][k&((1<<j)-1)]))dp[i+1][x][((k>>j)<<x+1)|(k&((1<<x+1)-1))]+=dp[i][j][k];
				if(~(x=p1[j][k&((1<<j)-1)]))dp[i+1][x][((k>>j)<<x+1)|(k&((1<<x+1)-1))]+=dp[i][j][k];
			}
/*	for(int i=0;i<=n;++i)
		for(int j=0;i+j<=n;++j)
		{
			printf("%d %d:",i,j);
			for(int k=0;k<1<<i+j;++k)printf("%d ",dp[i][j][k]);
			printf("\n");
		}*/
	for(int i=0;i<=n;++i)
		for(int j=0;i+j<=n;++j)
			for(int k=0;k<1<<i+j;++k)
				cnt[i][k>>j]+=dp[i][j][k];
//	for(int i=0;i<=n;++i)
//	{
//		for(int j=0;j<1<<i;++j)printf("%d ",cnt[i][j]);
//		printf("\n");
//	}
	for(int i=n;i;--i)
		for(int j=0;j<1<<i;++j)
			if(cnt[i][j]>=K)
			{
			//	printf("%d\n",cnt[i][j]);
				for(int k=i-1;~k;--k)printf("%d",j>>k&1);
				return 0;
			}
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    if(a%k==0 || b%k==0){
        cout << "OK";
    }
    else if(k - a%k <=b-a){
        cout << "OK";
    }else{
        cout << "NG";
    }
    return 0;
}


Measured memory_bytes: 3652
loop do
  n = gets.chomp.to_i
  break if n == 0

  keys = gets.chomp.split(' ').map(&:to_i)
  station_list = ('a'..'z').to_a + ('A'..'Z').to_a
  stations_pos = {}
  station_list.size.times do |i|
    stations_pos[station_list[i]] = i
  end

  enc_stations = gets.chomp
  dec_stations = ''

  enc_stations.size.times do |i|
    pos = stations_pos[enc_stations[i]]
    dec_stations << station_list[pos - keys[i % keys.size]]
  end

  puts dec_stations
end

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

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

int main(){
    int N;
    cin >> N;
    int ans = 1<<30;
    for(int A=1; A<N; A++){
        int B = N - A;
        ans = min(ans, func(A)+func(B));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
mNK = map(int, input().split())
lNK = list(mNK)

mTel = map(int, input().split())
lTel = list(mTel)

lWent = [-1 for i in range(lNK[0])]
nTown = 0
loopCnt = -1

for i in range(lNK[1]):
    nextTown = lTel[nTown] - 1
    lWent[nTown] = i
    if(lWent[nextTown] != -1):
        loopCnt = i - lWent[nextTown] + 1
        surplus = (lNK[1] - i - 1) % loopCnt
        nTown = lWent.index(lWent[nextTown] + surplus)
        break
    nTown = nextTown

print(nTown + 1)

Measured memory_bytes: 32192
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<int>> a(H+1,vector<int>(W+1));
    vector<vector<long long>> c(H+1,vector<long long>(W+1));
    for (int h=1; h<=H; h++) {
        string s;
        cin >> s;
        for (int w=1; w<=W; w++) {
            if (s[w-1]=='#') a[h][w] = 1;
        }
    }

    c[1][0] = 1;
    for (int h=1; h<=H; h++) {
        for (int w=1; w<=W; w++) {
            if (a[h][w]==1) continue;
            c[h][w] = (c[h-1][w] + c[h][w-1]) % MOD;
        }
    }

    cout << c[H][W] << '\n';
    return 0;
}

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

void solve() {
    ll N, M;
    cin >> N >> M;
    vector<Req> requests(M);
    for (ll i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        requests[i] = make_pair(a, b);
    }
    sort(requests.begin(), requests.end());
    ll left = -1;
    ll right = 100100;
    ll destroy = 0;
    for (ll i = 0; i < M; ++i) {
        Req req = requests[i];
        if (right <= req.first) {
            ++destroy;
            left = req.first;
            right = req.second;
        }
        if (left < req.first) left = req.first;
        if (req.second < right) right = req.second;
    }
    cout << ++destroy << endl;
}

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


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

int main()
{
    int n, k;
    cin >> n >> k;
    int ans = 1;
    for(int i=0;i<n;i++){
        ans = min(ans*2,ans+k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#include <queue>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
int N;
int K;
void solve(){
	int ans = 0;
	rep(i, N) {
		int c;
		cin >> c;
		if(c >= K)
			ans++;
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>


using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
#define INF 1e18
#define ar array
#define MAX 1000004
#define wt(x) int x;cin>>x;while(x--)

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
}
ll power(ll a,ll b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    ll res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
  

 int32_t main() {

c_p_c();
ll a; string s;
    cin>>a>>s;
    ll b = (s[0] - '0')*100 + (s[2] - '0')*10 + (s[3] - '0');
    ll tmp = a*b;
    tmp /= 100;
    cout<<tmp<<endl;


    

return 0;

}
 


   

        



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    while(1){
        int n,m;
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<int> h(n+1),w(m+1);
        h[0]=0;
        for(int i=0;i<n;i++){
            cin>>h[i+1];
            h[i+1]+=h[i];
        }
        w[0]=0;
        for(int i=0;i<m;i++){
            cin>>w[i+1];
            w[i+1]+=w[i];
        }
        vector<int> x(1000*1500+2),y(1000*1500+2);
        for(int i=0;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                x[h[j]-h[i]]++;
            }
        }
        for(int i=0;i<=m;i++){
            for(int j=i+1;j<=m;j++){
                y[w[j]-w[i]]++;
            }
        }
        long long ans=0;
        for(int i=1;i<1000*1500+2;i++){
            ans+=x[i]*y[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 14508
#include <stdio.h>

int main(void){
    int r,c;
    scanf("%d %d",&r,&c);
    int rcount[c];
    int i,count = 0;
    for(i=0;i<c;i++){
        rcount[i] = 0;
    }
    for(i=0;i<r;i++){
        int j,k;
        for(j=0;j<c;j++){
            scanf("%d",&k);
            printf("%d ",k);
            count += k;
            rcount[j] += k;
        }
        printf("%d\n",count);
        count = 0;
    }
    count = 0;
    for(i=0;i<c;i++){
        printf("%d ",rcount[i]);
        count += rcount[i];
    }
    printf("%d\n",count);
    return 0;
}


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

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

    int a, b; cin >> a >> b;

    if ((a+b)%2==0) cout << (a+b)/2;
    else cout << (a+b)/2 + 1;

    cout << "\n";

    return 0;
}

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

void solve(){
  int h, w; cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++){
    cin >> s[i];
  }
  for(int i = 0; i < w + 2; i++) cout << '#'; cout << endl;
  for(int i = 0; i < h; i++){
    cout << '#' << s[i] << '#' << endl;
  }
  for(int i = 0; i < w + 2; i++) cout << '#'; cout << endl;
  return;
}

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


Measured memory_bytes: 256
import sys
import collections


delta = [(0, 1), (1, 1), (1, 0), (0, -1), (-1, -1), (-1, 0)]
while True:
    t, n = map(int, raw_input().split())
    if t == 0 and n == 0:
        break
    obstacle = set()
    for i in xrange(n):
        x, y = map(int, raw_input().split())
        obstacle.add((x, y))
    cand = [tuple(map(int, raw_input().split()))]
    visited = set(cand)
    for i in xrange(t):
        new_cand = []
        for x, y in cand:
            for d_x, d_y in delta:
                key = (x + d_x, y + d_y)
                if key not in obstacle and key not in visited:
                    visited.add(key)
                    new_cand.append(key)
        cand = new_cand
    print len(visited)

Measured memory_bytes: 5060
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  tmp0 = input[0].split(" ")
  A = Number(tmp0[0])
  B = Number(tmp0[1])

  var ans=0
  var max1 = Math.max(A,B)
  ans += max1
  if(max1 === A){
    A--
  }else{
    B--
  }

  var max2 = Math.max(A,B)
  ans += max2
  console.log(ans)

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("5 3\n")

Measured memory_bytes: 7372
#include <set>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

struct Point {
	int x, y;
};

/*bool operator < (const Point& a, const Point& b) {
	return a.x < b.x && b.x < b.y; 
}*/

long long h, w, n;
Point points[100010];
std::set<std::pair<int, int>> pset;
std::set<std::pair<int, int>> used;
long long res[10];

void solve(int y, int x) {
	if(used.count({y, x})) {
		return;
	}

	used.insert({y, x});

	int cnt = 0;
	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			if(y + i >= h || x + j >= w) {
				continue;
			}
			cnt += pset.count({y + i, x + j});
		}
	}

	++res[cnt];
}

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

	for(int i = 0; i < n; ++i) {
		std::cin >> points[i].y >> points[i].x;
		--points[i].y, --points[i].x;
		pset.insert({points[i].y, points[i].x});
	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < 3; ++j) {
			for(int k = 0; k < 3; ++k) {
				if(points[i].y - j < 0 || points[i].y - j + 2 >= h || points[i].x - k < 0 || points[i].x - k + 2 >= w) {
					continue;
				}
				solve(points[i].y - j, points[i].x - k);
			}
		}
	}

	long long sum = 0;
	for(int i = 1; i < 10; ++i) {
		sum += res[i];
	}


	std::cout << (h - 2) * (w - 2) - sum << std::endl;

	for(int i = 1; i < 10; ++i) {
		std::cout << res[i] << std::endl;
	}
}

Measured memory_bytes: 47872
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    ll sum = accumulate(A.begin(), A.end(), 0LL);
    sort(A.rbegin(), A.rend());
    bool ok = true;
    REP(i, M) {
        if (4LL*A[i]*M < sum) {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3636
//支持分?操作的并?集
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e5+10;
int par[MAX_N];
int find(int x){
  int tmp=x;
  while(par[tmp]!=tmp){
    tmp=par[tmp];
  }
  return tmp;
}
int main(){
  //freopen("in", "r", stdin);
  char op[2];
  int N, Q, x;
  ll ans;
  par[1]=1;
  while(scanf("%d%d", &N, &Q), N){
    ans=0;
    for(int i=2; i<=N; i++){
      scanf("%d", par+i);
    }
    while(Q--){
      scanf("%s%d", op, &x);
      if(*op=='M'){
        par[x]=x;
      }
      else ans+=(ll)find(x);
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1564
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,k,ans=0;
  cin>>k;
  string s;cin>>s;
  vec ch(3);
  rep(i,1000){
    j=i;
    rep(k,3){
      ch[k]=j%10;
      j/=10;
    }
    k=0;
    rep(j,s.size()){
      if(s[j]=='0'+ch[k]){
        k++;
        if(k==3){
          ans++;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
        char s[128], p[128],c[256];
        scanf("%s%s",s,p);
        strcat(c,s);
        strcat(c,s);
        strstr(c,p)?printf("Yes\n"):printf("No\n");
        return 0;
}

Measured memory_bytes: 532
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;
    for (char c : S) {
        if (A + B > 0 && c == 'a') {
            cout << "Yes\n";
            A--;
        } else if (A + B > 0 && c == 'b' && B > 0) {
            cout << "Yes\n";
            B--;
        } else {
            cout << "No\n";
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<algorithm>

#define MAX 1000
#define INFINITY 2000000000

int A[MAX];
int m[MAX][MAX];
int n;

void minimumCount() {
    for (int i = 0; i < n; ++i) m[i][i] = 0;

    for (int l = 2; l <= n; ++l) {
        for (int i = 1; i <= n - l + 1; ++i) {
            int j = i + l - 1;
            m[i][j] = INFINITY;
            for (int k = i; k < j; ++k) {
                m[i][j] = std::min(m[i][j], m[i][k] + m[k+1][j] + A[i-1] * A[k] * A[j]);
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &A[i - 1], &A[i]);
    }
    minimumCount();
    printf("%d\n", m[1][n]);
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a,b,x;
	cin>>a>>b>>x;
	double ans;
	if(x>a*a*b/2){
		ans = atan(((2.0*a*a*b)-(2.0*x))/(a*a*a))*180/PI;
	}else{
		ans = atan((2.0*x)/(a*b*b))*180/PI;
		ans = 90.0 - ans;
	}
	printf("%.7f\n",ans);
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 4048
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q), r(Q);
    REP(i, Q) cin >> l[i] >> r[i];
    vector<int> a(S.size());
    bool f = false;
    FOR(i, 0, S.size()) {
        a[i] = a[i - 1];
        a[0] = 0;
        if (S[i] == 'A')
            f = true;
        else if (f && S[i] == 'C') {
            f = false;
            a[i]++;
        } else
            f = false;
    }

    REP(i, Q) {
        int ans = a[r[i] - 1] - a[l[i] - 1];
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 2256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int main(void){
	string s;
	string a = "..........";
	int pivot = 0;
	cin >> s;
	REP(i, s.size()){
		if(s[i] == 'B'){
			if(pivot > 0)
				pivot--;
		}
		else{
			a[pivot] = s[i];
			pivot++;
		}
	}
	REP(i, pivot){
		cout << a[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    vector<string> v = {"dream", "dreamer", "erase", "eraser"};
    
    for (int i=0; i<v.size(); i++){
        reverse(v[i].begin(), v[i].end());
    }
    
    int n = s.size();
    reverse(s.begin(), s.end());
    
    int i = 0;
    while(i < n){
        bool ok = false;
        for (int j=0; j<4; j++){
            bool flag = true;
            
            for (int k=0; k<v[j].size(); k++){
                if(s[i+k] != v[j][k]) flag = false;
            }
            if(flag){
                i += v[j].size()-1;
                // cout << v[j] << " " << i << endl;
                ok = true;
                if(i == n-1){
                    cout << "YES" << endl;
                    return 0;
                }
                break;
            }
        }
            if(!ok){
                cout << "NO" << endl;
                return 0;
            }
        i++;
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Yes(bool Yes){cout << (Yes ? "Yes" : "No") << endl;};
void YES(bool YES){cout << (YES ? "YES" : "NO") << endl;};

int main(){
    
    string s;
    cin >> s;
    Yes((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]));
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5)
from functools import lru_cache
N = int(input())

@lru_cache(maxsize=None)
def lucas(n):
    if n <= 1:
        return 2 - n
    else:
        return lucas(n - 2) + lucas(n - 1)

print(lucas(N))

Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        if(a.equals(b)){
            System.out.println("H");
        }else{
            System.out.println("D");
        }
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s,t;
	cin >> s >> t;
	int cnt=0;
	rep(i,0,3){
		if(s[i] == t[i])cnt++;;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

int N, K;

int main()
{
    cin >> N >> K;

    VI H;
    REP(i, N)
    {
        int h;
        cin >> h;

        H.push_back(h);
    }

    VL min_costs(N, 1'000'000'000'000);

    min_costs[0] = 0;

    FOR(i, 1, N) //3つ目に行くところからの一般化
    {
        int caped = max(0, i - K);
        LL cost = 1'000'000'000'000;
        FOR(from, caped, i)
        {
            cost = min(
                cost,
                min_costs[from] + abs(H[i] - H[from]));
        }
        min_costs[i] = cost;
    }

    cout << min_costs[N - 1] << endl;
}

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

int n ;
int m[13] , ans[13] ;

void f( int p ){
	int t ;
	
	for( int i=0 ; i<n ; i++ ){
		t=0 ;
		for( int j=0 ; j<n ; j++ ){
			if( m[i] == m[j] ){
				t++ ;
			}
		}
		ans[i] = t ;
	}
	
	int q=0 ;
	for( int i=0 ; i<n ; i++ ){
		if( m[i] == ans[i] ) q++ ;
	}
	
	if( q == n ){
		cout << p << endl ;
		for( int i=0 ; i<n ; i++ ){
			if( i != 0 ) cout << ' ' ;
			cout << ans[i] ;
		}
		cout << endl ;
	}else {
		swap( m , ans ) ;
		f(p+1) ;
	}
}

int main(){
	
	while( cin >> n , n ){
		for( int i=0 ; i<n ; i++ ){
			cin >> m[i] ;
		}
		
		f(0) ;
	}
	
return 0 ; 
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> arr(m, 0);
    for(auto& val: arr)
        cin >> val;
    int acc = accumulate(arr.begin(), arr.end(), 0);
    if (acc > n)
        cout << -1 << endl;
    else
        cout << n - acc << endl;

    return 0;
}



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

int main(){
	int a[3], n, r;
	double max;
	while (1){
		cin >> a[0] >> a[1] >> a[2];
		if (!a[0] && !a[1] && !a[2]) break;
		sort(a, a + 3);
		max = sqrt(a[0] * a[0] + a[1] * a[1]) / 2.0;
		cin >> n;
		for (int i = 0; i < n; i++){
			cin >> r;
			if (r > max) cout << "OK" << endl;
			else cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 1e6+7;

int ara[nmax];

/** Bit Sieve **/

const int pnmax = 1e6+7;
LL LIM;
bitset<pnmax> bs;   /// can sieve upto 1e8 in ~ 1 sec
int spf[pnmax];

void bit_sieve(LL upperbound)
{
    LIM = upperbound + 1;
    bs.set();                                     /// set all bits to 1
    bs[0] = bs[1] = 0;
    for (LL i = 2; i <= LIM; i++) /** If I don't want to know the primes , it is enough to loop upto sqrt(LIM) here **/
        if (bs[i])
        {
            for (LL j = i * i; j <= LIM; j += i)
                bs[j] = 0, spf[j] = i;
            spf[i] = i;
        }
}

/** Prime Factorization **/

bool ok = true;
bool vis[nmax];

void primeFactors(LL N)
{
    while(N>1)
    {
        LL sml = spf[N];

        if(N%sml==0)
        {
            if(vis[sml]==true) ok = false;
            else vis[sml] = true;

            while(N%sml==0)
            {
                N/=sml;
            }
        }
    }
}

int main()
{
    optimizeIO();

    bit_sieve(1e6);

    int n;
    cin>>n;


    for(int i=1; i<=n; i++) cin>>ara[i];

    int g = ara[1];

    for(int i=1; i<=n; i++)
    {
        g = __gcd(g,ara[i]);

        primeFactors(ara[i]);
    }

    if(ok) cout<<"pairwise coprime"<<endl;
    else
    {
        if(g==1)cout<<"setwise coprime"<<endl;
        else cout<<"not coprime"<<endl;
    }


    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int t=s.size();
  int k=0;
  for (int i = 0; i < t; i++) {
    if(s.at(i)=='o'){
      k++;
    }
  }
  if(15-t+k>=8){
    printf("YES");
  }
  else{
    printf("NO");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=1010;

int N;
int r[MAX_N],w[MAX_N];

void solve(){
    int maxr=0,sumr=0,sumw=0;
    for (int i=0;i<N;++i){
        maxr=max(maxr,r[i]);
        sumr+=r[i]; sumw+=w[i];
    }
    if (maxr*2>sumr){
        int rest=maxr*2-sumr;
        vector<bool> dp(rest+1,false);
        dp[0]=true;
        for (int i=0;i<N;++i){
            if (r[i]==maxr) continue;
            for (int j=rest;j>=w[i];--j){
                if (dp[j-w[i]]) dp[j]=true;
            }
        }
        int maxw=0;
        for (int j=0;j<=rest;++j) if (dp[j]) maxw=j;
        cout << maxr*2+sumw-maxw << '\n';
    } else cout << sumr+sumw << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N,N){
        for (int i=0;i<N;++i) cin >> r[i] >> w[i];
        solve();
    }
}


Measured memory_bytes: 3176
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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


    //start from here

    read(n);

    set <string> s; map <string, int> mp;

    fori (i, 1, n)
    {
        reads(str); sort(all(str));

        mp[str]++; s.insert(str);
    }

    int ans = 0;

    for (auto i : s)
    {
        ans += mp[i] * (mp[i] -1) / 2;
    }

    print(ans)

    return 0;
}


Measured memory_bytes: 19252
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
 
int main() {
    int m;
    cin >> m;
 
    vector<ll> c(m), d(m);
    ll u = 0;
    ll ans = -1;
    rep(i, m) {
        cin >> d[i] >> c[i];
        ans += c[i];
        u += c[i]*d[i];
    }
 
    ans += (u-1)/9;
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
# 以下の貪欲法は嘘解法（通るらしい）。
# 「高橋くんは右方向に落とすように、なるべく右を選ぶ。青木くんは落ちない範囲で左を選ぶ。これで落ちるか落ちないか判定する。
# これを上下左右で繰り返し、落ちなければ」
# 盤面が縦が十分大きい×横3、初期位置が中央、
# UULLRR
# RLUUUU
# は正解NOだが、貪欲でYESになってしまう。

# https://www.youtube.com/watch?v=Rr5ul_LDMiw
# コメントより：
# 3×3中央で、
# DRLL
# RUDD
# 初手青木くんがRなら高橋くんはそのままRするし、でなければLLしてどのみち外に出せる。

h, w, n = list(map(int, input().split()))
row, column = list(map(int, input().split()))
s_sente = input()
s_gote = input()

ans = [0, h-1, 0, w-1]
for i in reversed(range(n)):
    g = s_gote[i]
    if g == 'U':
        ans[1] = min(ans[1] + 1, h-1)
    elif g == 'D':
        ans[0] = max(ans[0] - 1, 0)
    elif g == 'L':
        ans[3] = min(ans[3] + 1, w-1)
    elif g == 'R':
        ans[2] = max(ans[2] - 1, 0)
    # print(ans)

    s = s_sente[i]
    if s == 'U':
        ans[0] = ans[0] + 1
    elif s == 'D':
        ans[1] = ans[1] - 1
    elif s == 'L':
        ans[2] = ans[2] + 1
    elif s == 'R':
        ans[3] = ans[3] - 1
    
    if not (ans[0] <= ans[1] and ans[2] <= ans[3]):
        print('NO')
        exit()
    # print(ans)

if ans[0] <= row-1 <= ans[1] and ans[2] <= column-1 <= ans[3]:
    # 「最後までコマが残るような初期配置の範囲」に、所与の初期配置が含まれる
    print('YES')
else:
    print('NO')


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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		int x = s.nextInt();
		char[] road = new char[n];
		int countFromStart = 0;
		int countToEnd = 0;
		int countC = 0;

		Arrays.fill(road, 'a');
		road[x] = 'x';

		for (int i = 0; i < m; i++) {
			int tmp = s.nextInt();
			road[tmp] = 'c';
		}
		for (int j = 0; j < x; j++) {
			if (road[j] == 'c') {
				++countFromStart;
			}
		}
		for (int k = x + 1; k < n; k++) {
			if (road[k] == 'c') {
				++countToEnd;
			}
		}

		if (countToEnd > countFromStart) {
			for (int p = 0; p < x; p++) {
				if (road[p] == 'c')
					++countC;
			}
		} else {
			for (int q = x + 1; q <n; q++) {
				if (road[q] == 'c') {
					++countC;
				}
			}
		}
		System.out.println(countC);
	}
}


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

int main() {
  int n; cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

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

  int pc, qc, count = 0;
  do {
    if (p == a) pc = count;
    if (q == a) qc = count;
    count ++;
  } while (next_permutation(all(a)));

  cout << abs(pc - qc) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 100005;
const LL INF = (LL)1e9 + 5;

int N, par[MAXN];
LL MOD, dp[MAXN], up_dp[MAXN];
vector<int> G[MAXN];

void dfs1(int v, int p) {
	par[v] = p;
	dp[v] = 1;
	for (int to : G[v]) {
		if (to != p) {
			dfs1(to, v);
			dp[v] = dp[v] * dp[to] % MOD;
		}
	}
	dp[v]++;
}

void dfs2(int v, int p) {
	LL suff;
	vector<LL> pref(G[v].size() + 1);
	pref[0] = suff = 1;
	for (int i = 0; i < G[v].size(); i++) {
		LL mul = (G[v][i] == p ? 1 : dp[G[v][i]]);
		pref[i + 1] = pref[i] * mul % MOD;
	}
	for (int i = G[v].size() - 1; i >= 0; i--) {
		if (G[v][i] != p) {
			up_dp[G[v][i]] = (suff * pref[i] % MOD * up_dp[v] + 1)% MOD;
			suff = suff * dp[G[v][i]] % MOD;
			dfs2(G[v][i], v);
		}
	}
}

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

	cin >> N >> MOD;
	for (int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	
	dfs1(1, 1);
	up_dp[1] = 1;
	dfs2(1, 1);
	
	for (int i = 1; i <= N; i++) {
		LL ans = up_dp[i];
		for (int to : G[i]) {
			if (to != par[i]) {
				ans = ans * dp[to] % MOD;
			}
		}
		cout << ans << "\n";
	}
	
	return 0;
}

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

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] str = line.split(" ");

        int num = Integer.parseInt(str[0])*100 + Integer.parseInt(str[1])*10 + Integer.parseInt(str[2]);

        if(num % 4 == 0){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23380
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
ll dp[333][333][333];

ll pl(ll a, ll b) {
  return (a+b)%mod;
}
ll ml(ll a, ll b) {
  return (a*b)%mod;
}

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  dp[0][1][0] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= n; j++) {
      //*
      // 強連結な頂点から強連結な頂点へ
      dp[i+1][j][0] = pl(dp[i+1][j][0], ml(dp[i][j][0], j));
      // 強連結な頂点から強連結でない頂点へ
      dp[i+1][j][1] = pl(dp[i+1][j][1], ml(dp[i][j][0], n-j));
      //*/
      for (int k = 1; k < n; k++) {
        // 強連結でない頂点から強連結でない頂点，新しく加える
        if (n-j-k >= 0) {
          dp[i+1][j][k+1] = pl(dp[i+1][j][k+1], ml(dp[i][j][k], n-j-k));
        }
        // 強連結でない頂点から強連結でない頂点へ
        dp[i+1][j][k] = pl(dp[i+1][j][k], ml(dp[i][j][k], k));
        // 強連結でない頂点から強連結な頂点へ
        if (j+k <= n) {
          dp[i+1][j+k][0] = pl(dp[i+1][j+k][0], ml(dp[i][j][k], j));
        }
      }
    }
  }
  ll res = 0;
  for (int i = 0; i < n; i++) {
    // printf("%lld\n", dp[m][n][i]);
    res = pl(res, dp[m][n][i]);
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 235392
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;

int main()
{
	int n; cin >> n;
	ll s = 0;
	unordered_map<int, int> cnt;
	vi a(n); rep(i, n) { cin >> a[i]; s += a[i]; cnt[a[i]]++; }
	int q; cin >> q;
	int b, c;
	rep(i, q)
	{
		cin >> b >> c;
		if(cnt.find(b) == cnt.end()) { cout << s << endl; continue; }
		s = s - cnt[b] * b + cnt[b] * c;
		cnt[c] += cnt[b];
		cnt.erase(b);
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 5960
#include<stdio.h>
int main()
{
	int n, k, ans = 0;
	int a, aa;
	scanf("%d%d", &n, &k);
	printf("%d", (n - 1) % (k - 1)? (n - 1) / (k - 1) + 1: (n - 1) / (k - 1));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#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!
        string s;
        cin >> s;

        if(s.size()==2){
            cout << s << endl;
        }else{
            cout << s[2] << s[1] << s[0] <<endl;
        }
}



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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lli long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()

#define forn(i, n)  for(int i=0;i<n;++i)
#define rforn(i,start) for(int i = start; i >= 0;--i)
#define forsn(i,start,end) for(int i=start;i<end;++i)
#define rforsn(i,start,end) for(int i=start;i>=end;--i)
#define debug(x) cout<<#x<<" = "<<x<<"\n";
const int CONST = 1e9 + 7;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
	//  freopen("input.txt", "r", stdin);
	//  freopen("output.txt","w",stdout);
	#endif

    string s;
    int k;
    cin>>k;
    cin>>s;
    int l=s.length();
    if(l<=k){
        cout<<s;
    }
    else{
        s = s.substr(0, k) + "...";
        cout<<s;
    }
	return 0;
}


Measured memory_bytes: 3656