akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
	int a,b,c,d,ans;
	cin>>a>>b>>c>>d;
	ans=-1e18;
	ans=max(ans,a*c);
	ans=max(ans,a*d);
	ans=max(b*c,ans);
	ans=max(b*d,ans);
	cout<<ans;
	return 0;
}


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

using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> V(N);
  for(auto& v : V)
  {
    cin >> v;
  }
  
  vector<int> dp(N, INT_MAX);
  
  dp[0] = 0;
  dp[1] = abs(V[1] - V[0]);
  
  for(int i = 2; i < N; ++i)
  {
    for(int j = i - 1; j >= i - 2 and j >= 0; --j)
    {
      dp[i] = min(dp[i], dp[j] + abs(V[i] - V[j]));
    }
  }
  
  cout << dp[N - 1] << "\n";
  
  return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;
	int a[n][3];
	for(int i = 0; i < n; i++){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}

	for(int i = 1; i < n; i++){
		a[i][0] += max(a[i-1][1], a[i-1][2]);
		a[i][1] += max(a[i-1][0], a[i-1][2]);
		a[i][2] += max(a[i-1][0], a[i-1][1]);
	}

	cout << max(a[n-1][0], max(a[n-1][1], a[n-1][2]));

	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main (void)
{
	int a,b;
	char op;
	
	while(1){
		
			scanf("%d %c %d\n",&a,&op,&b);

		if(op=='+'){
			
			printf("%d\n",a+b);
		
		}else if(op=='-'){
		
		printf("%d\n",a-b);
			
		}else if(op=='*'){
			
			printf("%d\n",a*b);
			
		}else if(op=='/'){
			
			printf("%d\n",a/b);
			
		}else{
			break;
		}
	}
		return 0;	
}

Measured memory_bytes: 604
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut bv = vec![0usize; n - 1];
    for i in 0..n - 2 {
        bv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    bv[n - 2] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut av = vec![0usize; n];
    av[0] = bv[0];
    for i in 1..n - 1 {
        av[i] = min(bv[i - 1], bv[i]);
    }
    av[n - 1] = bv[n - 2];

    let mut ans = 0;
    for i in 0..n {
        ans += av[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std; 
typedef long long lli;
#define mod 1000000007
#define fori(n) for(int i=0;i<n;i++)
#define forj(n) for(int j=0;j<n;j++)
#define forli(n) for(lli i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(),a.end())
 
//FUNCTONS
lli llipower(lli x, lli y){lli res = 1; while (y > 0){if (y & 1) res = (res*x); y = y>>1;x = (x*x);}return res;}
lli llipowerp(lli x, lli y,lli p){lli res = 1;x = x % p; while (y > 0){if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}
lli gcd(lli a, lli b){ if (!a) return b; return gcd(b%a,a);}
lli binarySearch(vector<int> arr, int l, int r, int x){ 
	if (r >= l) { 
		lli mid = l + (r - l) / 2; 
		if (arr[mid] == x) return mid; 
		if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); 
		return binarySearch(arr, mid + 1, r, x); 
	}return -1;
}
template <typename T> void printvec(vector<T> inp){for(int i=0;i<inp.size();i++){cout<<inp[i]<<" ";}cout<<endl;}
template <typename T> T ceildiv(T x, T y){return 1 + ((x - 1) / y);}
lli modInverse(lli a, lli m){lli g = gcd(a, m);if (g != 1) return -1;else return llipowerp(a, m-2, m);} 

int main(){
    long double n;
    cin>>n;
    long double ans=n/3;
    ans=ans*ans*ans;
    cout << setprecision(10)<<ans << endl;
}
 


Measured memory_bytes: 256
n,y=map(int,input().split())
a,b,c=-1,-1,-1
x=y//1000-n
if y%1000==0:
  for i in range(n+1):
    for j in range(n+1-i):
      if x==9*i+4*j:
        a=i
        b=j
        c=n-i-j
        break
    if a!=-1:
      break
print(a,b,c)

Measured memory_bytes: 9180
from heapq import *

def prim(V, E):
    '''
    Input:
        V = list(range(N))
        E = {i: defaultdict(int) for i in range(N)}
    Output:
        the edges of the minimum weight tree and its weight
    '''
    N = len(V)
    weight = 0; edges = [];
    used = [False]*N; used[0] = True; n_used = 1;
    heap = [(c, 0, v) for v, c in E[0].items()]; heapify(heap)
    while heap and n_used < N:
        c, u, v = heappop(heap)
        if used[v]: continue
        used[v] = True; n_used += 1; edges.append((u, v))
        weight += c
        for w, d in E[v].items():
            if not used[w]: heappush(heap, (d, v, w))
    return edges, weight

N = int(input())
cities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]
sorted_x, sorted_y = sorted(cities, key=lambda x:x[0]), sorted(cities, key=lambda x:x[1])
E = {i: {} for i in range(N)}
for i in range(N-1):
    (a1, _, u), (a2, _, v) = sorted_x[i], sorted_x[i+1]
    E[u][v] = min(a2 - a1, E[u][v]) if E[u].get(v) is not None else a2 - a1
    E[v][u] = E[u][v]
    (_, b1, u), (_, b2, v) = sorted_y[i], sorted_y[i+1]
    E[u][v] = min(b2 - b1, E[u][v]) if E[u].get(v) is not None else b2 - b1
    E[v][u] = E[u][v]
V = list(range(N))
_, ans = prim(V, E)
print(ans)

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

int main()
{
  int n;
  cin >> n;
  vector<int> s(n, 0);
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 10; ++j){
      int k;
      cin >> k;
      s[i] += k << j;
    }
  }
  vector<vector<int>> b(n, vector<int>(11));    
  for(auto& i : b){
    for(auto& j : i){
      cin >> j;  
    }
  }
  
  int ret = INT_MIN;
  int fin = 1 << 10;
  for(int i = 1; i < fin; ++i){
    int tempret = 0;
    for(int j = 0; j < n; ++j){
      int check = s[j] & i;
      int count = 0;
      while(check != 0){
        if(check & 1){
          ++count;
        }
        check = check >> 1;
      }
      tempret += b[j][count];
    }
    ret = max(ret, tempret);
  }
  cout << ret << endl;
  
  return 0;
}


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

typedef long long ll;
typedef long double ld;

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

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

int main(){

    ll r, g, b;

    cin >> r >> g >> b;

    cout << ((g * 10 + b) % 4 ? "NO" : "YES") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=2e6+1;
int n,k;
char c[N];
int main(){
	ios::sync_with_stdio(false);
	ll d;
	cin >> n >> d;
	int ans=0;
	for(int i=1; i<=n ;i++){
		ll x,y;
		cin >> x >> y;
		if(x*x+y*y<=d*d) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3656
import sys

while True:
    data = sys.stdin.readline().strip().split(' ')
    x = int(data[0])
    y = int(data[1])
    if x == 0 and y == 0:
        break
    if x < y:
        print('%d %d' % (x, y))
    else:
        print('%d %d' % (y, x))
        

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

int main(){
	long long n,t,a,ans = 0;
	int l = 0;
	cin >> n >> t;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a-l < t) ans += a-l;
		else ans += t;
		l = a;
	}
	cout << ans+t << endl;
}

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

int main(){
    int sx, sy, tx, ty;
    string ans = "";

    cin >> sx >> sy >> tx >> ty;
    for(int i=sy;i<ty;i++) ans += 'U';
    for(int i=sx;i<tx;i++) ans += 'R';
    for(int i=ty;i>sy;i--) ans += 'D';
    for(int i=tx;i>sx;i--) ans += 'L';
    ans += 'L';
    for(int i=sy;i<=ty;i++) ans += 'U';
    for(int i=sx;i<=tx;i++) ans += 'R';
    ans += 'D';
    ans += 'R';
    for(int i=ty;i>=sy;i--) ans += 'D';
    for(int i=tx;i>=sx;i--) ans += 'L';
    ans += 'U';
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<int> a = {0};
    vector<int> b = {s[0] - '0'};
    int now = s[0] - '0';
    rep(i, n){
        if(now == s[i] - '0'){
            a.back()++;
            continue;
        }
        now ^= 1;
        b.push_back(now);
        a.push_back(1);
    }

    vector<int> ss(SZ(a) + 1);
    rep(i, SZ(a)) ss[i+1] = a[i] + ss[i];

    int ans = 0;
    for(int i = 0; i < SZ(ss); i++){
        int len = k * 2;
        if(b[i] == 1){
            len++;
        }
        ans = max(ans, ss[min(i+len, SZ(ss) - 1)] - ss[i]);
    }
    cout << ans << endl;

    return 0;
}


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

int main(void)
{
	int n,i,max=0,s;
	double min,d;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>max)
			max=a[i];
	}
	min=abs(a[0]-(double)max/2);
	s=a[0];
	for(i=1;i<n;i++)
	{
		d=abs(a[i]-max/2);
		if(d<=min && a[i]!=max){
			min=d;
			s=a[i];
		}
	}
	printf("%d %d",max,s);
	return 0;
}
		

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> A;
    map<ll, ll> x;
    rep(i, N){
        ll tmp;
        cin >> tmp;
        if (x.find(tmp) != x.end()){
            x[tmp] += 1;
        } else {
            x[tmp] = 1;
            A.push_back(tmp);
        }
    }
    sort(A.begin(), A.end(), greater<ll>());

    vector<ll> ans;
    for (auto a: A){
        if (ans.size() >= 2){break;}
        if (x[a] >= 4){ans.push_back(a); ans.push_back(a); break;}
        if (x[a] >= 2){ans.push_back(a);}
    }
    if (ans.size() >= 2){
        cout << ans.at(0) * ans.at(1) << endl;
    } else {
        cout << 0 << endl;
    }
}

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


Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 1e6;

bool first_occ[N+5];
int arr[N+5];
int n;
int ans=0;


int main(){
    AC
    cin>>n;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        arr[a]++;
    }

    for(int i=1; i<=N; i++){
        if(arr[i]==0) continue;
        for(int j=i*2; j<=N; j+=i)
            arr[j]=0;
        if(arr[i]==1) ans++;
    }
    cout<<ans<<nl;
}

Measured memory_bytes: 7508
//Resting_Prince
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b)    for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

ll dp[100005]={0},n,m,visited[100055]={0},deg[100005]={0};
vector<ll> g[100005];
stack<ll> s;

void dfs(ll n)
{
    if(visited[n]==1)return;
    visited[n]=1;
    if(g[n].size()!=0)
    rep(i,0,g[n].size()-1)dfs(g[n][i]);
    s.push(n);
}

int main()
{
    ll k,l,o,p;
    cin>>n>>m;
    rep(i,0,m-1)cin>>k>>l,g[k].pb(l),deg[l]++;
    rep(i,0,n-1)
    {
        if(deg[i+1]==0)
        dfs(i+1);
    }
    while(!s.empty())
    {   o=s.top();
        if(g[o].size()!=0)
        {for(auto t:g[o])
        dp[t]=max(dp[t],dp[o]+1);}
        s.pop();
    }p=0;rep(i,0,n)p=max(p,dp[i]);
    cout<<p<<en;
    return 0;
}


Measured memory_bytes: 12032
def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))

N, M = s_input()
L, R = [], []

for i in range(M):
    Li, Ri = s_input()
    L.extend([Li])
    R.extend([Ri])

L_max = max(L)
R_min = min(R)

num = R_min - L_max

if num >= 0:
    print(num + 1)
else:
    print(0)

Measured memory_bytes: 11008
H, W=map (int, input().split(' '))
z=[]

for i in range(H):
    z.append(list(str(input())))

#上下左右なので斜めは消す
dx = [ 0,  -1,  1,   0, ]
dy = [ 1,   0,  0,  -1, ]

for h in range(H):
    for w in range(W):
        if z[h][w] == '#': 
            p=0
            for i in range(4):
                x = w + dx[i]
                y = h + dy[i]

                if x < 0 or y <0 or x > W-1 or y >H-1:
                    continue

                if z[y][x]=="#":
                    p+=1
            if p==0:
                print('No')
                exit()

print('Yes')

Measured memory_bytes: 3064
def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = gcd(l_gcds[-1], nums[i])
        r = gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))

Measured memory_bytes: 14452
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int max = 0, impNum;
    for (int i = 0; i < n; i++){
        int ind, num;
        cin >> ind >> num;
        if (ind > max) {
            max = ind;
            impNum = num;
        }
    }
    cout << max + impNum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
int f(string a, string b){
    int cnt = 0;
    for(int i = 0; i < a.size(); i++)
        cnt += (a[i] != b[i]);
    return cnt;
}
int main(){
    //fast;
    string S, T;
    int ans = 1e9;
    cin >> S >> T;
    for(int i = 0; i < S.size() - T.size() + 1; i++){
        string str = S.substr(i, T.size());
        ans = min(ans, f(str, T));
    }
    cout << (T == S? 0 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back 
#define pf push_front 
 
int main ()
{
    ios_base::sync_with_stdio(false) ; 
    cin.tie(NULL) ;
 
    deque <char> d ;

    string s ;
    cin >> s ; 

    for (int i = 0 ; i < s.size() ; i++)
    {
        d.pb(s[i]) ;
    }

    int q ;
    cin >> q ;
    int rev_count = 0 ;
 
    while (q--)
    {
        int op , pos ;
        char aux;
        cin >> op ;
 
        if (op == 1)
        {
            rev_count++ ;
        }
        else if (op == 2)
        {
            cin >> pos >> aux ;
 
            if (pos == 1 && rev_count % 2 != 0)
            {
                d.pb(aux);
            }
            else if (pos == 1 && rev_count % 2 == 0)
            {
                d.pf(aux);
            }
            else if (pos == 2 && rev_count % 2 != 0)
            {
                d.pf(aux);
            }
            else if (pos == 2 && rev_count % 2 == 0)
            {
                d.pb(aux);
            }
 
        }
    }
 
    if (rev_count % 2 != 0)
    {
        deque <char> :: reverse_iterator rit = d.rbegin() ;

        for (rit = d.rbegin() ; rit != d.rend() ; rit++) 
        {
            cout << *rit ; 
        }

        cout << endl ;
    }
    else
    {
        deque <char> :: iterator it ; 

        for (it = d.begin() ; it != d.end() ; it++) 
        {
            cout << *it ; 
        }

        cout << endl ;
    }
    
    return 0 ;
}

Measured memory_bytes: 976
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define N_MAX 300000
#define DIGIT_MAX 62
#define MOD 1000000007

int table[N_MAX][DIGIT_MAX];

long long int modpow(long long int base, long long int p)
{
	if (0 == p){
		return 1;
	}
	if (0 == p % 2){
		long long int val = modpow(base, p / 2);
		return (val*val) % MOD;
	}
	else{
		return (modpow(base, p - 1)*base) % MOD;
	}
}

void solv()
{
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++){
		long long int a; scanf("%lld", &a);
		for (int d = 0; d < DIGIT_MAX; d++){
			table[i][d] = a % 2;
			a = a / 2;
		}
	}

	int sum[DIGIT_MAX];
	fill(sum, sum + DIGIT_MAX, 0);
	for (int i = 0; i < N; i++){
		for (int d = 0; d < DIGIT_MAX; d++){
			sum[d] += table[i][d];
		}
	}

	long long int ret = 0;
	for (int i = 0; i < N; i++){
		long long int base = 1;
		for (int d = 0; d < DIGIT_MAX; d++){
			if (0 == table[i][d]){
				ret = (ret + base*(long long int)sum[d]) % MOD;
			}
			else{
				ret = (ret + base*(long long int)(N - sum[d])) % MOD;
			}
			base = (base * 2) % MOD;
		}
	}

	printf("%lld", (ret * modpow(2, MOD - 2)) % MOD);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

int main(void) {
	int a, b, c;
	int min;
	cin >> a >> b >> c;
	min = 100000000;
    if (min > b + c) {
		min = b + c;
	}
	if (min > a + c) {
		min = a + c;
	}
	if (min> a + b) {
		min = a + b;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main() {
	
	int N;
	int K;
	int RP;
	int SP;
	int PP;
	int myCH[100000];
	char T[100000];
	long ans = 0;

	scanf("%d %d", &N, &K);
	scanf("%d %d %d", &RP, &SP,&PP);
	scanf("%s", T);

	for (int i = 0; i < N; i++) {
		if (T[i] == 'r') {
			if (i >= K && myCH[i - K] == 'p') {
				continue;
			}
			else {
				myCH[i] = 'p';
				ans += PP;
			}
		}
		else if (T[i] == 's') {
			if (i >= K && myCH[i - K] == 'r') {
				continue;
			}
			else {
				myCH[i] = 'r';
				ans += RP;
			}
		}
		else if (T[i] == 'p') {
			if (i >= K && myCH[i - K] == 's') {
				continue;
			}
			else {
				myCH[i] = 's';
				ans += SP;
			}
		}
	}

	printf("%ld", ans);

	return 0;
}



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

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pr pair<int,int>
#define SZ(S) int(S.size())
#define REP(i,a,b) for(int i=a;i<b;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,b,a) for(int i=b;i>=a;--i)
#define CLR(A,x) memset(A,x,sizeof(A))
#define ALL(S) S.begin(),S.end()

#define OUT(a,l,r) cout<<#a": ";FOR(i,l,r)cout<<a[i]<<" ";cout<<endl
#define PRT(a) cout<<"--> "#a" "<<a<<endl

using namespace std;
typedef long long ll;

const int N=800005;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
const ll P=1e9+7;

template<typename T>
inline void read(T& x,int f=1,char s=getchar()) {
	for(x=0;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1; 
	while(s<='9'&&s>='0') x=x*10+s-'0',s=getchar();x*=f;
}

#define ne (o<<1)
#define mid ((l+r)>>1)

int e[N];
int L[N],R[N];
int a[N],c[N];
ll f[N],g[N];
int n,k,num;

void push(int o) {
	if(e[o]&&ne<N-1) e[ne]=e[ne|1]=e[o];
	e[o]=0;
}

void upd(int o,int l,int r,int L,int R,int v) {
//	if(o==1) cout<<"UPD: "<<L<<" "<<R<<endl;
//	cout<<"Upd: "<<o<<" "<<l<<" "<<r<<" "<<L<<" "<<R<<" "<<v<<endl;
	if(L<=l&&r<=R) {e[o]=v;return;}
	push(o);
	if(L<=mid) upd(ne,l,mid,L,R,v);
	if(R>mid) upd(ne|1,mid+1,r,L,R,v);
}

int que(int o,int l,int r,int P) {
//	cout<<"Que: "<<o<<" "<<l<<" "<<r<<" "<<P<<" "<<e[o]<<endl;
	if(e[o]||l==r) return e[o];
	if(P<=mid) return que(ne,l,mid,P);
	return que(ne|1,mid+1,r,P);
}

int main() {
	ll ans=INF,sum=0;
	int tp,j;
//	int num=19;
//	while(1) {
//		cin>>tp;
//		if(tp==1) {
//			int l,r,v;
//			cin>>l>>r>>v;
//			upd(1,1,num,l,r,v);
//		}
//		else {
//			int P;
//			cin>>P;
//			cout<<"xx: "<<que(1,1,num,P)<<endl;
//		}
//		cout<<"-----------------------"<<endl;
//	}
	
	read(n),read(k);
	FOR(i,1,n) {
		read(a[i]),read(tp);
		if(tp==1) {
			if(a[i]*2>k) {cout<<-1<<endl;return 0;}
			L[i]=sum;
			R[i]=(sum-(2*a[i])%k+k)%k;//
		}
		else {
			L[i]=0;
			R[i]=k-1;
		}
		sum=(sum-(2*a[i])%k+k)%k;  
//		PRT(sum);
	}
	
	FOR(i,1,n) c[++num]=L[i],c[++num]=R[i];
	sort(c+1,c+num+1),num=unique(c+1,c+num+1)-c-1;
	FOR(i,1,n) {
//		cout<<"=>  "<<L[i]<<" "<<R[i]<<endl;
		L[i]=lower_bound(c+1,c+num+1,L[i])-c;
		R[i]=lower_bound(c+1,c+num+1,R[i])-c;
//		cout<<"--> "<<L[i]<<" "<<R[i]<<endl;
	}
//	PRT(num);
//	OUT(c,1,num);
	FORD(i,n,1) {
		j=que(1,1,num,L[i]);
		if(j) f[i]=f[j]+(c[L[j]]-c[L[i]]+k)%k;
//		j=que(1,1,num,R[i]);
//		if(j) g[i]=g[j]+(c[L[j]]-c[L[i]]+k)%k;
//		cout<<"FUCK?"<<endl;
		if(L[i]<=R[i]) {
            if(R[i]<num) upd(1,1,num,R[i]+1,num,i);
            if(L[i]>1) upd(1,1,num,1,L[i]-1,i);  
        }  
        else if(R[i]+1<L[i]) upd(1,1,num,R[i]+1,L[i]-1,i);  
	}
	
	FOR(i,1,num) {
		int j=que(1,1,num,i);
		if(!j) {
//			cout<<"CAO? "<<i<<endl;
			ans=0;break;
		}
		ans=min(ans,f[j]+(c[L[j]]-c[i]+k)%k);
	}
//	cout<<ans<<endl;
	FOR(i,1,n) ans+=a[i]*2;
	cout<<ans<<endl;
	
//	cout<<"TEST: "<<que(1,1,num,10)<<endl;
	
}
/*
5 6
5 2
1 1
4 2
3 1
5 2
*/

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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
int main()
{
    quicker
    int n;
    cin >> n;
    cout << (n + 1) / 2;
    return 0;
}


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

using namespace std;

int main()
{
	// 入力
	int N, M;
	cin >> N >> M;
	// 好物の配列はM種類、0初期化する。
	vector<int> FavoriteFoodCount(M, 0);
	
	for (int i = 0; i < N; i++)
	{
		int K;
		cin >> K;
		for (int j = 0; j < K; j++)
		{
			int A;
			cin >> A;
			// 先頭の要素がKになるため、Aを先頭にするために1を引く
			A--;
			// 食べ物Aの好物のカウントを1
			FavoriteFoodCount[A]++;
		}
	}
	
	int answer = 0;
	// 好物の配列に対する
	for (int i = 0; i < M; i++)
	{
		// N人全員の食べ物の場合
		if (FavoriteFoodCount[i] == N)
		{
			answer++;
		}
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
s=list(input())
k=int(input())
s.append(-1)
i=0
ans=-1
while True:
    if s[i]=="-1":
        ans=s[i]
        break
    if s[i]!="1":
        ans=s[i]
        if i+1>k:
            ans="1"   
        break
    i+=1
print(ans)


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

typedef long long int ll;
typedef vector<int> vec;
typedef vector<vec> mat;

typedef priority_queue<int, vec, greater<int> > QUE;

int main() {
    int N, M;
    string str;
    QUE que;

    cin >> str;
    cin >> N;

    vec v(str.size());
    for (int i = 0; i < str.size(); i++) {
        v[i] = 'z' - str[i] + 1;
        if (v[i] == 26) v[i] = 0;
    }

    for (int i = 0; i < str.size(); i++) {
        if (v[i] <= N) {
            N -= v[i];
            str[i] = 'a';
        }
    }

    if (N) {
        str[str.size()-1] = 'a' + ((str[str.size()-1] - 'a') + N) % 26;
    }

    cout << str << endl;

    return 0;
}


Measured memory_bytes: 896
<?php

$n = trim(fgets(STDIN));

$ans = 0;
for($i=1; $i<=$n; $i++){
  $q = $i;
  $count = 0;
  $j = 1;
  while($j<=$q){
    if($q%$j == 0) $count++;
    $j++;
  }
  if ($count==8 && $q%2==1) $ans++;
}

echo $ans;

?>
  

Measured memory_bytes: 4604
#include<stdio.h>
#include<string.h>

int main(){
  char d[7][4]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  char s[4];
  int i;
  scanf("%s",s);
  for(i=0;i<7;i++){
    if(strcmp(s,d[i])==0){
      printf("%d",7-i);
    }
  }
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

int main() {
    ll n,sum,ans1=0,ans2=0;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    sum=0;
    for(ll i=0;i<n;i++){
        sum+=a[i];
        if(sum<=0&&i%2==1){
               ans1+=(1-sum);
               sum=1;
        }
        if(sum>=0&&i%2==0){
                ans1+=(sum+1);
                sum=-1;
        }
    }
    sum=0;
    for(ll i=0;i<n;i++){
        sum+=a[i];
        if(sum<=0&&i%2==0){
               ans2+=(1-sum);
               sum=1;
        }
        if(sum>=0&&i%2==1){
                ans2+=(sum+1);
                sum=-1;
        }
    }
    cout << min(ans1,ans2) << endl;
	return 0;
}

Measured memory_bytes: 1024
class PriorityQueue
  def initialize
    @heap = []
  end

  def push value
    @heap.push value
    update_heap_to_up
  end

  def empty?
    @heap.empty?
  end

  def shift
    min, last = @heap[0], @heap.pop
    unless @heap.empty?
      @heap[0] = last
      update_heap_to_down
    end
    min
  end

  alias pop shift

  private

  def update_heap_to_up
    index    = @heap.size - 1
    up_value = @heap[index]
    while 0 <= (parent_index = (index - 1) / 2)
      parent_value = @heap[parent_index]
      break if parent_value <= up_value

      @heap[index] = parent_value
      index        = parent_index
    end
    @heap[index] = up_value
  end

  def update_heap_to_down
    index      = 0
    down_value = @heap[0]
    size       = @heap.size
    while (child_index = 2 * index + 1) < size
      # 右の子がいて、右の子が小さければ、右の子を使う
      child_index += 1 if child_index + 1 < size and @heap[child_index + 1] < @heap[child_index]
      child_value = @heap[child_index]
      break if down_value <= child_value

      @heap[index] = child_value
      index        = child_index
    end
    @heap[index] = down_value
  end
end

MAX_V = 50 # 制約の最大値。
MAX_S = MAX_V * 50 + 5
INF   = Float::INFINITY

#　頂点
Edge = Struct.new(:to, :a, :b)
#　両替所
Exchange = Struct.new(:v, :s, :x) do
  include Comparable
  def <=>(other)
    self.x <=> other.x
  end
end

g    = Array.new(MAX_V) { Array.new { Edge.new } }
dist = Array.new(MAX_V) { Array.new(MAX_S + 5) { INF } }

def input
  gets.split.map &:to_i;
end

# メイン
n, m, s = input
#　都市の入力
m.times do
  u, v, a, b = input
  u          = u.pred
  v          = v.pred
  g[u] << Edge.new(v, a, b)
  g[v] << Edge.new(u, a, b)
end

# プライオリティキューのライブラリを利用
# require 'pqueue'
# 銀貨は最大でもMAX_S
s = [s, MAX_S].min
# プライオリティーキュー
q = PriorityQueue.new
# 入力用ラムダ
push = lambda { |v, s, x|
  return if s < 0
  return if dist[v][s] <= x

  dist[v][s] = x
  q.push(Exchange.new(v, s, x))
}

c = []
d = []
n.times do |i|
  cc, dd = input
  c[i]   = cc
  d[i]   = dd
end
push.call(0, s, 0)
until q.empty?
  hoge = q.pop
  v    = hoge.v; s = hoge.s; x = hoge.x
  next if dist[v][s] != x

  ns = [s + c[v], MAX_S].min
  push.call(v, ns, x + d[v])

  g[v].each do |e|
    push.call(e.to, s - e.a, x + e.b)
  end
end


(1 ... n).each do |i|
  ans = INF
  (0 ... (MAX_S + 5)).each do |j|
    ans = [ans, dist[i][j]].min
  end
  puts ans
end

Measured memory_bytes: 21404
n = int(input())
d = {}
c = 0
for i in range(n):
    s = input()
    s = tuple(sorted(s)) #文字列をsort
    if s in d:
        c = c + d[s]
        d[s] = d[s] + 1
    else:
        d[s] = 1
print(c)

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


void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
     Egriiiiiiiii() ;

     int n ;
     cin>>n;
     vector<pair<int,int> >v(n);
     int a,b;
     for(int i=0 ;i<n ;i++){
       cin>>a>>b;
       v[i].second=a;
       v[i].first=b ;
     }
     sort(v.begin(),v.end()) ;
     ll arr[n]={0} ; arr[0]=v[0].second ;
     for(int i=1 ;i<n ;i++){
        arr[i]=arr[i-1]+v[i].second ;
     }
     for(int i=0 ;i<n ;i++){
        a=v[i].first ;
        if(a<arr[i]){
            cout<<"No"<<"\n" ;
            return 0;
        }
     }
     cout<<"Yes\n" ;
     return 0;
}


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

bool compare(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second != b.second) return a.second > b.second;
  return a.first < b.first;
}

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

  map<int, int> om;
  map<int, int> em;
  for (int i = 0; i < n / 2; i++) {
    int o, e;
    scanf("%d%d", &o, &e);
    om[o]++;
    em[e]++;
  }

  if (om.size() == 1 && em.size() == 1) {
    int key1, key2;
    for (auto e : om) key1 = e.first; 
    for (auto e : em) key2 = e.first;
    if (key1 == key2) {
      printf("%d", n / 2);
    } else {
      printf("0");
    }
    return 0;
  }

  vector<pair<int, int>> ov;
  for (auto e : om) ov.push_back(make_pair(e.first, e.second));
  vector<pair<int, int>> ev;
  for (auto e : em) ev.push_back(make_pair(e.first, e.second));
  sort(ov.begin(), ov.end(), compare);
  sort(ev.begin(), ev.end(), compare);

  int ans = 0;
  int O1_key = ov.at(0).first;
  int O1 = ov.at(0).second;
  int E1_key = ev.at(0).first;
  int E1 = ev.at(0).second;
  ans = n - O1 - E1;
  if (O1_key == E1_key) {
    int O2 = ov.at(1).second;
    int E2 = ev.at(1).second;
    ans = min((n - O1 - E2), (n - O2 - E1));
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 6136
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int mod = 1000000007;
        long sum = 0;
        long[] a = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextLong();
            sum += a[i];
            sum %= mod;
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            sum -= a[i];
            if(sum < 0) sum += mod;
            ans += sum * a[i];
            ans %= mod;
        }

        System.out.println(ans);
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0)
        : x((x % mod + mod) % mod)
    {
    }
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint& operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint& operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint combination(int n, int k)
{
    mint res = 1;
    for (int i = 0; i < k; i++) {
        res = res * mint(n - i) * mint(i + 1).inv();
    }
    return res;
}
int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    mint ans = mint(2).pow(n) - 1 - combination(n, a) - combination(n, b);
    cout << ans.x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int K, S;
	cin >> K >> S;
	int count = 0;
	rep0(i, K) {
		rep0(j, K) {
			int a = S - i - j;
			if(0<=a && a <=K){
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# モジュールのインポート
import math


def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    S = int(input())

    return S


def combinations_count(n: int, r: int) -> int:
    """
    組み合わせの総数を取得する.

    Args:\n
        n (int): 整数
        r (int): 整数(r <= n)

    Returns:\n
        int: 組み合わせの総数
    """
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main(S: int) -> None:
    """
    メイン処理.

    Args:\n
        S (int): 整数(1 <= S <= 2000)
    """
    # 求解処理
    a = S // 3
    b = S % 3
    ans = 0
    while a > 0:
        ans += combinations_count(b + a - 1, b)
        a -= 1
        b += 3
    ans %= 10**9 + 7

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    S = get_input()

    # メイン処理
    main(S)


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

int main()
{
    int n;cin >> n;
    vector<int> A(n);
    int sum;
    cin >> A[0];
    sum=A[0];
    for (int i=1;i<n;i++)
    {
        cin >> A[i];
        sum^=A[i];
    }
    for (int i=0;i<n;i++)
    {
        int ans=sum^A[i];
        cout << ans <<" ";
    }
    cout << endl;
    return 0;
} 

Measured memory_bytes: 4052
import java.util.Scanner;
import java.util.Arrays;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = b - a;
        int K = 0;
        for (int i = 1; i <= ans; i++) {
            K += i;
        }
        System.out.println(K - b);
    }
}

Measured memory_bytes: 22100
import sys

sys.setrecursionlimit(2 ** 20)  # 再帰回数上限の向上 かなり多くしないとREになる


class Node:
    def __init__(self,
                 parent,
                 left,
                 right):
        self.parent = parent
        self.left = left
        self.right = right


n = int(input())
T = {key: Node(None, None, None) for key in range(n)}  # 初期化
for _ in range(n):
    tmp = list(map(int, input().split()))
    # 左から処理
    if tmp[1] != -1:
        T[tmp[0]].left = tmp[1]  # 子の代入
        T[tmp[1]].parent = tmp[0]  # 親の代入
    if tmp[2] != -1:
        T[tmp[0]].right = tmp[2]  # 子の代入
        T[tmp[2]].parent = tmp[0]  # 親の代入


def preorder(t: dict, p: int, pre_ls: list):
    pre_ls.append(p)
    if t[p].left is not None:
        preorder(t, t[p].left, pre_ls)
    if t[p].right is not None:
        preorder(t, t[p].right, pre_ls)


def inorder(t: dict, p: int, in_ls: list):
    if t[p].left is not None:
        inorder(t, t[p].left, in_ls)
    in_ls.append(p)
    if t[p].right is not None:
        inorder(t, t[p].right, in_ls)


def postorder(t: dict, p: int, post_ls: list):
    if t[p].left is not None:
        postorder(t, t[p].left, post_ls)
    if t[p].right is not None:
        postorder(t, t[p].right, post_ls)
    post_ls.append(p)


for id, node in T.items():
    if node.parent is None:
        ROOT = id

a, b, c = [], [], []
preorder(T, ROOT, a)
inorder(T, ROOT, b)
postorder(T, ROOT, c)

print('Preorder')
print('', *a)
print('Inorder')
print('', *b)
print('Postorder')
print('', *c)



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
using namespace std;
const int MAXN = 1e5 + 10, mod = 1e9 + 7, INF = 1e9;

int qpow(int a, int b)
{
	int res(1);
	while(b)
	{
		if(b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return res;
}

int mul(int x)
{
	int res(1);
	rep(i, 2, x) (res *= i) %= mod;
	return res;
}

signed main()
{
	int n, ans(1);
	scanf("%lld", &n);
	ans = ( qpow(10, n) - ( 2 * qpow(9, n) % mod ) % mod + mod ) % mod + qpow(8, n);
	printf("%lld\n", ans % mod);
	return 0;
}

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

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int INF = 1e9;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
//    freopen("out.txt", "w", stdout);
    
    int N; cin >> N;
    int c = 0;

    for(int i = 1; i < N; i++){
        int r = N - i;
        int d = 0;
        for(int j = 1; j < sqrt(r); j++){
            if(r%j == 0) d++;
        }
        d *= 2;
        if(sqrt(r) == (int) sqrt(r))
            d++;
        c += d;
    }

    cout << c;

    return 0;

}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];

  vector<int> dp(h + 1, INF);
  dp[h] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = h; j >= 0; j--) {
      dp[max(j - a[i], 0)] = min(dp[max(j - a[i], 0)], dp[j] + b[i]);
    }
  }

  cout << dp[0] << endl;
  return 0;
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
    
int GCD(int m,int n){
    int big,small;
    int p=-1;
    big=max(m,n);
    small=min(m,n);

    while(1){
        p=big%small;
        if(p==0)break;
        big=small;
        small=p;
    }
    
    return small;
}

int main(){
    int ans=0,sum=0;
    int n;
    
    cin >>n;
    int a[n];
    int toi[n];
    int fromiton[n];


    cin >>a[0];
    for (int i = 1; i < n; i++){
        cin >>a[i];
    }

    toi[0]=a[0];
    fromiton[n-1]=a[n-1];
    
    for (int i = 1; i < n; i++){
        toi[i] =GCD(a[i],toi[i-1]);
        fromiton[n-i-1]=GCD(a[n-i-1],fromiton[n-i]);
    }

    ans=max(ans,fromiton[1]);
    
    for (int i = 0; i < n-2; i++){
        ans=max(ans,GCD(toi[i],fromiton[i+2]));
    }    
    ans = max(ans,toi[n-2]);
    



    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const int N = 123456;
vector < int > a[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    map < pair < int , int > , int > pos;
    int n , m;

    cin >> n >> m;

    rep(i , 1 , m) {
        int x , y;
        cin >> x >> y;
        a[x].push_back(y);
        pos[{x , y}] = i;
    }

    rep(i , 1 , n) {
        sort(a[i].begin() , a[i].end());
    }

    vector < string > ans;
    ans.resize(m);

    rep(i , 1 , n) {
        if(a[i].size() == 0) continue;

        string A = to_string(i);
        while(A.length() != 6) {
            A = "0" + A;
        }
        int two = 1;

        //cout <<i  << " " << A << endl;
        for(auto j : a[i]) {
            string B = to_string(two);
            while(B.length() != 6) {
                B = "0" + B;
            }

           // cout << j << endl;

            ans[pos[{i , j}] - 1] = A + B;
            two++;
        }
    }

    for(auto j : ans) cout << j << endl;

    return 0;
}


Measured memory_bytes: 19712
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N;
	int A[110];
	int ans=0;
	int Max=0;
	cin>>N;
	REP(i,N){
		cin>>A[i];
		Max=max(A[i],Max);
	}
	int s=0;
	ans=0;
	for(int i=1;i<=Max;i++){
		bool back=false,now=false;
		for(int j=0;j<N;j++){
			if(i==0){
				if(A[j]>0){
					A[j]--;
					ans++;
					back=true;
				}
				else{
					back=false;
				}
			}
			else{
				if(A[j]>0){
					A[j]--;
					now=true;
				}
				else{
					now=false;
				}
				if(back==false&&now==true){
					ans++;
				}
				back=now;
			}
		}
	}
	DEB(ans)END
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
A = input()
B = input()
C = input()
print("" + A[0] + B[1] + C[2])


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<vector<int>> edges(N);
  REP(i,N-1){
    int a,b;cin>>a>>b;a--;b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  queue<int> q;
  q.push(0);q.push(N-1);
  vector<int> field(N,0);
  field[0]=1,field[N-1]=-1;

  while(!q.empty()){
    int now=q.front();q.pop();
    for(const auto &next:edges[now]){
      if(field[next]==0){
        field[next]=field[now];
        q.push(next);
      }
    }
  }

  if(accumulate(ALL(field),0)>0){
    cout<<"Fennec"<<endl;
  }else{
    cout<<"Snuke"<<endl;
  }
}


Measured memory_bytes: 6144
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<bool> > f(n, vector<bool>(10));
    for(int i=0; i<n; ++i){
        for(int j=0; j<10; ++j){
            int a;
            cin >> a;
            f[i][j] = (a == 1);
        }
    }
    vector<vector<int> > p(n, vector<int>(11));
    for(int i=0; i<n; ++i){
        for(int j=0; j<=10; ++j){
            cin >> p[i][j];
        }
    }

    int ans = INT_MIN;
    for(int i=1; i<(1<<10); ++i){
        bitset<10> bs(i);
        vector<int> cnt(n, 0);
        for(int j=0; j<n; ++j){
            for(int k=0; k<10; ++k){
                if(f[j][k] && bs[k]){
                    ++ cnt[j];
                }
            }
        }

        int sum = 0;
        for(int j=0; j<n; ++j)
            sum += p[j][cnt[j]];
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  vector<int> a(5);
  rep(i, 3){
    int x,y; cin >>x >>y;
    a[x]++; a[y]++;
  }
  bool ok = true;
  rep(i, a.size()) if (a[i] == 3) ok = false;
  cout <<(ok ? "YES" : "NO") <<endl;
}

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

long dp[10000+10][1000+10];
long a[1000+10];
long b[1000+10];
long INF = 2e10;

int main() {
  long h, n;
  cin >> h >> n;
  for (long j = 0; j < n; j++) {
    cin >> a[j+1] >> b[j+1];
  }
  
  for (long i = 1; i <= h; i++) {
    dp[i][0] = INF;
    for (long j = 1; j <= n; j++) {
      if (i <= a[j]) {
        dp[i][j] = b[j] > dp[i][j-1] ? dp[i][j-1] : b[j];
      } else {
        long tmp = dp[i-a[j]][j] + b[j];
        dp[i][j] = tmp > dp[i][j-1] ? dp[i][j-1] : tmp;
      }
    }
  }
  cout << dp[h][n] << endl;
}

Measured memory_bytes: 79232