akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A.at(i);

	int res = 0;
	bool flag = true;
	while(flag) {
		for(int i = 0; i < N; i++) {
			if(A.at(i) % 2 != 0) flag = false;
			else A.at(i) /= 2;
		}
		if(flag) res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;

int gcd(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	// ユークリッドの方法
	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd


int lcm(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int main()
{
	
	int A, B, C, D, E, F;

	cin >> A >> B >> C >> D >> E >> F;


	vector<bool> water(31, false);

	vector<bool> suger(3001, false);


	for (int i = 0; i*A <= 30; ++i)
	{
		for (int j = 0; i*A + j*B <= 30; ++j)
		{
			water[i*A + j*B] = true;
		}
	}


	for (int i = 0; i*D <= lcm(C, D); ++i)
	{
		for (int j = 0; i*D + j*C <= 3000; ++j)
		{
			suger[i*D + j*C] = true;
		}
	}


	int ans_w=0, ans_s=0;

	double ans_rate = 0;


	for (int i =0; i <= 30; ++i)
	{

		if (!water[i]) { continue; }

		for (int j = 0; j <= 3000; ++j)
		{

			if (!suger[j]) { continue; }

			if (1.0*j / i > E) { continue; }

			if (i*100 + j > F) { continue; }

			double rate = 100.0*j / (i * 100 + j);


			if (rate >= ans_rate)
			{

				ans_rate = rate;

				ans_w = i * 100;

				ans_s = j;

			}

		}
	}

	cout << ans_w + ans_s << " " << ans_s << endl;

	return 0;

}

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

using namespace std;

#define ALL(x) begin(x), end(x)

typedef long long ll;
typedef pair<int, int> ipair;

//const int INF = (int)1.1e9;

int main() {
    #ifndef MY
    // freopen("cards.in", "r", stdin);
    // freopen("cards.out", "w", stdout);
    cin.tie(0);
    #endif
    ios_base::sync_with_stdio(0);

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

    int p = 0;
    for (int i = 0; i < n; ++i) {
        if (a[a[i]] == i) ++p;
    }
    cout << p / 2 << "\n";
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int x;
  cin >> x;

  vec e(x + 1, 0);

  e[1] = 1;

  FOR(b, 2, x + 1){
    int v = b * b;
    while(v <= x){
      e[v] = 1;
      v *= b;
    }
  }

  RREP(i, x + 1){
    if(e[i] == 1){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using state= pair<int, bool>;

int64_t solve(string &N){ 
  int digit_tmp= N.at(0)- '0';
  int carryout= 10-digit_tmp;
  int dp0= min(digit_tmp  , 1+carryout); // carry_inなし
  int dp1= min(digit_tmp+1, carryout);   // carry_inあり
  int buf0, buf1;
  for(int i=1; i<N.size(); i++){
    digit_tmp= N.at(i)- '0';
    carryout= 10-digit_tmp;
    buf0= min(dp0+ digit_tmp  , dp1+ carryout  );
    buf1= min(dp0+ digit_tmp+1, dp1+ carryout-1);
    dp0= buf0; dp1= buf1;
  }

  return dp0;
}

int main() {
  string N;
  cin >> N;
  
  cout << solve(N) << endl;
}

Measured memory_bytes: 1412
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    double a, b, c;
    cin >> a >> b >> c;
    const double pi = acos(-1);
    double theta = c * pi / 180;
    double s = a * b * sin(theta) / 2;
    double x = sqrt(a*a + b*b - 2*a*b*cos(theta));
    double l = a + b + x;
    double h = 2*s / a;
    cout << fixed << setprecision(15) << s << endl;
    cout << l << endl;
    cout << h << endl;
}



Measured memory_bytes: 3656
// verified with 
#include<vector>
using namespace std;

template<typename T, T (*append)(T, T), T empty>
struct Segtree {
  vector<T> dat;
  int n;
  
  Segtree(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.reserve(2 * n - 1);
    for (int i = 0; i < 2 * n - 1; i++) dat[i] = empty;
  }

  void update(int k, T a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = append(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  // min([a, b))
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return empty;
    else if (a <= l && r <= b) return dat[k];
    else {
      T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return append(vl, vr);
    }
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

template<typename T>
T getmin(T x, T y) {
  return (x > y ? y : x);
}


#include<iostream>

int main() {
  int n, q;
  cin >> n >> q;
  Segtree<int, getmin<int>, 2147483647> s(n);

  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 1) {
      cout << s.query(x, y + 1) << endl;
    } else {
      s.update(x, y);
    }
  }
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 
  int main(){
      lint N;
      cin>>N;
      lint A[N];
      rep(i,N)cin>>A[i];
      sort(A,A+N);
      rep(i,N-1){
          if(A[i]==A[i+1]){
              cout<<"NO";
              return 0;
          }
      }
      cout<<"YES";
  }
  

Measured memory_bytes: 1792
#include <iostream>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n < 1000)
		cout << "ABC" << endl;
	else
		cout << "ABD" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  string s;
  int q;
  cin >> s >> q;
  string sen="",matu="";
  vector<pair<int,pair<int,char>>> Q(q);
  rep(i,q){
    cin >> Q[i].fi;
    if(Q[i].fi==2){
      cin >> Q[i].se.fi >> Q[i].se.se;
    }
  }
  bool reverse=false;

  rep(i,q){
    if(Q[i].fi==1){//ĺčť˘
      reverse= !reverse;
    }
    else{
      if((reverse==false && Q[i].se.fi==1) || (reverse==true && Q[i].se.fi==2)) sen=Q[i].se.se+sen;
      else matu+=Q[i].se.se;
    }
  }
  s=sen+s+matu;
  if(!reverse)cout << s << endl;
  else{
    for(int i=sz(s)-1; i>=0; i--) cout << s[i];
    cout  << endl;
  }
  return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <iomanip>
#include <cmath>
const long double PI = acos(-1);

using namespace std;

int main(void) {
  cout << fixed << setprecision(10);
  long double a, b, x, s;
  cin >> a >> b >> x;

  if (x >= a * a * b / 2.0) {
    cout << atan(2.0 * (a * a * b - x) / (a * a * a)) * 180.0 / M_PI << endl;
  } else {
    cout << (M_PI / 2 - atan(2.0 * x/(a * b * b))) * 180.0 / M_PI << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll unsigned long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=1e6+10;
int n,a[N],pri[N],jud[N],cnt,fac[N],num[N];
void init()
{
	jud[1]=1;
	for(int i=2;i<N;i++)
	{
		if(!jud[i])pri[++cnt]=i,fac[i]=i;
		for(int j=1;j<=cnt&&pri[j]*i<N;j++)
		{
			jud[pri[j]*i]=1,fac[pri[j]*i]=pri[j];
			if(i%pri[j]==0)break;
		}
	}
}
int main()
{
	init(),scanf("%d",&n);
	int g,f=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i==1)g=a[i];else g=__gcd(g,a[i]);
		while(a[i]!=1)
		{
			int t=fac[a[i]];
			if(num[t])f=0;
			num[t]=1;
			while(a[i]%t==0)a[i]/=t;
		}
	}
	if(f)puts("pairwise coprime");
	else if(g==1)puts("setwise coprime");
	else puts("not coprime");
	return 0;
}


Measured memory_bytes: 19412
n,a,b=map(int,input().split())

s=pow(2,n,10**9+7)-1
x=1
for i in range(a):
    x*=(n-i)
    x%=(10**9+7)
    x*=pow(i+1,10**9+5,10**9+7)
y=1
for i in range(b):
    y*=(n-i)
    y%=(10**9+7)
    y*=pow(i+1,10**9+5,10**9+7)

print((s-x-y)%(10**9+7))

Measured memory_bytes: 3064
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int M = in.nextInt();
		ArrayList<int[]> ab = new ArrayList<int[]>();
		for(int i = 0; i < M; i++){
			int[] edge = {in.nextInt(), in.nextInt()};
			ab.add(edge);
		}
		
		ab.sort((a1,a2)->a1[1]-a2[1]);
		
		/*
		for(int i = 0; i < M; i++){
			int[] edge = ab.get(i);
			int a = edge[0];
			int b = edge[1];
			System.out.println(a + " " + b);
		}
		*/
		
		
		int ans = 0;
		int preVisitedIndex = 0;
		
		for(int i = 0; i < M; i++){
			int[] edge = ab.get(i);
			int a = edge[0];
			int b = edge[1];
			
			if(preVisitedIndex >= a && preVisitedIndex < b)
				continue;
			
			preVisitedIndex = b - 1;
			ans++;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 86388
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 100000000
typedef long long ll;

using namespace std;


int main()
{
    int n;
    int a[100];
    cin >> n;
    int imax = 0;
    int number = 0;
    REP(i, n) {
        cin >> a[i];
        if (imax < abs(a[i])) {
            number = i;
            imax = abs(a[i]);
        }
    }
    cout << 2*n-1 << endl;
    REP(i, n) {
        cout << number + 1 << " " << i + 1 << endl;
        a[i] += a[number];
    }
    if (a[number] >= 0) {
        REP(i, n - 1) {
            cout << i + 1 << " " << i + 2 << endl;
            a[i + 1] += a[i];
        }
    }
    else {
        for(int i=n-2;i>=0;i--) {
            cout << i + 2 << " " << i + 1 << endl;
            a[i] += a[i+1];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  string S;
  cin >> S;
  
  auto func = [](string s) {
    //cout << s << endl;
    rep(i,0,s.size()) {
      i64 j =(i64)s.size() - 1 - i;
      if(i < j) {
        if(s[i] != s[j]) {
          return false;
        }
      }
    }
    return true;
  };

  if(func(S) &&
     func(S.substr(0, (S.size() - 1) / 2)) &&
     func(S.substr((S.size() + 3) / 2 - 1, S.size() - ((S.size() + 3) / 2 - 1)))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

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

    c = A -2*B;
    
    
    
    if(c<=0){
    printf("0");
    }else {
        printf("%d", c);
    }
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

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

  int ans = 0;
  int cnt = 0;
  string good_ch = "ACGT";

  for (char c : s) {
    if (good_ch.find(c) == string::npos) {
      cnt = 0;
    } else {
      cnt += 1;
    }

    ans = max(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


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

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

#define MAX (int)1e+5

int main(void) {
    int n, a[MAX], cnt = -1, pos = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }

    REP(i, n) {
        if (pos == 1) {
            cnt = i;
            break;
        }

        pos = a[pos];
    }

    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 640
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0]*N

for i in range(N-1):
    for j in range(i+1,N):
        k = min(j-i, abs(X-i)+abs(Y-j)+1)
        ans[k] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 3444
def ans(s):
	if len(s) == 1:
		return int(s)
	else:
		length = len(s)
		res = int(s)
		for i in range(1, length):
			x = 1 << (length - i - 1)
			res += int(s[0: i]) * x + ans(s[i:len(s)])
		return res

s = input()
print(ans(s))



Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    K = ii()

    ret = 1
    for i in range(N):
        if ret * 2 > ret + K:
            ret += K
        else:
            ret *= 2
    print(ret)


if __name__ == '__main__':
    main()


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

typedef long long int ll;

int main()
{
	int n,k;
	cin>>n>>k;
	int p[n];
	for(int i=0;i<n;i++)
		cin>>p[i];
	sort(p,p+n);
	int sum=0;
	for(int i=0;i<k;i++)
		sum+=p[i];
	cout<<sum<<endl;
}



Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<complex>
#include <string>
#include <vector>
#include <queue>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long

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

    int a[100000];

    int minuscount = 0;
    ll min_num = 1000000001;
    ll total = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0) {
            total += -a[i];
            minuscount++;
            if (min_num > -a[i]) {
                min_num = -a[i];
            }
        } else {
            total += a[i];
            if (min_num > a[i]) {
                min_num = a[i];
            }
        }
    }
    
    if(minuscount % 2 == 0) {
        cout << total << endl;
    } else {
         cout << (total - 2 * min_num) << endl;
    }

	return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	if (n - 1)%(k - 1) == 0 {
		fmt.Println((n - 1) / (k - 1))
	} else {
		fmt.Println((n-1)/(k-1) + 1)
	}
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int k,odd,even;
  cin >>  k;
  odd = (k+1)/2;
  even = k/2;
  cout << odd*even  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll t1; ll t2;
  cin >> t1 >> t2;
  ll a1; ll a2;
  ll b1; ll b2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;

  ll diff1 = a1-b1;
  ll diff2 = a2-b2;

  // cout << "diff1: " << diff1 << endl;
  // cout << "diff2: " << diff2 << endl;

  if (diff1 > 0 && diff2 > 0) {
    cout << 0 << endl;
    return 0;
  }
  if (diff1 < 0 && diff2 < 0) {
    cout << 0 << endl;
    return 0;
  }

  // Now, the sign of diff1 and diff2 is different.

  if (diff1 > 0) {
    diff1 *= -1;
    diff2 *= -1;
  }
  // Here, diff1 < 0, diff2 > 0.

  // cout << "diff1: " << diff1 << endl;
  // cout << "diff2: " << diff2 << endl;

  ll dis1 = diff1 * t1; // diff after t1;
  ll dis2 = dis1 + diff2 * t2; // diff after t1 + t2.

  // cout << "dis1: " << dis1 << endl;
  // cout << "dis2: " << dis2 << endl;

  if (dis2 < 0) { // can't reach to 0
    cout << 0 << endl;
    return 0;
  }

  if (dis2 > 0) {
    ll ans = 1;
    if (abs(dis1) % dis2 == 0) { // Touch 1 at last.
      ans += 2 * (abs(dis1) / dis2);
      ans -= 1; // minus 1 for last touch.
    } else {
      ans += 2 * (abs(dis1) / dis2);
    }
    cout << ans << endl;
    return 0;
  } else { // dis2 == 0
    cout << "infinity" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

const long long MOD = 998244353;

long long dp[3001][3001];

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

	int N, S;
	cin >> N >> S;

	vector<long long> numlist(N + 1, 0);
	for (int i = 1; i <= N; i++)
	{
		cin >> numlist[i];
		dp[i][numlist[i]] = i;
	}

	long long result = 0;
	for (int i = 1; i <= N; i++)
	{
		for (int j = S; j >= 0; j--)
		{
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
			if (j >= numlist[i])
				dp[i][j] = (dp[i][j] + dp[i - 1][j - numlist[i]]) % MOD;
		}

		result = (result + dp[i][S]) % MOD;
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 70656
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=400005;
int n,a[N],nxt[N],lst[N],pos,cur,ans[N],cnt; long long k;
int main()
{
	//freopen("B.in","r",stdin); freopen("B.out","w",stdout);
	RI i; for (scanf("%d%lld",&n,&k),i=1;i<=n;++i)
	scanf("%d",&a[i]),a[n+i]=a[i];
	for (i=(n<<1);i>n;--i) lst[a[i]]=i-n;
	for (i=n;i;--i) nxt[i]=lst[a[i]],lst[a[i]]=i;
	//for (i=1;i<=n;++i) printf("%d ",nxt[i]);
	for (pos=cur=1,i=1;i<=n;++i)
	{
		int pxt=nxt[pos]; if (pxt<=pos) ++cur;
		pos=pxt+1; if (pos==1) { --cur; break; }
	}
	for (pos=1,k%=cur,cur=0;;)
	{
		int pxt=nxt[pos]; if (pxt<=pos) ++cur;
		if (cur==k) break; pos=pxt+1;
	}
	for (;;)
	{
		int pxt=nxt[pos]; if (pxt<=pos) ans[++cnt]=a[pos++];
		else pos=pxt+1; if (pos>n) break;
	}
	for (i=1;i<=cnt;++i) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  int count=0;
  for(int i=a; i<=b; i++){
  	if(i/10000 ==i%10 && (i/1000)%10 == (i/10)%10) count++;
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
N = int(input())
P = tuple(int(i) for i in input().split())
Q = tuple(int(i) for i in input().split())

seq = tuple(range(1,N+1))
import itertools
p_list = list(itertools.permutations(seq))
for i,p in enumerate(p_list):
  if p == P:
    p_idx = i
  if p == Q:
    q_idx = i
print(abs(p_idx-q_idx))


Measured memory_bytes: 8052
import Control.Applicative

main :: IO()
main = do
    [n,y] <- map read . words <$> getLine
    putStrLn $ myshow [[a,b,n-a-b] | a <- [0..n], b <- [0..n], a+b<=n && 9000*a+4000*b==y-1000*n]
        where
            myshow [] = "-1 -1 -1"
            myshow (x:_) = tail $ concatMap ((' ':) . show) x


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

int n, m, a;
int dp[10005][10];
bool can[10];
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int solve(int k) {
    if (dp[k][0] >= 0) return dp[k][0];
    else {
        vector<pair<int, int>> V;
        for (int i = 1; i < 10; i++) {
            if (can[i] && k + match[i] <= n && solve(k + match[i]) != -1)
            V.emplace_back(solve(k + match[i]), i);
        }
        sort(V.begin(), V.end());
        for (int i = 0; i < V.size(); i++)
        //cout << i << " " << V[i].first << " " << V[i].second << endl;
        
        if (!V.empty()) {
            dp[k][0] = dp[k + match[V[V.size() - 1].second]][0] + 1;
            //cout << dp[k][0] << endl;
            for (int i = 1; i < 10; i++) {
                if (i == V[V.size() - 1].second) dp[k][i] = dp[k + match[V[V.size() - 1].second]][i] + 1;
                else dp[k][i] = dp[k + match[V[V.size() - 1].second]][i];
            }
        }
        return dp[k][0];
    }
    
    
}

int main(void){
    cin >> n >> m;
    for (int i = 1; i < 10; i++) can[i] = false;
    for (int i = 0; i < m; i++) {
        cin >> a;  can[a] = true;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) dp[i][j] = -1;
    }
    for (int j = 0; j < 10; j++) dp[n][j] = 0;
    
    int l = 0;
    solve(l);
    int idx = 9;
    while (idx != 0) {
        while (dp[l][idx] > 0) {
            cout << idx;
            dp[l][idx]--;
        }
        idx--;
    }
    cout << endl;
    
    /*
    for (int i = n; i >= 0; i--) {
        cout << solve(i) << " ";
        for (int j = 1; j < 10; j++) cout << dp[i][j] << " ";
        cout << endl;
    }*/
    
}


Measured memory_bytes: 1280
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int diff = 0;
        for(int i = 1; i <= n; i++){
            if(i != sc.nextInt()){
                diff++;
            }
        }
        
        System.out.println(diff <= 2 ? "YES" : "NO");
    }
}

Measured memory_bytes: 23636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	LL N, A, B;
	cin >> N >> A >> B;

	if((N < 2 && A != B) || B < A){
		cout << 0 << endl;
		return 0;
	}

	cout << (A + B * (N - 1)) - (A * (N - 1) + B) + 1 << endl;

	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

bool test(vll& A, int i, int N, ll M, ll V, int P) {
    vll B(A);

    B[i] += M;
    ll total = M*(V-1);

    // cout << "start: " << endl;
    // for (int j=0;j<N;j++) cout << j << " " << B[j] << endl;

    for (int j=0;j<N;j++) {
        if (B[j] < B[i]) {
            ll diff = min(B[i] - B[j], min(M, total));
            B[j] += diff;
            total -= diff;

        } else if (B[j] > B[i]) {
            B[j] += min(M, total);
            total -= min(M, total);
        }
    }

    // cout << "mid: " << endl;
    // for (int j=0;j<N;j++) cout << j << " " << B[j] << endl;

    for (int j=N-1;j>0;j--) {
        ll diff = min(M - (B[j] - A[j]), total);
        B[j] += diff;
        total -= diff;
    }

    int num_greater = 0;
    for (int j=0;j<N;j++) {
        if (B[j] > B[i]) num_greater++;
    }

    if (num_greater < P) return true;
    else return false;
}

int main(){
    int N, V, P;
    ll M;
    cin >> N >> M >> V >> P;

    vll A(N);

    for (int i=0;i<N;i++) cin >> A[i];

    sort(A.begin(), A.end());

    int low = 0;
    int high = N;

    while (high - low > 1) {
        int mid = (low + high) / 2;
        int i = (N-1) - mid;
        if (test(A, i, N, M, V, P)) {
            // cout << mid << "(" << A[i] << ") is possible" << endl;
            low = mid;
        } else {
            // cout << mid << "(" << A[i] << ") is not possible" << endl;
            high = mid;
        }
    }

    cout << low + 1 << endl;
}


Measured memory_bytes: 1792
h, w = map(int, input().split())
s = [input() for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      top = max(0, i-1)
      bottom = min(h-1, i+1)
      right = min(w-1, j+1)
      left = max(0, j-1)
      if s[i][right] != "#" and s[i][left] != "#" and s[top][j] != "#" and s[bottom][j] != "#":
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define pi pair<char,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

const int M = 1e9+7;
int mod(int n){
	n%=M;
	return (n+M)%M;
}

int power(int a,int b){
	int ans=1;
	while(b>0){
		if(b&1)
			ans=mod(ans*a);
		a=mod(a*a);
		b/=2;
	}
	return ans;
}

int32_t main() { 
    boost;
 
	int n,k;
	cin>>n>>k;
	int dp[k+1];
	for(int i=1;i<=k;i++)
		dp[i] = power(k/i,n);
	int ans=0;
	for(int i=k;i>=1;i--){
		for(int j=2*i;j<=k;j+=i){
			dp[i] = mod(dp[i]-dp[j]);
		}
		ans= mod(ans+mod(i*dp[i]));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4392
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.to_i
p a[k-1]

Measured memory_bytes: 1788
s=input()
if len(s)==2:
  if s[0]==s[1]:
    print("1 2")
  else:
    print("-1 -1")
else:
  ans=True
  for i in range(2,len(s)):
    if s[i]==s[i-1] or s[i]==s[i-2] or s[i-1]==s[i-2]:
      print(i-1,i+1)
      ans=False
      break
  if ans:
    print("-1 -1")

Measured memory_bytes: 3188
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = (1 << 30) - 1;
const ll LINF = (1L << 62) - 1;
const ll MOD = 1000000007;
template <class T> inline void chmin(T& a, T& x) { a = a < x ? a : x; }
template <class T> inline void chmax(T& a, T& x) { a = a > x ? a : x; }

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

  int n, p;
  string s;
  cin >> n >> p >> s;
  vector<int> r(n + 1);
  map<int, int> cnt;
  r[n - 1] = (s[n - 1] - '0') % p;
  int dig = 1;
  for (int i = n - 2; i >= 0; --i) {
    dig = (dig * 10) % p;
    r[i] = (r[i + 1] + dig * (s[i] - '0')) % p;
  }
  // dump(r);
  if (p == 2) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
      if ((s[i] - '0') % 2 == 0) {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (p == 5) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
      if ((s[i] - '0') % 5 == 0) {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return 0;
  }
  for (auto x : r) {
    if (cnt.find(x) == cnt.end()) cnt[x] = 0;
    ++cnt[x];
  }
  ll ans = 0;
  for (auto p : cnt) {
    ll c = p.second;
    ans += c * (c - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1684
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const ll mod = ((ll)1e9 + 7);
// loop
#define rep(i, n) for(ll i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(ll i = b; i < e; i++)
#define erep(i, b, e) for(ll i = b; i <= e; i++)
#define rrep(i, b, e) for(ll i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
// sort
#define vsort(v, b) sort(all(v), [](auto l, auto r){return (b);})
// access
#define gt(i, n) get<n>(i)
// debug
#define debug(x) cout << (#x) << ": " << x << endl;
// function
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
void prime(vll& v, ll n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}
ll egcd(ll a, ll b, ll& x, ll& y){if(b == 0){x = 1; y = 0; return a;} ll d = egcd(b, a % b, y, x); y -= a / b * x; return d;}

signed main(){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
two = 0
ONCE_LIMIT = 0
if w % 2 == 1 and h % 2 == 1:
    ONCE_LIMIT = 1
    TWO_LIMIT = (w-1)/2 + (h-1)/2
elif w % 2 == 1:
    TWO_LIMIT = h/2
elif h % 2 == 1:
    TWO_LIMIT = w/2
else:
    TWO_LIMIT = 0
for v in d.values():
    if v % 2 == 1 and once == ONCE_LIMIT:
        print 'No'
        exit()
    if v % 4 == 2 and two == TWO_LIMIT:
        print 'No'
        exit()
    if v % 4 == 2:
        two += 1
    if v % 2 == 1:
        once += 1
print 'Yes'

Measured memory_bytes: 2696
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
const ll MOD = 1000000007; 
map<ll,ll> mp;

void dfs(ll N){
    ll n = N;
    if(N==1) return;
    // cout<<"N:"<<N<<endl;
    for(ll i=2;i*i<=N;i++){
        if(N%i!=0)continue;
        ll num=0;
        while(N%i==0){
            num++;
            N/=i;
        }
        mp[i] += num;
    }
    if(N!=1)mp[N] ++;
    dfs(n-1);
}

int main(){
    int N;
    cin>>N;
    dfs(N);
    ll res=1;
    for(auto p:mp){
        // cout<<p.first<<":"<<p.second<<endl;
        res = (res*(p.second+1))%MOD;
    }
    cout<<res<<endl;
}


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

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	int n = sc.nextInt();
    	//double sum = 0;
    	double sumJPY = 0;
    	double sumBTC = 0;
    	for (int i = 0 ; i < n; i++){
        	double x = sc.nextDouble();
        	String y = sc.next();
        	//System.out.println(x);
        	//System.out.println(y);
        	if (y.equals("BTC")){
        		//System.out.println(y);
        		x = x * 380000.0;
        		sumBTC += x;
        		//System.out.println(x);
        	} else {
        		sumJPY += x;
        	}
        	//sum += x;

        	//System.out.println(sum);
    	}

    	// 出力
    	//System.out.println(sum);
    	System.out.println(sumJPY + sumBTC);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
const int MAXN = 200 + 10;
const int mod = 998244353;
pii points[MAXN];
int n;
bool check(int a, int b, int c) {
    int x1 = points[a].first - points[b].first;
    int x2 = points[a].first - points[c].first;
    int y1 = points[a].second - points[b].second;
    int y2 = points[a].second - points[c].second;
    return x1*y2==x2*y1;
}
LL power(LL base, int n) {
    LL ret = 1;
    while (n) {
        if (n & 1 == 1) {
            ret *= base;
            ret %= mod;
        }
        base *= base;
        base %= mod;
        n >>= 1;
    }
    return ret;
}


int main() {
//    freopen("test.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &points[i].first, &points[i].second);
    }
    LL ret = power(2, n);
    ret = ret - 1 - n - n*(n-1)/2;
    if (ret < 0) ret += mod;
    vector<pii> used;
    for (int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            bool flag = true;
            for (pii item : used) {
                if (check(item.first, item.second, i) && check(item.first, item.second, j)) {
                    flag = false;
                    break;
                }
            }
            if (flag) used.push_back({i,j});
            else continue;
            int cnt = 2;
            for (int k = 0; k < n; k++) {
                if (k == i || k == j) continue;
                if (check(i,j,k)) cnt++;
            }
            LL tmp = power(2, cnt) - 1 - cnt - cnt*(cnt-1)/2;
            if (tmp < 0) tmp += mod;
            ret -= tmp;
            if (ret < 0) ret += mod;
        }
    }
    ret = ret % mod;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a, b;
    cin >> a >> b;
    if(((max(a,b)+min(a,b))%2))
        cout << "IMPOSSIBLE";
    else
        cout << abs(a+b)/2;

    return 0;
}


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

long long H, W;
string S[55];

int main(){
	cin >> H >> W;
	long long num = 0;
	for(long long i = 0; i < H; i++){
		cin >> S[i];
		for(long long j = 0; j < W; j++)
			if(S[i][j] == '.')
				num++;
	}

	queue<pair<pair<long long, long long>, long long> >Q;
	Q.push(make_pair(make_pair(0, 0), 0));
	set<pair<long long, long long> >done;

	while(!Q.empty()){
		long long y = Q.front().first.first;
		long long x = Q.front().first.second;
		long long d = Q.front().second;
		Q.pop();
		if(done.count(make_pair(y, x)) != 0)
			continue;
		done.insert(make_pair(y, x));

		if(y == H - 1 && x == W - 1){
			cout << num - d - 1 << endl;
			return 0;
		}

		//up
		if(y > 0 && S[y-1][x] == '.'){
			Q.push(make_pair(make_pair(y-1, x), d+1));
		}
		//left
		if(x > 0 && S[y][x-1] == '.'){
			Q.push(make_pair(make_pair(y, x-1), d+1));
		}
		//down
		if(y + 1 < H && S[y+1][x] == '.'){
			Q.push(make_pair(make_pair(y+1, x), d+1));
		}
		//right
		if(x + 1 < W && S[y][x+1] == '.'){
			Q.push(make_pair(make_pair(y, x+1), d+1));
		}

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

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

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

before = -1
result = 0

for i in range(n):
    result += b[a[i]-1]
    if (before) == (a[i] -1 ):
        result += c[before-1]
    before = a[i]

print(result)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
int u, v;
vector<int> g[100010];
int d[100010];
int d2[100010];
void dfs(int x, int p){
	for(auto y:g[x]){
		if(y==p) continue;
		d[y]=d[x]+1;
		dfs(y, x);
	}
}
void dfs2(int x, int p){
	for(auto y:g[x]){
		if(y==p) continue;
		d2[y]=d2[x]+1;
		dfs2(y, x);
	}
}
int main()
{
	cin>>n;
	cin>>u>>v;
	u--; v--;
	for(int i=0; i<n-1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(u, -1);
	dfs2(v, -1);
	int ans=0;
	for(int i=0; i<n; i++){
		if(d[i]<d2[i]){
			ans=max(ans, d2[i]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 10368
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())







#define MAX_V 20002

struct edge{
	int to, cap, rev;
	edge(int a, int b, int c) :to(a), cap(b), rev(c){}
};
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}
//sからの最短距離をbfsで計算
void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()){
		int v = que.front(); que.pop();
		for (int i = 0; i<G[v].size(); i++){
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}
//増加パスをdfsで探す
int dfs(int v, int t, int f){
	if (v == t)return f;
	for (int &i = iter[v]; i<G[v].size(); i++){
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]){
			int d = dfs(e.to, t, min(f, e.cap));
			if (d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t){
	int flow = 0;
	for (;;){
		bfs(s);
		if (level[t]<0)return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF))>0){
			flow += f;
		}
	}
}




int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin>>h>>w;
	vector<int> p;

	rep(y,h)rep(x,w){
		char c;
		cin>>c;
		if (c=='X'){
			if (y==0||y+1==h||x==0||x+1==w){
				cout<<-1<<endl;
				return 0;
			}
			p.push_back(y*w+x);
		}
		if (0 < y){
			add_edge(y*w + x, h*w + (y - 1)*w + x, INF);
		}
		if (y+1<h){
			add_edge(y*w + x, h*w + (y + 1)*w + x, INF);
		}
		if (0 < x){
			add_edge(y*w + x, h*w + y*w + x - 1, INF);
		}
		if (x+1<w){
			add_edge(y*w + x, h*w + y*w + x+1, INF);
		}
	}
	rep(i,h*w){
		add_edge(h*w + i, i, 1);
	}

	int n=h*w*2;
	for (int y=0;y<h;y++){
		add_edge(y*w , n, INF);
		add_edge(y*w+w-1, n, INF);
	}
	for (int x = 1; x+1<w; x++){
		add_edge(x, n, INF);
		add_edge((h-1)*w + x, n, INF);
	}
	rep(i,p.size()){
		add_edge(n+1, p[i], INF);
	}
	cout<<max_flow(n+1,n)<<endl;


	return 0;
}

Measured memory_bytes: 3072
import java.io.*;
import java.util.StringTokenizer;

public final class Main{
    public static void main(String[] args){
        FastScanner stdIn = new FastScanner(System.in);
        long n = stdIn.nextLong();

        if(1<=n && n<10){
            System.out.println(n);
        }else if(10<=n && n<100){
            System.out.println(9);
        }else if(100<=n && n<1000){
            System.out.println(9+(n-99));
        }else if(1000<=n && n<10000){
            System.out.println(909);
        }else if(10000<=n && n<100000){
            System.out.println(909+(n-9999));
        }else{
            System.out.println(90909);
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

}


Measured memory_bytes: 23124
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    double ans = 0.0;
    rep(i, N)
    {
        ll a;
        cin >> a;
        ans += 1.0 / double(a);
    }
    printf("%.6f", 1.0 / ans);
    return 0;
}

Measured memory_bytes: 3232