akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
	int card[202];
	int i;
	int n;
	int x;
	int taro;
	int hana;
	int turn;
	int taro_num;
	int hana_num;

	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}

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

		for (i = 1; i <= n * 2; i++){
			if (card[i] != 1){
				card[i] = -1;
			}
		}
	/*
		for (i = 1; i <= n * 2; i++){
			printf("<%d>\n", card[i]);
		}
	*/
		turn = 1;
		taro_num = n;
		hana_num = n;
		
		while (taro_num != 0 && hana_num != 0){
			i = 1;
			while (card[i] != 0){
				if (card[i] != turn){
					i++;
				}
				else {
					card[i] = -2;
					if (turn == 1){
						taro_num--;
					}
					else {
						hana_num--;
					}
					if (taro_num == 0 || hana_num == 0){
						break;
					}
					i++;
					turn *= -1;
				}
			}
	/*
			for (i = 1; i <= n * 2; i++){
				printf("[%d]\n", card[i]);
			}
			printf("\n");
	*/
			turn *= -1;
		}

		taro = 0;
		hana = 0;
		for (i = 1; i <= n * 2; i++){
			if (card[i] == -1){
				taro++;
			}
			else if (card[i] == 1) {
				hana++;
			}
		}
		
		printf("%d\n", taro);
		printf("%d\n", hana);
	}
	return (0);
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[])throws Exception{
    Scanner sc = new Scanner (System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int count = 0;
        while(N-->0){
            long X = sc.nextLong();
            long Y = sc.nextLong();
            double dis = Math.sqrt(((long)X*X)+ ((long)Y*Y));
            if(dis<=D) count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 59300
#!/usr/bin/python3
#coding: utf-8

import sys

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        divisor = (4*h*n - N*h - N*n)
        if divisor <= 0:
            continue
        if (N*h*n) % divisor == 0:
            m = (N * h * n) // divisor
            print(h, n, m)
            sys.exit(0)


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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;cin >> N;
    map<string, int> mp;
    for(int i = 0;i < N;i++){
        string s;cin >> s;
        mp[s]++;
    }
    vector<pair<int, string>> v;
    for(auto a : mp)v.push_back(make_pair(a.second, a.first));
    sort(v.begin(), v.end());
    vector<string> s;
    for(int i = 0;i < v.size();i++){
        if(v[i].first == v.back().first)s.push_back(v[i].second);
    }
    sort(s.begin(),s.end());;
    for(int i = 0;i < s.size();i++){
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 32492
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<string>
using namespace std;


int main() {
	int C[9];

	for (int i = 0; i < 9; i++) {
		cin >> C[i];
	}

	if ((C[4] + C[0] == C[1] + C[3]) && (C[7] + C[0] == C[6] + C[1]) && (C[5] + C[0] == C[2] + C[3]) && (C[0] + C[8] == C[2] + C[6])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(void){
  int a, b, k;
  cin >> a >> b >> k;
  bool ad[101], bd[101];
  for(int i = 0; i <= 100; i++){
    ad[i] = false;
    bd[i] = false;
  }
  for(int i = 1; i <= a; i++) if(a % i == 0) ad[i] = true;
  for(int i = 1; i <= b; i++) if(b % i == 0) bd[i] = true;
  int ans = 0;
  int count = 0;
  for(int i = min(a, b); i >= 1; i--){
    if(ad[i] && bd[i]) count++;
    if(count == k) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i,j,k,n[5];
	scanf("%d",&n[0]);
	for(i=1;i<5;i++)
	{
		k=i;
		scanf("%d",&j);
		while(n[--k]<j&&k>=0)
			n[k+1]=n[k];
		n[k+1]=j;
	}
	for(i=0;i<5;i++)
		printf("%d%c",n[i],i+1==5?'\n':' ');
	return 0;
}

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

int main()
{
    int n,c;
    cin >> n >> c;
    int k[3][c] ;
    int d[c][c] ;
    int t;
   
    for(int i = 0;i<c;i++){
        for(int j = 0;j<c;j++){
            cin >> d[i][j];
        }
    }
    for(int i = 0;i<3;i++){
        for(int j = 0;j<c;j++){
            k[i][j] = 0;
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            
            cin >> t;
             k[(j+i)%3][t-1]++ ;
        }
    }
    
        
    int ans = 0;
    int t0;
    
    t0 = -1;
    for(int j0 = 0; j0<c;j0++){
        for(int j1 = 0; j1<c;j1++){
            if(j1!=j0){
            for(int j2 = 0; j2<c;j2++){
                if(j2!=j0 && j2!=j1){

                t = 0;
                for(int j = 0;j<c;j++){
                t += k[0][j]*d[j][j0];
                
            }
            for(int j = 0;j<c;j++){
                t += k[1][j]*d[j][j1];
                
            }
            for(int j = 0;j<c;j++){
                t += k[2][j]*d[j][j2];
                
            }
            if(t0 == -1 || t<t0){
                t0 = t;
                 
            }
            }
            }
            }
        }
    }
    cout <<t0;
    
    
    return 0;

}

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

int main(){
    int c=0;
    string s;
    cin >> s;

    char k=s[0];
    for(int i =1; s[i]!='\0'; i++){
        if(k==s[i]){ 
          c++;
        }
        k=='0' ? k='1' : k='0';
    }
    printf("%d\n",c);
    return 0;
}





Measured memory_bytes: 512
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    vector<P> v(M);
    rep(i, M) {
        ll B, C;
        cin >> B >> C;
        v[i] = make_pair(B,C);
    }
    sort(all(v), pairCompareS);
    ll sum = 0;
    rep(i, M) {
        rep(j, v[i].first) {
            if (sum >= N) break;
            if (A[sum] < v[i].second) {
                A[sum] = v[i].second;
            }
            sum++;
        }
    }
    ll ans = 0;
    rep(i, N) {
        ans += A[i];
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2560
n=int(input())
s=input()
a=list("abcdefghijklmnopqrstuvwxyz")
x=[]
y=[]
m=0
for i in range(n-1):
    x=[s[j] for j in range(i)]
    y=[s[j] for j in range(i,n)]
    ans=0
    for j in range(26):
        if a[j] in x and a[j] in y:
            ans+=1
    m=max(ans,m)
print(m)


Measured memory_bytes: 9128
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int k = sc.nextInt();
		String s = sc.next();
		
		if(s.length() > k) {
			System.out.println(s.substring(0,k)+"...");
		}else {
			System.out.println(s);
		}
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25340
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    cin.tie(0);
    int n,k,a;
    cin >> n >> k;

    a = -n+1;
    for(int i=0;i<n-a; i++){
        cout << k+a+i << " ";
    }
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
root_N = int(math.sqrt(N))
FLAG = False

for i in range(2, root_N + 1):
    rev = root_N - i + 2

    if (N%rev == 0):
        FLAG = True
        break

if (FLAG):
    answer = int(N/rev) + rev - 2
else:
    answer = N - 1

print(answer)

Measured memory_bytes: 3060
# 根節点、左部分木、右部分木の順で節点の番号を出力する。これを木の先行順巡回 (preorder tree walk) と呼びます。
# 左部分木、根節点、右部分木の順で節点の番号を出力する。これを木の中間順巡回 (inorder tree walk) と呼びます。
# 左部分木、右部分木、根節点の順で節点の番号を出力する。これを木の後行順巡回 (postorder tree walk) と呼びます。

n = gets.to_i

# rubyにも構造体（というクラス）があるらしいので使ってみる
Node = Struct.new(:id, :left, :right, :parent)
# Array.new(n, Node.new)だと同じ構造体を参照してしまうので
nodes = Array.new(n).map{Node.new}
n.times do
  data = gets.chomp.split.map(&:to_i)
  node = Node.new(*data)
  node.parent = nodes[data[0]].parent
  nodes[data[0]] = node
  nodes[data[1]].parent = node.id if data[1] != -1
  nodes[data[2]].parent = node.id if data[2] != -1
end

def preorder(par, nodes, order)
  # 中間 左 右
  # 中間から子を探索して存在するやつをたどっていく
  order << par
  if nodes[par].left != -1
    preorder(nodes[par].left, nodes, order)
  end
  if nodes[par].right != -1
    preorder(nodes[par].right, nodes, order)
  end
end

def inorder(par, nodes, order)
  if nodes[par].left > -1
    inorder(nodes[par].left, nodes, order)
  end
  order << par
  if nodes[par].right > -1
    inorder(nodes[par].right, nodes, order)
  end
end

def postorder(par, nodes, order)
  if nodes[par].left > -1
    postorder(nodes[par].left, nodes, order)
  end
  if nodes[par].right > -1
    postorder(nodes[par].right, nodes, order)
  end
  order << par
end
# 根を同定
root = nodes.select{|nd| nd.parent.nil?}[0].id
# preoder
preoder_res = []
preorder(root, nodes, preoder_res)
puts "Preorder"
puts " #{preoder_res.map(&:to_s).join(' ')}"
# inorder
inorder_res = []
inorder(root, nodes, inorder_res)
# 2 1 3 0 6 5 7 4 8
puts "Inorder"
puts " #{inorder_res.map(&:to_s).join(' ')}"
# postorder
postorder_res = []
postorder(root, nodes, postorder_res)
#  2 3 1 6 7 5 8 4 0
puts "Postorder"
puts " #{postorder_res.map(&:to_s).join(' ')}"


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


int main() {
  int N;
  cin >>N;
    vector<int> X(N);
  for(int i=0;i<N;i++) cin >>X[i];
  int ans = 10000000;
  for(int i=-100;i<100;i++){
    int wa =0;
   for(int j=0;j<N;j++){
   wa += (X[j] - i) *(X[j] - i) ;
   }
    ans = min(ans , wa);
  }
    cout << ans <<endl;
 }

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val a = in.readLine.split(" ").map(_.toInt).sorted

  val p = a.last
  val d = a.init./:(Int.MaxValue, -1) {
    case ((min,r), i) => {
      val x = (i - (p-i)).abs
      if(x < min) (x, i)
      else (min, r)
    }
  }._2

  println(p + " " + d)
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
 string t;
  cin >> t;
  ll pt=0;
  map<int,char> check;
  rep(i,n){
    if(i<=k-1){
      if(t.at(i)=='r'){
        pt+=p;
        check[i]='r';
      }
      else if(t.at(i)=='s'){
        pt+=r;
        check[i]='s';
      }
      else if(t.at(i)=='p'){
        pt+=s;
        check[i]='p';
      }
    }
    else{
      int  m=i%k;
      if(t.at(i)=='r'){
        if(check.at(m)=='r'){
          check.at(m)='x';
        }
        else{
          pt+=p;
          check.at(m)='r';
        }
      }
      else if(t.at(i)=='s'){
        if(check.at(m)=='s'){
          check.at(m)='x';
        }
        else{
        pt+=r;
        check.at(m)='s';
        }
      }
      else if(t.at(i)=='p'){
        if(check.at(m)=='p'){
          check.at(m)='x';
        }
        else{
        pt+=s;
        check.at(m)='p';
        }
      }
    }
  }
      cout << pt << endl;
      
    
    

}

Measured memory_bytes: 4480
n,k=map(int,input().split())
dp=[0 for i in range(n+1)]
dp[1]=1
accum=[0 for i in range(n+1)]
accum[1]=1
s=[]
for i in range(k):
    x,y=map(int,input().split())
    s.append([x,y])
for i in range(2,n+1):
    for j in s:
        l,r=j
        tmpl=i-r
        tmpr=i-l
        if(tmpl<1):
            tmpl=1
        if(tmpr>=i):
            tmpr=i-1
        if(tmpr<0):
            continue
        dp[i]+=accum[tmpr]-accum[tmpl-1]
        dp[i]%=998244353
    accum[i]=dp[i]+accum[i-1]
    accum[i]%=998244353
print(dp[n]%998244353)

Measured memory_bytes: 100500
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n,a[100],ans=0;
      bool f=true;
      cin>>n;
      REP(i,n)cin>>a[i];
      while(f){
            f=false;
            for(int j=n-1;j>=0;j--){
                  if(a[j]<a[j-1]){
                        swap(a[j],a[j-1]);
                        f=true;
                        ans++;
                  }
            }
      }
      REP(i,n)printf("%d%c",a[i],i==n-1?'\n':' ');
      cout<<ans<<endl;
}

Measured memory_bytes: 1192
n = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
v.append(0)

# forward
now = 0
for i in range(n):
    if now + t[i] < v[i]:
        v[i] = now + t[i]

    if v[i] <= v[i+1]:
        now = v[i]
    elif t[i] + v[i+1] + now < 2 * v[i]:
        v[i] = (t[i] + v[i+1] + now) / 2
        now = v[i+1]
    else:
        now = v[i+1]

# back
now = 0
for i in range(n-1, -1, -1):
    if now + t[i] < v[i]:
        v[i] = now + t[i]

    if v[i] <= v[i-1]:
        now = v[i]
    elif t[i] + v[i-1] + now < 2 * v[i]:
        v[i] = (t[i] + v[i-1] + now) / 2
        now = v[i-1]
    else:
        now = v[i-1]

ans = 0
now = 0
for i in range(n):
    t1 = v[i] - now
    t3 = v[i] - v[i+1]
    # t2 = t[i] - t1 - t3

    ans += now * t1 + t1 * t1 / 2
    now = v[i] # now += t1

    ans += now * (t[i] - t1 - t3) # ans += now * t2
    # now = now

    ans += now * t3 - t3 * t3 / 2
    now -= t3

print(ans)

Measured memory_bytes: 9248
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  vector<string> s(3);
  rep(i, 3) {
    cin >> s[i];
    reverse(ALL(s[i]));
  }

  char t = 0;
  while (true) {
    if (s[t].empty()) {
      printf("%c\n", char('A' + t));
      return 0;
    }
    char next = s[t].back() - 'a';
    s[t].pop_back();
    t = next;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
     int x1,x2;
     cin>>x1>>x2;
     if(x1<x2){cout<<x2-x1<<endl;}
     else if (x1>x2){cout<<x1-x2<<endl;}
     else if (x1==x2){cout<<"0"<<endl;}
    
     
    
}



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

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

    vector<int> a(3*N);
    for(int i = 0; i < 3*N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long sum = 0;
    for(int i = N; i < 3*N; i += 2) {
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4588
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

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

        System.out.println(solve(W, H, x, y, a));

        sc.close();
    }

    static int solve(int W, int H, int[] x, int[] y, int[] a) {
        boolean[][] grid = new boolean[H][W];
        for (int i = 0; i < x.length; ++i) {
            if (a[i] == 1) {
                for (int r = 0; r < H; ++r) {
                    for (int c = 0; c < x[i]; ++c) {
                        grid[r][c] = true;
                    }
                }
            } else if (a[i] == 2) {
                for (int r = 0; r < H; ++r) {
                    for (int c = x[i]; c < W; ++c) {
                        grid[r][c] = true;
                    }
                }
            } else if (a[i] == 3) {
                for (int r = 0; r < y[i]; ++r) {
                    for (int c = 0; c < W; ++c) {
                        grid[r][c] = true;
                    }
                }
            } else {
                for (int r = y[i]; r < H; ++r) {
                    for (int c = 0; c < W; ++c) {
                        grid[r][c] = true;
                    }
                }
            }
        }

        return Arrays.stream(grid).mapToInt(line -> (int) IntStream.range(0, W).filter(c -> !line[c]).count()).sum();
    }
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u64 n;
  cin >> n;
  unordered_multiset<u64> a;

  rep(i, n) {
    u64 ai;
    cin >> ai;
    a.emplace(ai);
  }

  for (auto &ai : a) {
    if (a.count(ai) > 1) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 11412
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    string N;
    cin >> N;
    int a = 0;
    for(char c: N){
        int temp = c - '0';
        a += temp;
    }

    if(a % 9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main () {
  stack<int> down;
  stack<pair<int, int>> s;
  char c;
  int x = 0;
  while(cin >> c) {
    x++;
    if(c == '\\') {
      down.push(x);
    } else if(c == '/' && !down.empty()) {
      int px = down.top(); down.pop();
      int a = x - px;
      while(!s.empty() && s.top().second > px) {
        a += s.top().first;
        s.pop();
      }
      s.push(pair<int,int>(a, x));
    }
  }

  int A = 0;
  vector<int> L(s.size());
  rep(i,L.size()) {
    int a = s.top().first;
    L[L.size() - 1 - i] = a;
    A += a;
    s.pop();
  }

  cout << A << endl;
  cout << L.size();
  rep(i,L.size()) cout << " " << L[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 3188
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
    int n;
    cin>>n;
    VI a(n-1);
    rep(i,n-1) cin>>a[i];
 
    ll sum=0;
    rep(i,n-2){
      sum+=min(a[i],a[i+1]);
    }
    sum+=a[0]+a[n-2];
    cout<<sum<<endl;
}



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

int main() {
  string s,t;
  cin >> s >> t;
  int ans = 1001;
  for (int i = 0; i <= s.size()-t.size(); i++)
  {
    int a = 0;
    for (int j = 0; j < t.size(); j++)
    {
      
      if (s.at(i+j) != t.at(j))
      {
        a++;
      }
      
    }
    ans = min(ans,a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;cin>>s;int a[26];memset(a,0,sizeof a);int cnt=0;
	for(int i=0;i<4;i++)
	{
		a[s[i]-'A']++;
		if(a[s[i]-'A']==2)
		{
			cnt++;
		}
	}	
	if(cnt==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
 } 

Measured memory_bytes: 256
n, m = map(int, input().split())
li = list(range(n))

l = []
for i in range(2**len(li)):
    x = [0]*n
    for j in range(len(li)):
        if i >> j & 1:
            x[j] = 1
    l.append(x)

s = []
for i in range(m):
  a = [int(i)-1 for i in input().split()]
  s.append(a[1:])
  
p = [int(i) for i in input().split()]

ans = 0
for i in l:
  b = 0
  for j in range(len(s)):
    a = 0
    for k in range(len(s[j])):
      if i[s[j][k]] == 1:
        a += 1
    if a%2 == p[j]:
      b += 1
  if m == b:
    ans += 1
    
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
using namespace std;

double dp[3001][3001];

double solve(vector<double>& arr,int i, int x){
    //Base Cases 
    if(x==0)
        return 1;
    if(i==0)
        return 0;
        
    if(dp[i][x]>-0.9)
        return dp[i][x];
        
    return dp[i][x] = arr[i]*solve(arr,i-1,x-1) + (1-arr[i])*solve(arr,i-1,x);
}

int main() {
	// your code goes here
	int n ;
	cin>>n;
	
	vector<double> arr(n+1);
	
	for(int i=1;i<=n;i++){
	    cin>>arr[i];
	}
	memset(dp,-1,sizeof(dp));
	prDouble(solve(arr,n,(n+1)/2));
	
	return 0;
}


Measured memory_bytes: 74368
#include <iostream>

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a < b){
        if (b < c){
            cout << a << " " << b << " " << c << endl;
        }
        else{
            if(a < c){
                cout << a << " " << c << " " << b << endl;
            }
            else{
                cout << c << " " << a << " " << b << endl;
            }
        }
    }
    else{
        if(a > c){
            if(b > c){
                cout << c << " " << b << " " << a << endl;
            }
            else{
                cout << b << " " << c << " " << a << endl;
            }
        }
        else{
            cout << b << " " << a << " " << c << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };

int main() {
    int n, height, idx;
    cin >> n;
    vi x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];
    rep(i, n) {
        if(h[i] != 0) {
            idx = i;
        }
    }
    rep(cx, 101) rep(cy, 101) {
        height = abs(cx - x[idx]) + abs(cy - y[idx]) + h[idx];
        rep(i, n) {
            if(h[i] != max(height - abs(x[i] - cx) - abs(y[i] - cy), 0)) {
                break;
            }
            if(i == n - 1) {
                cout << cx << " " << cy << " " << height << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e6;
const long long mod = 1e9 + 7;
int n, a[25][25];
long long mem[25][N];
bool vis[25][N];

long long dp(int idx, int bm) {
	if (bm == 0) {
		return 1;
	}
	if (idx == n) {
		return 0;
	}
	if (vis[idx][bm]) {
		return mem[idx][bm];
	}
	vis[idx][bm] = true;

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (!(bm & (1 << i)) || !a[idx][i]) continue;
		ans = (ans + dp(idx + 1, bm & ~(1 << i))) % mod;
	}

	return mem[idx][bm] = ans;
}

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

	cin >> n;

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

	cout << dp(0, (1 << n) - 1) << '\n';

	return 0;
}


Measured memory_bytes: 385280
data = input().split()
 
flag1 = 0
flag2 = 0
 
for i in range(3):
  if data[i] == '5':
    flag1 += 1
  elif data[i] == '7':
    flag2 += 1
 
if flag1 == 2 and flag2 == 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int numa[100010],numb[100010];
int n;
struct node
{
    int num,val;	
}a[100010],b[100010];
inline bool cmp(node a,node b){
	return a.num>b.num;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
    	int x;
    	scanf("%d",&x);
    	if(i&1)numa[x]++;
    	else numb[x]++;
    }
    for(int i=1;i<=100000;++i){
    	a[i].val=i;a[i].num=numa[i];
        b[i].val=i;b[i].num=numb[i];
    }
    sort(a+1,a+100000+1,cmp);
    sort(b+1,b+100000+1,cmp);
    int ans=0;
    if(a[1].val!=b[1].val)ans=n-a[1].num-b[1].num;
    else {
    	if(a[1].num>b[1].num)ans=n-a[1].num-b[2].num;
    	else if(a[1].num<b[1].num)ans=n-a[2].num-b[1].num;
    	else if(a[1].num==b[1].num)ans=n-a[1].num-max(b[2].num,a[2].num);
    }
    cout<<ans;
    return 0;

}

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

int main() {
  ll p,q,r,ans;
  cin >> p >> q >> r;
  vector<ll>d={p+q,q+r,r+p};
  ans=*min_element(d.begin(),d.end());
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
    
            // 入力値の受け取り
        Scanner sc = new Scanner(System.in);

        // 窓の長さ
        int A = sc.nextInt();

        // カーテンの長さ
        int B = sc.nextInt();

        int C = A - B * 2;

        if (C >= 1) {
            System.out.println(C);

        } else {
            System.out.println("0");
        }
    
    
    
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
using namespace std;
const long d = 1000000007;

int main()
{
  long n;
  cin >> n;
  long ans = 1;
  for (int i = 1; i <= n; i++)
  {
    ans *= i;
    ans %= d;
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
	int trans[27]={};
	string s,t;cin>>s>>t;
	for(int i=0;i<s.length();i++){
		int cs=s[i]-'a',ct=t[i]-'a';
		if(trans[cs]){
			if(trans[cs]!=ct){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else trans[cs]=ct;
	}
	int trans2[27]={};
	for(int i=0;i<s.length();i++){
		int cs=t[i]-'a',ct=s[i]-'a';
		if(trans2[cs]){
			if(trans2[cs]!=ct){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else trans2[cs]=ct;
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 3e3+5;
const int mod = 2019;

string s;
int cur, ans, x, base, n;
int f[maxn], pot[200005];

int main() {
    fastIO();
    cin >> s;
    n = len(s);

    pot[n-1] = 1;
    for (int i = n-2; i >= 0; --i) pot[i] = (pot[i+1] * 10) % mod;

    f[0] = 1;
    for (int i = 0; i < n; ++i) {
    	cur = (cur + pot[i] * (s[i]-'0')) % mod;
    	ans += f[cur];
    	++f[cur];
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4560
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)





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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

int digitlen(int i){
    int t = i;
    int count = 0;
    while(t){
        count += 1;
        t /= 10;
    }
    return count;
}

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

    int n;
    cin >> n;
    int ans = 100;
    rep(i,1,(int)sqrt(n)+1){
        if(n%i == 0){
            ans = min(ans, digitlen(n/i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define DIGIT_MAX 100
#define K_MAX 3
#define BUF_SIZE (DIGIT_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int main(void) {
    char nstr[BUF_SIZE];
    get_str(nstr, BUF_SIZE);
    int len = strlen(nstr)-1;
    int count = get_int();
    static uint64_t dp[DIGIT_MAX+1][10][K_MAX+1];
    static uint64_t map[K_MAX+1];

    // dp[1]
    int i;
    for(i = 0; i <= 9; i++) {
        dp[1][i][i!=0] = 1;
    }

    int d, k;
    for(d = 2; d <=len; d++) {
        memset(map, 0, sizeof(uint64_t)*(K_MAX+1));
        for(i = 0; i <= 9; i++) {
            for(k = 0; k <= count; k++) {
                map[k] += dp[d-1][i][k];
            }
        }
#ifdef DEBUG
        for(k = 0; k <= count; k++) {
            printf("%llu ", map[k]);
        }
        putchar('\n');
#endif
        for(i = 0; i <= 9; i++) {
            for(k = 0; k <= count; k++) {
                if(!i) {
                    dp[d][i][k] = map[k];
                } else {
                    if(k>=1) dp[d][i][k] = map[k-1];
                }
            }
        }
    }

    uint64_t res = 0;
    int c = count;
    for(d = len; d >= 1; d--) {
        int ch = nstr[len-d] - '0';
        for(i = 0; i < ch; i++) {
            res += dp[d][i][c];
        }
        if(ch!=0) c--;
#ifdef DEBUG
        printf("[%d] -> count: %d, %llu\n",ch, c, res);
#endif
        // all numbers are 0 below $d digit
        if(c==0) { res++; break; }
    }
    printf("%llu\n", res);
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <list>
#include <set>
using namespace std;

#define INF 99999999
bool prime[10000001];
bool like[10000001] = {};
int liken[10000002] = {};
int main() {
	fill(prime, prime + 10000001, true);
	prime[0] = prime[1] = false;
	vector<int> prime_n;
	for (int i = 2; i < 10000001; i++) {
		if (prime[i] == true) {
			prime_n.push_back(i);
			for (int j = 2; i * j < 10000001; j++) {
				prime[i * j] = false;
			}
		}
	}
	for (int i = 0; i < prime_n.size(); i++) {
		if (prime[(prime_n[i] + 1) / 2]) {
			like[prime_n[i]] = true;
			//cout << prime_n[i] << " " << (prime_n[i] + 1) / 2 << endl;
		}
	}
	for (int i = 1; i < 10000002; i++) {
		liken[i] += liken[i-1] + (int)like[i - 1];
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int a, b;
		cin >> a >> b;
		cout << liken[b + 1] - liken[a - 1] << endl;
	}

}

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

bool ada(int x)
{
	while (x>0)
	{
		if (x%10==9)
		 return true;
		x/=10;
	}
	return false;
}

int main()
{
	int x;
	cin>>x;
	//cout<<x<<"\n";
	cout<<(ada(x) ? "Yes" : "No")<<"\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
  int N,K;
  char S[11];
  scanf("%d",&N);
  scanf("%s",S);
  scanf("%d",&K);
  int i; /* index */
  for (i = 0;i < N;++i) {
    if(S[K - 1] != S[i]) {
      S[i] = '*';
    }
  }
  printf("%s\n", S);
  return 0;
}

Measured memory_bytes: 128
N,K=map(int,input().split())
A=list(map(int,input().split()))
One=[0]*40
OneK=format(K, '040b')
flg=True
for i in range(40):
  for j in range(N):
    if A[j]==0:
      continue
    flg=False
    One[39-i]+=A[j]&1
    A[j]=A[j]>>1
  if flg:
    break
  flg=True
ans=0
i=0
while i<40:
  if OneK[i]=='1':
    break
  ans+=pow(2,39-i)*One[i]
  i+=1
while i<40:
  if One[i]>=N/2:
    ans+=pow(2,39-i)*One[i]
    if OneK[i]=='1':
      i+=1
      break
  elif OneK[i]=='1':
    ans+=pow(2,39-i)*(N-One[i])
  else:
    ans+=pow(2,39-i)*One[i]
  i+=1
while i<40:
  ans+=pow(2,39-i)*max(One[i],(N-One[i]))
  i+=1
print(ans)



Measured memory_bytes: 14368
import math

def Dxy_p(X,Y,n,p):
    ret=0
    for i in range(n):
        ret += pow(abs(X[i]-Y[i]), p)
    return pow(ret, 1/p)

def Dxy_inf(X,Y,n):
    ret=0
    for i in range(n):
        ret = max(ret, abs(X[i]-Y[i]))
    return ret

n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

print(f"{Dxy_p(X,Y,n,1):.6f}")
print(f"{Dxy_p(X,Y,n,2):.6f}")
print(f"{Dxy_p(X,Y,n,3):.6f}")
print(f"{Dxy_inf(X,Y,n):.6f}")



Measured memory_bytes: 5712
from collections import deque

INFTY = 1e9 + 1


def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


n, a, cnt = int(input()), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print(*a)
print(cnt)

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  freopen("gout.txt", "w", stdout);
 
#endif
}
void solve()
{
  int n,cn=0,d;
  cin >> n >> d;
  
  forf(i,0,n)
  {
    int x,y;
    cin >> x >> y;
    if(x*x+y*y <= d*d) cn++;
  }

  cout<<cn<<"\n";

}
 
 
int32_t main()
{
  pr_init();
  fastio;
 
  auto start = high_resolution_clock::now();
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  // cout << "Time taken by function: "
  //       << duration.count() << " microseconds" << endl;
 
}
 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int h, w;
    cin >> h >> w;
    vvll dp(10, vll(10, (1LL << 50)));
    rep(i, 10) rep(j, 10) cin >> dp[i][j];
    rep(k, 10) rep(i, 10) rep(j, 10)
    {
        chmin(dp[i][j], dp[i][k] + dp[k][j]);
    }

    ll ans = 0;
    rep(y, h) rep(x, w)
    {
        int k;
        cin >> k;
        if (k < 0)
            continue;

        ans += dp[k][1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm> 
#include<cmath>
#include<iostream>
#include<cstring>
#include<cstdlib> 
#define ll long long
#define N 200005
using namespace std;
int n;
ll as,sum,a[N],ans=1e18;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i) 
	{
		ll x;
		cin>>x;
		x-=i;
		a[i]=x;
		sum+=x;
	}
	sort(a+1,a+1+n);
	ll k;
	if(n&1)
	k=a[(n+1)/2];
	else
	k=(a[n/2]+a[n/2+1])/2; 
	for(int i=1;i<=n;++i)
	{
	//	cout<<a[i]<<" ";
		as+=abs(a[i]-k);
	}
	ans=min(ans,as);
//	if(tmp>=0) k=(int)(tmp+0.5);
//	else k=(int)(tmp-0.5);
//	cout<<k<<endl; 
	k++;
	as=0;
	for(int i=1;i<=n;++i)
	{
	//	cout<<a[i]<<" ";
		as+=abs(a[i]-k);
	}
	ans=min(ans,as);
	k-=2;
	as=0;
	for(int i=1;i<=n;++i)
	{
	//	cout<<a[i]<<" ";
		as+=abs(a[i]-k);
	}
	cout<<min(ans,as);
	return 0;
 } 

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>
#include <queue>
#include <bitset>
#include <math.h>

int main(){

  ll N;
  cin >> N;

  if(N%2==0){
    ll N_2 = N/2;
    ll n_5 = 0;
    ll n_2 = 0;

    ll i = 1;
    ll div = 2*5;
    while(N>=div){
      n_5 += N/div;
      div *= 5;
    }


    cout << n_5;
  }else{
    cout << 0;
  }

  return 0;

}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int MAX = 20;
int N, M;
int k[MAX], s[MAX][MAX], p[MAX];

bool isOn(int v, int sw) {
    int count = 0;
    rep(i, k[v]) {
        if ((sw >> s[v][i]) & 1) {
            count += 1;
        }
    }
    // printf("valve: %d sw: %d count: %d, p: %d\n", v, sw, count, p[v]);
    if (count % 2 == p[v]) return true;
    return false;
}

int main(int argc, const char * argv[]) {
    cin >> N >> M;
    rep(i, M) {
        k[i] = inputValue();
        rep(j, k[i]) {
            s[i][j] = inputValue() - 1;
        }
    }

    inputArray(p, M);

    int ans = 0;
    rep(sw, 1 << N) {
        bool ok = true;
        rep(m, M) {
            if (!isOn(m, sw)) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans += 1;
        }
    }
    output(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=((ans%mod)*(x%mod))%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
int main()
{
fast_io
li i;
string s;
cin>>s;
li q;
cin>>q;
li flag=1;
deque<char>d;
for(i=0;i<s.length();i++)
d.push_back(s[i]);
while(q--)
{
  li x;
  cin>>x;
  if(x==1)
  {
    flag=1-flag;
  }
  else
  {
    li y;
    char p;
    cin>>y>>p;
    if(flag==0)
    y=3-y;
    if(y==1)
    {
      d.push_front(p);
    }
    else
    d.push_back(p);
  }
}
if(!flag)
{
  for(i=d.size()-1;i>=0;i--)
  cout<<d[i];
}
else
{
  for(i=0;i<d.size();i++)
  cout<<d[i];
}
  return  0;
}


Measured memory_bytes: 976
#!/usr/bin/env python3
import sys

def solve(N: int, A: "List[int]"):
    A.append(0)
    answer = 0
    for i in range(N):
        answer += A[i]//2
        A[i] %= 2
        if A[i] > 0 and A[i+1] > 0:
            A[i+1] -= 1
            answer += 1

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7072
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    vector<int> ans;
    set<int> s[26];
    rep(i, S.size())
        s[S[i] - 'a'].insert(i);
    //abcdbbd
    //alp['a'] = {0}, alp['b'] = {1, 4, 5}, alp['c'] = {2}
    //alp['d'] = {3, 6}
    rep(j, Q) {
        int type; cin >> type;
        if(type == 1) {
            int i;
            char c;
            cin >> i >> c;
            --i;
            rep(k, 26) {
                if(s[k].find(i) != s[k].end()) {
                    s[k].erase(i);
                }
            }
            s[c - 'a'].insert(i);
            // i -> cに変換，ある区間の種類数を更新
        } else {
            int l, r;
            int cnt = 0;
            cin >> l >> r;
            rep(k, 26) {
                auto key = s[k].lower_bound(l - 1);
                if(key != s[k].end()) {
                    if(*key < r) {
                        ++cnt;
                    }
                }
            }
            ans.pb(cnt);
            //l -> rの文字の種類を表示
        }
    }

    for(int v : ans) {
        cout << v << endl;
    }
}


Measured memory_bytes: 24452
import sys

N,M,K=list(map(int,input().split()))

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)

Measured memory_bytes: 41340
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
A2 = [-a if a<0 else a for a in A]
N2 = len([a for a in A if a<0])

if N2 % 2 == 0:
    print(sum(A2))
else:
    print(sum(A2) - min(A2) * 2)

Measured memory_bytes: 14412