akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc136/tasks/abc136_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    vector<int> v(len, 0);
    int r = 0, l = 0;
    // R,Lの境界を見つけたら、次のR,Lの境界までの合計を出す
    REP(i, len) {
        if (s[i] == 'R') {
            r++;
        } else if (s[i] == 'L') {
            if (r > 0) {
                bool flag = false;
                if (r % 2 == 0) {
                    flag = true;
                }
                // 次のRを探す
                int j = i;
                while (j < len) {
                    if (s[j] == 'R') {
                        break;
                    }
                    j++;
                    r++;
                }
                if (flag) {
                    v[i - 1] = (double)r / 2;
                    v[i] = ceil((double)r / 2);
                } else {
                    v[i - 1] = ceil((double)r / 2);
                    v[i] = (double)r / 2;
                }
                r = 0;
                i = j - 1;
            }
            l++;
        }
    }
    for (auto x : v) {
        cout << x << " ";
    }

    return 0;
}


Measured memory_bytes: 1104
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define INF 1000000007
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    int n, m;
    cin >> n >> m;
    int ac = 0;
    int penalty = 0;
    map<int, int> wa_map;
    map<int ,bool> ac_map;
    for (int i = 0; i < m; i++) {
        int q_num;
        string result;
        cin >> q_num >> result;

        // 初めて解く問題だったら初期化
        if (wa_map.count(q_num) == 0) {
            wa_map[q_num] = 0;
        }

        if (result == "AC") {
            if (ac_map.count(q_num) == 0) {
                ac_map[q_num] = true;
                ac++;
                penalty += wa_map[q_num];
            }
        } else {
            wa_map[q_num]++;
        }
    }
    cout << ac << " " << penalty << endl;

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 998244353;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 2e5 + 10;

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}

#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r or n < 0 or r < 0)return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}

int32_t main(){_

   pre(N);

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

   int ans = 0;
   for (int partition = 1; partition <= n; ++partition)
   {
      if (!(n - partition <= k)){
         continue;
      }
      // choose a start point
      int curr = nCr(n-1, partition-1);
      int fill = m * power((m - 1), partition - 1) % mod;
      curr *= fill;
      curr %= mod;
      ans += curr;
      ans %= mod;
   }

   cout<<ans;
   return 0;
}

Measured memory_bytes: 6744
class UnionFind:
    def __init__(self, size):
        self.table = [-1] * size
    
    def find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x
    
    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)
        if x_root != y_root:
            if self.table[x_root] < self.table[y_root]:
                self.table[x_root] += self.table[y_root]
                self.table[y_root] = x_root
            else:
                self.table[y_root] += self.table[x_root]
                self.table[x_root] = y_root
    
    def isDisjoint(self, x, y):
        return self.find(x) != self.find(y)

def solve():
    import sys
    file_input = sys.stdin
    N, M = map(int, file_input.readline().split())
    
    piles = [tuple(map(int, file_input.readline().split())) for i in range(N)]
    
    fences = []
    for i in range(M):
        p, q = map(int, file_input.readline().split())
        p -= 1
        q -= 1
        px, py = piles[p]
        qx, qy = piles[q]
        fence_len = ((px - qx) ** 2 + (py - qy) ** 2) ** 0.5
        fences.append((fence_len, p, q))
    
    fences.sort(reverse=True)
    S = UnionFind(N)
    fences_len = 0
    
    for f_len, p1, p2 in fences:
        if S.isDisjoint(p1, p2):
            S.union(p1, p2)
        else:
            fences_len += f_len
    
    print(fences_len)

solve()


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll A, B, C;

    cin >> A >> B >> C;

    cout << C - min(A - B, C) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1000005;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(), v.end());
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            for (int k = j; k < N; k++) {
                if (v[i] != v[j] && v[j] != v[k] && v[i] + v[j] > v[k]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
    
}


Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <queue>
#include <map>

using namespace std;
using ll = long long;

vector<ll> a;

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

    int N = 50;

    a.reserve(N);

    ll Q = K / N;
    ll R = K % N;

    cout << N << endl;

    for (int i = 0; i < N;i++)
    {
        a[i] = i + Q;
        if(i < R)
        {
            a[i] += N - (R - 1);
        }
        else
        {
            a[i] -= R;
        }
        if(i != N - 1)
        {
            cout << a[i] << " ";
        }
        else
        {
            cout << a[i] << endl;
        }
    }

    return 0;
}

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

int INF = 1001001001;

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<int> dp(n+k, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3976
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(c-a)<=d)cout<<"Yes"<<endl;
	else if(abs(b-a)<=d&&abs(b-c)<=d)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
N,M=map(int,input().split(' '))
if abs(N-M) not in (0,1):
  print(0)
else:
  x = math.factorial(N) % (10**9+7)
  y = math.factorial(M) % (10**9+7)
  print(((2 - abs(N-M))*x*y)%(10**9+7))

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> a(N),b(N);
  int64_t sump=0;
  int64_t sumn=0;
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<N;i++){
    if(b.at(i)-a.at(i)>0){
      sump+=(b.at(i)-a.at(i))/2;
    }else if(b.at(i)-a.at(i)<0){
      sumn-=(b.at(i)-a.at(i));
    }
  }
  if(sump>=sumn){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll gcd(ll x,ll y){
    if(x<y)swap(x,y);
    if(y==0)return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    --a;
    ll l=lcm(c,d);
    //cout<<g<<endl;
    cout<<(b-b/c-b/d+b/l)-(a-a/c-a/d+a/l);
}


Measured memory_bytes: 256
mod=998244353


##mod,nについての制約は自分でいかに記入する

def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n,mod):
    #0!からn!までの逆元を素数modで割ったあまりリストを作る関数
    c=1
    uselist=[0 for i in range(n+1)]
    for i in range(1,n+1):
        c*=i
        c%=mod
    first=pow(c,mod-2,mod)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(mod)
    return uselist
    
A=find_power(4*10**5,mod)
B=find_inv_power(4*10**5,mod)

def combi(n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (A[n]*B[r]*B[n-r])%(mod)



N,M,K=map(int,input().split())
dp=[0 for i in range(N+1)]
#dp[x]=塗り方でダブりが、ｘ通りになるものの個数
ans=M*pow(M-1,N-1,mod)

for i in range(1,K+1):
    ans+=M*combi(N-1,i,mod)*pow(M-1,N-1-i,mod)
print(ans%mod)


Measured memory_bytes: 99120
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B, C, D;

	cin >> A >> B >> C >> D;

	if (A + B == C + D) {

		cout << "Balanced" << endl;
	}
	else if (A + B > C + D) {
		cout << "Left" << endl;
	}
	else {
		cout << "Right" << endl;
	}

	return 0;
}

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

using namespace std;
int n, a, num;
int main() {
  cin >> n;
  a = n / 100;
  num = a*100 + a*10 + a;
  if (n<=num)
    cout << num << endl;
  else
    cout << (a+1)*100 + (a+1)*10 + (a+1) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[,] dp=new long[n,n+1];
		long[] r=new long[n+1];
		r[1]=a[0];
		for(int i=1;i<n;i++){r[i+1]=a[i]+r[i];}
		for(int i=1;i<n;i++){
			for(int j=0;j+i<n;j++){
				dp[j,i+j]=long.MaxValue;
				for(int k=j;k<i+j;k++){dp[j,i+j]=Math.Min(dp[j,k]+dp[k+1,i+j]+r[i+j+1]-r[j],dp[j,i+j]);}
			}
		}
		Console.WriteLine("{0}",dp[0,n-1]);
	}
}

Measured memory_bytes: 14176
#16:40
m,k = map(int,input().split())
if k >= 2**m:
  print(-1)
elif m == 1 and k == 1:
  print(-1)
elif m == 1 and k == 0:
  print(1,1,0,0)
else:
  a = []
  for i in range(2**m):
    if i != k:
      a.append(i)
  b = list(reversed(a))
  ans = b + [k] + a + [k]
  #print(ans)
  print(' '.join((list(map(str,ans)))))

Measured memory_bytes: 29456
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			int n = sc.nextInt();
			A.add(n);
			B.add(0);
		}
		for(int i = 0; i < N; i ++) {
			B.set(A.get(i) - 1, i + 1);
		}
		for(int i = 0; i < N; i++) {
			System.out.print(B.get(i) + " ");
		}
		sc.close();
	}
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (mp.find(s) == mp.end())
        {
            mp[s] = 1;
        }
        else
        {
            mp[s] += 1;
        }
    }
    int max_val = -1;
    for (auto key : mp)
    {
        if (key.second > max_val)
        {
            max_val = key.second;
        }
    }
    vector<string> v;
    for (auto key : mp)
    {
        if (key.second == max_val)
        {
            v.push_back(key.first);
        }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 26996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


int main() {
    int H,W,K; cin>>H>>W>>K;
    vector<string> S(H);
    vector<int> cnt[310];
    for (int i = 0; i < H; ++i) {
        cin>>S[i];
        for (int j = 0; j < W; ++j) {
            if(S[i][j]=='#') cnt[i].push_back(j);
        }
    }
    int nosrow=-1,lastsrow=-1;
    vector<vector<int>> ans(H,vector<int>(W,0));
    int kcnt=1;
    for (int i = 0; i < H; ++i) {
        if(cnt[i].empty()){
            if(nosrow==-1) nosrow=i;
            continue;
        }
        int start=((nosrow==-1)?i:nosrow);
        nosrow=-1;
        lastsrow=i;

        if(cnt[i].size()==1){
            for (int j = start; j <= i; ++j) {
                for (int k = 0; k < W; ++k) {
                    ans[j][k]=kcnt;

                }
            }
            ++kcnt;
            continue;
        }

        for (int j = 0; j < cnt[i].size(); ++j) {
            if(j==0){
                for (int k = start; k <= i; ++k) {
                    for (int l = 0; l <=cnt[i][0]; ++l) {
                        ans[k][l]=kcnt;
                    }
                }
                ++kcnt;
            }else if(j!=cnt[i].size()-1){
                for (int k = start; k <= i; ++k) {
                    for (int l = cnt[i][j-1]+1; l <=cnt[i][j]; ++l) {
                        ans[k][l]=kcnt;
                    }
                }
                ++kcnt;
            }else{
                for (int k = start; k <= i; ++k) {
                    for (int l = cnt[i][j-1]+1; l <=W-1; ++l) {
                        ans[k][l]=kcnt;
                    }
                }
                ++kcnt;
            }
        }
    }

    for (int i = lastsrow+1; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            ans[i][j]=ans[lastsrow][j];
        }
    }


    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }


    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
const int MAXN = 100005;
ll mod=1000000007;


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  // cin>>t;
  while(t--){
      int n;
      cin>>n;
      vector<ll> a(n);
      map<ll,int> freq;
      ll sum = 0;
      rep(i,0,n-1){
        cin>>a[i];
        sum += a[i];
        freq[a[i]]++;
      }
      int q;
      cin>>q;
      while(q--){
        int b,c;
        cin>>b>>c;
        sum+= (c - b)*freq[b];
        freq[c] += freq[b];
        freq[b] = 0;
        cout<<sum<<nl;
      }
      cout<<nl;
  }
  return 0;
}


Measured memory_bytes: 10012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 100010;
int n;
ll mod;
vector<int> G[N];

ll dp[N];
void dfs(int x, int p){
    dp[x] = 1;
    for(int e:G[x])if(e!=p){
        dfs(e,x);
        (dp[x]*=dp[e]) %= mod;
    }
    (dp[x] += 1) %= mod;
}

ll ans[N];
void dfs2(int x, int p, ll par_dp){
    ans[x] = par_dp;

    vector<int> c;
    for(int e:G[x])if(e!=p){
        (ans[x] *= dp[e]) %= mod;
        c.pb(e);
    }
    sort(all(c));
    int C = c.size();

    vector<ll> dpv(C+2,1);
    rep(i,C) dpv[i+1] = dp[c[i]];

    vector<ll> pre(dpv), suf(dpv);
    rep(i,C+1) (pre[i+1] *= pre[i]) %= mod;
    for(int i=C+1; i>0; --i) (suf[i-1] *= suf[i]) %= mod;

    rep(i,C){
        ll t_par = par_dp;
        (t_par *= pre[i]) %= mod;
        (t_par *= suf[i+2]) %= mod;
        (t_par += 1) %= mod;
        dfs2(c[i], x, t_par);
    }
}

int main(){
    cin >>n >>mod;
    rep(i,n-1){
        int x,y;
        cin >>x >>y;
        --x;
        --y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dfs(0,-1);
    dfs2(0,-1,1);

    rep(i,n) cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 27776
use proconio::input;

struct Helper {
  r: usize,
  s: usize,
  p: usize
}

impl Helper {
  fn get_score(&self, c: char) -> usize {
    match c {
      'r' => self.r,
      's' => self.s,
      'p' => self.p,
      _ => panic!("should not come here"),
    }
  }
}

fn main() {
  input! {
    n: usize,
    k: usize,
    r: usize,
    s: usize,
    p: usize,
    t: String
  }
  
  let helper = Helper { r: p, s: r, p: s };  
  let t: Vec<char> = t.chars().collect();
  let mut count = 0;
  let never_match_val = 'a';
  for i in 0..k {
    let mut index = i;
    let mut s_count = 0;
    let mut last_val = never_match_val;
    while index < n {
      let c = t[index];
      let val = helper.get_score(c);
      if last_val != c {
        s_count += val;
        last_val = c;
      } else {
        last_val = never_match_val;
      }
      index += k;
    }

    count += s_count;
  }

  println!("{}", count);
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    ll ans=-1;
    for (int i = 0; i <= n; ++i) {
        int komi=i*1.08;
        if(komi==n){
            cout <<i<<endl;
            ans=i;
            break;
        }
    }
    if(ans<0)puts(":(");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string str;
  cin >> str;
  
  string prt="";
  for(int i=0; i<str.size(); i++){
    if (str.at(i)=='0') prt+='0';
    else if (str.at(i)=='1') prt+='1';
    else if (str.at(i)=='B' && !str.empty()) prt=prt.substr(0, prt.size()-1);
  }
  cout<<prt<<endl;
}

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

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

    int n, W; cin >> n >> W;
    long long w[n+1], v[n+1], dp[n+1][W+1];
    memset(dp, 0, sizeof dp);
    for (int i=1; i<=n; i++){
        cin >> w[i] >> v[i];
    }

    for (int i=1; i<=n; i++){
        for (int j=1; j<w[i]; j++) dp[i][j] = dp[i-1][j];
        for (int j=w[i]; j<=W; j++){
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 79232
import java.util.*;
import java.io.*;

public class Main {
    public static long time(long a, long b){
        return Math.min(Math.abs(a-0)+Math.abs(b-a), Math.abs(b-0)+Math.abs(a-b));
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] x = new long[N];
        for(int n=0;n<N;n++)x[n]=sc.nextLong();
        
        long ans = Long.MAX_VALUE;
        for(int n=0;n<N-K+1;n++){
        	ans = Math.min(ans,time(x[n],x[n+K-1]));
        }
        System.out.println(ans);
    }
}

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

using namespace std;

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

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int d[200][200];
int r[8];

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    rep(i, N) {
        rep(j, N) {
            d[i][j] = (i == j? 0 : INF);
        }
    }
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    sort(r, r + R);
    ll ans = LINF;
    do {
        ll tmp = 0;
        rep(i, R - 1) {
            tmp += d[r[i]][r[i + 1]];
        }
        ans = min(ans, tmp);
    }while(next_permutation(r, r + R));
    cout << ans << endl;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys

# log2(10 ** 5) ≒ 16.6 → 最終的にans[17][]が求まれば良い。
LOG = 18

def main():
    S = input()
    N = len(S)
    to = []
    for _ in range(LOG):
        l = [0] * N
        to.append(l)
    
    for i in range(N):
        to[0][i] = i + 1 if S[i] == "R" else i - 1
    
    for i in range(1, LOG):
        for j in range(N):
            to[i][j] = to[i - 1][to[i - 1][j]]

    ans = [0] * N
    for j in range(N):
        ans[to[LOG - 1][j]] += 1

    L = [str(i) for i in ans]
    print(" ".join(L))
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 28156
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    LL A;
    string B;
    //~ double B;
    cin >> A >> B;
    LL C = (B[0]-'0')*100;
    for (int i = 2; i < (int)B.size(); i++) {
        if (i == 2) C += (B[i]-'0')*10;
        if (i == 3) C += (B[i]-'0');
    }
    //~ LL C = (double)100*B;
    LL res = (A*C)/100;
    cout << res << "\n";
    
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int MOD;

int query(int a, int b, int c, int d)
{
	cout<<"? " << a << ' ' << b << ' ' << c << ' ' << d << '\n';
	fflush(stdout);
	int x; cin>>x;
	return x;
}

bool exist[51][51];

ll pow2[2501];

void out()
{
	ll sum = 0;
	for(int i = 0; i < 50; i++)
	{
		for(int j = 0; j < 50; j++)
		{
			if(exist[i][j])
			{
				sum = (sum + pow2[i*50+j])%MOD;
			}
		}
	}
	cout<<"! "<<sum<<'\n';
	fflush(stdout);
}

int main()
{
	int h, w, n;
	cin>>h>>w>>n>>MOD;
	pow2[0] = 1;
	for(int i = 1; i <= 2500; i++)
	{
		pow2[i] = (pow2[i-1]*2LL)%MOD;
	}
	for(int i = 0; i < 50; i+=2)
	{
		for(int j = 0; j < 50; j+=2)
		{
			int cnt = query(i,j,i+1,j+1);
			if(cnt==4)
			{
				for(int k = i; k <= i + 1; k++)
				{
					for(int l = i; l <= i + 1; l++)
					{
						exist[k][l] = true;
					}
				}
			}
			else if(cnt>0)
			{
				exist[i][j] = query(i,j,i,j);
				exist[i][j+1]=query(i,j+1,i,j+1);
				exist[i+1][j]=query(i+1,j,i+1,j);
				exist[i+1][j+1] = cnt-exist[i][j]-exist[i][j+1]-exist[i+1][j];
			}
		}
	}
	out();
}


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

int main() {
  ll n, k;
  cin >> n >> k;

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

  vector<ll> b(n);
  rep(i, n) b[i] = -1;
  ll cnt = 0;
  ll next = 0;
  ll nokori = 0;
  rep(i, k) {
    if (b[next] >= 0) {
      // printf("k-b: %d / %d\n", k - b[next], cnt - b[next]);
      nokori = (k - b[next]) % (cnt - b[next]);
      break;
    } else {
      b[next] = cnt++;
    }
    next = a[next];
    // k--;
  }

  rep(i, nokori) next = a[next];
  // rep(i, n) printf("%2d", b[i]);
  // cout << endl;
  cout << next + 1 << endl;
  // cout << a[next] + 1 << endl;
  // printf("%d\n", k % (cnt - next));
  return 0;
}

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

using namespace std;

#define MOD 1000000007


int main() {
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> a(M);
  for (int64_t i = 0; i < M; i++)
    cin >> a[i];

  sort(a.begin(), a.end());

  vector<int64_t> x(N+3);
  x[0] = 0;
  x[1] = 1;
  x[2] = 1;
  for (int64_t i = 3; i < N+3; i++) {
    x[i] = (x[i-1] + x[i-2]) % MOD;
  }

  if (M == 0) {
    cout << x[N+1] << endl;
    return 0;
  }
  for (int64_t i = 1; i < M; i++) {
    if (a[i] == a[i-1] + 1) {
      cout << 0 << endl;
      return 0;
    }
  }

  int64_t ans = 1;
  for (int64_t i = 0; i < M; i++) {
    if (i == 0) {
      ans = (ans % MOD) * (x[a[i]] % MOD);
    } else {
      ans = (ans % MOD) * (x[a[i] - a[i-1] - 1] % MOD);
    }
  }
  ans = (ans % MOD) * (x[N - a[M-1]] % MOD);
  cout << ans % MOD << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

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

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

		int d = a / b;
		int r = a % b;
		double f = (double)a / (double)b;

		System.out.println(d + " " + r + " " + String.format("%.5f", f));
	}
}


Measured memory_bytes: 26520
from collections import deque

s = input()
q = int(input())

inv_cnt = 0


li = []
r = []

for i in range(q):
    d = [x for x in input().split()]
    if d[0] == '1':
        inv_cnt += 1
        inv_cnt %= 2
    else:
        if inv_cnt == 0:
            if d[1] == '1':
                li.append(d[2])
            else:
                r.append(d[2])
        else:
            if d[1] == '1':
                r.append(d[2])
            else:
                li.append(d[2])

if inv_cnt == 0:
    print(''.join(li[::-1]) + s + ''.join(r))
else:
    print(''.join(r[::-1]) + s[::-1] + ''.join(li))


Measured memory_bytes: 71768
import java.util.Scanner;

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

        StringBuilder sb = new StringBuilder();
        int sc = 0;
        int tc = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'S') {
                sc++;
            } else {
                if (sc == 0) {
                    sb.append('T');
                } else {
                    sc--;
                }

            }
        }
        for (int i = 0; i < sc; i++) {
            sb.append('S');
        }
        System.out.println(sb.length());
    }
}

Measured memory_bytes: 16436
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  const int N = 365, K = 26;
  vector<int> c(K);
  vector<vector<int>> s(N, vector<int>(K));
  cin >> c[0];
  for (int &x : c) cin >> x;
  for (auto &v : s) for (int &x : v) cin >> x;
  vector<int> best(N);
  int bs = -MOD;
  for (int f = 0; f < 26; ++f) {
    vector<int> ans(N);
    vector<int> last(K, -1);
    int score = (int) 1e6;
    for (int i = 0; i < N; ++i) {
      int dec = 0;
      for (int j = 0; j < K; ++j) {
        dec += c[j] * (i - last[j]);
      }
      int mx = -MOD, t = -1;
      if (i < 1) {
        t = f;
      } else {
        for (int j = 0; j < K; ++j) {
          if (uax(mx, s[i][j] - dec + c[j] * (i - last[j]))) t = j;
        }
      }
      score += s[i][t] - dec + c[t] * (i - last[t]);
      last[t] = i;
      ans[i] = t;
    }
    if (uax(bs, score)) swap(ans, best);
  }
  for (int &x : best) cout << 1 + x << '\n';
}


Measured memory_bytes: 3712
# ABC073D - joisino's travel
from heapq import heapify, heappop, heappush
from itertools import permutations


def dijkstra(G: "Array[Array[int]]", size: int, start: int) -> list:
    dist = [float("inf")] * size
    queue = [(start, 0)]
    heapify(queue)
    while queue:
        v, cost = heappop(queue)
        if cost > dist[v]:
            continue
        dist[v] = cost
        for u, next_cost in G[v]:
            if cost + next_cost < dist[u]:
                heappush(queue, (u, cost + next_cost))
    return dist


def main():
    global G, N
    N, M, R, *RABC = map(int, open(0).read().split())
    visit, ABC = RABC[:R], RABC[R:]
    G = [[] for _ in range(N + 1)]
    for v, u, c in zip(*[iter(ABC)] * 3):
        G[v].append((u, c)), G[u].append((v, c))
    dist = {v: dijkstra(G, N + 1, v) for v in visit}
    ans = float("inf")
    for perm in permutations(visit):
        cur = sum(dist[v][u] for v, u in zip(perm, perm[1:]))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 13292
<?php

fscanf(STDIN, "%d", $n);

$sum = 0;
for ($i = 0; $i < $n; ++$i) {
    $inputs = explode(' ', trim(fgets(STDIN)));

    switch ($inputs[1]) {
    case 'JPY':
        $sum += $inputs[0];
        break;
    case 'BTC':
        $sum += $inputs[0] * 380000;
        break;
    }
}
echo $sum;


Measured memory_bytes: 4728
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> Pii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const LL mod = 1000000007;
const int N = 1e5 + 5;
const double Pi = acos(-1.0);
const int maxn = 1e5 + 5;
char s[100005];
int L[100005],R[100005];
int main() {
#ifdef local
    freopen("in", "r", stdin);
#endif
    scanf("%s",s);
    int n = strlen(s);
    bool win = 0;
    if(s[0]==s[n-1]){
        win = (n%2==0);
    }
    else win = (n%2!=0);
//    for(int i = 0; i < n ;i++){
//        L[i] = i - 1;
//        R[i] = i+1;
//    }
//    L[0] = -1;
//    R[n-1] = -1;
//    for(int i = 1; i < n ; i++){
//        if(s[i]!='&'){
//            int l = L[i];
//            int r = R[i];
//            if(l >= 0 && r < n && r >= l &&l < n&&s[l]!=s[r]){
//                s[i] = '&';
//                R[i-1] = R[i];
//                L[i+1] = L[i-1];
//                win^=1;
//                i = L[i];
//            }
//        }
//    }
    if(win)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << ' ' + '=' + ' ' << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int a,b;
    cin>>a>>b;
    b*=2;
    if(a<b){
        cout<<0<<endl;
    }
    else{
        cout<<a-b<<endl;
    }
    
}

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

int x[4];
int y[4];

int main(void){
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	int s, t;
	s = x[1]-x[0];
	t = y[1]-y[0];
	x[2] = x[1]-t;
	y[2] = y[1]+s;
	x[3] = x[2]-s;
	y[3] = y[2]-t;
	cout << x[2] << " " <<  y[2] << " " << x[3] << " " << y[3] << " " <<  endl;
	return 0;
}


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

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

  if((N[0]==N[1] && N[1]==N[2]) || (N[1]==N[2] && N[2]==N[3])) {
    cout << "Yes" << endl;
  }else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	
	h=S/3600;
	m=S%3600/60;
	s=S%3600%60;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    if(k > ceil(n / 2.0))
    {
        cout << "NO\n";
    }
    else
    {
        cout << "YES\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	  public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int m = sc.nextInt();
	    int[] ac = new int[n];
	    int[] wa = new int[n];
	    
	    for (int i = 0; i < m; i++) {
			int temp = sc.nextInt() - 1;
			String s = sc.next();
			// まだACが出ていないなら
			if (ac[temp] == 0) {
				if (s.equals("AC")) {
					ac[temp]++;
				} else {
					wa[temp]++;
				}
			}
		}
	    
	    int ans1 = 0;
	    int ans2 = 0;
	    for (int i = 0; i < n; i++) {
	    	// ACが出ている問題のみカウント
			if (ac[i] == 1) {
				ans1 += ac[i];
				ans2 += wa[i];
			}
		}
	    
	    System.out.println(ans1 + " " + ans2);
	  
	  }
	}

Measured memory_bytes: 63604
k,t=map(int,input().split())
a=list(map(int,input().split()))
for i in range(t):
    a[i]=[a[i],i]
prev=-1
if t>1:
    for i in range(k):
        a.sort(reverse=True)
        if a[0][1]==prev:
            if a[1][0]==0:
                break
            else:
                a[1][0]-=1
                prev=a[1][1]
        else:
            a[0][0]-=1
            prev=a[0][1]
    print(a[0][0])
else:
    print(a[0][0]-1)

Measured memory_bytes: 9136
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from statistics import median

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

l1.sort()
l2.sort()

m1=median(l1)
m2=median(l2)

if n%2==1:
  ans=m2-m1
else:
  ans=(m2-m1)*2

print(int(ans+1))

Measured memory_bytes: 28792
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int A,B,C,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};
vector<char > v;

void solve(){
	for (int i = 0; i < S.size(); ++i)
	{
		if(find(v.begin(), v.end(),S[i]) == v.end()){
			v.push_back(S[i]);
		}else{
			ans = 0;
			break;
		}
		ans = 1;
	}
}

void debug(){

}

void answer(){
	if(ans) 
		cout << "yes\n";
	else 
		cout << "no\n";
}

int main(){
	cin >> S;
	
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int k,s,count=0;
  scanf("%d%d",&k,&s);
  
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int l=s-i-j;
      if(l>=0&&l<=k){
        count++;
      }
    }
  }
  
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= 9; i++) {
		if (N % i == 0 && N / i <= 9) {
			cout << "Yes" << endl;
			exit(0);
		}
	}
	cout << "No" << endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll n, k; cin >> n >> k;
    V<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    for(int ki = 0; ki < k; ki++){
        V<ll> b(n + 1);
        for(int i = 0; i < n; i++){
            ll l = max(0LL, i - a[i]);
            ll r = min(i + a[i] + 1, n);
            b[l]++;
            b[r]--;
        }
        for(int i = 0; i < n; i++) b[i + 1] += b[i];
        b.pop_back();
        if(a == b) break;
        a = b;
    }

    for(int i = 0; i < n; i++){
        if(i != n - 1) cout << a[i] << " ";
        else cout << a[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N,M;cin>>N>>M;
    if(N>=M/2){
        cout<<M/2<<endl;
    }
    else{
        M-=2*N;
        long long ans=N;
        ans+=M/4;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define Max(a,b) a=max(a,b);
typedef long long ll;

using namespace std;
#define N 200010
ll n,m,a[N],cnt[N],sum[N];
int main(){
    //ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    lol(i,N)cnt[i]=0,sum[i]=0;
    lol(i,n){
	cin>>a[i];
	if(a[i]<N)cnt[a[i]]++;
    }
    lol(i,N){
	for(ll j=i-cnt[i]+1;j<=i;j++)sum[j]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)ans+=sum[i]==0;
    lol(i,m){
	ll x,y;cin>>x>>y; x--;
	if(a[x]<=n){
	    ll p=a[x]-cnt[a[x]]+1;
	    if(p>=1){
		sum[p]--;
		if(sum[p]==0)ans++;
	    }
	    cnt[a[x]]--;
	}
	a[x]=y;
	if(a[x]<=n){
	    ll p=a[x]-cnt[a[x]];
	    if(p>=1){
		if(sum[p]==0)ans--;
		sum[p]++;
	    }
	    cnt[a[x]]++;
	}
	cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6144
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); //N角形
		List<Integer> L = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			L.add(sc.nextInt());
		}
		Collections.sort(L, Comparator.reverseOrder());
		int index = 0;
		int max = L.get(0);
		int total = 0;
		for(int i = 1; i < L.size(); i++) {
			total += L.get(i);
		}
		if(max < total) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string n;
    cin >> n;

    // 処理
    if (n[0] == '1') {
        n[0] = '9';
    } else if (n[0] == '9') {
        n[0] = '1';
    }
    if (n[1] == '1') {
        n[1] = '9';
    } else if (n[1] == '9') {
        n[1] = '1';
    }
    if (n[2] == '1') {
        n[2] = '9';
    } else if (n[2] == '9') {
        n[2] = '1';
    }
    // 出力
    cout << stoi(n) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;

int main(){
  ll n,m=0;cin>>n;
  vll a(n),b(n,0);
  rep(i,0,n){cin>>a[i];}
  for(ll i=n-1;i>=0;i--){
    ll tmp=0;
    for(ll j=2*i+1;j<n;j+=i+1){
      tmp+=b[j];
    }
    if(tmp%2!=a[i]){b[i]=1;m++;}
  }
  cout<<m<<endl;
  rep(i,0,n){
    if(b[i]==1){cout<<i+1<<" ";}
  }
  cout<<endl;
}



Measured memory_bytes: 3968
#include <stdio.h>
#include <string.h>
 int main(void){
    int N,i;
    scanf("%d",&N);
    
    char s[N],a[N/2],b[N/2];
    
    if(N%2==0){
    for(i=0;i<N;i++){
      scanf("%s",&s[i]);
     }
      for(i=0;i<N;i++){
      if(i<N/2){
        a[i]=s[i];
      }
      else
        b[i-N/2]=s[i];
      }
      
     // printf("%s %s %s\n",s,a,b); aの値がおかしくなる
      if(strncmp(a,b,N/2)==0) 
        printf("Yes");
      else
        puts("No");
    }
     else    
    printf("No");
} 


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    int mx = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> h[i];
        mx = max(mx,h[i]);
    }

    for(int i = 1; i <= mx; i++){
        int cnt = 0;
        bool flag = false;
        for(int j = 0; j < n; j++){
            if(h[j] >= i && !flag){
                cnt++;
                flag = true;
            }
            else if(h[j] >= i && flag) continue;
            else flag = false;
        }
        ans += cnt;
    }

    cout << ans << endl;

}


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

int main(){
	int n;
	cin >> n;
	vector<double> a(n);
	rep(i, n){
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
//	reverse(a.begin(), a.end());
	rep(i, n-1){
		a.at(i+1) = (a.at(i) + a.at(i+1)) / 2;
	}
	cout << fixed << setprecision(10) << a.at(n-1) << endl;
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> dp(n, vector<int>(3));
    for(int &i:dp.at(0))
    {
        cin >> i;
    }
    for (int i = 1; i < n;++i)
    {
        for(int &j:dp.at(i))
        {
            cin >> j;
        }
        dp.at(i).at(0) += max(dp.at(i - 1).at(1), dp.at(i - 1).at(2));
        dp.at(i).at(1) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(2));
        dp.at(i).at(2) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(1));
    }
    cout << *max_element(dp.back().begin(), dp.back().end());
    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<iomanip>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
#include <functional>
#include <cassert>
typedef long long int ll;
using namespace std;

int main(){
	int M,N,k;
	ll count=0;
	vector<int>A;
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>k;
		A.push_back(k);
		count=count+k;
	}
	sort(A.begin(),A.end());
	if((double)A[N-M]/(double)count>=(double)1/(double)(4*M)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {

  public static void main(String[] args)throws IOException
  {
      InputStreamReader read =new InputStreamReader(System.in);
      BufferedReader b=new BufferedReader(read);
      
      String st=b.readLine();
      String[] a=st.split(" ");
      int n=Integer.parseInt(a[0]);
      int m=Integer.parseInt(a[1]);
      int w=0;
      if(n>1 && m>1)
      w= (n*(n-1) + m*(m-1))/2 ;
      else if(n>1 && m<2)
      w=(n*(n-1))/2;
      else if(n<2 && m<2)
      w=0;
      else if(n<2 && m>1)
      w=(m*(m-1))/2;
      
      System.out.println(w);
  }
}
      
      

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


int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ll max_a = 0;
    REP(i, n){
        ll ai, bi;
        cin >> ai >> bi;
        if(ai > max_a){
            ans = ai + bi;
            max_a = ai;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

int main() {
    int n, a;
    cin >> n >> a;
    if(n%500 <= a)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256