akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
	int N;
	cin >> N;
	int H[100010];
	int tmp;
	
	for(int i=1; i<=N; i++){
		cin >> H[i];
	}
	
	if(N==1){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i=N;i>0;i--){
		tmp=H[i-1]-H[i];
		if(tmp==1){
			H[i-1]=H[i];
		} else if(tmp>1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 640
n = gets.strip.to_i
s = gets.strip.split("")
s.push("@")

st = s[0]
merge = []
s.each do |c|
  # puts "#{st} : #{c}"
  if st != c
    # puts "pushd #{st}"
    merge.push(st)
    st = c
  end
end
puts merge.length

# 一番後ろに終了の目印の@を追加している

Measured memory_bytes: 7804
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;
    cin >> N ;
    cin >> S ;

    vector<int> Rs,Gs,Bs;
    for (int i=0;i<S.length();i++){
        if (S[i]=='R'){
            Rs.push_back(i);
        } else if (S[i]=='G'){
            Gs.push_back(i);
        } else{
            Bs.push_back(i);
        }
    }

    long long total=Rs.size()*Gs.size()*Bs.size();
    long long cnt=0;

    for (int i=0;i<N;i++){
        for (int j=i+1;j<N;j++){
            int k = j + (j-i);
            if (k < N){
                if (S[i]!=S[j] && S[j]!=S[k] && S[i]!=S[k] ){
                    cnt++;
                }
            }
        }
    }
    cout << total-cnt << endl;
}

Measured memory_bytes: 3636
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,k;
    scanf("%d%d",&n,&k);
    if (k==0)
    {
        cout<<(long long)n*n<<endl;
        return 0;
    }
    int i;
    long long ans=0;
    for (i=1;i<=n;i++)
    {
        //b = i
        if (i<=k) continue;
        int t=n/i;
        ans+=(long long)(i-k)*t;
        ans+=max(n%i-k+1,0);
    }
    cout<<ans<<endl;
    return 0;
} 


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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < N; ++i)
    ans = (ans + v[i]) / 2.0;
  cout << fixed << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll a, b, m;
    cin >> a >> b >> m;

    vector<ll> p1(a), p2(b);
    ll ans = 1LL<<60;
    ll min_a = 1LL<<60;
    ll min_b = 1LL<<60;
    for(int i = 0; i < a; i++){
        cin >> p1[i];
        min_a = min(min_a, p1[i]);
    }
    for(int i = 0; i < b; i++){
        cin >> p2[i];
        min_b = min(min_b, p2[i]);
    }
    ans = min_a + min_b;
    for(int i = 0; i < m; i++){
        ll x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        ans = min(ans, p1[x] + p2[y] - c);
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
	int n;
	int i;
	int weight[]={1,2,4,8,16,32,64,128,256,512};
	bool isFirsttime;

	while(scanf("%d", &n)!=EOF){
		isFirsttime=true;
		for(i=0; i<10; i++){
			if(n%2==1){
				if(isFirsttime){ printf("%d", weight[i]); isFirsttime=false; }
				else printf(" %d", weight[i]);
			}
			n = n>>1;
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1032
#include<iostream>
#include<algorithm>
using namespace std;
const int BUF = 100005;


int N;
string s[BUF];

void read() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> s[i];
    }
}


void work() {
    int cnt[4] = {};
    static string result[4] = {"AC", "WA", "TLE", "RE"};

    for (int i = 0; i < N; ++i) {
        ++cnt[find(result, result + 4, s[i].c_str()) - result];
    }

    for (int i = 0; i < 4; ++i) {
        cout << result[i] << " x " << cnt[i] << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}


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

int main() {
    int r, s, p;
    cin >> r >> s >> p;
    vector<int> d(p);
    for(int i=0;i<p;i++){
        int a, b;
        cin >> a >> b;
        d[i] = r-a+1 + (b<=s ? s+1-b : b-s);
    }
    sort(d.begin(), d.end());
    int ans = 0;
    for(int i=0;i<p;i++){
        ans = max(d[i], ans+1);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4592
func readInt() -> Int {
    Int(readLine()!)!
}
 
func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}
 
prefix operator *
prefix func * <T> (a: [T]) -> (T, T) {return (a[0], a[1])}
prefix func * <T> (a: [T]) -> (T, T, T) {return (a[0], a[1], a[2])}

func main() {
    let k = readInt()

    var s: Set<Int> = []

    var v = 7 % k
    for i in 1... {
        guard !s.contains(v) else { break }

        s.insert(v)

        if v == 0 {
            print(i)
            return
        }

        v = (v * 10 + 7) % k
    }

    print(-1)
}

main()

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

int main() {

	int a ,b;
  
  	cin >> a >> b;
  a = a*b;
  	if(a % 2 == 0){
      cout << "Even";
    }
      else{
        cout << "Odd";
      }
  
 
   
}


Measured memory_bytes: 256
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    target = {(x - s, y - t) for x, y in target}
    max_tx = max(map(lambda x:x[0], target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - s, y - t)
            break


Measured memory_bytes: 6096
#include <iostream>                                                             
#include <cstring>                                                              
                                                                                 
using namespace std;                                                            
                                                                                 
int main(void) {                                                                
  int n, m, a;                                                                  
  int G[1001][101];                                                             
                                                                                 
  while(true){                                                                  
    cin >> n >> m >> a;                                                         
    if (n+m+a==0) {                                                             
      break;                                                                    
    }                                                                           
    memset(G,0,sizeof(G));                                                      
                                                                                 
    for (int i=0; i<m; i++) {                                                   
      int h ,p ,q;                                                              
      cin >> h >> p >> q;                                                       
      G[h][p]=q;                                                                
      G[h][q]=p;                                                                
    }                                                                           
    for (int i=1000; i>=0; i--) {                                               
      if (G[i][a]!=0) {                                                         
        a=G[i][a];                                                              
      }                                                                         
    }                                                                           
    cout << a << endl;                                                          
  }                                                                             
                                                                                 
  return 0;                                                                     
}                      

Measured memory_bytes: 3472
#include<stdio.h>
#define HeapSize 500000

void MaxHeapify(int * ,int ,int );
void BuildMaxHeap(int *,int );
int left(int );
int right(int );

int left(int i){
  return 2*i;
}
int right(int i){
  return (2*i + 1);
}
void MaxHeapify(int *A,int i,int n){
  int l,r,largest,temp;
 l = left(i);
 r = right(i);
 if(l <= n && A[l] > A[i]){
   largest = l;
 }
 else largest = i;
 if(r <=  n && A[r] > A[largest]){
   largest = r;
 }
 if(largest != i){
   temp = A[i];
   A[i] = A[largest];
   A[largest] = temp;
   MaxHeapify(A,largest,n);
 }
}
void BuildMaxHeap(int *A,int n){
  int i;
  for(i = n/2; i >= 1;i--){
    MaxHeapify(A,i,n);
  }
} 
 int main( ){
  int i,n;
  int A[HeapSize];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
    BuildMaxHeap(A,n);
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
 }
 



Measured memory_bytes: 3684
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if i*500 + j*100 + k*50 == x:
                count += 1

print(count)

Measured memory_bytes: 3064
import sys
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
b = sorted(b, reverse=True)
# b.reverse()
# list2 = sorted(list1, reverse=True)


def canSelect(a, total, M):
    return a >= total / (4 * M)


def returnWord(flag):
    if flag:
        return 'Yes'
    return 'No'


total = sum(b)
M = a[1]
count = 0
res = 'Yes'
for i in b:
    count += 1
    if not canSelect(i, total, M):
        res = returnWord(False)
    if count == M:
        print(res)
        sys.exit()

# print(-(-a[0] // a[1]))


Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

r = INT()

print(3*(r**2))

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

int func(int n, int a){
    int res = 0;
    while(n>0){
        res += n % a;
        n /= a;
    }
    return res;
}
int main() {
    int N; cin >> N;
    int res = N;
    for (int i=0;i<=N;++i){
        int tmp = func(i,6) + func(N-i, 9);
        res = min(res, tmp);
    }   
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
d = {}
bc = []
sumval = 0
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
  bc.append(tuple(map(int, input().split())))
for i in range(1, 10**5+1):
  d[i] = 0
for e in a:
  sumval += e
  d[e] += 1
for b, c in bc:
  sumval += (c-b) * d[b]
  d[c] += d[b]
  d[b] = 0
  print(sumval)


Measured memory_bytes: 37764
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll S, W;
    cin >> S >> W;
    if (W - S >= 0)
        cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

char mat[20][20];
int h, w;
vector<pair<int,int>> g;

vector<vector<int>> bfs(int si, int sj){
    vector<vector<int>> visit(h, vector<int>(w, 1<<30));
    queue<pair<int, pair<int,int>>> q;
    q.push({0, {si, sj}});
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int c = p.first, i = p.second.first, j = p.second.second;
        if(visit[i][j] <= c)    continue;
        visit[i][j] = c;
        for(int k = 0; k < 4; k++){
            int ni = i+di[k], nj = j+dj[k];
            if(inRange(ni, 0, h) && inRange(nj, 0, w) && mat[ni][nj] != 'x' && c+1 < visit[ni][nj]){
                q.push({c+1, {ni, nj}});
            }
        }
    }
    return visit;
}

int main(){
    while(cin >> w >> h, w+h){
        int ri, rj;
        g.clear();
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mat[i][j];
                if(mat[i][j] == 'o')    ri = i, rj = j;
                if(mat[i][j] == '*')    g.push_back({i, j});
            }
        }
        int gcnt = g.size();
        vector<vector<int>> dp(gcnt, vector<int>(1<<gcnt, 1<<30));
        auto p = bfs(ri, rj);
        bool valid = true;
        for(int i = 0; i < gcnt; i++){
            if(p[g[i].first][g[i].second] == 1<<30){
                valid = false;
                break;
            }
            dp[i][1<<i] = p[g[i].first][g[i].second];
        }

        if(!valid){
            cout << -1 << endl;
            continue;
        }

        vector<vector<int>> dist(gcnt, vector<int>(gcnt, 1<<30));
        for(int i = 0; i < gcnt; i++){
            auto p = bfs(g[i].first, g[i].second);
            for(int j = 0; j < gcnt; j++){
                dist[i][j] = p[g[j].first][g[j].second];
            }
        }

        for(int s = 0; s < 1<<gcnt; s++){
            for(int i = 0; i < gcnt; i++){
                if(((s>>i)&1)==0 || dp[i][s] == 1<<30) continue;
                for(int j = 0; j < gcnt; j++){
                    if((s>>j)&1) continue;
                    dp[j][s|(1<<j)] = min(dp[j][s|(1<<j)], dp[i][s] + dist[i][j]);
                }
            }
        }

        int ans = 1<<30;
        for(int i = 0; i < gcnt; i++)   ans = min(ans, dp[i][(1<<gcnt)-1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>
int gcd(int n,int m)
{
int r,t;
if(n>m)
{
  t=m;
  m=n;
  n=t;
}
while((r=m%n)!=0)
{
  m=n;
  n=r;
}
return n;
}

void main(void)
{
	int a,b,c,d;
  	int k;
    int total=0;
    scanf("%d",&k);
    for(a=1;a<=k;a++)
      for(b=1;b<=k;b++)
        for(c=1;c<=k;c++)
        {
        d=gcd(gcd(a,b),c);
        total=total+d;
        }
    printf("%d",total);
}

Measured memory_bytes: 1720
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int n;

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

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

  double ans=0;
  ans+=v[0]/pow(2,n-1);
  rep(i,1,n) ans+=v[i]/pow(2,n-i);

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dfs(int now,int cnt);
int n;
map<int,int>mp;
int memo[109][10009];

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n;
  for(int i=1;i<=n;i++){
    int temp=i;
    for(int j=2;j*j<=temp;j++){
      while(temp%j==0){
	temp/=j;
	mp[j]++;
      }
    }
    if(temp!=1)mp[temp]++;
  }
  cout<<dfs(2,1)<<endl;
  return(0);
}

int dfs(int now,int cnt){
  int rec=0;
  if(memo[now][cnt]!=-1)return memo[now][cnt];
  if(now==n){
    if(cnt==75)return 1;
    else return 0;
  }
  if(cnt>75)return 0;
  for(int i=1;i<=mp[now]+1;i++){
    rec+=dfs(now+1,cnt*i);
  }
  return memo[now][cnt]=rec;
}


Measured memory_bytes: 4480
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string str;

int main() {
    int res = 0;
    while (cin >> str) {
        string str2 = str;
        reverse(ALL(str2));
        if (str == str2) ++res;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		int m = s.nextInt();
		for (int x = 0; x < m; x++) {
			int moneyb = s.nextInt();
			int year = s.nextInt();
			int n = s.nextInt();

			int[] moneya = new int[n];
			int max = 0;

			for (int y = 0; y < n; y++) {
				int rate = s.nextInt();
				double rate_per_year = s.nextDouble();
				int fee = s.nextInt();

				if (rate == 0) {
					moneya[y] = SimpleInterester(moneyb, year, rate_per_year,
							fee);
				} else {
					moneya[y] = CompoundInterester(moneyb, year, rate_per_year,
							fee);
				}
			}

			for (int k = 0; k < n; k++) {
				if (max < moneya[k])
					max = moneya[k];
			}
			System.out.println(max);
		}
	}

	public static int CompoundInterester(int moneyc, int y, double rpy, int fee) {
		for (int i = 0; i < y; i++) {
			int b = (int) (moneyc * rpy);
			moneyc = moneyc + b - fee;
		}
		return moneyc;
	}

	public static int SimpleInterester(int moneys, int y, double rpy, int fee) {
		int b = 0;
		for (int i = 0; i < y; i++) {
			b += (int) (moneys * rpy);
			moneys = moneys - fee;
		}
		moneys += b;
		return moneys;
	}

}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>d1(n,0);
    vector<int>d2(n,0);
    string str="No";
    int count=0;
    for(int i=0;i<n;i++){
        cin>>d1[i]>>d2[i];
        if(d1[i]==d2[i]){
            count++;
            if(count==3){
                str="Yes";
            }
        }
        else{
            count=0;
        }
    }
    cout<<str;
   return 0;
}

Measured memory_bytes: 3600
from itertools import permutations
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
cnt = 1
for num in permutations(range(1,n+1)):
    cnt += 1
    if list(num) == p:
        p_num = cnt
    if list(num) == q:
        q_num = cnt
print(abs(q_num-p_num))

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    string s, t;
    cin >> s >> t;
    all(s); all(t);
    int ans = 0;
    rep(i, s.size()) if(s[i] != t[i]) ans++;
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 3920
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        long res = 0;

        for (int i = 1; i < n; ++i) {
            res += n / i - (n % i == 0 ? 1 : 0);
        }

        bw.write(Long.toString(res));

        bw.close();
        br.close();
    }
}


Measured memory_bytes: 32708
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    if (a<=b && a<=c){
        if(b<=c){
            cout << a <<" "<< b<< " " << c << endl;
        }else{
            cout << a<<" " << c<<" " << b << endl;
        }
    }else if (b<=a && b<=c){
        if (a<=c){
            cout << b << " " << a<< " " << c << endl;
        }else{
            cout << b <<" "<< c <<" "<< a << endl;
        }
    }else{
        if (a<=b){
            cout << c <<" "<< a <<" "<< b << endl;
        }else{
            cout << c <<" "<< b <<" "<< a << endl;
        }
    }
    
    return 0;
    
    
}


Measured memory_bytes: 3116
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));

$max = $f = $x = 0;
for ($i = 0; $i < $n; $i++) {
	$p = abs($a[$i]);
	if ($p > $max) {
		$max = $p;
		$f = $a[$i] < 0 ? 1 : 0;
		$x = $i;
	}
}
$m = 0;
$ans = [];
if ($f) {
	for ($i = $n - 2; $i >= 0; $i--) {
		while ($a[$i] > $a[$i+1]) {
			$a[$i] += $a[$x];
			$m++;
			$ans[] = ($x + 1) . ' ' . ($i + 1);
			if ($a[$i] < $a[$x]) $x = $i;
		}
	}
} else {
	for ($i = 1; $i < $n; $i++) {
		while ($a[$i] < $a[$i-1]) {
			$a[$i] += $a[$x];
			$m++;
			$ans[] = ($x + 1) . ' ' . ($i + 1);
			if ($a[$i] > $a[$x]) $x = $i;
		}
	}
}

echo $m;
if ($ans) {
	echo "\n", implode("\n", $ans);
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	string s;
	cin>>s;
	cout<<(s=="ABC"?"ARC":"ABC"); 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






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

H = list(map(int, input().split())) + [0] * K

dp = [10**10] * (N+K)
dp[0] = 0

for i in range(N):
  for j in range(1, K+1):
    dp[i+j] = min(dp[i+j], dp[i] + abs(H[i]-H[i+j]))
 

print(dp[N-1])

Measured memory_bytes: 53216
#include <iostream>
using namespace std;
long long int max_p(int w[],int v[],int n,int W){
    long long int dp[2][W+1];
    int even=0,odd=1;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<W+1;j++){
            if(i==0 || j==0){
                dp[even][j]=0;
                dp[odd][j]=0;
            } 
            else if(j-w[i-1] >=0){
                if(i%2==0) dp[even][j]=max(dp[odd][j],dp[odd][j-w[i-1]]+v[i-1]);
                else dp[odd][j]=max(dp[even][j],dp[even][j-w[i-1]]+v[i-1]);
            }
            else{
                if(i%2==0) dp[even][j]=dp[odd][j];
                else dp[odd][j]=dp[even][j];
            }
        }
    }
    if(n%2==0) return dp[even][W];
    else return dp[odd][W];
    // long long int dp[n+1][W+1];
    // for(int i=0;i<n+1;i++){
    //     for(int j=0;j<W+1;j++){
    //         if(i==0 || j==0) dp[i][j]=0;
    //         else if(j-w[i-1] >=0){
    //             dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
    //         } 
    //         else {
    //             dp[i][j]=dp[i-1][j];
    //         }
    //     }
    // }
    // return dp[n][W];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin>>n>>w;
    int we[n],va[n];
    for(int i=0;i<n;i++) cin>>we[i]>>va[i];
    cout<<max_p(we,va,n,w);
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

long long MOD = 1000000007;
const long long MAX = 20001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
   int K;
   int N;
   cin >> N >> K;
    comb_init();
   for(int i = 1; i <= K; i++){
       //cout << i << " ";
       long long ans = comb(K - 1, i - 1);
       //cout << ans << endl;
       ans = (ans * comb(N - K - (i - 1) + i, i)) % MOD;
       cout << ans << endl;
   }
   return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = (int)1e9;

using ll = long long;

int main() {

    ll r, g, b;
    cin >> r >> g >> b;
    ll x = r * 100 + g * 10 + b;
    string ans = x % 4 == 0 ? "YES" : "NO";
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import heapq
def main():

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

    A1 = sorted(A[:N])
    A2 = A[N:2*N]
    A3 = sorted([-a for a in A[2*N:]])

    tot1 = sum(A1)
    max_tot1 = [tot1]
    for i in range(N):
        heapq.heappush(A1, A2[i])
        v = heapq.heappop(A1)
        tot1 += A2[i] - v
        max_tot1.append(tot1)

    tot3 = -sum(A3)
    max_tot3 = [tot3]
    for i in range(N-1, -1, -1):
        heapq.heappush(A3, -A2[i])
        v = - heapq.heappop(A3)
        tot3 += A2[i]- v
        max_tot3.append(tot3)

    max_tot3 = max_tot3[::-1]

    # print(max_tot1)
    # print(max_tot3)
    ans = float('-inf')
    for i in range(N+1):
        ans = max(ans, max_tot1[i]-max_tot3[i])

    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 38288
function main(input){
  const lines = input.split('\n');
  const NW = lines.shift().split(' ').map(x => parseInt(x));
  const N = NW[0]
  const W = NW[1]
  const items = lines.map(line => line.split(' ').map(x => parseInt(x)));

  const first = items.shift();
  const first_weight = first[0];
  const first_value = first[1];
  var value_sum = first_value;
  dp = [0]

  for(var i=1;i<=value_sum;i++){
    dp[i]=first_weight;
  }

  for(var i=0;i<items.length;i++){
    var current_weight = items[i][0];
    var current_value = items[i][1];
    value_sum += current_value;

  //console.log(dp);

    for(var value=value_sum;value>0;value--){

      if(value >= current_value){
        var prev_weight = dp[value - current_value];
        if(dp[value]==undefined){
          dp[value] = current_weight + prev_weight;
        }else{
          dp[value] = Math.min(prev_weight+current_weight, dp[value]);
        }
      }else{
        if(dp[value]==undefined){
          dp[value]=current_weight;
        }else{
          dp[value]=Math.min(current_weight, dp[value]);
        }
     }
    }
  }


  var result = 0;

  for(var i=dp.length-1;i>=0;i--){
    if(dp[i]<=W){
      result = i;
      break;
    }
  }

  //console.log(dp);

//  console.log(result==90);
  console.log(result);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 49484
def main():
    N, M = (int(i) for i in input().split())

    def trial_division(n):
        """
        nの約数のリストをO(sqrt(n))で求める
        """
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        return divs
    divs = trial_division(M)
    ans = 0
    for d in divs:
        if d*N <= M:
            ans = max(ans, d)
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m, a, b;
    cin >> n >> m >> a >> b;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(j <= a && i <= n-b){
                cout << 0;
            }
            else if(j <= a || i <= n-b){
                cout << 1;
            }
            else cout << 0;
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  int mx = 0;
  int tot = 0;
  rep(i, n){
    int l;
    cin >> l;
    mx = max(mx, l);
    tot += l;
  }
  tot -= mx;
  if(mx < tot) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		
		int ans = 0;
		for (int i = 0; i< 3; i++) {
			if(S.charAt(i) == T.charAt(i)) ans++;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <vector>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;

using namespace std;

int main() {

	int n;

	cin >> n;

	int ans = 0;

	for (int i = 1; i <= n; i += 2) {
		int cut = 0;

		for (int j = 1; j <= n; j++) {
			if (i % j == 0) cut++;
		}

		if (cut == 8) {
			ans++;
		}
	}

	cout << ans << endl;
}

//printf("%ld\n", ans);

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" ";return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}"; }
#ifdef LMAO
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...); }
#else
    #define trace(...) 42
#endif
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;    
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)   
/*****************start************/

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(25);cerr<<fixed<<setprecision(10);
    int n,d;
    cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        if(d*1ll*d>=x*1ll*x+y*1ll*y)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int red_count = 0;
  rep(i, N)
  {
    if (S[i] == 'R')
      red_count++;
  }
  if (red_count > N - red_count)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	string s = readln.chomp;
	long w = read.to!long;
	
	string ans;
	foreach(i, c; s){
		if(i % w == 0) ans ~= c;
		}
	
	ans.writeln;
	}

Measured memory_bytes: 256
INF = 10 ** 15
MOD = 10 ** 9 + 7 
from collections import deque

def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    G_inv = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(N + M - 1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        deg[b] += 1
        G[a].append(b)
        G_inv[b].append(a)
    for i in range(N):
        if deg[i] == 0:
            root = i
            break
    
    q = deque([root])
    dist = [0] * N
    while q:
        v = q.popleft()
        for e in G[v]:
            dist[e] = dist[v] + 1
            deg[e] -= 1
            if deg[e] == 0:
                q.append(e)

    parents = [0] * N
    for i in range(N):
        if i == root:
            continue
        for e in G_inv[i]:
            if dist[e]  + 1 == dist[i]:
                parents[i] = e + 1
                break

    print('\n'.join(map(str,parents)))
if __name__ == '__main__':
    main()

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846
 
typedef long long ll;
typedef pair< int, int > P;   
typedef pair< int, P > PP;

//-----------------------------------------------------------------------------

int n, m, A[1000], B[1000], C[1000], ans;
ll d[100][100];

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

    REP(i, 100) REP(j, 100) d[i][j] = INF;

	cin >> n >> m;
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		d[a][b] = d[b][a] = c;
		A[i] = a, B[i] = b, C[i] = c;
	}

	REP(k, n) REP(i, n) REP(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	REP(i, m) {
		if (d[A[i]][B[i]] < C[i]) ans++;
		//cout << A[i] << B[i] << C[i] << ' ' << ans << endl;
		//cout << d[A[i]][B[i]] << endl;
	}
	cout << ans << endl;

    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<vector<int>> abc(n,vector<int>(3));
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) cin>>abc[i][j];
    vector<vector<int>> dp(n+1,vector<int>(3,0));

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]+abc[i][j]);
            }
        }
    }
    cout<<*max_element(dp[n].begin(),dp[n].end())<<endl;
    return 0;
}

Measured memory_bytes: 11136
N=int(input())
ls1=list(map(int,input().split()))
ls2=list(map(int,input().split()))
n=0
for i in range(N):
    if ls1[i]>=ls2[i]:
        n+=ls2[i]
    else:
        n+=ls1[i]
        ls2[i]=ls2[i]-ls1[i]
        if ls2[i]>=ls1[i+1]:
            n+=ls1[i+1]
            ls1[i+1]=0
        else:
            n+=ls2[i]
            ls1[i+1]=ls1[i+1]-ls2[i]
print(n)            

Measured memory_bytes: 18376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll maxa = 0;
    rep(i, n) { cin >> a[i]; }
    map<ll, ll> mp;
    ll ans = 0;
    for(size_t i = 0; i < n; i++) {
        ll key = a[i];
        mp[key]++;

        key = a[i] + 1;
        mp[key]++;

        key = a[i] - 1;
        mp[key]++;
    }

    for(auto &&i : mp) {
        maxa = max(maxa, i.second);
    }

    cout << maxa;
}


Measured memory_bytes: 6912
from sys import stdin
s = (stdin.readline().rstrip())
s = s.replace("BC","D")
ans = 0
acc = 0

for i in s:
    if i == "B" or i == "C":
        acc = 0
        continue
        
    if i == "A":
        acc += 1
    
    if i == "D":
        ans += acc

print(ans)

Measured memory_bytes: 3628
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n; cin>>n;
    ll A = 0, B = 1;
    while(n--){
        int q, x; cin>>q>>x;
        if(q == 1) A *= x, B *= x;
        else if(q == 2) A -= x;
        else A += x;
    }

    cout << A << " " << B << endl;

    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n+1);
  rep(i,n+1) cin>>a[i];
  vll b(n);
  rep(i,n) cin>>b[i];
  ll ans=0;
  rrep(i,n){
    ll tmp=a[i+1];
    a[i+1]=max(a[i+1]-b[i],0LL);
    ans+=tmp-a[i+1];
    b[i]=b[i]<=tmp?0LL:b[i]-tmp;
    if(b[i]<=0) continue;
    tmp=a[i];
    a[i]=max(a[i]-b[i],0LL);
    ans+=tmp-a[i];
  }
  cout<<ans<<endl;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>l={0,10,100};
  vector<ll>r={10,100,1000};
  vector<ll>s(m),c(m);
  rep(i,0,m){
    cin>>s[i]>>c[i];s[i]--;
  }
  rep(i,l[n-1],r[n-1]){
    auto t=to_string(i);
    bool sw=true;
    rep(j,0,m){
      if(t[s[j]]!=c[j]+'0')sw=false;
    }
    if(sw){
      cout<<i<<endl;
      break;
    }
    if(i==r[n-1]-1){
      cout<<-1<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        _: usize,
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        mut s: Chars,
    }

    if c > d && between(b, d, &s) == false {
        // c > dのとき、aがbを追い越すことになる。
        // 追い越すことができる条件は、b < d の間に岩のない空間が最小3つ連続していること。
        println!("No");
        return;
    }
    // そのタイミングでaはbを追いこすことができ、
    // そこからa, bのがそれぞれゴールにたどり着けるかどうかを判定する
    if goal(b, d, &s) == true && goal(a, c, &s) == true {
        println!("Yes");
    } else {
        println!("No");
    }
}
// ゴールにたどり着ける条件は、現在いる地点からゴールの間に岩のない空間が2つ連続しないこと
fn goal(start: usize, goal: usize, map: &Vec<char>) -> bool {
    for i in start - 1..goal {
        if map[i] == '#' && map[i + 1] == '#' {
            return false;
        }
    }
    true
}

fn between(b: usize, d: usize, map: &Vec<char>) -> bool {
    for i in b - 1..d {
        if map[i - 1] == '.' && map[i] == '.' && map[i + 1] == '.' {
            return true;
        }
    }
    false
}


Measured memory_bytes: 3032
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        PrintWriter prnt = new PrintWriter(System.out);
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

        String s = read.readLine();

        if (isMultipleOFNine(s)) {
            prnt.println("Yes");
        } else {
            prnt.println("No");
        }
        prnt.close();
    }

    static boolean isMultipleOFNine(String s) {
        char[] digits = s.toCharArray();
        long N = 0;
        for (int i = 0; i < digits.length; i++) {
            N += (digits[i] - '0');
        }
        if (N % 9 == 0) return true;
        else return false;
    }
}

Measured memory_bytes: 36372
s=int(input())
# b=input()
# c=[]
# for i in range(b):
#     c.append(a[i])
a = list(map(int,input().split()))
#b = list(map(int,input().split()))

c = {i for i in a}  

if len(a)==len(c):
    print("YES")
else:
    print("NO") 

Measured memory_bytes: 31064
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a<c&&a>b){
cout<< b <<" "<< a <<" "<< c <<endl;
}else if(a>b&&b>c){
cout<< c <<" "<< b <<" "<< a <<endl;
}else if(a>c&&c>b){
cout<< b <<" "<< c <<" "<< a <<endl;
}else if(c>b&&b>a){
cout<< a <<" "<< b <<" "<< c <<endl;
}else if(b>a&&a>c){
cout<< c <<" "<< a <<" "<< b <<endl;
}else if(b>c&&c>a){
cout<< a <<" "<< c <<" "<< b <<endl;
}else if(a==b&&a>c){
cout<< a <<" "<< b <<" "<< c <<endl;
}else if(a==c&&b<a){
cout<< a <<" "<< c <<" "<< b <<endl;
}else if(b==c&&a<b){
cout<< b <<" "<< c <<" "<< a <<endl;
}else if(a==b&&a<c){
cout<< b <<" "<< a <<" "<< c <<endl;
}else if(a==c&&b>a){
cout<< a <<" "<< c <<" "<< b <<endl;
}else if(b==c&&a>b){
cout<< c <<" "<< b <<" "<< a <<endl;
}
return 0;
}



Measured memory_bytes: 3080