akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    S = input()
    
    ans = []
    check = [False] * (N+1)
    
    idx = N
    while 0 < idx:
        f = False
        for i in range(M, 0, -1):
            if idx-i < 0: continue
            if S[idx-i] == '1':
                if check[idx-i]: print(-1); sys.exit()
                else: check[idx-i] = True
            else:
                ans.append(i)
                idx -= i
                f = True
                break
        if not f: print(-1); sys.exit()
    
    for a in ans[::-1]: print(a)
if __name__ == '__main__':
    main()

Measured memory_bytes: 6396
n, goal = gets.split.map(&:to_i)
boxes   = gets.split.map(&:to_i)

ans = 0

if boxes[0] > goal
  ans += (boxes[0] - goal)
  boxes[0] = goal
end

(n - 1).times do |i|
  candies = boxes[i] + boxes[i + 1]
  if candies > goal
    boxes[i + 1] -= (candies - goal)
    ans += candies - goal
  end
end

puts ans


Measured memory_bytes: 8580
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI 3.1415926535897932384
using namespace std;

int main(){
	int n,m,x;
	cin>>n>>m>>x;
	int ans=INT_MAX;
	vector<vector<int>> books(n,vector<int>(m));	//stores all A(i,j) for each ith book
	vector<int> cost(n);							//stores cost of all books
	for(int i=0;i<n;i++){
			cin>>cost[i];
		for(int j=0;j<m;j++)
			cin>>books[i][j];
	}
	int total=(1<<n);							//Total possible combinations of selecting books
	for(int mask=0;mask<total;mask++){			//Looping through every combination one by one
		vector<int> uLevel(m);					//For Storing uLevel of each Algo in that combination
		int currCost=0;							//For storing cost of books in that combination
		for(int i=0;i<n;i++){
			if((mask>>i)&1){					//if a '1' is present OR a book is present
				currCost+=cost[i];				//Cost of Current combination += cost of that book
				for(int j=0;j<m;j++)
					uLevel[j]+=books[i][j];		//uLevel for each algo is increased
			}
		}
		bool objectiveAchievable=true;
			for(int j=0;j<m;j++)
				if(uLevel[j]<x) objectiveAchievable=false;
		if(objectiveAchievable)
			ans=min(ans,currCost);
	}
	if(ans==INT_MAX) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int a, b;
  cin >> a >> b;

  FOR(i, 1, 4) {
    if(a*b*i % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }  
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;


signed main() {

    int X, Y;
    cin >> X >> Y;

    int ans = 1;
    while (1) {
        X *= 2;
        if (X <= Y) {
            ans++;
        }
        else {
            break;
        }

    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
count = 0
for i in range(n):
  minj = i
  for j in range(i,n):
    if A[j] < A[minj]:
      minj = j
  if i != minj:
    A[i], A[minj]=A[minj],A[i]
    count += 1
a=map(str,A)
print(" ".join(a))
print(count)


Measured memory_bytes: 5600
#include <iostream>

using namespace std;

int minPrice(int* menu, int length) {
	int mPrice = 0;
	for (int i = 0; i < length; i++) {
		if (mPrice == 0 || mPrice > menu[i])
			mPrice = menu[i];
	}

	return mPrice;
}

int main(void){
    int pasta[3], juice[2];
	for (int i = 0; i < 3; i++) {
		cin >> pasta[i];
	}
	for (int i = 0; i < 2; i++) {
		cin >> juice[i];
	}

	int minSetPrice = minPrice(pasta, 3) + minPrice(juice, 2) - 50;
	cout << minSetPrice << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007
// priority_queue<int, vector<int>, greater<int> > PQ; // 昇順PQ
priority_queue<int> PQ;

int main(){
  int n;
  int a,b;
  char s[100005];

  scanf("%d %d", &a, &b);

  printf("%d\n", a*b);

  return 0;
}

Measured memory_bytes: 3828
"use strict";
    
const main = arg => {
  let Num = arg.split("");
  let ans = "Good";
  for(let i = 0; i < 3; i++){
  	if(Num[i] == Num[i+1]){
       ans = "Bad";
    }
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    ll ans = 0;
    int n; cin >> n;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++)
        ans += __gcd(i, __gcd(j, k));
        cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;

typedef map<string, int> msi;

typedef pair<int, int> pii;
typedef pair <ll, ll> pll; // note 'single' ls

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)

#define pb \
push_back

#define ff \
first

#define ss \
second

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

	vector<pair<ll, int>> X;

	REP(i, 0, n-1)
	{
		ll x;
		cin >> x;

		X.pb({ x, i });
	}

	sort(X.rbegin(), X.rend());

	ll median_one = X[(n / 2) - 1].first;
	ll median_two = X[(n / 2)].first;

	vll print_out(n);

	for (int i=0; i<X.size(); i++)
	{
		pair<ll, int> x = X[i];

		if (i <= (n / 2) - 1) print_out[x.second] = median_two;
		else print_out[x.second] = median_one;
	}

	for (auto x : print_out)
	{
		cout << x << endl;
	}

	//cout << median_one << " " << median_two << endl;

	//cin >> n;
	return 0;
}

Measured memory_bytes: 7660
void main()
{
    long[] tmp = rdRow;
    long h = tmp[0], w = tmp[1], a = tmp[2], b = tmp[3];

    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            ((i < b) ^ (j < a)).to!long.write;
        }
        writeln;
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 1276
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 3"""
        output = """9"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 4"""
        output = """7"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6 6"""
        output = """12"""
        self.assertIO(input, output)

def resolve():
    X=[int(i) for i in input().split()]
    m=max(X)
    
    print(2*m if X[0]==X[1] else 2*m-1)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 51308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b; cin >> a >> b;
    if (a >= 13) cout << b << endl;
    else if (a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,a,b;
 string s,t;
 ll l,r,d;
 cin>>l>>r>>d;
 ll cnt = 0;
 for(ll i=l;i<=r;i++)if( i%d == 0)cnt++;
 cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		long sum=0;
		for(int i=0;i<n;i++){
			int x=scan.nextInt();
			if(x > max)max=x;
			if(x < min)min=x;
                        sum+=x;
		}
		
		System.out.printf("%d %d %d\n",min,max,sum);
		
	}
}


Measured memory_bytes: 41716
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
p_list = [int(n) for n in lines[0].split(" ")]

def _iter_minimum():
    prev = sys.maxsize
    for p in p_list:
        m = min(prev, p)
        yield m
        prev = m

mininum_list = list(_iter_minimum())

count = 0
for p, m in zip(p_list, mininum_list):
    if p == m:
        count += 1

print(count)


Measured memory_bytes: 32280
#include <iostream>

using namespace std;

int main () {
    int a, b;

    cin >> a >> b;

    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout  << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}


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

int n;
priority_queue<double> pQ;

int main() {
	scanf("%d", &n);

	for(int i=0; i<n; i++) {
		double x;
		scanf("%lf", &x);
		pQ.push(-x);
	}

	while(pQ.size() > 1) {
		double t = -pQ.top(); pQ.pop();
		t += -pQ.top(); pQ.pop();

		pQ.push(- t/2);
	}

	printf("%.10f", -pQ.top());
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,r;
	while(1){
		scanf("%d",&n);
		if(n==-1){
			break;
		}else if(n<10){
			r=1150;
		}else if(n<20){
			r=1150+125*(n-10);
		}else if(n<30){
			r=2400+140*(n-20);
		}else{
			r=3800+160*(n-30);
		}
		printf("%d\n",4280-r);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, d;
    cin >> n >> d;
    vector< vector< int > > x(n, vector< int >(d, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                sum += pow(x[i][k] - x[j][k], 2);
            }
            for (int k = 0; k <= sum; k++) {
                if (k * k == sum) {
                    ans++;
                    break;
                } else if (k * k > sum) {
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int z(int p) {
  int x = 1;
  if (p == 1) {
    return 1;
  }
  else {
    for (int i = 0; i < p - 1; i++) {
      x *= 10;
    }
    return x;
  } 
}

int main() {
   int N;
  cin >> N;
  string n;
  n = to_string(N);
  int size;
  size = n.size();
  if (size % 2 == 0) {
    int count;
    while (size > 0) {
      if (size % 2 == 0) {
        size--;
      }
      else {
        count += 9 * z(size);
        size--;
      }
    }
    cout << count <<endl;
  }
  
  else {
    int count = N - z(size) + 1;
    size--;
    while (size > 0) {
      if (size % 2 == 0) {
        size--;
      }
      else {
        count += 9 * z(size);
        size--;
      }
    }
    cout << count <<endl;
  }
}

Measured memory_bytes: 256
_n = STDIN.gets.split.map(&:to_i)
paras = STDIN.gets.chomp

t_paras = paras.dup

while t_paras.sub!('()', '')
end

t_paras.each_char do |ch|
  if ch == ')'
    paras = '(' + paras
  elsif ch == '('
    paras = paras + ')'
  end
end

puts paras


Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            Map<String, Integer> map = new HashMap<>();
            for (int i = 0; i < N; i++) {
                map.merge(in.next(), 1, Integer::sum);
            }
            String[] s = new String[]{"AC", "WA", "TLE", "RE"};
            for (String ss : s) {
                out.println(ss + " x " + map.getOrDefault(ss, 0));
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 50428
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
j=0
s=0
eq=''
A,B,C=map(int,input().split())
#A,B,Cを分けて入力しかも一行で
#N=int(input())
#Nori=N
#D, N=input().split()
#S=input()
D=0
D=A+B
if D >=C:
    print('Yes')
    sys.exit()
print('No')
def change(i):
    return int(i)

#S_list=list(S)
numberlist=[]
numberlist=list(map(change, numberlist))
keisanlist=sorted(numberlist, reverse=True)

#M=int(input())
#drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#D=int(D)
#N=int(N)
#不本意だが内包表記で二次元の空のリストを作成する
     
#dp=[['' for i in range(2)] for j in range(N)]
#absTH=[''for i in range(N)]
#K=int(K)
#S_list=[]
#sentence_list=[]
#total=0
#mojiretu=""
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#weight_value_list =  [list(input())for i in range(N)]#一文字づつばらして入れてしまう
#s = [input() for i in range(N)]
#複数行に複数の入力値を取得し、出力する
#sentence_list =  (list(input())for i in range(N))
#for i in range(H):
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる
#print(a_list)
first_term=0
second_term=0
#整数二次元配列を読み込む時のやり方
#a_b_c_list =  [list(map(int, input().split(" ")))for i in range(N)]
     
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
  
     
#x, y = [0]*N, [0]*N#N個の空のリストを作成
#l = list(range(N))#範囲がNのリストを作成する
     
#for i in range(N):
#  x[i], y[i] = map(int, input().split())
#分けて入力する形式を設定することで可読性が高く仕上がっている
#素晴らしいことだ
     
     
distance = 0
#comb = list(itertools.permutations(l))
#prmutation:英語の意味としては順列である
'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
#for i in range(0, len(comb)):#i番目のパターンの時を考える。
#  for j in range(0, N-1):#lのリスト番号を読み込み
#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
#print(distance/len(comb))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])
#リストを一周するようにすればいいのか


Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int main() {
    char a, b;
    scanf("%c %c", &a, &b);
    if (a == b) printf("H\n");
    else printf("D\n");
}


Measured memory_bytes: 384
using System;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine();
            if (input[0] == input[1] && input[1] != input[2] && input[2] == input[3]
                || input[0] == input[2] && input[2] != input[1] && input[1] == input[3]
                || input[0] == input[3] && input[3] != input[1] && input[1] == input[2])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/12/20 07:29:17
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n+1), B(n);
  for (auto& a:A) cin>>a;
  for (auto& b:B) cin>>b;

  ll all = accumulate(A.begin(), A.end(), 0ll);
  for (int i = 0; i < n; i++) {
    int di = min(B[i], A[i]);
    A[i] -= di;
    B[i] -= di;
    A[i+1] -= min(A[i+1], B[i]);
  }
  cout << all-accumulate(A.begin(), A.end(), 0ll) << endl;

  return 0;
}


Measured memory_bytes: 1024
import Foundation
var str = readLine()!.components(separatedBy:" ")
var n = Int(str[0])!
var m = Int(str[1])!
var l = readLine()!.components(separatedBy:" ")
var a = [Int]()
for aa in l {
  a.append(Int(aa)!)
}
let sum = a.reduce(0) { $0 + $1 }
if n-sum<0{
  print(-1)
} else {
  print(n-sum)
}

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

ll large[55], ps[55];

ll solve(ll now, int l){
    if(l == -1) return 1;
    if(now == 1) return 0;
    else if(now <= 1 + large[l]) return solve(now-1, l-1);
    else if(now == 2 + large[l]) return ps[l] + 1;
    else if(now <= 2 + 2*large[l]) return ps[l] + 1 + solve(now-large[l]-2, l-1);
    else return 2*ps[l] + 1;
}

int main(){
    int n;
    ll x;
    cin >> n >> x;
    
    large[0] = 1;
    ps[0] = 1;
    rep(i,n){
        large[i+1] = 2*large[i] + 3;
        ps[i+1] = 2*ps[i] + 1;
    }

    ll ans = solve(x, n-1);
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
    rep(i, m) {
        ll l, r;
        cin >> l >> r;
        rep(j, l) dp[j + 1][r]++;
    }
    rep(i, n) {
        rep(j, n) {
            dp[i + 1][j + 1] += dp[i + 1][j];
        }
    }
    rep(i, q) {
        ll p, q;
        cin >> p >> q;
        cout << dp[p][q] << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
def f(x,y,z):
    if x=="S" and y=="o":
        return z
    if x=="S" and y=="x":
        return g(z)
    if x=="W" and y=="o":
        return g(z)
    if x=="W" and y=="x":
        return z
def g(x):
    if x=="S":
        return "W"
    if x=="W":
        return "S"
def check(x,y):
    t[0]=x
    t[1]=y
    for j in range(1,N-1):
        t[j+1] = f(t[j],s[j],t[j-1])
    x1 = f(t[N-1],s[N-1],t[N-2])
    y1 = f(x1,s[0],t[N-1])
    if x==x1 and y==y1:
        return True
    else:
        return False
N = int(input())
s = input().strip()
t = [0 for _ in range(N)]
if check("S","S"):
    print("".join(t))
elif check("S","W"):
    print("".join(t))
elif check("W","S"):
    print("".join(t))
elif check("W","W"):
    print("".join(t))
else:
    print(-1)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

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

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

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


void Main() {
  int A, B; cin >> A >> B;
  cout << max(0, A - 2 * B) << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Diagnostics;

static class Program
{
    class Query
    {
        public readonly int a;
        public readonly int b;
        public readonly int c;
        public readonly int d;
        public Query(int[] args)
        {
            a = args[0];
            b = args[1];
            c = args[2];
            d = args[3];
        }
    }

    class Solver
    {
        public readonly int N;
        public readonly int M;
        public readonly int Q;
        public readonly Query[] queries;
        public Solver(int N, int M, int Q, Query[] queries)
        {
            this.N = N;
            this.M = M;
            this.Q = Q;
            this.queries = queries;
        }
        public int Solve(Stack<int> A)
        {
            if (A.Count == N)
            {
                int sum = 0;
                foreach (var q in queries)
                {
                    if (A.ElementAt(N - q.b) - A.ElementAt(N - q.a) == q.c) { sum += q.d; }
                }
                return sum;
            }
            else
            {
                int max = 0;
                for (int i = A.First(); i <= M; ++i)
                {
                    A.Push(i);
                    max = Math.Max(Solve(A), max);
                    A.Pop();
                }
                return max;
            }
        }
    }

    static long Solve(int N, int M, int Q, Query[] queries)
    {
        return 0;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int Q = V[2];
        var queries = new Query[Q];
        for (int i = 0; i < Q; ++i)
        {
            queries[i] = new Query(Array.ConvertAll(Console.ReadLine().Split(), int.Parse));
        }
        var A = new Stack<int>();
        A.Push(1);
        Console.WriteLine(new Solver(V[0], V[1], Q, queries).Solve(A));
    }
}


Measured memory_bytes: 46604
#include <stdio.h>
#include <math.h>

int main(){
  double x,x1,y,y1;
  scanf("%lf %lf %lf %lf",&x,&y,&x1,&y1);
  x-=x1;
  y-=y1;
  x1=x*x;
  y1=y*y;
  printf("%f\n",sqrt(x1+y1));

  return 0;
}

Measured memory_bytes: 652
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  long long K,X;
  cin>>K>>X;
  long long left,right;
  left = X - K + 1;
  right = X + K - 1;
  if(left < (-1000000) ) left = (-1000000);
  if(right > 1000000) right = 1000000;
  for(long long i = left; i <= right; i++){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
   
}


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

using namespace std;

int main(){
    int N,max=0;
    cin>>N;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    for(int i=0;i<N-1;i++){
        if(max>N-i-2){
            break;
        }
        int count=0;
        for(int j=i;j<N-1;j++){
            if(H[j]>=H[j+1]){
                count++;
            }else{
                break;
            }
        }
        if(max<count){
            max=count;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int hum(int);

int main(){
	int m,n;
	int h=0;
	cin>>m;
	while(m>0){
		cin>>n;
		for(int i=m;i<=n;i++){
			h+=hum(i);
		}
		cout<<h<<endl;
		h=0;
		cin>>m;
	}	
	return 0;
}

int hum(int x){
	while(x%2==0){
		x/=2;
	}
	while(x%3==0){
		x/=3;
	}
	while(x%5==0){
		x/=5;
	}
	if(x==1){
		return 1;
	}else{
		return 0;
	}
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
#define x first
#define y second
#define u(i,a,b) for(int i=a;i<b;i++)
using namespace std;pair<int,int> p[12];bool t[1010][1010],v[1010][1010];queue<pair<int,pair<int,int> > >Q;int main(){int h,w,k,a=0,dx[]={0,1,0,-1},dy[]={1,0,-1,0};cin>>h>>w>>k;u(i,0,h)u(j,0,w){t[i][j]=1;char z;cin>>z;if(z=='X')t[i][j]=0;if(z=='S')p[0]=make_pair(i,j);if(z>'0'&&z<='9')p[z-'0']=make_pair(i,j);}u(r,0,k){Q.push(make_pair(0,p[r]));u(i,0,h)u(j,0,w)v[i][j]=0;v[p[r].x][p[r].y]=1;while(1){int L=Q.front().x,Y=Q.front().y.x,X=Q.front().y.y;if(Y==p[r+1].x&&X==p[r+1].y){a+=L;break;}u(i,0,4){int f=Y+dy[i],g=X+dx[i];if(f>=0&&f<h&&g>=0&&g<w){if(t[f][g]==1&&v[f][g]==0){v[f][g]=1;Q.push(make_pair(L+1,make_pair(f,g)));}}}Q.pop();}while(!Q.empty())Q.pop();}cout<<a<<endl;return 0;}

Measured memory_bytes: 5096
#include <stdio.h>

void trace(int A[], int N){
  int i;
  for( i = 0; i < N; i++){
    if(i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void InSort(int A[], int N){
  int j, i, v;
  for(i = 1; i < N; i++){
    v = A[i];
    j = i-1;
    while (j>=0&& A[j] >v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main(){
  int N, i, j;
  int A[100];

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

  trace(A, N);
  InSort(A,N);
}

Measured memory_bytes: 1032
import copy
h, w, k = map(int,input().split())
dot_map = []
result = 0

for i in range(h):
    tmp_input = list(input())
    dot_map.append(tmp_input)

for h_i in range(2 ** h):
    tmp_dot_map = copy.deepcopy(dot_map)
    for h_degit in range(h):
        if bin(h_i >> h_degit)[-1] == "1":
            tmp_dot_map[h_degit] = list("." * w)

    for w_i in range(2 ** w):
        sharp_counter = 0
        tmp_dot_map_2 = copy.deepcopy(tmp_dot_map)
        for w_degit in range(w):
            if bin(w_i >> w_degit)[-1] == "1":
                for h_draw in range(h):
                    tmp_dot_map_2[h_draw][w_degit] = "."

        for h_s in range(h):
            for w_s in range(w):
                if tmp_dot_map_2[h_s][w_s] == "#":
                        sharp_counter += 1
        if sharp_counter == k:
            result += 1
        # print(tmp_dot_map)
print(result)


Measured memory_bytes: 9296
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n; 
double solve(int x, int y, int z){

if(x==0 && y==0 && z==0){
    return 0;
}
if(x<0 || y<0 || z<0){
    return 0;
}
if(dp[x][y][z]>-0.9){
    return dp[x][y][z];
}

   double e=n+x*solve(x-1,y,z)+ y*solve(x+1, y-1,z)+z*solve(x,y+1,z-1);
return dp[x][y][z]=e/(x+y+z);

}
int main() {
    memset(dp,-1,sizeof dp);
    cin>>n; int x;
    int one=0, two=0, three=0;
    for(int i=n;i>0;--i){
           cin>>x;
           if(x==1){
           one++;
           }
           else if(x==2){
               two++;
           } else{
               three++;
           }
    }
    //cout<<one<<" "<<two<<" "<<three<<"\n";
    cout<<fixed<<setprecision(20)<<solve(one, two, three);

    return 0;
}


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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define N 100005
int dp[N];
int h[N];
int n;

int solve(){
    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++){
        dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
    }
    return dp[n];

}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    cout<<solve();


}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

template <typename T> struct SegmentTree {
private:
    using F = function<T(T, T)>;

    int n;
    vector<T> node;
    F op;
    T id;
    T get(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) { return id; }
        if (a <= l && r <= b) {
            return node[k];
        } else {
            return op(get(a, b, 2 * k + 1, l, (l + r) / 2), get(a, b, 2 * k + 2, (l + r) / 2, r));
        }
    }

public:
    SegmentTree(int sz, F op, T id) : op(op), id(id) {
        n = 1;
        while (n < sz) { n *= 2; }
        node.resize(2 * n - 1, id);
    }
    void update(int i, T x) {
        i += n - 1;
        node[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            node[i] = op(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    T get(int i) { return node[i + n - 1]; }
    T get(int a, int b) { return get(a, b, 0, 0, n); }
};

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using Tree = SegmentTree<int>;

constexpr int N_CH = 26;

int ctoi(const char c) { return (c - 'a'); }

// O(log(n))
void change(vector<Tree>& trees, string& S, const int index, const char next_ch) {
    int curr_ci = ctoi(S[index - 1]);
    int next_ci = ctoi(next_ch);
    if (curr_ci == next_ci) { return; }

    S[index - 1] = next_ch;
    trees[curr_ci].update(index - 1, 0);
    trees[next_ci].update(index - 1, 1);
}

// O(log(n))
int count(vector<Tree>& trees, const int l, const int r) {
    int sum = 0;
    rep(i, 0, N_CH) {
        sum += trees[i].get(l - 1, r);
    }
    return sum;
}

void print(vector<Tree>& trees, const string& S, const int N) {
    cout << S << endl;
    rep(j, 0, N) {
        rep(i, 0, N_CH) {
            cout << trees[i].get(j) << " ";
        }
        cout << endl;
    }
}

int main() {
    int N, Q;
    cin >> N;
    string S;
    cin >> S;

    auto max_op = [](int a, int b) -> int { return max(a, b); };
    vector<Tree> trees(N_CH, Tree(N, max_op, 0));

    // O(N log(N))
    rep(i, 0, N) {
        trees[ctoi(S[i])].update(i, 1);
    }

    // print(trees, S, N);

    // O(Q log(N))
    cin >> Q;
    rep(q, 0, Q) {
        int t;
        cin >> t;

        if (t == 1) {
            // O(log(N))
            int i;
            char c;
            cin >> i >> c;
            change(trees, S, i, c);
        } else {
            // O(log(N))
            int l, r;
            cin >> l >> r;
            cout << count(trees, l, r) << endl;
        }
        // print(trees, S, N);
    }

    return 0;
}

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

bool c[100];
string a;
int main()
{
	int i;
	cin >> a;
	for (i = 0; i < a.size(); i++) c[a[i]] = 1;
    cout << (c['S'] ^ c['N'] | (c['E'] ^ c['W']) ? "No" : "Yes") << endl;
    return 0;
}

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

// int main(){
//     long long w,h,x,y;
//     cin >> w >> h >> x >> y;
//     long long yoko[2],tate[2];
//     yoko[0] = w*(h-y);
//     yoko[1] = w*y;
//     tate[0] = h*x;
//     tate[1] = h*(w-x);
//     cout << fixed << setprecision(6)<< double((max(min(yoko[0],yoko[1]),min(tate[0],tate[1]))));
//     cout << " ";
//     if (min(yoko[0],yoko[1])==min(tate[0],tate[1])){
//         cout << "1"<<endl;
//     }else{
//         cout << "0"<<endl;
//     }
//     return 0;
// }

int main(){
    long long w,h,x,y;
    cin >> w >> h >> x >> y;
    double res = (double)w*h/2;
    cout << fixed << setprecision(10) << res << " ";
    if(x*2==w&&y*2==h){
        cout << "1";
    }else{
        cout << "0";
    }
}

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

int main(){
  
  int n, m;
  char a[50][51], b[50][51];

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


  bool f1=false;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      bool f2=true;
      for(int k=0;k<m;k++){
	for(int l=0;l<m;l++){
	  if(a[i+k][j+l]!=b[k][l]) f2=false;
	}
      }
      if(f2) f1=true;
    }
  }

  if(f1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
def main():
    W = sorted([int(input()) for _ in range(10)], reverse=True)
    S = sorted([int(input()) for _ in range(10)], reverse=True)

    print(W[0] + W[1] + W[2], S[0] + S[1] + S[2])


if __name__ == '__main__':
    main()



Measured memory_bytes: 5604
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

    string str;
    cin >> str;

    vector<ll> a(26,0);

    for(int i = 0; i < n; i++){
        a[str[i] - 'a']++;
    }

    ll ans = 1;

    for(int i = 0; i < 26; i++){
        ans *= a[i]+1;
        ans %= MOD;
    }

    cout << (ans + (MOD - 1))%MOD << endl;

    return 0;
}

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

using ll = long long;
int main()
{
	ll t1,t2,a1,a2,b1,b2;
	cin>>t1>>t2;
	cin>>a1>>a2;
	cin>>b1>>b2;
	
	//Fuck calculations. Try with Relativity.
	ll rel_dist_1 = t1*(a1-b1);
	ll rel_dist_2 = t2*(a2-b2);
	
	//Cover first distance as positive no matter what...
	if(rel_dist_1 < 0)
	{
		rel_dist_1 *= -1;
		rel_dist_2 *= -1;
	}
	
	//Now see total_dist_covered...
	ll total_rel_dist_covered = rel_dist_1 + rel_dist_2;
	
	if(total_rel_dist_covered==0)
	{
		cout<<"infinity\n";
	}
	else if(total_rel_dist_covered > 0)
	{
		cout<<0<<endl;
	}
	else
	{
		//How many times do we meet now?
		//Can I somehow find a relation between them?
		total_rel_dist_covered *= -1;
		/* rd1 -rd2 where rd2>rd1...so now rd = rd2-rd1
		 * If I move ahead by 2rd1, i'll be pulled back by one rd2.
		 * ...-3 -2 -1 0 1 2 3 4...
		 * Find with repeated tug of war...+X & -Y, when do I finally become permanent negative.
		 * Pull is from +X to 0 => X
		 * Force doing the pull = Y-X
		 * Simulate a +X, -Y, +X, -Y, +X, -Y until finally doing +X no longer gives me a positive value.
		 * so umm...let us combine +X and -Y => X-Y, X-Y, X-Y...k times
		 * k(X-Y) = X
		 * or k = (X/(X-Y))
		 * and 2k would give me the times met. If there is remainder, 1 last push was needed.
		 * Therefore: X/(Y-X) will give me
		 */
		ll Q = (rel_dist_1)/(total_rel_dist_covered);
		ll R = (rel_dist_1)%(total_rel_dist_covered);
		//cout<<rel_dist_1<<" "<<total_rel_dist_covered<<endl;
		if(R==0)
			cout<<2*Q<<endl;
		else
			cout<<2*Q+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    int cnt = 0;
    cin >> n;
    for(int i = 1; i < n + 1; i++)
    {
        int digits = floor(log10(i)) + 1;
        if(digits % 2 != 0)
        {
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum,num;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double x=sum/(4.0*m);
	for(int i=1;i<=n;i++)
		if(a[i]>=x)
			num++;
	if(num>=m)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX=1<<18;
const int MAX_N=1<<18;
typedef pair<int,int> P;
int n,dat[2*MAX-1],laz[2*MAX-1];
P datp[2*MAX_N-1];
int query(int k){
  k+=n-1;
  P p=datp[k];
  while(k>0){
    k=(k-1)/2;
    p=min(p,datp[k]);
  }
  return p.second;
}
void update(int a,int b,P p,int k=0,int l=0,int r=n){
  if(r<=a||b<=l) return;
  if(a<=l&&r<=b) {
    datp[k]=min(p,datp[k]);
  }else{
    update(a,b,p,k*2+1,l,(l+r)/2);
    update(a,b,p,k*2+2,(l+r)/2,r);
  }
}
void init(int n_){
  n=1;
  while(n<n_) n*=2;
  for(int i=0;i<2*n-1;i++) dat[i]=laz[i]=0;
  for(int i=0;i<2*n-1;i++) datp[i].first=INT_MAX,datp[i].second=INT_MAX;
}
inline void eval(int len,int k){
  if(k*2+1<n*2-1){
    laz[k*2+1]+=laz[k];
    laz[k*2+2]+=laz[k];
  }
  dat[k]+=laz[k]*len;
  laz[k]=0;
}
int update(int a,int b,int x,int k=0,int l=0,int r=n){
  eval(r-l,k);
  if(r<=a||b<=l) return dat[k]+laz[k]*(r-l);
  if(a<=l&&r<=b) return dat[k]+(laz[k]+=x)*(r-l);
  eval(r-l,k);
  return dat[k]=update(a,b,x,k*2+1,l,(l+r)/2)+update(a,b,x,k*2+2,(l+r)/2,r);
}
int query(int a,int b,int k=0,int l=0,int r=n){
  eval(r-l,k);
  if(r<=a||b<=l) return 0;
  if(a<=l&&r<=b) return dat[k];
  int vl=query(a,b,k*2+1,l,(l+r)/2);
  int vr=query(a,b,k*2+2,(l+r)/2,r);
  return vl+vr;
}

signed main(){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++) cin>>a[i];
  vector<int> v(N);
  for(int i=0;i<N;i++) v[i]=a[i];
  v.push_back(0);
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  int M=v.size();
  init(M);
  map<int,int> m;
  for(int i=0;i<M;i++) m[v[i]]=i;
  for(int i=0;i<N;i++){
    //cout<<i<<":"<<m[a[i]]+1<<endl;
    update(0,m[a[i]]+1,P(i,i));
    update(0,m[a[i]]+1,1);
  }
  int o[N];
  memset(o,0,sizeof(o));
  for(int i=M-1;i>0;i--){
    //cout<<i<<" "<<query(i)<<endl;
    o[query(i)]+=(v[i]-v[i-1])*query(i,i+1);
  }
  for(int i=0;i<N;i++) cout<<o[i]<<endl;
}


Measured memory_bytes: 24048
from collections import Counter
import math
N ,L= map(int, input().split())
applesum=(L+L+N-1)*N//2
if 0 >= L and L+N-1 >= 0:
	print(applesum)
elif 0 > L+N-1 :
	print(applesum-L-N+1)
else:
	print(applesum-L)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0,b=0;
  cin>>n;
  vector<int> c(n);
  for(int i=0;i<n;i++) cin>>c[i];
  sort(c.begin(),c.end(),greater<int>());
  for(int i=0;i<n;i++){
    if(i%2==0)a+=c[i];
    else b+=c[i];
  }
  cout<<a-b;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int N;

vector<string> V;
vector<string> T;

bool isOK() {
    for ( int x = 0; x < N; x++ ) {
    for ( int y = 0; y < N; y++ ) {
        if ( T[y][x] != T[x][y] ) { return false; }
    }
    }
    return true;
}

int main() {
    
    
    cin >> N;
    V.resize(N);
    T.resize(N);
    
    for ( int i = 0; i < N; i++ ) {
        cin >> V[i];
    }

    long long ans = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int y = 0; y < N; y++ ) {
            T[y] = V[(y+i)%N];
        }
        if ( isOK() ) {
            ans += N-i;
        }

        if ( i == 0 ) { continue; }
        for ( int x = 0; x < N; x++ ) {
        for ( int y = 0; y < N; y++ ) {            
            T[y][x] = V[y][(x+i)%N];
        }
        }
        
        if ( isOK() ) {
            ans += N-i;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc043/tasks/abc043_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n, sum;

  cin >> n;

  sum = n * (n + 1) / 2;

  cout << sum << "\n";

  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <algorithm>

using namespace std;

void CountingSort(int A[],int B[],int k){
  int C[2000000];
  for (int i = 0; i < k; i++) {
    C[i] = 0;
    for(int j = 1;j<k;j++){
      C[A[j]]++;
    }
    for(int j = k;j<1;j--){
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
  }
}

int main(){
  int A[2000000],B[2000000];
  int n;
  int cnt = 0;
  cin >> n;
  for (int i=0; i < n; i++) {
    cin >> A[i];
  }
    for (int i=0; i < n; i++) {
    B[i] = A[i];
    cnt++;
  }
CountingSort(A,B,n);
sort(B,B+cnt);
cout << B[0];
  for (int i=1; i < n; i++) {
    cout << " ";
cout << B[i];
}
cout << endl;
return 0;
}



Measured memory_bytes: 18720
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	int n;
	cin >> n;
	cout << 180 * (n- 2);
	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 256