akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

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

    sort(all(l));

    auto f = [](int a, int b, int c){
        if(a + b > c && a + c > b && b + c > a) return true;
        else return false;
    };

    int ans = 0;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            if(l[i] == l[j]) continue;
            for(int k=j+1;k<n;++k){
                if(l[i] == l[k] || l[j] == l[k]) continue;
                if(f(l[i], l[j], l[k])) ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut ws = vec![];
    let mut s2 = 0;
    for _ in 0..n {
        let w = get!();
        ws.push(w);
        s2 += w;
    }
    let mut ans = s2;
    let mut s1 = 0;
    for t in 0..n-1 {
        s1 += ws[t];
        s2 -= ws[t];
        ans = std::cmp::min(ans, (s1 - s2).abs());
    }
    println!("{}", ans);
}

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




int main(){
    string X;
    cin >> X;
    stack<char> evalStr;
    for(int i=0;i<X.length();i++){
        if(X[i] == 'S') evalStr.push(X[i]);
        else if(X[i] == 'T'){
            if(evalStr.empty() || evalStr.top() == 'T'){
                
                evalStr.push(X[i]);
            }else{
                evalStr.pop();
            }
            
        }
    }
    
    
    cout << evalStr.size() << endl;
}

Measured memory_bytes: 644
#include<stdio.h>

int main(){
  char str[100];
  scanf("%s",str);
  int flag = 1;
  int i = 0;
  for(i = 0;i < 100;i++){ 
  	if((i % 2 == 0 && str[i] == 'L') || (i % 2 == 1 && str[i] == 'R')){
      flag = 0;
    }
  }
  
  if(flag){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
vector<ll> divisors(ll n) {
    vector<ll> ans;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ans.push_back(i);
            ans.push_back(n / i);
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    auto d = divisors(n);
    auto d1 = divisors(n - 1);
    set<ll> s;
    for(ll x : d) {
        if(x != 1) {
            ll nn = n;
            while(nn % x == 0) {
                nn /= x;
            }
            if(nn % x == 1) {
                s.insert(x);
            }
        }
    }
    s.insert(d1.begin(), d1.end());
    s.erase(1);
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 384
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])
  

Measured memory_bytes: 67716
n, m = map(int, input().split())
g = {}
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g.setdefault(a, [])
    g[a].append(b)
    g.setdefault(b, [])
    g[b].append(a)

isVisited = [False]*n
isVisited[0] = True

def dfs(v: int) -> int:
    if all(isVisited):
        return 1

    ret = 0

    for i in g[v]:
        if isVisited[i]:
            continue

        isVisited[i] = True
        ret += dfs(i)
        isVisited[i] = False

    return ret

print(dfs(0))


Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int distToA = Math.abs(x- a); 
    int distToB = Math.abs(x- b); 

    System.out.println(distToA < distToB ? "A" : "B");
  }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n, k, a[100005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<int> dp(n + 1, INF);
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i - j > 0) dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
        }
    }

    cout << dp[n] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	char c;
	while(true){
		cin>>a>>c>>b;
		if(c=='?')break;
		if(c=='+')
		cout<<a+b<<endl;
		else if(c=='-')
		cout<<a-b<<endl;
		else if(c=='*')
		cout<<a*b<<endl;
		else if(c=='/')
		cout<<a/b<<endl;
	}
}



Measured memory_bytes: 3092
n,m,x = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int,input().split()))
ans = 10**7
for i in range(2**n):
    count = 0
    sw = [0]*m
    for j in range(n):
        if (i>>j)&1:
            count += a[j][0]
            for k in range(m):
                sw[k] += a[j][k+1]
    q = 1
    for L in range(m):
        if sw[L] < x:
            q = 0
            break
    if q == 1:
        ans = min(ans,count)
if ans == 10**7:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9240
package main

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

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

var counter []int
var graph map[int][]int
var qsum []int

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()


	n := nextInt()
	q := nextInt()


	counter = make([]int, n)
	qsum = make([]int, n)
	graph = make(map[int][]int)

	for i := 0; i < n-1; i++ {
		a := nextInt()
		b := nextInt()
		a--
		b--
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	for i := 0; i < q; i++ {
		p := nextInt()
		x := nextInt()
		p--
		qsum[p] += x
	}

	dfs(0, -1)

	for i := 0; i < n; i++ {
		_, _ = fmt.Fprintf(out, "%v ", counter[i])
	}

}

var tot int

func dfs(v, p int) {
	tot += qsum[v]
	counter[v] = tot
	for _, u := range graph[v] {
		if u != p {
			dfs(u, v)
		}
	}
	tot -= qsum[v]
}


Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 10;
ll a, b, c, s;
int f(ll x)
{
	if(x & 1) return 0;
	return f(s - x / 2) + 1;
}
int main()
{
	cin >> a >> b >> c;
	if(a % 2 || b % 2 || c % 2)
	{
		puts("0");
		return 0;
	}
	s = (a + b + c) / 2;
	int ans = INF;
	if(3 * a / 2 != s) ans = min(ans, f(a));
	if(3 * b / 2 != s) ans = min(ans, f(b));
	if(3 * c / 2 != s) ans = min(ans, f(c));
	if(ans == INF) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3612
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
inline void Fail(){printf("0");exit(0);}

ll ans;
bool ok=true;
string s;

int main(){
	cin>>s;
	ans=9LL*(int)(s.size()-1);
	REP(i,s.size()-1)if(s[i]!='9')ok=false;
	if(ok)ans+=s[0]-'0';
	else ans+=s[0]-'1';
	cout<<ans;
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 256
program abc068c
  implicit none
  integer n, m, a, b, i
  logical,allocatable :: x(:), y(:)

  read *, n,m
  allocate(x(n),y(n))

  x = .false.
  y = .false.

  do i = 1,m
     read *, a,b
     if (a == 1) x(b) = .true.
     if (b == n) y(a) = .true.
  end do

  if (count(x.and.y) > 0) then
     print *, 'POSSIBLE'
  else
     print *, 'IMPOSSIBLE'
  end if
end program abc068c


Measured memory_bytes: 1792
import java.util.*;
public class Main {
		public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
        String s =sc.nextLine();
				if((s.indexOf("a") !=-1)&&(s.indexOf("b") !=-1)&&(s.indexOf("c") !=-1)){
						System.out.println("Yes");
				}
				else{
						System.out.println("No");
				}
    }
}


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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i < int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

int v[100500];
int w[200500];

int dp[3500][3500];

string ans;
string s, t;


void rec(int a, int b) {
    if (a == 0 || b == 0)
        return;

    if (s[a - 1] == t[b - 1]) {
        ans.push_back(s[a - 1]);
        rec(a - 1, b - 1);
    } else {
        if (dp[a][b] == dp[a - 1][b])
            rec(a - 1, b);
        else
            rec(a, b - 1);
    }
}

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t;

    forn(i, s.size())
        forn(j, t.size())
            if (s[i] == t[j])
                dp[i + 1][j + 1] = dp[i][j] + 1;
            else
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);

    rec(s.size(), t.size());

    reverse(ans.begin(), ans.end());

    cout << ans;

    return 0;
}

Measured memory_bytes: 43264
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    long long num = 1;

    for (int i = 1; i <= N; i++){
        num *= i;
        if (num > 10000000){
        num = num % 1000000007;
        }
    }
    cout << num % 1000000007 << endl;
}

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

int main() {
    int n, m;
  cin >> n >> m;
  vector<long long> a(n);
  multiset<long long> a_set;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a_set.insert(a[i]);
  }
  for (i = 0; i < m; i++) {
    auto ite = a_set.end();
    ite--;
    int temp = *ite;
    int before_size = a_set.size();
    a_set.erase(ite);
    a_set.insert(temp / 2);
    // while (before_size != a_set.size()) {
    //   a_set.insert(temp);
    // }
    // auto it = a_set.begin();
    // for (int j = 0; j < a_set.size(); j++) {
    //   cout << *it << ' ';
    //   it++;
    // }
    // cout << endl;
  }
  long long result = 0;
  auto ite = a_set.begin();
  for (i = 0; i < n; i++) {
    result += *ite;
    ite++;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n ;
  cin >> n ;
  vector<int> a(n);
  for(int i =0 ; i<n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int ans =0;
  int pre = 0;
  for(int i=0;i<n;i++){
    if(pre == a.at(i)){
      pre = 0;
      ans -= 1;
    }
    else{
      pre = a.at(i);
      ans +=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    double sum = 0;
    for(int i=0; i<N; i++) {
        double val; string s; cin >> val >> s;
        if(s == "JPY") {
            sum += val;
        }
        else {
            sum += 380000.0 * val;
        }
    }
    printf("%.12f\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll N,K;cin>>N>>K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(All(A));
    ll l=-2e18,r=2e18;
    while(l+1<r){
        ll x=(l+r)>>1;
        ll cnt=0;
        REP(i,N){
            int ok=i,ng=N;
            if(A[i]<0) swap(ok,ng);
            while(abs(ok-ng)>1){
                int midi=(ok+ng)>>1;
                if(A[i]*A[midi]<=x) ok=midi;
                else ng=midi;
            }
            if(A[i]>=0) cnt+=ok-i;
            else cnt+=N-ok;
        }
        if(cnt>=K) r=x;
        else l=x;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#define maxn 1005
#define mod 1000000007
using namespace std;

char grid[maxn][maxn];
int dp[maxn][maxn];

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);cout.tie(0);

    int n, m;cin >> n >> m;

    bool fl1 = 1, fl2 = 1;
    for (int i = 1; i <= n; i++){
        cin >> (grid[i] + 1);
        if (grid[1][i] == '.' && fl1)dp[1][i] = 1;
        else fl1 = false;
        if (grid[i][1] == '.' && fl2)dp[i][1] = 1;
        else fl2 = false;
    }

    for (int i = 2; i <= n; i++){
        for (int j = 2; j <= m; j++){
            if (grid[i][j] == '.'){
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }

    cout << dp[n][m];

    return 0;
}


Measured memory_bytes: 5120
n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)


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

int main(){
	string s;
  cin >> s;
  int l = s.length();
  for(int i=0;i<l;i++){
    if(i%2==0 && s[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2>0 && s[i]=='R'){
    	cout << "No" << endl;
      	return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
  
  
  
  
    


Measured memory_bytes: 256
def digitsum(n):#nは正の整数、各位の和、許容は１０＾１０００
    if n<10:
        return n
    else:
        m=n//10
        return n%10+digitsum(m)

snuke=[]
for i in range(4,16):
    #i桁のsnuke数を調べる
    #10**i-1はsnuke数
    #上三桁以外は9で確定なので10**i-1から順に調べればよい
    snuke.append(10**i-1)
    min=10**i-1
    k=998
    while k>=100:
        test=k*10**(i-3)+10**(i-3)-1
        if min*digitsum(test)>=test*digitsum(min):
            snuke.append(test)
            min=test
        k-=1


snuke.append(999)
min=999
k=998
while k>0:
    if min*digitsum(k)>=k*digitsum(min):
        snuke.append(k)
        min=k
    k-=1

snuke.sort()

K=int(input())
for i in range(0,K):
    print(snuke[i])

Measured memory_bytes: 86508
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d %d",&a,&b);
    c=a-1;
    if(a<=b)
        c++;
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

// const P {
//   string s[10];
// };

// const operator<(const P& a, const P &b) {
//   REP(i,5) {
//     a[i]
//   }
// }

int main() {
  string s[10];
  while(cin>>s[0],s[0]!="END") {
    REP(i,9)
      cin >> s[i+1];
    REP(i,10) {                 // ñÎÌÌàÌðs[0]@Æ·éB
      string t = s[i];
      reverse(ALL(t));
      if (s[i] != t) {
        swap(s[0],s[i]);
        break;
      }
    }
    string hoge = "1000002345";
    int res = 0, hogehoge = 0;  // hogehoge ÍãºÌ¾ªêv·éàÌÌd¡JEgðñð·é½ß
    
    do {
      if (hoge[0] > '3') break;
      if (hoge[0] == '3' && hoge[1] >= '3') continue;
      vector<string>vv(5);
      bool used[10];
      REP(i,10) {
        if (hoge[i]!='0') {
          vv[hoge[i]-'1'] = s[i];
          used[i] = 1;
        }else
          used[i] = 0;
      }
      REP(S, 1<<5) {
        if (S>>(hoge[0]-'1') & 1) continue;
        vector<string> v = vv;
        bool dame = 0;
        REP(i,5) {
          if (S>>i & 1) {
            reverse(ALL(v[i]));
            if (v[i] == vv[i]) {
              dame = 1;break;
            }
          }
        }
        if (dame) continue;
        bool f = 1;
        bool used2[10];
        memcpy(used2, used, sizeof(used));
        REP(i,5) {
          string tmp;
          REP(j,5) {
            if (v[j][i] == '0')
              tmp += '1';
            else
              tmp += '0';
          }
          string tmp2 = tmp;
          reverse(ALL(tmp2));
          bool ff = 0;
          REP(j,10) {
            if (!used2[j] && (tmp == s[j] || tmp2 == s[j])) {
              used2[j] = 1;
              ff = 1;
              break;
            }
          }
          if (!ff) {
            f = 0;
            break;
          }
        }
        if (f) {
          if (hoge[0] == '3' && hoge[1] == '0') hogehoge++;
          else res++;
          // cout << hoge << endl;
          // cout << bitset<5>(S) << endl;
          // FOR(it, v)
          //   cout << *it << " ";
          // cout << endl;
        }
      }
    } while(next_permutation(ALL(hoge)));
    cout << res + hogehoge/2 << endl;
  }
}

Measured memory_bytes: 924
#include <stdio.h>

int main(){
  int a[3], i, j;
  scanf("%d%d%d", &a[0], &a[1], &a[2]);
  for(i = 0;i < 3;i++){
    for(j = i + 1;j < 3;j++){
      if(a[i] > a[j]){
        a[i] += a[j];
        a[j] = a[i] - a[j];
        a[i] -= a[j];
      }
    }
  }

  printf("%d %d %d\n", a[0], a[1], a[2]);
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#define N 101

int main() {
    int i, j, n, key, k;
    int arr[N];

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    for (i = 1; i < n; i++) {

        k = 0;
        while(k < n-1){
            printf("%d ", arr[k]);
            k++;
        }
        printf("%d\n", arr[n-1]);

        key = arr[i];
        j = i-1;
        while(j >= 0 && arr[j] > key){
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = key;
    }

    k = 0;
    while(k < n-1){
        printf("%d ", arr[k]);
        k++;
    }
    printf("%d\n", arr[n-1]);

    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,K;
    scanf("%d%d",&N,&K);

    long ans=0;
    //bはK+1以上であることが確定している
    for(int b=K+1;b<=N;b++){
        int q=N/b;
        int r=N%b;
        ans+=(q*(b-K)+MAX(r-K+1,0));
    }
    if(K==0) ans-=N;
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		 Scanner scan = new Scanner(System.in);
		 int a = scan.nextInt();
		 int b = scan.nextInt();
		 int ans1 = a * b;
		 int ans2 = 2 * (a + b);
		 System.out.println(""+ans1+" "+ans2);
	}
}

Measured memory_bytes: 26160
#include <cstdio>
#include <utility>
#include <iostream>
#include <string>
#include <regex>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
is(string &s){int c;
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	for (int n; scan(n);)
		out((n * n + n + 2) / 2, '\n');
}


Measured memory_bytes: 2924
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
string t;
int main(void)
{
	int a, b, k;

	cin>>a>>b>>k;

	repr(i, a, a+k){
		if(i>=b-k+1) break;
		cout<<i<<endl;
	}

	repr(i, b-k+1, b+1){
		if(i>=a) cout<<i<<endl;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[1000010];
int n,i,j,k,a[1000010],sum;
int main(){
	scanf("%s",s);
	n=strlen(s);
	for(i=1;i<=n;i++)a[i]=(s[n-i]-'0')*9;
	for(i=1;i<=n;i++){
		a[i+1]+=a[i]/10;a[i]%=10;
	}
	if(a[n+1])n++;
	for(i=1;i<=n;i++)sum+=a[i];
	for(k=1;k<=n*10;k++){
		a[1]+=9;sum+=9;
		j=1;
		while(j<=n){
			if(a[j]<10)break;
			sum-=10;a[j]-=10;
			sum++;a[j+1]++;j++;
			if(j==n&&a[j+1])n++;
		}
		if(sum<=k*9){
			printf("%d\n",k);return 0;
		}
	}
}

Measured memory_bytes: 4608
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class Card
{
public:
  Card()
    : data(make_pair('\0', 0))
  {}
  Card(const Card& x)
    : data(x.data)
  {}

  pair<char, int> data;
  bool operator < (const Card& y) const
  {
    return this->data.second < y.data.second;
  }
  bool operator <= (const Card& y) const
  {
    return (*this < y) || (this->data.second == y.data.second);
  }
  bool operator == (const Card& y) const
  {
    return (this->data.first == y.data.first) && (this->data.second == y.data.second);
  }
  bool operator != (const Card& y) const
  {
    return !(*this == y);
  }
};

void mergeSort(vector<Card>&, int, int);
void merge(vector<Card>&, int, int, int);
int partition(vector<Card>&, int, int);
void quickSort(vector<Card>&, int, int);


void mergeSort(vector<Card>& A, int l, int r)
{
  if (l + 1 < r)
  {
    int m = (l + r) / 2;
    mergeSort(A, l, m);
    mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}

void merge(vector<Card>& A, int l, int m, int r)
{
  int n1 = m - l;
  int n2 = r - m;
  vector<Card> L(n1 + 1), R(n2 + 1);
  rep (i, n1) L[i] = A[l + i];
  rep (i, n2) R[i] = A[m + i];
  L[n1].data = make_pair('A', 1e9 + 1); R[n2].data = make_pair('A', 1e9 + 1);

  int i = 0, j = 0;
  for (int k = l; k < r; ++k)
  {
    if (L[i] <= R[j])
    {
      A[k] = L[i++];
    }
    else
    {
      A[k] = R[j++];
    }
  }
}

int partition(vector<Card>& A, int p, int r)
{
  Card x = A[r];
  int i = p - 1;

  for (int j  = p; j < r; ++j)
  {
    if (A[j] <= x)
    {
      ++i;
      swap(A[i], A[j]);
    }
  }
  swap(A[i + 1], A[r]);

  return i + 1;
}

void quickSort(vector<Card>& A, int p, int r)
{
  if (p < r)
  {
    int q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

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

    int n;
    cin >> n;

    vector<Card> A;
    vector<Card> ref;
    A.resize(n);
    ref.resize(n);
    rep (i, n)
    {
      char c;
      int a;
      cin >> c >> a;
      A[i].data = make_pair(c, a);
      ref[i].data = make_pair(c, a);
    }

    quickSort(A, 0, n - 1);
    mergeSort(ref, 0, n);

    bool stable = true;
    rep (i, n)
    {
      if (A[i] != ref[i])
      {
	stable = false;
	break;
      }
    }
    cout << (stable ? "Stable\n" : "Not stable\n");

    rep (i, n)
    {
      cout << A[i].data.first << " " << A[i].data.second << "\n";
    }
    return 0;
}




Measured memory_bytes: 5068
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const long INF = 1e5;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    long d[h][w];
    rep(i,h){
        rep(j,w){
            d[i][j] = 0;
        }
    }
    string ss;
    rep(i,h){
        cin >> ss;
        rep(j,w){
            s[i][j] = ss[j];
        }
    }
    int tem = -1;
    rep(i,h){
        tem = -1;
        rep(j,w){
            if(s[i][j] == '#'){
                d[i][j] = -INF;
                tem = j;
            }
            else{
                d[i][j]+=(j-tem);
            }
        }
        tem = w;
        for(int j = w-1;j>=0;j--){
            if(s[i][j] == '#'){
                d[i][j] = -INF;
                tem = j;
            }
            else{
                d[i][j]+=(tem-j);
            }
        }
        rep(j,w){
            d[i][j]--;
        }
    }
    rep(i,w){
        tem = -1;
        rep(j,h){
            if(s[j][i] == '#'){
                d[j][i] = -INF;
                tem = j;
            }
            else{
                d[j][i]+=(j-tem);
            }
        }
        tem = h;
        for(int j = h-1;j>=0;j--){
           if(s[j][i] == '#'){
                d[j][i] = -INF;
                tem = j;
            }
            else{
                d[j][i]+=(tem-j);
            } 
        }
        rep(j,h){
            d[j][i]--;
        }
    }
    long ans = 0;
    rep(i,h){
        rep(j,w){
            ans = max(ans,d[i][j]);
        }
    }
    cout << ans-1 << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(size_t i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int l = *max_element(a.begin(), a.end());
    int s = *min_element(a.begin(), a.end());
    cout << l - s << endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec L(M), R(M);
    REP(i,0,M) cin >> L[i] >> R[i];
    
    DESC(L);
    ASC(R);
    PR(MAX(R[0]-L[0]+1,0));

    return 0;
}

/*



*/

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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define sz(x) x.size()
#define INF LONG_LONG_MAX
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

/*LL gcd(LL a,LL b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}*/


int main()
{
    S s1,s2;
    cin>>s1>>s2;
    int a,b;
    cin>>a>>b;
    S s;
    cin>>s;
    if(s==s1)
    {
        cout<<a-1<<" "<<b;
    }
    else if(s==s2)
    {
        cout<<a<<" "<<b-1;
    }
    else
        cout<<a<<" "<<b;
}


Measured memory_bytes: 256
n = int(input())
maxv = -2000000000
rr = [0]*n
for i in range(n):
    rr[i] = int(input())
minv = rr[0]
for i in range(1,n):
    r = rr[i]
    maxv = max([maxv, r - minv])
    minv = min([minv, r])
print(maxv)


Measured memory_bytes: 13372
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong();
    long f=0;
    if((a%2==0&&b%2==0&&c%2==0)&&(a==b&&b==c)){
      System.out.println(-1);
    }else{
      while(true){
        if(a%2!=0||b%2!=0||c%2!=0){
          break;
        }else{
          long ha=a/2,hb=b/2,hc=c/2;
          a=hb+hc;
          b=ha+hc;
          c=ha+hb;
          f++;
        }
      }
      System.out.println(f);
    }
  }
}


Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;

    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 c[3][3];
	for (uint32 i = 0;i < 3;++i) {
		for (uint32 j = 0;j < 3;++j) {
			std::cin >> c[i][j];
		}
	}
	bool f = 1;
	int32 cur = c[0][0] - c[0][1];
	for (uint32 i = 1;i < 3;++i) {
		if (cur != c[i][0] - c[i][1]) f = 0;
	}
	cur = c[0][1] - c[0][2];
	for (uint32 i = 1;i < 3;++i) {
		if (cur != c[i][1] - c[i][2]) f = 0;
	}
	cur = c[0][0] - c[1][0];
	for (uint32 i = 1;i < 3;++i) {
		if (cur != c[0][i] - c[1][i]) f = 0;
	}
	cur = c[1][0] - c[2][0];
	for (uint32 i = 1;i < 3;++i) {
		if (cur != c[1][i] - c[2][i]) f = 0;
	}
	std::cout << (f ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())

grid = []
for _ in range(h):
    row = list(input())
    grid.append(row)

def bfs(grid, sy, sx, gy, gx, h, w):
    visited = [[float('inf')] * w for _ in range(h)]
    visited[sy][sx] = 1
    que = deque([(sy, sx)])
    # up, right, down, left
    dy = [-1, 0, 1, 0]
    dx = [0, 1, 0, -1]
    while que:
        y, x = que.popleft()
        for i in range(4):
            next_y = y + dy[i]
            next_x = x + dx[i]
            if 0 <= next_y < h and 0 <= next_x < w and grid[next_y][next_x] == '.' and visited[next_y][next_x] == float('inf'):
                visited[next_y][next_x] = visited[y][x] + 1
                que.append([next_y, next_x])
                if next_y == gy and next_x == gx:
                    return visited[gy][gx]
    return -1

r = bfs(grid, 0, 0, h - 1, w - 1, h, w)
if r == -1:
    print(r)
else:
    white = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '.':
                white += 1
    print(white - r)

Measured memory_bytes: 40816
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
}
int n,b[N];
struct line
{
	int l,r;
	bool operator < (const line &s)const
	{
		return l==s.l?r<s.r:l<s.l;
	}
}e[N];
int m;
void input()
{
	n=read<int>();
	For(i,1,n)b[i]=read<int>();
	m=read<int>();
	For(i,1,m)e[i].l=read<int>(),e[i].r=read<int>();
}
int sum0[N],sum1[N];
struct Tree
{
	int Max[N<<2];
	#define mid ((l+r)>>1)
	#define lson h<<1,l,mid
	#define rson h<<1|1,mid+1,r
	void build(int h,int l,int r)
	{
		Max[h]=-n;
		if(l==r)return;
		build(lson),build(rson);
	}
	void update(int h,int l,int r,int pos,int v)
	{
		if(l==r)Max[h]=v;
		else
		{
			pos<=mid?update(lson,pos,v):update(rson,pos,v);
			Max[h]=max(Max[h<<1],Max[h<<1|1]);
		}
	}
	int query(int h,int l,int r,int s,int t)
	{
		if(s<=l&&r<=t)return Max[h];
		int res=-n;
		if(s<=mid)cmax(res,query(lson,s,t));
		if(mid<t)cmax(res,query(rson,s,t));
		return res;
	}
}s[2];
int dp[N];
void work()
{
	For(i,1,n)dp[i]=-n;
	For(i,1,n)
	{
		sum0[i]=sum0[i-1]+(b[i]==0);
		sum1[i]=sum1[i-1]+(b[i]==1);
	}
	sort(e+1,e+m+1);
	s[0].build(1,0,n),s[1].build(1,0,n);
	s[0].update(1,0,n,0,0);
	s[1].update(1,0,n,0,0);
	int l,r;
	For(i,1,m)
	{
		//cout<<e[i].l<<' '<<e[i].r<<endl;
		l=e[i].l,r=e[i].r;
		cmax(dp[r],s[0].query(1,0,n,0,l-1)+sum0[l-1]+sum1[r]-sum1[l-1]);
		cmax(dp[r],s[1].query(1,0,n,l-1,r-1)+sum1[r]);
		
		s[0].update(1,0,n,r,dp[r]-sum0[r]);
		s[1].update(1,0,n,r,dp[r]-sum1[r]);
		//cout<<r<<' '<<dp[r]<<endl<<endl;
	}
	int ans=0;
	For(i,0,n)cmax(ans,dp[i]+sum0[n]-sum0[i]);
	write(n-ans,'\n');
}
int main()
{
	
	input();
	work();
	return 0;
}



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

int main() {
	long X,K,D;
	cin >> X >> K >> D;
	X = abs(X);
	long a = X % D;
	long ans;

	long n = K - ((X - a) / D);

	if(n<0) ans = X - (K * D);
	else {
		if (n % 2 == 0) ans = a;
		else ans = a - D;
	}
	cout << abs(ans) << endl;
	
	

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N); 
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  long long ans = 0;
  for(int i = 1; i < N; i++){
    if(A.at(i) <= A.at(i - 1)){    
    ans += (A.at(i - 1) - A.at(i));
    A.at(i) = A.at(i - 1);
    }
    else continue;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3992
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
res = set()
a = ord("a")
mx = lambda x: max(list(map(ord, x))) - a
def dfs(s):
  if len(s) == N:
    res.add("".join(s))
    return
  for k in range(mx(s) + 2): dfs(s + [chr(k + a)])
dfs(["a"])
for r in sorted(res): print(r)

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

int main()
{
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  int reverse = 0;
  rep(i, s.length()-1){
    if(s[i] != s[i+1]) ++reverse;
  }
  
  cout << (n -1) - max(0, (reverse - 2 * k)) << endl;
  
  return 0;
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 100050;

int n, sz[maxn];
pair<ll,int> d[maxn];
struct edge{int u, v;}e[maxn];

int main()
{
	// fp("1.in","r",stdin);
	// fp("2.out","w",stdout);
	sf("%d",&n);
	fo(i,1,n) sf("%lld",&d[i].fi), d[i].se = i;
	sort(d+1, d+n+1);
	fd(i,n,2)
	{
		sz[i] ++;
		int l = 1, r = i-1, mid, p = -1;
		while(l <= r)
		{
			mid = (l + r) >> 1;
			if(d[mid].fi <= d[i].fi-n+2*sz[i]) p = mid, l = mid + 1;
			else r = mid - 1;
		}
		if(p == -1 || d[p].fi != d[i].fi-n+2*sz[i]) 
			return 0 * pf("-1\n");
		sz[p] += sz[i];
		e[i].u = d[p].se; e[i].v = d[i].se;
	}
	sz[1] ++;
	ll ans = 0;
	fo(i,1,n) ans += sz[i] * (ll)(n - sz[i]);
	ans <<= 1;
	fo(i,1,n) ans -= d[i].fi;
	if(ans != 0) return 0 * pf("-1\n");
	fo(i,2,n) pf("%d %d\n",e[i].u,e[i].v);
	return 0;
}


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

#define MAX_N 50

// int N = 10;
// string S = "aabbbbaaca";

int N;
string S;
int ans = 0;

int main() {
    cin >> N >> S;
    stack<char> sta;

    rep(i, N) {
        if (sta.size() > 0) {
            if (S[i] == sta.top()) {
                continue;
            }
        }
        sta.push(S[i]);
    }

    int calc = sta.size();
    // rep(i, calc) {
    //     // cout << i;
    //     printf("%c", sta.top()); 
    //     sta.pop();
    // }
    cout << calc << endl;
}

Measured memory_bytes: 512
S[1<<20],Q[1<<20],q;b,u,x,i,n;main(c){for(;read(0,&c,1);)if(c-10)b=b*4+c%3+1,u=u*4+1;else{for(S[q=b]=0;b%u;b=Q[b])for(x=b^b/4,i=0;x>3;i+=2,x/=4)(n=x&3)&&!Q[n=b&~(15<<i)^n*5<<i]?S[q=Q[q]=n]=S[b]+1:0;b-1?b?printf("%d\n",S[b]):puts("NA"):0;memset(Q,b=u=0,4<<20);}}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7

int main() {
    int N, sum = 0;
    cin >> N;
    vector<int> d(N);
    rep(i, N) cin >> d[i];

    rep(i, N - 1) {
        REP(j, i + 1, N) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


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

int main(){
    char x,y;
    cin>>x>>y;
    if(x>y) cout<<">"<<endl;
    else if(x<y) cout<<"<"<<endl;
    else cout<<"="<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int a[200000];
int b[200001];

int main() {
    int n, k, i, j;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < min(k, 100); i++) {
        for (j = 0; j < n; j++) {
            b[max(j - a[j], 0)]++;
            b[min(j + a[j] + 1, n)]--;
        }
        
        for (j = 1; j < n; j++) b[j] += b[j - 1];
        
        for (j = 0; j < n; j++) {
            a[j] = b[j];
            b[j] = 0;
        }
    }
    
    for (j = 0; j < n; j++) {
        if (j > 0) putchar(' ');
        printf("%d", a[j]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
struct BIT {
private:
	vector<ll> node; int n;
public:
	void init(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

int main()
{
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	
	BIT bitTree[26];
	REP(i, 26) {
		bitTree[i].init(N);
	}
	REP(i, N) {
		int strOne = S[i] - 'a';
		bitTree[strOne].add(i, 1);
	}

	REP(i, Q) {
		int q;
		cin >> q;
		if (q == 1) {
			int l;
			char r;
			cin >> l >> r;
			l--;;

			int strOne = S[l] - 'a';
			bitTree[strOne].add(l, -1);
			strOne = r - 'a';
			bitTree[strOne].add(l, 1);
			S[l] = r;
		} else {
			int l, r;
			cin >> l >> r;
			l--; r--;

			int ansOne = 0;
			REP(j, 26) {
				ll lPos = bitTree[j].sum(l);
				ll rPos = bitTree[j].sum(r + 1);
				if (lPos != rPos) {
					ansOne++;
				}
			}

			cout << ansOne << endl;
		}
	}

	return 0;
}


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

int main(){
    int n,m,all=0,count=0;
    cin >>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin >>a[i];
        all+=a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]*4*m-all>=0){count++;}
    }
    if(count>=m){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256