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

using ll = long long;

template<typename Monoid>
class segment_tree {
    using T = typename Monoid::type;

public:
    segment_tree(std::vector<T> const& init)
        : sz(init.size()), n(expand(init.size()))
    {
        dat.assign(n*2, Monoid::id());
        std::copy(begin(init), end(init), begin(dat) + n);
        for(int i = n - 1; i >= 0; --i) {
            dat[i] = Monoid::op(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    segment_tree(int const n_, T const& init = Monoid::id())
        : segment_tree(std::vector<T>(n_, init))
    {}

    void update(int p, T val) {
        assert(0 <= p && p < sz);
        dat[p += n] = val;
        while(p /= 2) {
            dat[p] = Monoid::op(dat[p * 2], dat[p * 2 + 1]);
        }
    }

    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= sz);
        l += n, r += n;
        T res1 = Monoid::id(), res2 = Monoid::id();
        while(l != r) {
            if(l & 1) res1 = Monoid::op(res1, dat[l++]);
            if(r & 1) res2 = Monoid::op(dat[--r], res2);
            l /= 2, r /= 2;
        }
        return Monoid::op(res1, res2);
    }

private:
    int expand(int n_) const {
        assert(n_ >= 1);
        return n_ == 1 ? n_ : expand((n_ + 1) / 2) * 2;
    }

private:
    const int sz, n;
    std::vector<T> dat;
};

struct RMQ {
    using type = ll;
    static type id() {
        return std::numeric_limits<type>::min() / 2;
    }
    static type op(type const& l, type const& r) {
        return std::max(l, r);
    }
};

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

    const int max_h = 1 << 18;
    segment_tree<RMQ> seg(max_h);
    seg.update(0, 0);
    for(int i = 0; i < n; ++i) {
        seg.update(h[i], seg.query(0, h[i]) + a[i]);
    }
    cout << seg.query(0, max_h) << endl;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 200010;

int v[N], pmin[N], pmax[N];
int nxtInv[N];

int main()
{
	ios_base::sync_with_stdio(false);
	
	int n, k;
	deque<int> deq;

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

	nxtInv[n] = n;
	for(int i = n - 1; i >= 1; --i) nxtInv[i] = (v[i] > v[i + 1] ? i : nxtInv[i + 1]);

	for(int i = 1; i < k; ++i) {
		while(!deq.empty() && v[deq.back()] > v[i]) deq.pop_back();
		deq.push_back(i);
	}

	for(int i = k; i <= n; ++i) {
		while(!deq.empty() && v[deq.back()] > v[i]) deq.pop_back();
		deq.push_back(i);

		pmin[i - k + 1] = deq.front();
		if(deq.front() == i - k + 1) deq.pop_front();
	}

	while(!deq.empty()) deq.pop_back();

	for(int i = 1; i < k; ++i) {
		while(!deq.empty() && v[deq.back()] < v[i]) deq.pop_back();
		deq.push_back(i);
	}

	for(int i = k; i <= n; ++i) {
		while(!deq.empty() && v[deq.back()] < v[i]) deq.pop_back();
		deq.push_back(i);

		pmax[i - k + 1] = deq.front();
		if(deq.front() == i - k + 1) deq.pop_front();
	}

	int ans = 1, nrid = 0;

	if(nxtInv[1] >= k) ++nrid;
	for(int i = 1; i <= n - k; ++i) {
		int pm = (v[pmin[i]] < v[i + k] ? pmin[i] : i + k);
		int pM = (v[pmax[i]] > v[i + k] ? pmax[i] : i + k);
		if(pm != i || pM != i + k) {
			++ans;
			if(nxtInv[i + 1] >= i + k) ++nrid;
		}
	}

	cout << ans - (max(0, nrid - 1)) << '\n';

	return 0;
}


Measured memory_bytes: 3456
use std::collections::HashMap;
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    stdin.read_until(b' ', &mut Vec::new()).unwrap();
    let mut k = String::new();
    stdin.read_line(&mut k).unwrap();
    let k: usize = k.trim_right().parse().unwrap();

    let mut amt: Vec<u32> = stdin.split(b' ')
        .map(|r| {
            String::from_utf8(r.unwrap()).unwrap()
                .trim_right()
                .parse::<u32>().unwrap()
        })
        .fold(HashMap::with_capacity(200_000), |mut map, a| {
            *map.entry(a).or_insert(0) += 1;
            map
        })
        .values()
        .cloned()
        .collect();

    amt.sort();
    println!("{}", amt.iter().take(amt.len().saturating_sub(k)).sum::<u32>());
}

Measured memory_bytes: 8444
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0 and max(As) > 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

Measured memory_bytes: 60784
#include <iostream>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

typedef vector<string> vs;
typedef vector<int> vi;

#define rep(i,b) loop(i,0,b)
#define loop(i,a,b) for(int i=(a); i<int(b); i++)

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

int h,w;
inline bool in(int x, int y){
    return 0<=x && 0<=y && x<w && y<h;
}

bool solve(vs const& g1, vs const& g2){
    int sx1, sy1, sx2, sy2;
    rep(i,h)rep(j,w){
        if(g1[i][j]=='L'){
            sx1=j;sy1=i;
        }
        if(g2[i][j]=='R'){
            sx2=j;sy2=i;
        }
    }
    queue<vi> q;
    static bool vis[64][64][64][64];
    memset(vis,0,sizeof(vis));
    q.push(vi{sx1,sy1,sx2,sy2});

    while(q.size()){
        vi s=q.front();q.pop();
        int x1=s[0],y1=s[1],x2=s[2],y2=s[3];
        if(vis[x1][y1][x2][y2])continue;
        vis[x1][y1][x2][y2]=true;
        if(g1[y1][x1]=='%' && g2[y2][x2]=='%') return true;
        if((g1[y1][x1]=='%')^(g2[y2][x2]=='%')) continue;

        rep(d,4){
            int nx1=x1+dx[d],ny1=y1+dy[d];
            int nx2,ny2;
            if(d&1){
                nx2=x2+dx[d],ny2=y2+dy[d];
            }else{
                nx2=x2-dx[d],ny2=y2-dy[d];
            }
            if(!in(nx1,ny1) || g1[ny1][nx1]=='#')nx1=x1,ny1=y1;
            if(!in(nx2,ny2) || g2[ny2][nx2]=='#')nx2=x2,ny2=y2;
            q.push(vi{nx1,ny1,nx2,ny2});
        }
    }
    return false;    
}

int main(){
    while(cin>>w>>h && w|h){
        vs g1(h), g2(h);
        rep(i,h) cin>>g1[i]>>g2[i];
        vs ans{"No","Yes"};
        cout << ans[solve(g1,g2)] << endl;
    }
}

Measured memory_bytes: 29860
s=input()
t=input()

an=len(t)
wk=0
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            wk+=1
        else:
            continue
    an=min(an,wk)
    wk=0
print(an)

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  vector<bool> ok(1000, false);
  for (int i = 0; i <= 9; i++){
    int num1 = 0;
    while (num1 < N){
      if (S.at(num1) - '0' == i){
        break;
      }
      num1++;
    }
    if (num1 == N){
      continue;
    }
    
    for (int j = 0; j <= 9; j++){
      int num2 = num1 + 1;
      while (num2 < N){
        if (S.at(num2) - '0' == j){
          break;
        }
        num2++;
      }
      if (num2 == N){
        continue;
      }
      
      for (int k = num2 + 1; k < N; k++){
        ok.at(i * 100 + j * 10 + (S.at(k) - '0')) = true;
      }
      
    }
  }
  
  int ans = 0;
  for (int i = 0; i < 1000; i++){
    if (ok.at(i) == true){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.first < b.first )
        return true;
    if( a.first==b.first && a.S != b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 2e5+1;

int stoint(string s)
{
     int n = s.size();
     int num = 0;
     f(i,0,n){
          num = num*10+ (int)(s[i]-'0');

     }
     return num;
}


void solve()
{      
     string s ; cin >> s;

     ll n = s.size();

     ll dp[n+1][2];

     dp[0][0]=0, dp[0][1]=0;

     dp[1][0]=1, dp[1][1]=0;

     for(ll i = 2; i <= n; i++ ){

          if(s[i-1]==s[i-2]){
               dp[i][0] = dp[i-1][1] + 1;
               dp[i][1] = dp[i-2][0] + 1;
          }
          else{
               dp[i][0] = dp[i-1][0] + 1;
               dp[i][1] = dp[i-2][0] + 1;
          }

     }

     cout << max(dp[n][0], dp[n][1]) << endl;
}    

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 6904
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

#各子の色を決めていく。
color = [-1]*(N+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1

ans = []
for a,b in AB:
    if parent[a] == b: #子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])

print(max(ans))
for i in ans:
    print(i)
        


Measured memory_bytes: 79580
import sys;
input = sys.stdin.readline

def doit():
  n = int(input())
  if n >= 24:
    return 0

  d = [int(x) for x in input().split()]
  if n == 1:
    return d[0]
  
  res = [0] * 13
  for x in d:
    if x == 0:
      return 0
    res[x] += 1;
    if x == 12:
      if res[x] == 2:
        return 0
    if res[x] == 3:
      return 0
  
  #ban = [False] * 24
  mm = 12
  flip = False
  prev = [0, 24]
  for i, x in enumerate(res):
    diff = 12
    if x == 2:
      #ban[i] = ban[24 - i] = True
      diff = i - prev[0]
      prev[0] = i
      prev[1] = 24 - i
      #print("x2", i, diff, file=sys.stderr)
      flip = not flip
    if x == 1:
      if flip:
        #ban[i] = True
        diff = i - prev[0]
        prev[0] = i
      else:
        #ban[24 - i] = True
        diff = prev[1] - (24 - i)
        prev[1] = 24 - i
      flip = not flip
      #print("x1", i, diff, file=sys.stderr)
    if diff < mm:
      mm = diff
      #print(mm, file=sys.stderr)
  #last = abs(prev[1] - prev[0])
  last = prev[1] - prev[0]
  #print("last", prev[0], prev[1], file=sys.stderr)
  if last < mm:
    return last
  return mm


print(doit())


Measured memory_bytes: 3064
import sys

N = int(input())
pyramid = []

for _ in range(N):
    pyramid.append(list(map(int,input().split())))

# 総当たり
for cx in range(101):
    for cy in range(101):
        H = []
        for k in range(N):
            if pyramid[k][2] != 0:
                H.append(abs(pyramid[k][0]-cx) + abs(pyramid[k][1]-cy) + pyramid[k][2])
        if len(set(H)) == 1:
            for k in range(N):
                if pyramid[k][2] != max(H[0]-abs(pyramid[k][0]-cx)-abs(pyramid[k][1]-cy),0):
                    break
            if k == N-1:
                print(cx,cy,H[0])
                sys.exit()

Measured memory_bytes: 3064
#include <iostream>

int main()
{
    int monster_hp = 0;
    int sal_atk = 0;
    std::cin >> monster_hp; 
    std::cin >> sal_atk;
    if(monster_hp % sal_atk != 0){
        std::cout << (monster_hp / sal_atk) + 1 << std::endl;
    }else{
        std::cout << (monster_hp / sal_atk) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

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

	double d_h = 30 * h;
	d_h += 0.5 * m;
	double d_m = 6 * m;

	double d;
	if (d_h == 0.0)
		d_h = 360;
	if (d_m == 0.0)
		d_m = 360;
	if (d_h > d_m)
		d = d_h - d_m;
	else
		d = d_m - d_h;

	double rad = d * (M_PI/180);
	printf("%.10f\n", sqrt((a*a + b*b) - (2 * a * b * cos(rad))));
}



Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std; 
int main(){
    int s; cin>> s;
    int a = s / 100;
    int b = s - a * 100;
    int ja=0, jb=0;
    if(b >= 13 || b <= 0) jb=1;
 
    if(a >= 13 || a<=0) ja=1;
 
    if(jb == 0 && ja == 0) cout<< "AMBIGUOUS" << endl;
    else if(jb == 1 && ja == 0) cout<< "MMYY" << endl;
    else if(jb == 0 && ja == 1) cout<< "YYMM" << endl;
    else cout<< "NA" << endl;
}

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

#define INF 2147483647
#define ASTART (1<<17)
int a[1<<18][2];
int ti=1;

int find(int i){
  int nv=INF,t=0;
  i+=ASTART-1;
  nv=a[i][0];
  t=a[i][1];
  while (i>0){
    i=(i-1)/2;
    if (t<a[i][1])nv=a[i][0],t=a[i][1];
    //cout << i << " = " << a[i][0]<< " = " << a[i][1]<< endl;
  }
  return nv;
}
void update(int s,int t,int x,int k,int l,int r){
  if (l>=s&&r<=t){
    a[k][0]=x;
    a[k][1]=ti;
    return;
  }
  if (r<=s||l>=t)return;
  int m=(l+r)/2;
  update(s,t,x,k*2+1,l,m);
  update(s,t,x,k*2+2,m,r);
}
int main(){
  int n,q,com,s,t,x;
  for (int i=0;i<(1<<18);i++)a[i][0]=INF,a[i][1]=0;
  cin >> n>>q;

  for (int i=0;i<q;i++){
    cin >> com;
    if (com==0) {
      cin >> s >> t >> x;
      update(s,t+1,x,0,0,ASTART);
      ti++;
    }else {
      cin >> s;
      cout << find(s)<< endl;
    }
    //for (int i=0;i<5;i++)cout << a[i] << endl;
    //cout << a[ASTART];
  }

  return 0;
}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[100101];
int l[100115];
int j[101012];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[100101];
priority_queue<int,vector<int>,greater<int> > q;

//stack<int> s;
set<int> s;
map<int,int> p[100101];
vector<int> v[100101];

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

int f(int n)
{
  if(j[n]==n) return n;
  return j[n]=f(j[n]);
}

void g(int n,int m)
{
  l[n]=1;
  for(int h=0;h<v[n].size();h++)
  if(v[n][h]!=m)
  {
    g(v[n][h],n);
    if(o[v[n][h]])
    {
      o[n]^=1;
      q.push(p[n][v[n][h]]);
    }
  }
}

int main()
{
  scanf("%d %d",&a,&b);
  iota(j+1,j+a+2,1);
  for(int t=1;t<=a;t++)
  {
    scanf("%d %d",&n,&m);
    u[t]={n,m};
  }
  
  sort(u+1,u+a+1,as);
  for(int t=1;t<=a+1;t++)
    o[t]=u[t-1].y^u[t].y;
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    //printf("!!!%d %d\n",n,m);
    int c=1,d=a;
    for(;c<d;)
    {
      int h=(c+d)/2;
      if(n<=u[h].x) d=h;
      else c=h+1;
      //printf("%d %d\n",c,d);
    }
    //puts("#");
    n=c;
    c=1,d=a;
    for(;c<d;)
    {
      int h=(c+d)/2+1;
      if(m>=u[h].x) c=h;
      else d=h-1;
    }
    m=c;
    m++;
    //printf("@@%d %d\n",n,m);
    p[n][m]=p[m][n]=t;
    if(n<m&&f(n)!=f(m))
    {
      j[f(n)]=f(m);
      v[n].push_back(m);
      v[m].push_back(n);
    }
  }
  for(int t=1;t<=a+1;t++)
  if(!l[t])
  {
    g(t,0);
    if(o[t])
    {
      puts("-1");
      return 0;
    }
  }
  
  printf("%d\n",q.size());
  for(;q.size();q.pop())
    printf("%d ",q.top());
  
}



Measured memory_bytes: 31868
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n;
  string s;
  cin >> n >> s;
  int color[3][5005] = {};
  for(int i = n - 1;i >= 0;i --){
    if(s[i] == 'R'){
      color[0][i] ++;
    } else if(s[i] == 'G'){
      color[1][i] ++;
    } else {
      color[2][i] ++;
    }
    color[0][i] += color[0][i + 1];
    color[1][i] += color[1][i + 1];
    color[2][i] += color[2][i + 1];
  }
  lol ans = 0;
  rep(i, n){
    for(int j = i + 1;j < n;j ++){
      if(s[i] == 'R'){
	if(s[j] == 'G'){
	  ans += color[2][j + 1];
	  if(s[j + abs(j, i)] == 'B'){
	    ans --;
	  }
	} else if(s[j] == 'B'){
	  ans += color[1][j + 1];
	  if(s[j + abs(j, i)] == 'G'){
	    ans --;
	  }
	}
      } else if(s[i] == 'G'){
	if(s[j] == 'R'){
	  ans += color[2][j + 1];
	  if(s[j + abs(j, i)] == 'B'){
	    ans --;
	  }
	} else if(s[j] == 'B'){
	  ans += color[0][j + 1];
	  if(s[j + abs(j, i)] == 'R'){
	    ans --;
	  }
	}
      } else {
	if(s[j] == 'G'){
	  ans += color[0][j + 1];
	  if(s[j + abs(j, i)] == 'R'){
	    ans --;
	  }
	} else if(s[j] == 'R'){
	  ans += color[1][j + 1];
	  if(s[j + abs(j, i)] == 'G'){
	    ans --;
	  }
	}
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
 int n;cin>>n;int sum=1;
 vector<string>a(n);
 rep(i,n)cin>>a[i];
 sort(a.begin(),a.end());
 for(int i=0;i<n-1;i++){
     if(a[i]!=a[i+1])sum++;
 }  
 cout<<sum<<endl;
}

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

int main(){
  string S;
  int i,cnt=0;
  cin >> S;

  for(i=0;i<S.size()/2;i++)
  if(S.at(i)!=S.at(S.size()-1-i))
  cnt++;

  cout << cnt << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for(i=0; i<N-1; i++) {
    mini = i;
    for(j=i; j<N; j++) {
      if(A[j] < A[mini]) mini = j;
    }

  	t = A[i];
  	A[i] = A[mini];
  	A[mini] = t;

  	if(i != mini) sw++;
  }
  return sw;
}

int main(void) {
  int A[100], N, i, sw;
  scanf("%d", &N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    int n;
    cin>>n;
    Vi h(n);
    REP(i,0,n) cin>>h[i];
    int ans=0,maxh=0;
    REP(i,0,n){
        if(h[i]>=maxh) ans++;
        chmax(maxh,h[i]);
    }
    
    cout<<ans<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	priority_queue<int> pq;
	for(int i = 0; i < n;i++){
		int cur; 
		cin >> cur;
		pq.push(cur);
	}

	ll sol = 0;
	int cnt = 0;
	cnt = 2;
	sol += pq.top();
	pq.pop();
	int actual = 0;
	while(cnt < n){
		if(actual == 1){
			cnt++;
			sol += pq.top();
			pq.pop();
			actual = 0;
			continue;
		}
		actual++;
		cnt++;
		sol += pq.top();
	}
	cout << sol << '\n';
}


Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

string S, T;

int main() {
	cin >> S >> T;
	int N = S.size();
	int M = T.size();
	
	string ans = "~";
	REP(i, N) {
		bool ok = true;
		REP(j, M) {
			if (S[i + j] == '?') continue;
			if (S[i + j] == T[j]) continue;
			ok = false;
		}
		
		if (ok) {
			string cur = S.substr(0, i);
			cur += T;
			cur += S.substr(i + M);
			REP(j, cur.size()) if (cur[j] == '?') cur[j] = 'a';
			chmin(ans, cur);
		}
	}
	
	if (ans == "~") puts("UNRESTORABLE");
	else cout << ans << endl;
	
	
	
	return 0;
}


Measured memory_bytes: 256
#n=int(input())
n,m=map(int,input().split())
#t=int(input())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

dp=[0]*(n+1)
mod=10**9+7
broken={i:False for i in range(1,n+1)}
for i in range(m):
    a=int(input())
    broken[a]=True
if broken[1]:
    dp[1]=0
else:
    dp[1]=1
dp[0]=1
for i in range(2,n+1):
    if not broken[i]:
        dp[i]=(dp[i-1]+dp[i-2])%mod

print(dp[n])


Measured memory_bytes: 21256
import java.util.*;

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

      int a = scan.nextInt();
      int b = scan.nextInt();
      int X = scan.nextInt();

      int[] arr = new int[a + 1];
      int   u, count = 0;
      int   abs, sum = 0;
      for(int i = 0; i < a + 1; i++){
          arr[i] = 0;
          }
      for(int i = 0; i < b; i++){
          u      = scan.nextInt();
          arr[u] = 1;
          }

      for(int i = 0; i < X; i++){
          sum += arr[i];
          }
      //if(sum >= 1){
        // sum -= 1;
         //}

      for(int i = X; i < a + 1; i++){
          count += arr[i];
          }
     // count -= 1;


      System.out.println(Math.min(sum, count));
   }
}


Measured memory_bytes: 21972
N=int(input())
T, A=map(int,input().split())
p1=list(map(int,input().split()))

p2=list(map(lambda x: abs(x*(-0.006)+T-A), p1))
B=min(p2)

for i in range(N):
    if p2[i]==B:
        print(i+1)
        break
    

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

int main() {
  int l, r;
  cin >> l >> r;
  
  int answer = 2018;
  
  if(r / 2019 != l / 2019)
    answer = 0;
  else {
    r %= 2019;
    l %= 2019;
    for(int i=l; i<r; i++) {
      for(int j=i+1; j<=r; j++) {
        int p = i * j % 2019;
        if(p < answer)
          answer = p;
      }
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	long long a, b;
	cin >> a >> b;
	long long re = b / a;

	int ans = 0;
	while (re > 1) {
		re /= 2;
		ans++;
		
	}
	ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int k;
    char ar[102];
    scanf("%d%s",&k,ar);
    int len=strlen(ar);
    if(len>k){
    for(int i=0;i<k;i++)
        printf("%c",ar[i]);
    printf("...\n");}
    else
        printf("%s\n",ar);
   return 0;
}


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

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

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

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

const int64 mod = 1e9+7;

int main(void){
	int64 x;
	cin >> x;
	int64 sum = 0;
	for(int32 i = 0;sum < x;i++){
		sum += i;
		if(sum >= x){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,k,q=map(int,input().split())
#s=[k]*n
h=[0]*n
for _ in range(q):
    a=int(input().rstrip())
    h[a-1]+=1
for i in range(n):
    if k-(q-h[i])>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define h_p 1110111110111;
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
       int n,m;
       cin>>n>>m;
       int i = 1;
       int l1 = 1;
       int l2 = n/2;
       while(m && l1 < l2)
       {
              cout<<l1<<" "<<l2<<endl;
              l1++;
              --l2;
              --m;
       }
       l1 = (n/2)+1;
       l2 = n-((n%2)==0);
       while(m)
       {
              cout<<l1<<" "<<l2<<endl;
              l1++;
              l2--;
              --m;
       }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n;
    cin >> n;
    vector<long long> as(n);
    map<int, int> cnt;
    for (int i = 0; i < n - 1; i++) {
        cin >> as[i];
        cnt[as[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 14348
#include <cstdio>
#include <queue>
using namespace std;
char board[51][51];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
bool check[51][51];
queue<pair<int,int>> q;
int n,m;
void bfs(int i,int j){
    
    q.push({i,j});
    check[i][j]=true;
    
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        
        for(int k=0;k<4;k++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(0<=nx && nx < n && 0<= ny && ny<m){
                if(board[nx][ny]=='#' && !check[nx][ny]){
                    q.push({nx,ny});
                    check[nx][ny] = true;
                }
            }
        }
    }
}

int main(int argc, const char * argv[]) {
    
    scanf("%d %d",&n,&m);
    
    for(int i=0;i<n;i++){
        scanf("%s",board[i]);
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            
            if(check[i][j]) continue;
            if(board[i][j]=='.') continue;
            int cnt = 0;
            for(int k=0;k<4;k++){
                int nx = i + dx[k];
                int ny = j + dy[k];
                if(0<=nx && nx < n && 0<= ny && ny<m){
                    if(board[nx][ny]=='#')cnt++;
                }
            }
            
            if(cnt>=1) bfs(i,j);
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(!check[i][j] && board[i][j]=='#'){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}


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

int main(){
    char a[10];rep(i,4){cin>>a[i];}
    if(a[0]==a[1]&&a[2]==a[1])cout<<"Yes"<<endl;
    else if(a[3]==a[1]&&a[2]==a[1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

const int N = 2E5 + 5;
int A[N];

int findLIS(int A[], int n) {
    unordered_map<int, int> hash;
    int LIS_size = 1;
    int LIS_index = 0;
    hash[A[0]] = 1;
    for (int i = 1; i < n; i++) {
        hash[A[i]] = hash[A[i] - 1] + 1;
        if (LIS_size < hash[A[i]]) {
            LIS_size = hash[A[i]];
            LIS_index = A[i];
        }
    }
    return LIS_size;
}

int main() {
    int n;  
    cin >> n;
    for(int i = 0; i < n; i ++)
        cin >> A[i];
    int ext = findLIS(A, n);
    cout << n - ext << '\n';
    return 0;
}

Measured memory_bytes: 9288
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

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

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

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

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

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

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

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

const string YES = "Yes";
const string NO = "No";
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
  vector<pair<LL,LL > > p;
    REP(i,N)
      p.PB(make_pair(A[i],B[i]));
    
    sort(p.begin(), p.end(), compare_by_b);
    LL time= 0;
    REP(i, N){
      time+=p[i].first;
      if(time>p[i].second){
        cout<<NO<<endl;
        return;
      }
    }
  cout<<YES<<endl;
}

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


Measured memory_bytes: 9456
#include<bits/stdc++.h>
 using namespace std;
int gcd(int a, int b){
 return __gcd(a,b);
}

int main(){
  long long n,r=0;
  std::cin >> n;

  for(long long i=0;i<=n;i++){
    if(i%3==0 || i%5==0) continue;
    else r+=i;

  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

long long int *sort_sub(long long int *T, int N){
	long long int *ans = (long long int *)malloc(sizeof(long long int) * N);
	if(N == 1){
		ans[0] = T[0];
	}
	else{
		int N1 = N / 2;
		int N2 = (N + 1) / 2;
		long long int *sub1 = sort_sub(&T[0] , N1);
		long long int *sub2 = sort_sub(&T[N1], N2);
		int i, j, k;
		for(i = 0, j = 0, k = 0; i < N; i++){
			if((sub1[j] < sub2[k] && j != N1) || (k == N2)){
				ans[i] = sub1[j];
				j++;
			}
			else{
				ans[i] = sub2[k];
				k++;
			}
		}
		free(sub1);
		free(sub2);
	}
	return ans;
}

long long int *sort(long long int *T, int N){
	long long int *ans = sort_sub(T, N);
	free(T);
	return ans;
}

int main(){
	int N, i;
	scanf("%d", &N);
	long long int *A = (long long int *)malloc(sizeof(long long int) * N);
	long long int *S = (long long int *)malloc(sizeof(long long int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	A = sort(A, N);
	S[0] = A[0];
	for(i = 1; i < N; i++){
		S[i] = S[i - 1] + A[i];
	}
	for(i = N -1; i >= 1; i--){
		if(A[i] > 2 * S[i - 1]){
			break;
		}
	}
	printf("%d\n", N - i);
	return 0;
}

Measured memory_bytes: 2652
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using LD = long double;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        if (i) a[i] = a[i - 1];
        if (s[i] == 'W') a[i]++;
    }
    int ans = a[n - 2], now = 0;
    if (s.back() == 'E') now++;
    for (int i = n - 2; i > 0; i--) {
        ans = min(ans, a[i - 1] + now);
        if (s[i] == 'E') now++;
    }
    ans = min(ans, now);
    cout << ans << '\n';
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    string S;
    cin >> S;

    ll N = S.size();

    auto f = [](char c){
    	if(c == 'A' or c == 'C' or c == 'G' or c == 'T') return true;
    	else return false;
    };

    ll ma = 0;
    REP(i, N){
    	int j = i;
    	while(j<N and f(S[j])) j++;
    	chmax(ma, (ll)(j-i));
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    int L; cin >> L;
    int l=L;
    int r=L+N-1;
    int out=0;
    if(r<=0){
        out = (r+l)*(r-l+1)/2 - r;
    }else if(l<0){
        out = (r+l)*(r-l+1)/2;
    }else{
        out = (r+l)*(r-l+1)/2-l;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3572
import Data.List

makeLunlunNumberList :: [Integer] -> [Integer]
makeLunlunNumberList xs = foldl f [] xs
                                       where f = (\xs x -> do
                                                 let xd0 = x `mod` 10 
                                                 let a = x*10 + xd0
                                                 if xd0 == 0 then a : a+1 : xs else if xd0 == 9 then a-1 : a : xs else a-1 : a : a+1 : xs)

solve :: Int -> [Integer] -> Integer
solve k lnl = if length lnl >= k
                 then (sort lnl) !! (k-1)
                 else solve (k-(length lnl)) (makeLunlunNumberList lnl)

main = do
    k <- readLn :: IO Int
    print $ solve k [1..9]


Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
long long odata,hp;
void solve(){
    hp=odata/500*1000;
    odata=odata%500;
    hp+=odata/5*5;
    cout<<hp<<endl;
}

int main(){
    cin>>odata;

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll fr[ohara],ba[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    fr[0]=a[0];
    ba[n-1]=a[n-1];
    rrep(i,1,n){
        fr[i]=__gcd(fr[i-1],a[i]);
    }
    rrrep(i,n-2,0){
        ba[i]=__gcd(ba[i+1],a[i]);
    }
    rrrep(i,n-1,0){
        if(i==n-1){
            tmp=fr[n-2];
        }
        else if(i==0){
            tmp=ba[1];
        }
        else{
            tmp=__gcd(fr[i-1],ba[i+1]);
        }
        ans=max(ans,tmp);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  string s;cin>>s;
  int a;
  rep(i,s.size()){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  int z;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='Z'){
      z=i;
      break;
    }
  }
  cout<<z-a+1<<endl;
  return 0;
}

Measured memory_bytes: 640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};

fn is_kaibun(a: &str) -> bool {
    //println!("{:?}",a);
    let a : Vec<char> = a.chars().collect();
    let length : usize = a.len();
    (0..length/2).map(|i| {
        //println!("{:?}",a[i] == a[length-1-i]);
        a[i] == a[length-1-i]
    }).fold(true, |sum, i| sum && i)
}

fn check_kaibun(a: &str) -> bool {
    if is_kaibun(a) == false {return false}
    let len = a.len();
    if ( is_kaibun(&a[..(len-1)/2]) == false || is_kaibun(&a[(len+3)/2-1..]) == false) {return false}
    return true
}
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    let s: String = iter.next().unwrap().parse().unwrap();
    
    if check_kaibun(&s) {
        println!("Yes");
    } else {
        println!("No");
    }
    
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;


signed main(){
	int a,b,c;
	cin>>a>>c>>b;
	if(a<=b&&b<=c)out("Yes");
	else out("No");
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    REP(i,k,n+2){
        ans+=i*(n+n-i+1)/2+1-(i-1)*i/2;
        ans%=mod;
    }
    out(ans);
}

Measured memory_bytes: 3624