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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
  int n,ans=0;
  std::cin >> n;
  vi a(n);
  rep(i,n){
    std::cin >> a[i];
  }
  rep(i,n){
    if(i+1==a[a[i]-1]){
      a[i]=0;
      a[a[i]-1]=0;
      ans++;
    }
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 640
K, N = map(int, input().split())
Alist = list(map(int, input().split()))
dlist = [[]]*N
for n in range(N-1):
  dlist[n] = Alist[n+1] - Alist[n]
dlist[N-1] = K - Alist[N-1] + Alist[0]
print(K-max(dlist))

Measured memory_bytes: 26444
using System;
using System.Collections.Generic;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var NK = Console.ReadLine().Split().Select(int.Parse).ToList();

            var d = new int[NK[1]];
            var A = new int[NK[1]][];
            var result = new bool[NK[0]];

            for (int i = 0; i < NK[1]; i++)
            {
                d[i] = int.Parse(Console.ReadLine());
                A[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < A[i].Length; j++)
                {
                    result[A[i][j] - 1] = true;
                }
            }

            Console.WriteLine(result.Where(x => x == false).Count());


#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


Measured memory_bytes: 19580
#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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int M;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> M;
    int ans = 48 - M;
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
def main():
    n,m = map(int,input().split())
    ab = [[] for i in range(n)]
    for _ in range(m):
        a,b = map(int,input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    q = deque()
    q.append(0)
    ans = [-1] * n
    ans[0] = 0
    while len(q) != 0:
        now = q.popleft()
        for i, next in enumerate(ab[now]):
            if ans[next] == -1:
                ans[next] = now+1
                q.append(next)

    print('Yes')
    for i in range(1,n):
        print(ans[i])



if __name__=='__main__':
    main()


Measured memory_bytes: 36916
N, K = map(int, input().split())
S = input()

res = 0
pre = None
add = {2: 0}
add[1] = 0 if S[0] == S[-1] else 1
for s in S:
    if pre is None:
        pass
    elif pre == s:
        res += 1
    elif pre == "R":
        add[2] += 1

    pre = s

if add[2] > K:
    res += 2 * K
    print(res)
else:
    res += 2 * add[2]
    K -= add[2]
    if add[1] == 1 and S[-1] == "L":
        res -= 2
    if K > 0:
        res += add[1]
    print(res)





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

void Main() {
    // input
    u_int64_t N, K;
    cin >> N >> K;


    // translate
    // 整数での計算であることに注意
    // 特異点の手前 > 0
    u_int64_t before = N - (N / K ) * K;

    // 特異点の後 < 0
    u_int64_t after = -1 * (N - (N / K + 1) * K);

    u_int64_t ans;
    if (before < after) {
        ans = before;
    } else {
        ans = after;
    }
    


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
bool ABC167F_order(pll const& lhs, pll const& rhs)
{
	// first:  open
	// second: close

	int lhs_sign = 0;
	if (lhs.first > lhs.second)
		lhs_sign = 1;  // more open
	else if (lhs.first < lhs.second)
		lhs_sign = -1;  // more close

	int rhs_sign = 0;
	if (rhs.first > rhs.second)
		rhs_sign = 1;
	else if (rhs.first < rhs.second)
		rhs_sign = -1;

	if (lhs_sign != rhs_sign)
		return lhs_sign > rhs_sign;

	if (lhs_sign >= 0)
	{
		if (lhs.second != rhs.second)
			return lhs.second < rhs.second;  // use the smallest close at the first (because the restriction is toughest at the first)
		else
			return lhs.first > rhs.first;
	}
	else
	{
		if (lhs.first != rhs.first)
			return lhs.first > rhs.first;  // leave the smallest open for the last (because the restriction is toughest at the last)
		else
			return lhs.second < rhs.second;
	}
}

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

	int n;
	cin >> n;
	vector<pll> num_live_open_and_close(n);
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		for (auto it = s.begin(); it != s.end(); it++)
		{
			if (*it == '(')
			{
				num_live_open_and_close[i].first++;
			}
			else  // *it==')'
			{
				if (num_live_open_and_close[i].first > 0)
					num_live_open_and_close[i].first--;
				else
					num_live_open_and_close[i].second++;
			}
		}
	}

	sort(num_live_open_and_close.begin(), num_live_open_and_close.end(), ABC167F_order);

	ll level = 0;
	for (auto it = num_live_open_and_close.begin(); it != num_live_open_and_close.end(); it++)
	{
		level -= it->second;
		if (level < 0)
		{
			cout << "No" << "\n";
			return 0;
		}
		level += it->first;
	}
	if (level == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
	return 0;
}
MY_NAMESPACE_

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

int main() {
	string S;
	cin >> S;
	int n = S.size();

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = S[i] - '0';
	}
	
	long long ans = 0;
	for (int bit = 0; bit < (1 << (n-1)); bit++) {
		long long s = 0, cur = a[0];
		for (int i = 0; i < n - 1; i++) {
			if (bit & (1 << i)) {
				s += cur;
				cur = a[i + 1];
			}
			else {
				cur *= 10;
				cur += a[i + 1];
			}
		}
		s += cur;
		ans += s;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;
     
    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;                            
     
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()            
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) power(x, mod-2)
    #define ncr(n,r) ( n >= r ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-r]))%mod) : (ll)0)
    #define MAX 100005
     
    ll power(ll x, ll y) { 
        ll ans=1;
        x=x%mod;
        while(y>0) { 
            if (y&1) 
                ans=(ans*x)%mod; 
            y=y>>1;
            x=(x*x)%mod; 
        } 
        return ans; 
    }
    
    // vector<ll> adj[MAX];
    // ll visit[MAX];
    // void dfs(ll node){
    //     visit[node]=1;
    //     for(auto i : adj[node]){
    //         if(!visit[i]) dfs(i);
    //     }
    // }
    
    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }

    int main()
    {
        boost;
        ll d,t,s;
        cin>>d>>t>>s;
        if(d<=t*s)  cout<<"Yes";
        else    cout<<"No";
        return 0;
    }
    

Measured memory_bytes: 3604
#include<cstdio>

int main(){
    int count[760];
    // for(int i = 0; i < 1201; i++){
    //     count[i] = 0;
 	// }
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch - 'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch - 'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


Measured memory_bytes: 2672
sx, sy, tx, ty = map(int, input().split())
ans = ""


ans += "U"*(ty - sy)
ans += "R"*(tx - sx)
ans += "D"*(ty - sy)
ans += "L"*(tx - sx + 1)
ans += "U"*(ty - sy + 1)
ans += "R"*(tx - sx + 1)
ans += "DR"
ans += "D"*(ty - sy + 1)
ans += "L"*(tx - sx + 1)
ans += "U"

print(ans)

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

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

    sort(stage.begin(), stage.end());

    vector<int> diff(m-1);
    for(int i = 0; i < m-1; ++i)
    {
        diff[i] = abs(stage[i+1]-stage[i]);
    }

    sort(diff.begin(),diff.end());

    long long int ans = 0;
    for(int i = 0; i < (int)diff.size()-n+1; ++i)
    {
        ans += diff[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string a;
ll ans=1;
ll sum=1;
const ll mod=1e9+7;
int main(){
	cin>>a;
	reverse(a.begin(),a.end());
	for(int i=0;i<a.size();i++){
		if(i!=0)
			sum*=3;
		sum%=mod;
		if(a[i]=='1')
			ans=(2*ans+sum)%mod;
	}
	cout<<ans<<endl;
	return 0;
}
//3 5 11 29 83 245 731 2189 6563 19685 59051 177149
/*
3 5 9 11 15 19 27 29 33 37 45 49 57 65 81 83 87 91 99 103 111 119 135 139 147
155 171 179 195 211 243 245 249 253 261 265 273 281 297 301 309 317 333 341 357
373 405 409 417 425 441 449 465 481 513 521 537 553 585 601 633 665 729 731 735
739 747 751 759 767 783 787 795 803 819 827 843 859 891 895 903 911 927 935 951
967 999 1007 1023 1039 1071 1087 1119 1151 1215 1219 1227 1235 1251 1259
*/
/*
2 2 4 2 4 4 8 2 4 4 8 4 8 8 16 2 4 4 8 4 8 8 16 4 8 8 16 8 16 16 32 2 4 4 8 4
8 8 16 4 8 8 16 8 16 16 32 4 8 8 16 8 16 16 32 8 16 16 32 16 32 32 64 2 4 4 8 4
8 8 16 4 8 8 16 8 16 16 32 4 8 8 16 8 16 16 32 8 16 16 32 16 32 32 64 4 8 8 16 8
*/
/*
1 3 0 4 0 4 8 16 0 4 8 16 20 28 36 52 0 4 8 16 20 28 36 52 56 64 72 88 96 112 128
160 0 4 8 16 20 28 36 52 56 64 72 88 96 112 128 160 164 172 180 196 204 220 236
268 276 292 308 340 356 388 420 484 0 4 8 16 20 28 36 52 56 64 72 88 96 112 128
160 164 172 180 196 204 220 236 268 276 292 308 340 356 388 420 484 488 496 504
520 528
*/

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

int main(){
  int a, b, c; cin >> a >> b >> c;
  int v[3] = {abs(a-b), abs(b-c), abs(c-a)};
  sort(v, v+3);
  cout << v[0] + v[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

std::vector<int > A(200004), B(200004);
int N;



bool check(std::map<int, int > mp, int i, int val, int orig){
  if (i==mp.size()){
    if (val==orig) return false;
    auto itr1=std::lower_bound(B.begin(), B.end(), val);
    auto itr2=std::upper_bound(B.begin(), B.end(), val);
    //printf("val %d\n", val);
    //std::cout << *itr1 << std::endl;
    //std::cout << *itr2 << std::endl;
    
    if (itr1!=itr2) return true;
    else return false;
  }
  int counter=0;
  bool ret = false;
  for (auto &entry: mp){
    if (counter==i) {
      //printf("counter=%d, (%d, %d)\n", counter, entry.first, entry.second);
      for (int j=0; j<=entry.second; j++){
	//printf("val(%d) * pow(%d, %d)\n", val, entry.first, j);
	ret |= check(mp, i+1, val*pow(entry.first, j), orig);
      }
      break;
    }
    counter++;
  }
  return ret;
}

int main(){
  scanf("%d", &N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    B[i]=A[i];
  }
  std::sort(A.begin(), A.end(), std::greater<int>());
  std::sort(B.begin(), B.end());
  int ans =0;
  for (int i=0; i<N; i++){
    //printf("========= i%d ===\n", i);
    std::map<int, int> mp;
    //printf("mp init size=%d\n", mp.size());
    //std::vector<std::pair<int, int > > vec;
    int temp=A[i];
    auto itr1=std::lower_bound(B.begin(), B.end(), A[i]);
    auto itr2=std::upper_bound(B.begin(), B.end(), A[i]);
    if (itr2-itr1>1) {
      ans++;
      continue;
    }
    for (int j=2; j*j<=temp; j++){
      while(temp%j==0){
	mp[j]++;
	//vec.push_back(std::make_pair(temp,))
	temp = temp/j;
      }
      if (temp==1) break;
    }
    if (temp!=1)mp[temp]++;
    //printf("mp size=%d\n", mp.size());
    bool result = check(mp, 0, 1, A[i]);
    //printf("i=%d, result=%d\n", i, result);
    if (result) ans++;
  }
  std::cout << N-ans << std::endl;
  return 0;
}


Measured memory_bytes: 4408
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,x,t;
            cin>>n>>x>>t;
            ll ans=(n+x-1)/x;
            ans=ans*t;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3608
import java.util.*;

public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	int m = kbd.nextInt();
	while(m>0){
	    int start = kbd.nextInt();
	    int year = kbd.nextInt();
	    int n = kbd.nextInt();
	    int total = 0;
	    while(n>0){
		int s = management(start, year);
		if(total < s) total=s;
		n--;
	    }
	    System.out.println(total);
	    m--;
	}

    }
    static int management(int s, int y){
	int r = kbd.nextInt();
	double i = kbd.nextDouble();
	int f = kbd.nextInt();
	    
	if(r==1){
	    for(; y>0; y--){
		int a = (int)Math.floor(s*i);
		s = s-f + a;
	    }
	    return s;
	}
	else {
	    int m=0;
	    for(; y>0; y--){
		m += (int)Math.floor(s*i);
		s -= f;
	    }
	    s += m;
	    return s;
	}
    }
}

Measured memory_bytes: 13000
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;

    vector<ll> a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    ll Z = n*(n+1)/2LL;

    if(sum%Z != 0) {
        cout << "NO" << endl;
        return 0; 
    }

    ll k = sum/Z;    

    vector<ll> d(n);
    rep(i, n-1) {
        d[i] = a[i+1] - a[i];
    }
    d[n-1] = a[0] - a[n-1];

    rep(i, n) {
        if(d[i] - k > 0 || (d[i] - k)%n != 0) {
            cout << "NO" << endl;
            return 0; 
        }
    }

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

Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
  int A,B,S;
  scanf("%d%d",&A,&B);
  
  if(A>9||B>9){
    S=-1;
  }else{
    S=A*B;
  }
  
  printf("%d",S);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    static Node[] V;
    static ArrayDeque<Stack> stk = new ArrayDeque<>();

    public static void main(String[] args) {
    	int n = sc.nextInt();
    	V = new Node[n];
    	for(int i=0; i<n; i++) {
    		V[i] = new Node();
    	}
    	for(int i=0; i<n-1; i++) {
    		int a = sc.nextInt() - 1;
    		int b = sc.nextInt() - 1;
    		int w = sc.nextInt();
    		if(w%2 == 0) {
    			V[a].evennbr.add(b);
        		V[b].evennbr.add(a);
    		} else {
    			V[a].oddnbr.add(b);
        		V[b].oddnbr.add(a);
    		}
    	}
    	V[0].dfs(false);
    	for(int i=0; i<n; i++) {
    		if(V[i].color) {
    			System.out.println(0);
    		} else {
    			System.out.println(1);
    		}
    	}
    }

    static class Node {
        HashSet<Integer> oddnbr = new HashSet<>();
        HashSet<Integer> evennbr = new HashSet<>();
        boolean vst = false;
        boolean color;
        void dfs(boolean mode) {
        	vst = true;
        	color = mode;
        	for(int x : oddnbr) {
        		if(!V[x].vst) {
        			V[x].dfs(!mode);
        		}
        	}
        	for(int x : evennbr) {
        		if(!V[x].vst) {
        			V[x].dfs(mode);
        		}
        	}
        }
    }

    static class Stack {
    	int idx;
		Stack(int idx) {
			this.idx = idx;
		}

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 115072
#include <bits/stdc++.h>
using namespace std;
long long n, k, h[200000], a[200000];
int main (){
ios::sync_with_stdio(0);
cin.tie(0);
	cin >> n >> k;
	for (int i=1;i<n;i++) a[i]=1000000000000000000;
	for (int i=0;i<n;i++) cin >> h[i];
//	a[1]=abs(h[0]-h[1]);
//	cout << a[0] << " " << a[1] << " ";
	for (int i=1;i<n;i++){
		for(int j=1;j<=k and j<=i;j++) a[i]=min(a[i-j]+abs(h[i]-h[i-j]),a[i]);
//		cout << a[i] << " ";
	}
	cout << a[n-1];
return 0;
}

// 6 30 10 60 10 60 50

Measured memory_bytes: 1792
from itertools import permutations

def solve(N, P, Q):
    l = list(permutations(range(1, N+1)))
    
    a = l.index(P)
    b = l.index(Q)
    return abs(a-b)

def main():
    N = int(input())
    P = tuple(int(x) for x in input().split())
    Q = tuple(int(x) for x in input().split())
    ans = solve(N, P, Q)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 8052
n = int(input())
d = dict()
res = 0
for i in range(n):
    ss = input()
    ss = list(ss)
    ss.sort()
    ss = ''.join(ss)
    if d.__contains__(ss):
        res += d[ss]
        d[ss]+=1
    else:
        d[ss] = 1
print(res)


Measured memory_bytes: 17932
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        for (int i = 9; i >= 0; i--) {
            if (num > i * 111) {
                System.out.println((i + 1)*111);
                break;
            }
        }
    }
}


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

int main() {
    string s, t; cin >> s >> t; int minsz = s.size();
    for (int i = 0; i < s.size()-t.size()+1; i ++) {
        string currstr = ""; int diffcnt = 0;
        for (int j = 0; j < t.size(); j ++) currstr += s[i+j];
        for (int j = 0; j < t.size(); j ++) diffcnt += !(currstr[j] == t[j]);
        minsz = min(minsz, diffcnt);
    } cout << minsz << endl;
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "YES", string no = "NO") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    ll A, V, B, W, T; cin >> A >> V >> B >> W >> T;
    ll diff = abs(A - B);
    ll close_s = V - W;
    if (close_s <= 0LL) {
        yesno(false);
        return 0;
    }
    if (T * close_s >= diff) {
        yesno(true);
    } else {
        yesno(false);
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int b,c,d,flg;
	flg=0;
	scanf("%d %d %d",&b,&c,&d);
	if(b==1&&c==1&&d==0){
		flg=1;
	}
	if(b==0&&c==0&&d==1){
		flg=1;
	}
	if(flg==0){
		printf("Close\n");
	}
	if(flg==1){
		printf("Open\n");
	}
	return 0;
}


Measured memory_bytes: 2064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        if (a + b == 3) {
            System.out.println(3);
        }else if(a + b == 4) {
            System.out.println(2);
        }else {
            System.out.println(1);
        }
    }
}


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


signed main(){

    

    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int c1 =0, c2 =0;
    for(int i=0;i<2*n;i++){
    	if(i%2==0){
    		cout<<s[c1++];
    	}else{
    		cout<<t[c2++];
    	}
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int dir=0;
    vector<char> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
        if(s[i] == 'E'){
            dir++;
        }
    }
    int _min = n+1;
    for(int i=0; i<n; i++){
        if(s[i] == 'E'){
            dir--;
        }
        _min = min(_min, dir);
        if(s[i] == 'W'){
            dir++;
        }
    }
    cout << _min << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5+1;
int n, a[N], b[N];
V<int> ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  FORR(i, n, 1){
    int s = 0;
    for(int j = i; j <= n; j += i) s += b[j];
    if(s%2 != a[i-1]){
      b[i]++;
      ans.pb(i);
    }
  }
  cout << sz(ans) << endl;
  FOR(i, 0, sz(ans)) cout << ans[i] << (i<sz(ans)-1 ? " " : "\n");
}

Measured memory_bytes: 2936
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

class Main implements Runnable {
	public static final long MOD = 1000000007;
	private final FastScanner sc;
	private final PrintWriter out;
	int n,a,b;
	

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 16L * 1024 * 1024).start();
	}

	Main() {
		sc = new FastScanner();
		out = new PrintWriter(System.out);
	}

	private void init() throws Exception {
		n = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
	}

	private void solve() throws Exception{
		int d = b - a;
		if(d%2==0){
			out.println("Alice");
		} else {
			out.println("Borys");
		}
	}

	/*
	 * private void exit(int status){ out.flush(); out.close();
	 * System.exit(status); } //
	 */
	public void run() {
		try {
			init();
			solve();
		} catch (Exception e) {
			e.printStackTrace();
		}
		out.flush();
		out.close();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean read() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
			return true;
		}
	}

	private boolean hasNext() {
		while (read() && !isVisibleChar(buffer[ptr]))
			ptr++;
		return read();
	}

	private int getNextChar() {
		if (read()) {
			ptr++;
			return buffer[ptr - 1];
		} else {
			return -1;
		}
	}

	private static boolean isVisibleChar(int code) {
		return code >= 33 && code <= 126;
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = getNextChar();
		while (isVisibleChar(b)) {
			sb.appendCodePoint(b);
			b = getNextChar();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean sign = true;
		int b = getNextChar();
		if (b == '-') {
			sign = false;
			b = getNextChar();
		}
		if (b < '0' || b > '9') {
			throw new NumberFormatException();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isVisibleChar(b)) {
				return sign ? n : -n;
			} else {
				throw new NumberFormatException();
			}
			b = getNextChar();
		}
	}

	public int nextInt() {
		long n = nextLong();
		if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) n;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public void close() {
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class IntQueue {
	protected int[] a;
	protected int head, tail;

	public IntQueue(int max) {
		a = new int[max];
	}

	public void offer(int x) {
		a[tail++] = x;
	}

	public int poll() {
		return a[head++];
	}

	public int peek() {
		return a[head];
	}
}


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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	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;
}

signed main() {
    char C;
    cin >> C;
    C+=1;
    cout << C << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
const ll INF = 1LL << 60;
const double PI = acos(-1.0);

const ll MOD = 1000000007LL;

int main() {

	int n; cin >> n;
	vector<int> a(n), a_idx(n+1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a_idx[a[i]] = i;
	}
	set<int> idx;
	idx.insert(n);
	idx.insert(-1);

	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		int mn_idx = a_idx[i];
		idx.insert(mn_idx);
		ll left = (ll)(mn_idx - *(--idx.find(mn_idx)));
		ll right = (ll)(*(++idx.find(mn_idx)) - mn_idx);
		ans += i*left * right;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11136
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	cout << s.substr(0, 3) << endl;
	return 0;
}

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

int main(){
  char X[1001],Y[1001];
  int i,j,n,x,y,k;
  int l[1001][1001];  
  scanf("%d",&n);
  
  for(k=0;k<n;k++){
    
    scanf("%s %s",X+1,Y+1);
    x=strlen(X+1);
    y=strlen(Y+1);
    
    for(i=1;i<=x;i++){
      for(j=0;j<=y;j++){
	l[i][j]=0;
      }	
    }
    
    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
	if(X[i]==Y[j])  l[i][j]=l[i-1][j-1]+1;
	else if(l[i-1][j]>=l[i][j-1]) l[i][j]=l[i-1][j];
	else l[i][j]=l[i][j-1];
      }
    }
   
    printf("%d\n",l[i-1][j-1]);
    
  }
return 0;
}

Measured memory_bytes: 4524
// 2020.4.16

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <stdlib.h>
#include <cstdio>

using namespace std;

char S[4];
int S2[4];
int n = 4;

int dfs(int i, int sum, string str) {
    return 0;
}

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

    // for (int i = 0; i < n; i++) {
    //     // cout << i << "番目： " << atoi(S.substr(i, 1)) << endl;
    //     // S2[i] = (int)S[i];
    //     // cout << S2[i] << endl;
    //     // cout << S[i] - '0' << endl;
    //     S2[i] = S[i] - '0';
    // }

    // dfs(1, 0, S[0]);

    scanf("%s", S);
    int a = S[0] - '0';
    int b = S[1] - '0';
    int c = S[2] - '0';
    int d = S[3] - '0';

    if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if (a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <numeric>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=true;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll a,b,c,d;

ll gcd(ll n,ll m){
    if(n<m) return gcd(m,n);
    ll tmp;
    while(tmp=n%m){
        n=m;
        m=tmp;
    }
    return m;
}

int main(void) {
    cin >> a >> b >> c >> d;
    ll x=(d*c)/gcd(c,d);
    // DEBUG{cout << x << endl;}
    ll cnt=0;
    cnt += b/c;
    cnt -= (a-1)/c;
    cnt += b/d;
    cnt -= (a-1)/d;
    cnt -= b/x;
    cnt +=(a-1)/x;
    cout << b-a+1-cnt << endl;

    return 0;
}


Measured memory_bytes: 256
N, M, Q = map(int, input().split())
scores = [[0]*(N+1) for i in range(N+1)]

for i in range(M):
    L, R = map(int, input().split())
    scores[L][R] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        scores[i][j] += scores[i][j-1]
for i in range(1, N+1):
    for j in range(1, N+1):
        scores[i][j] += scores[i-1][j]

outputs = []
for i in range(Q):
    p, q = map(int, input().split())
    outputs.append(scores[q][q] - scores[p-1][q])

for output in outputs:
    print(output)

Measured memory_bytes: 17492
import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char[] c = s.toCharArray();
        if(c[2]==c[3]&&c[4]==c[5]){
            System.out.println("Yes");
        }
        else System.out.println("No");


    }
}

Measured memory_bytes: 23764
#include <stdio.h>

main(){
  double v, nv, t;
  int n, i;

  while(1){
    if(scanf("%lf", &nv)==EOF) break;
    nv = nv * nv;
    for(i=1;;i++){
      t = ((double)i-1.0)*5.0 / 4.9;
      v = 9.8 * 9.8 * t;
      if(v>=nv){
	printf("%d\n", i);
	break;
      }
    }
  }
  return 0;
}

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


int main()
{
	lli n;
	cin>>n;

	vector<lli> a(n), b(n), c(n), av(n), bv(n), cv(n);
	for(lli i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}

	av[0] = a[0];
	bv[0] = b[0];
	cv[0] = c[0];

	for(lli i=1;i<n;i++)
	{
		av[i] = max(bv[i-1], cv[i-1]) +a[i];
		bv[i] = max(av[i-1], cv[i-1]) +b[i];
		cv[i] = max(bv[i-1], av[i-1]) +c[i];
	}

	cout<<max(max(av[n-1], bv[n-1]),cv[n-1])<<endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
  
int GCD( int NO_1, int NO_2 );
  
int main(void)
{
    int NO_1 = 0;
    int NO_2 = 0;
 
    scanf("%d %d", &NO_1, &NO_2);
 
    printf("%d\n", GCD(NO_1, NO_2));
      
    return 0;
}
  
int GCD( int NO_1, int NO_2 ) {

    if ( NO_1 > NO_2 ) {
        if (NO_1 % NO_2 != 0) {
            return GCD( NO_1 % NO_2, NO_2 );
        } else {
            return NO_2;
        }
    } else {
        if ( NO_2 % NO_1 != 0 ) {
            return GCD( NO_1, NO_2 % NO_1 );
        } else {
            return NO_1;
        }
    }
}


Measured memory_bytes: 2108
n =int(input())
b = list(map(int,input().split()))
a = []
a.append(b[0])
sum = 0


for i in range(n-1):
    if(i>0):
        if(b[i]>=b[i-1]):
            a.append(b[i-1])
        else:
            a.append(b[i])

if(a[-1]>=b[-1]):
    a.append(a[-1])
else:
    a.append(b[-1])

for j in range(n):
    sum += a[j]

print(sum)


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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  int v,e;cin>>v>>e;
  vector<pair<int, pi>>edges;
  rep(i, e){
    ll a,b,c;cin>>a>>b>>c;
    edges.push_back({c, {a, b}});
  }
  sort(edges.begin(), edges.end());

  UnionFind uf(v);

  ll result = 0;
  for(auto p: edges)if(!uf.same(p.second.first, p.second.second)){
    result += p.first;
    uf.unite(p.second.first, p.second.second);
  }

  cout<<result<<endl;

  return 0;
}



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

#define MAX_N 100001
#define INF 100000000000001

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
long long diff_weight[MAX_N];
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
		diff_weight[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		long long f = find(par[x]);
		diff_weight[x] += diff_weight[par[x]];
		return par[x] = f;
	}
}

long long weight(long long x) {
  find(x); // 経路圧縮
  return diff_weight[x];
}

long long diff(long long x, long long y) {
  return weight(y) - weight(x);
}

// xとyの属する集合を併合
void unite(long long x, long long y, long long d) {
	d += weight(x); d -= weight(y);
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
		diff_weight[x] = -d;
	} else {
		par[y] = x;
		diff_weight[y] = d;

		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> R(M-1+1);
	vector<long long> D(M-1+1);
	vector<long long> L(M-1+1);
	init(N+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&L[i]);
		scanf("%lld",&R[i]);
		scanf("%lld",&D[i]);
	}
	bool flg = true;
	for(int i = 0 ; i <= M-1 ; i++){
		long long d = INF;
		if (same(L[i],R[i])) d = diff(L[i],R[i]);
		unite(L[i],R[i],D[i]);
		if (d != INF && d != D[i]) flg = false;
		// printf("%lld, %lld\n", d, D[i]);
	}
	if (flg) printf("Yes\n"); else printf("No\n");


	return 0;
}


Measured memory_bytes: 7296
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	string S;
	cin >> S;


	if (S.length() < 4)
	{
		cout << "No";
		return 0;
	}
	else
	{
		if (S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I')
		{
			cout << "Yes";

		}
		else

		{
			cout << "No";
		}
	}



}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int h, w, n;
int main() {
    cin >> h >> w;
    cin >> n;
    vector<int> a(n, 0);
    for(int i = 0; i < n; ++i) cin >> a.at(i);

    vector<vector<int>> mas(h, vector<int>(w, 0));
    int idx = 0;
    for(int i = 0; i < h; ++i) {
        if(i % 2 == 0) {
            for(int j = 0; j < w; ++j) {
                if(a.at(idx) > 1) {
                    mas.at(i).at(j) = idx+1;
                    a.at(idx)--;
                }else {
                    mas.at(i).at(j) = idx+1;
                    idx++;
                }
            }
        }else {
            for(int j = w-1; j >= 0; --j) {
                if(a.at(idx) > 1) {
                    mas.at(i).at(j) = idx+1;
                    a.at(idx)--;
                }else {
                    mas.at(i).at(j) = idx+1;
                    idx++;
                }
            }
        }
    }

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cout << mas.at(i).at(j) << " ";
        }
        cout << endl;
    }
}

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

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

    int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    int ans = 0;
    for (int i = 0; i < N;) {
        if (h[i] == 0) {
            i++;
            continue;
        }
        for (int j = i; j < N; j++) {
            if (h[j] == 0) break;
            h[j]--;
        }
        ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	long long n,p;
	cin>>n>>p;
	long long jg = pow(p,1.0/n);
	for(long long i = jg+1;;i--){
		if(p%(long long)pow(i,n) == 0){
			jg = i;
			break;
		}
	}
	printf("%lld\n",jg);
	return 0;
}

Measured memory_bytes: 256
##get int
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

##get string
#first_input = input().split(" ")

X = first_input[0]
num500 = X//500
num5 = (X-num500*500)//5

print(num500*1000+num5*5)


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

using namespace std;

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

  int n, m;
  cin >> n >> m;

  vector<int> l(m), r(m);
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i];
  }

  int a = 1, b = n;
  for (int i = 0; i < m; ++i) {
    a = max(a, l[i]);
    b = min(b, r[i]);
  }

  int ans = b - a + 1;
  if (ans < 0) {
    ans = 0;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3964