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

int main(){
	int h, w;
	cin >> h >> w;
	string s[h];
	int count[50][50] = {{0}};
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for(int i=0; i < h; i++) {
		for(int j=0; j < w; j++) {
			if(s[i].at(j) != '#')
				continue;
			count[i][j] = -10;
			for(int k=-1; k <= 1; k++) {
				for(int l=-1; l <= 1; l++) {
					if(i+k < 0 || i+k >= h || j+l < 0 || j+l >= w)
						continue;
					count[i+k][j+l]++;
				}
			}
		}
	}

	for(int i=0; i < h; i++) {
		for(int j=0; j < w; j++) {
			if(count[i][j] < 0)
				cout << '#';
			else
				cout << count[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
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 rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


const long long MAX = 2010;
const long long MOD = 1000000007;
long long COM[MAX][MAX];

void COMinit(){
  for (int i=0;i<MAX;i++){
    COM[i][0] = 1;
    for (int j=1;j<=i;j++){
      COM[i][j] = (COM[i-1][j] + COM[i-1][j-1])%MOD;
    }
  }
}

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

  reps(i,K){
    ll ans = COM[N-K+1][i]*COM[K-1][i-1];
    ans %= MOD;
    cout << ans << endl;
  }


  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 26380
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <climits>
#define INF INT_MAX>>1
 
using namespace std;
 
int main(void){
    while(1){
        int n, m; cin >> n >> m;
        if(!n && !m) break;
        int s, g; cin >> s >> g;
        s--; g--;
        pair<int, int> adjacent[35][35];//(距離, 制限速度)
        fill(adjacent[0], adjacent[35], make_pair(-1, -1));
        for(int i=0; i<m; i++){
            int x, y, d, c; cin >> x >> y >> d >> c;
            x--; y--;
            adjacent[x][y] = adjacent[y][x] = make_pair(d, c);
        }
 
        double dp[35][35][35];//dp[Node][speed][prev] = cost;
        fill(dp[0][0], dp[35][0], INF);
        dp[s][0][s] = 0.0;
        priority_queue<tuple<int, double, int, int>, vector<tuple<int, double, int, int> >, greater<tuple<int, double, int, int> > > que;//(Node, cost, speed, prev)
        //priority_queue<tuple<int, double, int, int> > que;//LTE(メモリ制限？)
        que.push(make_tuple(s, 0, 0, s));
        while(!que.empty()){
            tuple<int, double, int, int> t = que.top();
            que.pop();
            int pos = get<0>(t);
            double cost = get<1>(t);
            int speed = get<2>(t);
            int prev = get<3>(t);
            if(cost != dp[pos][speed][prev]) continue;
 
            for(int i=0; i<n; i++){
                if(adjacent[pos][i].first != -1 && i != prev){
                    int dist  = adjacent[pos][i].first;
                    int limit = adjacent[pos][i].second;
                    for(int ac=-1; ac<=1; ac++){
                        int n_speed = speed + ac;
                        if(n_speed <= 0 || limit < n_speed) continue;
                        double n_cost = cost + double(dist)/n_speed;
                        if(dp[i][n_speed][pos] > n_cost){
                            dp[i][n_speed][pos] = n_cost;
                            que.push(make_tuple(i, n_cost, n_speed, pos));
                        }
                    }
                }
            }
        }
 
        double ans = INF;
        for(int i=0; i<n; i++){
            ans = min((double)ans, dp[g][1][i]);
        }
        if(ans == INF) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 9588
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#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>;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
struct sieve {
  int n;
  vector<int> f, primes;
  sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> ans;
    while (x != 1) {
      ans.push_back(f[x]);
      x /= f[x];
    }
    return ans;
  }
  vector<P> factorMap(int x) {
    vector<int> factor = factorList(x);
    if (factor.empty()) return {};

    vector<P> ans(1, P(factor[0], 0));
    for (int p : factor) {
      if (ans.back().first == p) {
        ans.back().second++;
      } else {
        ans.emplace_back(p, 1);
      }
    }
    return ans;
  }
};

sieve sieve(1000005);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int,int> p;
  rep(i,n) {
    cin >> a[i];
    vector<P> fl = sieve.factorMap(a[i]);
    for(P f : fl){
      p[f.first] = max(p[f.first],f.second);
    }
  }
  mint x(1);
  for (auto e : p) {
    x *= mint(e.first).pow(e.second);
  }

  mint ans;
  rep(i,n) ans += x/a[i];
  cout << ans.x << endl;
}


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


int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int x_dif = tx - sx;
  int y_dif = ty - sy;
  
  for (int i=0; i<y_dif; ++i) {
    cout << "U";
  }
  for (int i=0; i<x_dif; ++i) {
    cout << "R";
  }
  for (int i=0; i<y_dif; ++i) {
    cout << "D";
  }
  for (int i=0; i<x_dif; ++i) {
    cout << "L";
  }
  cout << "L";
  ++x_dif;
  ++y_dif;
  for (int i=0; i<y_dif; ++i) {
    cout << "U";
  }
  for (int i=0; i<x_dif; ++i) {
    cout << "R";
  }
  cout << "DR";
  for (int i=0; i<y_dif; ++i) {
    cout << "D";
  }
  for (int i=0; i<x_dif; ++i) {
    cout << "L";
  }
  cout << "U";
}

Measured memory_bytes: 256
str = gets.chomp

l = str.length
sum = 0

if l == 1
  sum = str.to_i
else
  ["", "+"].repeated_permutation(l - 1) do |plus|
    plus << ""
    tmp = (str.chars).zip(plus).flatten.join
    sum += eval(tmp)
  end
end

puts sum

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

const int mod = 998244353;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    vector<vector<int>> a(n);
    a[0].pb(0);
    rep(i, n){
        if (i == 0 && d[i] != 0){
            cout << 0 << endl;
            return 0;
        }
        if (i && d[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        if (i) a[d[i]].pb(i);
    }
    int p;
    rep(i, n){
        if (a[i].size()) p = i;
    }
    ll ans = 1;
    for(int i = 1; i <= p; i++){
        if (a[i].size() == 0){
            cout << 0 << endl;
            return 0;
        }
        ll q = 1;
        rep(j, a[i].size()) q = (q * a[i - 1].size()) % mod;
        ans = (ans * q) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8968
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

XL = sorted(XL, key=lambda x: x[0]+x[1])

ans = 1
right = XL[0][0] + XL[0][1]

for i in range(1, N):
    if right <= XL[i][0] - XL[i][1]:
        right = XL[i][0] + XL[i][1]
        ans += 1

print(ans)

Measured memory_bytes: 33064
#include <iostream>
#include <vector>
#include <array>
#include <limits>
#include <cassert>
using namespace std;
const int MAX_N = 2e4;
const int INF = numeric_limits<int>::max();
int cost[] = {10000, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// dp[i] = i本使った時に作れる桁数の最大値
array<int, MAX_N> dp;

void solve(const vector<int> &as, int n)
{
    fill(dp.begin(), dp.end(), -INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < as.size(); ++j)
        {
            int a = as[j];
            dp[i + cost[a]] = max(dp[i] + 1, dp[i + cost[a]]);
        }
    }
    // dp[n] = dp[n - a] + 1 が成り立つ最大の a を探す
    for (int k = n; k > 0;)
    {
        int max_a = -1;
        for (int i = 0; i < as.size(); ++i)
        {
            int a = as[i];
            if (k - cost[a] < 0) continue;
            if (dp[k] == dp[k - cost[a]] + 1)
            {
                max_a = max(max_a, a);
            }
        }
        assert(max_a > 0);
        cout << (char)(max_a + '0');
        k = k - cost[max_a];
    }
    cout << endl;
}
int main()
{
    int n;
    int m;
    vector<int> as;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        as.push_back(a);
    }
    solve(as, n);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"


  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
	int a,b;
	cin >> a >> b;
	int x[a],sum=0;
	for(int i = 0; i<a; i++){
		cin >> x[i];
	}
	sort(x, x+a);
	
	for(int i = 0; i<b; i++){
		sum += x[i];
	}
	
	cout << sum;
	
	
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    N *= 4;
    long long ans = 0;
    vector<pair<pair<double, long long>, int>> v(4);
    v[0] = make_pair(make_pair(Q/0.25, Q), 1);
    v[1] = make_pair(make_pair(H/0.5, H), 2);
    v[2] = make_pair(make_pair(S/1.0, S), 4);
    v[3] = make_pair(make_pair(D/2.0, D), 8);
    sort(v.begin(), v.end());
    while(N > 0){
        for(int i=0; i<3; i++){
            if(v[i].second > N) continue;
            long long tmp = N / v[i].second;
            ans += v[i].first.second * tmp;
            N -= tmp * v[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{  
	fast;
	ll n,m;
	cin>>n>>m; ll sum = 0;
	ll arr[m]; for(ll i = 0; i < m; i++) 
	{
		cin>>arr[i];
		sum += arr[i];
	}
	if(sum > n)
	{
		cout << -1 << endl;
	}	
	else
	{
		cout << n - sum << endl;
	}
}

Measured memory_bytes: 3692
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int max = (n-1)*(n-2)/2;
        if((n-1)*(n-2)/2 < k) System.out.println(-1);
        else{
            int m = (n-1) + (max - k);
            StringBuilder sb = new StringBuilder();
            int t = 0;
            for (int i = 2; i <= n; i++) {
                sb.append("1 " + i + "\n");
                t++;
            }
            for (int i = 2; i < n; i++) {
                if(m <= t) break;
                for (int j = i+1; j <= n; j++) {
                    sb.append(i + " " + j + "\n");
                    t++;
                    if(m <= t) break;
                }
            }
            System.out.println(m);
            System.out.print(sb.toString());
        }
        sc.close();

    }

}


Measured memory_bytes: 23252
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] x=new int[100001];
		HashMap<Integer,Integer> map=new HashMap<>();
		for(int i=0; i<n; i++){
			int tmp=sc.nextInt();
			int mt=tmp%m;
			x[tmp]++;
			if(map.containsKey(mt)){
				map.put(mt,map.get(mt)+1);
			}else{
				map.put(mt,1);
			}
		}
		long ans=0;
		if(map.containsKey(0)){
			ans=map.get(0)/2;
		}
		for(int i=1; i<=(m-1)/2; i++){
			long sum=0;
			if(map.containsKey(i) && map.containsKey(m-i)){
			long ii=map.get(i);
			long mi=map.get(m-i);
			if(ii>mi){
				ans+=mi;
				for(int j=i; j<100001; j+=m){
					sum+=x[j]/2;
				}
				ans+=Math.min((ii-mi)/2,sum);
			}else{
				ans+=ii;
				for(int j=m-i; j<100001; j+=m){
					sum+=x[j]/2;
				}
				ans+=Math.min((mi-ii)/2,sum);
			}
			}else{
				if(map.containsKey(i)){
					for(int j=i; j<100001; j+=m){
					sum+=x[j]/2;
				}
					ans+=sum;
				}else if(map.containsKey(m-i)){
					for(int j=m-i; j<100001; j+=m){
					sum+=x[j]/2;
				}
					ans+=sum;
				}
			}
			
		}
		if(m%2==0 && map.containsKey(m/2)){
			ans+=map.get(m/2)/2;
		}
		System.out.println(ans);
	}
}


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

  /* code */


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];
  int max=INT_MIN;
  int max2=INT_MIN;
  map<int,int> mp;
  for(int i=0;i<n;i++)
  {
    ++mp[a[i]];
    if(a[i]>=max)
    {max=a[i];}

  }
  for(int i=0;i<n;i++)
  {
    if(a[i]>max2 && a[i]<max)
    max2=a[i];
  }
  //cout<<max<<'\n';
  for(int i=0;i<n;i++)
  {
    if(a[i]==max && mp[a[i]]==1)
    cout<<max2<<'\n';
    else
    cout<<max<<'\n';
  }
  return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(void)
{
    ll n , mx = -200 , i ,j,k , counter  = 0 ;
    string str;
    cin >> n >> str;

    for(i = 0 ; i <n ; i++)
    {
        if(str[i]=='I')
        {
            counter++;
            if(counter>mx)
            {
                mx = counter;
            }
        }
        else{
            counter--;
        }
    }
    if(mx<0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << mx <<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5+1e5;
int red[maxn],col[maxn],blu[maxn];
priority_queue<int,vector<int>,greater<int>> l,r;
int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=1;i<=a;i++)
        cin>>red[i];
    for(int i=1;i<=b;i++)
        cin>>blu[i];
    for(int i=1;i<=c;i++)
        cin>>col[i];
    for(int i=1;i<=a;i++){
        if(l.size()<x){
            l.push(red[i]);
        }else{
            l.push(red[i]);
            l.pop();
        }
    }  
    for(int i=1;i<=b;i++){
        if(r.size()<y){
            r.push(blu[i]);
        }else{
            r.push(blu[i]);
            r.pop();
        }
    }  
    sort(col+1,col+c+1);
    for(int i=1;i<=c;i++){
        int lmi=l.top();
        int rmi=r.top();
        if(col[i]<=min(lmi,rmi))
            continue;
        if(lmi<=rmi){
            l.push(col[i]);
            l.pop();
        }else{
            r.push(col[i]);
            r.pop();
        }
    }
    ll ans=0;
    while(l.size()){
        ans+=1ll*l.top();
        l.pop();
    }
    while(r.size()){
        ans+=1ll*r.top();
        r.pop();
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 2552
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

H,W = map(int,input().split())
A = [input() for _ in range (H)]

MOD = 10**9+7
dp = [[0] * (W+1) for _ in range(H+1)]
dp[0][0] = 1
dp[1][1] = 1
for i in range(H):
    for j in range(W):
        if i==j and i==0:continue
        if A[i][j]=='.':
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            dp[i+1][j+1] %= MOD

print(dp[H][W])

Measured memory_bytes: 51440
#include<iostream>
// Need start
#include<vector>
// Need end
using namespace std;

// Copy start
template <class T>
class Bellmanford {
    private:
        struct edge {
            int from, to;
            T cost;
        };
        T identity_;
        vector<edge> edges_;
        vector<T> dist_;
        vector<bool> in_negative_;
        bool negative_loop_;
    public:
        Bellmanford(int node_num, int edge_num, T identity):
        identity_(identity), dist_(vector<T>(node_num, identity)), in_negative_(vector<bool>(node_num, false)) {}
        void addEdge(int from, int to, T cost) {
            edge e = {from, to, cost};
            edges_.push_back(e);
        }
        void _calcShortestPath(int start_node) {
            dist_[start_node] = 0;
            int n = (int)dist_.size();
            int m = (int)edges_.size();
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    edge now_edge = edges_[j];
                    if (dist_[now_edge.from] != identity_ && dist_[now_edge.to] > dist_[now_edge.from] + now_edge.cost) {
                        dist_[now_edge.to] = dist_[now_edge.from] + now_edge.cost;
                        if (i == n - 1) {
                            negative_loop_ = true;
                            in_negative_[now_edge.to] = true;
                        }
                    }
                    if (in_negative_[now_edge.from]) {
                        in_negative_[now_edge.to] = true;
                    }
                }
            }
        }
        void calcShortestPath(int start_node) {
            _calcShortestPath(start_node);
            _calcShortestPath(start_node);
        }
        bool hasNegLoop() {
            return negative_loop_;
        }
        bool inNegLoop(int node) {
            return in_negative_[node];
        }
        T getDist(int node) {
            return dist_[node];
        }
};
// Copy end

using ll = long long;

const int INF = 1 << 30;

int main() {
    // This sample is Atcoder Beginners Contest 137 E
    int N, M, P;
    cin >> N >> M >> P;
    Bellmanford<int> bellmanford(N, M, INF);
    int A, B, C;
    for (int i = 0; i < M; ++i) {
        cin >> A >> B >> C;
        --A, --B;
        bellmanford.addEdge(A, B, P - C);
    }
    bellmanford.calcShortestPath(0);
    if (bellmanford.inNegLoop(N - 1)) {
        cout << -1 << endl;
    }
    else {
        cout << max(-bellmanford.getDist(N - 1), 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;

    vector<int> H(N);
    cin >> H;
    double mini = 1E30;
    int ans;

    REP(i, N)
    {
        double err = abs(T - 0.006 * H[i] - A);
        if (err < mini)
        {
            mini = err;
            ans = i + 1;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int n;
  int l,r;
  int x = 0;
  
  cin >> n;

  int i=0;
  while (i<n){
    cin >> l >> r;
    x += r-l+1;
    i++;
  }
  cout << x << endl;

}



Measured memory_bytes: 256
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True



def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    h, w, k = LMIIS()
    s = [input() for i in range(h)]


    ans = [[0] * w for i in range(h)]
    nu = 1

    a = 0
    first = -1
    for i in range(h):
        first = -1
        for j in range(w):
            if s[i][j] == "#":
                if first == -1:
                    first = 0
                else:
                    for k in range(first, j):
                        for l in range(a, i+1):
                            ans[l][k] = str(nu)
                    nu += 1
                    first = j
        if first != -1:
            for k in range(first, w):
                for l in range(a, i+1):
                    ans[l][k] = str(nu)
            nu += 1
            a = i+1
    if first == -1:
        for i in range(a, h):
            for j in range(w):
                ans[i][j] = ans[a-1][j]


    for i in range(h):
        print(" ".join(ans[i]))






if __name__ == '__main__':
    main()


Measured memory_bytes: 9360
#import sys
#sys.setrecursionlimit(10**9)

H, N = map(int, input().split())
magic = [_ for _ in range(N)]

for k in range(N):
  magic[k] = list(map(int, input().split()))
  magic[k].append(magic[k][0]/magic[k][1])

magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
ans2 = float('inf')
"""
def solve(start, power, point, maryoku):
  if start == H:
    print(min(point, min(anskouho)))
    exit()
  elif start > H:
    anskouho.append(point)
    return 0
  elif ans[start] != 0:
    return 0
  else:
    visited.append(start)
    ans[start] = point
    solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
  for item in visited:
    #solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
    start = item+magic[k][0]
    power = magic[k][0]
    point = ans[item]+ magic[k][1]
    maryoku = magic[k][1]
    for _ in range(10**5):
      if start == H:
        print(min(point, ans2))
        exit()
      elif start > H:
        ans2 = min(ans2, point)
        break
      elif ans[start]!=0:
        break
      else:
        visited.append(start)
        ans[start] = point
        start += power
        point += maryoku
      
print(ans2)

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

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define REP(i, n) for(int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for(int64 i = (a); i < (b); i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint32_t;
using int64 = int64_t;
using uint64 = uint64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

template<typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; }
template<typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; }

int main(void) {
  int64 n;
  while (cin >> n) {
    vector<int64> a(n);
    REP(i, n) cin >> a[i];
    sort(all(a));
    int64 res = 0, sum = 0;
    REP(i, a.size()) {
      sum += a[i];
      res += sum;
    }
    cout << res << endl;
  }
}


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

public class Main {

    public static void main(String[] args) {
        // input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        int[][] abcd = new int[q][4];
        for (int i = 0; i < q; i++) {
            abcd[i] = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }

        int max = 0;
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = 1;
        }
        boolean limit = true;
        int index = n - 1;
        while (limit) {
            int point = 0;
            for (int[] calc : abcd) {
                if (a[calc[1]] - a[calc[0]] == calc[2]) point += calc[3];
            }
            if (max < point) max = point;
            limit = countup(a, m);
        }

        System.out.println(max);
    }

    public static boolean countup(int[] a, int m) {
        boolean can_up = false;
        for (int i = a.length - 1; i >= 0; i--) {
            if (a[i] == m) {
                if (i == 0) break;
                if (a[i - 1] == m) continue;
//                if (a[i - 1] < m) {
//                    for (int j = i; j < a.length; j++) {
//                        a[j] = a[j - 1] + 1;
//                    }
//                }
                a[i - 1]++;
                for (int j = i; j < a.length; j++) {
                    a[j] = a[j - 1];
                }
                can_up = true;
                break;
            }
            a[i]++;
            can_up = true;
            break;
        }
        return can_up;
    }
}

Measured memory_bytes: 37528
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int P = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	return (a + b) % P;
}

int mult(int a, int b) {
	return (a * (long long) b) % P;
}


vector<int> GetDyn(int steps, int n, int x) {
    if (n == 0) {
		vector<int> res(steps + 1, 0);
		res[0] = 1;
		return res;
	}

	vector<int> res(steps + 1);
	vector<vector<int>> dyn(2, vector<int>(n + 1));
	for (int i = 0; i <= n; ++i) {
		dyn[0][i] = 1;
    }
    res[0] = dyn[0][x];

    int t = 0;
    for (int i = 1; i <= steps; ++i) {
    	dyn[t ^ 1][0] = dyn[t][1];
    	dyn[t ^ 1][n] = dyn[t][n - 1];
    	for (int j = 1; j < n; ++j) {
    		dyn[t ^ 1][j] = sum(dyn[t][j - 1], dyn[t][j + 1]);
    	}
    	res[i] = dyn[t ^ 1][x];
    	t ^= 1;
    }

    return res;                               
}

int main () {
//  ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	int n, m;
	cin >> n >> m;

	vector<int> small0 = GetDyn(2 * m, 2 * n - 2, 0);
	vector<int> big1 = GetDyn(2 * m, 2 * n, 1);
	
	int res = big1[2 * m - 1];
	for (int j = 0; j < m; ++j) {
		res = sum(res, mult(small0[2 * j], big1[2 * m - 2 * j - 1]));
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 384
n, m = map(int, input().split())

card_list = [1] * n

minr = 10**9
maxl = 0

for i in range(m):
    l, r  = map(int, input().split())
    maxl = max(maxl, l)
    minr = min(minr, r)
print(max(minr - maxl + 1, 0))


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	double q, x;
	
	while(true){
		
		scanf("%lf", &q);
		
		if(q < 0){
			break;
		}
		
		x = q / 2;
		
		while(true){
			if(abs(x * x * x - q) < q * 0.00001){
				break;
			}
			x -= (x * x * x - q) / (3 * x * x);
		}
		
		printf("%.10f\n", x);
		
	}
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string.h>
#include <queue>

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

char t[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ans,h,w;
queue<P> q;

int bfs(int x, int y){

  q.push( P(x, y) );
  
  while( !q.empty() ){
    P now = q.front();
    q.pop();
    for( int i = 0 ; i < 4 ; i++ ){
      int nx = now.first + dx[i];
      int ny = now.second + dy[i];
      if( 0 <= nx && nx < w && 0 <= ny && ny <= h 
	  && t[ny][nx] == '.' ){
	t[ny][nx] = '#';
	q.push( P(nx, ny) );
	ans++;
      }
    }
  }
  return ans;
}

int main(void){

  int x,y;
  while( cin >> w >> h, h + w ){

    memset( t, 0, sizeof(t) );
    ans = 1;

    for( int i = 0 ; i < h ; i++ ){
      for( int j = 0 ; j < w ; j++ ){
	cin >> t[i][j];
	if( t[i][j] == '@' ){
	  x = j;
	  y = i;
	}
      }
    }
    cout << bfs(x,y) << endl;
  }
  return 0;
}

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

int main(){
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	cout.tie(NULL);
	
	long long int a,b,c;
	cin>>a>>b>>c;
	if(c-(a+b)<0){
	    cout<<"No";
	}
	else{
	    if(((c-(a+b))*(c-(a+b)))>4*a*b){
	        cout<<"Yes";
	    }
	    else{
	        cout<<"No";
	    }
	}
	
	return 0;
}


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

using namespace std;

#define ll long long

int main(void){
    int x;
    int a, b;
    cin >> x;

    a = x / 500;
    x = x - 500*a;
    b = x / 5;

    cout << a*1000 + b*5 << endl;

    return 0;
}

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

int main() {
  int A, B, C, D, E;
  cin >> A;
  B = A % 2;
  C = (A - B) / 10;
  D = C % 2;
  E = (C - D) / 10;
  cout << B + D + E << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    map<ll, ll> mp;
    FOR(i, 0, N){
        ll a;
        cin >> a;
        mp[a]++;
    }

    vector<ll> candidates;
    for(auto a : mp){
        ll length = a.first;
        ll count = a.second;
        if(count >= 2){
            candidates.push_back(length);
        }
    }
    sort(ALL(candidates));

    if(candidates.size()==0){
        p(0);
    }
    else if(candidates.size()==1){
        ll length = candidates[0];
        ll count = mp[length];
        if(count < 4){
            p(0);
        }else{
            p(length * length);
        }
    }
    else{
        ll L = candidates.size();
        ll longest = candidates[L-1];
        ll count = mp[longest];
        if(count > 3){
            p(longest * longest);
        }else{
            p(longest * candidates[L-2]);
        }
    }
    
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll dp[110][100100];
	
int main(){
	ll n, wc; cin >> n >> wc;
	vector<ll> w(n+10, 0);
	vector<ll> v(n+10, 0);
	for( int i = 0; i < n; ++i ){
		cin >> w[i+1] >> v[i+1];
	}
	for( ll i = 1; i <= n; ++i ){
		for( ll j = 1; j <= wc; ++j ){
			dp[i][j] = dp[i-1][j];
			if( j >= w[i] ) dp[i][j] = max( dp[i][j], dp[i-1][j-w[i]] + v[i]  ); 
		}
	}
	cout << dp[n][wc] << endl;
	return 0;
}

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

typedef long long ll;

const int minum = 104;
const int MAX = 200;

int main() {
    ll ans = 0;
    ll N;
    cin >> N;

    if (N <= minum) ;
    else if (N == 105) ans = 1;
    else {
        ans++;
        for (ll i = 107; i <= N; i += 2) {
            ll div = 0;
            for(ll j = 1; j <= i; j += 2) {
                if (i % j == 0) div++;
            }
            if (div == 8) {
                ans++;
                // cout << i << endl;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD

class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L

n, a, b = list(map(int, input().split()))
MOD = 10 ** 9 + 7

inv = Inv(MOD)
com = comb(max(a, b) + 1, MOD)

ans = inv.modpow(2, n) - 1

def nasu(n, a):
  ans = 1
  for i in range(a):
    ans = ans * (n - i) * com.I[i + 1] % MOD
  return ans

ans = ans - nasu(n, a)
ans = ans - nasu(n, b)

while ans < 0:
  ans += MOD

print(ans)

Measured memory_bytes: 80880
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n;
  cin >> n;
  map<string, ll> m;
  string s;
  for (int i = 0; i < n; i++){
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }

  ll ret = 0;
  for (auto i = m.begin(); i != m.end(); i++){
    ret += i->second * (i->second - 1)/2;
  }


  cout << ret << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 36

struct Card {
    char suit, value;
};

void bubbleSort(struct Card deck[], int n);
void selectionSort(struct Card deck[], int n);
bool isStable(struct Card deck1[], struct Card deck2[], int n);
void print(struct Card deck[], int n);
int main() {
    int n, i;
    bool status;
    cin >> n;
    struct Card deck1[MAX], deck2[MAX], temp[MAX];
    for (i = 0; i < n; i++) cin >> deck1[i].suit >> deck1[i].value;
    for (i = 0; i < n; i++) deck2[i] = deck1[i];
    for (i = 0; i < n; i++) temp[i] = deck1[i];

    status = 0;
    bubbleSort(deck1, n);
    print(deck1, n);
    cout << "Stable" << endl;
    selectionSort(deck2, n);
    print(deck2, n);
    if (isStable(deck1, deck2, n))
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    
    
    return 0;
}
void print(struct Card deck[], int n) {    
    for (int i = 0; i < n; i++) cout << deck[i].suit << deck[i].value << (i < n - 1 ? " " : "\n");
}

void bubbleSort(struct Card deck[], int n) {
    bool flag;
    int i, j;
    flag = 1;
    for (i = 0; flag; i++) {
        flag = 0;
        for (j = n - 1; j >= i; j--) {
            if (deck[j - 1].value > deck[j].value) {
                swap(deck[j - 1], deck[j]);
                flag = 1;
            }
        }
    }
}

void selectionSort(struct Card deck[], int n) {
    int i, j, minj;
    for (i = 0; i < n; i++) {
        minj = i;
        for (j = i + 1; j < n; j++) {
            if (deck[j].value < deck[minj].value)
                minj = j;
        }
        swap(deck[i], deck[minj]);
    }
}

bool isStable(struct Card deck1[], struct Card deck2[], int n) {
    for (int i = 0; i < n; i++)
        if (deck1[i].suit != deck2[i].suit) return false;
    return true;
}


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            int n = NextInt;
            var a = IntList;

            System.Console.WriteLine(
                string.Join(" ", Enumerable.Range(1, n).OrderBy(i => a[i - 1]))
            );
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 31068
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int n,sum=0,max=0,p=0,ans=0,flag=0,count=0,count2=0,min=INF;
	string s;
	cin>>n>>s;
	REP(i,s.size()){
		if(s[i]=='E'){
			count++;
		}
	}
	REP(i,s.size()){
		if(s[i]=='E'){
			count--;
		}
		if(count+count2<min){
			min=count+count2;
		}
		if(s[i]=='W'){
			count2++;
		}
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll INF = 1e18;
int MOD = 1e9+7;
using edge = struct {int to; ll cost;};
vector<edge> tree[100010];
ll depth[100010];
void dfs(int v,int p,ll d){
    depth[v] = d;
    for(auto &e:tree[v]){
        if(e.to == p)continue;//行き先と来た道が一致してたら
        dfs(e.to,v,d+e.cost);
    }
}
main(){
    int N,Q,K;
    cin >> N;
    for(int i = 0;i < N-1;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }
    cin >> Q >> K;
    dfs(K-1,-1,0);
    for(int i = 0;i < Q;i++){
        int a,b;
        cin >> a >> b;
        cout << depth[a-1] + depth[b-1] << endl;
    }
}

Measured memory_bytes: 14336
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class BinaryIndexedTree {
    vector<int64_t> container;

public:
    BinaryIndexedTree(size_t size)
        : container(size + 1)
    {
        fill(container.begin(), container.end(), 0);
    }
    void add(size_t i, int64_t v)
    {
        size_t idx = i + 1;
        while (idx < container.size()) {
            container[idx] += v;
            idx += idx & -idx;
        }
    }
    int64_t find(size_t i)
    {
        size_t idx = i;

        int64_t result = 0;
        while (idx != 0) {
            result = container[idx] + result;
            idx -= idx & -idx;
        }
        return result;
    }
};

int main()
{
    string s;
    cin >> s;
    const int n = s.size();

    vector<int> cnt(26);

    rep(i, n)
    {
        cnt[s[i] - 'a']++;
    }

    char center = '.';
    rep(i, 26)
    {
        if (cnt[i] % 2 != 0) {
            if (center != '.') {
                cout << -1 << endl;
                return 0;
            } else {
                center = i + 'a';
            }
        }
    }

    vector<int> v;

    vector<int> tcnt(26);
    string t, u;
    rep(i, n)
    {
        int j = s[i] - 'a';
        if (s[i] == center) {
            if (tcnt[j] < cnt[j] / 2) {
                t.push_back(s[i]);
                v.push_back(0);
            } else if (tcnt[j] > cnt[j] / 2) {
                u.push_back(s[i]);
                v.push_back(2);
            } else {
                v.push_back(1);
            }
        } else {
            if (tcnt[j] < cnt[j] / 2) {
                t.push_back(s[i]);
                v.push_back(0);
            } else {
                u.push_back(s[i]);
                v.push_back(2);
            }
        }
        tcnt[j]++;
    }
    reverse(u.begin(), u.end());

    BinaryIndexedTree bit1(3);
    int64_t noi1 = 0;
    rep(i, n)
    {
        noi1 += bit1.find(3) - bit1.find(v[i] + 1);
        bit1.add(v[i], 1);
    }

    vector<vector<int>> idx(26);
    rrep(i, u.size())
    {
        idx[u[i] - 'a'].push_back(i);
    }

    vector<int> x;
    rep(i, t.size())
    {
        x.push_back(idx[t[i] - 'a'].back());
        idx[t[i] - 'a'].pop_back();
    }

    BinaryIndexedTree bit2(x.size());
    int64_t noi2 = 0;
    rep(i, x.size())
    {
        noi2 += bit2.find(x.size()) - bit2.find(x[i] + 1);
        bit2.add(x[i], 1);
    }

    cout << noi1 + noi2 << endl;

    return 0;
}

Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    int a; cin>>a;
    if(a>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }








































Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    ll N;
    cin >> N;
    vl C(N),D(N);
    ll ans=0;
    rep(i,N){
        cin >> C[i] >> D[i];

    }
    rep(i,N){
        if(C[i]==D[i]) {
            ans++;
            if(ans == 3) break;
        }else{
            ans = 0;
        }
    }
    print((ans==3)?"Yes":"No");

}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	ll N,M; cin>>N>>M;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];
	sort(all(A),greater<ll>());

	ll cnt=0;
	while(cnt<=M){
		ll mem=0;
		bool flag=false;

		rep(i,N){
			if(i==0){
				mem=((A[i]/2)+1)/2;
				A[i]/=2;
				cnt++;
			}
			else if(mem*2-1<=A[i]){
				A[i]/=2;
				cnt++;
			}

			if(cnt==M){
				flag=true;
				break;
			}
		}

		if(flag) break;
		else sort(all(A),greater<ll>());
	}

	ll ans=0;
	rep(i,N){
		ans+=A[i];
	}
	cout<<ans;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    cout << (n-1)*n/2 + (m-1)*m/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
from collections import defaultdict
N, M = list(map(int, input().split()))

visited = [False] * (N+1)
visited[0] = True
visited[1] = True
T = defaultdict(list)
for _ in range(M):
    a, b = list(map(int, input().split()))
    T[a].append(b)
    T[b].append(a)

q = deque()
q.append(1)

route = [0] * (N+1)

while q:
    v = q.popleft()
    for n in T[v]:
        if not visited[n]:
            route[n] = v
            q.append(n)
            visited[n] = True

if visited.count(False) > 0:
    print("No")
    sys.exit(0)

print("Yes")
for i in range(2, N+1):
    print(route[i])


Measured memory_bytes: 105216