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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

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

  int N, D;
  cin >> N >> D;
  long ans = 0;
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    if (hypot(X, Y) <= D) ans++; 
  }
  cout << ans << "\n";
}

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

int main() {
  long int N, Q = 1000000007, n10 = 1, n9 = 1, n8 = 1;
  cin >> N;
  for(int i = 0;i<N; i++){
    n10 = n10*10%Q;
    n9 = n9*9%Q;
    n8 = n8*8%Q;
  }
  cout << (2*Q + n10+n8-2*n9)%Q << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define MAX 100
#define WHITE 0
#define BLACK 1
#define INFTY 100000001

// グラフの頂点数
int n;
// 隣接行列
vector<vector<int> > M(MAX, vector<int>(MAX, -1));
// 頂点の状態を表す配列
vector<int> color(MAX, WHITE);
// d[v]は始点sからS内の点のみを通ってvに行く経路の最小コスト
vector<int> d(MAX, INFTY);

void dijkstra()
{
  // 初期化
  d.at(0) = 0;

  // 初期状態でSの頂点数は0
  while (1)
  {
    // uはV-Sの頂点でd[u]が最小となるもの
    int u;
    int m = INFTY;
    for (int i = 0; i < n; i++)
    {
      // dが未設定の頂点については条件式の右の条件ではじかれる
      if (color.at(i) == WHITE && d.at(i) < m)
      {
        m = d.at(i);
        u = i;
      }
    }

    if (m == INFTY)
    {
      // V=Sとなったとき
      break;
    }

    // uをSに追加する
    color.at(u) = BLACK;

    // uに隣接するV-Sの頂点のdを更新する
    for (int i = 0; i < n; i++)
    {
      if (M.at(u).at(i) != -1 && color.at(i) == WHITE)
      {
        // iはuと隣接しているV-Sの頂点
        d.at(i) = min(d.at(i), d.at(u) + M.at(u).at(i));
      }
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, m;
    cin >> u >> m;
    for (int j = 0; j < m; j++)
    {
      int v, c;
      cin >> v >> c;
      M.at(u).at(v) = c;
    }
  }

  dijkstra();

  for (int i = 0; i < n; i++)
  {
    cout << i << " " << d.at(i) << endl;
  }
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

bool isp(string s){
    int n = s.length();
    bool b=true;
    rep(i,n){
        if(s[i]!=s[n-i-1]) b=false;
    }
    return b;
}

void solve(){

    string s;
    cin >> s;
    //cout << isp("asdsdka") << endl;
    string ans = "Yes";

    if(!isp(s)) ans = "No";

    string tmp = s.substr(0,(s.length()-1)/2);

    if(!isp(tmp)) ans = "No";

    cout << ans << endl;

}

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


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 5001;
int arr[mxN];
int p[mxN];
int n;
bool flag[mxN];
int k;
ll ans = -INFLL;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>k;
    owo(i, 0, n) {
        cin>>p[i];
        p[i]--;
    }
    owo(i, 0, n) {
        cin>>arr[i];
    }
    owo(i, 0, n) {
        if(flag[i])continue;
        vector<int> vals;
        vals.senpai(arr[i]);
        flag[i] = true;
        int curr = p[i];
        while(curr!=i) {
            vals.senpai(arr[curr]);
            flag[curr] = true;
            curr = p[curr];
        }
        ll sum = 0;
        for(int k: vals) {
            sum+=k;
        }
        int num = k/vals.size();
        int over = k%vals.size();
        owo(j, 0, vals.size()) {
            ll val = 0;
            owo(b, j, j+vals.size()) {
                int idx = b%vals.size();
                val+=vals[idx];
                if(b-j+1>over) {
                    if(num) {
                        ans = max(val + max(sum, 0LL)*(num-1), ans);
                    }else break;
                }else {
                  ans = max(val + max(sum, 0LL)*num, ans);
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3736
# ????????¨??????????????§???????????¢?´¢????????? ????????? ????????? ?????????n???
# ?§£??¬??????????????£????????§??????????????????????????????

w, h, n = gets.split.map(&:to_i)
ps = []
n.times { ps << gets.split.map(&:to_i) }

ans = 0
ps.each_cons(2) do |(sx, sy), (dx, dy)|
  if (sx < dx && sy > dy) || (sx > dx && sy < dy)
    ans += (dx - sx).abs + (sy - dy).abs
  else
    ans += [(sx - dx).abs, (dy - sy).abs].max
  end
end

puts ans

Measured memory_bytes: 8764
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A<=5){
    cout<<0;
  }
  else if(A<=12){
    cout<<B/2;
  }
  else{
    cout<<B;
  }
}


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

int main() {

	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	for(int i=0; i<n; i++){
		cin >> x.at(i) >> y.at(i);
	}

	float ans=0.0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ans += sqrt(pow((x.at(i)-x.at(j)),2.0) + pow((y.at(i)-y.at(j)),2.0));
		}
	}

	printf("%.10f\n",ans/n);

	return 0;
}


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

const int MOD_CONST = 2019;

using namespace std;


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

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

	vector<int> rain(n);

	int diff = 0;
	for (int i = 0; i < n / 2; i++) {
		diff += a[2 * i];
		diff -= a[2 * i + 1];
	}

	rain[0] = a[n - 1] + diff;
	for (int i = 0; i < n -1; i++) {
		rain[i + 1] = 2 * a[i] - rain[i];
		
	}

	for (int i = 0; i < n; i++) {
		cout << rain[i] << " ";
	}


}

Measured memory_bytes: 2048
n = int(input())
A = list(map(int, input().split()))
b = [-1] * n
ans = []

for i in range(n - 1, -1, -1):
    cnt = 0
    for j in range(i, n, i + 1):
        if i == j:
            continue
        else:
            if b[j] == 1:
                cnt += 1
    if (A[i] + cnt) % 2 == 0:
        b[i] = 0
    else:
        b[i] = 1
        ans.append(i + 1)

m = len(ans)
print(m)
if m > 0:
    print(*ans)


Measured memory_bytes: 14096
while True:
    try: n = input().split()
    except: break
    
    m5, m10 = map(float, n)
    if m5 < 35.50 and m10 < 71.0:
        print('AAA')
    elif m5 < 37.50 and m10 < 77.0:
        print('AA')
    elif m5 < 40.0 and m10 < 83.0:
        print('A')
    elif m5 < 43.0 and m10 < 89.0:
        print('B')
    elif m5 < 50.0 and m10 < 105.0:
        print('C')
    elif m5 < 55.0 and m10 < 116.0:
        print('D')
    elif m5 < 70.0 and m10 < 148.0:
        print('E')
    else:
        print('NA')


Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue<long long>a;
    int n,d=0,r;
    long long b,p[2],area,temp,j;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>b;
        a.push(b);
    }

    for(int i=0;i<n;i++)
    {
    r=0;
    if(d==2)break;
    j=a.top();
    a.pop();

     if(a.top()==j)
     {
      if(d==2)break;
        temp=a.top();
        p[d]=a.top();
        d++;
         if(d==2)break;
        while(temp==a.top())
        {
        if(a.size()==0||a.size()==1)break;
            a.pop();
            r++;
            if(r==3)
            {
                p[d]=temp;
                d++;
            }
             if(d==2)break;
        }
         if(d==2)break;
     }
    }
    area=p[0]*p[1];
    if(d!=2)
    {
        cout<<0;
    }
    else
    {
        cout<<area;
    }
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
const int N=1000007;
int a[N],b[N];
int main()
{
    int n,m,t;cin>>n>>m;t=(m+1)/2;
    for(int i=1;i<=t;++i) a[i]=i,b[i]=t+t+1-i;
    for(int i=t+1;i<=m;++i) a[i]=t+i,b[i]=a[i]+2*(m-i+1);
    for(int i=1;i<=m;++i) printf("%d %d\n",a[i],b[i]);
}


Measured memory_bytes: 4220
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main(){
    speed;
    int a,b;
    cin >> a >> b;
    for ( long long int i = 0 ; i < 1000000000;i++){
        if (abs(a-i)==abs(b-i)){
            cout << i;
            exit(0);
        }
    }
    cout << "IMPOSSIBLE";
}





Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n = 0;
  scanf("%d", &n);
  
  int sum = 0;
  int max = 0;
  for( int i = 0; i < n; ++i ) { 
    int v = 0;
    scanf("%d", &v);
    max = max >= v ? max : v;
    sum += v;
  }
  if( max < (sum - max) ) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 3052
s = set()
e = set()
n, m = map(int, input().split())

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        s.add(b)
    elif b == n:
        e.add(a)
        
print('IM' * (1 - len(s & e)) + 'POSSIBLE')

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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> A(N-1,vector<int>(3));
  for(vector<int> &i:A)
    for(int &j:i)
      cin>>j;
  for(int i=0;i<N;i++){
    int t=0;
    for(int j=i;j<N-1;j++)
      t=(max(t,A[j][1])+A[j][2]-1)/A[j][2]*A[j][2]+A[j][0];
    cout<<t<<endl;
  }
}

Measured memory_bytes: 3588
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
int n;
vector<pair<int,int> > v[30];
int process(int s,int e,int x){
	int sid = lower_bound(v[x].begin(),v[x].end(),make_pair(s,0)) - v[x].begin();
	int eid = upper_bound(v[x].begin(),v[x].end(),make_pair(e,2)) - v[x].begin();
	if(sid < eid){
		int res = 0;
		int P = s;
		int not_payed = 0;
		for(int i=sid; i<eid; i++){
			int Z = v[x][i].first;
			int Q = v[x][i].second;
			if(Z > P){
				res += process(P, Z-1, x+1) + 1;
				not_payed = 0;
			}else
			if(not_payed == 1){
				not_payed = 0;
				res ++;
			}else
			if(Q == 1)
				not_payed = 1;
			P = Z+1;
		}
		if(P <= e){
			res += process(P, e, x+1) + 1;
		}else
		if(not_payed == 1)
			res ++;
		return res;
	}else
		return process(s, e, x+1) + 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		int x,t=0;
		scanf("%d",&x);
		while((1<<t) <= x)t++;
		--t;
		v[t].push_back(make_pair(i, (1<<t) == x ? 0 : 1));
	}
	printf("%d\n",process(1,n,0));
	return 0;
}

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

int main(void){
    int mod=pow(10,9)+7;
    int N,M;
    cin >> N >> M;
    long long ans=1;

    if(abs(N-M)>1) cout << 0 << endl;
    else if(N==M){
        for(int i=1; i<=N; i++){
            ans = (ans*i)%mod;
        }
        for(int j=1; j<=M; j++){
            ans = (ans*j)%mod;
        }
        cout << 2*ans%mod << endl;
    }
    else if(abs(N-M)<=1){
        for(int i=1; i<=N; i++){
            ans = (ans*i)%mod;
        }
        for(int j=1; j<=M; j++){
            ans = (ans*j)%mod;
        }
        cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = sc.nextInt() - 1;
			r[i] = sc.nextInt() - 1;
		}
		Set<Integer> set = new TreeSet<>();
		int[] sum = new int[n];
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 2).equals("AC")) {
				count++;
				set.add(i);
			}
			sum[i] = count;
		}
		sum[n - 1] = count;
		for (int i = 0; i < q; i++) {
			if (set.contains(r[i])) {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - 1 - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - 1 - sum[l[i]]);
				}
			} else {
				if (set.contains(l[i])) {
					System.out.println(sum[r[i]] - sum[l[i]] + 1);
				} else {
					System.out.println(sum[r[i]] - sum[l[i]]);
				}
			}
		}
	}
}

Measured memory_bytes: 95964
def roll_e(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[3], w[1], w[0], w[5], w[4], w[2]
    return d

def roll_s(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[4], w[0], w[2], w[3], w[5], w[1]
    return d

d1 = input().split()
d2 = input().split()
no_flag = 0

i = 0
while d1[1] != d2[1]:
    if i == 7:
        no_flag = 1
        break
    elif i == 4:
        d2 = roll_e(d2)
    d2 = roll_s(d2)
    i += 1

i = 0
while d1[0] != d2[0] or 4 > i or no_flag == 1:
    d2 = roll_e(d2)
    i += 1

if d1 == d2:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5572
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int L, R, d;
  cin >> L >> R >> d;
  cout << R / d - (L - 1) / d << endl;
  return 0;
}


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

using namespace std;

int main(){
  int a;
  int b;
  int c;
  int d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  int ans=0;

  for(int i=0;i<=100;i++){
    if(a<i && b>=i && c<i && d>=i){
      ans++;
      //cout << i << endl;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int64_t n;
    cin >> n;
    map<int64_t, int64_t> mns, pls;
    for(int64_t i = 0; i < n; i++){
        int64_t a;
        cin >> a;
        mns[i - a]++, pls[i + a]++;
    }
    int64_t ans = 0;
    for(auto& e : mns){
        int64_t k, v;
        tie(k, v) = e;
        ans += v * pls[k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 37916
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift()
S = inp.shift()
c = 0
for (i = 0; i < N - 2; i++) {
    if (S[i] == "A" && S[i+1] == "B" && S[i+2] == "C") {
        c++
    }
}
console.log(c)


Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
const int INF=-1000000000;
int main() {
  int n,k;cin >> n >> k;
  vector<int> v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  long long ans=-10000000000;
  int m=min(n,k);
  for(int a=0; a<m+1; a++){
    for(int b=0; b<m+1; b++){
      if(a+b>m) continue;
      long long now=0;
      vector<int> num;
      for(int i=0; i<a; i++){
        now+=v[i];
        if(v[i]<0) num.push_back(v[i]);
      }
      for(int i=n-1; i>n-b-1; i--){
        now+=v[i];
        if(v[i]<0) num.push_back(v[i]);
      }
      if(k-a-b>0){
        sort(num.begin(),num.end());
        for(int i=0; i<min(k-a-b,(int)num.size()); i++){
          now-=num[i];
        }
      }
      ans=max(ans,now);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	if(n/100<=12 && n%100<=12 && n/100!=0 && n%100!=0) {cout << "AMBIGUOUS\n";}
	else if(n/100<=12 && n/100!=0) {cout << "MMYY\n";}
	else if(n%100<=12 && n%100!=0) {cout << "YYMM\n";}
	else cout << "NA\n";
	return 0;
}

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

typedef long long ll;
using namespace std;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        parent = vector<int>(N, -1);
    }

    int root(int n) {
        if (parent[n] < 0) return n;
        return parent[n] = root(parent[n]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (sizeOf(rx) < sizeOf(ry)) swap(rx, ry);
        parent[rx] += parent[ry];
        parent[ry] = rx;
    }

    int sizeOf(int n) {
        return -parent[root(n)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int a[m], b[m];
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    ll out[m];
    out[m-1] = (ll)n*(n-1)/2;
    UnionFind tree(n);
    for (int i = m-2; i >= 0; i--) {
        out[i] = out[i+1];
        if (tree.root(a[i+1]) != tree.root(b[i+1])) {
            out[i] -= tree.sizeOf(a[i+1]) * tree.sizeOf(b[i+1]);
            tree.unite(a[i+1], b[i+1]);
        }
    }
    for (auto& o : out) cout << o << endl;
    return 0;
}


Measured memory_bytes: 3320
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n , m ; 
    cin >> n >> m ; 
    vector<vector<ll> > graph(n+1) ; 
    for(ll i=0;i<n-1;i++){
    	ll x , y ; 
    	cin >> x >> y ; 
    	graph[x].push_back(y) ; 
    	graph[y].push_back(x) ; 
    }
    vector<ll> val(n+1) ; 
    for(ll i=0;i<m;i++){
    	ll x , c ; 
    	cin >> x >> c ; 
    	val[x] += c ; 
    }
    vector<ll> dist(n+1) ; 
    vector<bool> vis(n+1) ; 
    dist[1] = val[1] ;
    queue<ll> q ;
    q.push(1) ;
    vis[1] = true ;
    while(not q.empty()){
    	ll f = q.front() ; q.pop() ;
    	for(ll &p : graph[f]){
    		if ( vis[p] ) continue ;
    		dist[p] = val[p] + dist[f] ; 
    		vis[p] = true ; 
    		q.push(p) ; 
    	}
    }
    for(ll i=1;i<=n;i++){
    	cout << dist[i] << ' ' ;
    }
    cout << endl;
    return 0 ;
}


Measured memory_bytes: 19568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

void solve(long long N, std::vector<long long> X){
    ll ans = INF;
    for(ll i = 0; i < 100; ++i){
        ll s = 0;
        for(ll j = 0; j < N; ++j){
            s += (i+1-X[j]) * (i+1-X[j]);
        }
        ans = min(ans, s);
    }
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 3700
#include<stdio.h>
#include<string.h>
int main(){
    char sea[400]={0};
    char *ans;
    int N,cnt=0;
    scanf("%s",&sea);
    scanf("%d",&N);
        while(N--){
        char data[400]={0},word[400]={0};
        scanf("%s",word);
        strcpy(data,word);
        strcat(word,data);
        ans = strstr(word,sea);
        if(ans!=NULL)cnt++;
        else ;
        }
        printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1052
#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 a, b, c;
    cin >> a >> b >> c;

    if (a == b && a != c)
    {
        cout << "Yes" << endl;
    }
    else if (b == c && b != a)
    {
        cout << "Yes" << endl;
    }
    else if (c == a && c != b)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, X, ans = 0;

    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if (500 * i + 100 * j + 50 * k == X)
                {
                    ans++;
                }
            }
        }
    }

    cout << ans;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N), dp(N, INF);

    rep(i, N)
    {
        cin >> h[i];
    }

    dp[0] = 0;
    rep(i, N - 1)
    {
        for (int j = 1; j <= K; j++)
        {
            if (i + j < N)
            {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
            }
        }
    }
    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <utility>
#include <vector>
#include <stack>
#include <string.h>

int main(void) {
  int i, j, k, n;
  long long ans = 0, now = 0, nm = -1;
  std::vector<long long> v;
  char s[60000], c = 92;
  scanf("%s", s);
  n = strlen(s);
  int d[n + 1], max;
  d[0] = 0;
  for(i = 0; i < n; ++i) {
    d[i + 1] = d[i];
    if(s[i] == c) d[i + 1]--;
    else if(s[i] == '/') d[i + 1]++;
  }
  std::pair<int, int> p[n + 1];
  p[n].first = d[n], p[n].second = n;
  for(i = n - 1; i >= 0; --i) {
    p[i] = p[i + 1];
    if(p[i].first < d[i]) p[i].first = d[i], p[i].second = i;
  }
  for(i = 0; p[i].second != i; ++i) {
    //printf("%lld %lld %lld\n", i, nm, now);
    if(nm > d[i]) {
      now += 2 * nm - d[i] - d[i + 1];
    } else if(nm < d[i] && d[i + 1] < d[i]) {
      nm = d[i];
      now += 2 * nm - d[i] - d[i + 1];
    } else if(nm == d[i] && d[i + 1] < d[i]) {
      if(now) {
        v.push_back((long long)now / 2);
        ans += now / 2;
        now = 0;
      }
      now += 2 * nm - d[i] - d[i + 1];
    } else {
      if(now) {
        v.push_back((long long)now / 2);
        ans += now / 2;
        now = 0;
      }
      nm = d[i];
    }
  }
  //printf("%lld\n", now);
  if(now) v.push_back(now / 2), ans += now / 2, now = 0;
  std::stack<long long> st;
  nm = d[n] - 1;
  j = i;
  for(i = n; i > j; --i) {
    //printf("%d %d %lld\n", i, nm, now);
    if(nm > d[i]) {
      now += 2 * nm - d[i] - d[i - 1];
    } else if(nm < d[i] && d[i - 1] < d[i]) {
      nm = d[i];
      now += 2 * nm - d[i] - d[i - 1];
    } else if(nm == d[i] && d[i - 1] < d[i]) {
      if(now) {
        st.push((long long)now / 2);
        ans += now / 2;
        now = 0;
      }
      now += 2 * nm - d[i] - d[i - 1];
    } else {
      if(now) {
        st.push((long long)now / 2);
        ans += now / 2;
        now = 0;
      }
      nm = d[i];
    }
  }
  if(now) st.push(now / 2), ans += now / 2, now = 0;
  while(!st.empty()) {
    long long tmp = st.top();
    st.pop();
    v.push_back(tmp);
  }
  printf("%lld\n%d", ans, (v.end() - v.begin()));
  std::vector<long long>::iterator it;
  for(it = v.begin(); it != v.end(); ++it) printf(" %lld", *it);
  printf("\n");
  return 0;
}


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

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

  int aIndex = 0;
  int zIndex = 0;

  for(int i = 0;i < str.length(); ++i) {
    if (str.at(i) == 'A') {
      aIndex = i;
      break;
    }
  }
  for(int i = str.length();i > 0; --i) {
    if (str.at(i - 1) == 'Z') {
      zIndex = i;
      break;
    }
  }

  cout << zIndex - aIndex;
}


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

int main(){
  int n;
  cin >> n;
  double sum=0;
  int div=1;
  vector<double>num(n),x(n),y(n);
  for(int i=0; i<n; i++){
    div*=(i+1);
    num[i]=i;
    cin >> x[i] >> y[i];
  }
  for(int i=0; i<div; i++){
    for(int i=0; i<n-1; i++){
      sum+=sqrt(pow(x[num[i]]-x[num[i+1]],2)+pow(y[num[i]]-y[num[i+1]],2));
    }
    next_permutation(num.begin(),num.end());
  }
  cout << fixed << setprecision(7) << sum/div << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        if(a > b){
            System.out.println("a > b");
        } else if(a == b) {
            System.out.println("a == b");
        } else {
            System.out.println("a < b");
        }
        
    }
}


Measured memory_bytes: 26192
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
int n;
long long ans,ma;
long long a[300005];
long long s[300005];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    }
    s[0]=a[0];
    for(int i=1;i<n;i++){
    s[i]=s[i-1]+a[i];
    }
    ans=-1;
    for(int i=1;i<n;i++){
    long long x=s[i-1];
    long long y=s[n-1]-s[i-1];
    //cout<<x<<" "<<y<<endl;
    long long t=x-y;
    if(t<0)t=-t;
    if(ans==-1) ans=t;else
    ans=min(ans,t);
    }
    cout<<ans;//<<endl;
    //system("pause");
    return 0;
}


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

int main(void){
    string N;
    int ans;
    
    cin >> N;
    
    if(N == "SUN"){
        ans = 7;
    }
    if(N == "MON"){
        ans = 6;
    }
    if(N == "TUE"){
        ans = 5;
    }
    if(N == "WED"){
        ans = 4;
    }
    if(N == "THU"){
        ans = 3;
    }
    if(N == "FRI"){
        ans = 2;
    }
    if(N == "SAT"){
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,C,K;
int ar[100005];
int main(){
  cin>>n>>C>>K;
  REP(i,n) cin>>ar[i];
  sort(ar,ar+n);

  int res=0;
  for(int i=0;i<n;){
    int j=i;
    while(j-i+1<=C && ar[j]-ar[i]<=K && j<n) ++j;
    i=j;
    ++res;
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    reverse(all(s));

    int n=s.size();
    vector<ll> cnt(2019,0);

    cnt[0]++;
    ll x=1;
    ll tmp=0;
    rep(i,n){
        tmp=(tmp+((s[i]-'0')*x)%2019)%2019;
        cnt[tmp]++;
        //cout<<tmp<<endl;
        x=(x*10)%2019;
    }

    ll ans=0;
    rep(i,2019){
        ans+=cnt[i]*(cnt[i]-1)/2;
    }

    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int k;
  cin >> k;

  unordered_set<int> s = unordered_set<int>();

  int m = 7 % k;
  int cnt = 1;

  while (m) {
    m = (10 * m + 7) % k;
    if (s.find(m) != s.end()) {
      cout << "-1\n";
      return;
    }
    s.insert(m);
    ++cnt;
  }

  cout << cnt << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 42640
#include <iostream>

int main(int argc, char const *argv[])
{
	int num;
	int index = 0;

	while (1) {
		std::cin >> num;
		if (num == 0) {
			break;
		}
		index++;
		std::cout << "Case " << index << ": " << num << std::endl;
	}

	return 0;
}

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

using namespace std;

using ll = long long;

inline double Tmp (double t, double x) { return t - x * 0.006; }

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

    int n, t, a;
    cin >> n >> t >> a;

    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];

    int ans = 0;
    for (int i = 1; i < n; ++i)
        if (abs(Tmp(t, h[i]) - a) < abs(Tmp(t, h[ans]) - a)) ans = i;

    cout << ans + 1 << endl;

    return 0;
}


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

using namespace std;

#define int long long
#define forn(i,n) for(int i = 0; i <(int)n; ++i)
const int MOD = 1000000007; // opsi : 998244353, 1000000007,

int32_t main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int arr[n];
    int total = 0;
    forn(i,n){
        cin >> arr[i];
        total^=arr[i];
    }
    forn(i,n){
        int temp = total^arr[i];
        cout << temp << (i == n-1 ? '\n' : ' ');
    }

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

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


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int N; int arr[101];

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N; for(int i = 1; i <= N; i++) { cin >> arr[i]; arr[i] += arr[i-1]; }
    int diff = INT_MAX;
    
    for(int t = 1; t < N; t++)
    {
        int s1 = arr[t]; int s2 = arr[N] - arr[t];
        diff = min(diff, abs(s1 - s2));
    }
    
    cout << diff << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val a= readLine()!!.toInt()
    val b= readLine()!!.toInt()
    val c= readLine()!!.toInt()
    val x= readLine()!!.toInt()

    var count=0
    for(ai in 0..a)for(bi in 0..b)for(ci in 0..c){
        if(500*ai+100*bi+50*ci==x) count++
    }
    println(count)
}

Measured memory_bytes: 31688
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stdio.h>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;



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


	pair<int, int>a[100002];
	rep(i, n) {
		cin >> temp;
		a[i] = make_pair(temp, i);
	}
	sort(a, a + n);


	rep(i, n) {
		if (i == n - 1) { cout << a[i].second + 1 << ' '; }
		else { cout << a[i].second + 1 << endl; }
	}

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    ll acc = 0;
    ll counter = 1;
    while(acc < N)
    {
        acc += counter;
        counter++;
    }
    
    for(ll i = 1; i < counter; i++)
    {
        if(i == acc - N) continue;
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N, x;
  cin >> N >> x;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  int p = 0;
  for (int i = 0; i < N; i++) {
    if (x >= a[i]) {
      x -= a[i];
      p++;
    } else {
      x = 0;
    }
  }
  if (p > 0 && x > 0) {
    p--;
  }
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t,n,k=0,ans=0;
  int s[11],f[11];
  int sa[105];
  t=1;
  cin>>t;
  while(t!=0){
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>s[i]>>f[i];
      if(f[i]<s[i]){
	ans+=(24-s[i]+f[i]);
      }else{
	ans+=(f[i]-s[i]);
      }
    }
    if(ans<t){
      sa[k]=t-ans;
    }else{
      sa[k]=0;
    }
    k++;
    cin>>t;
    ans=0;
  }
  for(int i=0;i<k;i++){
    if(sa[i]==0){
      cout<<"OK"<<"\n";
    }else{
      cout<<sa[i]<<"\n";
    }
  }
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int bk_r = 0,wh_r = 0;
  rep(i,N) {
    if(S[i] == '#') {
      bk_r++;
    } else {
      wh_r++;
    }
  }
  int bk_l = 0,wh_l = 0;
  int ans =bk_l + wh_r;
  rep(i,N) {
    if(S[i] == '#') {
      bk_r--;
      bk_l++;
    } else {
      wh_l++;
      wh_r--;
    }
    ans = min(ans,bk_l + wh_r);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int N;
	string s;

	cin >> N;

	if (N == 0) cout << 0 << endl;

	while (N != 0) {
		if (N == 1) {
			s.insert(s.begin(), '1');
			break;
		}
		if (N == -1) {
			s.insert(s.begin(), '1');
			s.insert(s.begin(), '1');
			break;
		}
		if (N % -2 == 0) {
			s.insert(s.begin(), '0');
			N /= -2;
		}
		else {
			s.insert(s.begin(), '1');
			N /= -2;
			if (N > 0) {	
				N++;
			}
		}
	}
	cout << s << endl;
	return 0;
}

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

string s[410];
int Y, X;

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

void calc(int y, int x, ll &black, ll &white, char pre) {
    if (y < 0 || x < 0 || x>=X || y>=Y) return;
    if (s[y][x] == '!' || s[y][x] == pre) return;
    if (s[y][x] == '#') black++;
    if (s[y][x] == '.') white++;
    char cur = s[y][x];
    s[y][x] = '!';
    rep(i,4){
        calc(y+dy[i], x+dx[i], black, white, cur);
    }
}

int main(void){
    cin >> Y >> X;
    rep(y,Y) cin >> s[y];

    ll res = 0;
    rep(y,Y) rep(x,X){
        ll black = 0;
        ll white = 0;
        calc(y, x, black, white, '!');
        res += black * white;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 12928
N,M,Q = map(int,input().split())
LR = [ list(map(int,input().split())) for i in range(M)]
pq = [ list(map(int,input().split())) for i in range(Q)]

lr = [ [0]*(N+1) for i in range(N+1)]
for i in range(M):
    l,r = LR[i][0],LR[i][1]
    lr[l][r] += 1

for i in range(N):
    for j in range(N):
        lr[i][j+1] += lr[i][j]

for i in range(Q):
    ans = 0
    p,q = pq[i][0],pq[i][1]
    for i in range(p,q+1):
        ans += (lr[i][q] - lr[i][p-1])
    print(ans)



Measured memory_bytes: 113880
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int n,a,b,train,taxi;
	cin >> n >> a >> b;
	train = n*a;
	taxi = b;
	cout << (min(train, taxi));
	return 0;
}

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


int main(){
	string S;
	cin >>S;
	if(S=="Sunny"){
		cout <<"Cloudy";
	}else if(S=="Cloudy"){
		cout <<"Rainy";
	}
	else if(S=="Rainy"){
		cout <<"Sunny";
	}
	cout <<endl;
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    if (S.size() == 2) cout << S << endl;
    else cout << S[2] << S[1] << S[0] << endl;
}



Measured memory_bytes: 3628
s=[]
p=[]
a=i=0
for c in input():
    if"\\"==c:
        s+=[i]
    elif"/"==c and s:
        j=s.pop()
        t=i-j
        a+=t
        while p and p[-1][0]>j:
            t+=p[-1][1];p.pop()
        p+=[(j,t)]
    i+=1
print(a)
if p:
    print(len(p),*list(zip(*p))[1])
else:
    print(0)


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

int main() {
  int X, A, B;
  cin >> X >> A >> B;

  if (A - B >= 0) {
    cout << "delicious" << endl;
  }else if (B - A <= X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <utility>
#include <vector>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;

int N;
int a[55];
vector<P> ope;


int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	
	int mini = inf, maxi = -inf;
	int min_i, max_i;
	
	for(int i = 1; i <= N; i++){
		if(mini > a[i]){
			min_i = i;
			mini = a[i];
		}
		if(maxi < a[i]){
			max_i = i;
			maxi = a[i];
		}
	}
	
	if(mini >= 0){
		cout << N-1 << endl;
		for(int i = 1; i < N; i++){
			cout << i << " " << i+1 << endl;
		}
		return 0;
	}
	
	if(maxi < 0){
		cout << N-1 << endl;
		for(int i = N; i > 1; i--){
			cout << i << " " << i-1 << endl;
		}
		return 0;
	}
	
	if(-mini <= maxi){
		cout << 2*N-1 << endl;
		for(int i = 1; i <= N; i++){
			if(i == max_i ) continue;
			cout << max_i << " " << i << endl;
		}
		cout << max_i << " " << max_i << endl;
		for(int i = 1; i < N; i++){
			cout << i << " " << i+1 << endl;
		}
		return 0;
	}
	
	if(-mini > maxi){
		cout << 2*N-1 << endl;
		for(int i = 1; i <= N; i++){
			if(i == min_i ) continue;
			cout << min_i << " " << i << endl;
		}
		cout << min_i << " " << min_i << endl;
		for(int i = N; i > 1; i--){
			cout << i << " " << i-1 << endl;
		}
		return 0;
	}
	
	return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

string s;
int longest()
{
	int fstA = -1, lstZ = -1;
	for(int i = 0; i < sz(s); ++i) {
		if(fstA == -1 && s[i] == 'A')
			fstA = i;
		if(s[i] == 'Z')
			lstZ = i;
	}
	return lstZ - fstA + 1;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> s;

	cout << longest() << endl;

	return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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



int main() {
	llong N;
    cin >>N;
    int be = N/100;
    int af = N % 100;

    if(be<13 && af < 13 && be!=0 && af != 0){
        cout << "AMBIGUOUS" << endl;
    }else if(be < 13 && be != 0 && (af > 12 || af==0)){
        cout << "MMYY" << endl;
    }else if( (be == 0 ||  be > 12 ) && af < 13 && af != 0){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }







}


Measured memory_bytes: 256