akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  ll A; string B;
  cin >> A >> B;
  ll b = atoi((B.substr(0, B.size()-3) + B.substr(B.size()-2)).c_str());
  cout << A * b / 100 << endl;
  // ll n = A * B * 100;
  // cout << n / 100 << endl;

  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.valueOf(sc.next());
		int w = Integer.valueOf(sc.next());

		int[][] table = new int[n][2];
		for (int i = 0; i < table.length; i++) {
			for (int j = 0; j < table[i].length; j++) {
				table[i][j] = Integer.valueOf(sc.next());
			}
		}

		long[][] dp = new long[n][(int) Math.pow(10, 3) * 100 + 1];
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[i].length; j++) {
				dp[i][j] = Long.MAX_VALUE;
			}
		}
		for (int i = 0; i <= table[0][1]; i++) {
			dp[0][i] = table[0][0];
		}
		dp[0][0] = 0;

		for (int i = 1; i < dp.length; i++) {
			for (int j = 0; j < dp[i].length && dp[i - 1][Integer.max(j - table[i][1], 0)] != Long.MAX_VALUE; j++) {
				dp[i][j] = Long.min(dp[i - 1][j], dp[i - 1][Integer.max(j - table[i][1], 0)] + table[i][0]);
			}
		}

		for (int i = dp[dp.length - 1].length - 1; i >= 0; i--) {
			if (dp[dp.length - 1][i] <= w) {
				System.out.println(i);
				break;
			}
		}

		sc.close();
	}

}


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

using namespace std;

int  clock(int a, int b, int k){
	if(a < b){
		if(a==0){
			return b;
		}else return b - a;
	}else if(b==0){
		return k-a;
	}else return k - (a - b);
}
int neclock(int a, int b , int k){
	if(a < b){
		if(a == 0){
			return k - b;
		}else return k - (a - b);
	}else if(b == 0){
		return a;		
	}else return a - b;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long k, n,temp, mn = 100000000;
	cin >> k >> n;
	vector<int> vec(n);
	for(int i = 0; i < n; i++){
		cin >> vec[i];
	}
	sort(vec.begin(),vec.end());
	
	for(int i = 0; i < n; i++){
		if(i==0)
		{
			temp = min(clock(vec[i],vec[n-1],k),neclock(vec[i],vec[i+1],k));
		//	cout << temp << endl;
			
		}else if(i == n-1){
			
			temp = min(clock(vec[i],vec[i-1],k),neclock(vec[i],vec[0],k));
			//cout << clock(vec[i],vec[i-1],k)<< " "<< neclock(vec[i],vec[0],k);
		//	cout << temp << endl;
			
		}else{
			temp = min(clock(vec[i],vec[i-1],k),neclock(vec[i],vec[i+1],k));
		//	cout << temp << endl;
		}
		if(mn > temp){
		mn = temp;
		}
	}
	cout << mn;
	
	
	
	
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1) break;
			else if (m == -1 || f == -1) System.out.println("F");
			else if (m + f >= 80) System.out.println("A");
			else if (m + f >= 65 && m + f < 80) System.out.println("B");
			else if (m + f >= 50 && m + f < 65) System.out.println("C");
			else if (m + f >= 30 && m + f < 50) {
				if (r >= 50) System.out.println("C");
				else System.out.println("D");
			}
			else if (m + f < 30) System.out.println("F");
		}
	}
}

Measured memory_bytes: 26268
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
int c[1<<24];
int main(){
  int i,j;
  int n;
  scanf("%d",&n);
  int g=0;
  for(i=0;i<n;++i)
    g|=i<<i*3;
  int a[8][8];
  for(i=0;i<n;++i)
    for(j=0;j<n;++j)
      scanf("%d",&a[i][j]);
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > b;
  b.push(make_pair(0,g));
  memset(c,-1,(1<<n*3)*sizeof(int));
  c[g]=0;
  while(!b.empty()){
    int p,q;
    p=b.top().first;
    q=b.top().second;
    b.pop();
    for(i=0;i<n;++i){
      int s=(q&(7<<i*3))>>i*3;
      for(j=0;j<n;++j){
	int t=(q&(7<<j*3))>>j*3;
	int u=(((q&~(7<<i*3))|(t<<i*3))&~(7<<j*3))|(s<<j*3);
	if(i==j||(c[u]>=0&&c[u]<=p+a[s][t]))
	  continue;
	c[u]=p+a[s][t];
	b.push(make_pair(c[u],u));
      }
    }
  }
  int mx=0;
  for(i=0;i<(1<<n*3);++i)
    mx=max(mx,c[i]);
  printf("%d\n",mx);
  return 0;
}

Measured memory_bytes: 65000
INF=100100100

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    t=list(map(int,input().split()))
    c.append(t[0])
    a.append(t[1:])
cost=INF
for i in range(2**n):
    ab=[0]*m
    tmp=0
    for j in range(n):
        idx=i>>j & 1
        if(idx):
            tmp+=c[j]
            for k in range(m):
                ab[k]+=a[j][k]
    for k in range(m):
        if(ab[k]<x):break
    else:cost=min(cost,tmp)
if(INF==cost):print(-1)
else:print(cost)

Measured memory_bytes: 9224
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll calc(char c) {
    if(c == 'r') {
        return 0;
    }
    if(c == 's') {
        return 1;
    }
    if(c == 'p') {
        return 2;
    }
}

int main() {
    ll n, k;
    cin >> n >> k;

    vl rsp(3);
    rep(i, 3) {
        cin >> rsp[i];
    }

    string t;
    cin >> t;

    vvl dp(n+1, vl(3));  // dp[i][j] : i回目(iは0-index)に自分がj('r' = 0, 's' = 1, 'p' = 2)を出すとき i mod.k の手番についての得点の総和の最大値
    rep(i, n) {
        rep(j, 3) {
            if(i >= k) {
                rep(x, 3) {
                    if(j != x) {
                        chmax(dp[i][j], dp[i-k][x]);
                    }
                }
            }
            if((j+1)%3 == calc(t[i])) {
                dp[i][j] += rsp[j];
            }
        }
    }

    ll ans = 0;
    rep(i, k) {
        ll now = 0;
        rep(j, 3) {
            chmax(now, dp[n-1-i][j]);
        }
        ans += now;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;

    set<int> coins;
    for(int i=0; pow(6,i)<=N; ++i) coins.insert(pow(6,i));
    for(int i=0; pow(9,i)<=N; ++i) coins.insert(pow(9,i));
    const int inf = 1<<15;
    vector<int> dp(1001000, inf);

    dp[0] = 0;

    REP(i, N+1){
        for(auto x: coins){
            if(i>=x) chmin(dp[i], dp[i-x]+1);
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 4096
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
int N;
bool flags[101];

int main()
{
    cin>>N;
    for (int i=0;i<N;i++){
        int d;
        cin>>d;
        flags[d]=true;
    }
    int sum;
    for (int i=1;i<101;i++){
        if (flags[i]==true){
            sum++;
        }
    }
    cout<<sum<<endl;
}


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



int main(void){
    int X, Y;
    scanf("%d%d", &X, &Y);
    if(X==1 && Y==1)printf("1000000\n");
    else{
        int ans = 0;
        if(X<=3)ans += (4-X) * 100000;
        if(Y <= 3)ans += (4-Y) * 100000;
        printf("%d\n", ans);
    }
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        int xor = a[0];
        for(int i = 1; i < n; i++){
            xor ^= a[i];
        }

        for(int i = 0; i < n; i++){
            System.out.println(a[i] ^ xor);
        }

    }
}


Measured memory_bytes: 59876
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n[4];
	for (int i = 0; i < 4; ++i) {
		cin >> n[i];
	}
	if (n[0] == n[1] && n[2] == n[3] || n[2] == n[1] && n[0] == n[3] || n[0] == n[2] && n[1] == n[3]) {
		cout << "yes" << endl;
	}
	else cout << "no" << endl;
}


Measured memory_bytes: 3112
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
}

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

int main(){
  int N;
  double f=0;
  cin>>N;
  int c[N][2],a[N];
  int fact[9];
  fact[1]=1;
  for(int i=2;i<=8;i++) fact[i]=i*fact[i-1];
  for(int i=0;i<N;i++) {cin>>c[i][0]>>c[i][1];a[i]=i;}
  do{
    for(int i=0;i<N-1;i++){
      int j=a[i],k=a[i+1];
      float dx=c[j][0]-c[k][0];
      float dy=c[j][1]-c[k][1];
      f+=sqrt(dx*dx+dy*dy);
    	}
   
    }while(next_permutation(a,a+N));
  printf("%.8f",f/fact[N]);
}

Measured memory_bytes: 256
a,b = map(int,input().split())
s = list(input())
ans = "No"
if not "-" in s[0:a] and s[a] == "-" and not "-"  in s[a+1:]:
  ans = "Yes"
# for i in range(len(s)):
#   if i == a and s[i] == "-":
#     ans = "Yes"
#   elif i != a and s[i] == "-":
#     ans = "No"
print(ans)

Measured memory_bytes: 2940
#https://atcoder.jp/contests/dp/tasks/dp_b
import sys
inf = sys.maxsize

n, k = map(int,input().split())
h = [int(i) for i in input().split()]

dp = [0 for _ in range(n)]
dp[0] = 0

for i in range(1, n): #段数
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(k, i) + 1)])
    '''
    tmp = inf
    for j in range(1, k + 1): #一度に登る段数
        if i - j >= 0:
            tmp = min(tmp, dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = tmp
    '''

print(dp[n - 1])

Measured memory_bytes: 56672
a, b, c = [int(x) for x in input().strip().split()]
k = int(input())

while (b<=a or c<=b) and k:
    
    if b<=a:
        b = b*2
    else:
        c = c*2
    
    k-=1

if a<b<c:
    print('Yes')
else:
    print('No')
    

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

int n;

int solve(int i,int m){
    if(m==0) return 1;
    if(i>n) return 0;

    int ans = solve(i+1,m-i);

    return ans;
}

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

        if(n==0)break;

        int count = 0;

        for(int i=1; i<n; i++){
            if(solve(i,n))count++;
        }

        cout<<count<<endl;
    }

        return 0;

}


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

int main()
{
	int n, x,way=0;
	while (1)
	{
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		else
		{
			for (int a = 1; a <= n; a++)
			{
			   for (int b = a + 1; b <= n; b++)
			   {
				   for (int c = b + 1; c <= n; c++)
				   {
					   if (a + b + c == x) way++;
				   }
			   }
			}
			cout << way << endl;
			way = 0;
		}
	}
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int N,K;
    cin >> N >> K;
    
    int p = 0;
    double P[N+1];
    P[0] = 0;
    
    for(int i=1;i<=N;i++){
        cin >> p;
        P[i] = P[i-1]+(double)(1+p)/2;
    }
    
    double ans = 0;
    for(int i=K;i<=N;i++){
        ans = max(ans,P[i]-P[i-K]);
    }
    
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N, A, B;
    cin >> N >> A >> B;
    if(A==0 && B==0){
        cout << 0 << el;
        return;
    }
    ll ans = (N/(A+B))*A + min(N%(A+B), A);
    cout << ans << el;
}



Measured memory_bytes: 256
#include<stdio.h>



int main()
{
	int time ;

	while( 1 )
	{
		scanf( "%d" ,&time ) ;

		if( time == 0 )
		{
			return 0 ;
		}


		int study = 0 ;

		int n ;
		int t1 ,t2 ;

		scanf( "%d" ,&n ) ;

		while( n-- )
		{
			scanf( "%d %d" ,&t1 ,&t2 ) ;


			study += ( t2 - t1 ) ;
		}


		if( study < time )
		{
			printf( "%d\n" ,time - study ) ;
		}

		else
		{
			puts( "OK" ) ;
		}
	}
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;

int main(){
  int a,b,c,x;
  cin >> a >> b >> c;

  int ret = 0;
  // 全てを奇数 or 偶数にする

  if(a%2==0 && b%2==0 && c%2==1){ a++; b++; ret++; }
  else if(a%2==0 && b%2==1 && c%2==0){ a++; c++; ret++; }
  else if(a%2==0 && b%2==1 && c%2==1){ b++; c++; ret++; }
  else if(a%2==1 && b%2==0 && c%2==0){ b++; c++; ret++; }
  else if(a%2==1 && b%2==0 && c%2==1){ a++; c++; ret++; }
  else if(a%2==1 && b%2==1 && c%2==0){ a++; b++; ret++; }

  x = max(a,max(b,c));

  ret += (x-a)/2 + (x-b)/2 + (x-c)/2;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = [int(_) for _ in input().split()]

ab = []
for i in range(n):
    ab.append([int(_) for _ in input().split()])

ab.sort(key=lambda x:x[0])

money = 0
n_dri = 0
for i in range(len(ab)):
    mon_num = ab[i]
    if n_dri + mon_num[1] < m:
        money += mon_num[0] * mon_num[1]
        n_dri += mon_num[1]
    else:
        money += mon_num[0] * (m - n_dri)
        print(money)
        exit()

Measured memory_bytes: 22752
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

bool ch(int a[], int N){
	rep(i,N)if(a[i]>0)return false;
	return true;
}

int main(){
	int N; cin>>N;
	int garden[114];
	rep(i,N)cin>>garden[i];
	queue<int> Q;
	Q.push(0);
	int ans = 0;
	bool al = true;
	while(!Q.empty() && !ch(garden,N)){
		int head = Q.front();
		Q.pop();
		bool al = false;
		while(garden[head]>0 && head <N){
			--garden[head];
			++head;
			al = true;
		}
		if(head != N)Q.push(head+1);
		else Q.push(0);
		if(!al)continue;
		++ans;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
  unsigned long long A, B;
  cin >> A >> B;

  unsigned long long X = A * B;

  if ( A < B )
  {
    unsigned long long temp = A;
    A = B;
    B = temp;
  }

  unsigned long long r = A % B;
  while(r!=0){
    A = B;
    B = r;
    r = A % B;
  }

  cout << X/B << endl;
  
  return 0;
}


Measured memory_bytes: 256
memo = {}
def solve(p, t):
  key = "{}:{}".format(p, t)
  if key in memo: return memo[key]
  if p >= len(A): return False
  if t == A[p]: return True
  if t <= 0: return False
  #print("({}, {})".format(p, t))

  if solve(p + 1, t):
    memo["{}:{}".format(p + 1, t)] = True
    return True
  else:
    memo["{}:{}".format(p + 1, t)] = False
    return solve(p + 1, t - A[p])

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

for t in M:
  if solve(0, t): print("yes")
  else: print("no")

Measured memory_bytes: 11076
import java.util.*;

public class Main {
 
   public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] nums = new int[n];

        for (int i = 0;i < n;i++) {
            nums[i] = s.nextInt();
            //System.out.println(nums[i]);
        }
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1]-nums[0]);
        for (int i = 2;i < n;i++) {
            dp[i] = Math.min(dp[i-1]+Math.abs(nums[i]-nums[i-1]),dp[i-2]+Math.abs(nums[i]-nums[i-2]));
        }

        System.out.println(dp[n-1]);
    }
  
}

Measured memory_bytes: 50432
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  int x;
  int y;
  int a = 0;
  cin >> x;
  cin >> y;
  vector<int> vec(y);
  for (int i = 0; i < y; i++) {
    cin >> vec.at(i);
    a = x -= vec.at(i);
    if (a <= 0) {
      cout << "Yes";
      exit(0);
    } else {
      continue;
    }
  }
  cout << "No";
}

Measured memory_bytes: 640
import java.util.*;


public class Main {
    public static void main(String[] args) {
        int i;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long []x = new long[n];
        long []y = new long[m];
        for(i = 0;i < n; i++)
            x[i] = sc.nextLong();
        for(i = 0;i < m; i++)
            y[i] = sc.nextLong();

        long ans = 0;
        long WidthSum = 0;
        long HeightSum = 0;
        for (i = 0;i < n;i++){
            WidthSum += i * x[i] - (n - 1 - i) * x[i];
            WidthSum %= (1000000000 + 7);
        }
        for (i = 0;i < m; i++){
            HeightSum += i * y[i] - (m - 1 - i) * y[i];
            HeightSum %= (1000000000 + 7);
        }
        ans += WidthSum * HeightSum % (1000000000+7);
        System.out.println(ans);
    }
}

Measured memory_bytes: 81788
#pragma GCC optimize ("O2") // "Ofast" for REAL FAST
// #pragma GCC optimization ("unroll-loops")

// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#include <bits/stdc++.h>
#define DEBUG 0

using namespace std;

#define rep(i, a, b) for (i = (a); i < (b); i++)
#define trav(a, x) for (auto & a : x)
#define all(x) (x).begin (), (x).end ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair <int, int> pii;
#define f first
#define s second
#define mp(x, y) make_pair (x, y)

typedef vector <int> vi;
#define pb(x) push_back (x)

#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7; // UPDATE

int main ()
{
    FASTIO;
    int i = 0, j, k = 5;
    scanf ("%d", &j);
    ddprintf ("%d\n", j);
    while (j > 0 && j%100)
    {
        while (j > 0 && (j%100) > ((j-k)%100))
        {
            ddprintf ("%d, %d, %d\n", j, (j%100), ((j-k)%100));
            j -= 100 + k;
        }
        ddprintf ("%d\n", j);
        --k;
    }
    if (j >= 0)
        printf ("1\n");
    else
        printf ("0\n");

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            WriteLine(A+B/2);
        }

        static long GcdArray(long[] array)
        {
            var ans = array[0];
            for(var i=1; i<array.Length; i++)
            {
                ans = Gcd(ans, array[i]);
            }
            return ans;
        }

        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
package main

import (
        "fmt"
)

func babble(in []int) []int {
        tin := in
        for ii := 0; ii < len(tin)-1; ii++ {
                for jj := ii + 1; jj < len(tin); jj++ {
                        if tin[ii] > tin[jj] {
                                tm := tin[ii]
                                tin[ii] = tin[jj]
                                tin[jj] = tm
                        }
                }
        }
        return tin
}

func main() {
        n := 0
        fmt.Scan(&n)

        a := make([]int, n)
        for ii := 0; ii < len(a); ii++ {
                fmt.Scan(&a[ii])
        }

        out := babble(a)
        d := []int{out[0]}
        for _, v := range out {
                found := false
                for _, vd := range d {
                        if vd == v {
                                found = true
                        }
                }
                if !found {
                        d = append(d, v)
                }
        }
        fmt.Println(len(d))
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<climits>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 12

using namespace std;

int h,w,sp,sdir;
char G[MAX][MAX];
int dx[] = {+0,+1,+0,-1};
int dy[] = {-1,+0,+1,+0};
int leaf[MAX*MAX];
int lpos[31],lindex;
vector<int> move[31][4];
int bitlist[31];

inline int getDir(char c){
  if(c == 'U')return 0;
  if(c == 'R')return 1;
  if(c == 'D')return 2;
  return 3;
}

inline char getCDir(int i){
  if(i == 0)return 'U';
  if(i == 1)return 'R';
  if(i == 2)return 'D';
  return 'L';
}

void INIT(){

  rep(y,h){
    rep(x,w){
      if(G[y][x] == '.')continue;

      rep(k,4){
      int nx = x, ny = y;
	while(true){
	  nx += dx[k], ny += dy[k];
	  if(!( 0 <= nx && nx < w && 0 <= ny && ny < h ))break;
	  if(G[ny][nx] != '.'){
	    move[leaf[x+y*w]][k].push_back(leaf[nx+ny*w]); 
	    bitlist[leaf[x+y*w]] |= (1<<leaf[nx+ny*w]);
	  }
	}
      }
    }
  }

}

bool dfs(int cur,int dir,int used,deque<char>& deq){
  //bitset<10> bt(used);
  //cout << "cur = " << cur << " " << getCDir(dir) << " " << bt << endl;
  if(used == (1<<lindex)-1){
    rep(i,deq.size()){
      cout << getCDir(deq[i]);
    }
    cout << endl;
    return true;
  }

  for(int k = -1; k <= 1; k++){

    int ndir = ( dir + 4 + k ) % 4;

    rep(i,move[cur][ndir].size()){
      int next = move[cur][ndir][i];
      if( (used>>next) & 1 )continue;
      deq.push_back(ndir);
      if(dfs(next,ndir,used|(1<<next),deq)){
	return true;
      }
      deq.pop_back();
      break;
    }

  }
  return false;
}

void compute(){
  deque<char> deq;
  dfs(leaf[sp],getDir(G[sp/w][sp%w]),(1<<leaf[sp]),deq);
}

int main(){
  cin >> h >> w;
  lindex = 0;
  rep(y,h){
    rep(x,w){
      cin >> G[y][x];
      if(G[y][x] != '.' && G[y][x] != 'o'){
	sp = x + y * w;
	lpos[lindex] = x + y * w;
	leaf[x+y*w] = lindex++;
      }
      else if(G[y][x] != '.'){
	lpos[lindex] = x + y * w;
	leaf[x+y*w] = lindex++;
      }
    }
  }

  //cout << "sp = " << (int)(sp%w) << "," << (int)(sp/w) << endl;
  //cout << "leaf = " << lindex << endl;
  INIT();
  /*
  cout << "move --- " << endl;
  rep(i,lindex){
    rep(j,4){
      cout << "move[" << i << "][" << getCDir(j) << "] = ";
      rep(k,move[i][j].size()){
	cout << move[i][j][k] << " ";
      }
      cout << endl;
    }
  }
  */
  compute();

  return 0;
}

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

using namespace std;

int main() {
	int x, y, sum;

	cin >> x >> y;
	sum = x + 1;
	for (int i = 1; i < y; ++i) {
		if ((x*i) % y != 0) {
			++sum;
		}
	}
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3108
h,m,d;
main(){
	scanf("%*d");
	for(;~scanf("%d:%d",&h,&m);){
		d=h*60-m*11;
		if(d<-360)
			d+=720;
		if(d>360)
			d-=720;
		d=abs(d);
		if(d<60)
			puts("alert");
		else if(d<180)
			puts("warning");
		else
			puts("safe");
	}
}

Measured memory_bytes: 0
x,y=$<.map{|s|s.split.map &:to_i}.transpose;_,*x=x;a=x.max;h,*b=y;c=0;p b.select{|x|x>a}.sort.reverse.any?{|d|c+=1;1>h-=d}?c:~-h/a+1+c

Measured memory_bytes: 16784
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

ll n;
vector<long double> ar;

long double dp[3000][3000];

long double func(ll idx,ll num)
{
    if(idx==n){
        if(num>n-num){return 1.0;}
        else{return 0.0;}
    }
    if(dp[idx][num]==-1){
    dp[idx][num]=ar[idx]*func(idx+1,num+1)+(1-ar[idx])*func(idx+1,num);
    }
    return dp[idx][num];
}

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

    cin>>n;
    ar.resize(n);
    for(ll i=0;i<n;++i){cin>>ar[i];}
    for(ll i=0;i<n;++i){
        for(ll j=0;j<n;++j){dp[i][j]=-1;}
    }
    long double ans=func(0,0);
    cout<<std::fixed;
    cout<<setprecision(9);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 141184
"use strict";

// 外部からもらってきた関数
function asc(a,b){
	return (b - a);
}

function Main(input) {
  let lines = input.trim().split("\n");
  let monstarInfo = lines[0].split(" ").map(x => x - 0);
  let monstarNum = monstarInfo[0];
  let hissatsuNum = monstarInfo[1];
  let feneInfo = lines[1].split(" ").map(x => x - 0).sort(asc);
  let sum = 0;
  feneInfo = feneInfo.splice(hissatsuNum);
  if(feneInfo.length > 0){
  	sum = feneInfo.reduce((sum, x) => sum + x );
  }
  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 48284
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int s1, s2, s3, s;
  cin >> s;
  s1 = s/100;
  s2 = (s - s1*100)/10;
  s3 = s - s1*100 - s2*10;
  
  cout << s1 + s2 + s3 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main() {
	int n, i, c[111111], m, x, y, ans = 0,p[111111];
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		p[i] = 0;
		c[i] = 1;
	}
	p[1]++;
	for (i = 0; i < m; i++) {
		cin >> x >> y;
		if (p[x] == 1)
			p[y] = 1;
		if (c[x] == 1)
			p[x] = 0;
		c[x]--;
		c[y]++;
	}
	for (i = 1; i <= n; i++)
		if (p[i] == 1)
			ans++;
	cout << ans << endl;
}

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

int main(){
    int N,K,d,A,cnt[100],rlt = 0;
    cin >> N >> K;
    for (int i = 1; i <= N; i++)cnt[i] = 0;
    
    for (int i = 0; i < K; i++){
        cin >> d;
        for (int i = 0; i < d; i++){
            cin >> A;
            cnt[A]++;
        }
    }
    for (int i = 1; i <= N; i++){
        if (cnt[i] == 0)rlt++;
    }
    cout << rlt << endl;

return 0;
}
    
    

Measured memory_bytes: 3632
program prob50
    implicit none
    integer :: a,b
    read(*,*) a,b
    if(mod(a,3) == 0 .or. mod(b,3) == 0 .or. mod(a+b,3) == 0)then
        write(*,*) "Possible"
    else
        write(*,*) "Impossible"
    end if

    stop
contains
end program prob50

Measured memory_bytes: 2656
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            divisors.append(n//i)
    return divisors
n = int(input())
d = make_divisors(n)
d.sort()

l = len(d)
print(d[l//2 - 1] + d[l//2] - 2)

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
// #define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll mod=1e9+7;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }


int main()
{
	fast;
	ll n;
	cin>>n;
	ll p10[32];
	p10[0]=1;
	p10[1]=5;
	for (ll i=2;i<=25;i++)
	{
		p10[i]=p10[i-1]*5;
		// ll val=2*p10[i];
		// if (val<=1e18)
		// cout<<val<<" ";
	}
	ll ans=0;
	for (ll i=1;i<=25;i++)
	{
		if (2*p10[i]<=1e18)
		ans+=(n/(2*p10[i]));
	}
	if (n&1)
		cout<<0;
	else
	cout<<ans;


}



Measured memory_bytes: 256
A, B, C, X, Y = [int(x) for x in input().split()]
maxAB = max(X, Y)
min = 2*maxAB*C+1

for i in range(maxAB+1):
    numA = max(X-i, 0)
    numB = max(Y-i, 0)
    value = numA*A+numB*B+2*i*C
    if value < min:
        min = value

print(min)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int X;
	cin >> X;

	int kotae = 0;
	rep1(i, 100000) {
		if (i * (i + 1) / 2 >= X) {
			kotae = i;
			break;
		}
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

int n;
vii g;
vii dp;

const int white = 1;
const int black = 0;

void dfs(int v, int p = -1) {
    for (auto w : g[v]) {
        if (w == p) continue;

        dfs(w, v);
        dp[v][black] *= dp[w][white];
        dp[v][black] %= MOD;
        
        dp[v][white] *= dp[w][black] + dp[w][white];
        dp[v][white] %= MOD;
    }
}

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

    cin >> n;
    g.resize(n);
    dp.assign(n, vi(2, 1));

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(0);
    cout << (dp[0][0] + dp[0][1]) % MOD;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
  string s;
  cin >> s;
  vector<char> answer;
  for (auto i = s.begin(); i != s.end(); i++) {
    if (*i == 'B') {
      if (!answer.empty()) {
        answer.pop_back();
      }
    } else
      answer.push_back(*i);
  }
  for (auto i = answer.begin(); i != answer.end(); i++) {
    cout << *i;
  }
  cout << endl;
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
int vv[111111];
int n, k, ans=1e9;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>k; int i, j;
	for(i=1 ; i<=n ; i++) cin>>vv[i];
	for(i=1 ; i<=n-k+1 ; i++)
	{
		if(vv[i]<=0 && vv[i+k-1]<=0) ans=min(ans,abs(vv[i]));
		if(vv[i]>=0 && vv[i+k-1]>=0) ans=min(ans,abs(vv[i+k-1]));
		if(vv[i]<=0 && vv[i+k-1]>=0) ans=min(ans,vv[i+k-1]-vv[i]+min(abs(vv[i]),abs(vv[i+k-1])));
	}
	cout<<ans; return 0;
}

// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.00000001;
int sign(double x){
  if (x > EPS){
    return 1;
  } else if (x < - EPS){
    return -1;
  } else {
    return 0;
  }
}
struct point{
  double x, y;
  point(){
  }
  point(double x, double y): x(x), y(y){
  }
  point operator +(point P){
    return point(x + P.x, y + P.y);
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
  point operator *(double k){
    return point(x * k, y * k);
  }
  point operator /(double k){
    return point(x / k, y / k);
  }
};
double cross(point P, point Q){
  return P.x * Q.y - P.y * Q.x;
}
struct line{
  point A, B;
  line(){
  }
};
point vec(line L){
  return L.B - L.A;
}
bool is_parallel(line L1, line L2){
  return sign(cross(vec(L1), vec(L2))) == 0;
}
point line_intersection(line L1, line L2){
  return L1.A + vec(L1) * cross(L2.A - L1.A, vec(L2)) / cross(vec(L1), vec(L2));
}
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<line> L(n);
    for (int i = 0; i < n; i++){
      cin >> L[i].A.x >> L[i].A.y >> L[i].B.x >> L[i].B.y;
    }
    map<pair<long long, long long>, int> mp;
    int ans = n * (n + 1) / 2 + 1;
    for (int i = 0; i < n; i++){
      for (int j = i + 1; j < n; j++){
        if (!is_parallel(L[i], L[j])){
          point P = line_intersection(L[i], L[j]);
          if (abs(P.x) < 100 - EPS && abs(P.y) < 100 - EPS){
            mp[make_pair((long long) (P.x * 10000000000 + 0.5), (long long) (P.y * 10000000000 + 0.5))]++;
          } else {
            ans--;
          }
        } else {
          ans--;
        }
      }
    }
    for (auto P : mp){
      int cnt = P.second;
      if (cnt >= 3){
        ans -= cnt - (int) sqrt(cnt) - 1;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3436
N = int(input())
dict = {}
for _ in range(N):
  num = int(input())
  if num in dict:
    dict[num] += 1
  else:
    dict[num] = 1
    ans = 0
for key, value in dict.items():
  if value%2 == 1:
    ans += 1
print(ans)

Measured memory_bytes: 15072
n,m,l=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in xrange(n)]
b=[map(int,raw_input().split()) for i in xrange(m)]
c=[[0]*l for i in xrange(n)]

for i in xrange(n):
	for j in xrange(l):
		c[i][j] = sum(a[i][k]*b[k][j] for k in xrange(m))
for p in c:
	print " ".join(map(str, p))


Measured memory_bytes: 5356
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
const int N = 2e5 + 12, bs = 500;
const ll inf = 1e9;
const double EPS = 0.000001;

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

	int x;
	cin >> x;
	if(x <= 599){
		cout << 8;
	}
	else if(x <= 799){
		cout << 7;
	}
	else if(x <= 999){
		cout << 6;
	}
	else if(x <= 1199){
		cout << 5;
	}
	else if(x <= 1399){
		cout << 4;
	}
	else if(x <= 1599){
		cout << 3;
	}
	else if(x <= 1799){
		cout << 2;
	}
	else{
		cout << 1;
	}
}

Measured memory_bytes: 3648
import java.util.*

fun main(args: Array<String>) {
    val (N) = readLine()!!.split(" ").map { it.toInt() }
    val L =readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    L.sortDescending()
    var ans = 0
    for (a in 0 until N - 2){
        for (b in (a+1) until N - 1) {
            var c = bsearch(L, L[a] - L[b] + 1, b + 1, N-1) - 1
            if (L[a] + L[b] > L[c]) {
                ans += c - b
            }
        }
    }
    println(ans)
}

fun bsearch(array: IntArray, v: Int, min: Int, max: Int) : Int {
    if (min > max) return min
    val mid = min + (max - min) / 2
    return when {
        array[mid] < v -> bsearch(array, v, min, mid-1)
        array[mid] >= v -> bsearch(array, v, mid + 1, max)
        else -> Integer.MAX_VALUE
    }
}

Measured memory_bytes: 40696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), M = in.nextInt();
		long[][] student = new long[N][2], check = new long[M][2];
		int larger;
		for (int x = 0; x < M + N; x++) {
			if (x < N) {
				student[x][0] = in.nextLong();
				student[x][1] = in.nextLong();
			} else {
				check[x - N][0] = in.nextLong();
				check[x - N][1] = in.nextLong();
			}
		}
		for (int x = 0; x < N; x++) {
			long cDist = 0;
			int cCheck = 0;
			for (int y = 0; y < M; y++) {
				if (y == 0) {
					cDist = Math.abs(student[x][0] - check[y][0]) + Math.abs(student[x][1] - check[y][1]);
					cCheck = 0;
					continue;
				}
				long distance = Math.abs(student[x][0] - check[y][0]) + Math.abs(student[x][1] - check[y][1]);
				if (distance < cDist) {
					cDist = distance;
					cCheck = y;
				}
			}
			System.out.println(cCheck + 1);
		}
	}

}


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

int main() {
  int x, y;
  cin >> x >> y;
  vector<string> vec(x);
  for (int i = 0; i < x; i++) {
    cin >> vec.at(i);
  }
  
  for (int i = 0; i < y + 2; i++) {
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < x; i++) {
    cout << "#" << vec.at(i) << "#" << endl;
  }
  
  for (int i = 0; i < y + 2; i++) {
    cout << "#";
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc078/tasks/abc078_b

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    int ans = X / (Y+Z);
    if (X % (Y+Z) < Z) ans--;

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define mod 1000000007
#define inf 1000000005
int ans=0;
vector<int> in_degree(100005);
vector<int> adj[100005];
vector<int> d(100005,-1);
void dfs(int v){
    //cout<<v<<" ";
    for(int x: adj[v]){
        in_degree[x]--;
        if(d[x]<d[v]+1){
            d[x] = d[v]+1;
            ans = max(ans,d[x]);
        }
        if(in_degree[x]==0) dfs(x);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    rep(i,0,m){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        in_degree[y]++;
    }
    rep(i,1,n+1){
        adj[0].push_back(i);
        in_degree[i]++;
    }
    d[0]=0;
    dfs(0);
    //d.assign(100005,-1);
    cout<<ans-1;
    
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
    int test;
    //cin>>test;
    test=1;
    //int cse=1;
    while(test--){
         //cout<<"Case #"<<cse<<": ";
         solve();
         cout<<endl;
         //cse++;
    }
    return 0;
}


Measured memory_bytes: 9204