akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int main()
{
	stack<int> s;

	int n;
	while (cin >> n) {
		if (n != 0)s.push(n);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 3092
// https://atcoder.jp/contests/abc079/tasks/abc079_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool flag = false;
    if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]) {
        flag = true;
    }
    cout << (flag ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
ll mod = 2e18;
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; }
ll n;
ll d[100010];
ll total = 1;
bool check() {
	rep(i, 0, n + 1) {
		if (d[i] > total)return false;
		total = (total - d[i]) * 2;
		if (total > (int)1e9)return true;
	}
	return true;
}
void solve() {
	cin >> n;
	rep(i, 0, n + 1)cin >> d[i];
	if (!check()) {
		cout << -1 << endl;
		return;
	}
	vector<ll> most(n + 1);
	most[n] = d[n];
	for (int i = n-1; i >= 0; i--) {
		if(i<60)most[i] = min((1LL << i), most[i+1] + d[i]);
		else most[i] = most[i + 1] + d[i];
	}
	ll ans = 1, lo = 1 - d[0], hi = 2 * lo;
	for (int i = 1; i < n + 1; i++) {
		while (lo < hi) {
			ll mid = (lo + hi + 1) / 2;
			if (mid <= most[i]) {
				lo = mid;
			}
			else {
				hi = mid - 1;
			}
		}
		ans += lo;
		lo -= d[i];
		hi = 2 * lo;
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 4784
import sys
from collections import deque
import copy

input = sys.stdin.readline

h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
s = [input() for _ in range(h)]

v = [[-1] * w for _ in range(h)]
d = [(0,1), (0,-1), (1,0), (-1,0)]
d2 = [(2,2), (2,1), (2,0), (2,-1), (2,-2), (1,2), (1,1), (1,-1), (1,-2), (0,2), (0,-2), (-1,2), (-1,1),(-1,-1), (-1,-2), (-2,2), (-2,1), (-2,0),(-2,-1),(-2,-2)]

v[ch-1][cw-1] = 0

q = deque([(ch-1, cw-1)])
q2 = [(ch-1, cw-1)]
tmp = 0

while True:
    while q:
        i,j = q.popleft()
        for ii,jj in d:
            if 0 <= i + ii < h and 0 <= j + jj < w:
                if v[i+ii][j+jj] == -1 and s[i+ii][j+jj] == '.':
                    v[i+ii][j+jj] = tmp
                    q.append((i+ii,j+jj))
                    q2.append((i+ii,j+jj))

    cnt = 0
    for k in range(len(q2)):
        i,j = q2[k][0], q2[k][1]
        for ii,jj in d2:
            if v[i][j] == tmp and 0 <= i + ii < h and 0 <= j + jj < w:
                if v[i+ii][j+jj] == -1 and s[i+ii][j+jj] == '.':
                    v[i+ii][j+jj] = tmp+1
                    q.append((i+ii,j+jj))
                    q2.append((i+ii,j+jj))
                    cnt += 1
    if not q:
        break
    tmp += 1
    q2 = q2[-cnt:]
print(v[dh-1][dw-1])


Measured memory_bytes: 90108
n, m =map(int, input().split())
from itertools import product
s = [0,1]
ptns = sorted(list(product(s, repeat=n)), reverse=1)
#print(ptns)
lis=[]
for _ in range(m):
  tmp=list(map(int, input().split()))
  lis.append(tmp[1:])
#print(lis)
cnt=0
check=0
rem=list(map(int, input().split()))
for i in ptns:# パターンを全部チェックするループ
  for s in range(m): #s-1番目の電球 をチェックしています
    check=0
    for t in lis[s]: #電球のつながっているスイッチを一個ずつチェック
      if i[t-1]==1:
        check+=1
    if check%2!=rem[s]:
      break
    else:
      continue
    break
  else:
    cnt+=1
print(cnt)


Measured memory_bytes: 3188
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int INF=1000000007;
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		int N=sc.nextInt();int K=sc.nextInt();
		StringBuffer S = new StringBuffer(sc.next());
		
		
		char a=(char) (S.charAt(K-1)+32);
		
		S.replace(K-1, K, a+"");
		
		p(S.toString());
			
			
		}
	
	
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


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

int main() {
    
    ios::sync_with_stdio(false);
    
    int x; cin >> x;
    vector<int> xs;

    while (x--) {
        int a; cin >> a;
        xs.push_back(a);
    }

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

    cout << xs[xs.size()/2] - xs[xs.size()/2 - 1] << endl;

    return 0;
}

Measured memory_bytes: 892
let () =
  let n = read_int () in
  Printf.printf "%d:" n;
  let rec doit i x acc =
    if i*i > n then
      if x = 1 then acc
      else x :: acc
    else if x mod i = 0 then doit i (x / i) (i :: acc)
    else doit (i + 1) x acc in
  doit 2 n [] |> List.rev |> List.iter (fun e -> Printf.printf " %d" e);
  print_newline ()

Measured memory_bytes: 2280
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner sc = new Scanner();

    class ab {
        public int a { get; set; }
        public int b { get; set; }
    }

    internal static void Main(string[] args) {
        var N = sc.nextInt();
        var K = sc.nextLong();
        var lst = new List<ab>();
        for (int i = 0; i < N; i++) {
            lst.Add(new ab() {
                a = sc.nextInt(),
                b = sc.nextInt()
            });
        }
        lst = lst.OrderBy(hoge => hoge.a).ToList();

        long sum = 0;
        for (int i = 0; i < N; i++) {
            sum += lst[i].b;
            if (sum >= K) {
                WriteLine(lst[i].a);
                return;
            }
        }

    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 26824
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	char input[101];
	while (scanf(" %s",input)!=EOF) {
		for (int i=0; i<strlen(input); i++) {
			if (input[i]=='@') {
				for (int j=0; j<input[i+1]-'0'; j++) {
					cout<<input[i+2];
				}
				i+=2;
			} else {
				cout<<input[i];
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1144
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		long sum = 0;
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		for (int i = 0 ; i < n ; i++){
			int a = x.nextInt();
			sum = sum +a;
			if(max < a){
				max = a;
			}
			if(min > a){
				min = a;
			}
		}
		System.out.println(min +" "+ max +" "+ sum);
		
	}

}

Measured memory_bytes: 31748
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
a = [0] * (n + 1)
for i in range(len(s)):
    if '<' == s[i]:
        a[i + 1] = a[i] + 1
for i in reversed(range(len(s))):
    if '>' == s[i]:
        a[i] = max(a[i], a[i + 1] + 1)
print(sum(a))


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  ll H,W;cin>>H>>W;
  vector<vector<int>> grid(H,vector<int>(W));

  REP(h,H)REP(w,W) {
    cin>>grid[h][w];
  }

  // 右方向に進んでいるか
  bool right = true;
  // 現在運んでいるか
  bool carring = false;
  struct deal { ll a,b,c,d; };
  vector<deal> ds;
  REP(h,H) {
    if (right) {
      REP(w,W) {
        if (carring && grid[h][w]%2==0) {
          if (w==0) ds.push_back({h-1,w,h,w});
          else ds.push_back({h,w-1,h,w});
        } else if (carring && grid[h][w]%2==1) {
          if (w==0) ds.push_back({h-1,w,h,w});
          else ds.push_back({h,w-1,h,w});
          carring = false;
        } else if (!carring && grid[h][w]%2==1) {
          carring = true;
        }
      }
    } else {
      for(int w=W-1;w>=0;w--) {
        if (carring && grid[h][w]%2==0) {
          if (w==W-1) ds.push_back({h-1,w,h,w});
          else ds.push_back({h,w+1,h,w});
        } else if (carring && grid[h][w]%2==1) {
          if (w==W-1) ds.push_back({h-1,w,h,w});
          else ds.push_back({h,w+1,h,w});
          carring = false;
        } else if (!carring && grid[h][w]%2==1) {
          carring = true;
        }
      }
    }
    right = right ? false : true;
  }
  OUT(ds.size());
  for(auto d:ds) {
    cout<<d.a+1<<' '<<d.b+1<<' '<<d.c+1<<' '<<d.d+1<<endl;
  }

  return 0;
}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
int64_t INF = 10010010010;
// int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;
// int64_t INF = 998244353;

vvi mem(21,vi(0));

ll getSalary(ll i){
    if(mem.at(i).size()==0) return 1;
    if(mem.at(i).size()==1) return 2*getSalary(mem.at(i).at(0))+1;
    ll maxS = -1;
    ll minS = INF;
    for(ll j:mem.at(i)){
        maxS = max(maxS, getSalary(j));
        minS = min(minS, getSalary(j));
    }
    return maxS + minS + 1;
}
int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll x;
    cin >> x;
    ll res = (x/11)*2;
    ll remain = x%11;
    if(remain==10) res += 2;
    if(remain==9) res += 2;
    if(remain==8) res += 2;
    if(remain==7) res += 2;
    if(remain==6) res += 1;
    if(remain==5) res += 1;
    if(remain==4) res += 1;
    if(remain==3) res += 1;
    if(remain==2) res += 1;
    if(remain==1) res += 1;
    cout << res << endl;
}

Measured memory_bytes: 256
from heapq import heapify,heappush,heappop
n = int(input())
INF = float("inf")
adj = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    adj[a].append((b,c))
    adj[b].append((a,c))
H = []
heapify(H)
searched = [0]*n
q,k = map(int,input().split())
k-=1
d = [INF]*n
d[k] = 0
heappush(H, (0,k))
while H:
    f = heappop(H)
    u = f[-1]
    searched[u] = 1
    if d[u] < f[0]:
        continue
    for j in range(len(adj[u])):
        v = adj[u][j][0]
        if searched[v]:
            continue
        if d[v] > d[u]+adj[u][j][-1]:
            d[v] = d[u]+adj[u][j][-1]
            heappush(H,(d[v],v))
for _ in range(q):
    x,y = map(int,input().split())
    x,y = x-1,y-1
    print(d[x]+d[y])

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N,K;
    Scd(N);
    Scd(K);
    
    printf ("%d\n", N-K+1 );

    return 0;
}



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

int main()
{
  int N, a, b;
  cin >> N;
  vector<int> P(N), Q(N), S(N);
  for (int i = 0; i < N; i++)
  {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    cin >> Q.at(i);
  }
  S = P;
  sort(S.begin(), S.end());
  int cnt = 1;
  do
  {
    if (S == P)
      a = cnt;
    if (S == Q)
      b = cnt;
    cnt++;
  } while (next_permutation(S.begin(), S.end()));
  cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

string s;vector<int> v(4);

string dfs(int sum, int d, string x){
  if(d == 4){
    if(sum == 7)return x;
    else return string();
  }
  string ret;
  string a = dfs(sum-v[d], d+1, x + "-" + s[d]),
         b = dfs(sum+v[d], d+1, x + "+" + s[d]);
  if(a.length() != 0)return a;
  else return b;
}

signed main(){
  cin>>s;
  rep(i,4)v[i] = (int)(s[i]-'0');
  string i = s.substr(0,1);
  cout << dfs(v[0],1, i) + "=7" << endl;;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;

    cout<<1+(N-K+K-2)/(K-1)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[3][101010 * 2];
int rem[101010 * 2];

bool deal(char x, char y, const int p, const int w, const int n){
    int l = 1, r = w;
    for(int i = n; i > 0; i --){
        if(a[2][i] == x){
            r ++;
            r = min(r, w);
        }
        else if(a[2][i] == y){
            l --;
            l = max(l, 1);
        }
        if(a[1][i] == x){
            l ++;
        }
        else if(a[1][i] == y){
            r --;
        }
        if(l > r) return true;
    }
    if(p < l || r < p) return true;
    return false;
}
int main(){
    int h, w, n, x, y;
    scanf("%d%d%d%d%d", &h, &w, &n, &x, &y);
    scanf("%s%s", a[1] + 1, a[2] + 1);
    bool flag = false;
    flag = flag | deal('L', 'R', y, w, n);
    flag = flag | deal('U', 'D', x, h, n);
    printf("%s\n", flag ? "NO" : "YES");
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(){
    char S[4];
    scanf("%s", S);
    if((strcmp(S, "AAA")==0) || (strcmp(S, "BBB")==0)){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n, m;
ll tree[800009];
ll lazy[800009];
void push(ll v){
    tree[2*v] += lazy[v];
    lazy[2*v] += lazy[v];
    tree[2*v+1] += lazy[v];
    lazy[2*v+1] += lazy[v];
    lazy[v] = 0;
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll val){
    if(tl > r || tr < l)
        return;
    if(tl >= l && tr <= r){
        tree[v] += val;
        lazy[v] += val;
        return;
    }
    else{
        push(v);
        ll tm = (tl+tr)/2;
        update(2*v, tl, tm, l, r, val);
        update(2*v+1, tm+1, tr, l, r, val);
        tree[v] = max(tree[2*v], tree[2*v+1]);
    }
}
ll get(ll v ,ll tl, ll tr, ll l, ll r){
    if(tl > r || tr < l)
        return -1e18;
    if(tl >= l && tr <= r)
        return tree[v];
    else{
        push(v);
        ll tm = (tl+tr)/2;
        ll t1 = get(2*v, tl, tm, l, r);
        ll t2 = get(2*v+1, tm+1, tr, l, r);
        return max(t1, t2);
    }
}
ll ans;
ll dp[200009];
vector<pair<pll, ll>> seg;
multiset<pair<pll, ll>> rev;
ll curseg;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        ll t1, t2, t3;
        cin >> t1 >> t2 >> t3;
        seg.pb({{t1, t2}, t3});
    }
    sort(seg.begin(), seg.end());
    ll adval = 0;
    for(int i = 1; i <= n; ++i){
        while(i >= seg[curseg].ff.ff && curseg < m){
            update(1, 0, n, seg[curseg].ff.ff, seg[curseg].ff.ss, -seg[curseg].ss);
            rev.insert({{seg[curseg].ff.ss, seg[curseg].ff.ff}, seg[curseg].ss});
            adval += seg[curseg].ss;
            ++curseg;
        }
        while(rev.size() > 0){
            pair<pll,ll> tmp = *rev.begin();
            if(tmp.ff.ff >= i)
                break;
            rev.erase(rev.begin());
            update(1, 0, n, tmp.ff.ss, tmp.ff.ff, tmp.ss);
            adval -= tmp.ss;
        }
        dp[i] = adval + max((ll)0, get(1, 0, n, 0, i-1));
        update(1, 0, n, i, i, dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 30828
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int a,b;
	
	//データの読み込み
	
	scanf("%d %d",&a,&b);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
//	printf("計算部分終了\n");
	
	//出力
	if(b>=a){
		printf("%d",a);
	}else{
		printf("%d",a-1);
	}
	
	
	//('・ω・'）
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	int s,w;
	cin >> s >> w;
	if(w>=s){
		cout << "unsafe" << endl;
	}
	else{
		cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const N = 1000000007

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	cntZeroZero := 0
	battles := make(map[PairInt][]int)

	for i := 0; i < n; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		ra, rb := Ratio(a, b)
		if ra == 0 && rb == 0 {
			cntZeroZero++
			continue
		}

		if rb <= 0 {
			ra, rb = ReverseRatio(ra, rb)
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][1]++
		} else {
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][0]++
		}
	}

	cnt := 1
	for _, battle := range battles {
		cntSub := Pow(2, uint(battle[0])) + Pow(2, uint(battle[1])) - 1
		cnt = cnt * cntSub % N
	}

	cnt = (cnt + cntZeroZero - 1) % N
	cnt = cnt + N
	cnt = cnt % N

	fmt.Println(cnt)
}

type PairInt struct {
	A int
	B int
}

// util
// *   math/simple

func Ratio(x, y int) (int, int) {
	if x == 0 {
		if y == 0 {
			return 0, 0
		}
		return 0, 1
	} else if y == 0 {
		return 1, 0
	}

	sign := 1
	if x > 0 && y < 0 {
		sign = -1
	} else if x < 0 && y > 0 {
		sign = -1
	}

	x = Abs(x)
	y = Abs(y)
	var small, big int
	if x < y {
		small, big = x, y
	} else {
		small, big = y, x
	}
	gcd := GCD(small, big)
	return x / gcd, sign * y / gcd
}

func ReverseRatio(x, y int) (int, int) {
	sign := -1
	if x == 0 || y <= 0 {
		sign = 1
	}

	return Abs(y), sign * Abs(x)
}

func GCD(smaller, bigger int) int {
	rem := bigger % smaller
	if rem == 0 {
		return smaller
	}
	return GCD(rem, smaller)
}

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer = answer * base % N
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 31192
num = int(input())
s = input().rstrip().split(' ')
count = 0
key = True

while key:
    for i in range(num):
        s[i] = int(s[i])
        if( s[i] % 2 == 0):
            s[i] = s[i] // 2
        else:
            key = False

    count += 1

print(count - 1)


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

#define MOD 1000000007

int main() {
	
	int n; cin >> n;
	string s, t; cin >> s >> t;
	int m = s.size();

	ll ans = 0;

	int p, preb;
	if (s[0] == t[0]) {
		p = 1;
		ans = 3;
		preb = 0;
	}
	else {
		p = 2;
		ans = 6;
		preb = 1;
	}

	while (p < m) {
		if (preb == 0){
			if (s[p] == t[p]){
				ans = (ans * 2) % MOD;
				p++;
			}
			else {
				ans = (ans * 2) % MOD;
				p += 2;
				preb = 1;
			}
		}
		else {
			if (s[p] == t[p]) {
				p++;
				preb = 0;
			}
			else {
				ans = (ans * 3) % MOD;
				p += 2;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
vx = x2 - x1
vy = y2 - y1
vx, vy = -vy, vx
x3 = x2 + vx
y3 = y2 + vy
vx, vy = -vy, vx
x4 = x3 + vx
y4 = y3 + vy
print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include<stdio.h>

typedef struct{//構造体
  int num;
  char mark;
  int index;
}Card;

//関数宣言
int partition(Card*,int,int);
void quicksort(Card*,int,int);


int main(){

  //変数
  Card a[100000];
  int a_num,i,key,stability=0;

  //入力
  scanf("%d",&a_num);
  for(i = 0; i < a_num; i++){
    scanf(" %c %d",&a[i].mark,&a[i].num);
    a[i].index = i;
  }
  
  //ソート
  quicksort(a,0,a_num-1);
  for(i = 0; i < a_num-1; i++){
    if(a[i].num == a[i+1].num && a[i].index > a[i+1].index){
      stability=1;
    }
  }

  //出力
  if(stability == 0)printf("Stable\n");
  else if(stability == 1)printf("Not stable\n");
    for(i = 0; i < a_num; i++){
    printf("%c %d\n",a[i].mark,a[i].num);
  }
  
  return 0;
}



int partition(Card *a, int p, int last)
{
  int key,i,j;
  Card swap;

  key = a[last].num;
  i = p-1;


  for(j = p; j < last; j++){
    if(a[j].num <= key){
      i = i+1;
      swap = a[i];
      a[i] = a[j];
      a[j] = swap;
    }
  }
      swap = a[i+1];
      a[i+1] = a[last];
      a[last] = swap;

      return i+1;
}

void quicksort(Card *a, int p, int last){
  int q;

  if(p < last){
    q = partition(a,p,last);
    quicksort(a,p,q-1);
    quicksort(a,q+1,last);
  }
}

Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n;
  cin >> n;
  vector<lint> a(n);
  std::vector<lint> ball(n,0);
  REP(i,n){
    cin >> a[i];
    ball[a[i]-1]++;
  }

  lint sum = 0;
  REP(i,ball.size()) sum += ball[i]*(ball[i]-1)/2;

  REP(i,n){
    cout << sum - ball[a[i]-1] + 1 << "\n";
  }
  return 0;
}


Measured memory_bytes: 5760
def janken(val):
    if val == "r":
        return "p",p
    elif val == "p":
        return "s", s
    else:
        return "r",r
n, k=map(int, input().split())
r,s,p = map(int,input().split())
t = input()

jan = []
ans = 0
for i in range(n):
    hand, point = janken(t[i])
    if i < k :
        jan.append(hand)
        ans += point
    else:
        if jan[i-k] == hand:
            jan.append("all")
        else:
            jan.append(hand)
            ans+=point
print(ans)


Measured memory_bytes: 4212
# nikkei2019-qualC - Different Strokes
def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=sum, reverse=1)
    ans = sum(i for i, j in A[::2]) - sum(j for i, j in A[1::2])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22104
N = gets.to_i
h = gets.split.map(&:to_i)
dp = [0, (h[0] - h[1]).abs]
2.step(N-1) do |i|
  dp[i] = [dp[i-1] + (h[i-1] - h[i]).abs, dp[i-2] + (h[i-2] - h[i]).abs].min
end
puts dp.last

Measured memory_bytes: 11524
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
int main() {
  ll n;
  cin>>n;
  vec a(3*n);
  ll ans=0;
  loop(i,3*n){
    cin>>a[i];
  }
  sort(all(a));
  for(ll i=3*n-2;i>=n;i-=2){
    ans+=a[i];
  }
 putout(ans);
 
 
 
 
 
 
 
 
 
}


Measured memory_bytes: 2560
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 105, maxk = 1e5+5;
int N,K, a[maxn], sg[maxk];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    memset(sg, -1, sizeof(sg));
    cin>>N>>K;
    sg[0] = 0;
    for(int i = 0; i<N; i++){
        cin>>a[i];
        sg[a[i]] = 0;
    }
    sort(a, a+N);
    
    for(int i = 0; i <= K; i++){
        set<int> mex;
        for(int j = 0;j<N&&a[j]<=i; j++){
            mex.insert(sg[i-a[j]]);
        }
        int k = 0;
        while(mex.count(k)){k++;}
        sg[i] = k;
    }
    
    cout<<(sg[K]?"First":"Second")<<"\n";

    return 0;
}





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

int main() {
  int n, k, num = 1;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int squareNum = num * 2;
    int kplus = num + k;
    if (squareNum < kplus) {
      num = squareNum;
    } else {
      num = kplus;
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 3632
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def _cmb(N, mod):
    N1 = N + 1
    fact = [1] * N1
    inv = [1] * N1

    for i in range(2, N1):
        fact[i] = fact[i-1] * i % mod

    inv[N] = pow(fact[N], mod-2, mod)
    for i in range(N-1, 1, -1):
        inv[i] = inv[i+1]*(i+1) % mod

    def cmb(a, b):
        return fact[a] * inv[b] * inv[a-b] % mod
    return cmb

def resolve():
    K = int(input())
    s = input()
    ls = len(s) - 1
    mod = 10**9+7

    cmb = _cmb(ls+K, mod)

    ans = 0
    p25 = 1
    p26 = pow(26, K, mod)
    p26inv = 576923081 #pow(26,  mod-2, mod)
    for i in range(K+1):
        ans = (ans + cmb(ls+i, ls) * p25 * p26) % mod
        p25 = p25 * 25 % mod
        p26 = p26 * p26inv % mod
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 106672
# https://atcoder.jp/contests/abc058/tasks/abc058_b

odd = input()
even = input()
ans = []

for i in range(len(even)):
    ans.append(odd[i])
    ans.append(even[i])

if len(odd) != len(even):
    ans.append(odd[-1])

print(''.join(ans))

Measured memory_bytes: 38580
a,b=io.read("*n","*n")
if a<=0 and 0<=b then
    print("Zero")
elseif 0<a then
    print("Positive")
elseif b<0 then
    if (b-a+1)%2~=0 then
        print("Negative")
    else
        print("Positive")
    end
end

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

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

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

int main() {
  ll n, m; cin >> n >> m;
  string s, t; cin >> s >> t;
  ll l = lcm(n,m);
  ll ln = l / n, lm = l / m;
  ll lnm = lcm(ln,lm);
  ll ans = l;
  for (ll i = 0; i<l; i+=lnm) {
    if (s[i/ln] != t[i/lm]) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int cnt[100060],n;
int main(){
	cin>>n;
	for(int i=0;i<100060;i++)cnt[i]=0;
	for(int i=0;i<n;i++){
		int a;cin>>a;
		for(int j=a-1;j<=a+1;j++)cnt[j+5]++;
	}
	int ans=0;
	for(int i=0;i<100060;i++)ans=max(ans,cnt[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    string s; cin >> s;

    int rcnt[n], gcnt[n], bcnt[n];
    rcnt[n - 1] = (s[n - 1] == 'R' ? 1 : 0);
    gcnt[n - 1] = (s[n - 1] == 'G' ? 1 : 0);
    bcnt[n - 1] = (s[n - 1] == 'B' ? 1 : 0);

    repr(i, n - 1){
        rcnt[i] = rcnt[i + 1];
        gcnt[i] = gcnt[i + 1];
        bcnt[i] = bcnt[i + 1];

        if(s[i] == 'R') rcnt[i]++;
        if(s[i] == 'G') gcnt[i]++;
        if(s[i] == 'B') bcnt[i]++;
    }

    ll ans = 0;
    rep(i, n - 2){

        reps(j, i + 1, n - 1){
            if(s[i] == s[j]) continue;

            int checkdigit = 0b111;
            if(s[i] == 'R' || s[j] == 'R'){
                checkdigit -= 0b100;
            }
            if(s[i] == 'G' || s[j] == 'G'){
                checkdigit -= 0b010;
            }
            if(s[i] == 'B' || s[j] == 'B'){
                checkdigit -= 0b001;
            }

            int pos = j + (j - i);

            switch(checkdigit){
            case 0b100:
                ans += rcnt[j + 1];
                if(pos < n && s[pos] == 'R') ans--;
                break;
            case 0b010:
                ans += gcnt[j + 1];
                if(pos < n && s[pos] == 'G') ans--;
                break;
            case 0b001:
                ans += bcnt[j + 1];
                if(pos < n && s[pos] == 'B') ans--;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
// https://atcoder.jp/contests/abc119/tasks/abc119_a
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    string text;
    cin >> text;
    int year = atoi(text.substr(0, 4).c_str());
    int month = atoi(text.substr(5, 2).c_str());
    int date = atoi(text.substr(8, 2).c_str());
    // cout << date << " " << month << " " << year << endl;
    if (year < 2019)
        cout << "Heisei" << endl;
    else if (year == 2019 && month < 4)
        cout << "Heisei" << endl;
    else if (year == 2019 && month == 4 && date <= 30)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

void solv() {

	string s;
	cin >> s;
	int c[3];
	fill(c, c + 3, 0);
	for (size_t i = 0; i < s.size(); i++)
	{
		c[s[i] - 'a']++;
	}
	if (abs(c[0] - c[1]) > 1 || abs(c[0] -c[2]) > 1 || abs(c[2] - c[1]) > 1) {
		cout << "NO" << endl;
	}
	else cout << "YES" << endl;
}


int main() {
	solv();

	return 0;
}


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

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int[] a = new int[5];
			for(int i=0;i<a.length;i++){
				a[i] = sc.nextInt();
			}
			Arrays.sort(a);
			for(int i=a.length-1;i >= 0;i--){
				System.out.print(a[i]);
				if(i <= 0){
					break;
				}else{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.rbegin(), v.rend());
  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(i%2==0)a+=v[i];
    else b += v[i];
  }
  cout<<a-b<<endl;

  return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (a, b) = listOfInt()
    var ans: Int
    if (a <= 0 && 0 <= b) {
        ans = 0
    } else if (a > 0) {
        ans = 1
    } else {
        ans = if ((b - a + 1) % 2 == 0) 1 else -1
    }
    print(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun print(ans: Int) = println(if (ans > 0) "Positive" else if (ans < 0) "Negative" else "Zero")


Measured memory_bytes: 37744
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A,B,C,D,E,F = (int(_) for _ in input().split())
    memo = {}
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a +(100*B)*b
                    s = c*C + d*D
                    if w ==0:
                        break
                    elif w + s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100 * s/(w+s)
                            memo[a,b,c,d] = density
    max_density = max(memo.values())
    for k,v in memo.items():
        if v==max_density:
            print((100*A)*k[0] +(100*B)*k[1]+k[2]*C + k[3]*D,k[2]*C + k[3]*D)
            break
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 40148
#include <string>
#include <iostream>
using namespace std;
int main() {
	std::string str;
	cin >> str;	// 代入できます
  	char c;
  	int y=1000000;
  	for(int n=0;n<2;n++){
    int y2 = 0;
  	if(n==0){c='0';}else{c='1';}
  	for(int i=0;i<str.length();i++){
    	if(c=='0'){
          if(str[i]==c){y2=y2;}else{y2++;}
    	c = '1';}
      	else{
          if(str[i]==c){y2=y2;}else{y2++;}
    	c = '0';}
      	    }
    if (y > y2){
      y = y2;
    }
    }
	cout << y;
}

Measured memory_bytes: 512
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<endl;

    return 0;
}





Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=300005;
int n,m,dq,by;
int x[N],t[N],l[N],r[N];
int main(){
	n=read(); m=read()*2; int ans=1;
	for(int i=1;i<=n;i++)x[i]=read();
	for(int i=1;i<=n;i++){
		int v=read();
		ans+=v/m+(v%m!=0); v%=m;
		l[i]=(0<v&&v<=2*x[i]); r[i]=(0<v&&v<=m-2*x[i]);
	}
	for(int i=1;i<n;i++){
		if(dq&&r[i]){
			if(l[i])by++;
			ans--; dq--;
		}else if (l[i]) dq++;
		else if (r[i]&&by){ by--; dq++; }
	}
	if(r[n])ans--;
	cout<<(ll)ans*m<<endl;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAXN = 1e5 + 47;
const LL MAX = 47;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	int n, m;
	cin >> n;
	VI d(n);
	FOR(i, 0, n)
		cin >> d[i];
	cin >> m;
	multiset<int> a(ALL(d));
	int x;
	FOR(i, 0, m)
	{
		cin >> x;
		if (a.count(x))
		{
			a.erase(a.find(x));
		}
		else
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

Measured memory_bytes: 10368
n=int(input())
a,b,c=map(int,input().split())
for i in range(n-1):
    a1, b1, c1 = map(int, input().split())
    a,b,c=a1+max(b,c),b1+max(a,c),c1+max(a,b)
print(max(a,b,c))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;
using LL = long long;

#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN_LL(v) LL v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
#define MOD 1000000007

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

  int stock_0 = 0;
  int stock_1 = 0;
  int ans = 0;
  for (const auto& e : S) {
    if (e == '0') {
      if (stock_1 > 0) {
        --stock_1;
        ans += 2;
      } else ++stock_0;
    }
    if (e == '1') {
      if (stock_0 > 0) {
        --stock_0;
        ans += 2;
      } else ++stock_1;
    }
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int sum=0;
    for (int hoge=1;hoge<1000;hoge++) {
        if (hoge%3==0) {
            sum+=200;
        } else {
            sum+=195;
        }
    }
    int n,y,m,d;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>y>>m>>d;
        int count=0;
        for (int j=1;j<y;j++) {
            if (j%3==0) {
                count+=200;
            } else {
                count+=195;
            }
        }
        for (int k=1;k<m;k++) {
            if (y%3==0) {
                count+=20;
            } else {
                if (k%2==1) {
                    count+=20;
                } else {
                    count+=19;
                }
            }
        }
        count+=d;
        cout<<sum-count+1<<endl;
    }
}



Measured memory_bytes: 3088