akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            int h = NextInt, w = NextInt;
            var input = Enumerable.Repeat(0, h).Select(_ => Line).ToArray();
            var s = Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Select(j => input[i][j] == '#' ? int.MinValue : 1).ToArray()).ToArray();
            var t = Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Select(j => input[i][j] == '#' ? int.MinValue : 1).ToArray()).ToArray();

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w - 1; j++)
                {
                    if (s[i][j + 1] != int.MinValue)
                    {
                        s[i][j + 1] = Math.Max(s[i][j + 1], s[i][j + 1] + s[i][j]);
                    }
                }
            }

            for (int i = 0; i < h; i++)
            {
                for (int j = w - 1; j > 0; j--)
                {
                    if (s[i][j - 1] != int.MinValue)
                    {
                        s[i][j - 1] = Math.Max(s[i][j - 1], s[i][j]);
                    }
                }
            }

            for (int j = 0; j < w; j++)
            {
                for (int i = 0; i < h - 1; i++)
                {
                    if (t[i + 1][j] != int.MinValue)
                    {
                        t[i + 1][j] = Math.Max(t[i + 1][j], t[i + 1][j] + t[i][j]);
                    }
                }
            }

            for (int j = 0; j < w; j++)
            {
                for (int i = h - 1; i > 0; i--)
                {
                    if (t[i - 1][j] != int.MinValue)
                    {
                        t[i - 1][j] = Math.Max(t[i - 1][j], t[i][j]);
                    }
                }
            }

            System.Console.WriteLine(Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Max(j => s[i][j] + t[i][j])).Max() - 1);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 76048
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
int n,x;
cin>>x>>n;
int a;
int ans=0;
int minval=INT_MAX;
int maxval=0;
map<int,int> mp;
for(int i=0;i<n;i++)
{   
	cin>>a;
	mp[a]+=1;
	/*if(maxval<a)
	   maxval=a;*/
}
for(int i=-101;i<=101;i++)
{
	if(mp.find(i)==mp.end())
	{
		int z=abs(x-i);
		if(z<minval)
		{
			minval=z;
			ans=i;
		}
	}
}
cout<<ans;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
    long long x,temp;
    long long sum=0;
    scanf("%lld",&x);
    temp=x/500;
    sum+=temp*1000;
    x=x-temp*500;
    temp=x/5;
    sum+=temp*5;
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 128
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int H = scan.nextInt();
		long[] arr = new long[N];
		long sum =0;
		for(int i=0;i<N;i++){
			arr[i] = scan.nextInt();
			sum+= arr[i];
		}
		if(H==0){
			System.out.println(sum);
		}else {
			if(H>=N){
							System.out.println(0);
			}
			else{
				long ans = 0;
				Arrays.sort(arr);
				for(int j=N-1-H;j>=0;j--){
					ans += arr[j];
				}
				System.out.println(ans);
			}
		}
		
}

}

Measured memory_bytes: 89180
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	int n;
	cin >> n;
	int d=sqrt(n);
	cout << d*d << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 8 //8×8のマス
#define FREE -1
#define NOT_FREE 1

int row[N];
int col[N];
int dpos[2*N-1],dneg[2*N-1]; /*dpos:左下方向 dneg:右下方向*/

int Z[N][N];

void Initialize(void); 
void PrintBoard(void);
void Recursive(int);

int main(){
  int i, j;
  int k, r, c;
  /*1行目に整数 k 、続く k 行にクイーンが配置されているマスが2つの整数 r, c で与えられます。r, c はそれぞれ0から始まるチェス盤の行と列の番号を表します。*/

  initialize();

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      Z[i][j] = -1;
    }
  }

  scanf("%d",&k);
  for(i = 0 ; i < k ; i++){
    scanf("%d %d",&r,&c);
    Z[r][c] = 1;
  }
  for(i = 0; i < 100; i++);
  Recursive(0);

  return 0;
}

void initialize(){
  int i;

  for(i = 0 ; i < N ; i++){
    row[i] = FREE;
    col[i] = FREE;
  }

  for(i = 0 ; i < 2 * N - 1 ; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void Recursive(int i){
  int j;

  if(i == N){ //クイーンの配置に成功
    PrintBoard();
    return;
  }

  for(j = 0 ; j < N ;j++){
    //(i,j)が他のクイーンに襲撃されている場合は無視
    if(col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i - j + N - 1] == NOT_FREE) continue;

    //(i,j)にクイーンを配置する
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + N -1] = NOT_FREE;

    //次の行を試す
    Recursive(i + 1);

    //(i,j)に配置されているクイーンを取り除く
    row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
  }
  	//クイーンの配置に失敗
}

void PrintBoard(){
  int i, j;

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(Z[i][j] == 1){
	if(row[i] != j) return;
      }
    }
  }

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2140
/*
1  insertionSort(A, n, g)
2      for i = g to n-1
3          v = A[i]
4          j = i - g
5          while j >= 0 && A[j] > v
6              A[j+g] = A[j]
7              j = j - g
8              cnt++
9          A[j+g] = v
10
11 shellSort(A, n)
12     cnt = 0
13     m = ?
14     G[] = {?, ?,..., ?}
15     for i = 0 to m-1
16         insertionSort(A, n, G[i])
*/
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<int> &A){
    for(int i=0;i<A.size();i++){
        cout << A.at(i);
        if(i == A.size()-1){
            cout << endl;
        }else{
            cout << ' ';
        }
    }
}

void insertionSort(vector<int> &A,int &cnt,int g){
    for(int i=g;i<A.size();i++){
        int v = A.at(i);
        int j = i-g;
        while(j >= 0 && A.at(j) > v){
            A.at(j+g) = A.at(j);
            j -= g;
            cnt++;
        }
        A.at(j+g) = v;
    }
}

void shellSort(vector<int> &A,int &cnt){
    int m = 0;
    vector<int> G;
    for(int i=1;i<=A.size();i = 3*i+1){
        m++;
        G.push_back(i);
    }
    reverse(all(G));

    cout << m << endl;
    print_vec(G);

    for(int i=0; i<G.size();i++){
        insertionSort(A,cnt,G.at(i));
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int cnt = 0;
    rep(i,N) cin >> A.at(i);
    shellSort(A,cnt);
    cout << cnt << endl;
    rep(i,N) cout << A.at(i) << endl;

}   


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


bool check(long long x) {
  bool ans = true;
  for (int i = 2; i < x; i++) {
    if (x % i == 0) {
      ans = false;
    }
  }
  if (ans) return true; //素数
  else return false;   //素数でない
}



 
int main() {
  long long x;
  cin >> x;
  while (!(check(x))) {
    x++;
  }
  cout << x << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    double h, w;
    cin >> h >> w;
    cout << (h * w) / 2 << " ";
    int x, y;
    cin >> x >> y;
    if(h / 2 == x && w / 2 == y)
        cout << 1;
    else
        cout << 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,k;
    string s;
    cin>>n>>s>>k;
    char c=s[k-1];
    for(int i=0;i<n;i++){
        if(s[i]==c){
            cout<<s[i];
        }
        else{
            cout<<"*";
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,K,count=0,check=0;
  cin>>N>>K;
  vector<ll> A(0);
  unordered_map<ll,ll> mp;
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    if(mp[a]==0){check++;A.push_back(a);}
    mp[a]++;
  }
  ll d=A.size();
  if(check<=K){cout<<0<<endl;return 0;}
  for(ll i=1;i<=N;i++){
    ll rock=0;
    for(ll j=0;j<d;j++){
      if(mp[A.at(j)]==i){count+=i;check--;}
      if(K>=check){rock=1;break;}
    }
    if(rock==1){break;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 10044
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val abc = Array(M) {
        val (a, b) = listOfInt()
        var c = 0
        listOfInt(-1).forEach { c = c or (1 shl it) }
        Pair(a, c)
    }
    val INF = 1111111111
    val B = (-1 shl N).inv()
    val dp = IntArray(B + 1) { INF }
    dp[0] = 0
    for (k in abc) {
        for (n in 0..B) {
            dp[n or k.second] = Math.min(dp[n or k.second], dp[n] + k.first)
        }
    }
    println(if (dp[B] != INF) dp[B] else -1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 42452
n, d = list(map(int, input().split()))

x = [list(map(int, input().split())) for _ in range(n)]

def is_square_num(n):
  i2 = 0
  for i in range(0, n + 1):
    if i2 == n:
      return True
    if i2 > n:
      return False
    i2 += i * 2 + 1

c = 0

for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2

        if is_square_num(dist):
            c += 1

print(c)

Measured memory_bytes: 63328
n,m=map(int,input().split())
k=[]
a=[]
for i in range(n):
  b=list(map(int,input().split()))
  k.append(b[0])
  a.append(b[1:])
d={}
for i in range(n):
  for j in range(k[i]):
    if a[i][j] not in d:
      d[a[i][j]]=1
    else:
      d[a[i][j]]+=1
nd=list(d.values())
cnt=0
for i in range(len(nd)):
  if nd[i]==n:
    cnt+=1
print(cnt)


Measured memory_bytes: 3064
import java.util.*;
import java.util.Queue;
import java.util.ArrayDeque;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        String S = sc.next();
        int l = S.length();
        char[] ch = S.toCharArray();
        int Q = sc.nextInt();
        int[] T = new int[Q];
        int reverse = 0;
        ArrayDeque<Character> deq = new ArrayDeque<Character>();

        for(int i=0; i<l; i++){
            deq.add(ch[i]);
        }

        int ad = 0;
        for(int i=0; i<Q; i++){
            T[i] = sc.nextInt();
            if(T[i]==1){
                reverse += 1;
            }
            else{
                ad += 1;
                int F = sc.nextInt();
                char C = sc.next().charAt(0);
                if((F==1 && reverse%2==0) || (F==2 && reverse%2!=0)){
                    deq.push(C);
                }
                else{
                    deq.add(C);
                }
            }
        }
        for(int i=0; i<l+ad; i++){
            if(reverse%2==0){
                System.out.print(deq.pop());
            }
            else{
                System.out.print(deq.removeLast());
            }
        }
        System.out.println("");
    }
}

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

#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;

using namespace std;

short a[100007];
short b[100007];
short c[100007];
long long arr[100007];
long long brr[100007];
long long crr[100007];

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	loop(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	arr[0] = a[0];
	brr[0] = b[0];
	crr[0] = c[0];
	for (int i = 1; i < n; ++i)
	{
		/* code */
		arr[i] = a[i] + max(brr[i - 1], crr[i - 1]);
		brr[i] = b[i] + max(arr[i - 1], crr[i - 1]);
		crr[i] = c[i] + max(arr[i - 1], brr[i - 1]);
	}

	cout << max({arr[n - 1], brr[n - 1], crr[n - 1]});

}

Measured memory_bytes: 6560
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

dice = Dice([int(n) for n in input().split()])
dice.move(input())
print(dice.nums[dice.top])

Measured memory_bytes: 7764
# input
N, D = map(int, input().split())
coordinate = []
for i in range(N):
    coordinate.append( list( map(int, input().split()) ) )

# processing
count = int(0)
for i in range(N):
    distance = ( (coordinate[i][0]) ** 2 + (coordinate[i][1]) ** 2 ) ** 0.5
    if distance <= D:
        count += 1
    else:
        continue

# output
print(count)

Measured memory_bytes: 45784
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i, x, y;
	cin >> num;
	vector<int> d(num), X(num - 1), Y(num - 1);
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	x = d[num - 1];
	y = d[0];
	i = 1;
	while (i < num - 1 && d[i] < 0) {
		X[i] = x;
		Y[i] = d[i];
		x -= d[i++];
	}
	while (i < num - 1) {
		X[i] = y;
		Y[i] = d[i];
		y -= d[i++];
	}
	printf("%d\n", x - y);
	for (i = 1; i < num - 1; i++)
		printf("%d %d\n", X[i], Y[i]);
	printf("%d %d\n", x, y);
	return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>
#define Nmax 1500
#define Mmax 1500
#define INF 1000000

int main (void){
    int N, M;
    int i,j;
    int h[Nmax]={},w[Mmax]={};
    int counth[INF], countw[INF];
    int tmp;
    int sum;
 
    while(1){
        //?????????
        for(i=0;i<Nmax;i++)
            h[i]=0;
        for(i=0;i<Mmax;i++)
            w[i]=0;
        for(i=0;i<INF;i++)
            counth[i]=0;
        for(i=0;i<INF;i++)
            countw[i]=0;
        sum = 0;
        //??\???
        scanf("%d %d", &N, &M);
        if(!N && !M)
            break;
        for(i=0;i<N;i++)
            scanf("%d",&h[i]);
        for(i=0;i<M;i++)
            scanf("%d",&w[i]);
        //??????
        for(i=0;i<N;i++){
            tmp=0;
            for(j=i;j<N;j++){
                tmp += h[j];
                counth[tmp]++;
            }
        }
        for(i=0;i<M;i++){
            tmp=0;
            for(j=i;j<M;j++){
                tmp += w[j];
                countw[tmp]++;
            }
        }
        //??????
        for(i=0;i<INF;i++){
            sum += (counth[i] * countw[i]);
        }
        printf("%d\n",sum);
    }
    
    return 0;
}

Measured memory_bytes: 8424
#include <bits/stdc++.h>
using namespace std;
int nxt[300001][10];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	memset(nxt, -1, sizeof nxt);
	for(int i=n-1; i; i--) {
		memcpy(nxt[i-1], nxt[i], sizeof(nxt[i]));
		nxt[i-1][s[i]-'0'] = i;
	}
	int ans = 0;
	for(int i=0; i<10; i++) {
		for(int j=0; j<10; j++) {
			for(int k=0; k<10; k++) {
				if(s[0]-'0' == i) {
					ans += nxt[0][j] != -1 && nxt[nxt[0][j]][k] != -1;
				} else {
					ans += nxt[0][i] != -1 && nxt[nxt[0][i]][j] != -1 && nxt[nxt[nxt[0][i]][j]][k] != -1;
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define int long long int
#define F first
#define S second
#define pb push_back
#define M 1000000007
#define inf 1e18
#define endl "\n"
#define jam(x) cout<<"Case #"<<x<<": "
#define N 100005

void display1D( vector<int> &v ) {
	int n = v.size();
	for (int i = 0; i < n; i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}

std::vector<int> v[N];
std::vector<int> ind;

int lp(int n) {
	set<int> st;
	std::vector<int> dp(n + 1, 0);
	for (int i = 1; i <= n; ++i) {
		if (ind[i] == 0) st.insert(i);
	}



	while ( !st.empty() ) {
		int cur = *st.begin();
		st.erase(st.begin());
		for ( int adj : v[cur] ) {
			dp[adj] = max(dp[adj], dp[cur] + 1 );
			ind[adj]--;
			if ( ind[adj] == 0 ) st.insert(adj);
		}
	}

	//display1D(dp);
	return *max_element( dp.begin(), dp.end() );
}


int32_t main() {
	fastio;
#ifndef ONLINE_JUDGE
	fileIO;
#endif

	int n, m, a, b;
	cin >> n >> m;
	ind.resize(N);
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		v[a].push_back(b);
		ind[b]++;
	}

	cout << lp(n);

	return 0;
}

Measured memory_bytes: 11056
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A+B == C+D) 
        cout << "Balanced" << endl;
    if (A+B < C+D)
        cout << "Right" << endl;
    if (A+B > C+D)
        cout << "Left" << endl;
}


Measured memory_bytes: 256
#N, K = map(int, input().split())
#p = list(map(int, input().split()))

n = int(input())
res = str()
while 0 < n:
    n -= 1
    r = n % 26
    res += chr(r+ord('a'))
    # print(res)
    n //= 26
 
print(res[::-1])

Measured memory_bytes: 8976
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n; cin >> n;
  LL ret = 0;
  int pre = 0;
  for (int i = 0; i < n; i++) {
    int val; cin >> val;
    if (val < pre) ret += pre - val;
    pre = max(pre, val);
  }
  cout << ret << '\n';




/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3196
n = int(input())
s = input()
s = s+'_'
white = [0]*(n+1)
black = [0]*(n+1)
for i in range(n):
	if s[i] == '#':
		black[i+1] = black[i] + 1
	else:
		black[i+1] = black[i]
for i in range(n-1,-1,-1):
	if s[i]	== '.':
		white[i] = white[i+1] + 1
	else:
		white[i] = white[i+1]

tmpmin = float('inf')
for i in range(n+1):
	tmp = black[i]+white[i]
	if tmpmin > tmp:
		tmpmin = tmp

print(tmpmin)

Measured memory_bytes: 12808
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    CINVEC(A);
    CINVEC(B);

    bool exist = false;
    REP(n1, N) {
        REP(n2, N) {
            if (n1 + M - 1 >= N || n2 + M - 1 >= N)continue;
            if (A[n1][n2] == B[0][0]) {
                bool f = true;
                REP(m1, M) {
                    REP(m2, M) {
                        if (A[n1 + m1][n2 + m2] != B[m1][m2]) {
                            f = false;
                        }
                    }
                }
                if (f)exist = true;
            }

        }
    }
    YESNO(exist, "Yes", "No");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
	long long int a; cin >> a;
	long long int b; cin >> b;
	long long int c; cin >> c;
	long long int d; cin >> d;

	long long int x;
	long long int y;
	long long int Ans;
	long long int buf1;
	long long int buf2;
	if ((a < 0) && (b < 0)) {//ｘが負しか取れない
		if ((c < 0) && (d < 0)) {//ｙが負しか取れない
			//両方負
			x = a;
			y = c;
			Ans = x * y;
			cout << Ans << endl;
		}
		else if ((c < 0) && (d >= 0)) {//ｙが正と負がとれる
			x = a;
			y = c;
			Ans = x * y;
			cout << Ans << endl;
		}
		else if ((c >= 0) && (d >= 0)) {//ｙが正しか取れない
			x = b;
			y = c;
			Ans = x * y;
			cout << Ans << endl;
		}
	}else if ((a < 0) && (b >= 0)) {//ｘが正と負がどちらもとれる場合
		if ((c < 0) && (d < 0)) {//ｙが負しかとれない
			x = a;
			y = c;
			Ans = x * y;
			cout << Ans << endl;
		}
		else if ((c < 0) && (d >= 0)) {//ｙが正と負がとれる
			buf1 = b * d;
			buf2 = a * c;
			if (buf1 > buf2) {
				Ans = buf1;
				cout << Ans << endl;
			}
			else {
				Ans = buf2;
				cout << Ans << endl;
			}
		}
		else if ((c >= 0) && (d >= 0)) {//ｙが正しか取れない
			x = b;
			y = d;
			Ans = x * y;
			cout << Ans << endl;
		}
	}
	else if ((a >= 0) && (b >= 0)) {//ｘが正しかとれない
		if ((c < 0) && (d < 0)) {//ｙが負しか取れない
			x = a;
			y = d;
			Ans = x * y;
			cout << Ans << endl;
		}
		else if ((c < 0) && (d >= 0)) {//ｙが正と負がとれる
			x = b;
			y = d;
			Ans = x * y;
			cout << Ans << endl;
		}
		else if ((c >= 0) && (d >= 0)) {//ｙが正しか取れない
			x = b;
			y = d;
			Ans = x * y;
			cout << Ans << endl;
		}
	}
}

Measured memory_bytes: 3576
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<int,int>;

int main(){

  int N;
  cin >> N;

  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if(N == i*j){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3620
#X = int(input())
def maxnumber(N, B):
  if N < B:
    return N
  a = (N // B) * B - 1
  if N == a + B:
    return N
  else:
    return a
  
A, B, N = list(map(int, input().strip().split()))
X = maxnumber(N, B)
ans = (A * X) // B - A * (X // B)
#print(X)
print(ans)

Measured memory_bytes: 9188
def printData(data) :
    for i, value in enumerate(data) :
        if i > 0 :
            print(" ", end = "")
        print(value, end = "")
    print()
    
def insertionSort(data, N) :
    for i in range(1, N) :
        target = data[i]
        j = i -1
        while j >= 0 and target < data[j] :
            data[j + 1] = data[j]
            j -= 1
        data[j + 1] = target
        printData(data)
        
N = int(input())
data = [int(char) for char in input().split()]
printData(data)
insertionSort(data, N)
            


Measured memory_bytes: 6316
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
int vis[N];
vector<vector<int>>adj(N);


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
void dfs(int x){
    vis[x]=1;
    for(auto i:adj[x]){
        if(!vis[i])
            dfs(i);
    }
}


void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        k--;
        string s;
        cin>>s;
        for(int i=0;i<n;i++){
            if(i==k){
                char c=tolower(s[i]);
                cout<<(char)(c);
            }
            else
                cout<<s[i];
        }
    }
    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
	int N, P, A[52];
	scanf("%d %d", &N, &P);
	int even = 0, odd = 0;
	rep(i, N) {
		scanf("%d", &A[i]);
		(A[i] % 2) ? ++odd : ++even;
	}
	ll res = 0;
	if(!odd && !P) {
		res = 1;
		rep(i, N) res *= 2;
	}
	else if(odd){
		res = 1;
		rep(i, N - 1) res *= 2;
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 256
import sys
A,B,K = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())

i = 1
cnt = 1
factor = [0]*100
for i in range(1,101):
    if(A%i == 0 and B%i == 0):
        factor.append(i)
factor = sorted(factor)
print(factor[-K])


Measured memory_bytes: 3060
a,b,c = map(int, input().split())
k = int(input())

while(a >= b and k >0 ):
    b = b*2
    k -= 1    

c = c*2**(k)
#print(a,b,c)
if (a<b and  b<c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8816
#include <stdio.h>

int main(void) {
	int a,b;
	char op;
	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='?') break;
	if(op=='+')
		printf("%d\n",a+b);
	else if(op=='-')
		printf("%d\n",a-b);
	else if(op=='*')
		printf("%d\n",a*b);
	else 
		printf("%d\n",a/b);
	}
	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[114514];
int main(){
  ll a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  ll ans=a[2]-a[1];
  if((a[1]-a[0])%2)ans++;
  ans+=(a[1]-a[0]+1)/2;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

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

	char c = s[0];
	int ans = 1;
	for (int i = 1; i < N; ++i) {
		if (c != s[i]) {
			++ans;
			c = s[i];
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e3+50;

struct point {
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
    bool operator < (const point &rhs)const{
        return atan2(y,x) < atan2(rhs.y, rhs.x);
    }
}p[maxn];

int main(){
    int n;cin>>n;
    FOR(i,1,n){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p+1,p+1+n);
    double ans=0;
    FOR(i,1,n){

        double allx=0,ally=0;
        int pos=i;
        do{
            allx+=p[pos].x;
            ally+=p[pos].y;
            ans=max(allx*allx+ally*ally,ans);
            if(pos+1<=n)pos=pos+1;
            else pos=1;
        }while(pos!=i);
    }
    printf("%.12f\n",sqrt(ans));
}


Measured memory_bytes: 384
from heapq import heappush, heappop
INF = 10**15
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
  l,r,c=map(int,input().split())
  l-=1;r-=1
  graph[l].append((r,c))
for i in range(n-1):
  graph[i+1].append((i,0))
def dijkstra(N, G, s):
    global dist
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
dijkstra(n,graph,0)
if dist[n-1]==INF:
  print(-1)
else:print(dist[n-1])


Measured memory_bytes: 75044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	V<int> A(N+2); rep1(i,N) cin >> A[i];
	ll S = 0;
	rep(i,N+1) S += abs(A[i]-A[i+1]);
	rep(i,N){
		cout << S - abs(A[i]-A[i+1]) - abs(A[i+1]-A[i+2]) + abs(A[i]-A[i+2]) << endl;
	}
}


Measured memory_bytes: 1664
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);

  printf("%d\n", max(C-(A-B), 0));


  return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	static int H,W;
	static char field[][];
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int T=in.nextInt();
		for(int I=0;I<T;I++)
		{
			if(I!=0)
				System.out.println();
			int H=in.nextInt();
			int W=in.nextInt();
			int sh=0;
			int sw=0;
			int dir=0;
			field=new char[H][W];
			for(int i=0;i<H;i++)
			{
				char ch[]=in.next().toCharArray();
				for(int j=0;j<W;j++)
				{
					field[i][j]=ch[j];
					if(ch[j]=='>'||ch[j]=='v'||ch[j]=='<'||ch[j]=='^')
					{
						 sh=i;
						 sw=j;
						 field[i][j]='.';
					}
					if(ch[j]=='^')
						dir=1;
					else if(ch[j]=='>')
						dir=2;
					else if(ch[j]=='v')
						dir=3;
					else if(ch[j]=='<')
						dir=4;
				}
			}
			
			int N=in.nextInt();
			char d[]=in.next().toCharArray();
			
			for(int i=0;i<N;i++)
			{
				
				if(d[i]=='U')
				{
					dir=1;
					if(sh-1>=0&&field[sh-1][sw]=='.')
						sh--;
				}
				else if(d[i]=='R')
				{
					dir=2;
					if(sw+1<W&&field[sh][sw+1]=='.')
						sw++;
				}
				else if(d[i]=='D')
				{
					dir=3;
					if(sh+1<H&&field[sh+1][sw]=='.')
						sh++;
				}
				else if(d[i]=='L')
				{
					
					dir=4;
					if(sw-1>=0&&field[sh][sw-1]=='.')
						sw--;
				}
				else
				{
					int nh=sh;
					int nw=sw;
					if(dir==1)
					{
						while(nh>=0)
						{
							if(field[nh][nw]=='*')
							{
								field[nh][nw]='.';
								break;
							}
							else if(field[nh][nw]=='#')
								break;
							nh--;
						}
					}
					else if(dir==2)
					{
						while(nw<W)
						{
							if(field[nh][nw]=='*')
							{
								field[nh][nw]='.';
								break;
							}
							else if(field[nh][nw]=='#')
								break;
							nw++;
						}
					}
					else if(dir==3)
					{
						while(nh<H)
						{
							if(field[nh][nw]=='*')
							{
								field[nh][nw]='.';
								break;
							}
							else if(field[nh][nw]=='#')
								break;
							nh++;
						}
					}
					else if(dir==4)
					{
						while(nw>=0)
						{
							if(field[nh][nw]=='*')
							{
								field[nh][nw]='.';
								break;
							}
							else if(field[nh][nw]=='#')
								break;
							nw--;
						}
					}
				}
			}
			if(dir==1)
				field[sh][sw]='^';
			else if(dir==2)
				field[sh][sw]='>';
			else if(dir==3)
				field[sh][sw]='v';
			else if(dir==4)
				field[sh][sw]='<';
			
			for(int i=0;i<H;i++)
			{
				for(int j=0;j<W;j++)
					System.out.print(field[i][j]);
				System.out.println();
			}
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

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

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

    string s;
    cin >> s;

    stack<int> st;
    int res = s.size();
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'S'){
            st.push(1);
        }
        else{
            if(!st.empty()){
                st.pop();
                res -= 2;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3980
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    double sum = 0.0;
    for(int i = 0;i<n;i++){
        sum += (1.0 / a[i]);
    }
    printf("%lf",(1.0 / sum));
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ll, ll> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)
ul H, W;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<P> Dish(N, P(0, 0));
  ul tmp;
  REP(ii, N) {
    cin >> Dish[ii].second >> tmp;
    Dish[ii].first = Dish[ii].second + tmp;  // Aさんのプラス分
  }

  sort(Dish.begin(), Dish.end());
  // REP(ii, N){
  //   cout <<Dish[ii].first <<" "<<Dish[ii].second<<endl;
  // }
  bool dir = true;
  ll tak_point = 0;
  while (Dish.begin() != Dish.end()) {
    if (dir) {
      tak_point += Dish.back().second;
    } else {
      tak_point += Dish.back().second - Dish.back().first;
    }
    Dish.pop_back();
    dir = !dir;
  }
  cout << tak_point <<endl;
  //      [](auto &left, auto &right) { return left.second < right.second; });
  // sort(Dish_val.begin(), Dish_val.end());

  // REP(ii, N) { ans += max(tmp, 0); }
  // cout << ans << endl;
}

//青木くんがどちらを食べても同じく，タカハシくんの好みが別れる時にX


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

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> c(h);
  for(int i=0;i<h;i++){
    cin>>c.at(i);
  }

  for(int i=0;i<w+2;i++){
    cout<<"#";
  }
  cout<<endl;

  for(int i=0;i<h;i++){
    cout<<"#"<<c.at(i)<<"#"<<endl;
  }

  for(int i=0;i<w+2;i++){
    cout<<"#";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	int N;
	cin >> N;



	int ans = 0;
	for (int i = 0; pow(10, i) <= N; i++) {

		ans += (N % int(pow(10, i+1))) / pow(10, i)  ;


	}

	if (N % 10 == 0 && ans == 1) {
		cout << 10;
		return 0;
	}

	cout << ans;





}


Measured memory_bytes: 256
#!/usr/bin/env python3

S = list(input())

A = [S[0]]
prev = ""
for x in S[1:]:
    if prev != "":
        A.append(prev+x)
        prev = ""
    elif A[-1] == x:
        prev = x
    else:
        A.append(x)

print(len(A))



Measured memory_bytes: 17128
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int N;
deque<Int> A;

void solve(){
	sort(ALL(A));
	reverse(ALL(A));
	bool all_minus = true, all_plus = true;
	REP(i,N){
		if(A[i]>0)all_minus = false;
		if(A[i]<0)all_plus = false;
	}
	if(all_minus){
		Int sum = accumulate(ALL(A),0ll);
		cout<<A[0] * 2 - sum<<endl;
		Int result = A[0];
		REP(i,N-1){
			cout<<result<<" "<<A[i+1]<<endl;
			result = result - A[i+1];
		}
		return;
	}
	if(all_plus){
		Int sum = accumulate(ALL(A),0ll);
		cout<<sum - A.back() * 2<<endl;
		if(A.size()==2){
			cout<<A[0]<<" "<<A[1]<<endl;
			return;
		}
		Int result = A.back();
		A.pop_back();
//		assert(A.size()>=2);
		for(int i = 0;i < (int)A.size() - 1;i++){
			cout<<result<<" "<<A[i]<<endl;
			result = result - A[i];
		}
		cout<<A.back()<<" "<<result<<endl;
		return;
	}
	deque<Int> vp, vn;
	REP(i,N){
		if(A[i]>0)vp.push_back(A[i]);
		else vn.push_back(A[i]);
	}
	cout<<accumulate(ALL(vp),0ll)-accumulate(ALL(vn),0ll)<<endl;
	Int result;
	if(vp.size()==1){
		result = vp.front();
		vp.pop_front();
	}else{
		result = vn.front();
		vn.pop_front();
		REP(i,vp.size()-1){
			cout<<result<<" "<<vp[i]<<endl;
			result = result - vp[i];
		}
		cout<<vp.back()<<" "<<result<<endl;
		result = vp.back() - result;
	}
	REP(i,vn.size()){
		cout<<result<<" "<<vn[i]<<endl;
		result = result - vn[i];
	}
}

//{{{ main fucnction
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	/*
	N = rand()%1000;
	A.assign(N,Int());
	REP(i,N)A[i] = rand()%2000 - 1000;
	*/

	cin >> N;
	A.assign(N,Int());
	for(int i = 0 ; i < N ; i++){
		cin >> A[i];
	}
	solve();
	return 0;
}

//}}}


Measured memory_bytes: 3584
#include<stdio.h>
int main(){
	int N,K,i,mid,total=0;

	scanf("%d",&N);
	scanf("%d",&K);

	int x[N];

	mid = K/2;

	for(i=0;i<N;i++){
		scanf("%d",&x[i]);

		if(x[i] <= mid) total += 2*x[i];
		else total += 2*(K-x[i]);

	
	}

	printf("%d\n",total);





	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

public class Main {
public static void main(String[] args) throws IOException{
  BufferedInputStream bis = new BufferedInputStream(System.in);
  BufferedReader r = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8));
  PrintStream ps = new PrintStream(System.out);
  String str[]=r.readLine().trim().split(" ");
  BigInteger a = new BigInteger(str[0]);
  BigInteger b = new BigInteger(str[1]);
  BigInteger c = new BigInteger(str[2]);
  BigInteger d = new BigInteger(str[3]);

  BigInteger amax;
  BigInteger bmax;
  BigInteger result;

  if (a.multiply(c).compareTo(a.multiply(d)) >= 1)
    amax = a.multiply(c);

  else
    amax = a.multiply(d);

  if (b.multiply(c).compareTo(b.multiply(d)) >= 1)
    bmax = b.multiply(c);

  else
    bmax = b.multiply(d);

  if (amax.compareTo(bmax) >= 1) 
    result = amax;
   else
    result = bmax;

  System.out.println(result);
  

  
}
}
  

Measured memory_bytes: 33120
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll par[200002];
ll rk[200002];
ll sz[200002];
void init(ll n){
	for(ll i=0; i<n; i++){
		par[i]=i; sz[i]=1;
	}
}
 
ll find(ll x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
 
void unite(ll x, ll y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y; sz[y]+=sz[x];
	}else{
		par[y]=x; sz[x]+=sz[y];
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(ll x, ll y){
	return find(x)==find(y);
}
int main()
{
  ll n, m; cin>>n>>m;
  ll ans[20002];
  ll a[200002], b[200002];
  for(ll i=0; i<m; i++){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
  }
  init(n);
  ll c=0;
  ll cnt;
  cnt=0;
  for(ll i=m-1; i>=0; i--){
    ans[i]=c;
    ll x=a[i], y=b[i];
    if(same(x, y)){
      continue;
    }
    x=find(x), y=find(y);
    unite(x, y);
	
  }
  map<ll,ll>mp;
  for(ll i=0;i<n;i++){
	  mp[find(i+1)]++;
  }
  ll max=0;
  cout<<mp.size()-1<<endl;
  
	return 0;
}


Measured memory_bytes: 10340