akhauriyash/Code-Regression huggingface dataset:
/**
*    Username : adhoc_king
*    Name : adhoc_king
*    Institute : IIT Bombay
*/

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
// #include <map>
// #include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m;
    cin>>n>>m;
    int arr[m];
    for0(i,m) cin>>arr[i];
    sort(arr, arr+m);
    vi vec;
    for0(i,m-1) vec.push_back(arr[i+1] - arr[i]);
    sort(all(vec));
    int sum = 0;
    for0(i,m-n) sum += vec[i];
    cout<<sum;

    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <unordered_set>

using namespace std;

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

    cout << pow(r,2) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                long X = scan.nextLong();
                if(0<X || X<0){
                    for(long i=-120; i<=120; i++){
                        for(long j=-120; j<=120; j++){
                            if(i*i*i*i*i-j*j*j*j*j==X){
                                System.out.println(i + " " + j);
                                System.exit(0);
                            }
                        }
                    }
                }
                else if(X==0){
                    System.out.println("1 1");
                }
        }
}

Measured memory_bytes: 38764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

bool hantei(string s,string tansaku,string part[]){
    int j=0;
    while(j<s.size()){
        bool flag=false;
        for(int i=0; i<4; i++){
            if(j+7<s.size()&&s[j+7]=='a'&&i==0)continue;
            if(s.substr(j,part[i].size())==part[i]){
                j+=part[i].size();
                flag=true;
                break;
            }
        }
        if(!flag){
            return false;
        }
    }
    return true;
}

int main(){
    string part[4]={"dreamer","dream","eraser","erase"};
    string s,tansaku;
    cin>>s;
    if(hantei(s,tansaku,part)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    long int a[n],max = 0, min = 1000000000;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(min > a[i]) {
            min = a[i];
        }
        if(max < a[i]) {
            max = a[i];
        }
    }
    cout << abs(max-min);
    return 0;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    a = input()
    k = a.find('#')
    if k == -1:
        k = W
    v = [1] * k + [0] * (W - k)
    u = [0] * W

    for _ in range(1, H):
        a = input()
        u, v = v, u
        v[0] = t = u[0] if a[0] == '.' else 0
        for j, uu, aa in zip(range(1, W), u[1:], a[1:]):
            v[j] = t = uu + t if aa == '.' else 0
    print(v[-1] % (10 ** 9 + 7))


main()


Measured memory_bytes: 3444
n, a, b = map(int, input().split())

sum = 0
for i in range(n + 1):
    sum2 = 0
    j = i
    while j != 0:
        sum2 += j % 10
        j = j // 10
    if sum2 >= a and sum2 <= b:
        sum += i

print(sum)

Measured memory_bytes: 3060
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int N; std::cin >> N;
	std::vector<Int> A(N);
	rep(i, N)std::cin >> A[i];
	std::vector<Int> S(N + 1);
	S[0] = 0;
	for (Int i = 1; i <= N; ++i) {
		S[i] = S[i - 1] + A[i - 1];
	}
	std::unordered_map<Int, Int> m;
	rep(i, N + 1)m[S[i]]++;
	Int ans = 0;
	for (const auto& elem : m) {
		if (elem.second >= 2)
			ans += (elem.second * (elem.second - 1) / 2);
	}
	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,K; cin >> N >> K;
    ll ans = 0;
    if(K == 0){
        cout << N*N << endl;
        return 0;
    }
    for(int b = K+1; b <= N; b++){
        //K+mb <= Nとなる最大のm: m <= (N-K)/b
        int mul = b-K;
        ans += ((N-K)/b + 1)*mul;
        //あまりがKからb-1まで考える
        if(N % b >= K){
            ll rem = N % b;
            //remがK+1だったら,rem+1,...,b-1を余分に一回ずつ数えている
            ans -= b-rem-1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        (n, m) = [int(e) for e in lines[0].split(" ")]
        for _ in range(m):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        (n, m) = [int(e) for e in lines[0].split(" ")]


    ps = [] 
    for i in range(1, m + 1):
        e = lines[i].split(" ")
        p = int(e[0])
        s = e[1]
        ps.append((p, s))

    return (n, m, ps)


def solve(n, m, ps):

    
    submits = dict()
    # for i in range(1, n+1):
    #     submits[i] = []

    for (p, s) in ps:

        ans_list = submits.get(p, [])
        ans_list.append(s)
        submits[p] = ans_list
    
    total_ac = 0
    total_wa = 0
    for (p, ans_list) in submits.items():

        ac = 0
        wa = 0
        for ans in ans_list:
            if ans == 'WA':
                wa = wa + 1
            elif ans == 'AC':
                ac = ac + 1
                break
        
        if ac == 0:
            wa = 0

        total_ac = total_ac + ac
        total_wa = total_wa + wa
        
        if debug:
            log("p=%d, ac=%d, wa=%d" % (p, ac, wa))
            log("total_ac=%d, total_wa=%d" % (total_ac, total_wa))

    result = [total_ac, total_wa] 

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        print("%d %d" % (result[0], result[1]))
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 37668
import sys
import math
import itertools
import bisect
from copy import copy
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 X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0

N = i()
A = l()
ans = A[0]
for i in range(1,N):
    ans = math.gcd(ans,A[i])

print(ans)


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S; 
    cin >> S; 
    for (int i = 0; i<S.size(); ++i) {
        if (S[i]=='?') S[i]='D';
    }
    cout << S;
    
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fr(i,a,b) for(ll i = b;i>=a;i--)
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vpll vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;      
    x = x % p; 
                
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

 

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

ll n;
cin>>n;

vll v(n+1,0);

f(i,1,n+1){
    for(ll j = i;j<=n;j+=i)
    v[j]++;
}

ll ans = 0;
f(i,1,n+1)
ans += i*v[i];

cout<<ans<<endl;




}


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

// https://abc102.contest.atcoder.jp/tasks/abc102_b
public class Main
{

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i=0; i<n; i++) {
            a.add(in.nextInt());
        }
        int max = Collections.max(a);
        int min = Collections.min(a);
        System.out.println(max - min);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;

int main()
{
    int type_ref, type_mic, type_dis;    //冷蔵庫の種類 電子レンジの種類 割引券の種類
    cin >> type_ref >> type_mic >> type_dis;

    //冷蔵庫の種類別の値段を取得し、最も値段の安いものを探す
    vector<int> price_ref(type_ref);
    int mp_ref = 100100;
    rep(i, type_ref)
    {
        cin >> price_ref[i];
        mp_ref = min(mp_ref, price_ref[i]);
    }

    //電子レンジの種類別の値段を取得
    vector<int> price_mic(type_mic);
    int mp_mic = 100100;
    rep(i, type_mic)
    {
        cin >> price_mic[i];
        mp_mic = min(mp_mic, price_mic[i]);
    }

    //割引券なしでの最小金額
    int min_amount = mp_ref + mp_mic;

    //割引券(効果がないものは除外)を使いながら最小金額を探す
    rep(i, type_dis)
    {
        int target_ref, target_mic, discount;
        cin >> target_ref >> target_mic >> discount;
        
        //対象外の場合飛ばす
        if (target_ref > type_ref || target_mic > type_mic) continue;
        
        int _min_amount = price_ref[target_ref-1] + price_mic[target_mic-1] - discount;
        min_amount = min(min_amount, _min_amount);
    }

    cout << min_amount << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int N;
	cin >> N;
	vector<string> str;
	vector<string> str1;
	bool judge = true;

	for (int i = 0; i < N; i++) {
		string temp;
		cin >> temp;
		str.push_back(temp);
		str1.push_back(temp);
	}
	for (int i = 0; i < N - 1; i++) {
		if (str[i+1].front() != str[i].back()) {
			judge = false;
		}
	}
	sort(str.begin(), str.end());
	str.erase(unique(str.begin(), str.end()), str.end());


	if (str.size() != str1.size()) {
		judge = false;
	}
	if (judge == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	
	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val input = readLine()!!.split(" ").map(String::toDouble)
    val a = input[0]
    val b = input[1]
    val x = input[2]

    if (x > a * a * b / 2) {
        val tmp = 2 * x / (a * a) - b
        val atan = Math.atan2(b - tmp, a)
        val ans = Math.toDegrees(atan)
        println(ans)
    } else {
        val tmp = 2 * x / (a * b)
        val atan = Math.atan2(b, tmp)
        val ans = Math.toDegrees(atan)
        println(ans)
    }
}


Measured memory_bytes: 38032
#include <stdio.h>
#include<string.h>
int main (){
  char s[101];
  int a,cont=0;

  scanf("%s",s);

  a=strlen(s);

  for(int i=1; i<=a-2; i++){
    cont++;
  }
  printf("%c%d%c\n",s[0],cont,s[a-1]);

  return 0;
}


Measured memory_bytes: 128
#coding: UTF-8
import math

def RN(n,a):
    ans=""
    for i in range(int(n)):
        ans+=a[int(n)-1-i]+" "
    print(ans[:-1])

if __name__=="__main__":
    n=input()
    a=input()
    List=a.split(" ")
    RN(n,List)

Measured memory_bytes: 7776
# -*- coding: utf-8 -*-
n,x = list(map(int,input().split()))
a =  list(map(int,input().split()))
ret = 0
if a[0] > x:
    ret+=a[0]-x
    a[0]=x
for i in range(1,len(a)):
    if a[i-1]+a[i]>x:
        ret+=(a[i-1]+a[i]-x)
        a[i]=x-a[i-1]
print(ret)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    
    int ans = 1e9;
    repi(i,-110,110){
        int cost = 0;
        rep(j,N) cost += (a[j]-i)*(a[j]-i);
        ans = min(ans,cost);
    }
    
    cout << ans << '\n';
}

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

int main()
{
	ll H,N,i,j;
	cin>>H>>N;
	
	ll A[N],B[N];
	
	for(i=0;i<N;i++)
	{
		cin>>A[i]>>B[i];
	}
	
	ll dp[H+1];
	
	for(i=0;i<=H;i++)
	{
		dp[i]=LLONG_MAX;
	}
	dp[0]=0;
	for(i=0;i<N;i++)
	{
		for(j=1;j<=H;j++)
		{
			if(j<A[i])
			{
				dp[j]=min(dp[j],B[i]);
			}
			else
			{
				dp[j]=min(dp[j],dp[j-A[i]]+B[i]);
			}
		}
	}
	cout<<dp[H]<<endl;
	//return 0;
}

Measured memory_bytes: 384
s = input()
s = s[::-1]

mod = 2019

sum_digits = 0

cnts = [0] * (mod + 1)
cnts[0] = 1

d = 1

for c in s:
    sum_digits += int(c) * d
    sum_digits %= mod
    d *= 10
    d %= 2019
    cnts[sum_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)


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

using namespace std;

using ll = long long;

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

    int n, x;

    cin >> n >> x;
    vector<int> m(n);
    for (int i = 0; i < n; ++i) cin >> m[i];

    int ans = n;

    x -= accumulate(m.begin(), m.end(), 0);
    sort(m.begin(), m.end());
    ans += x / m[0];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	long long key;
	int id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200002] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

void add_BIT(int BIT[], int n, int i, int k)
{
	while (i <= n) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{
	int i, N, K, a[200002];
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) scanf("%d", &(a[i]));
	
	data d[200002];
	for (i = 1, d[0].key = 0, d[0].id = 0; i <= N; i++) {
		d[i].key = d[i-1].key + a[i-1] - K;
		d[i].id = i;
	}
	merge_sort(d, N + 1);
	
	int k;
	for (i = 1, k = 1, a[d[0].id] = 1; i <= N; i++) {
		if (d[i].key > d[i-1].key) k++;
		a[d[i].id] = k;
	}
	
	int BIT[200002] = {};
	long long ans = 0;
	for (i = 0; i <= N; i++) {
		ans += sum_BIT(BIT, a[i]);
		add_BIT(BIT, k, a[i], 1);
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 9532
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    K, S = MAP()
    
    ans = 0
    for x in range(K+1):
    	for y in range(K+1):
        	ans += 0 <= S - (x + y) <= K
            
    print(ans)
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{x:i64, y:i64};
    match x {
        2 => println!("No"),
        4|6|9|11 => {
            match y {
                4|6|9|11 => println!("Yes"),
                _ => println!("No"),
            }
        },
        _ => {
            match y {
                4|6|9|11|2 => println!("No"),
                _ => println!("Yes"),
            }
        }
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && b>=1 && a<=10000 && b<=10000)
    {
      a=a*b;
      if(a%2==0)
      {
        System.out.println("Even");
      }else
      System.out.println("Odd");
    }
  }
}

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

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }
 
   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

int main(){
  int h,w;
  cin >> h >> w;
  char c[h][w];
  rep(i,h){
    rep(j,w)cin >> c[i][j];
  }
  int ans=0;
  UnionFind x[h](w);
  UnionFind y[w](h);
  rep(i,h){
    rep(j,w-1){
      if(c[i][j]=='.' && c[i][j+1]=='.')x[i].unite(j,j+1);
    }
  }
  rep(j,w){
    rep(i,h-1){
      if(c[i][j]=='.' && c[i+1][j]=='.')y[j].unite(i,i+1);
    }
  }
  rep(i,h){
    rep(j,w){
      if(c[i][j]=='.'){
        ans=max(ans,x[i].size(j)+y[j].size(i)-1);
      }
    }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 35584
_n = gets.strip.split('').map(&:to_i)
ideal =Array.new(_n.length)
ideal.fill{|i| i%2} if  _n[0] == 0
ideal.fill{|i| (i+1)%2} if  _n[0] == 1

count = 0
_n.each_with_index do |v, i|
  if v != ideal[i] then
    count+=1
  end
end

puts count

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

int main(){
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        m.insert(pair<int,int>(k,i));
    }
    cout<<(m.size()==n?"YES":"NO");
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N,M;cin>>N>>M;
    vector<int>x(M);
    priority_queue<int>pq;
    rep(i,M){
        cin>>x.at(i);
    }
    sort(x.begin(),x.end());
    rep(i,M){
        if(i!=0){
            pq.push(x.at(i)-x.at(i-1));
        }
    }
    if(N>=M){
        cout<<0<<endl;
        return 0;
    }
    int sum=0;
    rep(i,N-1){
        sum+=pq.top();
        pq.pop();
        
    }
    cout<<x.at(M-1)-x.at(0)-sum<<endl;

}

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

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

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

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

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

    // 入力
    int d, n;
    cin >> d >> n;

    // 処理
    ll ans = 0;
    if (n == 100) n++;
    if (d == 0) {
        ans = n;
    } else if (d == 1) {
        ans = 100 * n;
    } else if (d == 2) {
        ans = 10000 * n;
    }

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;


//#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 5000 + 10 ;

int n , a [ N ] , k ; 
bool dp [ N ] ;

bool chk ( int mid ) {
	memset ( dp , 0 , sizeof dp ) ;
	dp [ 0 ] = 1 ;
	for ( int i = 1 ; i <= n ; i++ ) {
		if ( i == mid )
			continue ; 
		for ( int j = N - 1 ; j >= a [ i ] ; j-- ) {
			dp [ j ] |= dp [ j - a [ i ] ] ; 
		}
	}
	bool isFound = 0 ;
	for ( int i = max ( 0 , k - a [ mid ] ) ; i < k ; i++ )
		isFound |= dp [ i ] ;
	return !isFound ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k ; 
	for ( int i = 1 ; i <= n ; i++ )
		cin >> a [ i ] ;
	sort ( a + 1 , a + n + 1 ) ; 
	int lo = -1 , hi = n + 1 ;
	while ( hi - lo > 1 ) {
		int mid = ( hi + lo ) >> 1 ; 
		( chk ( mid ) ? lo : hi ) = mid ; 
	}
	cout << lo << '\n' ; 
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int LL
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read() {
	int x=0;
	char ch=' ';
	bool flag=false;
	while(ch<'0' || ch>'9') {
		if(ch=='-')flag=true;
		ch=getchar();
	}
	while(ch>='0' && ch<='9') {
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return flag?-x:x;
}
int n;
const int MAX_N=1005;
int x[MAX_N],y[MAX_N];
signed main() {
	cin>>n;
	rep(i,0,n)cin>>x[i]>>y[i];
	rep(i,0,n)if(abs(x[i]+y[i])%2!=abs(x[0]+y[0])%2)return cout<<-1<<endl && 0;
	vec arms;
	per(i,31,0)arms.pb(1LL<<i);
	if((x[0]+y[0])%2==0)arms.pb(1);
	cout<<arms.size()<<endl;
	rep(i,0,arms.size())cout<<arms[i]<<" \n"[i==arms.size()-1];
	rep(i,0,n) {
		int nx=0,ny=0;
		rep(j,0,arms.size()) {
			if(abs(x[i]-nx)>abs(y[i]-ny)) {
				if(x[i]-nx>0) {
					putchar('R');
					nx+=arms[j];
				} else {
					putchar('L');
					nx-=arms[j];
				}
			} else {
				if(y[i]-ny>0) {
					putchar('U');
					ny+=arms[j];
				} else {
					putchar('D');
					ny-=arms[j];
				}
			}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
A = input()

pre_ch = {}
pre_ch_cnt = []
for i, c in enumerate(A):
  if c in pre_ch:
    pre_ch_cnt.append(pre_ch_cnt[pre_ch[c]] + 1)
  else:
    pre_ch_cnt.append(0)
  pre_ch[c] = i

s_cnt = [1]
for i, c in enumerate(A):
  s_cnt.append(s_cnt[i])
  s_cnt[i + 1] += i - pre_ch_cnt[i]

print(s_cnt[len(A)])

Measured memory_bytes: 20456
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector<pair<int ,int> >vepa;
typedef set<ll>se;
typedef map<string ,ll> mpp;
const ll N=1e5+1 ,OO=1e18;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,x,y,cnt,arr[N];
bool f,vis[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
        vis[1000]=vis[2000]=vis[3000]=vis[4000]=vis[5000]=vis[6000]=vis[7000]=vis[8000]=vis[9000]=vis[10000]=1;
        cin>>n;
        for(int i=n;i<=10000;i++)
        {
            if(!vis[i])
                cnt++;
              else
                break;
        }
        cout<<cnt;

 go;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


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

    vector<int> s(n + 1);
    rep(i, n) s[i + 1] = s[i] + w[i];
    int sum = s[n];

    int ans = INF;
    rep(i, n) {
        ans = min(ans, abs(sum - 2 * s[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t;
	cout<<(t+s)<<endl;
	return 0;
}


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

int main() {
  long long N;
  cin >> N;
  long long A[100000];
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  long long ans[100000];
  for (long long i = 0; i < N; i++) {
    ans[A[i] - 1] = i + 1;
  }
  for (long long i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
 
}

Measured memory_bytes: 2432
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() 
{
	char c;
	cin >> c;
	cout << char(int(c) + 1) << endl;
}




Measured memory_bytes: 3616
import sys
N = int(input())
A = [int(x) for x in input().split()]

L = [0] * N + [A[N]]    # 下限
U = [0] * N + [A[N]]    # 上限
for i in range(N - 1, -1, -1):
    L[i] = (L[i + 1] + 1) // 2 + A[i]
    U[i] = U[i + 1] + A[i]

if 1 < L[0]:
    print(-1)
    sys.exit()

U[0] = 1
for i in range(1, N + 1):
    U[i] = min(2 * (U[i - 1] - A[i - 1]), U[i])   # 深さiの頂点数

print(sum(U))

Measured memory_bytes: 23128
#include <iostream>

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;

    long ans = 0;
    bool breakFlag = false;
    int mn = n;
    int gn = 0;
    int sn = 0;
    for (int mi = n; mi >= 0; --mi) {
        int diff = n - mi;
        for (int gi = 0; gi <= diff; ++gi) {
            ans = mi * 10000 + gi * 5000 + (diff - gi) * 1000;
            if (ans == y) {
                mn = mi;
                gn = gi;
                sn = n - mn - gn;
                breakFlag = true;
                break;
            }
        }

        if (breakFlag) {
            break;
        }

        mn = -1;
        gn = -1;
        sn = -1;
    }

    cout << mn << " " << gn << " " << sn << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    int N = S.size();
    bool ans = true;
    rep(i, N / 2) {
        if (S[i] != S[N - 1 - i]) ans = false;
    }
    rep(i, (N - 1) / 2) {
        if (S[i] != S[(N-1)/2-1-i]) ans = false;
    }
    rep(i, (N - 1) / 2) {
        int idx = (N + 3) / 2 + i - 1;
        if (S[idx] != S[N-1-i]) ans = false;
    }

    if (ans) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
dp = [[-float("inf"),-float("inf"),-float("inf")] for i in range(n+1)]

a = [list(map(int,input().split())) for i in range(n)]

dp[0] = [0]*3
dp[1] = a[0]

for i in range(2,n+1):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i-1][0]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + a[i-1][1]
    dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + a[i-1][2]
print(max(dp[n]))

Measured memory_bytes: 78940
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll lcm(ll a, ll b)
{
   return a / gcd(a, b) * b;
}

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

  if(n % 2 == 0){
    vector<ll> first(n/2),second(n/2);
    rep(i,n){
        if(i % 2 == 0){
            second[i/2] = a[i];
        }
        else{
            first[(i-1)/2] = a[i];
        }
    }  
    reverse(first.begin(),first.end());
    rep(i,n/2) cout << first[i] << " ";
    rep(i,n/2) cout << second[i] << " ";
  }

  else{
      vector<ll> first((n+1)/2),second((n-1)/2);
      rep(i,n){
          if(i % 2 == 0){
              first[i/2] = a[i];
          }
          else{
              second[(i-1)/2] = a[i];
          }
      }
      reverse(first.begin(),first.end());
      rep(i,(n+1)/2) cout << first[i] << " ";
      rep(i,(n-1)/2) cout << second[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, P[101010], A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> P[i];

    string ans = "";
    int cnt = 0;
    rep(i, 0, N) {
        while (cnt < P[i]) {
            ans += "(";
            cnt++;
        }
        ans += ")";
    }

    stack<int> stk;
    int st = 1;
    int idx = 0;
    rep(i, 0, N * 2) {
        if (ans[i] == '(') {
            stk.push(st);
            st++;
        }
        else {
            if (stk.size() == 0) {
                printf(":(\n");
                return;
            }

            A[idx] = stk.top();
            stk.pop();
            idx++;
        }
    }

    rep(i, 0, N) if (P[i] != A[i]) {
        printf(":(\n");
        return;
    }

    printf("%s\n", ans.c_str());
}


Measured memory_bytes: 4180
#include <iostream>
#include <vector>
#include <string>

typedef long long int ll;
using namespace std;

ll f(ll num, ll d){
  return num/d;
}
int main(int argc, char const *argv[]) {
  ll l, r, d;std::cin >> l >> r >> d;
  std::cout << f(r, d) - f(l-1, d) << '\n';
  return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,K,G,C,P; cin>>N>>K>>G>>C>>P;
  string S; cin>>S;
  vector<char> A(K,'X');
  int ans=0;
  rep(i,0,N){
    if(S[i]=='r'){
      if(A[i%K]=='r')
        A[i%K]='X';
      else{
        A[i%K]='r';
        ans+=P;
      }
    }
    else if(S[i]=='s'){
      if(A[i%K]=='s')
        A[i%K]='X';
      else{
        A[i%K]='s';
        ans+=G;
      }
    }
    else{
      if(A[i%K]=='p')
        A[i%K]='X';
      else{
        A[i%K]='p';
        ans+=C;
      }
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
    int n;
    cin>>n;
    int a[n];
    int max=-1000009,min=1000009,maxi=-1,mini=-1;
    rep(i,n)
    {
        cin>>a[i];
        if(a[i]>max)
        {
            max=a[i];
            maxi=i;
        }
        else;
    }
    rep(i,n)
    {
        if(a[i]<min)
        {
            min=a[i];
            mini=i;
        }
        else;
    }
    if(max+min>=0)
    {
        cout<<2*n-1<<endl;
        rep(i,n)
        {
            cout<<maxi+1<<" "<<i+1<<endl;
        }
        rep(i,n-1)
        {
            cout<<i+1<<" "<<i+2<<endl;
        }
    }
    else
    {
        cout<<2*n-1<<endl;
        rep(i,n)
        {
            cout<<mini+1<<" "<<i+1<<endl;
        }
        rep(i,n-1)
        {
            cout<<n-i<<" "<<n-i-1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 100005;
int H[MAX], n, dp[MAX], inf = 1e9;

int f(int i){
    if(i == n-1)return 0;
    int &ans = dp[i];
    if(ans != -1)return ans;
    ans = inf;
    if(i+1 < n)ans = min(ans, f(i+1)+abs(H[i]-H[i+1]));
    if(i+2 < n)ans = min(ans, f(i+2)+abs(H[i]-H[i+2]));
    return ans;
}

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

  cin >> n;
  forn(i, 0, n)cin >> H[i];
  memset(dp, -1, sizeof dp);
  dp[n-1] = 0;
  for(int i = n-1; i >= 0; i--){
      if(i-1 >= 0)dp[i-1] = min(dp[i-1], dp[i]+abs(H[i]-H[i-1]));
      if(i-2 >= 0)dp[i-2] = min(dp[i-2], dp[i]+abs(H[i]-H[i-2]));
  }
  cout << f(0) << endl;

}





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

A,B,C,X,Y = map(int, input().split())

if A+B <= 2*C:
  print(A*X + B*Y)
else:
  ab_num = max(X, Y)
  total1 = 2*C*ab_num

  ab_num = min(X, Y)
  a_num  = X - ab_num
  b_num  = Y - ab_num
  total2 = 2*C*ab_num + A*a_num + B*b_num

  if total1 >= total2:
    print(total2)
  else:
    print(total1)


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


void solve(long long N, std::vector<long long> u, std::vector<long long> v, std::vector<long long> w){
    vector<bool>visited(N+1,false);
    vector<ll> length(N+1,0);
    vector<vector<pair<ll,ll>>> link_list(N+1);
    for (ll i=0;i<N-1;i++){
        link_list[u[i]].push_back(make_pair(v[i],w[i]%2));
        link_list[v[i]].push_back(make_pair(u[i],w[i]%2));
    }
    queue<ll> q;
    q.push(1);
    visited[1] = true;
    while(!q.empty()){
        auto node = q.front();q.pop();
        for (const auto & next_node :link_list[node]){
            if (!visited[next_node.first]){
                q.push(next_node.first);
                length[next_node.first] = length[node]+next_node.second;
                visited[next_node.first]=true;
            }
        }
    }
    for (ll i=1;i<=N;i++){
        printf("%s\n", length[i]%2 == 0 ? "0" : "1");
    }
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> u(N-1);
    std::vector<long long> v(N-1);
    std::vector<long long> w(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        scanf("%lld",&w[i]);
    }
    solve(N, std::move(u), std::move(v), std::move(w));
    return 0;
}


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

using namespace std;

int main(){
 
  int A, B;
  cin >> A >> B;
  
  int ans = 0, sum = 1;
  
  while(true){
    if (sum >= B) break;
    sum += (A - 1);
    ans++;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, K;
int x[100010], a[100010];

vector<int> mul(vector<int> &a, vector<int> &b) {
    int S = a.size();
    vector<int> ret(S);
    rep(i,0,S) ret[i] = a[b[i]];
    return ret;
}

signed main() {
    cin >> N;
    rep(i,0,N) cin >> x[i];
    vector<int> diff(N-1);
    rep(i,1,N) diff[i-1] = x[i] - x[i-1];

    cin >> M >> K;
    vector<int> swp(N-1);
    iota(swp.begin(), swp.end(), 0);
    rep(i,0,M) {
        int val; cin >> val; val--;
        swap(swp[val-1], swp[val]);
    }

    while(K) {
        if(K & 1) diff = mul(diff, swp);
        swp = mul(swp, swp);
        K >>= 1;
    }

    int ans = x[0];
    rep(i,0,N) {
        if(i == 0) cout << ans << endl;
        else {
            ans += diff[i-1];
            cout << ans << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(){
	long long int n;
	cin>>n;
	long long int ar[2][n];
	for(int i=0;i<n;i++) cin>>ar[0][i];
	for(int i=0;i<n;i++) cin>>ar[1][i];
	
	for(int i=1;i<n;i++) ar[0][i] += ar[0][i-1];
	ar[1][0] += ar[0][0];
	for(int i=1;i<n;i++) ar[1][i] += max(ar[1][i-1],ar[0][i]);
	
	cout<<ar[1][n-1]; 
	return 0;
	
}

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

int main() {
    int N,K;
    cin >> N >> K;
    string s;
    cin >> s;
    if(s.at(K - 1) == 'A') {
        s.at(K - 1) = 'a';
    }else if(s.at(K - 1) == 'B') {
        s.at(K - 1) = 'b';
    }else {
        s.at(K - 1) = 'c';
    }
    cout << s << endl;
}

  

Measured memory_bytes: 256