akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

solve :: Int -> Int
solve number = loop number 0
  where
    loop n count = let (a,b) = n `divMod` 2 in
                     if b == 0 then loop a (count+1) else count


main = do
  n <- readLn :: IO Int
  as <- getIntVector
  let ans = VU.minimum $ VU.map solve as
  print ans


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

int N, K;
string S;
vector<int> conn_num;

int main(){
    cin >> N >> K;
    cin >> S;

    int prev = S[0] - '0', cnt = 1;
    if(prev == 0){
        conn_num.push_back(0);
    }
    for(int i = 1; i < S.length(); i++){
        if(S[i] - '0' == prev){
            cnt++;
        }else{
            conn_num.push_back(cnt);
            cnt = 1;
        }
        prev = S[i] - '0';
    }
    conn_num.push_back(cnt);
    for(auto itr = conn_num.begin(); itr != conn_num.end(); itr++){
        //cout << *itr << endl;
    }

    int base = 0;
    int base_cnt_max = 2 * K + 1;
    for(int i = 0; i < min(base_cnt_max, (int)conn_num.size()); i++){
        base += conn_num[i];
    }

    int ans = base;
    for(int i = base_cnt_max; i < conn_num.size(); i += 2){
        base -= conn_num[i - base_cnt_max] + conn_num[i - base_cnt_max + 1];
        base += conn_num[i];
        if(i + 1 < conn_num.size()){
            base += conn_num[i + 1];
        }
        ans = max(ans, base);
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int a,b,c; cin >> a >> b >> c;
	if(a==b){
		if(a==c){
			cout << "No" << endl;
			return 0;
		}else{
			cout << "Yes" << endl;
			return 0;
		}
	}else{
		if(a==c){
			cout << "Yes" << endl;
			return 0;
		}else if(b==c){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;
int main(){
	int n;
	std::cin >> n;
	std::vector<pair<int,int>> a(n);
	rep(i,n){
		std::cin >> a[i].first;
		a[i].second=i+1;
	}
	sort(all(a));
	rep(i,n)std::cout << a[i].second <<endl;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int X;
    cin >> X;

    int a = X / 500;
    int b = (X % 500) / 5;

    cout << (1000*a + 5*b) << '\n';

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    
    
    cin>>n;
    vector<long long> vi(n), s(n,0);
    long long tot=0;
    for(long long&i:vi){
        cin>>i;
    }
    s[0]=vi[0];
    for(int i=1; i<n; i++){
        s[i]+=s[i-1]+vi[i];
    }
    
    tot=s[n-1];
    long long ans=abs(tot-2*s[0]);
    for(int i=0; i<n-1; i++){
        ans=min(ans,abs(tot-2*s[i]));
    }
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
int A,B,M;
int a[MAX],b[MAX],x[MAX],y[MAX],c[MAX];
int main(){
    int a_min=INF,b_min=INF;
    cin>>A>>B>>M;
    rep(i,A){
        cin>>a[i];
        if(a_min>a[i])a_min=a[i];
    }
    rep(i,B){
        cin>>b[i];
        if(b_min>b[i])b_min=b[i];
        }
        int mini=a_min+b_min;
    rep(i,M){
        cin>>x[i]>>y[i]>>c[i];
        int cnt=a[x[i]-1]+b[y[i]-1]-c[i];
        if(cnt<mini)mini=cnt;
    }
        cout<<mini<<endl;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <set>
#include <string>

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

  std::set<std::string> s;
  for (size_t i = 0; i < n; ++i) {
    char buf[16];
    scanf("%s", buf);
    std::string si = buf;
    s.insert(si);
  }

  printf("%zu\n", s.size());
}


Measured memory_bytes: 18920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numM = 0;

		try {
			scanner = new Scanner(System.in);
			numM = scanner.nextInt();

			System.out.println(24 + 24 - numM);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		String s = "";

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			s = scanner.next();
			try {
				String wkA = s.substring(0, numA);
				String wkB = s.substring(numA + 1, s.length());
				Integer.parseInt(wkA);
				Integer.parseInt(wkB);

				if (numA + numB + 1 == s.length()) {
					String wk = s.substring(numA, numA + 1);
					if (wk.equals("-")) {
						System.out.println("Yes");
						return;
					}
				}
			} catch (NumberFormatException e) {
				//				e.printStackTrace();
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
		System.out.println("No");
	}

	private int getTime(int currentI, int currentTime) {

		if (currentI == cNumN - 1) {
			return currentTime;
		}

		int res = 0;

		int c = csf[currentI][0];
		int s = csf[currentI][1];
		int f = csf[currentI][2];

		if (currentTime < s) {
			res = s;
		} else {
			res = currentTime;
		}
		if (res % f != 0) {
			res = res + (f - res % f);
		}
		res += c;
		res = getTime(currentI + 1, res);
		return res;
	}

	int cNumN = 0;
	int[][] csf;

	private void solveC() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			cNumN = scanner.nextInt();
			csf = new int[cNumN - 1][3];

			for (int i = 0; i < csf.length; i++) {
				csf[i][0] = scanner.nextInt();
				csf[i][1] = scanner.nextInt();
				csf[i][2] = scanner.nextInt();
			}

			for (int i = 0; i < csf.length; i++) {
				System.out.println(getTime(i, 0));
			}

			System.out.println(0);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 26340
w,h,n = gets.chomp.split.map(&:to_i)
lx,ly = 0,0
hx,hy = w,h
n.times do
    x,y,a = gets.chomp.split.map(&:to_i)
    case a
    when 1 then
        lx = x if lx < x
    when 2 then
        hx = x if hx > x
    when 3 then
        ly = y if ly < y
    when 4 then
        hy = y if hy > y
    end
end

p [hx-lx,0].max * [hy-ly,0].max

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

int main()
{
	int a,b;
	char c;
	while(cin >> a >> c >> b)
	{
		if(c == '?') break;

		if(c == '+') cout << a+b << endl;
		else if(c == '-') cout << a-b << endl;
		else if(c == '*') cout << a*b << endl;
		else if(c == '/') cout << a/b << endl;
	}
}

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


typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pii;
typedef vector<long long> vll;
typedef vector<int> vi;
#define pb push_back
#define mod  1000009
#define PI 2*acos(0.0)
#define REP(i,a,b) for (i = a; i <= b; i++)
#define f(i,b) for (i = 0; i < b; i++)


bitset<100000001> b;
ll ara[10000000];
vector<pair<ll,ll> > p;
vll v;
map<ll,ll> m;




void SieveOfEratosthenes()
{

	b.set();
	ll n=sqrt(1000009);

	for (ll p=2; p*p<=n; p++)
	{
		if (b[p] == 1)
		{
			for (ll i=p*2; i<=n; i += p)
				b[i] = 0;
		}
	}
    ll i=0;
	for (ll p=2; p<=n; p++)
	if (b[p])
		{
		    ara[i]=p;i++;
		}
}




main()
{
    //SieveOfEratosthenes();
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,t;
    cin >> n >> x >> t;
    x=(n-1)/x+1;
    cout << x*t << endl;

}


Measured memory_bytes: 3604
def convert(s): 
  
    # initialization of string to "" 
    new = "" 
  
    # traverse in the string  
    for x in s: 
        new += x  
  
    # return string  
    return new 

n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(0)
b=[]
if n==1:
  b.append(0)
else:
  b.append(1)
  for i in range(n-1):
    b.append(0)
fail=0
for i in range(m):
  s,c=map(int,input().split())
  if c!= b[s-1] and a[s-1]==1:
    fail=1
    break
  b[s-1]=c
  a[s-1]=1
if n>1 and b[0]==0:
  fail=1
for i in range(n):
  b[i]=str(b[i])

if fail==1:
  print(-1)
else:
  print(convert(b))
    
    
      

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define nitro ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define PI 3.141592653589793238
#define endl '\n'
int main()
{
    nitro
    int a[3];cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5 and a[1]==5 and a[2]==7) cout<<"YES";
    else cout<<"NO";
    return 0;
}


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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<bool> VB;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 5e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

signed main() {
    SCIN(S);
    ll N = S.length();
    REP(i, N) {
        if(i % 2 == 0 && S[i] == 'L')
            eputs("No");
        else if(i % 2 && S[i] == 'R')
            eputs("No");
    }
    eputs("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0){
		puts("0");
		return 0;
	}
	cout<<min(min(a*b,b*c),c*a)<<endl;
}


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

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


signed main(){
  Int n;
  string s;
  
  while(cin>>n>>s,n){
    using ull = unsigned long long;
    ull m=0;

    auto calc=[](char c){if(isdigit(c)) return c-'0';return c-'A'+10;};
  
    for(Int i=0;i<(Int)s.size();i++){
      m=m*n+calc(s[i]);
    }

    using P = pair<Int, Int>;
    vector<P> vp;
    Int k=n;
    for(Int i=2;i<=50;i++){
      if(k%i) continue;
      vp.emplace_back(i,0);
      while(k%i==0) k/=i,vp.back().second++;
    }
  
    ull ans=m;

    for(auto p:vp){
      ull k=p.first;
      ull res=0;
      while(k<=m){
	res+=m/k;
	if(k>=ULLONG_MAX/p.first-1) break;
	k*=p.first;
      }
      chmin(ans,res/p.second);
    }
  
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 3212
import java.util.*;
import java.math.*;
class Main {
    public static void main(String[] args) {
        int A, B;
        int N;
        int[] sum;
        int minVal;
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sum = new int[N - 1];
        for (A = 1; A <= N - 1; A++) {
            B = N - A;
            sum[A - 1] = sumOfEachDigit(A) + sumOfEachDigit(B);
        }
        minVal = sum[0];
        for (A = 1; A <= N - 1; A++) {
            if (minVal > sum[A - 1]) minVal = sum[A - 1];
        }
        System.out.println(minVal);
    }
    public static int sumOfEachDigit (int n){
        if (n / 10000 != 0) {
            int n5, n4, n3, n2, n1;
            n5 = n / 10000;
            n4 = (n - n5 * 10000) / 1000;
            n3 = (n - n5 * 10000 - n4 * 1000) / 100;
            n2 = (n - n5 * 10000 - n4 * 1000 - n3 * 100) / 10;
            n1 = n - n5 * 10000 - n4 * 1000 - n3 * 100 - n2 * 10;
            return n5 + n4 + n3 + n2 + n1;
        } else if (n / 1000 != 0) {
            int n4, n3, n2, n1;
            n4 = n / 1000;
            n3 = (n - n4 * 1000) / 100;
            n2 = (n - n4 * 1000 - n3 * 100) / 10;
            n1 = n - n4 * 1000 - n3 * 100 - n2 * 10;
            return n4 + n3 + n2 + n1;
        } else if (n / 100 != 0) {
            int n3, n2, n1;
            n3 = n / 100;
            n2 = (n - n3 * 100) / 10;
            n1 = n - n3 * 100 - n2 * 10;
            return n3 + n2 + n1;
        } else if (n / 10 != 0) {
            int n2, n1;
            n2 = n / 10;
            n1 = n - n2 * 10;
            return n2 + n1;
        } else {
            return n;
        }
    }
}


Measured memory_bytes: 21844
S=int(input())
A,B=S//100,S%100
if A < 13 and B < 13 and A != 0 and B != 0:
  print("AMBIGUOUS")
elif A < 13 and A > 0:
  print("MMYY")
elif B < 13 and B > 0:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int read()
{
	char c;
	int w=1;
	while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
	int ans=c-'0';
	while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
	return ans*w;
}
int a;
signed main(){
	a=read();
	int ans=0;
	ans+=(a/500*1000);
	a-=a/500*500;
	ans+=a/5*5;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int x,y,a,b; cin >> x >> y;
  if (x == 2) a = 2;
  else if (x == 4 || x == 6 || x == 9 || x == 11) a = 1;
  else a = 0;
  if (y == 2) b = 2;
  else if (y == 4 || y == 6 || y == 9 || y == 11) b = 1;
  else b = 0;
  if (a == b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

void outYesOrNo(bool res)
{
    cout << (res ? "Yay!" : ":(") << endl;
}

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

    int n;
    cin >> n;

    for (int i = 0; i < 50100; i++)
    {
        if ((int)(1.08 * i) == n)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
 string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());

  if(s < t){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n,k; cin >> n >> k;
  
  if(n % k == 0) cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

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

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int x,n;
  scanf("%d%d",&x,&n);
  int p[n+10];
  for(int i=0;i<n+10;i++){
    p[i]=0;
  }
  if(n==0){
    printf("%d\n",x);
    return 0;
  }
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  int sum,dif;
  for(int i=0;i<100;i++){
    sum=0;
    dif=0;
    for(int j=0;j<n;j++){
      if(p[j]==x+i){
        sum++;
      }
      if(p[j]==x-i){
        dif++;
      }
    }
    if(sum==0&&dif==0){
      printf("%d\n",x-i);
      return 0;
    }else if(sum==0&&dif!=0){
      printf("%d\n",x+i);
      return 0;
    }else if(sum!=0&&dif==0){
      printf("%d\n",x-i);
      return 0;
    }
  }
}

Measured memory_bytes: 1720
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		for(int i = 0; i < 3000; i++) {
			String l = scanner.nextLine();
			String xy[] = l.split(" ");
			int xy_list[] = new int[2];
			for (int j = 0; j < xy.length; j++ ) {
				int int_xy = Integer.parseInt(xy[j]);
				xy_list[j] = int_xy;
			}

			if (xy_list[0] == 0 && xy_list[1] == 0) break;

			else if (xy_list[0] < xy_list[1]) {
				System.out.printf("%d %d\n", xy_list[0], xy_list[1]);
			}
			else {
				System.out.printf("%d %d\n", xy_list[1], xy_list[0]);
			}

		    //System.out.print(x);
		    //String trimmed = str.trim();


		}

	}
}


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

public static class P {
    public static void Main() {
        int[]nq=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n=nq[0];
        int q=nq[1];
        String s=Console.ReadLine();
        int[]a=new int[n+1];
        for(int i=1;i<=n;i++){
            a[i]=a[i-1];
            if(2<=i&&s[i-2]=='A'&&s[i-1]=='C')a[i]++;
        }
        for(int i=0;i<q;i++){
            int[]lr=Console.ReadLine().Split().Select(int.Parse).ToArray();
            int l=lr[0];
            int r=lr[1];
            Console.WriteLine(a[r]-a[l]);
        }
    }
}


Measured memory_bytes: 18620
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 double a, b, c, d, e, f;
 double x, y;
 while(cin >> a >> b >> c >> d >> e >> f){
  x = (c*e - b*f) / (a*e - b*d);
  y = (a*f - d*c) / (e*a - b*d);

  if(x == 0){
    x = 0;
  }
  if(y == 0){
    y = 0;
  }

  printf("%.3f %.3f\n",x,y);
  
 }

 return 0; 
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int n;
string s, t;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> n >> s >> t;

	s = "!" + s;
	t = "!" + t;

	for (int i = 1; i <= n; i++) {
		bool ok = 1;
		for (int j = i, k = 1; j <= n; j++, k++)
			ok &= s[j] == t[k];
		if (ok) {
			cout << n + i - 1;
			return 0;
		}
	}

	cout << n + n;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=110;
int a[N];
int main(){
	int n,x; scanf("%d%d",&n,&x);
	for (int i=1; i<=n; ++i) scanf("%d",&a[i]);
	long long k=0;
	for (int i=1; i<=n; ++i) k+=a[i];
	if (k==x) return cout<<n,0;
	sort(a+1,a+n+1);
	int ans=0;
	int b=1;
	while (x>=0){
		if (x-a[b]<0||b==n) break;
		++ans;
		++b;
		x-=a[b-1];
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
int main() {
    FAST_IO;
    
    int a, b;
    cin >> a >> b;

    if (a <= 9 && b <= 9) {
        cout << a*b << endl;
        return 0;
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100010
#define eps 1e-8
struct Nodes{
	int x,y;
}p1[maxn],p2[maxn];
vector<int>vect[10010];
int n,m,r;
double ly,ry;
bool cmp(Nodes a,Nodes b)
{
	if(a.x==b.x)return a.y<b.y;
	return a.x<b.x;
}
double sqr(double x)
{
	return x*x;
}
void cal(int x,Nodes s)
{
	double tmp;
	tmp=sqr(4*r+0.0)+0.0-sqr(x-s.x+0.0);
	ly=s.y-sqrt(tmp)-eps;
	ry=s.y+sqrt(tmp)+eps;
}
int main()
{
	int i,j,k;
	int ans,L,R;
	int k1,k2;
	double tmp;
	while(scanf("%d%d%d",&n,&m,&r),n+m+r){
		for(i=1;i<=n;i++){
			scanf("%d%d",&p1[i].x,&p1[i].y);
		}
		for(i=1;i<=m;i++){
			scanf("%d%d",&p2[i].x,&p2[i].y);
		}
		sort(p2+1,p2+m+1,cmp);
		for(i=0;i<10000;i++){
			vect[i].clear();
		}
		for(i=1;i<=m;){
			for(j=i;j<=m;j++){
				if(p2[j].x!=p2[i].x)break;
				vect[p2[i].x].push_back(p2[j].y);
			}
			i=j;
		}
		ans=0;
		for(i=1;i<=n;i++){
			L=max(0,p1[i].x-4*r);
			R=min(9999,p1[i].x+4*r);
			for(j=L;j<=R;j++){
				if(vect[j].size()==0)continue;
				cal(j,p1[i]);
				//printf("%d %lf %lf\n",j,ly,ry);
				k1=lower_bound(vect[j].begin(),vect[j].end(),ly)-vect[j].begin();
				k2=upper_bound(vect[j].begin(),vect[j].end(),ry)-vect[j].begin();
				//printf("**%d %d\n",k1,k2);
				ans+=k2-k1;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3876
use proconio::*;

fn main() {
    input!{
        n: usize,
    }

    let mut ans = 0;
    for i in 1..=n {
        let mut t = n as u64 / i as u64;
        ans += i as u64 * (t * (t+1)/2);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = n; i >= 0; --i)
#define P pair<int, int>
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;
using namespace std;

void search(int x, int y) {
	
}

void dfs(int x, int y) {
	
}

int main() {
	unsigned qn, q, iq;
	bitset<64>b(0);
	cin >> qn;
	rep(i,qn) {
		cin >> q;
		switch(q) {
			case 0:
				cin >> iq;
				cout << b.test(iq) << endl;
			break;
			case 1:
				cin >> iq;
				b.set(iq);
			break;
			case 2:
				cin >> iq;
				b.reset(iq);
			break;
			case 3:
				cin >> iq;
				b.flip(iq);
			break;
			case 4:
				cout << b.all() << endl;
			break;
			case 5:
				cout << b.any() <<endl;
			break;
			case 6:
				cout << b.none() << endl;
			break;
			case 7:
				cout << b.count() << endl;
			break;
			case 8:
				cout << b.to_ulong() << endl;
			break;
		}
			
	}
}


Measured memory_bytes: 3128
N, K = map(int,input().split())
As = list(map(int,input().split()))
bit_length = max(len(bin(K)), len(bin(max(As))))-2 #0bの除去
ans = 0
for i in range(bit_length,-1,-1): #上から順番に
    bit = 2**i 
    #iビット目の立っている数を数える
    n_bit = sum([1 for a in As if a & bit]) 
    # 0のほうが大きい場合
    # Xのビットは立っているのが望ましいが、Kを超えては駄目
    if n_bit < N - n_bit and K-bit >= 0:
        n_bit = N - n_bit
        K -= bit
    ans += bit * n_bit
print(ans)


Measured memory_bytes: 14708
//packages
#include <bits/stdc++.h>//C++14 GCC mode!!!
//alias and namespaces
using namespace std;
//macros
#define REP(i,O,N) for(int i=O;i<N;i++)//うーん、python同様にRange関数でも実装してしまおうかしら…？
#define rep(i,N) for(int i=0;i<N;i++)
#define all(v) v.begin(),v.end()//v.end()-i は[-i]相当
#define debug(x) cerr<< #x <<":"<<x<<endl;
//functions   



//solution
int solution(std::vector<std::vector<bool>> grid){
    
    return 0;
}
int main(void){
    //input
    int H,W;
    cin >> H>>W;
    std::vector<std::vector<int>> grid(W);
    std::vector<int> gridH(H);
    char a;
    rep(i,W){
        rep(j,H){
            cin >> a;

            gridH.at(j)= (a=='.')?0:1;
            grid.at(i)=gridH;

        }
    }
    int ans=1;
    int r,l,u,d;
    rep(i,W){
        rep(j,H){
            if (grid[i][j]==1){
                r = (j==H-1)?0:grid[i][j+1];
                l = (j==0)?0:grid[i][j-1];
                u = (i==0)?0:grid[i-1][j];
                d = (i==W-1)?0:grid[i+1][j];
                
                if (r+l+u+d == 0){
                    debug(i)
                debug(j)
                debug(grid[i][j])
                    ans = 0;
                }
            }
        }
        
    }
    //output
    cout<<((ans==1)?"Yes":"No")<<endl;//true to yes
    //cout << solution(points)<<endl;//value
    //cout << ans<<endl;//other
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;

struct node
{
	int l,r;
	node *ls,*rs;
	LL tms,s;
} *root;
int n,m;
int a[maxn];
LL ans,ori;

void buildtree(node *p,int l,int r)
{
	p->l=l;p->r=r;
	p->tms=p->s=0;
	if (l==r) return;
	p->ls=new node;
	p->rs=new node;
	buildtree(p->ls,l,(l+r)>>1);
	buildtree(p->rs,((l+r)>>1)+1,r);
	return;
}

LL gets(node *p,int pos)
{
	if (p->l==p->r) return p->s;
	else 
	{
		if (pos<=p->ls->r) return p->s+gets(p->ls,pos);
		else return p->s+gets(p->rs,pos);
	}
}

LL gettms(node *p,int pos)
{
	if (p->l==p->r) return p->tms;
	else 
	{
		if (pos<=p->ls->r) return p->tms+gettms(p->ls,pos);
		else return p->tms+gettms(p->rs,pos);
	}
}

void adds(node *p,int l,int r,LL val)
{
	if (l>r) return;
	if (l<=p->l && p->r<=r) 
	{
		p->s+=val;
		return;
	}
	
	if (l<=p->ls->r) adds(p->ls,l,r,val);
	if (p->rs->l<=r) adds(p->rs,l,r,val);
	return;
}

void addtms(node *p,int l,int r)
{
	if (l>r) return;
	if (l<=p->l && p->r<=r) 
	{
		p->tms++;
		return;
	}
	
	if (l<=p->ls->r) addtms(p->ls,l,r);
	if (p->rs->l<=r) addtms(p->rs,l,r);
	return;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	root=new node;
	buildtree(root,1,m);
	for(int i=1;i<n;i++)
	{
		if (a[i]<a[i+1])
		{
			adds(root,a[i]+1,a[i+1],(LL)-a[i]-1);
			addtms(root,a[i]+1,a[i+1]);
		}
		else
		{
			adds(root,a[i]+1,m,(LL)-a[i]-1);
			addtms(root,a[i]+1,m);
			adds(root,1,a[i+1],m-a[i]-1);
			addtms(root,1,a[i+1]);
		}
	}
	
	ori=0;
	for(int i=1;i<n;i++)
		if (a[i]<a[i+1]) ori+=(LL)(a[i+1]-a[i]);
		else ori+=(LL)(a[i+1]+m-a[i]);
	ans=0;
	for(int i=1;i<=m;i++)
		ans=max(ans,gets(root,i)+gettms(root,i)*(LL)i);
	ans=ori-ans;
	
	printf("%lld\n",ans);
	return 0;	
}

Measured memory_bytes: 9984
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep2(i, s, e) for(int i=s; i<e; i++)
#define print(i) cout << i << endl;

int main(){

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

    int ans = 0;
    int n = 1;
    while(true){
        if(n >= b) break;

        n += a-1;
        ans++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = sorted(list(map(int, input().split())))
dp = [0] * (10 ** 6 + 10)
for x in A:
    i = 0
    while x + i <= 10 ** 6 + 10:
        if dp[(x-1)] == 2:
            break
        else:
            dp[(x-1) + i] += 1
            i += x

cnt = 0
for x in A:
    if dp[x-1] == 1:
        cnt += 1

print(cnt)

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

using namespace std;

int N;
int A, B;

void solve() {
    int res = 0;
    for (int j = 1; j <= N; ++j) {
        string s = to_string(j);
        int num = 0;
        for (int i = 0; i < int(s.size()); ++i) {
            num += s[i] - '0';
        }
        if (A <= num && num <= B) {
            res += j;
        }
    }
    printf("%d\n", res);
}

int main() {
    cin >> N >> A >> B;
    solve();
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)

  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hcount(h), wcount(w);
  vector<pll> bomb(m);
  for (int i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    hcount[a-1]++, wcount[b-1]++;
    bomb[i] = pll(a-1, b-1);
  }
  ll hmax = -1LL, wmax = -1LL;
  for (int i = 0; i < h; i++) hmax = max(hmax, hcount[i]);
  for (int j = 0; j < w; j++) wmax = max(wmax, wcount[j]);

  ll cnt = 0;
  for (int i = 0; i < m; i++) {
    if ((hcount[bomb[i].first] == hmax) && (wcount[bomb[i].second] == wmax)) cnt++;
  }

  ll counth = 0, countw = 0;
  for (int i = 0; i < h; i++) if (hmax == hcount[i]) counth++;
  for (int i = 0; i < w; i++) if (wmax == wcount[i]) countw++; 
  if (cnt == counth * countw) {
    cout << hmax + wmax - 1 << endl;
    return 0;
  }
  cout << hmax + wmax << endl;
}


Measured memory_bytes: 12680
N,Y=(int(x) for x in input().split())
count=0
for z in range(0,N+1):
    for y in range(0,N-z+1):
        x=N-z-y
        if 10000*z+5000*y+1000*x==Y:  
            print(z,y,x)
            count+=1
            break
    if 10000*z+5000*y+1000*x==Y:  
            break
if count==0:
    print("-1 -1 -1")
    

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:
    def __init__(self, n):
        # 0-indexed
        self.size = n
        self.tree = [0] * (n+1)

    # [0, i]の区間和
    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    # 値の追加：添字, 値
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

N=INT()
A=LIST()
# 区間の全組み合わせ(累積和配列N+1から2つ選ぶ組み合わせ)
ALL=(N+1)*N//2

# 転倒数の取得
def get_inv(A):
    N=len(A)
    # マイナスの値を考慮するため今回は*2する
    bit=BIT(N*2+1)
    ans=0
    for i in range(N-1, -1, -1):
        bit.add(A[i]+N, 1)
        # 自分より右にある、自分より小さな数の個数
        ans+=bit.sum(A[i]+N-1)
    return ans

def calc(X):
    # X以上かどうかで1と-1にする配列L
    L=[0]*N
    for i in range(N):
        if A[i]>=X:
            L[i]=1
        else:
            L[i]=-1
    # 累積和
    sm=[0]+list(accumulate(L))
    # 区間の全組み合わせ - 累積和の転倒数(1より-1のが多かった区間の数)
    # = 中央値がX以上となる区間の数(1のが多いor同数だった区間の数)
    ans=ALL-get_inv(sm)
    # 中央値がX以上となる区間が、全体の半分(切り上げ)以上あるかどうか
    return ans>=ceil(ALL, 2)

# 二分探索
A2=sorted(set(A))
low=0
hi=len(A2)
while low+1<hi:
    mid=(hi+low)//2
    if calc(A2[mid]):
        low=mid
    else:
        hi=mid
# 今回は境界の下が欲しいのでlowを出力
print(A2[low])


Measured memory_bytes: 120204
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	    int N = Integer.parseInt(scanner.next());
	    int K = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }
	    
	    Arrays.parallelSort(H);
	    
	    int min=Integer.MAX_VALUE;
	    for (int i=0; i<N-K +1; i++) {
	    	int t= H[i+K-1] - H[i];
	    	if (t < min) {
	    		min=t;
	    	}
	    }

	    System.out.println(min);
	}
}

Measured memory_bytes: 59560
n , k =list(map(int,input().split()))
p = list(map(int,input().split()))
maxval = sum(p[0:k])
now = sum(p[0:k]) + p[-1] - p[k-1]
for i in range(n-k+1):
    now = now - p[i-1] + p[i+k-1]
    if  now > maxval:
        maxval = now

print((maxval+k)/2)

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int k, a, b;
    cin >> k >> a >> b;
    
    bool ans = false;
    reps(i,a,b){
        if(i % k == 0) ans = true;
    }
    
    cout << (ans ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3656
n,m,c =list(map(int,input().split()))
b=list(map(int,input().split()))
list_a=[list(map(int,input().split())) for i in range(n)]
cnt=0
for a in list_a:
    if sum([x * y for (x, y) in zip(a, b)])+c>0:
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	long long kabu = 0;
	long long money = 1000;

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

	for (int i = 0;i < n - 1;i++) {
		if (a[i] < a[i + 1]) {
			kabu += (money / a[i]);
			money %= a[i];
		}
		else if (a[i] > a[i + 1]) {
			money += (kabu * a[i]);
			kabu = 0;
		}
	}

	money += (kabu * a[n - 1]);

	cout << money << endl;

	return 0;
}

Measured memory_bytes: 3620
N = int(input())
P = [int(input()) for i in range(N)]
Q = [0]*N
for i in range(N):
    Q[P[i]-1] = i

cur = 1; ans = 1
for i in range(N-1):
    if Q[i] < Q[i+1]:
        cur += 1
    else:
        cur = 1
    ans = max(cur, ans)
print(N - ans)


Measured memory_bytes: 18924
#include <stdio.h>
 
int main(void)
{
  long a, b;
 
  while(scanf("%ld %ld", &a, &b) != EOF)
  {
    printf("%ld ", a / b);
    printf("%ld ", a % b);
    printf("%.5lf\n", ((double)a / (double)b));
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    string S;  cin >> S;
    int N = S.length();
    int ans = N;
    for(int i=0; i<N-1; i++){
        if(S[i]!=S[i+1]) ans = min(ans, max(i+1, N-i-1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
/**
 *    author:  tourist
 *    created: 08.12.2019 08:24:29       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, len;
  cin >> n >> len;
  vector<int> a(n);
  vector<int> L(n);
  vector<int> R(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    L[i] = 1;
    R[i] = 1;
  }
  long long ans = n;
  set<pair<int, int>> s;
  set<int> alive;
  for (int i = 0; i < n; i++) {
    s.emplace(a[i], i);
    alive.insert(i);
  }
  while (!s.empty()) {
    int id = s.begin()->second;
    s.erase(s.begin());
    vector<int> pos(1, id);
    while (true) {
      auto it = alive.lower_bound(pos.back() + 1);
      if (it == alive.end() || a[*it] != a[id]) {
        break;
      }
      s.erase(make_pair(a[*it], *it));
      pos.push_back(*it);
    }
    int sz = (int) pos.size();
    if (sz < len) {
      continue;
    }
    {
      long long sumL = 0;
      for (int i = len - 1; i < sz; i++) {
        sumL += L[pos[i - len + 1]];
        ans += sumL * R[pos[i]];
      }
    }
    for (int x : pos) {
      alive.erase(x);
    }
    int new_sz = sz / len;
    vector<int> newL(new_sz);
    vector<int> newR(new_sz);
    for (int i = 0; i < sz; i++) {
      if (i >= len - 1) {
        newR[(i - (len - 1)) / len] += R[pos[i]];
      }
      if (i <= sz - len) {
        newL[new_sz - 1 - ((sz - len) - i) / len] += L[pos[i]];
      }
    }
    for (int i = 0; i < new_sz; i++) {
      alive.insert(pos[i]);
      L[pos[i]] = newL[i];
      R[pos[i]] = newR[i];
      a[pos[i]] += 1;
      s.emplace(a[pos[i]], pos[i]);
    }
    if (len <= new_sz) {
      long long sumL = 0;
      for (int i = len - 1; i < new_sz; i++) {
        sumL += L[pos[i - len + 1]];
        ans -= sumL * R[pos[i]];
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 21760
#include <iostream>

using namespace std;

int main() {
	int n;
	while ( cin >> n, n ) {
		int ans = 0;
		for (int i = 1; i < n; ++i) {
			int sum = 0;
			for (int j = 2; j < n; ++j) {
				int k = j;
				sum = i * j + k*(k-1)/2;
				if (sum == n) ++ans;
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
  string s;
  string t;
  cin >> s;
  cin >> t;
  int count = 0;
  for(int i = 0; i < s.length(); ++i){
    if(s[i] != t[i]){
     ++count; 
    }
  }
  cout << count;
  return 0;
}

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

// counting-roads.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2017 Seong Yong-ju

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  int ans[n] = {};
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    ++ans[a - 1];
    ++ans[b - 1];
  }

  REP(i, n) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
long long n,va,to;
int len;
void pr(long long id,int stl){
	if(stl==0) return;
	pr((id-1)/26,stl-1);
	cout<<(char)((id-1)%26+'a');
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	va=1;
	to=0;
	while(to<n){
		va*=26;
		to+=va;
		len++;
	}
	pr(n,len);
	cout<<endl;
	return 0;
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) & 1) {
        puts("Borys");
    } else {
        puts("Alice");
    }
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    cout << min(b/a, c) << endl;
    return 0;
}

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

int main(){
    int n;
    ll a[MAX],b[MAX],c[MAX];
    pair<ll,ll >pa[MAX];
    cin>>n;
    rep(i,n){
        cin>>a[i];
        cin>>b[i];
        c[i]=a[i]+b[i];
        pa[i]=make_pair(c[i],b[i]);
    }
    sort(pa,pa+n);
    ll int ans=0;
    for(int i=n-1;i>=0;i--){
        if((n-i)%2==1)ans+=pa[i].first-pa[i].second;
        else ans-=pa[i].second;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
str = gets.chomp

f = str[0,2]
b = str[2,2]

flg_f = f.match(/(11|12|0[1-9])/)
flg_b = b.match(/(11|12|0[1-9])/)

if flg_f && flg_b
  puts 'AMBIGUOUS'
elsif flg_f && !(flg_b)
  puts 'MMYY'
elsif !(flg_f) && flg_b
  puts 'YYMM'
else
  puts 'NA'
end


Measured memory_bytes: 1788
import Control.Applicative
import Control.Monad
import Numeric ( readHex )
import Data.Bits ((.&.), shiftR, testBit)
import Text.Printf

main :: IO ()
main = do
  n <- readLn
  map solve <$> replicateM n getLine >>= mapM_ putStrLn

solve :: String -> String
solve s = sgn ++ it ++ "." ++ f (n .&. 0x7f)
  where
    ((n, _) : _) = readHex s :: [(Int, String)]
    sgn = if testBit n 31 then "-" else ""
    it = show $ shiftR (n .&. 0x7fffff80) 7
    f 0 = "0"
    f ex = reverse $ dropWhile (== '0') $ reverse s 
      where
        b6 = if testBit ex 6 then 5000000 else 0 :: Int
        b5 = if testBit ex 5 then 2500000 else 0 :: Int
        b4 = if testBit ex 4 then 1250000 else 0 :: Int
        b3 = if testBit ex 3 then  625000 else 0 :: Int
        b2 = if testBit ex 2 then  312500 else 0 :: Int
        b1 = if testBit ex 1 then  156250 else 0 :: Int
        b0 = if testBit ex 0 then   78125 else 0 :: Int
        s = printf "%07d" (b6 + b5 + b4 + b3 + b2 + b1 + b0) :: String



Measured memory_bytes: 9328
import collections
def hoge(n):
    k = 1    
    while k<=n:
        k*=2
    return k-n
ans = 0
input()
a = [int(x) for x in input().split()]
c = collections.Counter(a)
sa = list(set(a))
sa.sort()
sa.reverse()
for i in range(len(sa)):
    x = sa[i]
    if c[x]<= 0:
        continue    
    y = hoge(x)
    if x==y:
        ans += c[x]//2
    elif c[y]>= 0:
        ans += min(c[x],c[y])
        c[y] -=c[x]
print(ans)

Measured memory_bytes: 61164
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int res = 0;
    while(n)
    {
        res += n % 10;
        n /= 10;
    }

    if(1 == res)
    {
        res *= 10;
    }

    cout << res << endl;

    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int t=1, u,v;
  for(int i=0; i<N; i++){
    u = t * 2;
    v = t + K;
    if(u <= v){t = u;}else{t = v;}
  }
  cout << t << endl;
}


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

int main(){
  int h,w;cin >> h >> w;
  string a[h];
  for(int i=0;i<h;i++)cin >> a[i];
  for(int i=0;i<w+2;i++)cout << "#";
  cout << endl;
  for(int i=0;i<h;i++){
    cout << "#" << a[i] << "#" << endl;
  }
  for(int i=0;i<w+2;i++)cout << "#";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
src = [0] + list(map(int,input().split())) + [0]
cums = [0]
for a,b in zip(src,src[1:]):
    d = abs(a-b)
    cums.append(cums[-1] + d)

ans = []
for i in range(N):
    tmp = cums[i] + abs(src[i] - src[i+2]) + cums[-1] - cums[i+2]
    ans.append(tmp)
print(*ans, sep='\n')

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

int main()
{
  int n;
  cin>>n;
  int a[n],i,sum=0,sub=0,keep[n],ans;
  for(i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sub=a[0];
  keep[0]=sum-2*sub;
  for(i=1;i<n;i++){
    sub+=a[i];
    keep[i]=sum-2*sub;
    if(keep[i]<0){
      keep[i]=-keep[i];
    }
    if(keep[i]<keep[0]){
      keep[0]=keep[i];
    }
  }
  cout<<keep[0]<<endl;
  return 0;
}


Measured memory_bytes: 256