akhauriyash/Code-Regression huggingface dataset:
from collections import deque

H, W = map(int, input().split())
s = [list(input().rstrip('\n')) for _ in range(H)]

root_num = 0
block_num = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            root_num+=1
        else:
            block_num+=1

directions = [[1,0],
             [-1,0],
             [0,1],
             [0,-1]]

seen = [[False for _ in range(W)] for _ in range(H)]
answer = [[-10000 for _ in range(W)] for _ in range(H)]
answer[0][0] = 0

todo = deque([[0,0]])
seen[0][0] = True
while len(todo) > 0:
    checking = todo.popleft()
    for direction in directions:
        moved = [checking[0] + direction[0], checking[1] + direction[1]]
        if moved[0] < 0 or moved[0] >= H or moved[1] < 0 or moved[1] >= W:
            continue
        if seen[moved[0]][moved[1]] == False and s[moved[0]][moved[1]] ==".":
            seen[moved[0]][moved[1]] = True
            answer[moved[0]][moved[1]] = answer[checking[0]][checking[1]] + 1
            todo.append([moved[0], moved[1]])

if answer[-1][-1] == -10000:
    print("-1")
else:
    print(root_num - (answer[-1][-1] + 1))

Measured memory_bytes: 3436
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>

#include<queue>

using namespace std;

int main() {

	int N;
	cin >> N;

	vector<tuple<string, int, int>> info;
	for (int i = 0; i < N; i++)
	{
		string name;
		int point;
		cin >> name >> point;
		point *= -1;
		info.push_back(make_tuple(name, point, i + 1));
	}

	sort(info.begin(), info.end());
	
	for (int i = 0; i < N; i++)
	{
		cout << std::get<2>(info[i]) << endl;
	}

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (n < k) return 0;
        return fact[n]*ifact[n-k];
    }
} comb(100005);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> graph[N]; // 0-indexed
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    mint ans = 1;
    int root = 0;
    vector<int> parent(N, -1);
    vector<int> order;
    stack<int> stk; // llかどうかに注意
    stk.push(root);
    while (!stk.empty()) {
        int cur = stk.top(); stk.pop();
        order.push_back(cur);
        if (cur == root) {
            ans *= comb.p(K, sz(graph[root]) + 1);
        } else {
            ans *= comb.p(K-2, sz(graph[cur]) - 1);
        }
        for (int next : graph[cur]) {
            if (next == parent[cur]) continue;
            parent[next] = cur;
            stk.push(next);
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		String[] tmpArray = input.split(" ");
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		
		String posStr = br.readLine();
		String[] postal = posStr.split("-", -1);
//		Pattern p = Pattern.compile("[\\d]++");
//		Matcher m = p.matcher(arg0)
		boolean available = false;
		if(posStr.charAt(a) != '-'){
			available = false;
		}
		else if(postal.length != 2){
			available = false;
		}
		
//		else if(!postal[1].equals("-")){
//			available = false;
//		}
		else if(postal[0].length() == a && Pattern.matches("\\d++", postal[0])
			&& postal[1].length() == b && Pattern.matches("\\d++", postal[1])){
			available = true;
		}
		
		if(available){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23252
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b){
        	int x = a;
        	a = b;
        	b = x;
        }
        if(a<=0 && b>=0){
        	System.out.println("Zero");
        }
        else if(a>0){
        	System.out.println("Positive");
        }
        else{
        	if((b-a)%2==0){
        		System.out.println("Negative");
        	}
        	else{
        		System.out.println("Positive");
        	}
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

int main() {
  int A, B, K;
  std::vector<int> v;

  cin >> A >> B >> K;

  for (int i = 0; i < K; ++i) {
    if (A + i <= B) v.push_back(A + i);
    if (B - i >= A) v.push_back(B - i);
  }

  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());

  for (auto tmp : v) {
    cout << tmp << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
using namespace std;
int main(void){
    string s ;
    string t ;
    cin >> s >> t ;
    size_t n = s.length() ;
    int ans = 0 ;
    rep(i , n){
        if(s[i] !=t[i]){
            ans++ ;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3912
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var q = from p in Console.ReadLine().Split(' ')
					select double.Parse(p);
			var aList = new List<double>(q);

			double t = 0;
			for (int i = 0; i < n; i++)
			{
				t += 1.0 / aList[i];
			}
			Console.WriteLine(1 / t);
		}
	}
}


Measured memory_bytes: 11348
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    if K[i] > 0:
        for j in range(n):
            res += (L[j]-1)//K[i]
        if res <= k:
            P.append(K[i])
print(min(P))


Measured memory_bytes: 30772
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int res = 0;
    vector<int> l(n);
    for(int i=0; i<n; ++i){cin >> l[i];}
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            for(int k=0; k<n; ++k){
                if(l[i]==l[j] || l[j]==l[k] || l[k]==l[i]){continue;}
                if(l[i]+l[j]<=l[k]){continue;}
                if(l[j]+l[k]<=l[i]){continue;}
                if(l[k]+l[i]<=l[j]){continue;}
                res++;
                
            }
        }
    }
    cout << res/6 << endl;
    return 0;
}

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

int a[128][128];
int b[128][128];

int main() {
  for(int N; cin >> N, N; ) {
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N; j++) cin >> a[i][j];

    memset(b, 0, sizeof(b));

    for(int i = 0; i < N; i++) {
      int small = 99999999;
      for(int j = 0; j < N; j++) {
        if( small > a[i][j] )
          small = a[i][j];
      }
      for(int j = 0; j < N; j++)
        if( a[i][j] == small )
          b[i][j] |= 1;
    }

    for(int j = 0; j < N; j++) {
      int tall = 0;
      for(int i = 0; i < N; i++) {
        if( tall < a[i][j] )
          tall = a[i][j];
      }
      for(int i = 0; i < N; i++)
        if( a[i][j] == tall )
          b[i][j] |= 2;
    }

    vector<int> v;    
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N; j++)
        if( b[i][j] == 3 )
          v.push_back( a[i][j] );

    if( v.empty() )
      cout << 0 << endl;
    else
      cout << *max_element( v.begin(), v.end() ) << endl;
    

  }

}

Measured memory_bytes: 0
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MOD = (ll)1e9+7;
const ll MAX = (ll)1e6;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
   ll X,Y;
   cin>>X>>Y;
   if ((X+Y)%3 != 0) {
      cout<<0<<endl;
      return 0;
   }
   ll m = X - (X+Y)/3;
   ll n = Y - (X+Y)/3;
   // cout<<n<<" "<<m<<endl;
   COMinit();
   ll ans = COM(n+m,n);
   cout<<ans<<endl;

   return 0;
}



Measured memory_bytes: 23680
use strict;
use warnings;
package SuffixArray;
#sub sa_is(\@$);
sub sa_is{
	my$upper=shift;
	my@s=@_;
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	elsif($n==2){
		if($s[0]<$s[1]){
			return(0,1);
		}
		else{
			return(1,0);
		}
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l;#=(0)x($upper+1);
	my@sum_s;#=(0)x($upper+1);
	for(0..$n-1){
		if($ls[$_]){
			$sum_l[$s[$_]+1]++;
		}
		else{
			$sum_s[$s[$_]]++;
		}
	}
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa;#=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(0..$n-1){
			my$v=$sa[$_];
			$sa[$buf[$s[$v-1]]++]=$v-1if$v>=1&&!$ls[$v-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms_map=(-1)x($n+1);
	my$m=0;
	my@lms=();
	for(1..$n-1){
		if(!$ls[$_-1]&&$ls[$_]){
			$lms_map[$_]=$m++;
			push@lms,$_;
		}
	}
	@sa=$induce->(@lms);
	if($m>0){
		my@sorted_lms;
		for(@sa){
			push@sorted_lms,$_ if$lms_map[$_]!=-1;
		}
		my@rec_s=();
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms_map[$l]+1<$m?$lms[$lms_map[$l]+1]:$n;
			my$end_r=$lms_map[$r]+1<$m?$lms[$lms_map[$r]+1]:$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$r==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=sa_is($rec_upper,@rec_s);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(255,@s);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 262592
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(",|\\s+");
		while (sc.hasNext()) {
			double[] xs = new double[4];
			double[] ys = new double[4];
			Point2D.Double[] ps = new Point2D.Double[4];
			for (int i = 0; i < 4; i++) {
				xs[i] = sc.nextDouble();
				ys[i] = sc.nextDouble();
				ps[i] = new Point2D.Double(xs[i], ys[i]);
			}
			Line[][] ls = new Line[4][2];
			for (int i = 0; i < 4; i++) {
				ls[i][0] = new Line(ps[i], ps[(i + 1) % 4]);
				ls[i][1] = new Line(ps[(i + 1) % 4], ps[i]);
			}
			boolean convex = false;
			double pro = 1;
			for (int i = 0; i < 4; i++) {
				pro *= ls[(i + 1) % 4][0].ep(ls[i][1]);
			}
			if (pro < 0) {
				convex = true;
			}
			System.out.println(convex ? "NO" : "YES");
		}
	}
}

class Line {
	public Point2D.Double p1;
	public Point2D.Double p2;

	Line(Point2D.Double p1, Point2D.Double p2) {
		this.p1 = p1;
		this.p2 = p2;
	}

	public double length() {
		return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y)
				* (p1.y - p2.y));
	}

	public double ip(Line l) {
		Point2D.Double q1 = l.p1;
		Point2D.Double q2 = l.p2;
		return (p2.x - p1.x) * (q2.x - q1.x) + (p2.y - p1.y) * (q2.y - q1.y);
	}

	public double ep(Line l) {
		Point2D.Double q1 = l.p1;
		Point2D.Double q2 = l.p2;
		return (p2.x - p1.x) * (q2.y - q1.y) - (p2.y - p1.y) * (q2.x - q1.x);
	}

	public double disToPoint(Point2D.Double q1) {
		Line p1q1 = new Line(p1, q1);
		double ip1 = p1q1.ip(this);
		double ip2 = this.ip(this);
		if (ip1 <= 0)
			return p1q1.length();
		else if (0 < ip1 && ip1 < ip2) {
			double d2 = ip1 / this.length();
			double size = p1q1.length();
			return Math.sqrt(size * size - d2 * d2);
		} else {
			Line p2q1 = new Line(p2, q1);
			return p2q1.length();
		}
	}

	public boolean isCross(Line q1q2) {
		Point2D.Double q1 = q1q2.p1;
		Point2D.Double q2 = q1q2.p2;
		Line p1q1 = new Line(p1, q1);
		Line p1q2 = new Line(p1, q2);
		Line q1p1 = new Line(q1, p1);
		Line q1p2 = new Line(q1, p2);
		if (this.ep(p1q1) * this.ep(p1q2) < 0
				&& q1q2.ep(q1p1) * q1q2.ep(q1p2) < 0)
			return true;
		else
			return false;
	}

	public double minDistance(Line q1q2) {
		if (this.isCross(q1q2))
			return 0;
		double ans = Double.MAX_VALUE;
		Point2D.Double q1 = q1q2.p1;
		Point2D.Double q2 = q1q2.p2;
		ans = Math.min(ans, this.disToPoint(q1));
		ans = Math.min(ans, this.disToPoint(q2));
		ans = Math.min(ans, q1q2.disToPoint(p1));
		ans = Math.min(ans, q1q2.disToPoint(p2));
		return ans;
	}

	public String toString() {
		return p1 + "=>" + p2;
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
    std::string str;
    int n, r;
    getline(std::cin, str, ' ');
    n = std::stoi(str);

    getline(std::cin, str);
    r = std::stoi(str);

    auto res = n >= 10? r : r + 100 * (10 - n);
    std::cout << res << std::endl;

    return 0;
}


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

int a[100010];

int main()
{
	register int n;
	scanf("%d", &n);
	for (register int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	for (register int i = n - 1; i >= 1; --i) {
		if (a[i + 1] >= a[i]) continue;
		--a[i];
		if (a[i + 1] >= a[i]) continue;
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

bool cp(string s)
{
  int n = s.size();
  for(int i = 0; i < n; i++)
  {
    if(s[i] != s[n - i - 1]) return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  if(cp(s) && cp(s.substr(0, n / 2)) && cp(s.substr(n / 2 + 1, n / 2)))
  {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	string x, y ,z;
	cin >> x >> y >> z;
	cout << (x[x.size() - 1] == y[0] && y[y.size() - 1] == z[0] ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <algorithm>    // std::min_element, std::max_element
using namespace std;


int main(){
    
    int c = 0; //count how many input sets
    int l; //entire length
    int n; // number of branches
    int m; //number of orders
    vector<int> v;
    int sum;
    
    
    for(;; c++){
        
        sum = 0;
        cin >> l;
        if(l == 0)
            break;
        cin >> n;
        cin >> m;
        
        vector<int> d; //from 4th to n-1 line on txt
        d.push_back(0);
        int k[m]; //coustomer k1' house at k[0] meater     n+3 to m line
        int minRoute[m];
        
        for(int i = 1; i < n; i++){
            int in;
            cin >> in;
            d.push_back(in);
        }
        
        for(int i = 0; i < m; i++)
            cin >> k[i];
        
        std::sort(d.begin(), d.end());

        for (int j = 0; j < m; j++){
            
            for (int i = 0; i < n; i++){
                
                if ( k[j] < d[i] ){
                    minRoute[j] = min(d[i] - k[j], k[j] - d[i-1]);
                    break;
                }else if (d[n-1] <= k[j]){
                    minRoute[j] = min(k[j] - d[n-1], l - k[j]);
                    break;
                }
            }
            
            sum += minRoute[j];
        }
        v.push_back(sum);
    }
    
    for (int i = 0; i < c; i++)
        cout << v[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3424
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

void solve(ll A, ll B, ll C) {
  int ans{0};
  if (A%2 || B%2 || C%2) {
    ans = 0;
  } else if (A==B && B==C) {
    ans = -1;
  } else {
    while(A%2==0 && B%2==0 && C%2==0) {
      int newA = (B+C)/2;
      int newB = (A+C)/2;
      C = (A+B)/2;
      A = newA;
      B = newB;
      ++ans;
    }
  }
  cout << ans << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let (n, k) = input();
    println!("{}", solve(n, k));
}

fn input() -> (usize, usize) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut buf = buf.split_whitespace();
    let n: usize = buf.next().unwrap().parse().unwrap();
    let k: usize = buf.next().unwrap().parse().unwrap();
    (n, k)
}

fn solve(n: usize, k: usize) -> usize {
    let mut ans: usize = 0;
    for m in k..n+2 {
        let min = m*(m-1)/2;
        let max = (2*n-m+1)*m/2;
        ans += max - min + 1;
    }
    ans % 1000000007
}

Measured memory_bytes: 2108
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RDR.ARR;
	long o, e;
	foreach (i; 0..N)
	{
		if (A[i] % 2 == 0)
			++e;
		else
			++o;
	}
	e += o / 2;
	e  = e >= 1 ? 1 : 0;
	o  = o % 2;

	writeln(o+e == 1 ? "YES" : "NO");
	stdout.flush();
	debug readln();
}


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

int main() {

  int A, B, C, D;

  cin >> A >> B >> C >> D;

  int left = A + B;
  int right = C + D;

  if (left == right) {
    cout << "Balanced" << endl;
  } else if (left < right ) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
int main(void){
    long int n, d, j=0, ans=0;
    scanf("%ld%ld", &d, &n);
    if(d==0){
        ans=0;
        while(1){
            if(ans%100 != 0){
                j++;
            }
            if(j==n) break;
            ans++;
        }
    }
    else if(d==1){
        ans=100;
        while(1){
            if(ans%100==0 && ans%10000!=0){
                j++;
            }
            if(j==n) break;
            ans=ans+100;
        }
    }
    else if(d==2){
        ans=10000;
        while(1){
            if(ans%10000==0 && ans%1000000!=0){
                j++;
            }
            if(j==n) break;
            ans=ans+10000;
        }
    }

    printf("%ld\n", ans);
    return 0;
    
}
            


Measured memory_bytes: 128
def tsort(key,inCnt,out)
	s = []
	ret = []
	key.each do |v|
		s << v if inCnt[v] == 0
	end
	while v = s.shift
		ret << v
		out[v].each do |u|
			inCnt[u] -= 1
			s << u if inCnt[u] == 0
		end
	end
	return ret
end

N,M = gets.split.map(&:to_i)
dp = [0]*(N+1)
inCnt= [0]*(N+1)
vin = (N+1).times.map{[]}
vout = (N+1).times.map{[]}

M.times do
	x,y = gets.split.map(&:to_i)
	inCnt[y] += 1
	vin[y] << x
	vout[x] << y
end

list = tsort((1..N),inCnt,vout)

list.each do |t|
	max = -1
	vin[t].each do |j|
		max = dp[j] if max < dp[j]
	end
	dp[t] = max+1
	#p [t,vin[t],dp[t]]
end
p dp.max

Measured memory_bytes: 27772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if((b-1-a)%2==0) printf("Borys");
	if((b-1-a)%2==1) printf("Alice");
	return 0;
}

Measured memory_bytes: 256
/* Volume0-0001(山の高さ) */

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

public class Main {
  public static void main (String[] args) throws java.lang.Exception {
    // 入力された値をゲット
    Scanner sc = new Scanner(System.in);

    // 10個の要素を持つ配列を作成
    Integer[] yama = new Integer[10];

    // 入力値を配列にセット(10×繰り返し)
    for(int i=0; i<10; i++) {
      yama[i] = sc.nextInt();
    }

    // 降順で並び替え
    Arrays.sort(yama, Collections.reverseOrder());

    // 上位３つを画面に出力
    System.out.println(yama[0]);
    System.out.println(yama[1]);
    System.out.println(yama[2]);
  }
}



Measured memory_bytes: 26048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007

int main(){

    ll n,t,a,A=1,B=1;
    cin >> n;
    ll j = 1;
    REP(n){
        
        ll tmp;
        cin >> t >> a;
        if(A/t == 0 && B/a == 0){
            tmp = 1;
        }else{
            tmp = max((A+t-1)/t,(B+a-1)/a);
        }
        //cout << tmp << endl;
        A = t*tmp;
        B = a*tmp;
        //cout << A << " " << B << endl;
    }


    cout << A+B << endl;





    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class BitMax:
    def __init__(self, n):
        self.n = n + 3
        self.table = [0] * (self.n + 1)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            if x > self.table[i]: self.table[i] = x
            i += i & -i

    def max(self, i):
        i += 1
        res = 0
        while i > 0:
            if self.table[i] > res: res = self.table[i]
            i -= i & -i
        return res

def main():
    n = int(input())
    hh = LI()
    aa = LI()
    dp = BitMax(n + 1)
    for h, a in zip(hh, aa):
        dp.update(h, dp.max(h - 1) + a)
    print(dp.max(n))

main()


Measured memory_bytes: 35204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	static class Task {
        public void solve(InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	ArrayList<Integer> nums = new ArrayList<Integer>();
        	for(int i=0; i<n; i++) {
        		nums.add(in.nextInt());
        	}
        	int max = Collections.max(nums);
        	int sum = 0;
        	for(int i=0; i<n; i++) {
        		sum += nums.get(i);
        	}
        	Boolean ans = sum-max > max ? true : false;
        	if(ans)
        		out.println("Yes");
        	else
        		out.println("No");
        }
    }
	
    public static void main(String argds[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
    }	
}

Measured memory_bytes: 21460
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: i64 = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let M: usize = sc.get();
    let mut a = vec![0; M];
    let mut c = vec![0; M];
    for i in 0..M {
        a[i] = sc.get();
        let b: usize = sc.get();
        for _ in 0..b {
            let ci: usize = sc.get();
            c[i] |= 1<<(ci-1);
        }
    }
    let mut dp = vec![vec![INF; 1<<N]; M+1];
    dp[0][0] = 0;
    for i in 0..M {
        for k in 0..1<<N {
            if k | c[i] != k {
                dp[i+1][k | c[i]] = min(dp[i+1][k | c[i]], dp[i][k] + a[i]);
            }
            dp[i+1][k] = min(dp[i+1][k], dp[i][k]);
        }
    }
    if dp[M][(1<<N)-1] != INF {
        println!("{}", dp[M][(1<<N)-1]);
    } else {
        println!("-1")
    }
}


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


int main()
{
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2))
    puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 256
#define RAD M_PI/180
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	int  move, angle;
	double x = 0, y = 0, theta = 90;
	
	while (scanf("%d,%d", &move, &angle), (move != 0) && (move != 0)) {
		x += (double)move * cos(theta*RAD); y += (double)move * sin(theta*RAD);
		theta -= angle;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	return 0;
}

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

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

    int x = 0;
    for (int i = 1; i < 1000005; i++) {
        x = x * 10 + 7;
        if (x % k == 0) {
            cout << i << endl;
            return 0;
        }
        x %= k;
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	
	int s;
	Mat[] mats;
	int[] mem;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;

			Mat[] matA = new Mat[n];
			for(int i=0;i<n;i++) matA[i] = new Mat(sc.nextInt(), sc.nextInt());
			
			int m = sc.nextInt();
			Mat[] matB = new Mat[m];
			for(int i=0;i<m;i++) matB[i] = new Mat(sc.nextInt(), sc.nextInt());
			
			s = n+m;
			mats = new Mat[s];
			for(int i=0;i<n;i++) mats[i] = new Mat(matA[i].x, matA[i].y);
			for(int j=0;j<m;j++) mats[n+j] = new Mat(matB[j].x, matB[j].y);
			sort(mats);
			
			mem = new int[s];
			fill(mem, -1);
			
			dfs(0);
			
			int max = 0;
			for(int i=0;i<s;i++) max = max(max, mem[i]);
			System.out.println(max);
		}
	}
	
	int dfs(int i) {
		if( mem[i] > 0 ) return mem[i];
		
		int max = 1;
		for(int j=i+1;j<s;j++) if( mats[j].x > mats[i].x && mats[j].y > mats[i].y ) {
			max = max(max, dfs(j) + 1);
		}
		
		return mem[i] = max;
	}
	
	class Mat implements Comparable<Mat> {
		int x, y;
		Mat(int x, int y) {
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Mat o) {
			// TODO 自動生成されたメソッド・スタブ
			return x - o.x;
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
n = int(input())

m = [[0] * 10 for _ in range(10)]

for a in range(1, n + 1):
  s = str(a)
  t = int(s[0])
  b = int(s[-1])
  m[b][t] += 1

ans = 0
for a in range(1, n + 1):
  s = str(a)
  t = int(s[0])
  b = int(s[-1])
  ans += m[t][b]

print(ans)


Measured memory_bytes: 3064
import math

m = [0,0,-1]
mem = [[-1 for i in range(3200)] for j in range(3200)]

def cal(a,b):
    try:
        return 100 * b / (a + b)
    except:
        return 0

def dfs(water,suger,p,nums):
    global m
    global mem
    
    if water+suger > nums[5]: pass
    elif mem[water][suger] == -1: 
        mem[water][suger] = cal(water,suger)
    else:
        return mem[water][suger]


    if water != 0 and ((suger / water > nums[4] / 100 ) or (water + suger > nums[5])):
        return p

    if m[2] < cal(water,suger):
        m = [water,suger,cal(water,suger)]

    ans = max(
            dfs(water + nums[0] * 100, suger, cal(water,suger), nums),
            dfs(water + nums[1] * 100, suger, cal(water,suger), nums),
            dfs(water, suger + nums[2], cal(water,suger),nums),
            dfs(water, suger + nums[3], cal(water,suger),nums)
            )
    return ans


nums = [int(x) for x in input().split()]
A,B = nums[0],nums[1]
dfs(nums[0]*100,0,0,nums)
dfs(nums[1]*100,0,0,nums)
print(str(m[0]+m[1]) + " " + str(m[1]))

Measured memory_bytes: 87028
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;


int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    if(k == 1){
        cout << 0 << endl;
    }else{
        cout << n - k << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in );
		
		int []pow=new int [6];
		pow[0]=1;
		for(int i=1;i<=5;i++)
			pow[i]=2*pow[i-1];
		int n=sc.nextInt();int m=sc.nextInt();
		int ans=(n-m)*100+1900*m;
		System.out.println(pow[m]*ans);
		
		
		
		
		
	}
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
		
		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}
		
		public boolean ready() throws IOException {return br.ready();}


	}
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>

void sort1(char *s, int n);
void sort2(char *s, int n);

int main(void)
{
    int ns, nt;
    char s[101], t[101];

    scanf("%s", s);
    scanf("%s", t);

    ns = strlen(s);
    nt = strlen(t);

    sort1(s, ns);
    sort2(t, nt);

    if (strcmp(s,t)<0)  printf("Yes\n");
    else                printf("No\n");

    return 0;
}

void sort1(char *s, int n)
{
    int i, j, m;
    char tmp;

    for (i=0; i<n-1; i++) {
        m = i;
        for (j=i+1; j<n; j++) {
            if (s[j]<s[m])  m=j;
        }
        tmp=s[i]; s[i]=s[m]; s[m]=tmp;
    }
}

void sort2(char *s, int n)
{
    int i, j, m;
    char tmp;

    for (i=0; i<n-1; i++) {
        m = i;
        for (j=i+1; j<n; j++) {
            if (s[j]>s[m])  m=j;
        }
        tmp=s[i]; s[i]=s[m]; s[m]=tmp;
    }
}

Measured memory_bytes: 128
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
node = [0]*(N)
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    node[a] ^= 1
    node[b] ^= 1

if any(node):
    print("NO")
else:
    print("YES")


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

int main() {
  string n;
  cin >> n;
  for(int i = 0; i < 3; i++) {
    if(n.at(i) == '1')
      n.at(i) = '9';
    else
      n.at(i) = '1';
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i,j,k,ans=0,n,h;
	scanf("%d %d",&k,&n);
	for(i=0;i<=k;i++)
		for(j=0;j<=k;j++)
		{
			h=n-i-j;
			if(h>k) continue;
			else if(h<0) continue;
			else ans++;
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
ll n;
inline ll doit(ll n) {
	if(n==1) return 1;
	return 2*doit(n/2)+1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n,cout<<doit(n)<<'\n';
	cout<<flush;	 
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

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

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

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		int count = 0;
		int[] ans = new int[6];
		int[] pasta = new int[3];
		int[] juice = new int[2];
		
		for(int r = 0; r < 3; r++) {
			pasta[r] = stdIn.nextInt();
		}
		for(int r = 0; r < 2; r++) {
			juice[r] = stdIn.nextInt();
		}
		
		for(int r = 0; r < pasta.length; r++) {
			for(int c = 0; c < juice.length; c++) {
				ans[count++] = pasta[r] + juice[c] - 50;
			}
		}
		int min = ans[0];
		for(int r = 1; r < ans.length; r++) {
			if(ans[r] < min) min = ans[r];
		}
		System.out.println(min);
		
	}

}

Measured memory_bytes: 17308
#include <iostream>
#include <string>
#include <set>
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
#include <cmath>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;
typedef pair<double, P> E;

struct Node{
	llint left, right, val;
	Node(){
		left = -1, right = -1, val = 0;
	}
};

string s, t;
vector<Node> S, T, U;

llint p;

llint num(string &s, llint n)
{
	llint ret = 0;
	while(1){
		if(s[p] < '0' || s[p] > '9') break;
		ret *= 10, ret += s[p]-'0';
		p++;
	}
	return ret;
}

llint dec(string &s, vector<Node> &vec, llint &p)
{
	if(s[p] != '(') return -1;
	
	vec.push_back(Node());
	llint root = (int)vec.size()-1;
	
	p++;
	llint l = dec(s, vec, p);
	p++;
	
	p++;
	llint res = num(s, p);
	p++;
	vec[root].val = res;
	
	p++;
	llint r = dec(s, vec, p);
	p++;
	
	vec[root].left = l, vec[root].right = r;
	
	return root;
}

llint calc(llint u, llint v)
{
	U.push_back(Node());
	llint root = (int)U.size()-1;
	U[root].val = S[u].val + T[v].val;
	
	if(S[u].left != -1 && T[v].left != -1){
		llint res = calc(S[u].left, T[v].left);
		U[root].left = res;
	}
	if(S[u].right != -1 && T[v].right != -1){
		llint res = calc(S[u].right, T[v].right);
		U[root].right = res;
	}
	return root;
}

void enc(int v)
{
	if(v == -1) return;
	
	cout << "(";
	enc(U[v].left);
	cout << ")";
	
	cout << "[";
	cout << U[v].val;
	cout << "]";
	
	cout << "(";
	enc(U[v].right);
	cout << ")";
}

int main(void)
{
	cin >> s >> t;
	s += "#", t += "#";
	
	p = 0;
	llint rootS = dec(s, S, p);
	
	p = 0;
	llint rootT = dec(t, T, p);
	
	llint rootU = calc(rootS, rootT);
	
	enc(rootU);
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
bool mem[3010];
int a, b, c, d, f, e;
vector <int> v1, v2;
void doo(int x){
  if(x>f)
    return;
  if(mem[x])
    return;
  mem[x]=1;
  v1.push_back(x);
  doo(x+100*a);doo(x+100*b);
  return;
}
void doo2(int x){
  if(x>f)
    return;
  if(mem[x])
    return;
  mem[x]=1;
  v2.push_back(x);
  doo2(x+c);doo2(x+d);
  return;
}
int main(){
  while(cin>>a>>b>>c>>d>>e>>f){
    memset(mem, 0, sizeof mem);
    v1.clear();v2.clear();
    doo(0);
    memset(mem, 0, sizeof mem);
    doo2(0);
    int tmp, tmp2, ans1=0, ans2=a*100;
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for(int i=0; i<v1.size(); ++i){
      if(v1[i]>f)
        break;
      tmp=min(f-v1[i], v1[i]/100*e);
      tmp2=0;
      for(int j=0; j<v2.size(); ++j){
        if(v2[j]>tmp)
          break;
        tmp2=v2[j];
      }
      if(ans1*(v1[i]+tmp2)<ans2*(tmp2)){
        ans1=tmp2;ans2=v1[i]+tmp2;
      }
    }
    printf("%d %d\n",ans2, ans1);
  }
  return 0;
}




Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    int A, B, H, M;
    while (cin >> A >> B >> H >> M) {
        H %= 12;
        M %= 60;
        long double AH, AM;
        // if (H * 5 < M) {
        AM = M * 6.0;
        AH = H * 30.0 + (30.0 / 60) * M;
        // }
        long double angle = fabs(AM - AH);
        if (angle > 180)
            angle = 360 - angle;

        long double ans =
            sqrt(A * A + B * B - 2 * A * B * cos((angle / 180) * acos(-1)));
        cout << setiosflags(ios::fixed) << setprecision(20) << ans << endl;
    }

    return 0;
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,m,a,b,c,cnt[1000],memo[1000];
vector<pair<int,int>> v[1000];
priority_queue<pair<int,int>> pq;

signed main() {
    rep(i,1000) memo[i] = -INF;
    cin >> n >> m;
    rep(i,m) cin >> a >> b >> c, a--, b--, v[a].pb(mp(c,b));
    rep(i,v[0].size()) pq.push(v[0][i]);
    while(!pq.empty()) {
        int cost = pq.top().fi, to = pq.top().se;pq.pop();
        if (memo[to] >= cost) continue;
        memo[to] = cost;
        cnt[to]++;
        if (cnt[n-1] > n) {cout << "inf" << endl;return 0;}
        rep(i,v[to].size()) if (cnt[v[to][i].se] <= n*5) pq.push(mp(v[to][i].fi + cost, v[to][i].se));
    }
    cout << memo[n-1] << endl;
}


Measured memory_bytes: 18540