akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF INT_MAX
#define INFLL _I64_MAX
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	int n, a, b;

	cin>>n>>a>>b;

	if((b-a)%2){
		cout<<"Borys"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
content = 0

for i in range(len(a)):
  content += b[a[i]-1]
  if i>=1:
    if a[i] == a[i-1] +1:
      content += c[a[i-1]-1]
print(content)
  
  

Measured memory_bytes: 9060
#include <iostream>
#include <vector>

using namespace std;
using int64 = long long;

int main() {
    int64 h;
    cin >> h;

    int64 ans = 0;
    int64 cnt = 1;
    while (h) {
        ans += cnt;
        cnt *= 2;
        h /= 2;
    }

    cout << ans << endl;
}


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

int main()
{
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for (int i = 0; i < 2; i++)
    {
        if (A >= B)
        {
            ans += A;
            A--;
        }
        else
        {
            ans += B;
            B--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int INF = 1001001001;

int a[12][12];

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }

    int ans = INF;
    rep(s,1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i,n) {
            if(s>>i&1){
                cost += c[i];
                rep(j,m){
                    d[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(j,m){
            if(d[j] < x){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, cost);
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

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

string s;

int main() {
	cin >> s;
	
	int i;
	for (i = 0; i < s.length(); i++) if (s[i] == 'A') break;
	
	int j;
	for (j = s.length() - 1; j >= 0; j--) if (s[j] == 'Z') break;
	
	cout << j - i + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	
	ll ans = 0LL;
	
	ans += min(a, k);
	k -= min(a, k);
	k -= min(b, k);
	ans += -1 * k;
	
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
    int r;
    cin >> r;
    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
string s,t;
int dp[3005][3005];

int solve(int i, int j) {
    if (i == s.length() || j == t.length())
        return 0;
    if (dp[i][j] != -1)
        return dp[i][j];
    int ans = 0;
    if (s[i] == t[j]) {
        return dp[i][j] = solve(i + 1, j + 1) + 1;
    }
    else
        return dp[i][j] = max(solve(i + 1,j), solve(i, j + 1));
}

void print(int i, int j) {
    if (i == s.length() || j == t.length())
        return;
    if (s[i] == t[j]) {
        cout << s[i];
        print (i + 1, j + 1);
        return;
    }
    if (dp[i + 1][j] > dp[i][j + 1])
        print (i + 1,j);
    else
        print (i, j + 1);
}

int main() {
    IO;
    cin >> s >> t;
    for (int i = 0;i < 3000; i++) {
        for (int j = 0; j < 3000; j++)
            dp[i][j] = -1;
    }
    solve(0,0);
    print(0,0);
    return 0;
}


Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define int ll
#define abs(x) llabs((x))
using namespace std;
typedef long long ll;

signed main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int count=0;
    int ans=0;
    for(int i=0;i<n;i++){
        count+=a[i];
        if(i%2==0){
            if(count<=0){
                ans+=abs(count)+1;
                count=1;
            }
        }
        else{
            if(count>=0){
                ans+=count+1;
                count=-1;
            }
        }
    }

    int count2=0;
    int ans2=0;
    for(int i=0;i<n;i++){
        count2+=a[i];
        if(i%2==1){
            if(count2<=0){
                ans2+=abs(count2)+1;
                count2=1;
            }
        }
        else{
            if(count2>=0){
                ans2+=count2+1;
                count2=-1;
            }
        }
    }
    
    cout<<min(ans,ans2)<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int a[2], b[2];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int j = 0; j < 2; j++)
        cin >> a[j];
    for(int j = 0; j < 2; j++)
        cin >> b[j];
    int ans = -2e18;
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < 2; j++)
            ans = max(ans, a[i] * b[j]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3648
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = [0]*(10**4)
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            ans = i**2+j**2+k**2+i*j+j*k+i*k
            if ans <= 10**4:
                L[ans-1] += 1
for i in range(N):
    print(L[i])

Measured memory_bytes: 74220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305,mod=998244353;
int n,p[2][N];
char s[N];
int dp[N][N][N];
bool f[N][N][N];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++) p[0][i]=p[0][i-1]+(s[i]=='0'),p[1][i]=p[1][i-1]+(s[i]=='1');
    p[1][n+1]=p[1][n];p[0][n+1]=p[0][n];
    f[0][0][0]=true;
    for(int k=0;k<=n;k++)
        for(int i=0;i<=p[0][k];i++)
            for(int j=0;j<=p[1][k];j++)
    {
        if(!f[k][i][j]) continue;
        f[k+1][i][j]=true;
        if(i&&s[k+1]=='1')
            f[k+1][i-1][j+1]=true;
        if(j&&s[k+1]=='0')
            f[k+1][i+1][j-1]=true;
        if(k+2<=n&&(s[k+1]=='1'||s[k+2]=='1'))
            f[k+2][i][j+1]=true;
        if(k+2<=n&&(s[k+1]=='0'||s[k+2]=='0'))
            f[k+2][i+1][j]=true;
    }
    dp[n+1][0][0]=1;
    ll ans=0;
    for(int k=n+1;k>=1;k--)
        for(int i=0;i<=p[0][k];i++)
        for(int j=0;j<=p[1][k];j++)
    {
        if(dp[k][i][j]==0) continue;
        if(f[k-1][i][j])
            ans=(ans+dp[k][i][j])%mod;
        if(k>1)
        {
            dp[k-1][i][j]=(dp[k-1][i][j]+dp[k][i][j])%mod;
            if(s[k-1]=='1')
                dp[k][i+1][j]=(dp[k][i+1][j]+dp[k][i][j])%mod;
            else dp[k][i][j+1]=(dp[k][i][j+1]+dp[k][i][j])%mod;
        }
    }
    ans=(ans+mod-1)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 57200
#include<stdio.h>
int main(void){

	int N,M,X,A[100],i,x=-1;

	scanf("%d%d%d",&N,&M,&X);

	for(i=0;i<M;i++){

		scanf("%d",&A[i]);
		if(A[i]>X&&x==-1)
			x=i;

	}

		printf("%d\n",M-x>x?x:M-x);

	return 0;

}

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

class Main {

	void solve() {
		
		char c = inchar();
		if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') out.println("vowel");
		else out.println("consonant");

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

int main()
{
    int N, ans;
    scanf("%d", &N);

    ans = N%1000;
    if(ans == 0)printf("0");

    else
    {
        ans = 1000 - ans;
        printf("%d", ans);
    }
    
    return 0;
}


Measured memory_bytes: 3688
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                var number = Console.ReadLine()
                    .Split(' ')
                    .Select(decimal.Parse)
                    .ToArray();
                var dx1 = number[0] - number[2];
                var dy1 = number[1] - number[3];
                var dx2 = number[4] - number[6];
                var dy2 = number[5] - number[7];

                if (dy1 * dx2 - dy2 * dx1 == 0)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 6124
f=lambda:map(int,input().split())
n,a=f()
l=[i-a for i in f()]
dp=[[0]*5000 for _ in range(51)]
Z=2500
dp[0][Z]=1
for i in range(n):
  for s in range(5000-max(l[i],0)):
    dp[i+1][s]+=dp[i][s]
    dp[i+1][s+l[i]]+=dp[i][s]
print(dp[n][Z]-1)

Measured memory_bytes: 5620
/* Bismillahirrahmanirrahim
   Semoga Dapet AC ya Allah
   Amin.................. :)
*/
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
#define ll long long
#define F first
#define S second
using namespace std;

int main(){
	char a;
	cin >> a;
	if(a=='A') cout << 'T';
	else if(a=='T') cout << 'A';
	else if(a=='C') cout << 'G';
	else if(a=='G') cout << 'C';
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<utility>
#include<queue>
#define mod 1000000007
#define INF 1000000000000000
using namespace std;
int h,w;
char s[2010][2010];
int dp[4][2010][2010],ans;
int main(){
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                dp[0][i][j]=i;
                dp[2][i][j]=j;
            }
            else{
                if(i){
                    dp[0][i][j]=dp[0][i-1][j];
                }
                else{
                    dp[0][i][j]=-1;
                }
                if(j){
                    dp[2][i][j]=dp[2][i][j-1];
                }
                else{
                    dp[2][i][j]=-1;
                }
            }
        }
    }
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(s[i][j]=='#'){
                dp[1][i][j]=i-1;
                dp[3][i][j]=j-1;
            }
            else{
                if(i!=h-1){
                    dp[1][i][j]=dp[1][i+1][j];
                }
                else{
                    dp[1][i][j]=h-1;
                }
                if(j!=w-1){
                    dp[3][i][j]=dp[3][i][j+1];
                }
                else{
                    dp[3][i][j]=w-1;
                }
            }
        }
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='.'){
                ans=max(ans,dp[1][i][j]-dp[0][i][j]+dp[3][i][j]-dp[2][i][j]-1);
            }
        }
    }
    printf("%d\n",ans);
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define REP(i,l,r) for(int i=l;i<r;++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int,int> P;
//other libs

signed main(int argc, char * argv[]) {
	int n;
	double sum;
	cin>>n;
	rep(i,n){
		double in;
		cin>>in;
		sum+=(1.0/in);
	}
	printf("%.15f",1.0/sum);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

int main(){
    int R, C, K; cin >> R >> C >> K;
    vector<vector<ll>> items(R, vector<ll>(C));
    rep(i, K){
        int r, c; ll v; cin >> r >> c >> v; r--, c--;
        items[r][c] = v;
    }

    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4, -1)));
    dp[0][0][0] = 0;
    if(items[0][0])dp[0][0][1] = items[0][0];

    rep(i, R){
        rep(j, C){
            rep(k, 4){
                if(dp[i][j][k] == -1)continue;
                //右に遷移
                if(j < C-1){
                    //アイテムを拾う
                    if(k < 3 && items[i][j+1]){
                        chmax(dp[i][j+1][k+1], dp[i][j][k] + items[i][j+1]);
                    }
                    //拾わない
                    chmax(dp[i][j+1][k],dp[i][j][k]);
                }
                //下に遷移
                if(i < R-1){
                    //アイテムを拾う
                    if(items[i+1][j]){
                        chmax(dp[i+1][j][1], dp[i][j][k] + items[i+1][j]);
                    }
                    //拾わない
                    chmax(dp[i+1][j][0], dp[i][j][k]);
                }
            }
        }
    }
    ll res = 0;
    rep(k, 4)chmax(res, dp[R-1][C-1][k]);
    cout << res << ln;
}


Measured memory_bytes: 706828
_ = int(input())
bef_time = 0
bef_x = 0
bef_y = 0
ans = True

for i in range(_):
    next = input().split()
    next_time = int(next[0])
    next_x = int(next[1])
    next_y = int(next[2])
    time = next_time - bef_time
    range = abs(next_x - bef_x) + abs(next_y - bef_y)

    if (next_time - bef_time) < range:
        ans = False
        break

    if time % 2 == 0:
       if range % 2 != 0:
          ans = False
          break
    else:
       if range % 2 == 0 or range == 0:
          ans = False
          break

    bef_time = next_time
    bef_y = next_y
    bef_x = next_x



if ans == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
use std::io;
use std::collections::VecDeque;
use std::process::exit;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().ok().unwrap();
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();

    let (mut r, mut w) = (VecDeque::new(), VecDeque::new());
    r.push_back(0);
    for (i, c) in s.trim().chars().enumerate() {
        match c {
            'R' => r.push_back(i),
            'W' => w.push_front(i),
            _ => exit(1),
        };
    }
    w.push_front(n);
    let c = r.iter().rev().zip(w.iter().rev())
        .filter(|(x, y)| x > y)
        .count();
    println!("{}", c);
}


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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vll A(N);
  for (auto& a : A) {
    cin >> a;
  }

  sll S;
  for (auto a : A) {
    auto p = S.insert(a);
    if (!p.second) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 11264
#include <iostream>
using namespace std;
int main (void) {
    int a, b;

    cin >> a >> b;

    if ((a < 0 && b > 0) || (a == 0 || b == 0)) {
        cout << "Zero" << endl;
    } else if ((a > 0 && b > 0) || (a < 0 && b < 0 && (b - a + 1) % 2 == 0)) {
        cout << "Positive" << endl;
    } else {
        cout << "Negative" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(i,x) for(int (i)=1;(i)<=(x);(i)++)
#define fo(i,x) for(int (i)=0;(i)<=(x);(i)++)
#define G 3
#define p 998244353
const int N=1e6;
int i,j,k,x,y,m,n,tot,sum;
int a[N],b[N],ver[N],nxt[N],head[N];
inline int read()
{
	int r=1;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+ch-'0',ch=getchar();
	return r;
}
inline ll ksm(ll x,ll y)
{
	ll re=1;
	for(;y;y>>=1,x=(x*x)%p) if(y&1) re=(re*x)%p;
	return re;
}
inline void add(int x,int y)
{
	ver[++tot]=y,nxt[tot]=head[x],head[x]=tot;
}
int main()
{
	scanf("%d%d",&n,&m);
	m=2*m+1;
	if(n%m==0) printf("%d",n/m);
	else printf("%d",n/m+1);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  int n, k;
  char ch[5010];
  vector<string> vs;
  vs.clear();
  scanf("%s", ch);
  string smain = ch;
  scanf("%d", &k);
  map<string, bool> dict; dict.clear();
  string smax = "";
  string smin[5];
  for(int i = 0; i < 5; ++i) {
    smin[i] = "";
    for(int j = 0; j < 5010; ++j) smin[i] += "z";
  }
  int len = strlen(ch);
  for(int i = 1; i <= 6; ++i) {
    for(int j = 0; j <= len - i; ++j) {
      string stemp = smain.substr(j, i);
      if(!dict[stemp]) {
        vs.pb(stemp);
        dict[stemp] = true;
        if(stemp < smin[0]) smin[0] = stemp;
        if(stemp > smax) smax = stemp;
      }
    }
  }
  int sz = vs.size();
  //cout << smin[0] << endl << smax << endl;
  //sort(vs.begin(), vs.end());
  //for(int j = 0; j < sz; ++j)
  //cout << i << " " << vs[i] << endl;
  for(int i = 1; i < 5; ++i) {
    //cout << i << " " << vs[i] << endl;
    for(int j = 0; j < sz; ++j) {
      if(smin[i] > vs[j] && vs[j] > smin [i - 1]) {
        smin[i] = vs[j];
      }
    }
  }
  //for(int i = 0; i < 5; ++i) cout << smin[i] << endl;
  printf("%s\n", smin[k - 1].c_str());
  return 0;
}


Measured memory_bytes: 2684
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = List.fill(n)(sc.nextInt())
  val (x, idx) = a.zipWithIndex.maxBy(_._1.abs)

  println(2 * (n-1))
  for (i <- 1 to n if i != idx + 1) {
    println(s"${idx + 1} $i")
  }

  if (x >= 0) {
    for (i <- 1 until n) {
      println(s"${i} ${i+1}")
    }
  } else {
    for (i <- n until 1 by -1) {
      println(s"${i} ${i-1}")
    }
  }
}

Measured memory_bytes: 55360
# -*- coding: utf-8 -*-

# See:
# http://drken1215.hatenablog.com/entry/2018/06/08/210000
max_value = 500050
mod = 10 ** 9 + 7

fac = [0 for _ in range(max_value)]
finv = [0 for _ in range(max_value)]
inv = [0 for _ in range(max_value)]


def com_init():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, max_value):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    n, k = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    com_init()
    ans = 0

    # See:
    # https://www.youtube.com/watch?v=1oLDDdWRu6Y&feature=youtu.be
    for index, ai in enumerate(a):
        now = com(index, k - 1)
        ans += now * ai

    for index, ai in enumerate(a[::-1]):
        now = com(index, k - 1)
        ans -= now * ai

    print(ans % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


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

int main(){
    double A, B; cin >> A >> B;

    double l = max(A * 12.5, 10*B);
    double r = min((A+1)*12.5, 10*(B+1));

    int ans = ceil(l);
    if(ans < r) cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
ans = 0
c1 = 0
c2 = 0
c3 = 0
for _ in range(N):
    s = (stdin.readline().rstrip())
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        c1 += 1
    elif s[0] == "B":
        c2 += 1
    elif s[-1] == "A":
        c3 += 1
if c1 == 0:
    ans += min(c2,c3)
else:
    if c2 + c3 == 0:
        ans += (c1-1)
    else:
        ans += (c1 + min(c2,c3))
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
long long a,b;
long long GCD(long long x,long long y)
{
	if(x%y==0)return y;
	else return GCD(y,x%y);
}
int main()
{
	while(cin>>a>>b)
	{
		cout<<GCD(a,b)<<" "<<a/GCD(a,b)*b<<endl;	
	}
} 


Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,i = 1;
    while(true){
        cin>>x;
        if(i>10000){
            break;
        }
        if(x==0){
           break;
        }
        cout <<"Case "<<i<<": "<<x<<endl;
        i = i + 1;
   }
}


Measured memory_bytes: 3076
#ABC114-D 756
"""
約数の個数の求め方は、素因数分解した時の各要素の(乗数+1)をかけ合わせると求まる。
入力例2の32400を素因数分解してみると、
2^4*3^4*5^2となり、それぞれの乗数+1をかけ合わせると
(4+1)*(4+1)*(2+1) = 75となる。

また、75自体を素因数分解すると、
3^1*5^2となり、これが最小の約数であるので、
3*5*5
15*5
3*25
75
の4通りが素因数分解した時の乗数+1の候補として考えられる。

よって、約数が75個存在する数とは、基数をp,q,rとして,
p^(3-1)*q^(5-1)*r^(5-1)
p^(15-1)*q^(5-1)
p^(3-1)*q^(25-1)
p^(75-1)
のいずれかとして得られる数である。

なお、p^2*q^4*r^4の場合は4を2回使うため、combinationを使って数える必要があるのに注意。
"""
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
dic1 = defaultdict(int)

"""素因数分解"""
def factrize(n):
    b = 2
    fct = []
    while b*b <= n:
        while n % b == 0:
            n //= b
            #もし素因数を重複させたくないならここを加えてfct.append(b)を消す
            """
            if not b in fct:
                fct.append(b)
            """
            fct.append(b)
        b = b+1
    if n > 1:
        fct.append(n)
    return fct #リストが帰る

#二項係数(modなし) O(k)
def large_conbination(n,k): #no mod. return nCk.
    res1 = 1
    for i in range(n,n-k,-1):
        res1*=i
    res2 = 1
    for i in range(1,k+1):
        res2*= i
    return res1//res2

for i in range(2,n+1): #n!を素因数分解する時、各要素ごとに素因数分解しても結果は変わらない
    for j in factrize(i):
        dic1[j] += 1

def num(m):
    return len(list(filter(lambda x:x>=m-1,dic1.values())))

#解法の条件を満たす通り数の順に再現
print(
    large_conbination(num(5),2)*(num(3)-2) +
    num(15)*(num(5)-1) + 
    num(25)*(num(3)-1) +
    num(75)
)

Measured memory_bytes: 38640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    //線形探索
    static boolean linearSearch(int[] s, int n, int key){
        int i = 0;
        s[n] = key;//番兵
        while(s[i] != key){
            i++;
        }
        if(i == n){
            return false;
        }else{
            return true;
        }
    }
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try{
            int n = Integer.parseInt(br.readLine());
            String[] str1 = br.readLine().split(" ");
            int[] s = new int[n + 1];//+1は番兵の分
            for(int i = 0; i < n; i++)
                s[i] = Integer.parseInt(str1[i]);

            int q = Integer.parseInt(br.readLine());
            String[] str2 = br.readLine().split(" ");
            int[] t = new int[q];
            for(int i = 0; i < q; i++)
                t[i] = Integer.parseInt(str2[i]);

            int count = 0;
            for(int i = 0; i < q; i++)
                if(linearSearch(s, n, t[i]))
                    count++;
                

            System.out.println(count);
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 27148
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<queue>

typedef long long ll;
using namespace std;

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const int max_n = 1e5+5;
const int INF = 1e9 + 7;


int n;
int a[2001];
int ans;
int main()
{
	IOS;
	cin >> n;
	 
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a, a + n);
	//1 1 1000 1001
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
		{
			int val = lower_bound(a, a + n, a[i] + a[j]) - (a + j+1);
			ans += val;
		}
	cout << ans;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;

  vector<int> s(M, 0);  
  for ( int i = 0; i < M; i++ ) {
    int k;
    cin >> k;
    while ( k-- ) {
      int b;
      cin >> b;
      b--;
      s[i] |= (1<<b);      
    }
  }

  vector<int> p(M);
  for ( int i = 0; i < M; i++ ) {
    cin >> p[i];
  }

  int ans = 0;
  for ( int i = 0; i < (1<<N); i++ ) {
    int cnt = 0;
    for ( int j = 0; j < M; j++ ) {
      if ( __builtin_popcount(i&s[j])%2 == p[j] ) cnt++;      
    }
    if ( cnt == M ) ans++;
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{

	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin>>t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> arr(n);
		unordered_map<int, int> m;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
			m[arr[i]]++;
			sum += arr[i];
		}
		int q;
		cin >> q;
		while (q--) {
			int a, b;
			cin >> a >> b;
			int diff = (b - a) * m[a];
			sum += diff;
			m[b] += m[a];
			m.erase(a);
			cout << sum << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 7116
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int cntS[100009], cntT[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;
    int Q;
    
    cin>>s>>t>>Q;
    
    int cnt=0;
    rep(i,s.size()){
        cnt+=(s[i]=='A'?1:2);
        cntS[i+1]=cnt;
    }
    
    cnt=0;
    rep(i,t.size()){
        cnt+=(t[i]=='A'?1:2);
        cntT[i+1]=cnt;
    }
    
    
    rep(i,Q){
        int s1,s2,t1,t2;
        cin>>s1>>s2>>t1>>t2;
        
        int a=cntS[s2]-cntS[s1-1];
        int b=cntT[t2]-cntT[t1-1];
        if(abs(a-b)%3==0){
            cout1("YES")
        }else{
            cout1("NO")
        }
    }
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)
int main() {
  string B;
  cin >> B;
  int A = 0;
  rep(i, 3) {
    if(B.at(i) == 'R') {
      A++;
      if(i == 2) {
        break;
      }
      else {
        if(B.at(i + 1) == 'R') {
          A++;
          if(i == 1) {
            break;
          }
          else {
            if(B.at(i + 2) == 'R') {
              A++;
              break;
            }
            else {
              break;
            }
          }
        }
        else {
          break;
        }
      }
    }
    else if(i == 2) {
      break;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m;
ll a[MN];
pll r[MN]; //num first

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

    cin >> n >> m;
    FOR(i, 1, n){
        cin >> a[i];
    }
    FOR(i, 1, m){
        cin >> r[i].s >> r[i].f;
    }

    sort(a+1, a+n+1);
    sort(r+1, r+m+1);
    int cur = 1;
    RFOR(i, m, 1){
        if(cur > n) break;
        if(a[cur] >= r[i].f) break;
        while(r[i].s != 0){
            if(cur > n) break;
            if(a[cur] >= r[i].f) break;
            a[cur] = r[i].f;
            r[i].s--;
            cur++;
        }
    }

    ll sm = 0;
    FOR(i, 1, n){
        sm += a[i];
    }

    cout << sm << "\n";

    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const int N=200010;
struct A{
	ll in,out;
}a1[N],a2[N];
int l[N],r[N],lc[N],rc[N],fa[N];
vector<A> f[N];
ll mid;
void insert(int x,A ins){
	if(f[x].empty()) f[x].push_back(ins);
	else if(f[x][f[x].size()-1].out>ins.out){
		if(f[x][f[x].size()-1].in==ins.in) f[x].pop_back();
		f[x].push_back(ins);
	}
}
bool dfs(int x){
	if(!l[x]){
		f[x].push_back((A){0,0});
		return true;
	}
	if(dfs(l[x])==0||dfs(r[x])==0) return false;
	int t=lc[x]+rc[x],i,j,s1=0,s2=0;
	A ins;
	j=f[r[x]].size()-1;
	for(i=f[l[x]].size()-1;i>=0;i--){
		while(j>=0&&t+f[l[x]][i].out+f[r[x]][j].in>mid) j--;
		if(j>=0)
			a1[++s1]=(A){f[l[x]][i].in+lc[x],rc[x]+f[r[x]][j].out};
	}
	i=f[l[x]].size()-1;
	for(j=f[r[x]].size()-1;j>=0;j--){
		while(i>=0&&t+f[l[x]][i].in+f[r[x]][j].out>mid) i--;
		if(i>=0)
			a2[++s2]=(A){rc[x]+f[r[x]][j].in,f[l[x]][i].out+lc[x]};
	}
	for(i=1,j=s1;i<j;i++,j--) swap(a1[i],a1[j]);
	for(i=1,j=s2;i<j;i++,j--) swap(a2[i],a2[j]);
	i=1;j=1;
	while(i<=s1&&j<=s2){
		if(a1[i].in<a2[j].in) ins=a1[i++];
		else ins=a2[j++];
		insert(x,ins);
	}
	while(i<=s1) insert(x,a1[i++]);
	while(j<=s2) insert(x,a2[j++]);
	if(!f[x].size()) return false;
	else return true;
}
int n;
bool ok(){
	for(int i=1;i<=n;i++) f[i].clear();
	return dfs(1);
}
int main(){
	int i,x;
	ll lb=0,rb=0;
	scanf("%d",&n);
	for(i=2;i<=n;i++){
		scanf("%d %d",&fa[i],&x);
		if(l[fa[i]]) r[fa[i]]=i,rc[fa[i]]=x;
		else l[fa[i]]=i,lc[fa[i]]=x;
		rb+=x;
	}
	/*
	mid=15;
	printf("%d\n",ok());
	for(int i=1;i<=n;i++,printf("\n")){
		printf("%d: ",i);
		for(int j=0;j<f[i].size();j++)
			printf("(%lld %lld)",f[i][j].in,f[i][j].out);
	}
	return 0;*/
	while(rb-lb>1){
		mid=lb+rb>>1;
		if(ok()) rb=mid;
		else lb=mid;
	}
	printf("%lld\n",rb);
	return 0;
}

Measured memory_bytes: 35240
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Node{
//ノードはポインタでもっておこう
public:
  ///ノードの番号
  int num;
  //そのノードの親
  //rootの場合はnullptr
  Node* p=nullptr;
  //そのノードの子
  //葉でなければ少なくとも一つ持つ
  Node* l=nullptr;Node* r=nullptr;
};

//参照とかポインタとか気をつけよ(統一する)
//関数内はスタックに保存される
//xは根のNode
void insert(Node* &root,int k){
  //見ているNode、そのNodeの親を、それぞれx,yで管理する
  //newで確保するとポインタはスタック領域にあるので破棄されるけどnewで確保した領域はヒープ領域にあるから残ってる
  //つまり、その領域をvectorにあげれば良い
  Node* z= new Node;z->num=k;
  Node* y=nullptr;
  Node* x=root;

  while(x!=nullptr){
    y=x;
    if(z->num<x->num){
      x=x->l;
    }else{
      x=x->r;
    }
  }

  if(y==nullptr){
    root=z;
  }else{
    z->p=y;
    if(z->num<y->num){
      y->l=z;
    }else{
      y->r=z;
    }
  }
}

void pre_calc(Node* &n,vector<int>& v){
  if(n==nullptr) return;
  v.push_back(n->num);
  pre_calc(n->l,v);
  pre_calc(n->r,v);
}

void in_calc(Node* &n,vector<int>& v){
  if(n==nullptr) return;
  in_calc(n->l,v);
  v.push_back(n->num);
  in_calc(n->r,v);
}

void tree_print(Node* N){
  vector<int> vin;vector<int> vre;
  //v[0]はrootNode、vin,vreは出力したいものを入れておく
  in_calc(N,vin);
  pre_calc(N,vre);
  int le=vin.size();
  //printするところ
  for(int i=0;i<le;i++){
    cout << " " << vin[i];
  }
  cout << endl;
  for(int i=0;i<le;i++){
    cout << " " << vre[i];
  }
  cout << endl;
}

//根がx
bool find(Node* x,int k){
  while(x!=nullptr){
    if(x->num==k)return true;
    else if(x->num>k) x=x->l;
    else x=x->r;
  }
  return false;
}

int main(){
  Node* N=nullptr;
  int n;cin >> n;
  for(int i=0;i<n;i++){
    string s;cin >> s;
    if(s=="insert"){
      int z;cin >> z;
      insert(N,z);
    }else if(s=="print"){
      tree_print(N);
    }else{
      int k;cin >>k;
      //cout << find(v,k) << endl;
      if(find(N,k)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 26248
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
#define pb push_back
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int a[n],dp[n];
	dp[0]=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<n;i++){
		dp[i]=INT_MAX;
		for(int j=i-1;i-j<=k&&j>=0;j--){
			dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
		}
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
"use strict"
const fs = require('fs');
const input = fs.readFileSync("/dev/stdin", "utf8");
const range = input.toString().split(" ");
const min = parseInt(range[0]);
const max = parseInt(range[1]);
let result = 0;
for(let i = min; i <= max; i++) {
  const s = i.toString();
  if(s[0] === s[4] && s[1] === s[3]) result++;
}
console.log(result);

Measured memory_bytes: 10560
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long A[100000];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  int cur_price = 1;
  long long ans = 0;
  for(int i = 0; i < N; i++){
    if(A[i] % cur_price != 0){
      ans += (A[i] / cur_price);
    } else {
      ans += (A[i] / cur_price) - 1;
      if(A[i] == cur_price || cur_price == 1){
        cur_price ++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4412
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int D;
int c[32];
int s[512][32];
int ans[512];

void inp(){
    cin>>D;
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
}

void ans_inp(){
    for(int i=1;i<=D;i++){
        cin>>ans[i];
    }
}

void ans_ran(){
    for(int i=1;i<=D;i++){
        ans[i]=rand()%26+1;
    }
}

int man_calc(bool disp){
    int l[32]={0};
    int man=0;
    for(int i=1;i<=D;i++){
        int n=ans[i];
        l[n]=i;
        man+=s[i][n];
        for(int j=1;j<=26;j++){
            man-=c[j]*(i-l[j]);
        }
        if(disp) cout<<man<<endl;
    }
    return man;
}

void ans_disp(){
    for(int i=1;i<=D;i++){
        cout<<ans[i]<<endl;
    }
}

int change_ans(int i,int n,bool f){
    int ret=0;
    if(f){
        int fr=ans[i];
        ret+=s[i][n];
        ret-=s[i][fr];

        //cout<<ret<<endl;
        int fl=0;
        for(int j=1;j<=i-1;j++){
            if(ans[j]==fr) fl=0;
            else fl++;
        }
        for(int j=i;j<=D;j++){
            if(ans[j]==fr&&j!=i) break;
            ret-=c[fr]*(fl+1);
        }
        //cout<<ret<<endl;
        int tl=0;
        for(int j=1;j<=i-1;j++){
            if(ans[j]==n) tl=0;
            else tl++;
        }
        for(int j=i;j<=D;j++){
            if(ans[j]==n) break;
            ret+=c[n]*(tl+1);
        }
        //cout<<ret<<endl;
    }
    ans[i]=n;
    //cout<<ret<<endl;
    return ret;
}

void solve_C(){
    int M;
    cin>>M;
    int man=man_calc(false);
    //cout<<man<<endl;
    for(int i=0;i<M;i++){
        int from,to;
        cin>>from>>to;
        int cng=change_ans(from,to,true);
        man+=cng;
        cout<<man<<endl;
    }
}

void random_solve(){
    int seed=1234;
    int cnt=6000000;
    srand(seed);
    ans_ran();
    for(int i=0;i<=cnt;i++){
        int ci=rand()%D+1;
        int tn=rand()%26+1;
        int fn=ans[ci];
        int cng=change_ans(ci,tn,true);
        if(cng<0){
            change_ans(ci,fn,false);
        }
    }
    ans_disp();
    //cout<<man_calc(false)<<endl;
}

signed main(){
    inp();
    //ans_inp();
    //solve_C();
    random_solve();
    return 0;
}



Measured memory_bytes: 3292
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: chars, y: chars
    }

    println!("{}", if x[0] < y[0] {"<"} else if x[0] > y[0] {">"} else {"="});
}

Measured memory_bytes: 4476
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);

            string[] a = Console.ReadLine().Split(' ');
            int count = 0;
           
            for(int i = 0;i < n;i++)
            {
                long ai = long.Parse(a[i]);
                if(k <= ai)
                    count++;

            }

            Console.WriteLine(count);
        }
    }

Measured memory_bytes: 15584
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<vector<pair<ll, int>>> edge(n + 1);

    rep(i, n - 1){
        int a,b;
        ll c;
        cin >> a >> b >> c;

        edge[a].pback(mpair(c,b));
        edge[b].pback(mpair(c,a));
    }

    int q,k;
    cin >> q >> k;

    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;

    pq.push(mpair(0, k));
    vector<ll> mind(n + 1, LLONG_MAX);

    while(!pq.empty()){

        int node = pq.top().second;
        ll tmpd = pq.top().first;

        if(mind[node] > tmpd){
            mind[node] = tmpd;

            rep(i, edge[node].size()){
                ll d = edge[node][i].first;
                int next = edge[node][i].second;
                pq.push(mpair(tmpd + d, next));
            }
        }

        pq.pop();
    }

    rep(i,q){
        int x,y;
        cin >> x >> y;

        cout << mind[x] + mind[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
#include<inttypes.h>//__int64,__int128..
#define MAX_N 300005
//vector&pair
#define pb push_back
#define mp make_pair
//math
#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))//Regardless of type
//for pair
#define fi first
#define se second
//infinit
#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
//MOD
#define MOD 1000000007LL
using namespace std;
//type
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef long double LD;
int n;
char s[MAX_N];
int main(){
	int i,x,y,ans=MAX_N;
	scanf("%d",&n);
	scanf("%s",s);
	x=y=0;
	for(i=0;i<n;i++){
		if(s[i]=='E')	y++;
	}
	for(i=0;i<n;i++){
		if(s[i]=='E')	y--;
		ans=min(ans,x+y);
		if(s[i]=='W')	x++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
str = input()
str = list(str)


for index, value in enumerate(str):
    if (value == '?' and index == len(str) - 1):
        str[index] = 'D'

    elif (value == '?' and index != 0 and str[index - 1] == 'P'):
        str[index] = 'D'

    elif (value == '?' and str[index + 1] == '?'):
        str[index] = 'P'
        str[index + 1] = 'D'
    elif (value == '?'):
    	str[index] = 'D'


print(''.join(str))

Measured memory_bytes: 10728
#include <iostream>
using namespace std;
int main(){
	int N, M, P;
	while( 1 ){
		cin >> N >> M >> P;
		if( N == 0 && M == 0 && P == 0 ) break;
		int money = 0, mn;
		for( int i = 1; i <= N; i++ ){
			int j;
			cin >> j;
			if(M == i) mn = j;
			money += j;
		}
		if( mn == 0 ){
			cout << 0 << endl;
		}else{
			money = money * (100 - P) / mn;
			cout << money << endl;
		}
	}
}

Measured memory_bytes: 1160