akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int n;
    cin >> n;
    vector<int> t(n+1),x(n+1),y(n+1);

    t[0] = x[0] = y[0] = 0;
    for(int i = 1; i < n+1;i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    
    bool isTravel = true;
    for(int i = 0; i < n;i++){
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dist <= t[i+1] - t[i]){
            if((x[i+1] + y[i+1])%2 == 0 && t[i+1]%2 == 0){
            }else if((x[i+1] + y[i+1])%2 == 1 && t[i+1]%2 == 1){
            }else{
                isTravel = false;
                break;
            }
        }else{
            isTravel = false;
            break;
        }
    }

    if(isTravel) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 1408
n=int(input())
s=[int(input()) for _ in range(n)]
ans=sum(s)
if ans%10!=0:
    print(ans)
else:
    l=[s[i] for i in range(n) if s[i]%10!=0]
    if l==[]:
        print('0')
    else:
        l.sort()
        print(ans-l[0])

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

int main(){
  map<ll,ll> m;
  ll asum = 0;
  
  int n;cin >> n;
  
  rep(i,n) {
    int a;cin >> a;
    m[a] += 1;
    asum += a;
  }

  int q;cin >> q;
  rep(i,q){
    int b,c;cin >> b >> c;
    asum = asum - (m[b] * b) + (m[b] * c);
    m[c] += m[b]; m[b] = 0;
    cout << asum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 9576
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int d = sc.nextInt();
		int ans=0;
		int[][] dd=new int[n][d];
		for(int i=0; i<n; i++){
			for(int j=0; j<d; j++){
				dd[i][j]=sc.nextInt();
			}
		}
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				int sum=0;
				for(int k=0; k<d; k++){
					sum+=(dd[i][k]-dd[j][k])*(dd[i][k]-dd[j][k]);
				}
				if(Math.sqrt(sum)==(int)Math.sqrt(sum)){
				
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}




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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N * 3);
  for (int i = 0; i < N * 3; ++i) cin >> a[i];

  vector<ll> mx(3 * N + 1), mn(3 * N + 1);
  {
    priority_queue<ll, vector<ll>, greater<ll>> pq1;
    ll acc = 0;
    for (int i = 0; i < N; ++i) {
      pq1.push(a[i]);
      acc += a[i];
    }
    mx[N] = acc;
    for (int i = N; i < 3 * N; ++i) {
      acc -= pq1.top();
      acc += a[i];
      pq1.pop();
      pq1.push(a[i]);
      mx[i + 1] = max(mx[i], acc);
    }
  }

  {
    priority_queue<ll, vector<ll>, less<ll>> pq2;
    ll acc = 0;
    for (int i = 0; i < N; ++i) {
      pq2.push(a[3 * N - 1 - i]);
      acc += a[3 * N - 1 - i];
    }
    mn[2 * N] = acc;
    for (int i = 2 * N - 1; i >= 0; --i) {
      acc -= pq2.top();
      acc += a[i];
      pq2.pop();
      pq2.push(a[i]);
      mn[i] = min(mn[i + 1], acc);
    }
  }

  ll ans = -1e18;
  for (int i = N; i < 2 * N + 1; ++i) {
    ans = max(ans, mx[i] - mn[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9068
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int N;
  	cin >> N;
  	vector<int> W(N);
  	rep(i,N) cin >> W[i];
  
  	vector<int> left(N);
  	vector<int> right(N);
  	
  	left[0] = W[0];
  	rep(i,N-1) left[i+1] = left[i] + W[i+1];
  	right[N-1] = W[N-1];
  	rep3rev(i,N-2,0) right[i] = right[i+1] + W[i];
  	
  	/*
  	rep(i,N) cout << left[i] << " ";
  	cout << endl;
  	rep(i,N) cout << right[i] << " ";
  	*/
  	
  	int ans = INT_MAX;
  	rep(i,N-1) ans = min(ans, abs(left[i] - right[i+1]));
	cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
"use strict";
    
// 組み合わせ（nCr）列挙ではなく計算のみ
const permutation = (n, r) => {
    let res = 1;
    
    for(let i=0; i<r; i++) {
        res *= n - i;
    }
    
    return res;
}
 
const nCr = (n, r) => {
    return permutation(n, r) / permutation(r, r);
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const S = arg.slice(1, N + 1);
    
    const map = {};
    
    for(let i=0; i<N; i++) {
        let temp = S[i].split("").sort().join("");
        
        // console.log(temp)
        
        if(map[temp]) {
            map[temp]++;
        } else {
            map[temp] = 1;
        }
    }
    
    let answer = 0;
    
    for(let key in map) {
        if(map[key] >= 2) {
            answer += nCr(map[key], 2);
        }
    }
    
    console.log(answer)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 45008
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; string s; cin >> n >> s; ll ans = 1e10;
  vl wcnt(n+1); vl ecnt(n+2);
  
  
  rep(i,n){
    wcnt[i+1] = wcnt[i];
    if(s[i] == 'W') wcnt[i+1]++;
  }
  
  for(ll i=n+1; i >= 2; i--){
    ecnt[i-1] = ecnt[i];
    if(s[i-2] == 'E') ecnt[i-1]++;
  }

  
  for(ll i=1; i <= n; i++){
    ans = min(ans,wcnt[i-1] + ecnt[i+1]);
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 8256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0;i < N;i++) {
   cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int counta = 0;
  int countb = 0;
  
  for (int i = 0;i < N;i++) {
   if ((i+1)%2 == 1) {
    counta+=vec.at(i);
   }
   else {
    countb+=vec.at(i);
   }
  }
  
  cout << counta - countb << endl;
  
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

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

            if (a > 9 || b > 9)
                out.println(-1);
            else
                out.println(a * b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {

                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23124
//48
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    int p[1000];
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    sort(p,p+n,greater<int>());
    int cost=0;
    int h=0;
    for(int i=0;i<n;i++){
      h++;
      if(h%m){
	cost+=p[i];
      }
    }
    cout<<cost<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int dp[2020];
int main() {
    Int S; cin >> S;
    for (int i = 3; i <= S; i++) {
        dp[i] = 1;
        for (int j = 3; j <= i; j++) {
            dp[i] = (dp[i] + dp[i - j]) % MOD;
        }
    }
    cout << dp[S] << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const int INF = 1e8;
struct MaximumFlow {
    vector<vector<tuple<int, int, int>>> G;
    vector<int> visited;
    MaximumFlow(int n) {
        G.resize(n);
        visited.resize(n);
    }
    void add_edge(int s, int t, int c) {
        int si = G[s].size();
        int ti = G[t].size();
        G[s].emplace_back(t, c, ti);
        G[t].emplace_back(s, 0, si);
    }
    int dfs(int s, int t, int c) {
        visited[s] = 1;
        if (s == t) return c;
        for (auto& tup : G[s]) {
            int n, nc, i; tie(n, nc, i) = tup;
            if (visited[n]) continue;
            if (nc == 0) continue;
            int ret = dfs(n, t, min(c, nc));
            if (ret > 0) {
                get<1>(tup) -= ret;
                get<1>(G[n][i]) += ret;
                return ret;
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int ans = 0;
        for (;;) {
            fill(begin(visited), end(visited), 0);
            int f = dfs(s, t, INF);
            if (f == 0) break;
            ans += f;
        }
        return ans;
    }
};
int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); for (auto &s : S) cin >> s;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == 'X' && (i == 0 || i == H - 1 || j == 0 || j == W - 1)) {
                cout << -1 << '\n';
                return 0;
            }
        }
    }
    MaximumFlow mf(2 * (H + 2) * (W + 2) + 2);
    auto idx = [&](int i, int j, int k) { return (i * (W + 2) + j) * 2 + k; };
    int s = 2 * (H + 2) * (W + 2), t = 2 * (H + 2) * (W + 2) + 1;
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            mf.add_edge(idx(i, j, 0), idx(i, j, 1), 1);
            if (1 <= i && i <= H && 1 <= j && j <= W && S[i-1][j-1] == 'X') {
                mf.add_edge(s, idx(i, j, 1), INF);
            }
            if (i + 1 < H + 2) {
                mf.add_edge(idx(i + 1, j, 1), idx(i, j, 0), INF);
                mf.add_edge(idx(i, j, 1), idx(i + 1, j, 0), INF);
            }
            if (j + 1 < W + 2) {
                mf.add_edge(idx(i, j + 1, 1), idx(i, j, 0), INF);
                mf.add_edge(idx(i, j, 1), idx(i, j + 1, 0), INF);
            }
            if (i == 0 || j == 0 || i == H + 1 || j == W + 1) {
                mf.add_edge(idx(i, j, 0), t, INF);
            }
        }
    }
    cout << mf.max_flow(s, t) << '\n';
    return 0;
}


Measured memory_bytes: 3712
//Compiler optimization
#pragma GCC optimize("Ofast")

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

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    ll x,n; cin >> x >> n;
    vl data(110);
    fr(i,n){
        ll p;cin >> p;
        data[p]++;
    }
    ll ans = 0;
    ll now = 100000;
    for(int i = -300;i <= 300;i++){
        if(i >= 1 && i <=100 && data[i])continue;
        if(abs(ans- x) > abs(i - x)){
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	string S;
  	cin >> S;
  	string T;
  	cin >> T;
  	int count = 0;
  	for(int i = 0; i < 3; i++){
    	if(S[i] == T[i]) count++;
    }
	cout << count << endl;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,ans,memo=100000;
map<int,int> m;

signed main () {
    cin >> n >> a;
    a = memo-a;
    m[a]++;
    m[INF]++;
    rep(i,n-1) {
        cin >> a;
        a = memo-a;
        auto itr = m.upper_bound(a);
        if (itr->fi == INF) m[a]++;
        else {
            itr->se--;
            if (!(itr->se)) m.erase(itr);
            m[a]++;
        }
    }
    for(auto i : m) ans += i.se;
    cout << ans-1 << endl;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+10;
int a[maxn];
int pre[maxn];
int net[maxn];
vector<int>s;
int vis[maxn];
ll stute[maxn];
int main()
{
   int  n;
     ll k;
      cin>>n>>k;
       for(int i=1;i<=n;i++)
          cin>>a[i],a[i+n]=a[i];
       for(int i=2*n;i>=1;i--){
            net[i]=pre[a[i]];
             pre[a[i]]=i;
       }
            int now=1;
        memset(stute,-1,sizeof stute);
        while(1)
        {
            if(k<=2)
            {

                for(int i=now;i<=k*n;i++)
                {
                     if(i>n) i=i-n,k--;
                     int temp=a[i];
                     if(vis[a[i]]==1)
                     {


                         while(s.back()!=temp)
                         {
                             vis[s.back()]=0;
                             s.pop_back();

                         }
                         s.pop_back();
                         vis[a[i]]=0;
                     }
                     else
                     {
                         s.push_back(a[i]);
                         vis[a[i]]=1;
                     }

                }
                break;
            }
             now=net[now]+1;
             while(now>n)
            {
                now-=n;
                k--;
            }
        if(stute[now]!=-1)
        {
            k=k%(stute[now]-k);
        }
        stute[now]=k;
        }
        for(int i=0;i<s.size();i++)
            cout<<s[i]<<' ';
        cout<<endl;

    return 0;
}


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

int main()

{string ch;
    cin>>ch;
      int x=stoi(ch.substr(0,2));
      int y=stoi(ch.substr(2,2));
   if(x<=12&&y<=12&&x>0&&y>0)
    cout<<"AMBIGUOUS";
   else if(x<=12&&x>0)
    cout<<"MMYY";
   else if(y<=12&&y>0)
    cout<<"YYMM";
   else
    cout<<"NA";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
   int n; cin >> n;
   map<string,int> count;
   rep(i,n){
       string s;
       cin >> s;
       count[s]++;
   }

   int m; cin >> m;
   rep(i,m){
       string t;
       cin >> t;
       count[t]--;
   }
   int max_count = 0;
    for (auto & it : count) {
        max_count = max(max_count, it.second);
    }
    print(max_count);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3424
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	for ( int n; cin >> n, n; )
	{
		VPII events;

		REP( i, 0, n )
		{
			int h1, m1, s1, h2, m2, s2;
			char d;
			cin >> h1 >> d >> m1 >> d >> s1 >> h2 >> d >> m2 >> d >> s2;
			events.PB( MP( h1 * 3600 + m1 * 60 + s1, 1 ) );
			events.PB( MP( h2 * 3600 + m2 * 60 + s2, -1 ) );
		}
		sort( ALL( events ) );

		int res = 0, cur = 0;
		REP( i, 0, events.size() )
		{
			res = max( res, ( cur += events[i].snd ) );
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1464
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    string S;
    cin >> S;
    rep(i, S.size()){
        S[i] = 'x';
    }

    cout << S <<endl;
}

int main(){
    Main();
}

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

int main(void) {
  int pus, n, count = 0, times = 0;
  cin >> n;
  int buton[n];
  for (int i = 0; i < n; i++) {
    cin >> buton[i];
  }
  pus = buton[0];
  count = times = 1;
  if (pus == 2) {
    cout << count << endl;
    return 0;
  }
  while (true) {
    if (buton[pus - 1] == 2) {
      cout << count + 1 << endl;
      return 0;
    }
    pus = buton[pus - 1];
    count++;
    times++;
    if (times > n * 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}


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

void solve(long long N)
{
    cout << static_cast<double>(N + (N % 2)) / static_cast<double>(2 * N) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	OUT(n <= 2 ? n : n - 1);
	inc1(i, n) {
		if(i == 1) {
			if(n <= 2) { OUT("1"); }
		} else {
			OUT("0" + string(i - 2, '1') + "0");
		}
	}
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
int inf=1000001000;
ll INF=100000000000000000;

template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    // using F = function<T(T, T)>
    // using G = function<T(T, E)>
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
 
    
    
    /* TODO わからない 聞く 
    template<typename C>
    int find(int a,int b,C &check,int k,int l,int r){
        if(!check(dat[k])||r<=a||b<=l) return -1;
        if(k>=n) return k-n;
        int m=(l+r)>>1;
        int vl=find(a,b,check,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(a,b,check,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int a,int b,C &check){
        return find(a,b,check,1,0,n);
    }*/

    // sg.query(l,r) rは含まない
    // sg.update(i,E) iにEをする
    
};
int main() {
    using T = ll;  // type T
  using E = ll;  // type E
  auto f = [](T a, T b){ // return type T value
    return max(a, b);
  };
  auto g = [](T a, E b){ // return type T value
    return b;
  };
  T ti = 0;  // identify element
  SegmentTree<T, E, decltype(f), decltype(g)> sg(f, g, ti);  // don't change
    int n;
    cin >> n;
    vector<ll> r(n+1,0);
    sg.build(r);
    vector<int> h(n);
    vector<ll> a(n);
    rep(i,n) {cin >> h[i];}
    rep(i,n) cin >> a[i];
    ll ans=0;
    rep(i,n){
        ll e=sg.query(0,h[i]);
        ans=max(ans,e+a[i]);
        sg.update(h[i],e+a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8320
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
ss = ["".join(sorted(s[i])) for i in range(n)]
d = Counter()
ans = 0
for i in range(n):
  t = ss[i]
  if t in d:
    ans += d[t]
  d[t] += 1
  #print(d)
print(ans)

Measured memory_bytes: 26864
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int H,W,K;
    cin>>H>>W>>K;
    vector<vector<char>>c(H, vector<char>(W));//操作に用いる二次元はいれつ
    int bcount=0;
    int counter=0;
    int b=0;
    rep(i,H){
        rep(j,W){
            cin>>c.at(i).at(j);
            if(c.at(i).at(j)=='#'){
                b++;
            }
        }
    }
    for(int t1=0;t1<(1<<H);t1++){
        for(int t2=0;t2<(1<<W);t2++){
            bitset<6>s1(t1);//gyou
            bitset<6>s2(t2);//retsu
            bcount=b;//黒の数を選択前にする
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(s1.test(i)||s2.test(j)){
                        if(c.at(i).at(j)=='#'){
                            bcount--;
                        }
                    }
                }            
            }
            if(bcount==K){//黒であればcounterに数える
                counter++;
            }
        }
    }
    cout<<counter<<endl;    
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	int li, ri, ans;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> li >> ri;
		ans += ri - li + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
const int mod = 1000000007;//998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

string s, t;
int c = 0;
int l, r;

void Solve()
{
	cin >> s >> t;
	for(int i = 0; i < s.length(); i++)
	{
		if(s[i] != t[i])
		{
			cout << "No";
			return;
		}
	}
	cout << "Yes";
}
 
int main()
{	
	Fastio();
	Solve();
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 5e5 + 100;
typedef long long ll;
string s;
int a[N];
void expend(int pos) {
	for(int i = 1; s[pos-i] == '>'; i++) {
		a[pos-i] = max(a[pos-i], i);
	}
	for(int i = 1; s[pos+i-1] == '<'; i++) {
		a[pos+i] = max(a[pos+i], i);
	}
}
int main() {
	//freopen("01-05.txt", "r", stdin);
	cin >> s;
	s = ">" + s + "<";
	int n = s.size()-2;
	for(int i = 0; i <= n+1; i++) {
		if(s[i] == '>' && s[i+1] == '<') {
			expend(i + 1);
		}
	}
	
	ll ans = 0;
	for(int i = 1; i <= n+1; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5404
#include <iostream>
#include <cstdio>
using namespace std;
int n,m;
char sh[105][105];
bool is_need(int x)
{
	for(int i=0;i<m;i++){
		if(sh[x][i]=='#')return false;
	}
	return true;
}
void change(int x)
{
	for(int i=0;i<m;i++)
		sh[x][i]='*';
}
bool is_need2(int x)
{
	for(int i=0;i<n;i++){
		if(sh[i][x]=='#')return false;
	}
	return true;
}
void change2(int x)
{
	for(int i=0;i<n;i++)
		sh[i][x]='*';
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",sh[i]);
	for(int i=0;i<n;i++)
		if(is_need(i))change(i);
	for(int i=0;i<m;i++)
		if(is_need2(i))change2(i);
	/*for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			printf("%c",sh[i][j]);
		printf("\n");
	}*/
	for(int i=0;i<n;i++){
		int f=0;
		for(int j=0;j<m;j++)
			if(sh[i][j]!='*'){
				f=1;printf("%c",sh[i][j]);
			}
		if(f)printf("\n");
	}
	return 0;
}

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

vector<int> V = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
  int K;
  cin >> K;
  cout << V[K-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pll a[300001];
ll kx[300001], ky[300001], d[1200004];
set<ll> st[300001];
void update(ll l, ll r, ll pos, ll zn, ll v)
{
    if (l == r)
    {
        d[v] = zn;
        return;
    }
    ll m = (l + r) / 2;
    if (pos <= m) update(l, m, pos, zn, 2 * v);
    else update(m + 1, r, pos, zn, 2 * v + 1);
    d[v] = max(d[2 * v], d[2 * v + 1]);
}

int main()
{
    fast_io;
    ll h, w, m, i, s = 0;
    cin >> h >> w >> m;
    for (i = 1; i <= m; i++) cin >> a[i].first >> a[i].second, kx[a[i].first]++, ky[a[i].second]++, st[a[i].first].insert(a[i].second);
    for (i = 1; i <= w; i++) update(1, w, i, ky[i], 1);
    for (i = 1; i <= h; i++)
    {
        vector<ll> v;
        for (auto f: st[i])
            s = max(s, kx[i] + ky[f] - 1), update(1, w, f, 0, 1), v.pb(f);
        s = max(s, kx[i] + d[1]);
        for (auto f: v) update(1, w, f, ky[f], 1);
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 50588
#include <iostream>
#include <cstdlib>

using namespace std;

class Stack {
private:
	int A[100];
	int pos;
public:
	Stack() { pos = 0; }
	void push(int i) { A[pos++] = i; }
	int pop() { return A[--pos]; }
};

int main() {
	int a, b, n, check;
	char str[8];
	Stack stack;

	while (cin >> str) {
		check = str[0] & 0x0F;
		if (check >= 0 && check < 10) {
			stack.push(atoi(str));
			continue;
		}
		a = stack.pop();
		b = stack.pop();
		switch (str[0]) {
		case '+':
			stack.push(a + b);
			break;
		case '-':
			stack.push(b - a);
			break;
		case '*':
			stack.push(a * b);
			break;
		}
	}

	cout << stack.pop() << endl;

	return 0;
}


Measured memory_bytes: 3092
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int c = sc.nextInt();

        // 出力
        System.out.println(a * b / 2);

    }

}

Measured memory_bytes: 23764
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
vi v;
int a[200005];
map<int,int>pos;
int main(){
	std::ios::sync_with_stdio(false);
	int n,i,val;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	rep(i,v.size()){
		pos[v[i]]=i;
	}
	val=n/2-1;
	rep(i,n){
		if(a[i]>v[val]){
			cout<<v[val]<<endl;
		}
		else{
			cout<<v[val+1]<<endl;
		}
	}
} 
	

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

int main() {
  int N,sum=0;
  cin >> N;
  vector<int> length(N);
  for(int i=0;i<N;i++){
  	cin >> length.at(i);
  }
  sort(length.begin(),length.end());
  for(int i=0;i<N-1;i++){
  	sum+=length.at(i);
  }
  if(sum<=length.at(N-1)){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi a(n);
    cin >> a;
    rep(i, n) a[i]--;
    vl e(m), f(m);
    auto add = [&](int l, int r, int st) {
        assert(l <= r);
        e[l]++;
        f[l] += st - l;
        if (r < m - 1) {
            e[r + 1]--;
            f[r + 1] -= st - l;
        }
    };
    ll ans = 0;
    rep(i, n - 1) {
        int x = a[i], y = a[i + 1];
        if (x < y) {
            ans += y - x;
            add(x + 1, y, 0);
        } else {
            ans += y + m - x;
            if (x < m - 1) add(x + 1, m - 1, 0);
            add(0, y, m - x - 1);
        }
    }
    rep(i, m - 1) {
        e[i + 1] += e[i];
        f[i + 1] += f[i];
    }
    ll mx = 0;
    rep(i, m) chmax(mx, e[i] * i + f[i]);
    cout << ans - mx << endl;
}


Measured memory_bytes: 5260
#include<bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
using namespace std;
typedef long long ll;
 
ll ch1(ll a,ll b){
    if(a>b)swap(a,b);
    ll s=sqrt((long double)a*b-1);
    if(s==0)return 0;
    ll mx=(a*b-1)/s;
    ll ans=2*s;
    if(mx==s)ans--;
    if(a<=s)ans--;
    return ans;
}
 
signed main(){
  ll q,a,b;
  cin>>q;
  while(q--){
    cin>>a>>b;
    cout<<ch1(a,b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
 
#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30
 
int main()
{
	int N, T, A;
	int H;
	int id, diff, tmp;
 
	cin >> N >> T >> A;
	cin >> H;
	A *= 1000;
	T *= 1000;
	id = 0;
	diff = abs( A - (T - H*6) );
	for(int i=1; i<N; i++ ){
		cin >> H;
		tmp = abs( A - (T - H*6) );
		if( tmp < diff ){
			id = i;
			diff = tmp;
		}
	}
	cout << id+1 << endl;
 
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int i = 1, x;
    while (cin >> x, x)
    {
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
}



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

typedef long long ll;

int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;
    vector<int> ans;
    int x = N;
    while (x > 0) {
        bool f = true;
        for (int i = min(M, x); i > 0; i--) {
            if (S[x - i] == '0') {
                ans.push_back(i);
                x -= i;
                f = false;
                break;
            }
        }
        if (f) {
            cout << "-1\n";
            return 0;
        }
    }
    rep(i, ans.size()) {
        cout << ans[ans.size() - 1 - i];
        if (i == ans.size() - 1) cout << "\n";
        else cout << " ";
    }
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h+2,vector<char>(w+2));
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> a[i][j];
    }
  }
  int cnt=0;
  for(int i=1;i<=h;i++){
   for(int j=1;j<=w;j++){
      if(a[i-1][j]!='#' && a[i+1][j]!='#'&& a[i][j-1]!='#' && a[i][j+1]!='#' && a[i][j]=='#')cnt++;
   }
  }
  if(cnt==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using ll = long long;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

template <typename T>
class starry_sky_tree {
public:
    starry_sky_tree(int n_)
        : n(expand(n_)), data(n * 2, 0), lazy(n * 2, 0)
    {}

    void add(int l, int r, T val) {
        l += n;
        r += n;
        int const left = l, right = r;
        while(l != r) {
            if(l & 1) {
                lazy[l] += val;
                data[l++] += val;
            }
            if(r & 1) {
                lazy[--r] += val;
                data[r] += val;
            }
            l /= 2;
            r /= 2;
        }
        l = left, r = right - 1;
        while(l /= 2, r /= 2) {
            data[l] = std::min(data[l * 2], data[l * 2 + 1]) + lazy[l];
            data[r] = std::min(data[r * 2], data[r * 2 + 1]) + lazy[r];
        }
    }

    T min(int l, int r) const {
        if(l == r) {
            return inf<T>;
        }
        l += n;
        r += n;
        T res1 = inf<T>, res2 = inf<T>;
        while(l != r) {
            if(l & 1) {
                res1 = std::min(res1, data[l++]);
            }
            if(r & 1) {
                res2 = std::min(res2, data[--r]);
            }
            l /= 2;
            r /= 2;
            res1 += lazy[l - 1];
            res2 += lazy[r];
        }
        --l;
        while(l /= 2, r /= 2) {
            res1 += lazy[l];
            res2 += lazy[r];
        }
        return std::min(std::min(res1, res2), inf<T>);
    }

private:
    int expand(int n) const {
        assert(n != 0);
        return n == 1 ? n : expand((n + 1) / 2) * 2;
    }

private:
    int const n;
    std::vector<T> data, lazy;
};


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

    int Q;
    cin >> Q;
    vector<int> l(Q), r(Q);
    for(int i = 0; i < Q; ++i) {
        cin >> l[i] >> r[i];
    }

    starry_sky_tree<int> seg(N + 1); // dp
    seg.add(1, N + 1, 1e8);
    vector<vector<int>> rs(N + 1);
    for(int i = 0; i < Q; ++i) {
        rs[l[i] - 1].push_back(r[i]);
    }
    for(int i = 0; i < N; ++i) {
        for(auto r : rs[i]) {
            int mi = seg.min(0, r);
            int def = seg.min(r, r + 1);
            if(mi < def) {
                seg.add(r, r + 1, mi - def);
            }
        }
        seg.add(0, i + 1, b[i]);
        seg.add(i + 1, N + 1, !b[i]);
    }
    cout << seg.min(0, N + 1) << endl;
}



Measured memory_bytes: 15360
#include<stdio.h>
int main(){
    int a[5];
    for(int i = 0; i < 5; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < 5; i++)
        if(a[i] == 0)
            printf("%d\n",i + 1);
    return 0;
}

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

int n;
vector<int> a;

// kを増やすべきかどうか
bool check(int x, int k){
    if (n-k <= n/2) return false;
    return abs(a[n-k*2-1]-x) <= abs(a[n-k-1]-x);
}

int main(void){
    int q;
    cin >> n >> q;
    a.resize(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1), t_sum(n+1);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
        if (i % 2 != n % 2) {
            t_sum[i+1] = t_sum[i] + a[i];
        } else {
            t_sum[i+1] = t_sum[i];
        }
    }
    rep(_,q){
        int x;
        cin >> x;
        int l = 0, r = 1e9;
        while (l + 1 < r) {
            int m = (l+r)/2;
            if (check(x, m)) l = m;
            else r = m;
        }
        int k = r;
        cout << sum[n]-sum[n-k] + t_sum[max(n-2*k,0)]<< endl;
    }

    return 0;
}


Measured memory_bytes: 3712