akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
ll n;
int gcd(int a, int b)
{
    while(a && b)
    {
        if(a > b) a%=b;
        else b%=a;
    }
    return a + b;
}
int solve(int a, int b)
{
    ll g=gcd(a, b);
    ll ag=a/g, bg=b/g;
    if(ag*ag*bg != a) return 0;
    if(bg*bg*ag != b) return 0;
    return 1;
///if()
}
string s1, s2;
bool ch(int idx)
{
    int n=s1.size();
    string ss;
    int ii=idx;
    while(n--)
    {
        ss+=s1[idx++];
        if(idx == s1.size()) idx=0;
    }
///if(ss.size() != s2.size()) cout<<ii<<'\n';
///cout<<ss;
    if(ss == s2) return 1;
    return 0;
}
int main()
{
    cin>>s1>>s2;
    for(int i=0;i<s1.size();i++)
    {
        if(ch(i)) {
            cout<<"Yes\n";
            return 0;
        }
      ///  break;
    }
    cout<<"No\n";
    return 0;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int remain[100100][13];
string S;
const int mod = 1000000007;

signed main() {
    cin >> S;
    remain[0][0] = 1;
    rep(i, S.size()) {
        rep(j, 13) {
            if (S[i] != '?') {
                int k = S[i] - '0';
                remain[i + 1][(j * 10 + k) % 13] += remain[i][j];
            } else {
                rep(k, 10) {
                    remain[i + 1][(j * 10 + k) % 13] += remain[i][j];
                }
            }
        }
        rep(j, 13) {
            remain[i + 1][j] %= mod;
        }
    }
    (remain[S.size()][5] += mod) %= mod;
    cout << remain[S.size()][5] << endl;
    return 0;
}


Measured memory_bytes: 10624
#include"bits/stdc++.h"
using namespace std;

void Main() {
	int N, K, d, tmp;
	int A[100] = {};
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> d;
		for (int j = 0; j < d; j++) {
			cin >> tmp;
			A[tmp - 1] = 1;
		}
	}
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

Measured memory_bytes: 3636
n,m,x,y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

if min(Y) <= max(X):
  print("War")
  exit()
else:
  for i in range(max(X)+1, min(Y)+1):
    if x < i <= y:
      print("No War")
      exit()
      
print("War")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  for(int i =0;i < M;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<M;i++){
    N-=A.at(i);
  }
  if(N<0){
    cout << -1 <<endl;
  }
  else{
  cout << N <<endl;
  }
}


Measured memory_bytes: 3640
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(0,n):
  if a[i] > b[i]:
    c = c + b[i]
  elif a[i] <= b[i]:
    c = c + a[i]
    b[i] = b[i] - a[i]
    if b[i] < a[i+1]:
      c = c + b[i]
      a[i+1] = a[i+1] - b[i]
    else:
      c = c + a[i+1]
      a[i+1] = 0
print(c)


Measured memory_bytes: 18624
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int r;
	cin >> r;
	cout << r * r << endl;
}

Measured memory_bytes: 3520
// Problem : D - Anything Goes to Zero
// Contest : AtCoder - エイシング プログラミング コンテスト 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, m;
char s[N];
int cnt;
LL m1, m2, m3;
LL p1[N], p2[N], p3[N];

inline int get2(LL x)
{
	LL j = x;
	int cnt = 0;
	while (j)
	{
		if (j & 1) ++cnt;
		j >>= 1;
	}
	return cnt;
}

inline int getans(LL x)
{
	int ans = 0;
	while (x)
	{
		++ans;
		x %= get2(x);
	}
	return ans;
}

int main()
{
    //File("");
    n = gi();
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i+=1) cnt += (s[i] - '0');
    p1[n] = p3[n] = 1;
    for (int i = n - 1; i >= 1; i-=1) 
    {
    	if (cnt > 1) p1[i] = p1[i + 1] * 2 % (cnt - 1);
    	p3[i] = p3[i + 1] * 2 % (cnt + 1);
    }
    if (cnt > 1) p1[n] = 1 % (cnt - 1);
    p3[n] = 1 % (cnt + 1);
    for (int i = 1; i <= n; i+=1)
    	if (s[i] == '1')
    	{
    		if (cnt > 1) m1 = (m1 + p1[i]) % (cnt - 1);
    		m3 = (m3 + p3[i]) % (cnt + 1);
    	}
    for (int i = 1; i <= n; i+=1)
    {
    	if (s[i] == '1')
    	{
    		if (cnt > 1) 
    		{
    			int xx = (m1 - p1[i] + cnt - 1) % (cnt - 1);
    			printf("%d\n", getans(xx) + 1);
    		}
    		else puts("0");
    	}
    	else 
    	{
    		//cout << (x + (1 << (n - i))) << ' ' << cnt + 1 << endl;
    		//cout << m3 << ' ' << p3[i] << '?' << endl;
    		int xx = (m3 + p3[i] + cnt + 1) % (cnt + 1);
    		//cout << ' ' << m3 << endl;
    		//cout << m3 << endl;
    		printf("%d\n", getans(xx) + 1);
    	}
    }
    return 0;
}

Measured memory_bytes: 7036
n,A,B,C=map(int,input().split())
t=[int(input()) for i in range(n)]
s=A+B+C
def dfs(cur,a,b,c):
    if cur == n:
        #print(abs(a-A)+abs(b-B)+abs(c-C))
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else s
    ret0 =dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+t[cur],b,c)+10
    ret2=dfs(cur+1,a,b+t[cur],c)+10
    ret3=dfs(cur+1,a,b,c+t[cur])+10
    #print(min(ret0,ret1,ret2,ret3))
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int dfs(int n, int sum, int x){
    int cnt = 0;
    if(n == 0 && sum == 0)  return 1;
    if(n > 0){
        for(int i = x;i <= 9; i++){
            if(sum-i >= 0)    cnt += dfs(n-1, sum-i, i+1);
        }
    }
    return cnt;
}

int main(void){
    int n, sum;
    while(1){
        cin >> n >> sum;
        if(n == 0 && sum == 0)    break;
        cout << dfs(n, sum, 0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define pb push_back
#define ef(i,u) for(int i=b[u];i;i=nxt[i])
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,a[N];
int main(){
    cin>>n;
    int x;
    rep(i,2,n){
        read(x);
        a[x]++;
    }
    rep(i,1,n)cout<<a[i]<<'\n';
	return 0;
}


Measured memory_bytes: 4404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputArray = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                inputArray.Add(int.Parse(Console.ReadLine()));
            }
            inputArray.Sort();
            inputArray.Reverse();
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine(inputArray[i]);
            }
        }
    }
}

Measured memory_bytes: 5780
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a, b, c;
  //string c;
  cin >> a >> b >> c;

  int ans = 0;
  //string ans = "Yes";
  ans = max(c - (a - b), 0);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i,j;
	int height[10];
	int temp;
	for(i=0;i<10;i++)scanf("%d",&height[i]);
	for(i=9;i>=0;i--) {
		for(j=0;j<i;j++) {
			if(height[j]<height[j+1]) {
				temp=height[j];
				height[j]=height[j+1];
				height[j+1]=temp;
			}
		}
	}
	for(i=0;i<3;i++)printf("%d\n",height[i]);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a,b;
    cin>>a>>b;
    int q,r;
    double f;
    q=a/b;
    r=a-q*b;
    f=a/b;
    cout<<q<<" "<<r<<" "<<fixed <<setprecision(15)<<f<<endl;
}


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

using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

//typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
//typedef vector<ll> vl;
//typedef vector<vl> vll;
typedef pair<int,int> pii;
//typedef pair<ll,ll> pll;




int main(){
	double x1,x2,xq,xr,y1,y2,yq,yr;
	char ch;
	while(cin>>x1>>ch>>y1>>ch>>x2>>ch>>y2>>ch>>xq>>ch>>yq){
		x2-=x1;
		y2-=y1;
		xq-=x1;
		yq-=y1;
		double a=x2,b=y2,c=xq,d=yq;
		xq=(a*c+b*d)/(a*a+b*b);
		yq=(a*d-b*c)/(a*a+b*b);
		xr=xq;
		yr=yq*(-1.0);
		c=xr;
		d=yr;
		xr=a*c-b*d;
		yr=a*d+b*c;
		xr+=x1;
		yr+=y1;
		printf("%.15lf %.15lf\n",xr,yr);
	}
}

Measured memory_bytes: 1240
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
	void scan(int edcount, bool oindexed, bool w) {
		REP(i, edcount) {
			int a, b, c = 1;
			scanf("%d %d", &a, &b);
			if (w)scanf("%d", &c);
			con(a - oindexed, b - oindexed, c);
		}
	}
};
class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};
int factorial(int n) {//階乗
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}

int main() {

	int n;
	cin >> n;
	vector<int> r[2];
	REP(i, n) {
		int a;
		scanf("%d", &a);
		r[i % 2].push_back(a);
	}
	bool f = n % 2;

	REP(i, r[1-f].size())
		printf("%d ", r[1-f][r[1-f].size() - i - 1]);
	REP(i, r[f].size())
		printf("%d ", r[f][i]);
	return 0;
}

Measured memory_bytes: 3188
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();

  string s;
  cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC") << "\n";

  return 0;
}


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

public class Main {
	/* Comparable<P> で比較可能なオブジェクトにする */
	static class P implements Comparable<P>{
		int x, y;
		P(int x, int y) {
			this.x = x; this.y = y;
		}
		@Override /* Comparable<P> の実装 */
		public int compareTo(P o2) {
			int f = Integer.compare(this.x, o2.x);
			if(f == 0) {
				return Integer.compare(this.y, o2.y);
			}
			return f;
		}
		/* toString() を作ると、println()で文字列化される */
		public String toString() {
			return this.x + " " + this.y;
		}
	}
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			P[] a = new P[n];
			for(int i = 0; i < n; i++) {
				a[i] = new P(sc.nextInt(), sc.nextInt());
			}
			Arrays.sort(a);
			for(int i = 0; i < n; i++) {
				System.out.println(a[i]);
			}
		}
	}
}



Measured memory_bytes: 111412
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,l[55],ans=0;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l,l+n);
	for(int i=n-1; i>n-1-k; i--){
		ans += l[i];
	}
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;

ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  ll check[n]={0};
  if(n%2==0){
    for(ll i=1;i<n;i+=2) check[i]=2;
  }
  else{
    check[0]=1;
    for(ll i=2;i<n;i+=2) check[i]=2;
  }
  for(ll i=0;i<n;i++){
    check[a[i]]--;
  }
  bool res=true;
  for(ll i=0;i<n;i++) if(check[i]) res=false;
  if(!res) cout << 0 << endl;
  else{
    ll ans=1;
    for(ll i=0;i<n/2;i++){
      ans=(ans*2)%mod;
    }
    cout << ans << endl;
  }
}


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






int X;
vector<string> month = { "thu", "fri", "sat", "sun", "mon", "tue","wed" };
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> X;
    cout << month[X % 7] << endl;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;

void solve()
{
  int k,n,x;
  cin>>k>>n;
  vector<int> V;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    V.pb(x);
  }
  vector<int> diff;
  for(int i=1;i<n;i++)
  diff.pb(V[i]-V[i-1]);
  diff.pb(k+V[0]-V[n-1]);
  sort(diff.begin(),diff.end());
  cout<<k-diff[diff.size()-1];
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 2548
n = int(input())
a = list(map(int,input().split()))
a.append(0)
res = 0
p = 0
for i in range(n+1):
    res += abs(p-a[i])
    p = a[i]

for i in range(n):
    ass = res - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
    print(ass)


Measured memory_bytes: 14044
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	string a,b;
	int n;
	cin>>n;
	cin>>a>>b;
	int c=0,d=0;
	for(int i=1;i<=2*n;i++){
		if(i%2!=0){
			cout<<a[c++];
		}else{
			cout<<b[d++];
		}
	}
	return 0;
	
}

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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

ll getNum(ll n){
    return n/1000;
}

ll getWeight(ll n, ll w1){
    return getNum(n)*w1 + n%1000;
}

ll encode(ll num, ll w, ll w1){
    return num*1000 + (w - w1*num);
}


void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v){
    // value[i][j]は(i-1)番のアイテムまで使って重さjが実現できるかどうか(-1) & そのときの最大価値
    vector<vector<ll>> value(N+1, vector<ll>(300000 + 1, -1));
    value[0][0] = 0;
    ll w1 = w.at(0);
    
    for(int i=1; i < value.size(); i++){
        for(int j=0; j < value.at(0).size(); j++){
            // vs[i-1], ws[i-1]と、インデックス1つずれにきをつける！
            int taking = -1;
            // とる
            ll num = getNum(j);
            if(getWeight(j, w1) > W){
                continue;
            }
            ll subWeight = getWeight(j, w1) - w[i-1];
            if(subWeight >= 0 && encode(num-1, subWeight, w1) >= 0 && num-1 >= 0 && value[i-1][encode(num-1, subWeight, w1)] >= 0){
                taking = value[i-1][encode(num-1, subWeight, w1)] + v[i-1];
            }
            int notaking = -1;
            // とらない
            if(value[i-1][j] >= 0){
                notaking = value[i-1][j];
            }
            value[i][j] = max(taking, notaking);
        }
    }
    
    auto res = *max_element(value[N].begin(), value[N].end());

    cout << res << endl;
}

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


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

int n,m,x;
int s[1000000];
int a[1000000];
int size=0;
char str[100];
set<int> t;
map<int,int> u;

bool check(int r,int x){
  int cnt=n;
  int* d=a;
  set<int> :: iterator it;
  for(it=t.begin();it!=t.end();it++){
    int k=*it;
    int* target=lower_bound(d,a+n,k-r);
    d = upper_bound(d,a+n,k);
    cnt-=(d - target);
  }
  if(cnt<=x)return true;
  else return false;
}

int solve(int x){
  int L=0,R=1e9,M;
  if(!check(R,x))return -1;
  while(L<R){
    M=(L+R)/2;
    if(check(M,x))R=M;
    else L=M+1;
  }
  return L;
}

int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%d",&s[i]);
    a[i]=s[i];
  }
  sort(a,a+n);
  
  for(int i=0;i<m;i++){
    scanf("%s %d",str,&x);    
    if(str[0]=='A'){
      if(u[s[x-1]]==0)t.insert(s[x-1]);
      u[s[x-1]]++;
    }else if(str[0]=='R'){
      u[s[x-1]]--;
      if(u[s[x-1]]==0)t.erase(s[x-1]);
    }else if(str[0]=='C'){
      int ans=solve(x);
      if(ans==-1)printf("NA\n");
      else printf("%d\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 9052
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>


using namespace std;
#define ll long long


int main(void){
    int N;
    cin>>N;
    vector<int> P(N);
    vector<string> S(N);
    vector<pair<string,int>> SP(N);
    for(int i=0;i<N;i++) {
        cin>>S.at(i)>>P.at(i);
        SP.at(i)=make_pair(S.at(i),100-P.at(i));
    }
    sort(SP.begin(),SP.end());
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(SP.at(i).first==S.at(j) && SP.at(i).second+P.at(j)==100) cout<<j+1<<endl;
        }
    }
    return 0;
}


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

fn main() {
    input! {
        a: i64, b: i64, c: i64
    }
    println!("{}", if b-a==c-b {"YES"} else {"NO"});
}

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

int a[100100], b[100100], c[100100];
int memo[100100][3];
int n;

int go(int i, int last) {
	if (i > n-1) return memo[i][last] = 0;
	if (memo[i][last] != -1) return memo[i][last];

	if (last == 0) return memo[i][last] = max(go(i+1, 1) + b[i], go(i+1, 2) + c[i]);
	if (last == 1) return memo[i][last] = max(go(i+1, 0) + a[i], go(i+1, 2) + c[i]);
	if (last == 2) return memo[i][last] = max(go(i+1, 0) + a[i], go(i+1, 1) + b[i]);
}

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

	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

	int ans = 0;
	for(int i = 0; i <= 2; i++) {memset(memo, -1, sizeof(memo)); ans = max(ans, go(0, i));}
	cout << ans << endl;
}

Measured memory_bytes: 7296
#include<stdio.h>
int main() {
  double a, b, c, d, e, f, x, y;
  while (scanf("%lg %lg %lg %lg %lg %lg", &a, &b, &c, &d, &e, &f) != EOF) {
    x = (c * e - b * f) / (a * e - b * d); y = (c * d - a * f) / (b * d - a * e);
    if (-0.0005 < x && x < 0.0005) x = 0; if (-0.0005 < y && y < 0.0005) y = 0;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 652
#include<stdio.h>
int main()
{
	int i, N, a[100001], b[100001], c;
	c=0;
	for (i=1;i<=100000;i++) b[i]=0;
	scanf("%d",&N);
	for (i=1;i<=N;i++){scanf("%d",&a[i]); 
		if (a[i]>100000) c=c+1;
		else b[a[i]]=b[a[i]]+1;}
	for (i=1;i<=100000;i++){ 
		if (i>b[i]) c=c+b[i];
		else c=c+b[i]-i;
	}
	printf("%d",c);
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 9223372036854775807;

int main(){

    ll N, K;
    cin >> N >> K;

    cout << N - K + 1 << endl;

}

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

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

	int N;
	scanf("%d", &N);

	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &h[i]);
	}

	vector<int> c(N);

	c[0] = 0;
	c[1] = c[0] + abs(h[0] - h[1]);

	for (int i = 2; i < N; i++) {
		c[i] = min(c[i - 2] + abs(h[i] - h[i - 2]),
		           c[i - 1] + abs(h[i] - h[i - 1]));
	}

	printf("%d", c[N - 1]);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e6+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

int n;
ll k;
ll whole[51],p[N];

ll solve(int indx,ll rem){

	if(indx==0){
		return rem>=1;
	}
	if(whole[indx]<=rem){
		return p[indx];
	}
	else{
		if((whole[indx-1]+2)<=rem){
			return p[indx-1]+1+solve(indx-1,rem-whole[indx-1]-2);
		}
		else{
			return solve(indx-1,rem-1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

     cin>>n>>k;
     whole[0]=p[0]=1;
     for(int i=1;i<=n;i++){
     		whole[i]=whole[i-1]*2+3;
     		p[i]=p[i-1]*2+1;
     }

     cout<<solve(n,k)<<"\n";
     	
 }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = -1;
	int x = INF;
	for (int i = 0; i < n; i++) {
		if (x > a[i]) {
			x = a[i];
			ans = i;
		}
	}
	cout << ans + 1 << endl;
}


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





int main(){
    int n;
    cin >> n;
    //inputを可変長配列に入れ込む
    vector <int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    //1からnまでの可変長配列を作成
    vector<int> a(n);
    rep(i,n) a[i] =i +1;
    //順列（key）とその順番（value）を保持するマップを作成
    map<vector<int>, int> mp;
    //next_permutationはdo-whileで書くみたい。なぜかは不明
    do{
        //mp[a]に代入することは、aという順列(key)の順番(value)を代入するということ
        //mp.size()は値が入るごとに1ずつ増えるので、順番になる
        mp[a] = mp.size();
        //next_permutationは開始から終了までの順列を辞書順に生成する（=aに生成した順列を代入して、全列挙したらfalseを返す）
        //algorithmヘッダをインクルードする必要がある
        //引数には昇順の順列が必要（今回はa）配列の始点と終点を指定する
    } while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>

using namespace std;

int main() {
	int h, w, n;
	
	while(cin >> h >> w >> n) {
		
		int a[n + 1];
		
		for(int i = 1; i <= n; i++) cin >> a[i];
		
		int map[h][w];
		int cur = 1;
		
		for(int i = 0; i < h; i++) {
						
			if(i % 2 == 0) {
				for(int j = 0; j < w; j++) {
					while(a[cur] == 0) cur++;
					map[i][j] = cur;
					a[cur]--;
				}
			}
			else {
				for(int j = w - 1; j >= 0; j--) {
					while(a[cur] == 0) cur++;
					map[i][j] = cur;
					a[cur]--;
				}
			}
		}
		
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w - 1; j++) cout << map[i][j] << " ";
			cout << map[i][w - 1] << endl;
		}		
	}

	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <unordered_map>
#include <array>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <random>
#include <numeric>

#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;


const int MAX_N = 100000;
ll N;
ll A[MAX_N+1];
ll S[MAX_N+1];

int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];

  ll Asum = 0, sum = 0;
  for (int i =  1; i <= N; ++i) Asum += A[i];
  if ((2*Asum)%(N*(N+1)) != 0) {
    cout << "NO" << endl;
    return 0;
  } else {
    sum = (2*Asum)/(N*(N+1));
  }

  for (int i = 1; i < N; ++i) {
    if (sum-A[i+1]+A[i] < 0 || (sum-A[i+1]+A[i])%N != 0) {
      cout << "NO" << endl;
      return 0;
    } else {
      S[i] = (sum-A[i+1]+A[i])/N;
    }
  }

  if (sum-A[1]+A[N] < 0 || (sum-A[1]+A[N])%N != 0) {
    cout << "NO" << endl;
    return 0;
  } else {
    S[N] = (sum-A[1]+A[N])/N;
  }

  ll accum_S = 0;
  for (int i = 1; i <= N; ++i) accum_S += S[i];

  if (accum_S == sum) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define f first
#define s second



using namespace std;

int main()
{
  flash
  ll s,w;
  cin>>s>>w;

  if(w>=s)
    cout<<"unsafe\n";
  else
    cout<<"safe\n";



}


Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, W, w;

  long long v, vp = 0;

  std::cin >> N >> W;

  std::set<std::pair<int, long long>> set;

  set.insert(std::make_pair(0, 0LL));

  for (int i = 0; i < N; i ++) {
    std::cin >> w >> v;

    std::set<std::pair<int, long long>> s(set);

    for (const auto& pair : set) {
      int       ww = pair.first  + w;
      long long vv = pair.second + v;

      if (ww > W)
        break;

      auto it = s.lower_bound(std::make_pair(ww, 0));

      if (it == std::end(s)) {
        s.insert(std::make_pair(ww, vv));
      }
      else if (it->first == ww) {
        if (vv > it->second) {
          s.erase(it);
          
          s.insert(std::make_pair(ww, vv));
        }
      }
      else {
        s.insert(std::make_pair(ww, vv));
      }
    }

    set = std::move(s);
  }

  for (const auto& pair : set)
    if ((v = pair.second) > vp)
      vp = v;

  std::cout << vp << std::endl;

  return 0;
}


Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p pair<int,int>
template<class T> void chmax(T& a, T b){if(a < b) a = b;}
template<class T> void chmin(T& a, T b){if(a > b) a = b;}
int N, L;
int main(){
    cin >> N >> L;

    int m = 1 << 30;
    int sum = 0;
    for(int i = 1; i <= N; i++){
        sum += L + i - 1;
        if(abs(m) > abs(L + i - 1)) m = L + i - 1;
    }
    cout << sum - m << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef unsigned int uint;
typedef vector<int> V;
typedef vector<vector<int> > VV;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

const int INF = 1 << 28;
const double EPS = 1e-9;

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

    vector<int>dis(n),cost(n);
    for(int i = 0; i < n; i++) {
        cin >> dis[i] >> cost[i];
    }

    PQ que;
    que.push(P(0,0));
    V dx(100000 * 2, INF);
    dx[0] = 0;
    while (que.size()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (dx[v] < p.first) continue;
        if (v == x) break;

        for (int i = 0; i < n; i++) {
            int to1 = abs(v + dis[i]);
            int to2 = abs(v - dis[i]);
            int cost_ = p.first + cost[i];
            if (to1 < 100000 * 2 && dx[to1] > cost_) {
                dx[to1] = cost_;
                que.push(P(cost_, to1));
            }
            if (to2 < 100000 * 2 && dx[to2] > cost_) {
                dx[to2] = cost_;
                que.push(P(cost_, to2));
            }
        }
    }

    cout << (dx[x] == INF ? -1 : dx[x]) << endl;

    return 0;
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
    ll n,k,ans=INF;
    cin >> n >> k;
    ll a2[n];
    for (ll i=0;i<n;i++){
        cin >> a2[i];
    }
    for (ll bit=0;bit<=(1<<(n));bit++){
        ll a[n];
        for (ll i=0;i<n;i++)a[i]=a2[i];
        ll mini=a[0],count=0,kc=1;
        for (ll i=1;i<n;i++){
            if ((1<<i)&bit){
                if (a[i]<=mini){
                    count+=(mini-a[i])+1;
                    a[i]=mini+1;
                }
                kc++;
            }else if (a[i]>mini)kc++;
            mini=max(a[i],mini);
        }
        if (kc>=k)ans=min(ans,count);
    }
    cout << ans << endl;
    return 0;
}    


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define INF 9223372036854775807
const ll mod=1e9+7;

bool comp(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first==b.first)
        return a.second<b.second;
    return a.first>b.first;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    ll s,w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";

    return 0;
}
/*
98 24
91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22 32 34 91 37 30 26 92 77 69 11 59 78 24 66 88 15 32 49 46 14 57 20 5 69 53 99 81 70 67 22 54 31 49 52 46 51 46 2 53 59 8 66 28 53 54 5 85 75 15 55 87 16 68 6 36 98
*/

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

int main (){
    int n,a=1000,d=0;
    cin>>n;
    int i;
    int b=n,c=0;
    while(b!=0){
        b/=10;
        c++;
    }

    for(i=0;i<c;i+=2){
        if(n/(int)pow(10,(double)i+1)>=1){
            if(i==0)d+=9;
            else{
            d+=pow(10,(double)i+1)-pow(10,(double)i);
            }
        }
        else if(n/pow(10,(double)i)>=1){
            d+=n-pow(10,(double)i)+1;
        }
    }
    cout << d;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k
l1 ... ln
 */
int n,k,l[50];

int main(){
  cin>>n>>k;
  REP(i,n){
    cin>>l[i];
  }

  sort(l,l+n,greater<int>());

  int ans=0;
  REP(i,k){
    ans += l[i];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back 
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,a,b) for(int i=a;i<b;i++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define printmp(b) for(auto y:b) {printP(y);}

#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;
typedef long long int ll;
typedef unsigned long long int ull;

/* 

*/
ll apowb(ll a,ll b)
{
  if(b==0)
  return 1;
  if(b==1)
  return a;
  if(b%2==0)
  {
    return apowb(a*a,b/2);

  }else
  {
    return apowb(a*a,b/2)*a;

  }
  
}

void solve()

{
  
  int r,c,n,x,y;
  cin>>r>>c>>n;

  //vector<vector<int>> arr(r,vector<int>(c));
  int rw[r],cl[c];
  FOR(i,r)
  rw[i]=0;

  FOR(i,c)
  cl[i]=0;
 
 
   // unordered_map<int,int>  row,col;
  map<vector<int>,int> mat;

  FOR(i,n)
  {
    cin>>x>>y;
mat[{x-1,y-1}]=1;
  //  arr[x-1][y-1]=1;
   
    cl[y-1]++;
    rw[x-1]++;
  } 

 
int mx=0;


int mxr=0,mxc=0;

for(int x:rw)
{
mxr=max(x,mxr);
}

for(int x : cl)
{
mxc=max(x,mxc);
}

vector<int> nr,nc;


FOR(i,r)
{
  if(rw[i]==mxr)
  {
    nr.pb(i);
  }
}


FOR(i,c)
{
  if(cl[i]==mxc)
  {
    nc.pb(i);
  }
}

mx=0;
for(int i:nr)
{
  for(int j:nc)
  {
    if(mat[{i,j}]==0)
    {
      cout<<mxr+mxc;
      return;
    }
  }
}

      cout<<mxr+mxc-1;
      
//  FOR(i,r)
//  {
//    if(row[i]>0)
//    FOR(j,c)
//    {
     
//      mx=max(mx,row[i]-mat[{i,j}]+col[j]);
//      if(mx==n)
//      {
//        cout<<mx;
//        return;
//      }

//    }

//  }
 

  
//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;  
   
}


int main()
{
  /*
6
4 0
4 41
0 1000000
44 0
1 0
10000 1000000


  */
  fast;
  int t=1;
 //cin>>t;
  while(t--){
  
  solve();
 cout<<endl;
   
}
  
  
      
      return 0;
    }

Measured memory_bytes: 42504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct Union_Find_Tree{
    vector<int> par, rank, num;
    
    Union_Find_Tree(int N){
        par.assign(N, -1);
        rank.assign(N, 0);
        num.assign(N, 1);
    }
    
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x, num[x] += num[y];
        return true;
    }
    
    int size(int x) {return num[root(x)];}
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void clear(){
        fill(all(par), -1);
        fill(all(rank), 0);
        fill(all(num), 1);
    }
};

struct edge{int u, v, cost;};

int main(){
    int N;
    cin >> N;
    int x[N], y[N];
    rep(i, N) cin >> x[i] >> y[i];

    vector<int> xs(N), ys(N);
    iota(all(xs), 0), iota(all(ys), 0);
    sort(all(xs), [&](int a, int b){return x[a] < x[b];});
    sort(all(ys), [&](int a, int b){return y[a] < y[b];});

    vector<edge> es;
    rep(i, N-1) es.eb((edge){xs[i], xs[i+1], x[xs[i+1]]-x[xs[i]]});
    rep(i, N-1) es.eb((edge){ys[i], ys[i+1], y[ys[i+1]]-y[ys[i]]});
    sort(all(es), [](const edge &a, const edge &b){
        return a.cost < b.cost;
    });

    Union_Find_Tree uf(N);
    int ans = 0;
    for(auto &e: es){
        if(uf.unite(e.u, e.v)) ans += e.cost;
    }
    cout << ans << endl;
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  int N, M;
  cin >> N >> M;

  vector<pi> V;

  rep(i, N){
    int a, b;
    cin >> a >> b;
    V.emplace_back(make_pair(a,b));
  }

  sort(ALL(V), [](pi a, pi b){return a.first < b.first;});

  int ans = 0;
  auto cp = [](pi l, pi r) {return l.second < r.second;};
  priority_queue<pi, vector<pi>, decltype(cp)> q(cp);
  auto pre = V.begin();
  REP(i, 1, M+1){
    while(pre != V.end() && (*pre).first <= i){
      q.emplace(*pre);
      pre++;
    }
    if(!q.empty()){
      auto e = q.top(); q.pop();
      //cout << e.first << ", " << e.second << endl;
      ans += e.second;
    }

  }

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

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

const int Maxn = 100005;
int n, q, ct;
long long A[Maxn], cnt[Maxn], f[Maxn];
void work(long long len, long long w)
{
	int pos = upper_bound(A + 1, A + 1 + ct, len) - A - 1;
	if (!pos) cnt[1] += w, cnt[len + 1] -= w;
	else f[pos] += len / A[pos] * w, work(len % A[pos], w);
}
int main()
{
	scanf("%d%d", &n, &q);
	A[++ct] = n;
	while (q--)
	{
		long long x;
		scanf("%lld", &x);
		while (ct && x <= A[ct]) ct--;
		A[++ct] = x;
	}
	f[ct] = 1;
	for (int i = ct - 1; i >= 1; i--)
		f[i] += A[i + 1] / A[i] * f[i + 1], work(A[i + 1] % A[i], f[i + 1]);
	cnt[1] += f[1], cnt[A[1] + 1] -= f[1];
	for (int i = 1; i <= n; i++)
		printf("%lld\n", cnt[i]), cnt[i + 1] += cnt[i];
	return 0;
}

Measured memory_bytes: 6152