akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define debug(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    ll n, k, c;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> tmp;
    vector<bool> flag(n, false); //前に来たかどうかのflag
    for (ll i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = c - 1; //配列の番号と合わせるため
    }

    tmp.pb(0);
    flag[0] = true;

    for (ll i = 0; i < n; i++)
    {
        tmp.pb(a[tmp[i]]);
        if (flag[a[tmp[i]]] == true)
            break;
        flag[a[tmp[i]]] = true;
    }

    auto loop_start_place_iter = find(tmp.begin(), tmp.end(), *(tmp.end() - 1));
    ll loop_num = distance(loop_start_place_iter, tmp.end()) - 1;
    ll before_num = tmp.size() - loop_num - 1;

    //debug(loop_num);
    //debug(before_num);

    //debug(before_num + (k- before_num ) % loop_num);
    //DEBUG_VEC(tmp);

    if (k > before_num)
    {
        cout << tmp[before_num + (k- before_num ) % loop_num] + 1 << endl;
    }
    else
    {
        cout << tmp[k] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 6884
def solve2():
    """ メモ化再帰 
    N=1000以上で RecursionError: maximum recursion depth exceeded in comparison

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    """
    import sys
    sys.setrecursionlimit(10**5+10)  # RecursionError対策

    N = int(input())
    H = list(map(int, input().split()))

    INF = 10**14+10
    dp = [INF] * (N+10)
    dp[0] = 0
    dp[1] = abs(H[0]-H[1])

    def dfs(i):
        """ 足場iの時点の最小値を返す """
        if dp[i] < INF: return dp[i]
                
        ans1, ans2 = INF, INF
        ans1 = dfs(i-1) + abs(H[i]-H[i-1])  # i-1の足場から来た場合
        if i-2 >= 0:
            ans2 = dfs(i-2) + abs(H[i]-H[i-2])  # i-2の足場から来た場合

        dp[i] = min(ans1, ans2)

        return dp[i]
    
    print(dfs(N-1))


if __name__ == "__main__":
    solve2()

Measured memory_bytes: 119812
#include<iostream>
using namespace std;
int main(){
	int n;
  cin>>n;
  int p=0;
  int a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
    if(a[i]%2==0){
    	if(a[i]%3!=0&&a[i]%5!=0)p=1;
    }
  }
  if(p==1)cout<<"DENIED"<<endl;
  else cout<<"APPROVED"<<endl;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

using namespace std;

template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vl a(N+2),s1(N+2),s2(N+2);
  rep(i,N) cin >> a[i+1];
  ll ssum = 0LL;
  rep(i,N+1) ssum += abs(a[i+1]-a[i]);
  REP(i,1,N+1){
    ll temp = abs(a[i]-a[i+1]) + abs(a[i]-a[i-1]);
    temp -= abs(a[i-1]-a[i+1]);
    cout << ssum - temp << endl;
  }
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 

typedef long long int ll; 
const ll mod = 1000000007;
vector<ll>v,h; 

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t;
    t=1;
    while(t--){
        ll a,b,c;
        cin>>a>>b>>c;
        if((a==b&&a!=c)||(a==c&&c!=b)||(b==c&&b!=a)){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

static const int MAX = 100005;
int N;
int A[MAX], B[MAX];
int mod = 1000000007;

int main(){
	for(int i = 0; i < MAX; i++){
		A[i] = 0;
	}

	cin >> N;
	int idx;
	for(int i = 0; i < N; i++){
		cin >> idx;
		A[idx]++;
	}

	int ans = 1;
	for(int i = 0; i < N / 2; i++){
		ans = (ans * 2) % mod;
	}

	if(N % 2 == 0){
		int i = 1;
		while(i <= N - 1){
			if(A[i] != 2){
				cout << 0 << endl;
				return 0;
			}
			i += 2;
		}
		cout << ans << endl;
		return 0;
	}else{
		if(A[0] != 1){
			cout << 0 << endl;
			return 0;
		}
		int i = 2;
		while(i <= N - 1){
			if(A[i] != 2){
				cout << 0 << endl;
				return 0;
			}
			i += 2;
		}
		cout << ans << endl;
		return 0;
	}
}	


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>

using namespace std;

int main() {
    size_t a, b;
    cin >> a >> b;
    size_t c = 0;
    size_t sum = 1;
    while (sum < b) {
        sum += a;
        sum -= 1;
        ++c;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np
from numba import njit
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    s=readline().strip()
    ans=s.count("R")*s.count("G")*s.count("B")
    s=np.array([0 if s[i]=="R" else 1 if s[i]=="G" else 2 for i in range(n)],dtype=np.int64)

    print(f(n,ans,s))

@njit
def f(n,ans,s):
    for i in range(n):
        for j in range(i+1,n):
            k=2*j-i
            if k>=n: break
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans-=1
    return ans

if __name__=="__main__":
    main()

Measured memory_bytes: 109780
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    lint ans = 0;
    for(lint i=1; i<n; i++) {
        lint j = n-i;
        if(i<=j)  continue;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a = str(input())
b = int(a[:2])
c = int(a[2:])

if 1 <= b <= 12 and 1 <= c <= 12: 
    print("AMBIGUOUS")
elif 1 <= b<= 12:
    print("MMYY")
elif 1 <= c <= 12:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll arr[3005], dp[3005][3005];
ll solve(bool turn, int begin, int end, ll sum)
{
	if (begin == end)
		return arr[begin];
	if (dp[begin][end])
		return dp[begin][end];
	return dp[begin][end] = sum - min(solve(!turn, begin + 1, end, sum - arr[begin]), solve(!turn, begin, end - 1, sum - arr[end]));
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		sum += arr[i];
	}
	cout << 2 * solve(0, 0, n - 1, sum) - sum << '\n';
	return 0;
}

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

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] AV = Array.ConvertAll(Console.ReadLine().Split(),double.Parse);
            double A = AV[0];
            double V = AV[1];
            double[] BW = Array.ConvertAll(Console.ReadLine().Split(),double.Parse);
            double B = BW[0];
            double W = BW[1];
            double T = double.Parse(Console.ReadLine());
            bool flag = false;
            if(V>W){
                if(Math.Abs(A-B)/(V-W)<=T){
                    flag = true;
                }
            }
            Console.WriteLine(flag?"YES":"NO");
        }   
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}


Measured memory_bytes: 27512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "2016B") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    int n, a, b; string str; cin >> n >> a >> b >> str;
    int ac = 0, bc = 0;
    for (int i = 0; i < n; i++) {
        if (str[i] == 'a' && ac + bc < a + b) {
            cout << "Yes" << "\n";
            ac++;
        } else if (str[i] == 'b' && ac + bc < a + b && bc < b) {
            cout << "Yes" << "\n";
            bc++;
        } else {
            cout << "No" << "\n";
        }
    }
}

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;



signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   string s;
   cin >> s;
   stack <char> st;
   vector <char> v;
   for (int i = 0; i < s.size(); i++) {
      if (st.size() == 0) {
         st.push(s[i]);
      }
      else {
         if (st.top() == 'S' && s[i] == 'T') st.pop();
         else st.push(s[i]);
      }
   }
   cout << st.size();
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N);
    vector<ll> cum(N);
    ll sum = 0;
    REP(i,N){
        cin >> a[i];
        sum += a[i];
    }
    cum[0] = a[0];
    for(int i=1;i<N;i++) cum[i] = cum[i-1] + a[i];
    ll ans = LINF;

    REP(i,N){
        ll tmp = cum[i];
        ll rest = sum - cum[i];
        chmin(ans,abs(tmp-rest));
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

template <typename T,typename E>
struct SegmentTree{
private:
    typedef std::function<T(T,T)> F;
    typedef std::function<T(T,E)> G;
    int n;
    std::vector<T> init;
    F f;//function for caliculate
    G g;//function for update
    std::vector<T> node;

public:
    explicit SegmentTree(
            int sz,
            F cal,
            G upd,
            std::vector<T> initv=std::vector<T>(1,0)
    ){
        n=1;
        init=initv;
        f=cal;
        g=upd;
        while(n<sz)n=n*2;
        node.assign(static_cast<unsigned int>(2 * n-2), init[0]);
        for (int i = 0; i <sz ; ++i) node[i+n-1]=init[i+1];
        for (int i = n-2; i >= 0 ; --i) node[i]=f(node[2*i+1],node[2*i+2]);
    }

    void update(int x, E val){//x:0-indexed
        x+=n-1;
        node[x]=g(node[x],val);
        while(x>0){
            x=(x-1)/2;
            node[x]=f(node[2*x+1],node[2*x+2]);
        }
    }

    T query(int p,int q,int k=0,int l=0,int r=-1){//[p,q):0-indexed
        if(r<0)r=n;
        if(r<=p||l>=q)return init[0];//out of range
        if(p<=l&&r<=q)return node[k];

        return f(query(p,q,2*k+1,l,(l+r)/2),query(p,q,2*k+2,(l+r)/2,r));
    }
};

int main() {
    int n;
    cin>>n;
    ll c;
    cin>>c;
    vector<pair<ll,ll>> d;
    for(int i = 0;i < n;++i) {
        ll x,v;
        cin>>x>>v;
        d.emplace_back(x,v);
    }
if(n==1) {
    cout<<max(0LL,max(d[0].second-d[0].first,d[0].second-(c-d[0].first)))<<endl;
    return 0;
}
    vector<ll> cw(n+1,-12345678901234LL);
    cw[1]=d[0].second-d[0].first;
//cerr<<cw[1]<<endl;
    for(int i = 1;i < n;++i) {
        cw[i+1]=cw[i]+d[i].second-(d[i].first-d[i-1].first);
//cerr<<cw[i+1]<<endl;
    }
    vector<ll> ccw(n+1,-12345678901234LL);
    ccw[1]=d[n-1].second-(c-d[n-1].first);
//cerr<<ccw[1]<<endl;
    for(int i = 1;i < n;++i) {
        ccw[i+1]=ccw[i]+d[n-1-i].second-(d[n-i].first-d[n-1-i].first);
//cerr<<ccw[i+1]<<endl;
    }
    SegmentTree<ll,ll> st1(n,
        [](ll a,ll b){return std::max(a,b);},
        [](ll a,ll b){return b;},
        cw
    );
    SegmentTree<ll,ll> st2(n,
        [](ll a,ll b){return std::max(a,b);},
        [](ll a,ll b){return b;},
        ccw
    );

    ll ans = 0;
    ll tans;
    for(int i = 0;i < n;++i) {
        tans=cw[i+1];
//cerr<<i<<" "<<st2.query(0,n-1-i)<<endl;
        if(i!=n-1&&st2.query(0,n-1-i)>d[i].first){
//cerr<<i<<" "<<st2.query(0,n-1-i)<<endl;
            tans-=d[i].first;
            tans+=st2.query(0,n-1-i);
        }
//cerr<<tans<<endl;
        ans=max(ans,tans);
    }

    for(int i = 0;i < n;++i) {
        tans=ccw[i+1];
        if(i!=n-1&&st1.query(0,n-1-i)>c-d[n-1-i].first){
            tans-=c-d[n-1-i].first;
            tans+=st1.query(0,n-1-i);
        }
        ans=max(ans,tans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9840
N = int(input())
A = list(map(int, input().split()))

cnt = 0
ans = 0
absmin = 10**9
for i in range(N):
    ans += abs(A[i])
    if A[i] < 0:
        cnt += 1
    if abs(A[i]) < absmin:
        absmin = abs(A[i])

if cnt % 2 == 0 or 0 in A:
    print(ans)
else:
    print(ans - 2 * absmin)


Measured memory_bytes: 14412
//********** ANKIT KESARWANI **********//
#include <bits/stdc++.h>/
using namespace std;
#define   FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define   vi vector<int>
#define   pii pair<int,int>
#define   all(a) (a).begin(), (a).end()
#define   rep(i,a,b)  for(int  i=a;i<b;i++)
#define   tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define   pb push_back
#define   endl  "\n"
#define   dbg(x,y) cout<<(x)<<" -->  "<<(y)<<endl
#define   F first
#define   S second
#define   int long long
const int  N=2e5+20;
const int  inf=1e18;
const int  ninf=-1e17 ;
const int  mod=1e9+7;
/*------------------------------------------------------------------------------------------------------------------------*/
int n;

vector<vi> matmul(vector<vi> & a,vector<vi> &b)
{
    vector<vi>c(n,vi(n));

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j]+=(a[i][k]*b[k][j]);
                c[i][j]%=mod;
            }
        }
    }
    return c;
}
vector<vi> power(vector<vi> &a,int k)
{
    if(k==1LL)
    {
        return a;
    }
    vector<vi> v;
    if(k&1)
    {
        v=power(a,k-1);
        return matmul(a,v);
    }
    v=power(a,k/2);
    return matmul(v,v);
}

void solve()
{
    int k;cin>>n>>k;

    vector<vi> v(n,vi(n));

    rep(i,0,n)
    rep(j,0,n)
    cin>>v[i][j];

    vector<vi>final_mat=power(v,k);
    int ans=0;

    rep(i,0,n)
    {
        rep(j,0,n)
        {
            ans+=final_mat[i][j];
            ans%=mod;
        }
    }

    cout<<ans<<endl;


}





signed main()
{
  FASTIO;
  int T=1;
  //cin>>T;
  while (T--)
    solve();
  return 0;
}


Measured memory_bytes: 384
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)*}
    };
}

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)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    a: chars,
    b: chars,
    }
    let mut ab = a;
    ab.extend_from_slice(&b);
    let n = ab.len();
    let mut p = 0;
    for i in (0..n).rev() {
        p += ab[i].to_digit(10).unwrap() as usize * 10usize.pow((n - i - 1) as u32);
    }
    let mut i:usize = 2;
    while i.pow(2) <= p{
        if i.pow(2) == p {
            println!("Yes");
            return;
        }
        i += 1;
    }
    println!("No")
}


Measured memory_bytes: 4352
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(10000000)

N = int(input())
A_list = [int(e) for e in input().split()]

#pairwise coprime …… 素因数分解したとき、共通のものが1個もない
#setwise coprime　…… 素因数分解したとき、全てで共通のものがない

#試し割の結果の辞書を求める
def make_trial_division_dict(n):
    #import math
    td_dict = dict()
    for i in range(2,n+1):
        if i not in td_dict:
            td_dict[i] = i
            for j in range(2,1+n//i):
                if j*i not in td_dict:
                    td_dict[j*i] = i
    td_dict[1] = 1
    return td_dict

#試し割結果の辞書を利用して素因数分解する
@lru_cache(maxsize=None)
def high_speed_prime_factorization(n):
    pf_list = list()
    pf_list.append(td_dict[n])
    
    if n//td_dict[n] == 1:
        if n!=1:
            pf_list.append(1)
        return pf_list
    else:
        pf_list.extend(high_speed_prime_factorization(n//td_dict[n]))
        return pf_list

td_dict = make_trial_division_dict(max(A_list))

all_pf = set()    #含まれる素因数がすべて集約される
common_pf = set() #共通する素因数が集約される
all_pf |= set(high_speed_prime_factorization(A_list[0]))
common_pf |= set(high_speed_prime_factorization(A_list[0]))
is_pairwise = True

#print(A_list[0],set(high_speed_prime_factorization(A_list[0])))

for i in range(1,len(A_list)):
    A_pf = set(high_speed_prime_factorization(A_list[i]))
    common_pf &= A_pf 
    
    #print(A_list[i],set(high_speed_prime_factorization(A_list[i])))
    
    if is_pairwise and len(all_pf&A_pf)!=1: #1は共通で含まれる
        is_pairwise = False
    else:
        all_pf |= A_pf

if is_pairwise:
    print("pairwise coprime")
elif len(common_pf) == 1: #1は共通で含まれる
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 320056
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int S[100005],T[100005],n,ans,sum;
int A[100005],B[100005],sa,sb;
int fa[100005],Do[200005];
int gg(){printf("-1");return 0;}
int ask(int x){if(fa[x]==x)return x;return fa[x]=ask(fa[x]);}
void unite(int x,int y){fa[x]=y;}
int main(){
//  freopen("duliu.in","r",stdin);
//  freopen("duliu.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&A[i]),sa^=A[i];A[n+1]=sa;
    for(int i=1;i<=n;i++)scanf("%d",&B[i]),sb^=B[i];B[n+1]=sb;
    memcpy(S,A,sizeof A);memcpy(T,B,sizeof B);
    n++;sort(S+1,S+1+n);sort(T+1,T+1+n);
    for(int i=1;i<n;i++)if(S[i]^T[i])return gg();
    for(int i=1;i<=n;i++)
    	if(A[i]^B[i]||(i==n)){
			Do[++sum]=A[i];
			Do[++sum]=B[i];
			if(i<n)ans++;
		}
	if(ans==0)return printf("0"),0;
	sort(Do+1,Do+1+sum);
	sum=unique(Do+1,Do+sum+1)-Do-1;
	for(int i=1;i<=sum;i++)fa[i]=i;
	for(int i=1;i<=n;i++){
		if(A[i]^B[i]){
			A[i]=lower_bound(Do+1,Do+1+sum,A[i])-Do;
			B[i]=lower_bound(Do+1,Do+1+sum,B[i])-Do;
			unite(ask(A[i]),ask(B[i]));
		}
	}
	for(int i=1;i<=sum;i++)ans+=(fa[i]==i);
	printf("%d",ans-1);
}
/*
3
1 2 3
1 3 2
*/
/*
4
1 4 2 6
1 2 4 6
*/
/*
10
1 3 3 9 4 5 1 6 4 0
4 1 3 9 10 4 3 1 6 5
*/
/*
5
1 2 4 8 0
2 1 15 8 4
*/
/*
10
1 2 3 4 4 5 6 7 8 12
2 1 4 3 4 0 5 6 7 8
*/
/*
10
1 2 3 4 5 6 7 8 9 10
10 1 2 3 4 5 6 7 8 9
*/
/*
10
1 2 3 4 5 6 7 8 9 10
2 1 4 3 6 5 8 7 10 9
*/
/*
9
1 2 3 4 5 6 7 8 9
9 1 2 3 4 5 6 7 8
*/

Measured memory_bytes: 4480
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int sum=0;
		// 整数の入力
		int N = sc.nextInt();
      	int[] L=new int[N];
		for(int i=0;i<N;i++){
		L[i] = sc.nextInt();
        }
      	Arrays.sort(L);
      	for(int i=0;i<N-1;i++){
          sum=sum+L[i];
        }
      if(L[N-1]<sum){
		System.out.println("Yes");
      }else{
        System.out.println("No");
      }
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, S; cin >> N >> K >> S;
    vector<int> A(N);
    for (int i = 0; i < K; i++) A[i] = S;
    for (int i = K; i < N; i++) A[i] = (S == 1e9 ? 1 : 1e9);
    for (auto a : A) cout << a << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int m,n,i,j=0,t=0;
  cin>>n>>m;
  if(n!=1 && n!=0)
  {
  	for(i=1;i<n;i++)
 	 {
	j=j+i;
 	 }
    for(i=1;i<m;i++)
    {
		t=t+i;
    }
    if(m>1)
    {
  	j=j+t;
    }
  	cout<<j;
  }
  else
  {
    if(m>1)
    {
      for(i=1;i<m;i++)
      {t=t+i;
      }
      cout<<t;
      
    }
    else
    {
      cout<<0;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for(int a = 1;a>0;a++){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0){
				break;
			}
			for(int b = 0;b<H;b++){
				for(int c =0;c<W;c++){
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 25744
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int A,B;
    cin >> A >> B;
    cout << (A^B) << endl;
    return 0;
}



Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop i acc =
        if i = n then acc else
            if a.(i) = a.(i - 1) then (
                a.(i) <- -i;
                loop (i + 1) (acc + 1)
            ) else loop (i + 1) acc
    in
    loop 1 0 |> Printf.printf "%d\n"
)

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

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

    int count = 0;

    for(int i = 0; i < 3; i++){
        if(S.at(i) == 'o'){
            count++;
        }
    }

    int P = 700 + (100 * count);

    cout << P << endl;

}

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

void maze_fill(vector<vector<int> > &maze, int c, int d, int x, int y){
	int w, h;
	if(d == 0){
		w = 4;
		h = 2;
	}else{
		w = 2;
		h = 4;
	}

	for(int i=y;i<y+h;i++)
		for(int j=x;j<x+w;j++)
			maze[i][j] = c;
}

void search(vector<vector<int> > &maze, int x, int y, int c){
	maze[y][x] = 6;

	if(maze[y-1][x] == c)
		search(maze, x, y-1, c);
	
	if(maze[y][x-1] == c)
		search(maze, x-1, y, c);
	
	if(maze[y+1][x] == c)
		search(maze, x, y+1, c);
	
	if(maze[y][x+1] == c)
		search(maze, x+1, y, c);
}

int main(){
	while(1){
		int w, h, xs, ys, xg, yg, n;
		vector<vector<int> > maze;

		cin>>w>>h;
		if((w == 0) && (h == 0))
			break;

		maze.resize(h+2);
		for(int i=0;i<h+2;i++)
			maze[i].resize(w+2);

		for(int i=0;i<h+2;i++){
			if((i == 0) || (i == h+1)){
				for(int j=0;j<w+2;j++)
					maze[i][j] = 9;
			}else{
				maze[i][0] = 9;
				maze[i][w+1] = 9;
				for(int j=1;j<w+1;j++)
					maze[i][j] = 0;
			}
		}

		cin>>xs>>ys;
		cin>>xg>>yg;
		cin>>n;
		for(int i=0;i<n;i++){
			int c, d, x, y;
			cin>>c>>d>>x>>y;
			maze_fill(maze, c, d, x, y);
		}
		
		search(maze, xs, ys, maze[ys][xs]);

		if(maze[ys][xs] == maze[yg][xg])
			cout<<"OK"<<endl;
		else
			cout<<"NG"<<endl;
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  int sum = 0;
  rep(i,n-1)sum+=a.at(i);
  cout << sum + a.at(n-1)/2 << endl;
 }


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long INF = 1L << 50;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto P = s[2].to!long;
    auto G = new Edge!long[][](N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        auto u = s[0] - 1;
        auto v = s[1] - 1;
        long c = -s[2] + P;
        G[u] ~= Edge!long(v, c);
    }

    auto dist = bellman_ford!(long, INF)(G, 0);

    if (dist[N-1] == -INF) {
        writeln(-1);
    } else {
        writeln(max(0L, -dist[N-1]));
    }
}

struct Edge(T) {
    int to;
    T cost;
}

T[] bellman_ford(T, T inf)(const Edge!(T)[][] graph, int start) {
    int n = graph.length.to!int;
    auto dist = new T[](n);
    dist[] = inf;
    dist[start] = 0;

    foreach (const i; 0..n) {
        foreach (const u; 0..n) {
            foreach (const e; graph[u]) {
                if (dist[u] != inf && dist[e.to] > dist[u] + e.cost) {
                    dist[e.to] = dist[u] + e.cost;
                    if (i == n - 1) {
                        dist[e.to] = -inf;
                    }
                }
            }
        }
    }

    auto stack = new int[](n);
    int sp = 0;

    foreach (const i; 0..n) {
        if (dist[i] == -inf) {
            stack[sp++] = i;
        }
    }

    while (sp > 0) {
        int u = stack[--sp];
        foreach (const e; graph[u]) {
            if (dist[e.to] == -inf) continue;
            dist[e.to] = -inf;
            stack[sp++] = e.to;
        }
    }

    return dist;
}


Measured memory_bytes: 2300
#include <iostream>

using namespace std;

int B[100];

int main()
{
	int N;
	int sum = 0;

	cin >> N;

	for (int i = 0; i < N - 1; i++) cin >> B[i];

	sum += B[0];
	for (int i = 1; i < N - 1; i++) sum += (B[i - 1] < B[i]) ? B[i - 1] : B[i];
	sum += B[N - 2];

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
a, w, t, r = 0, 0, 0, 0
for i in range(N):
  if s[i] == "AC":
    a += 1
  elif s[i] == "WA":
    w += 1
  elif s[i] == "TLE":
    t += 1
  else:
    r += 1
print("AC x "+str(a), "WA x "+str(w), "TLE x "+str(t), "RE x "+str(r), sep="\n")
    

Measured memory_bytes: 16252
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
double getnum(lint n) {
  lint sum = 0;
  lint tmp = n;
  while(tmp > 0) {
    sum += tmp%10;
    tmp /= 10;
  }
  return (double)n/sum;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint K;
  cin >> K;
  double last = 1;
  lint now = 1;
  lint plus = 1;
  cout << now << "\n";
  REP(k, K-1) {
    while(true) {
      if(getnum(now+plus) - 1e-9 > getnum(now+plus*2)) plus *= 10;
      else break;
    }
    now += plus;
    last = getnum(now);
    cout << now << "\n";
  }
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  double debt = 100000;

  cin >> n;
  for (int i = 0; i < n; i++) {
    debt *= 1.05;
    if ((int)debt % 1000)
      debt = ((int)debt / 1000 + 1) * 1000;
    else
      debt = ((int)debt / 1000) * 1000;
  }
  cout << (int)debt << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int N, W[101];
int S[101];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for (int i=0; i<N; i++)
    cin >> W[i];
  for (int i=0; i<N; i++)
    S[i+1] = S[i] + W[i];
  int ans = abs(S[N-1]-W[N-1]);
  for (int i=1; i<N; i++){
  	ans = min(ans, abs(S[i] - (S[N]-S[i])));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m; cin>>m;
  while(m--){
    string s,t,u;
    set<string> a;
    cin>>s;
    for(int i=1;i<s.size();++i)
      for(int j=0;j<8;++j){
        t=s.substr(0,i),u=s.substr(i);
        if(j%2) reverse(t.begin(),t.end());
        if(j%4>1) reverse(u.begin(),u.end());
        if(j>3) swap(t,u);
        a.insert(t+u);
      }
    cout<<a.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n, k;
  cin >> n >> k;
  long long a[n], count = 0, b[n];
  for(long long i = 0; i < n; i++){
    b[i] = -1;
    cin >> a[i];
  }
  long long now = 1;
  b[now-1] = 0;
  while(1){
    count++;
    now = a[now-1];
    if(b[now-1] != -1){
      break;
    }
    b[now-1] = count;
  }
  long long limit;
  if(b[now-1] < k){
    k -= b[now-1];
    limit = k%(count-b[now-1]);
    for(long long i = 0; i < limit; i++){
      now = a[now-1];
    }
  }else{
    now = 1;
    for(long long i = 0; i < k; i++){
      now = a[now-1];
    }
  }
    
  cout << now << endl;
}


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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int y = 0; y < H; y++) cin >> S[y];
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (S[y][x] == '#') continue;
      int bomb_count = 0;
      for (int dy = -1; dy <= 1; dy++) {
        int y2 = y + dy;
        if (y2 < 0 || H <= y2) continue;
        for (int dx = -1; dx <= 1; dx++) {
          if (dx == 0 && dy == 0) continue;
          int x2 = x + dx;
          if (x2 < 0 || W <= x2) continue;
          if (S[y2][x2] == '#') bomb_count++;
        }
      }
      S[y][x] = '0' + bomb_count;
    }
  }

  for (int y = 0; y < H; y++) {
    cout << S[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  char c;
  while(1){
    scanf("%c",&c);
    if('a'<= c && 'z'>= c){
      c-=32;
      printf("%c",c);
    }
    else{
      printf("%c",c);
    }
    if(c == '\n'){
      break;
    }
  }
  return (0);
}

Measured memory_bytes: 524
import sys
res=[]

for (l,text) in enumerate(sys.stdin):
    if not l%2:
        a=list(map(int,text.split()))
    else:
        h=0
        b=0
        for (i,j) in enumerate(map(int,text.split())):
            if a[i]==j:
                h=h+1
            elif j in a:
                b=b+1
        res.extend([[h,b]])
[print(i[0],i[1]) for i in res]



Measured memory_bytes: 5608
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

macro_rules! tern {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition {
            $_true
        } else {
            $_false
        }
    };
}

fn main() {
    let N = get!(usize);
    let mut cnt = 0;
    let mut base = 1;
    while base <= N {
        if base * 10 <= N {
            cnt += base*9;
        } else {
            cnt += N - base + 1;
        }
        base *= 100;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   ll ans = min(a, k);
   if(k>a){
       if(a + b >= k){
           cout<<ans<<endl;
       }
       else {
           cout<<-1*(k-(a+b)) + a<<endl;
       }
   }
   else cout<<ans;
   
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

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

    vector<int> a(A);
    vector<int> b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    vector<int> x(m);
    vector<int> y(m);
    vector<int> c(m);
    rep(i, m) cin >> x[i] >> y[i] >> c[i];

    int sum;
    int sum_min = N;

    int a_min = *min_element(a.begin(),a.end());
    int b_min = *min_element(b.begin(),b.end());

    for (int i = 0; i < m; ++i) {
            sum = a[x[i] - 1] + b[y[i] - 1] - c[i];
            if (sum < sum_min)sum_min = sum;
    }
    print(min(a_min + b_min,sum_min));
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main()
{
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    string s; cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
        cout << "Yes\n";
    else cout << "No\n";
    



}


Measured memory_bytes: 3636
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
using namespace std;

class Cube{
public:
	int f[6];
	Cube(){}
	void roll_z(){roll(1,2,4,3);}
	void roll_y(){roll(0,2,5,3);}
	void roll_x(){roll(0,1,5,4);}
	void roll(int i, int j, int k, int l){
		int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
	}
};

bool eq( Cube c1, Cube c2){
	for (int i=0;i<6;i++)
		if(c1.f[i] !=c2.f[i])return false;
	return true;
}

bool equal(Cube c1,Cube c2){
	for( int i=0;i<6;i++){
		for( int j=0;j<4;j++){
			if(eq(c1,c2))return true;
			c1.roll_z();
		}
		if(i%2==0)c1.roll_y();
		else c1.roll_x();
	}
	return false;
}

int main() {
	Cube c1,c2;

	for(int i=0;i<6;i++){
		cin>>c1.f[i];
	}
	for(int i=0;i<6;i++){
		cin>>c2.f[i];
	}
	if(equal(c1,c2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3100
n = int(input())
s = {"AC":0, "WA":0, "TLE":0, "RE":0}
for i in range(n):
    temp = input()
    s[temp] += 1
print("AC x " + str(s["AC"]))
print("WA x " + str(s["WA"]))
print("TLE x " + str(s["TLE"]))
print("RE x " + str(s["RE"]))

Measured memory_bytes: 9200
import Foundation

var input = readLine()
var inputs : [String] = input!.components(separatedBy: " ")

var a = Int(inputs[0])!
var b = Int(inputs[1])!
var c = Int(inputs[2])!

if(a + b + c == 17){
    print("YES")
}else{
    print("NO")
}


Measured memory_bytes: 14020
input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
N = len(B)
c = 0
r = A[0]
for i in range(N):
    if B[i] <= r:
        c += B[i]
        r = A[i + 1]
    elif B[i] <= A[i + 1] + r:
        c += B[i]
        r = A[i + 1] + r - B[i]
    else:
        c += A[i + 1] + r
        r = 0
print(c)


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,k;
	cin >> n >> k;
	VL h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	VL dp(n,INT32_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k and i + j < n; j++) {
			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]= new int[n];
        for (int i=0;i<n;i++){
            ar[i]=sc.nextInt();
        }
        int sum=0;
        Arrays.sort(ar);
        for (int i=0;i<k;i++){
            sum+=ar[i];

        }
        System.out.println(sum);
    }
}


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

signed main(void)
{
	long long n;
	cin >> n;
	long long a[n];
	deque<long long> dq;
	bool ok;
	rep(i, n) cin >> a[i];
	ok = false;

	rep(i, n)
	{
		ok ^= 1;
		if (i % 2 == 0)
			dq.push_back(a[i]);
		else
			dq.push_front(a[i]);
	}
	if (ok)
		reverse(dq.begin(), dq.end());
	while(!dq.empty())
	{
		printf("%lld ", dq.front());
		dq.pop_front();
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>

int main(void) {
  int i, j, h, w, cnt[26], c2 = 0, c1 = 0;
  scanf("%d%d", &h, &w);
  char a[w + 10];
  bool ans = false;
  for(i = 0; i < 26; ++i) cnt[i] = 0;
  for(i = 0; i < h; ++i) {
    scanf("%s", a);
    for(j = 0; j < w; ++j) cnt[a[j] - 'a']++;
  }
  for(i = 0; i < 26; ++i) {
    cnt[i] %= 4;
    if(cnt[i] & 2) c2++;
    if(cnt[i] & 1) c1++;
  }
  if((h * w) & 1){
    if(c1 == 1 && c2 <= w / 2 + h / 2) ans = true;
  } else if(h & 1) {
    if(!c1 && c2 <= w / 2) ans = true;
  } else if(w & 1) {
    if(!c1 && c2 <= h / 2) ans = true;
  } else {
    if(!c1 && !c2) ans = true;
  }
  printf("%s", ans ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
   int  a,b;
   cin >> a >>b;
  cout <<max(max(a+b,a-b),a*b);
}

Measured memory_bytes: 256