akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()

int main(){
	int N, K, Q, a;
	cin >> N >> K >> Q;
	vector<int> A(N, K - Q);
	for (int i = 0;i < Q;i++) {
		cin >> a;
		a--;
		A[a]++;
	}
	for (int i = 0;i < N;i++) {
		if (A[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1024
#include<stdio.h>

#define NIL -10

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e,sum,m;
  int g[MAX][MAX],a[MAX],pi[MAX],key[MAX];
  
  scanf("%d",&n);  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&g[i][j]);
      
      if(g[i][j]==-1) g[i][j]=INFTY; 
    }  
  }
  
  for(i=0;i<n;i++){
    key[i]=INFTY;
    a[i]=NIL;
    key[0]=0;
    pi[i]=-1;
  }
  
  while(1){  
    j=NIL;
    m=INFTY;
    for(i=0;i<n;i++){
      if(key[i] < m && a[i]==NIL){
	j=i;
	m=key[i];
	}
      }
    if(j==NIL) break;
    a[j]=10;
    
    for(i=0;i<n;i++){
      if(g[i][j] < key[i] && a[i]==NIL){
	key[i]=g[i][j];
	pi[i]=j;
      }
    }
  }
  sum=0;
  
  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) sum += g[i][pi[i]];
  }
  printf("%d\n", sum);  
  return 0;
}

Measured memory_bytes: 804
from collections import defaultdict

import itertools

# 引数のリストから3つ選ぶときの組み合わせリストを返す
def comb_list(seq:list, n:int):
    return list(itertools.combinations(seq, n))

# aCbを返す
def comb_num(a, b):
    if a - b < b: b = a - b
    if b == 0: return 1
    if b == 1: return a

    numerator = [a - b + k + 1 for k in range(b)]
    denominator = [k + 1 for k in range(b)]

    for p in range(2,b+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (a - b) % p
            for k in range(p-1,b,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(b):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N = int(input())

cnt = defaultdict(int)
for i in range(N):
    s = input()
    s = sorted(s)
    cnt[str(s)] += 1

ans = 0
for c in cnt.values():
    if c==1:
        continue
    ans += comb_num(c, 2)
print(ans)

Measured memory_bytes: 22372
import java.lang.reflect.Array;
import java.util.*;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        int count = 0;

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        for (int hi : h) {
            if (hi >= K) {
                count++;
            }
        }

        System.out.println(count);


    }
}





Measured memory_bytes: 50024
#include<iostream>
using namespace std;
#define PI 3.141592653589
int main()
{
    int i,j,H,W;
    while(1)
    {
        cin >> H >> W ;
        if((H == 0)&& (W == 0)) break;
 
        for(i=0;i<H;i++)
        {
            for(j=0;j<W;j++)
            {
                cout << '#' ;
            }
            cout << endl ;
        }
 
        cout << endl ;
 
    }
 
    return 0;
}

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


int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i=0; i<s.size(); i++) {
    if(s[i]!=t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

bool solve(){
    int n;
    cin >> n;
    if(!n)
        return 0;
    vector<int> w(n);
    for(auto& x : w)
        cin >> x;

    vector<vector<bool>> dp(n + 1, vector<bool>(n + 1, 0));
    for(i64 i = 0; i <= n; ++i)
        dp[i][i] = 1;
    for(int i = 0; i + 2 <= n; ++i)
        dp[i][i + 2] = (abs(w[i] - w[i + 1]) <= 1);

    for(int len = 3; len <= n; ++len){
        for(int l = 0, r = len; r <= n; ++l, ++r){
            for(int i = l + 1; i < r; ++i)
                if(dp[l][i] && dp[i][r])
                    dp[l][r] = true;
            if(dp[l + 1][r - 1] && abs(w[l] - w[r - 1]) <= 1)
                dp[l][r] = true;
        }
    }

    /*
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j)
            cout << dp[i][j];
        cout << endl;
    }
    */

    vector<i64> dp2(n + 1, INF);
    dp2[0] = 0;
    for(int i = 0; i < n; ++i){
        dp2[i + 1] = min(dp2[i + 1], dp2[i] + 1);
        for(int j = i + 1; j <= n; ++j)
            if(dp[i][j])
                dp2[j] = min(dp2[j], dp2[i]);
    }

    cout << n - dp2[n] << endl;

    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3156
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=2017;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch>'9'|ch<'0')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int main()
{
	int n=read(),a=read();
	if(n*n-a<0)
	{
		cout<<0;
		exit(0);
	}
	cout<<n*n-a;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> L(n);
    for(int i=0;i<n;i++)cin>>L[i];
    sort(L.begin(),L.end());
    int ans=0;
    for(int b=0;b<n;b++){
        for(int a=0;a<b;a++){
            int ab=L[a]+L[b];
            int r=lower_bound(L.begin(),L.end(),ab)-L.begin();
            int l=b+1;
            ans+=max(0,r-l);//r-l
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a if N & 1 else 2 * a)
    B.append(b if N & 1 else 2 * b)

a, b = int(np.median(A)), int(np.median(B))
print(b - a + 1)


Measured memory_bytes: 45812
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;cin>>n;
    int a[n];
    for (int i=0;i<n;i++)cin>>a[i];
   
    int flag=1;
    int c=0;
    while (flag){
        flag=0;
        for(int j=n-1;j>=1;j--){
            
            if (a[j]<a[j-1]){
                int b=a[j];
                a[j]=a[j-1];
                a[j-1]=b;
                flag=1;
                c+=1;
            }
        }
        
    }for (int k=0;k<n-1;k++){cout<<a[k]<<" ";}cout<<a[n-1]<<endl;
    cout<<c<<endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

void solve(long long K, long long X) {
  K--;
  ll left = max((ll)-10000000, X - K);
  ll right = min((ll)10000000, X + K);
  for (ll i = left; i <= right; i++) {
    cout << i;
    if (i != right) {
      cout << " ";
    }
  }
  cout << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  long long X;
  scanf("%lld", &X);
  solve(K, X);
  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def gcd(a,b):
    while b:a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

def main():
    md=10**9+7
    n=II()
    aa=LI()
    l=1
    for a in aa:
        l=lcm(l,a)
    bb=[]
    for a in aa:
        bb.append(l//a)
    print(sum(bb)%md)

main()

Measured memory_bytes: 262644
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
  int max = 0, t = 0;
  vector<int> A(3, 0), abss(3, 0); cin >> A[0] >> A[1] >> A[2];
  abss[0] = abs(A[0] - A[1]);
  abss[1] = abs(A[1] - A[2]);
  abss[2] = abs(A[2] - A[0]);
  for(int i = 0; i < 3; i++) {
    if(max < abss[i]) max = abss[i];
    t += abss[i];
  }
  cout << t - max << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

n = len(S)
m = len(T)

def solve(s, t):
    res = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            continue
        res += 1
    return res

ans = m
for i in range(n - m + 1):
    ans = min(ans, solve(S[i:i+m], T))
print(ans)


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

void solve() {
    i64 n;
    cin >> n;
    vector<vector<i64>> a(n, vector<i64>(n));
    for (auto& e : a) for (auto& f : e) cin >> f;

    vector<m64> dp(1 << n);
    dp[0] = 1;
    for (i64 i = 0; i < (1 << n) - 1; i++) {
        i64 cnt = __builtin_popcountl(i);
        for (i64 j = 0; j < n; j++) {
            if ((i >> j) & 1 || !a[cnt][j]) continue;
            dp[i | (1 << j)] += dp[i];
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

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


Measured memory_bytes: 19540
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	long a,b,n,q=0;
	long cnt[1000000];
	cin >> n;
	for(long i=1;i<=sqrt(n);i++){
		if(n%i == 0){
			cnt[q] = i;
			q++;
		}
	}
	a = cnt[q-1];
	b = n/a;
	cout << a+b-2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int sm=0,ss=0,c=0;
  int m,s;
  double a;
  while(scanf("%d,%d",&m,&s)!=EOF){
    ss+=s;
    sm+=s*m;
    c++;
  }
  a=(double)ss/(double)c+0.5;
  printf("%d\n%d\n",sm,(int)a);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    char C;
    cin >> C;
    print(char(C + 1));

    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 rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a+b >= c) puts("Yes");
	else puts("No");
	return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,a,b,c,d;cin >> n >> a >> b >> c >> d;
    a--;b--;c--;d--;
    string s;cin >> s;
    if(c<d){
        repl(i,a,d-1){
            if(s[i]=='#'&&s[i+1]=='#'){
                cout << "No" <<endl;
                return 0;
            }
        }
        cout << "Yes" <<endl;
    }
    else{
        repl(i,a,c-1){
            if(s[i]=='#'&&s[i+1]=='#'){
                cout << "No" <<endl;
                return 0;
            }
        }
        repl(i,b-1,d){
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
                cout << "Yes" <<endl;
                return 0;
            }
        }
        cout <<"No" <<endl;
    }
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>	

#define PI 3.14159265359
using namespace std;

int main(){
	int n;
	double dist;
	cin >> n;
	vector<double> x(n), y(n);
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < n; i++) cin >> y[i];
	dist = 0;
	for (int i = 0; i < n; i++) dist += abs(x[i] - y[i]);
	cout << fixed << setprecision(9) << dist << endl;
	dist = 0;
	for (int i = 0; i < n; i++) dist += (x[i] - y[i]) * (x[i] - y[i]);
	cout << fixed << setprecision(9) << sqrt(dist) << endl;
	dist = 0;
	for (int i = 0; i < n; i++) dist += abs(pow(x[i] - y[i], 3));
	cout << fixed << setprecision(9) << pow(dist, 1.0 / 3.0) << endl;
	dist = abs(x[0] - y[0]);
	for (int i = 1; i < n; i++) dist = max(dist, abs(x[i] - y[i]));
	cout << fixed << setprecision(9) << dist << endl;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;
int64 a[200000];

signed main(){
	cin >> N;
	int64 wk;
	REP(i, 0, N) {
		cin >> wk;
		a[i] = wk - i - 1;
	}
	// ソートする
	sort(a, a + N);
	
	int64 m = a[N / 2];
//	cout << m << endl;
	
	int64 ans = 0;
	REP(i, 0, N) {
		ans += abs(a[i] - m);
//        cout << "ans = " << ans << " (a[" << i << "] = " << a[i] << "  - " << m << " )" << endl;
	}	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
s = raw_input()

p = raw_input()

flag = 0
for i in range (len(s)):
    flag = 0
    for j in range(len(p)):
        if p[j] == s[(i + j) % len(s)]:
            flag += 1

        if flag == len(p):
            break

    if flag == len(p):
        break

if flag == len(p):
    print "Yes"
else:
    print "No"

Measured memory_bytes: 6448
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    l = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
    l = sorted(l,key=lambda l:l[1])
    t = 0
    for e in l:
        t += e[0]
        if t > e[1]:
            print("No")
            exit()
    print("Yes")

Measured memory_bytes: 56180
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=list(ss())
n=list(reversed(list(map(int,n))))+[0]
#print(n)
ans=0
for i in range(len(n)):
    if n[i]>=6 or (n[i]==5 and n[i+1]>=5):
        ans+=10-n[i]
        n[i+1]+=1
    else:
        ans+=n[i]
#print(n)
print(ans)

Measured memory_bytes: 159432
using System;

namespace ABC026A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            int d = 0;
            int max = a;

            if (max > b)
                d += b;
            else
            {
                d += a;
                max = b;
            }

            if (max > c)
                d += c;
            else
            {
                d += max;
            }

            Console.WriteLine(d);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

#define int long long

signed main(){
    int n; cin >> n;
    vector<int> A(n), S(n);
    for(int i=0; i<n; ++i){
        cin >> A[i];
    }
    
    int posC = 0, negC = 0;
    //pos-minus
    if(A[0]<=0){
       posC += abs(A[0]) + 1;
       S[0] = 1;
    }else S[0] = A[0];
    for(int i=1; i<n; ++i){
        //cout << posC << endl;
        S[i] = S[i-1] + A[i];
        if(S[i]*S[i-1] < 0) continue;
        posC += abs(S[i]) + 1;
        if(S[i-1] < 0) S[i] = 1;
        else S[i] = -1;
    }
    // nega-pos
    if(A[0]>=0){
       negC += A[0] + 1;
       S[0] = -1;
    }else S[0] = A[0];
    for(int i=1; i<n; ++i){
        S[i] = S[i-1] + A[i];
        if(S[i]*S[i-1] < 0) continue;
        negC += abs(S[i]) + 1;
        if(S[i-1] < 0) S[i] = 1;
        else S[i] = -1;
    }
    //cout << posC << " " << negC << endl;
    cout << min(negC, posC) << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n;
	while(scanf("%d", &n),n){
		int t[300], r[300], num[300];
		long double ent = 100000000.0;
		int ss, aa, cc;
		rep(i,n) scanf("%d", &t[i]);
		for(int s = 0; s <= 15; s++){
			for(int a = 0; a <= 15; a++){
				for(int c = 0; c <= 15; c++){
					long double tent = 0.0;
					rep(i,300) num[i] = 0;
					r[0] = s;
					for(int i = 1; i < 300; i++) r[i] = (a*r[i-1]+c)%256;
					rep(i,299) r[i] = r[i+1];
					rep(i,n) num[(t[i]+r[i])%256]++;
					rep(i,300){
						if(num[i] == 0) continue;
						long double tmp = (long double)log((double)num[i])-(long double)log((double)n);
						tent -= (long double)num[i]*tmp;
					}
					if(tent < ent){
						ent = tent;
						ss = s;
						aa = a;
						cc = c;
					}
				}
			}
		}
		printf("%d %d %d\n", ss, aa, cc);
	}
}

Measured memory_bytes: 1228
#include<stdio.h>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e5+5;
struct node{
	int en[maxn],owo,la[maxn],nt[maxn];
	void adg(int x,int y) {
		en[++owo]=y; nt[owo]=la[x]; la[x] = owo;
		en[++owo]=x; nt[owo]=la[y]; la[y] = owo;
	}
}v,v1,v2;
int n;
int zb[maxn],yc[maxn],zz[maxn];
int sta[maxn],tp;
void dfs1(int x,int ba) {
	for(int it=v1.la[x];it;it=v1.nt[it]) {
		int y = v1.en[it];
		if(y==ba) continue;
		dfs1(y,x);
	}
	if(zb[x]==1) sta[++tp] = x;
	while(tp>=2) {
		v.adg(sta[tp],sta[tp-1]);
		tp-=2;
	}
}
void dfs2(int x,int ba) {
	for(int it=v2.la[x];it;it=v2.nt[it]) {
		int y = v2.en[it];
		if(y==ba) continue;
		dfs2(y,x);
	}
	if(zb[x]==1) sta[++tp] = x;
	while(tp>=2) {
		v.adg(sta[tp],sta[tp-1]);
		tp-=2;
	}
}
void dfs(int x,int vv) {
	yc[x] = vv;
	for(int it=v.la[x];it;it=v.nt[it]) {
		int y = v.en[it];
		if(yc[y]==0) dfs(y,-vv);
	}
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) zb[i] = zz[i] = 1;
	int rt1 = 0 , rt2 = 0;
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d",&x);
		if(x==-1) rt1 = i;
		else v1.adg(x,i),zb[x]^=1;
	}
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d",&x);
		if(x==-1) rt2 = i;
		else v2.adg(x,i),zz[x]^=1;
	}
	for(int i=1;i<=n;i++) {
		if(zz[i]!=zb[i]) {
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	puts("POSSIBLE");
	dfs1(rt1,0);
	tp = 0; 
	dfs2(rt2,0);
	for(int i=1;i<=n;i++) {
		if(zb[i]==1&&(yc[i]==0)) {
			dfs(i,1);
		}
	}
	for(int i=1;i<=n;i++) {
		if(zb[i]==0) printf("0 ");
		else printf("%d ",yc[i]);
	}
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    double n; cin >> n;
    string flg = "No";
    REP(i,1,10){
        if(n/i<=9 && (n/i)-int(n/i)==0){
            flg = "Yes";
        }
    }
    cout << flg << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;

int n, m;
pii a[maxn];
vector<pii> g[maxn];
vector<int> ans;
bool vis[maxn];

int dfs(int x) {
    vis[x] = 1;
    int &res = a[x].second;
    for (auto cur: g[x]) {
        int v = cur.first, id = cur.second;
        if (vis[v]) continue;
        int tmp = dfs(v);
        if (tmp) ans.push_back(id);
        res ^= tmp;
    }
    return res;
}

void solve() {
    scanf("%d%d", &n, &m);
    int pn = 0;
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &a[i].first, &a[i].second);
    sort(a + 1, a + 1 + n);
    a[0].second = a[1].second;
    for (int i = 1; i < n; ++i)
        a[i].second ^= a[i + 1].second;

    for (int l, r, i = 1; i <= m; ++i) {
        scanf("%d%d", &l, &r);
        l = lower_bound(a + 1, a + 1 + n, make_pair(l, 0)) - a - 1;
        r = upper_bound(a + 1, a + 1 + n, make_pair(r, 1)) - a - 1;
        g[l].push_back({r, i});
        g[r].push_back({l, i});
    }

    for (int i = 1; i <= n; ++i) {
        if (vis[i]) continue;
        if (dfs(i)) return puts("-1"), void();
    }
    printf("%d\n", ans.size());
    sort(ans.begin(), ans.end());
    for (auto v: ans)
        printf("%d ", v);
    puts("");
}

int main() {
    int T = 1;
//    scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 14844
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;

int insertionSort(int *A, int n, int g, long cnt) {
    for (int i=g; i<n; i++) {
        int v = A[i];
        int j = i - g;
        
        while(j>=0 && A[j]>v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    
    return cnt;
}


void shellSort(int *A, int n) {
    long cnt = 0;
    vector<int> G;
    
    for (int h=1; ; ) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }
    
    for (int i=G.size()-1; i>=0; i--) {
        cnt = insertionSort(A, n , G[i], cnt);
    }
    
    printf("%d\n", G.size());
    printf("%d", G[G.size()-1]);
    for (int i=G.size()-2; i>=0; i--) printf(" %d", G[i]);
    printf("\n");
    printf("%d\n", cnt);
}


int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i=0; i<n; i++) scanf("%d", &a[i]);
    
    shellSort(a, n);
    
    for (int i=0; i<n; i++) printf("%d\n", a[i]);
    
    return 0;
}





Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC171 F - Strivore
// 2020.06.27

ll MOD = 1e9+7;
ll fastpow(ll a, ll n){  // a^n mod MOD
  if(n==0) return 1;
  if(n%2==0){
    ll t = fastpow(a, n/2) % MOD;
    return t*t % MOD;
  }
  return a * fastpow(a, n-1) % MOD;
}

const ll MAX = 5123456;
vector<ll> fac(MAX);
vector<ll> finv(MAX);
vector<ll> inv(MAX);

// COMinit()を忘れないように！
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(ll i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll K; cin >> K;
  string S; cin >> S;
  COMinit();
  ll N = S.size();
  ll ans = 0;
  REP(i, K+1){
    ans += ((fastpow(25, i)*nCr(i+N-1, i))%MOD)*fastpow(26, K-i)%MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 124332
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 9; ++i) {
    if (n % i == 0 && n / i <= 9) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int H,W,i,j;

	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 &&W==0)
			break;
		for(i=0;i<H;i++){
		    if(i==0 || i==H-1){
                for(j=0;j<W;j++)
                    printf("#");
			}
			else{
                printf("#");
                for(j=1;j<W-1;j++)
                    printf(".");
                printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll dp[3001][3001];
ll arr[3001];
ll n;
ll func(ll i,ll j)
{
    if(i>j)
        return 0;
    ll &ret = dp[i][j];
    if(ret!=-1)
        return ret;
    if((n-(i+j))%2)
    {
        ret = max(arr[i]+func(i+1,j),arr[j]+func(i,j-1));
    }
    else
        ret = min(-arr[i]+func(i+1,j),-arr[j]+func(i,j-1));
    return ret;
}
signed main()
{
    fast;
    cin>>n;
    mem(dp,-1);
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i];
    cout<<func(0,n-1);
}

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

int main() {
    int ans, N, L, taste, C, pie = 0;
    
    cin >> N >> L;
    vector<int> total(N);    
    
    for (size_t i = 1; i <= N; i++) {
        taste = L+i-1;
        pie += taste; total.at(i-1) = taste;
    }
    auto result = find(total.begin(), total.end(), 0);
    if (result!=total.end()) { cout << pie << endl; }
    else if (total.at(N-1) < 0) { cout << pie-total.at(N-1) << endl; }
    else { cout << pie-total.at(0) << endl; }
    return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

Q, H, S, D, N = map(int, read().split())
H = min(Q * 2, H)
S = min(H *2 , S)

if S * 2 < D:
    print(N * S)
else:
    print(N // 2 * D + N % 2 * S)

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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n;
  string s;
  cin >> n >> s;

  ll b_humm = 0;
  ll w_humm = 0;

  ll res = 0;

  for(ll i=0; i<n; i++) {
    if(s[i] == '.') {
      b_humm++;
    }
  }

  res = b_humm + w_humm;

  for(ll i=0; i<n; i++) {
    if(s[i] == '.') {
      b_humm--;
    } else {
      w_humm++;
    }
    if(res > b_humm + w_humm) {
      res = b_humm + w_humm;
    }
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
// #define endl '\n'

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vll dp(n + 1, vl(2));
  dp[0][1] = 1;
  rep (i, n) {
    rep (j, 2) {
      if (j == 0) {
        (dp[i + 1][0] += dp[i][j] * 3 % MOD) %= MOD;
      }
      else {
        if (s[i] == '1') {
          (dp[i + 1][1] += dp[i][j] * 2 % MOD) %= MOD;
          (dp[i + 1][0] += dp[i][j]) %= MOD;
        }
        else {
          (dp[i + 1][1] += dp[i][j]) %= MOD;
        }
      }
    }
  }
  cout << (dp[n][0] + dp[n][1]) % MOD << endl;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pw 1000000000
#define pi 3.141592653589793238

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       cout<<2*pi*n;
       //string s;
       /*f(i,0,n)
       cin>>a[i];
       sort(a,a+n);*/
       cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3788
#include<algorithm>
#include<deque>
#include<iostream>
#include<string>
#include<unordered_map>

int main(void)
{
	int n;
	std::cin >> n;

	std::unordered_map<std::string, int> mapCount;
	std::string name;
	int maxNumber = 0;
	for (int count = 0; n > count; ++count)
	{
		std::cin >> name;
		int& c = mapCount[name];
		c += 1;
		maxNumber = (std::max)(maxNumber, c);
	}

	std::deque<std::string> nameList;
	for (const std::pair<const std::string, int>& nameToCount : mapCount)
	{
		if (maxNumber != nameToCount.second)
		{
			continue;
		}
		nameList.emplace_back(nameToCount.first);
	}
	std::sort(nameList.begin(), nameList.end());
	for (const std::string& s : nameList)
	{
		std::cout << s << std::endl;
	}
}

Measured memory_bytes: 20860
import sys


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [int(s) for s in sys.stdin.readline().strip().split()]

    seen_nums = []
    s = 0
    for i in range(n):
        for seen in seen_nums:
            if seen > a[i]:
                s += 1
        seen_nums.append(a[i])

    t = 0
    for i in range(n):
        for seen in seen_nums:
            if a[i] < seen:
                t += 1

    ans = (k * (k-1) * t // 2 + k * s) % (10 ** 9 + 7)
    print(ans)


main()


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

int main(){
    int board[3][3], n;
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            cin >> board[i][j];
        }
    }
    cin >> n;
    int b[n];
    for(int i=0;i<n;++i){
        cin >> b[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(board[j][k]==b[i]){
                    board[j][k]=0;
                }
            }
        }
        /*
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                cout << board[j][k];
            }
            cout << endl;
        }
        */
    }

    for(int i=0;i<3;++i){
        if( board[i][0]==board[i][1] && board[i][1]==board[i][2] && board[i][2]==0){
            cout << "Yes" << endl;
            return 0;
        }
        if( board[0][i]==board[1][i] && board[1][i]==board[2][i] && board[2][i]==0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(board[0][0]==board[1][1] && board[1][1]==board[2][2] && board[2][2]==0){
            cout << "Yes" << endl;
            return 0;
    }
    if(board[0][2]==board[1][1] && board[1][1]==board[2][0] && board[2][0]==0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
S=str(input()) #Sの入力
Smojisuu=len(S)
c=S.count("eraser")
S=S.replace("eraser","xxxxxx",c)
d=S.count("erase")
S=S.replace("erase","xxxxx",d)
e=S.count("dreamer")
S=S.replace("dreamer","xxxxxxx",e)
f=S.count("dream")
S=S.replace("dream","xxxxx",f)
g=S.count("x")
if len(S)>g:
  print("NO")
elif len(S)==g:
  print("YES")
else:
  print("error")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#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(a) (a).begin(),(a).end()
using namespace std;
double EPS=1e-10;
int INF=1e9;
int dp[11][156];
int main(){
      int n,k,s;
      while(cin>>n>>k>>s&&(n||k||s)){
            memset(dp,0,sizeof(dp));
            dp[0][0]=1;
            for(int i=1;i<=n;i++){
                  for(int j=k;j>=1;j--){
                        for(int l=i;l<=s;l++){
                              dp[j][l]+=dp[j-1][l-i];
                        }
                  }
            }
            cout<<dp[k][s]<<endl;
      }
}

Measured memory_bytes: 1164
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(M):
    c.append(list(map(int,input().split())))
C=min(a)+min(b)
for i in range(0,M):
    d.append(a[(c[i][0]-1)]+b[(c[i][1]-1)]-c[i][2])
D=min(d)
print(min(C,D))

Measured memory_bytes: 42604
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    int h[N];
    REP(0, i, N) {
        cin >> h[i];
    }

    int k[N];
    REP(0, i, N) {
        if (i == 0) {
            k[0] = h[0];
        } else {
            k[i] = h[i] - h[i - 1];
        }
    }

    int ans = 0;
    REP(0, i, N) {
        if (k[i] > 0) {
            ans += k[i];
        }
    }

    cout << ans << endl;

    return 0;
}


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

//C Get AC
int main(){
    int n,q,l,r;
    string s;
    cin>>n>>q;
    cin>>s;
    vector<int> vec(n+1,0);

    for(int i=2; i<=n; i++){
        vec[i]+=vec[i-1];
        if(s[i-1]=='C'&&s[i-2]=='A'){
            vec[i]++;
        }
    }
    while(q){
        cin>>l>>r;
        cout<<vec[r]-vec[l]<<"\n";
        --q;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, h;
  cin >> a >> b >> h;

  int ans = (a + b) * h / 2;
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;


int main(){
	int A,B;
	cin >> A >>B;
	if(A+B < A-B){
		if(A-B < A*B)cout << A*B;
		else cout << A-B;
	}
	else{
		if(A+B < A*B)cout << A*B;
		else cout << A+B;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    int X;cin>>X;
    int ans=(X/500)*1000;
    X-=(X/500)*500;
    ans+=(X/5)*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

const ll MOD = 1e9 + 7;

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

    int N; cin >>N;
    vector<int> A(N+1);
    vector<int> pos(N, -1);
    int l, r;
    rep(i, N+1) {
        cin >> A[i];
        A[i]--;
        if (pos[A[i]] == -1) {
            pos[A[i]] = i;
        } else {
            l = pos[A[i]];
            r = i;
        }
    }

    vector<int> fact(N+1+1);
    vector<int> finv(fact.size());
    vector<int> inv(fact.size());
    
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[0] = 0; inv[1] = 1;
    for (int i = 2; i < fact.size(); i++) {
        fact[i] = (ll)fact[i-1] * i % MOD;
        inv[i] = MOD - (ll)inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
    }

    auto C = [&](int n, int r) { return (ll)fact[n] * finv[n-r] % MOD * finv[r] % MOD; };

    cout << N+1-1 << endl;
    for (int k = 2; k <= N+1; k++) {
        int a = C(N+1, k);
        int b = l + N+1-(r+1) >= k - 1 ? C(l + N+1-(r+1), k-1) : 0;
        int s = ((ll)a - b) % MOD;
        while (s < 0) s += MOD;
        cout << s << endl;
    }
}

Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10, 9) + 7;
#define vect vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vect) for(int aqw=0;aqw<vect.size();aqw++){cout<<vect[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
//cout << setprecision(15) << std::fixed;


int main() {
	ll n,a;
	cin >> n;
	ll maxt = 0;
	for (int i = 0;i < 5;i++) {
		cin >> a;
		maxt = max(maxt, (n - 1) / a);
	}
	print(maxt + 5);
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	queue<int> a;
	for (int i = 0; i < (1 << n); i++) {
		int x;
		cin >> x;
		a.push(x);
	}
	while (a.size() > 1) {
		int x = a.front();
		a.pop();
		int y = a.front();
		a.pop();
		if (x == y) a.push(x);
		else a.push(abs(x - y));
	}
	cout << a.front() << endl;
	return 0;
}

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

vector<vector<char>> field(8, vector<char>(8, '.'));
vector<bool> row_available(8,true);
vector<bool> column_available(8,true);
vector<bool> lower_right_available(15,true);
vector<bool> lower_left_available(15,true);
vector<int> memo(8, -1);
void putQ(int i, int j){
    field[i][j] = 'Q';
    row_available[i] = false;
    column_available[j] = false;
    lower_right_available[i-j+7] = false;
    lower_left_available[i+j] = false;
}
void rmQ(int i, int j){
    field[i][j] = '.';
    row_available[i] = true;
    column_available[j] = true;
    lower_right_available[i-j+7] = true;
    lower_left_available[i+j] = true;
}
int main()
{
    // input
    vector<int> row_list(0);
    rep(i,8) row_list.emplace_back(i);
    int k;
    cin >> k;
    rep(i,k){
        P p;
        cin >> p.first >> p.second;
        putQ(p.first,p.second);
        memo[p.first] = p.second;
        row_list.erase(remove(ALL(row_list), p.first), row_list.end());
    }
    
    // solve
    int i=0;
    int j=0;
    while(i<row_list.size()){
        j=memo[row_list[i]]+1;
        if(!row_available[row_list[i]])continue;
        while(j<8){
            if(column_available[j] && lower_right_available[row_list[i]-j+7] && lower_left_available[row_list[i]+j]){
                putQ(row_list[i],j);
                memo[row_list[i]] = j;
                i++;
                break;
            }
            if(j==7){
                do{
                    memo[row_list[i]]=-1;
                    i--;
                    rmQ(row_list[i], memo[row_list[i]]);
                }
                while(memo[row_list[i]]==7);
                break;
            }
            j++;
        }
    }

    // output
    rep(i,8){
        rep(j,8){
            cout << field[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string a;
    ll b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++){
        if(i+1==b){
            cout<<a[i]<<endl;
            return 0;
        }
        if(a[i]!='1'){
            cout<<a[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256