akhauriyash/Code-Regression huggingface dataset:
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_C
/*
    1 floor :10 rooms
    3 story
    4 buildings
    total 120 rooms
*/
#include <iostream>
#include <vector>

int main()
{
    using std::vector;

    int n;
    int cnt = 0;
    int b, f, r, v;
    const int B = 4;
    const int F = 3;
    const int R = 10;
    vector<vector<vector<int>>> V(B, vector<vector<int>>(F, vector<int>(R, 0)));

    std::string sepa = std::string(20, '#');

    std::cin >> n;
    while (n)
    {
        std::cin >> b >> f >> r >> v;
        V.at(b - 1).at(f - 1).at(r - 1) += v;
        n--;
    }

    for (auto &vecvec : V)
    {
        for (auto &vec : vecvec)
        {
            for (auto &elme : vec)
            {
                std::cout << " " << elme;
            }
            std::cout << std::endl;
        }
            cnt++;
        if (cnt < B)
        {
            std::cout << sepa << std::endl;
        }
        else
        {
        }
    }
}



Measured memory_bytes: 3156
import java.util.Scanner;


public class Main {
	
	static boolean t = true;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int count = 0;
		
		while(true){
			int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			count++;
			
			int[][] vertexs = new int[n][2];
			
			for(int i = 0; i < n; i++){
				vertexs[i][0] = sc.nextInt();
				vertexs[i][1] = sc.nextInt();
			}
			
			double sum = 0;
			
			for(int i = 0; i < n-1; i++){
				sum += (vertexs[i][0]*vertexs[i+1][1] - vertexs[i][1]*vertexs[i+1][0])/2.0;
			}
			sum += (vertexs[n-1][0]*vertexs[0][1] - vertexs[n-1][1]*vertexs[0][0])/2.0;
			
			System.out.println(count + " " + (-sum));
			
		}
	}
	
	
}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;

namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            List<int> A = new List<int>();
            for(var i = 0; i < N; i++)
            {
                int na = -(int.Parse(Console.ReadLine()));
                if (i == 0)
                {
                    A.Add(na);
                    continue;
                }

                if (na >= A[A.Count() - 1])
                {
                    A.Add(na);
                }
                else
                {
                    int l = -1;
                    int r = A.Count();
                    while (r - l > 1)
                    {
                        int c = (l + r) / 2;
                        if (A[c] <= na)
                        {
                            l = c;
                        }
                        else
                        {
                            r = c;
                        }
                    }
                    A[r] = na;
                }
            }

            Console.WriteLine(A.Count());
            

            //Console.Out.Flush();

        }
    }


    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }

}


Measured memory_bytes: 17324
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((l (read))
         (k (- (integer-length l) 1))
         (out (make-string-output-stream :element-type 'base-char))
         (n (+ k 1))
         (m 0))
    (declare (uint32 m l))
    (dotimes (i k)
      (format out "~D ~D ~D~%" (+ i 1) (+ i 2) 0)
      (format out "~D ~D ~D~%" (+ i 1) (+ i 2) (ash 1 i))
      (incf m 2))
    (loop for v from (- k 1) downto 0
          when (>= (- l (ash 1 v)) (ash 1 k))
          do (format out "~D ~D ~D~%" (+ v 1) n (- l (ash 1 v)))
             (decf l (ash 1 v))
             (incf m))
    (format t "~D ~D~%" n m)
    (write-string (get-output-stream-string out))))

#-swank (main)


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

int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X);
  vector<long long> B(Y);
  vector<long long> C(Z);
  for(int i=0; i<X; i++) cin >> A.at(i);
  for(int i=0; i<Y; i++) cin >> B.at(i);
  for(int i=0; i<Z; i++) cin >> C.at(i);
  vector<long long> AB(X*Y);
  int k=0;
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      AB.at(k)=A.at(i)+B.at(j);
      k++;
    }
  }
  sort(AB.begin(),AB.end());
  reverse(AB.begin(),AB.end());
  
  vector<long long> ABC(min(3000,X*Y)*Z);
  int l=0;
  for(int i=0; i<min(3000,X*Y); i++){
    for(int j=0; j<Z; j++){
      ABC.at(l)=AB.at(i)+C.at(j);
      l++;
    }
  }
  sort(ABC.begin(),ABC.end());
  reverse(ABC.begin(),ABC.end());

  for(int i=0; i<K; i++) cout << ABC.at(i) << endl;  
}

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

int main( void )
{
  string S, T;
  cin >> S >> T;

  int count = 0;
  int max = -1000;

  for( int i = 0; i < S.size() - T.size() + 1; i++ ) {
    for( int j = 0; j < T.size(); j++ ) {
      if( T.at( j ) == S.at( i + j ) ) {
	//cout << "T:" << j << " S:" << j + i << endl;
	count++;
      }
    }
    if( max < count ) {
      max = count;
    }
    count = 0;
  }
  //cout << max << endl;
  cout << T.size() - max << endl;
}

Measured memory_bytes: 3580
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
       ll a,b;
       cin>>a>>b;
       (a==b)? cout<<"Yes\n":cout<<"No\n";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3640
n, m, x = map(int, input().split())
books = []
for i in range(n):
	books.append(tuple(map(int, input().split())))

def combinations():
	from itertools import product
	
	for i in product([0, 1], repeat = n):
		lst = []
		for j in range(n):
			if i[j] == 1:
				lst.append(books[j])
		yield lst

ans = 10**9
for books_bought in combinations():
	level = [0]*m
	cost = 0
	for book in books_bought:
		cost += book[0]
		for i in range(m):
			level[i] += book[i + 1]
		
	for num in level:
		if num < x:
			break
	else:
		ans = min(ans, cost)

if ans == 10**9:
	print (-1)
else:
	print (ans)		

Measured memory_bytes: 69268
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

dp=[[-1,-1,-1] for i in range(n)]
dp[0]=[l[0][0],l[0][1],l[0][2]]

for i in range(1,n):
 for j in range(3):
  for k in range(3):
   if j==k:
    continue
   dp[i][j]=max(dp[i][j],dp[i-1][k]+l[i][j])

print(max(dp[-1]))

Measured memory_bytes: 78552
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

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

  string s, t;
  cin >> s >> t;

  ll last = -1;

  ll ls = s.size(), lt = t.size(), rec[ls - lt + 1] = {};

  REP(i, ls - lt + 1){
    REP(j, lt){
      if(s[i + j] == t[j] || s[i + j] == '?') rec[i]++;
    }
    if(rec[i] == lt) last = i;
  }

  if(last == -1){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  REP(j, lt) s[last + j] = t[j];

  REP(i, ls){
    if(s[i] == '?') s[i] = 'a';
  }
  cout << s << endl;
  return 0;
}


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

const int N = 100005;
const int md = 1e9 + 7;
int n, k;
vector<int> dvs;
int dp[N];

int pw(int x, int y) {
	int res = 1;
	while(y) {
		if (y & 1) res = 1LL * res * x % md; x = 1LL * x * x % md;
		y >>= 1;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;

	// find divisors of n
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			dvs.push_back(i);
			if (i != n / i) dvs.push_back(n / i);
		}
	}
	sort(dvs.begin(), dvs.end());

	// calculate DPs
	dp[0] = k;
	for (int i = 1; i < dvs.size(); ++i) {
		int d = dvs[i]; // minimum period
		dp[i] = pw(k, (d + d % 2) / 2);
		for (int j = 0; j < i; ++j) if (d % dvs[j] == 0) {
			dp[i] -= dp[j];
			if (dp[i] < 0) dp[i] += md;
		}
	}

	// calculate the answer
	int ans = 0;
	for (int i = 0; i < dvs.size(); ++i) {
		int d = dvs[i]; 
		ans = (ans + 1LL * dp[i] * ((d & 1) ? d : d / 2)) % md;
	}
	cout << ans << endl;
}

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

int main()
{
  string s;
  cin >> s;
  
  int alphabets[26] = {0};
  for(unsigned int i = 0; i < s.length(); ++i)
  {
    alphabets[s[i] - 'a']++;
  }

  bool flag = true;
  for(int i = 0; i < 26; ++i)
  {
    if(alphabets[i] == 0)
    {
      char c = 'a' + i;
      cout << c << endl;
      flag = false;
      break;
    }
  }
  if(flag) cout << "None" << endl;
}

Measured memory_bytes: 3720
#include <iostream>
 
using namespace std;
 
int main(){
  int A,B;
  cin>>A>>B;
  if(A%3==0){
    cout<<"Possible";
  }else if(B%3==0){
  	cout<<"Possible";
  }else if((A+B)%3==0){
  cout<<"Possible";
  }else{
  cout<<"Impossible";
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int c = scanner.nextInt() % 39;
      if (c == 0) {
        c = 39;
      }
      System.out.printf("3C%02d\n", c);
    }
  }
}

Measured memory_bytes: 17192
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n;
	cin >> n;
	ll ans = 0;
	vector<ll> a(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 1) {
		ll d = max(a[i] - a[i + 1], 0ll);
		ans += d;
		a[i + 1] += d;
	}
	printf("%lld\n" ,ans);
	return 0;
}

Measured memory_bytes: 4840
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define sz(v) ((int)(v).size())
#define clr(v, d)        memset(v, d, sizeof(v))
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;
const double PI = acos(-1.0);
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);// freopen("out.txt", "w", stdout);  
#endif
}
bool check_prime(ll a)
{
	bool flag = true;
	if (a <= 1)
		return false;
	else
	{
		for (ll i = 2; i <= sqrt(a); i++)
		{
			if (a % i == 0)
			{
				flag = false;
				break;
			}
		}
	}
	if (flag)
		return true;
	else
	{
		return false;
	}
}

int main()
{
	//file();
	Fast;
	int a, b, c;
	cin >> a >> b >> c;
	int arr[3];
	arr[0] = a;
	arr[1] = b;
	arr[2] = c;
	sort(arr, arr + 3);
	if (arr[0] == 5 && arr[1] == 5 && arr[2] == 7)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}

}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ans := 0
	t := 0
	for i := 0; i < n; i++ {
		t += i + 1
		ans += t
	}
	for i := 0; i < n-1; i++ {
		a, b := scanInt(), scanInt()
		ans -= min(a, b) * (n + 1 - max(a, b))
	}
	fmt.Fprintln(wr, ans)
}


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

using namespace std;

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

  int ans = (B - 1) / (A - 1);
  if ((B - 1) % (A - 1) > 0) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	int n,m;
	cin>>n>>m;

	string r=string(n,' ');
	for (int i=0;i<m;i++)
	{
		int s;
		char c;
		cin>>s>>c;
		s--;
		
		if (r[s]!=' ' && r[s]!=c)
		{
			cout<<-1<<endl;
			return 0;
		}
		else
		{
			r[s]=c;
		}
	}
	if (r[0]==' ') r[0]='0'+(n>1);
	for (int i=1;i<n;i++)
	{
		if (r[i]==' ') r[i]='0';
	}
	if (n!=1 && r[0]=='0')
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<r<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int N, W;
    cin >> N >> W;
    vector< pair<int, int> > goods(N);
    rep(i, N){
        int v, w;
        cin >> v >> w;
        goods[i] = make_pair(v, w);
    }
    int dp[110][10010]; //dp[i][j] i番目まで、重さj以下で選んだときの価値の最大値
    rep(i, N+1){
        dp[i][0] = 0;
    }
    REP(i, 1, N+1){
        rep(j, W+1){
            if(j >= goods[i-1].second){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-goods[i-1].second] + goods[i-1].first);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}


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

int main() {
    long long n, ab, r = 0, l = 0, sum = 0, ans = 1000000000;
    cin >> n;
    long w[n];
    for(int i = 0; i < n; ++i) {
        cin >> w[i];
        sum += w[i];
    } 
    ab = sum;
    r = sum;
    for(int i = 0; i < n; ++i) {
        l += w[i];
        r -= w[i];
        ab = abs(l-r);
        if(ab < ans) ans = ab;
    }
    cout << ans << endl;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  //bit全探索
  long long ans = 0;
  for(int bit=0; bit < (1 << (n-1)); bit++){
    long long tmp = s.at(0) - '0';
    for(int i=0; i<n-1; i++){
      if(bit & (1<<i)){
        ans += tmp;
        tmp = 0;
      }
      tmp = tmp*10 + (s.at(i+1)-'0');
    }
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

int n;
int m;

int main () {
	scanf ("%d%d", &n, &m);
	int sum = 0, top = 0;
	for (int i = 0; i < m; i++) {
		int x;
		scanf ("%d", &x);
		sum += x;
		top = max (top, x);
	}
	if (top > (sum - top) + 1) printf ("%d\n", top - (sum - top + 1)); else printf ("0\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int w[110],v[110];
long long int dp[110][100345];

int N,W;
int main () {
    cin >> N >> W;
    for(int i=0; i<N; i++) for(int j=0; j<=W; j++) dp[i][j] = -1;
    for(int i=0; i<N; i++) cin >> w[i] >> v[i];
    for(int i=0; i<N; i++) dp[i][0] = 0;
    for(int i=0; i<N; i++) {
        for(int we=0; we <=W; we++) {
            if( w[i] > we) dp[i+1][we] = dp[i][we];
            if (dp[i][we-w[i]] >= 0 && w[i] <= we){
                dp[i+1][we] = max(dp[i][we-w[i]]+v[i],dp[i][we]);
            } else dp[i+1][we] = dp[i][we];
        }
    }
    long long int ans = 0;
    for(int i=0; i<=W; i++) ans = max(ans,dp[N][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Main {

  public static void main( String[] args ) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    BigDecimal cost = new BigDecimal(100000);
    BigDecimal thousand = new BigDecimal("1000");
    
    for (int i = 0; i < n; i++) {
      cost = cost.add(cost.multiply(new BigDecimal(0.05))).setScale(0, RoundingMode.FLOOR);
      cost = cost.divide(thousand)
              .setScale(0, RoundingMode.CEILING)
              .multiply(thousand);
    }
    System.out.println(cost);
  }
}

Measured memory_bytes: 25148
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), x = sc.nextInt();
		if(a+b < x) {
			System.out.println("NO");
		} else if (a > x) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
 
}

Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define ss                second
#define pb                push_back
#define int                long long
#define forn(i, n)        for (int i = 0; i < n; i++)
#define Forn(j, a, b)     for (int j = a; j < b; j++)
#define sp                " "
#define br                "\n"
#define mii               map<int ,int>
#define setbits(x)        _builtin_popcountll(x)
#define zrobits(x)        _builtin_ctzll(x)
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define MAXN              10000000
void c_p_c()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("ou.txt", "w", stdout);
#endif
}
//map--------------------------
// auto it=map.begin();
// for(it;it!=map.end();++it)
// {

// }
// int dp[100002][6];
// int fun(int arr[],int i,int k,int z,int n)
// {
//   if(i>=n||k==0||i<0)
//   return 0;
//   if(dp[i][z]!=-1)return dp[i][z];
//   int value=0;
//   if(i<n)
//   value=max(value,arr[i]+fun(arr,i+1,k-1,z,n));
//   if(i>0 and z>0)
//   value=max(value,arr[i]+fun(arr,i-1,k-1,z-1,n));
//   return dp[i][z]=value;
// }


//char num[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};

void solve()
{
  int n;cin>>n;
  string s;cin>>s;
  int r=0;
  for(int i=0;i<s.length();i++)if(s[i]=='R')r++;
  int w=0;
  int ans=n;
  ans=min(ans,max(r,w));
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='W')w++;
    else r--;
    ans=min(ans,max(r,w));
  }
  cout<<ans;
}
int32_t main()
{
  c_p_c();
  solve();
}   


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;

void solve(){
   int a,b;
    cin>>a>>b;
    if(a>=10)
         cout<<b;
   else  
         cout<<b+(100)*(10-a);
}
int main(){
   std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   
   solve(); 
   return 0;
}


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

int main()
{
    string s;
    cin >> s;
    unordered_set<char> st;
    bool unique = true;
    for (int i = 0; i < s.size(); i++) {
        if (st.count(s[i]) == true) {
            unique = false;
            break;
        }
        st.insert(s[i]);
    }
    if (unique) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, x, m, M = 1000;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> m;
        x -= m;
        M = min(m, M);
    }
    cout << n+x/M << endl;
}







Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a >= b) {
        rep(i, a) { cout << b; }
        cout << endl;
    } else {
        rep(i, b) { cout << a; }
        cout << endl;
    }
}


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

using namespace std;




int main(){

	string s; cin >> s;



	for(int i = 0; i < s.size(); i++){
		if(i & 1){
			if(s[i] == 'R'){
				cout << "No" << endl; return 0;
			}
		}else{
			if(s[i] == 'L'){
				cout << "No" << endl; return 0;
			}
		}
	}


	cout << "Yes" << endl;

	return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	ll ct = 0;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
	{
		ll au = b / 2 + c / 2;
		ll bu = a / 2 + c / 2;
		ll cu = a / 2 + b / 2;
		if (au == a && bu == b && cu == c)
		{
			cout << -1;
			return 0;
		}
		else
		{
			a = au;
			b = bu;
			c = cu;
			ct++;
		}
	}
	cout << ct;
	return 0;
}


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

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

  for(int i = 0; i < 2; i++){
  	for(int j = 9; j > 0; j--){
    	if(n % j == 0){
        	n /= j;
          	break;
        }
    }
  }
  if(n == 1){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n).map{gets.to_i}

def generate_G(g,h,n)
  h = 3*h + 1

  if h > n
    return g
  else
    g = g.unshift(h)
    generate_G(g,h,n)
  end

end

def insertion_sort(a,n,g)
  g.upto(n-1) do |i|
    v = a[i]
    j = i-g

    while j >= 0 && a[j] > v
      a[j+g] = a[j]
      j -= g
      $cnt += 1
    end

    a[j+g]=v
  end
end

def shell_sort(a,n)
  $cnt = 0
  $g = generate_G([1],1, n)
  $g.each do |g|
    insertion_sort(a, n, g)
  end
end

shell_sort(a, n)

puts $g.length
puts $g.join(" ")
puts $cnt

a.each{|v| puts v}


Measured memory_bytes: 22504
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

ll sum(ll n){
    ll s = 0;
    while(n){
        s += n%10;
        n /= 10;
    }
    return s;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll k;
    cin >> k;
    ll start = 1, add = 1;
    for(int i=1; i<=k; i++){
        cout << start << nl;
        while((start+2*add)*sum(start+add) < (start+add)*sum(start+2*add)) //check for 19, 29 or the like ending with 9
            add *= 10;
        start += add;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<string> str(n);
	for (int i = 0; i < n; i++) {
		cin >> str[i];
	}

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

	vector<string> s(n);
	vector<int> t(n + 1, 0);
	s[0] = str[0];
	t[0] = 1;
	int j = 0;
	for (int i = 1; i < n; i++) {
		if (str[i] == str[i - 1]) {
			t[j]++;
		}
		else {
			j++;
			s[j] = str[i];
			t[j] = 1;
		}
	}
	
	int max = 0;
	for (int i = 0; i < n; i++) {
		if (max < t[i]) {
			max = t[i];
		}
	}

	vector<string> ans;
	for (int i = 0; t[i] != 0; i++) {
		if (t[i] == max) {
			ans.push_back(s[i]);
		}
	}

	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 18292
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define DEBUG false
#pragma GCC optimize "trapv"

void solve(int arr[],int n)
{
    int dp[n];
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<'\n';
}

int32_t main()
{
    nitro;
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    solve(arr,n);
return 0;
}

Measured memory_bytes: 1792
from collections import Counter
# union find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

AB = AB[::-1]
ret = []
tmp = 0
uf = UnionFind(N)
for a,b in AB:
    if uf.is_same_group(a-1, b-1):
        ret.append(0)
    else:

        ret.append(uf.count(a-1) * uf.count(b-1))
        uf.unite(a-1,b-1)

ans = 0
for i in range(M-1, -1, -1):
    ans += ret[i]
    print(ans)

Measured memory_bytes: 37780
def main():
    from builtins import int, map, list, print, len
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    S = set()
    for i in range(N):
        S.add(input())
    print(len(S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 31212
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  int ok = 1;
  for (int i = 1; i < N; i++) {
    if (H[i-1] < H[i]) {
      H[i]--;
    } else if (H[i-1] > H[i]) {
      ok = 0;
      break;
    }
  }
  cout << ((ok) ? "Yes" : "No") << endl;
}



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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for(int i=0; i<N; i++) {
            H[i] = sc.nextInt();
        }

        Arrays.sort(H);
        long attackTimes = 0;
        
        for(int ri = N-1; ri>=0; ri--) {
            if(K>0) {
                K--;
            }else {
                attackTimes += H[ri];
            }
        }
        
        System.out.println(attackTimes);


    }

}


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

using namespace std;

int main() {
    char s[201], p[101], S[101];
    scanf("%s %s", s, p);
    strcpy(S, s);
    strcat(s, S);
    if (strstr(s, p) == NULL) printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A = 1;
  int sum = 1;
  for (int i = 0; i < N; i++){
    if (K <= A){
      sum += K;
    }
    else {
      sum += A;
    }
    A *= 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;

int d;
vector<int> c;
vector<vector<int>> s;
vector<int> last(26, 0);

ll calculate(int date, int choice) {
    ll ans = 0;
    ans += s[date][choice];
    rep (i, 26) {
        ans -= last[i];
    }
    return ans;
}

vector<int> argsort(vector<int> v) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    // ソートする。
    sort(indices.begin(), indices.end(), [&v](int i1, int i2) {
        return v[i1] < v[i2];
    });
    return indices;
}

int greedy(int date) {
    vector<int> score(26, 0);
    rep (i, 26) {
        score[i] = s[date][i] + last[i] * c[i];
        last[i]++;
    }
    vector<int> indices = argsort(score);
    last[indices[25]] = 0;
    return indices[25];
}

int main() {
    cin >> d;
    c.resize(26);
    rep (i, c.size()) {
        scanf("%d", &c[i]);
    }
    s.resize(d, vector<int>(26));
    rep (i, d) {
        rep (j, c.size()) {
            cin >> s[i][j];
        }
    }
    ll default_score = 0;
    vector<int> default_res(d);
    rep (i, d) {
        default_res[i] = greedy(i);
        default_score += calculate(i, default_res[i]);
    }
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand26(0, 25), rand365(0, 364);

    rep (i, 10000) {
        int p = rand26(mt);
        int q = rand365(mt);
        auto changed_res = default_res;
        changed_res[q] = p;
        ll changed_score = 0;
        rep (j, d) {
            changed_score += calculate(j, changed_res[j]);
        }
        if (changed_score > default_score) {
            default_res = changed_res;
            default_score = changed_score;
        }
    }

    rep (i, d) {
        cout << default_res[i] + 1 << endl;
    }
}




Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;

int H, W;

void bfs(vvc &field, queue<pii> q, vvi &dist)
{
    vi dir_h = {1, -1, 0, 0};
    vi dir_w = {0, 0, 1, -1};

    while (!q.empty())
    {
        int h = q.front().first;
        int w = q.front().second;
        q.pop();

        for (int i = 0; i < 4; i++)
        {
            int next_h = h + dir_h[i], next_w = w + dir_w[i];

            if (next_h < 0 || next_h >= H || next_w < 0 || next_w >= W)
            {
                continue;
            }

            if (field[next_h][next_w] == '#')
            {
                continue;
            }

            dist[next_h][next_w] = dist[h][w] + 1;
            field[next_h][next_w] = '#';
            q.push(make_pair(next_h, next_w));
        }
    }
}

int main()
{
    cin >> H >> W;

    vvc field(H, vc(W));
    vvi dist(H, vi(W, 0));
    queue<pii> q;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> field[i][j];

            if (field[i][j] == '#')
            {
                q.push(make_pair(i, j));
            }
        }
    }

    bfs(field, q, dist);

    int ans = 0;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 21520
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	int a[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)cin >> a[i][j];
	}
	bool ans = true;
	for (int i = 0; i < 2; i++) {
		if (!(a[0][i] - a[0][i + 1] == a[1][i] - a[1][i + 1] && a[1][i] - a[1][i + 1] == a[2][i] - a[2][i + 1]))ans = false;
		if (!(a[i][0] - a[i + 1][0] == a[i][1] - a[i + 1][1] && a[i][1] - a[i + 1][1] == a[i][2] - a[i + 1][2]))ans = false;
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){
    int n;
    scanf("%d",&n);
    int c[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    
    int cnt,x=0;
    for(int j=0;j<n;j++)
    {
    for(int i=n-1;i>0;i--)
        {
            if(c[i]<c[i-1])cnt=c[i],c[i]=c[i-1],c[i-1]=cnt,x++;
            else;
        }
    }
    for(int i=0;i<n-1;i++){
        printf("%d ",c[i]);
    }
    printf("%d\n%d\n",c[n-1],x);
    return 0;
}


Measured memory_bytes: 2732
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[101010]={};
	cin>>n;
	FORQ(i,1,n){
		cin>>a[i];
	}
	int c=0;
	FORQ(i,2,n){
		if(a[i]==i&&a[i-1]==i-1){
			swap(a[i],a[i-1]);
			c++;
		}
	}
	if(a[1]==1){
		swap(a[1],a[2]);
		c++;
	}
	FORQ(i,2,n){
		if(a[i]==i){
			swap(a[i],a[i-1]);
			c++;
		}
	}
	cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 640
rect_cnt = dia_cnt = 0
while True:
    try:
        a, b, c = map(int, input().split(","))
        if a==b:
            dia_cnt = dia_cnt+1
        elif (a**2 + b**2) == c**2:
            rect_cnt = rect_cnt + 1
        else:
            pass
    except EOFError:
        break
print(rect_cnt)
print(dia_cnt)


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int k, s;
    std::cin>>k>>s;

    int cnt = 0;
    for(int x = 0;x <= k;x++){
        for(int y = x; y <= k;y++){
            for(int z = y;z <= k;z++){
                if(x + y + z == s){
                    if(x == y && y == z){
                        cnt += 1;
                    }else if(x != y && y != z){
                        cnt += 6;
                    }else{
                        cnt += 3;
                    }
                }
            }
        }
    }
    std::cout<<cnt<<std::endl;
    return 0;
}

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

using namespace std;

# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define REPD(i, a, b) for(int i = a; i >= b; -- i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPG(i, h, x) for(int i = h[x]; ~i; i = edge[i].next)

const int N = 2e5 + 5, N_ = 19, S_ = (1 << 19) - 1;

int r[N_ + 3][N], cnt[N_ + 3];
int f1[S_ + 5], f2[S_ + 5];
int n, v, len = -1;
int d[N], S;

int main() {
	scanf("%d%d", &n, &v);
	REP(i, 1, n) scanf("%d", &d[i]);
	int x = v << 1;
    while(x) {
        x >>= 1, ++ len;
        REP(i, 1, n - 1) {
            if(d[i + 1] - d[i] <= x) continue;
            r[len][++ cnt[len]] = i;
        } r[len][++ cnt[len]] = n;
    }
	S = (1 << len) - 1;
	if(cnt[0] > len + 1){
        REP(i, 1, n) puts("Impossible"), exit(0);
    }
	REP(i, 0, S) f2[i] = n + 1;
	REP(i, 0, S) {
		REP(j, 1, len) if(i & (1 << j - 1)) {		
			f1[i] = max(f1[i], *upper_bound(r[j] + 1, r[j] + cnt[j] + 1, f1[i ^ (1 << j - 1)]));
			f2[i] = min(f2[i], r[j][lower_bound(r[j] + 1, r[j] + cnt[j] + 1, f2[i ^ (1 << j - 1)] - 1) - r[j] - 1] + 1);
		}
	}
	REP(i, 1, cnt[0]) {
		bool okay = 0;
		REP(s, 0, S) {
			if(f1[s] >= r[0][i - 1] && f2[S - s] <= r[0][i] + 1) { okay = 1; break; }
		}
		REP(j, r[0][i - 1] + 1, r[0][i]) puts(okay ? "Possible" : "Impossible");
	} 

	return 0;
}

Measured memory_bytes: 22656
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

//色々計算する用
ll C[26],last2[26],T[365],Tans[365],V[365],Vorigin[365];
ll S[365][26],last[365][26],last_sim[365][26];
ll D,vmax,dadd_best,steps=0;

//リセット用の関数S
void R26(ll A[26]){
    for(int i=0;i<26;++i)A[i]=0;
}

void R365(ll A[365]){
    for(int i=0;i<365;++i)A[i]=0;
}

void R365_26(ll A[365][26]){
    for(int i=0;i<365;++i)for(int j=0;j<26;++j)A[i][j]=0;
}

void copy26(ll A[26],ll B[26]){
    for(int i=0;i<26;++i)A[i]=B[i];
}

void copy365(ll A[365],ll B[365]){
    for(int i=0;i<365;++i)A[i]=B[i];
}

void copy365_26(ll A[365][26],ll B[365][26]){
    for(int i=0;i<365;++i)for(int j=0;j<26;++j)A[i][j]=B[i][j];
}

void greedy(){
    ll dadd,i,j,k,l,i_calc,tbest,score,vbest;
    for(dadd=0;dadd<=26;++dadd){
        //リセット
        R26(last2);
        R365_26(last);

        for(i=0;i<D;++i){
            i_calc=min(i+dadd+1,D);
            for(j=0;j<26;++j){
                //得点の初期化
                if(i==0){
                    V[i]=0;
                }else{
                    V[i]=V[i-1];
                }
                
                //lastの初期化
                if(i==0)R26(last[i]);
                else copy26(last[i],last[i-1]);

                last[i][j]=i+1;
                V[i]+=S[i][j];

                for(k=0;k<26;++k)
                    for(l=i;l<i_calc;l++)V[i]-=C[k]*(l+1-last[i][k]);

                if(j==0||V[i]>=vmax){
                    vmax=V[i];
                    tbest=j;
                }
            }
            if(i==0)R26(last[i]);
            else copy26(last[i],last[i-1]);
            T[i]=tbest+1;
            last[i][tbest]=i+1;
        }

        //得点の再計算
        score=0;
        R26(last2);

        for(i=0;i<D;++i){
            score+=S[i][T[i]-1];
            last2[T[i]-1]=i+1;
            for(j=0;j<26;j++)score-=C[j]*(i+1-last2[j]);
        }

        if(dadd==0||(dadd!=0 && score>vbest)){
            dadd_best=dadd;
            vbest=score;
            copy365(Tans,T);
            copy365_26(last_sim,last);
        }
    }

    vmax=vbest;
    copy365(T,Tans);
    copy365_26(last,last_sim);
}

int main(){
    int i,j;
    cin>>D;
    for(i=0;i<26;++i)scanf("%lld",&C[i]);
    for(i=0;i<D;++i)for(j=0;j<26;++j)scanf("%lld",&S[i][j]);

    //初期解の生成    
    greedy();

    for(i=0;i<D;++i)printf("%lld\n",T[i]);
    return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    ll t = 0, a = 0; 
    if(A - K <= 0){
         t = 0;
         if (K - A >= B){
             a = 0;
         }
         else a = B - (K - A);
    }
    else{
        t = A - K;
        a = B;
    }
    
    cout << t << " " << a << endl;
}

Measured memory_bytes: 3680