akhauriyash/Code-Regression huggingface dataset:
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

class Mint:
    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def __init__(self, val, mod=10**9+7):
        val = Mint.get_value(val)
        self.__mod = mod
        self.__val = val % self.__mod

    @property
    def value(self): return self.__val
    @property
    def inverse(self): return pow(self.__val, self.__mod - 2, self.__mod)

    def __eq__(self, other): return self.__val == other.val
    def __ne__(self, other): return self.__val != other.val

    def __neg__(self): return Mint(self.__val, self.__mod)

    def __iadd__(self, other):
        other = Mint.get_value(other)
        self.__val = (self.__val + other) % self.__mod
        return self
    def __add__(self, other):
        new = Mint(self.__value, self.__mod)
        new += other
        return new
    def __radd__(self, other): return self + other

    def __isub__(self, other):
        other = Mint.get_value(other)
        self.__val = (self.__val - other + self.__mod) % self.__mod
        return self
    def __sub__(self, other):
        new = Mint(self.__value, self.__mod)
        new -= other
        return new
    def __rsub__(self, other):
        new = Mint(Mint.get_value(other), self.__mod)
        new -= self
        return new

    def __imul__(self, other):
        other = Mint.get_value(other)
        self.__val = self.__val * other % self.__mod
        return self
    def __mul__(self, other):
        new = Mint(self.__value, self.__mod)
        new *= other
        return new
    def __rmul__(self, other): return self * other

    def __ifloordiv__(self, other):
        other = Mint(other, self.__mod)
        self *= other.inverse
        return self
    def __floordiv__(self, other):
        new = Mint(self.__value, self.__mod)
        new //= other
        return new
    def __rfloordiv__(self, other):
        new = Mint(Mint.get_value(other), self.__mod)
        new //= self
        return new

if T[N-1] != A[0]:
    print(0)
    exit()

ans = Mint(1)
for i in range(N):
    if i==0 or i==N-1: continue
    if T[i-1] != T[i]:
        if T[i] == A[0] and A[i] != A[0]:
            print(0)
            exit()
        continue
    if A[i] != A[i+1]:
        if A[i] == A[0] and T[i] != A[0]:
            print(0)
            exit()
        continue
    ans *= min(T[i], A[i])
print(ans.value)

Measured memory_bytes: 82660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    srand(time(nullptr));
    int D; cin >> D;
    vector<int> c(26+1, 0);
    for(int i = 1; i <= 26; i++) cin >> c[i];
    vector<vector<int>> s(D+1, vector<int>(26+1, 0));
    for(int i = 1; i <= D; i++)for(int j = 1; j <= 26; j++) cin >> s[i][j];
    vector<int> t(D+1, 0);
    for(int i = 1; i <= D; i++) {
        t[i] = i % 26 + 1;
    }
    ll ans = 0;
    int mx = 0;
    int id = 0;
    for(int _ = 0; _ <= 100000; _++){
        vector<int> last(26+1, 0);
        auto f = [&](int d){
            int res = 0;
            for(int i = 1; i <= 26; i++){
                res += c[i] * (d - last[i]);
                if(mx < c[i] * (d - last[i])) id = i;
            }
            return res;
        };
        vector<int> old = t;
        srand(time(nullptr));
        t[rand() % (D-1) + 1] = rand() % 25 + 1;
        ll tmp = 0;
        for(int day = 1; day <= D; day++){
            mx = 0;
            t[day] = id;
            int con = t[day];
            tmp += s[day][con];
            last[con] = day;
            tmp -= f(day); 
        }
        if(ans > tmp) {
            t = old;
            continue;
        }
        ans = max(ans, tmp);
    }
    for(int i = 1; i <= D; i++) cout << t[i] << endl;
}

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

int main(){
    while(1){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0) break;
        
        for(int i=0;i<h; i++){
            
            for(int j=0; j<w; j++){
                
                if(i==0 || i==h-1 || j==0 || j==w-1) cout<<'#';
                else cout<<'.';
            }
            cout<<'\n';
        }
        cout<<endl;
    
   }
}


Measured memory_bytes: 3092
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>

using namespace std;

long long x,y,A,B,C,a[100010],b[100010],c[100010],r[200010],R,i,tam;

int main()
{
    cin>>x>>y>>A>>B>>C;
    for (int i=0;i<A;i++) cin>>a[i];
    for (int i=0;i<B;i++) cin>>b[i];
    for (int i=0;i<C;i++) cin>>c[i];
    sort(a,a+A);
    sort(b,b+B);
    sort(c,c+C);
    i=A-1;
    while (x--){
        r[tam]=a[i];
        i--;
        tam++;
    }
    i=B-1;
    while (y--){
        r[tam]=b[i];
        i--;
        tam++;
    }
    sort(r,r+tam);
    C=C-1;
    for (int i=0;i<tam;i++){
        if (C>=0 && r[i]<c[C]){
            r[i]=c[C];
            C--;
        }
    }
    for (int i=0;i<tam;i++) R+=r[i];
    cout<<R<<endl;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

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

int shichigosan(int n){
    if (n==0) return 3;
    else if (n==1) return 5;
    else return 7;
};

int main(){
    int N;
    cin >> N;
    
    int ans = 0;
    for (int digits = 3; digits<=9; digits++){
        for(int i=0; i<pow(3, digits); i++) {
            int tmp = i;
            int shichigosan_num = 0;
            bool num[3] = {false, false, false};
            for (int pos = 0; pos < digits; ++pos){
                num[tmp%3] = true;
                shichigosan_num += pow(10, pos) * shichigosan(tmp%3);
                tmp /= 3;
            }
            if (shichigosan_num > N) continue;
            if (num[0]==false||num[1]==false||num[2]==false) continue;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
N = int(input())
a = [int(i) for i in input().split()]

result = 0
prev = -1
count = 1
for i in range(len(a)):
    if a[i] == prev:
        count += 1
        if i == N - 1:
            result += count // 2
    else:
        result += count // 2
        prev = a[i]
        count = 1

print(result)

Measured memory_bytes: 3316
import math
from decimal import Decimal

a, b, h, m = map(int, input().split())
lon = 0.5 * m + 30 * h
sho = 6 * m
d = max(lon, sho) - min(lon, sho)
deg = min(d, abs(360-d))

f = lambda c: c if c <= 90 else 180 - c
rad = math.radians(f(deg))
y = Decimal(math.sin(rad))
x = Decimal(math.cos(rad))
if deg > 90:
    L = a + x * b
else:
    L = a - x * b
l = b * y

print("{:.9f}".format(Decimal(math.sqrt((l**2)+(L**2)))))

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

int main(){
  
  int N;
  cin >> N;
  int a[N+1];
  int b[N+1];
  for(int i=1; i<=N; i++) cin >> a[i];
  for(int i=1; i<=N; i++){
  	b[a[i]]=i;
  }
  for(int i=1; i<=N; i++){
  	cout << b[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1536
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

A_counter = collections.Counter(A)
ans = sum(A)

for q in range(Q):
    B,C=map(int, input().split())
#    B,C=map(int, f.readline().split())
#    B_count = A_counter.pop(B)
    B_count = A_counter[B]
    A_counter[B]=0
    A_counter[C] += B_count
    ans += (C-B)*B_count
    print(ans)

Measured memory_bytes: 93956
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    # 頂点が探索済みかどうかのチェック配列
    check = [False for _ in range(n)]
    check[s] = True
    # 次見る頂点を格納するキュー
    queue = deque([s])
    visited_num = 1

    # 問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        # グラフが全連結ではない場合
        if len(queue) == 0:
            # 空配列を返す
            # 現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex = queue.popleft()
        # インデックスがない場合は
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            # 問題固有の計算
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7
# n=int(input())
# n,m=list(map(int,input().split()))
# a=list(map(int,input().split()))
def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


#n = int(input())

n, m = list(map(int, input().split()))
ans = 0
for i in range(n):

    x, y = list(map(int, input().split()))
    if math.sqrt(x**2+y**2) > m:
        continue
    ans += 1
print(ans)


Measured memory_bytes: 9584
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		String[] input = new Scanner(System.in).nextLine().split(" ");
		
		float a = Float.parseFloat(input[0]);
		float b = Float.parseFloat(input[1]);
		
		System.out.printf("%1$.6f\n", a*b/3.305785);
	}
}

Measured memory_bytes: 26476
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>

using namespace std;

vector<int>
insersionsort(const vector<int> a, const int g, int &cnt)
{
    vector<int> work(a);
    for (int i = g; i < work.size(); i++) {
        int v = work[i];
        int j = i - g;
        while (j >= 0 && work[j] > v) {
            work[ j + g ] = work[j];
            j = j - g;
            cnt++;
        }
        work[ j + g ] = v;
    }
    return work;
}

void
shellsort(const vector<int> a)
{
    vector<int> work(a);
    int cnt = 0;
    int m = 1;
    vector<int> gs;
    while (pow(3, m) < 2 * a.size() + 2) { 
        gs.push_back((pow(3, m) - 1) / 2);
        m++;
    }

    cout << gs.size() << endl;

    for (auto it = gs.crbegin(); it != gs.crend(); it++) {
        if (it != gs.crbegin()) { cout << ' '; }

        vector<int> w = insersionsort(work, *it, cnt);
        cout << *it;
        work.swap(w);
    }
    cout << endl;
    cout << cnt << endl;

    for (auto it : work) {
        cout << it << endl;
    }
}

int
main()
{
    int N;
    cin >> N; cin.ignore();

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i]; cin.ignore();
    }
    shellsort(A);

    return 0;
}

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

import sys

def main():
    n = int(sys.stdin.readline())

    total = 0
    for _ in range(n):
        l = sys.stdin.readline().split(" ")
        x, u = float(l[0]), l[1].strip()
        if u == "JPY":
            total += x
        else:
            total += x * 380000.0

    print(total)

main()



Measured memory_bytes: 2940
import sys
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))

def main():
    s = input().strip()
    for c in s:
        if c == "7":
            print("Yes")
            sys.exit()

    print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 61784
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j,ans=hell,k;
	cin>>n;
	ll x[n+2],y[n+2];
	map<pii,ll>m;
	for(i=1;i<=n;i++){
		cin>>x[i]>>y[i];
		m[mp(x[i],y[i])]=i;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(i!=j){
				ll a=x[i]-x[j],b=y[i]-y[j];
				ll vis[n+2]={0},cnt=0;
				for(k=1;k<=n;k++){
					if(!vis[k]){
						cnt++;
						vis[k]=1;
						ll aa=x[k],bb=y[k];
						while(m[mp(aa-a,bb-b)]!=0){
							aa-=a;
							bb-=b;
							vis[m[mp(aa,bb)]]=1;
						}
						aa=x[k],bb=y[k];
						while(m[mp(aa+a,bb+b)]!=0){
							aa+=a;
							bb+=b;
							vis[m[mp(aa,bb)]]=1;
						}
					}
				}
				ans=min(ans,cnt);
			}
		}
	}
	if(n==1)cout<<"1";else
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
     
    using namespace std;
     
    int main(void){
    	int N;
      	cin >> N;
      	if(N<105) cout << 0 << endl;
      	else if(N<135) cout << 1 << endl;
      	else if(N<165) cout << 2 << endl;
      	else if(N<189) cout << 3 << endl;
      	else if(N<195) cout << 4 << endl;
      	else cout << 5 << endl;
    }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;

    int ans = 0;
    for(int i=0; i<S.length(); i++){
        int t = 0;
        for(int j=i; j<S.length(); j++){
            if(S[j] == 'A') {
                t++;
                continue;
            };
            if(S[j] == 'T') {
                t++;
                continue;
            }
            if(S[j] == 'G') {
                t++;
                continue;
            }
            if(S[j] == 'C') {
                t++;
                continue;
            }
            break;
        }
        if(t > ans) ans = t;
    }

    cout << ans;

    return 0;
}

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

#define MAXN (60)
#define ll long long

int n, p;
int a[MAXN];
ll dp[MAXN][2];

int main(){
	scanf("%d%d", &n, &p);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", a + i);
	}
	dp[0][0] = 1;
	for(int i = 1; i <= n; ++ i){
		int c = a[i] & 1;
		dp[i][0] = dp[i - 1][0] + dp[i - 1][c];
		dp[i][1] = dp[i - 1][1] + dp[i - 1][c ^ 1];
	}
	printf("%lld\n", dp[n][p]);
	return 0;
}

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

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> ans(2*n, 0);
	Int a = 0;
	cout << "? ";
	for(Int i=0; i<n; ++i){
		cout << i+1;
		if(i != n-1) cout << " ";
		else cout << endl;
	}
	string res; cin >> res;
	if(res == "-1") return 0;
	if(res == "Red") a = 1;
	else a = -1;
	Int l = 0, r = n;
	while(r > l+1){
		Int m = (l+r) / 2;
		cout << "? ";
		for(Int i=0; i<n; ++i){
			cout << m+i+1;
			if(i != n-1) cout << " ";
			else cout << endl;
		}
		cin >> res;
		if(res == "-1") return 0;
		Int t;
		if(res == "Red") t = 1;
		else t = -1;
		if(a != t) r = m;
		else l = m;
	}
	Int x = l, y = l+n;
	if(a == 1){
		ans[x] = 1;
		ans[y] = -1;
	}else{
		ans[x] = -1;
		ans[y] = 1;
	}
/*	for(Int i=0; i<n+1; ++i){
		cout << "? ";
		for(Int j=0; j<n; ++j){
			cout << i+j+1;
			if(j != n-1) cout << " ";
			else cout << endl;
		}
		string res; cin >> res;
		if(res == "-1") return 0;
		Int t;
		if(res == "Red") t = 1;
		else t = -1;
		if(l == 1 && t == -1){
			ans[i-1] = 1;
			ans[i+n-1] = -1;
			x = i-1;
			y = i+n-1;
			break;
		}else if(l == -1 && t == 1){
			ans[i-1] = -1;
			ans[i+n-1] = 1;
			x = i-1;
			y = i+n-1;
			break;
		}
		l = t;
	}
*/	for(Int i=0; i<2*n; ++i){
		if(x == i || y == i) continue;
		if(x < i && i < y){
			cout << "? ";
			for(Int j=x; j<=y; ++j){
				if(i == j) continue;
				cout << j+1;
				if(j != y) cout << " ";
				else cout << endl;
			}
			cin >> res;
			if(res == "-1") return 0;
			if(res == "Red") ans[i] = -1;
			else ans[i] = 1;
		}else{
			cout << "? " << i+1 << " ";
			for(Int j=x+1; j<y; ++j){
				cout << j+1;
				if(j != y-1) cout << " ";
				else cout << endl;
			}
			cin >> res;
			if(res == "-1") return 0;
			if(res == "Red") ans[i] = 1;
			else ans[i] = -1;
		}
	}
	cout << "! ";
	for(Int i=0; i<2*n; ++i) cout << (ans[i] == 1 ? 'R' : 'B');
	cout << endl;
}

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

int main() {
  ul n,f[45];
  cin>>n;
  f[0]=1;
  f[1]=1;
  for (size_t i = 2; i <= n; i++)
  {
    f[i]=f[i-1]+f[i-2];
  }
  
  cout<<f[n]<<endl;

  return 0;
}



Measured memory_bytes: 3096
X, K, D = map(int, input().split())
if X - K * D >= 0:
    print(abs(X - K * D))
elif X + K * D <= 0:
    print(abs(X + K * D))
else:
    i = (D * K - X) // (2 * D)
    print(min( abs(X - D * K + 2 * i * D), abs(X - D * K + 2 * (i+1) * D) ))

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

#define ll long long
typedef pair <int, int> ii;
typedef pair <ll, int> lli;
#define ar array
#define pb push_back
#define fi first
#define se second
#define sz size
#define mp make_pair
#define nl '\n'
#define all(x) (x).begin(), (x).end()
#define int_max numeric_limits<int>::max()
#define int_min numeric_limits<int>::min()
#define ll_max numeric_limits<ll>::max()
#define ll_min numeric_limits<ll>::min()

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define im(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// custom sort example
//sort(all(a), [ ]( const auto& c, const auto& d) {
	//if (c.fi.se != d.fi.se) {
		//return c.fi.se < d.fi.se; // lower first
	//}
	//if (c.fi.fi != d.fi.fi) {
		//return c.fi.fi > d.fi.fi; // higher first
	//}
	//return c.se > d.se; // higher first
//});

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
auto lbf(const std::set<std::pair<T, T>>& s, T first)
{
   static constexpr T min = std::numeric_limits<T>::min();

   return s.lower_bound({first, min});
}

int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1;
	for(; k; k >>= 1) {
		if(k&1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t;
	cin >> t;
	if (t == 0) {
		cout << 1 << nl;
	} else {
		cout << 0 << nl;
	}
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n, m, x; cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  ll ans = LMAX;
  bool itta = 0;
  for(int bit = 0; bit < (1 << 12); bit ++){
    vector<ll> ri(n, 0);
    ll sum = 0;
    rep(i, n){
      int d = (1 << i);
      if((d & bit) != 0){
        sum += (ll)c[i];
        rep(j, m) ri[j] += (ll)a[i][j];
      }
    }
    bool sc = 1;
    rep(i, m){
      if(ri[i] < x) sc = 0;
    }
    if(sc){
      itta = 1;
      ans = min(sum, ans);
    }
  }

  if(!itta)
  cout << -1 << endl;
  else
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
bool is_prime(int n){
  for(int i=2; i*i<=n; i++){
    if(n%i == 0) return false;
  }
  return n!=1;
}

int main(void)
{
    int q;cin>>q;
    vector<p> qu;
    vector<int> is(100001);
    vector<int> s(100002, 0);
    for(int i=0; i<q;i++){
      int l,r; cin>>l>>r; qu.push_back(make_pair(l,r));
    }

    for(int i=1;i<=100000;i++){
      if(is_prime(i)&&is_prime((i+1)/2)) is[i]++;
    }

    for(int i=1;i<=100000;i++){
      s[i+1] = s[i] + is[i];
    }

    for(int i=0; i<q;i++){
      cout<<s[qu[i].second+1]-s[qu[i].first]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
    long n;
    scanf("%d\n",&n);
    for(long a=1;a<=3500;a++){
        for(long b=a;b<=3500;b++){
            if(4*a*b - n*b - n*a==0){
                goto nop;
            }
            long c=(n*a*b)/(4*a*b-n*b-n*a);
            long c2=(n*a*b)%(4*a*b-n*b-n*a);
            if(c>=1 && c2==0){
                printf("%ld %ld %ld\n",a,b,c);
                return 0;
            }
nop:;
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
using namespace std;
#define ll long long
typedef pair<int,int>P;
int main(void){
    ll w,h,x,y;
    cin >>w>>h>>x>>y;
    printf("%.10f ",double(w*h/2.0));
    if(w==2*x and h==2*y){
        cout <<1<<endl;
    }else{
        cout << 0<<endl;
    }
    return 0;
}


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

int main(){
	int a,b;
	int k;
	int count=0;
	cin>>a>>b;
	cin>>k;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			count++;
		}
	}
	cout<<count<<endl;
	
}

Measured memory_bytes: 3588
import math

def bunkai(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x%i == 0:
            return [i] + bunkai(x//i)
    return [x]

def snake(a, b):
    a_l = bunkai(a)
    b_l = bunkai(b)
    ans = 1
    for a_i in a_l:
        ans *= a_i
        if a_i in b_l:
            b_l.pop(b_l.index(a_i))
    for b_i in b_l:
        ans *= b_i
    return ans

a, b = [int(i) for i in input().split()]

print(snake(a, b))

Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define SZ 100001

int N;
int arr[SZ];
int res = 0;
int main() {
	cin.tie(NULL); cout.tie(NULL);
	ios::sync_with_stdio(false);

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> arr[i];
		while (arr[i] % 2 == 0) {
			res++; arr[i] /= 2;
		}
	}

	cout << res;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-10
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    
    for (int i = 0; i < 1<<3; i++) {
        int num = s[0] - '0';
        for (int j = 0; j < 3; j++) {
            if (1<<j & i)
                num += s[j+1] - '0';
            else
                num -= s[j+1] - '0';
        }
      
        if (num == 7) {
            for (int j = 0; j < 3; j++) {
                cout << s[j];
                if (1<<j & i)
                    cout << '+';
                else
                    cout << '-';
            }
            cout << s[3] << "=7" << '\n';
            break;
        }
    }
    
    return 0;
}

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

int main(){
	int H,W;

	while(1){
		cin >> H >> W;
		if( H==0 && W==0)
			break;
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout << '#';
			}
			cout << "\n";
		}
		cout << "\n";
	}

	return 0;
	
}

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

int main(){
    int n;cin>>n;
    long long l[87];
    l[0]=2;
    l[1]=1;
    for(int i=2;i<=n;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout<<l[n]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b;

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

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

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

  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

from functools import reduce
xor = reduce(lambda x,y:x^y,A)

ans = [None] * N
for i in range(len(A)):
  ans[i] = xor ^ A[i]
  
print(*ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

bool check(ll k, ll n) {
    while (n >= k && n % k == 0) n /= k;
    return (n % k == 1);
}

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

    ll n;
    cin >> n;
    set<ll> st;

    for (ll i = 2; i * i <= n; i++) {
        if ((n - 1) % i == 0) {
            st.insert(i);
            st.insert((n - 1) / i);
        }
        if (n % i == 0) {
            if (check(i, n)) st.insert(i);
            if (check(n / i, n)) st.insert(n / i);
        }
    }

    st.insert(n - 1);
    st.insert(n);
    st.erase(1);

    cout << (int)st.size();

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const string nl="\n";
const ll MOD=1000000007;

int main(){
  	int n;cin>>n;
  	int cnt=0;
  	for(int i=1;i<=n;i++){
  		int c=0;
  		int t=i;
  		while(t>0){
  			c++;
  			t/=10;
  		}
  		if(c%2) cnt++;
  	}
  	cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
string s;
int q;
cin>>s>>q;
vector<int>t(q);
vector<int>f(q);
vector<char>c(q);
rep(i,q){
    cin>>t[i];
    if(t[i]==2){
        cin>>f[i]>>c[i];
    }
}
int x=0;

rep(i,q){
    
    if(t[i]==1){
    if(x)x=0;
    else x=1;
    continue;}
    if(t[i]==2){
        if(f[i]==1&&x==0){s=c[i]+s;}
        if(f[i]==1&&x==1){s+=c[i];}
        if(f[i]==2&&x==0){s+=c[i];}
        if(f[i]==2&&x==1){s=c[i]+s;}
    }
}
if(x==1)reverse(s.begin(),s.end());
cout<<s;
return 0;


}

Measured memory_bytes: 5884
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

struct st{
	int val;
	char tag;
	st(int _val,char _tag):val(_val),tag(_tag){}
};

vector<st> bubblesort(vector<st> c){
	rep(i,c.size()){
		for(int j = c.size() - 1;j > i;j--){
			if(c[j].val < c[j-1].val)swap(c[j],c[j-1]);
		}
	}
	return c;
}

vector<st> selectionsort(vector<st> c){
	rep(i,c.size()){
		int minj = i;
		FOR(j, i+1 ,c.size()){
			if(c[minj].val > c[j].val)minj = j;
		}
		swap(c[i],c[minj]);
	}
	return c;
}



bool check(vector<st> C1, vector<char> r[]){
	bool f = true;
	rep(i,10){
		int pos = 0;
		rep(j,C1.size()){
			if(C1[j].val == i){
				if(C1[j].tag == r[i][pos])pos++;
				else f = false;
			}
		}
	}
	return f;
}

int n;
vector<st> C;
vector<char> r[10];

int main(){
	cin >> n;
	rep(i,n){
		string s;
		cin >> s;
		r[s[1]-'0'].push_back(s[0]);
		C.push_back(st(s[1]-'0',s[0]));
	}
	
	vector<st> C1 = bubblesort(C);
	rep(i,C1.size()){
		cout << C1[i].tag << C1[i].val;
		if(i != C1.size() - 1)cout << " ";
 	}
	cout << endl;
	if(!check(C1,r))cout << "Not stable" << endl;
	else cout << "Stable" << endl;
	
	C1 = selectionsort(C);
	rep(i,C1.size()){
		cout << C1[i].tag << C1[i].val;
		if(i != C1.size() - 1)cout << " ";
 	}
	cout << endl;
	if(!check(C1,r))cout << "Not stable" << endl;
	else cout << "Stable" << endl;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
 
   int x,y;
   x=(a+d-1)/d;
   y=(b+c-1)/b;
 
   if(x>=y)
    cout<<"Yes";
   else 
    cout<<"No";
 
}

Measured memory_bytes: 3520
object Main extends App {
    val w = Seq(1, 3, -1, 2, 4, 5, 1, -1, 5, 3, 3, 1).grouped(2).toSeq.lift
    val in = io.Source.stdin.getLines
    for (p <- in if p != "#") {
        val x = p.foldLeft(0)((city, way) => w(city) match {
            case None => -1
            case Some(way0or1) => way0or1(way.asDigit)
        })
        if (x == 5) println("Yes")
        else println("No")
    }
}

Measured memory_bytes: 44264
#include<stdio.h>
int G[101][101];
int n;
int m=1;
int A[101][2];

int dfs(int);

int main()
{
  int k,l,m,i,j;
  scanf("%d", &n);
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++) G[i][j]=0;
    A[i][0]=0;
    A[i][1]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d", &m);
    scanf("%d", &k);
    for(j=0;j<k;j++){
      scanf("%d", &l);
      G[m][l] = 1;
    }
  }
  dfs(1);
  for(i=1;i<=n;i++){
    if(A[i][0]==0) dfs(i);
  }
  for(i=1;i<=n;i++) printf("%d %d %d\n", i, A[i][0], A[i][1]);
  return 0;
}

int dfs(int num)
{
  int l;
  if(A[num][0]==0){
    A[num][0]=m;
    m++;
  }
  for(l=0;l<=n;l++){
    if(G[num][l]==1&&A[l][0]==0) dfs(l);
  }
  if(A[num][1]==0){
    A[num][1]=m;
    m++;
  }
  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

const long long INF=9000000000000000;
int main(){
  long long n,ans=0;
  cin>>n;
  long long a[n];
  long long b[n];
  long long c[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  for(int i=0;i<n;i++){
    ans+=1*(lower_bound(a,a+n,b[i])-a)*(c+n-upper_bound(c,c+n,b[i]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
n = int(input())
A = list(map(int, input().split()))
a = []
for i in range(len(A)):
    a.append([A[i], i])
a.sort(key = lambda x: x[0], reverse = True)
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(n):
    for l in range(i+1):
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + a[i][0]*(n-1-(i-l)-a[i][1]))
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + a[i][0] * (a[i][1] - l))
ans = 0
for now in dp[n]:
    ans = max(now, ans)
print(ans)




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


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    ll manzoku = 0;
    for(auto x: B)
        manzoku += x;
    for (int i = 0; i < N; i++) {
        if(A[i] + 1 == A[i+1]){
            manzoku += C[A[i] - 1];
        }
    }
    

    cout << manzoku << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


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

using namespace std;
using ll=long long;
template <typename T=int>
struct Rmq {
    vector<T> raw;
    static const int LOG = 19; // 20;
    int k;
    int n;
    vector<int> st[LOG];
    Rmq(vector<T> _v) { // pass in vec[0, n)
        raw = _v;
        n = raw.size();
        k = 32 - __builtin_clz(n);
        for (int j = 0; j < k; j++) {
            st[j].resize(n);
        }
        build();
    }
    inline int comp(int x, int y) { // DO! > max
        return raw[x] < raw[y] ? x : y;
    }
    void build() {
        for (int i = 0; i < n; i++) {
            st[0][i] = i;
        }
        for (int j = 1; j < k; j++) {
            for (int i = 0; i + (1<<j) <= n; i++) {
                st[j][i] = comp(st[j-1][i], st[j-1][i + (1<<(j-1))]);
            }
        }
    }
    // [l, r)
    inline int query_id(int l, int r) {
        assert(0 <= l && l < r && r <= n);
        int j = 31 - __builtin_clz(r - l);
        return comp(st[j][l], st[j][r - (1<<j)]);
    }
    inline T query(int l, int r) {
        return raw[query_id(l, r)];
    }
};

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

struct Edge {
    int x, y;
    ll cost;
    Edge() {}
    Edge(int _x, int _y, ll _cost) : x(_x), y(_y), cost(_cost) {}
    bool operator<(const Edge& _oth) const {
        return cost < _oth.cost;
    }
};

void solve() {
    int n; ll D;
    cin >> n >> D;
    vector<ll> a(n), L(n), R(n);
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        a[i] = x;
        L[i] = x - i*D;
        R[i] = x + i*D;
    }
    Rmq<ll> mL(L), mR(R);
    
    vector<Edge> es;
    function<void(int,int)> cut = [&](int l, int r){
        if (r-l <= 1) return;
        int m = (r+l)/2;
        int i = mL.query_id(l, m);
        for (int k = m; k < r; k++) {
            es.emplace_back(i,k, R[k]+L[i]);
        }
        int j = mR.query_id(m, r);
        for (int k = l; k < m; k++) {
            es.emplace_back(j,k, L[k]+R[j]);
        }
        cut(l, m);
        cut(m, r);
    };
    cut(0, n);
    sort(es.begin(), es.end());
    
    Dsu d(n);
    ll res = 0;
    for (auto& e: es) {
        if (!d.check(e.x, e.y)) {
            res += e.cost;
            d.join(e.x, e.y);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 106332
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        op: String,
        b: i64,
    }
    println!("{}",
        match op.as_ref() {
            "+" => a + b,
            "-" => a - b,
            _   => panic!(),
        }
    );
}


Measured memory_bytes: 4352
n = int(input())
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
left = 0
right = s
for i,l in enumerate(li):
    if i == len(li)-1:
        break
    left += l
    right -= l
    sum_li.append(abs(left-right))
print(min(sum_li))

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

int main(){
  vector<int> v(3);
  for(int i=0;i<3;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  cout << abs(v.at(0)-v.at(1))+abs(v.at(1)-v.at(2)) << endl;
  return 0;
}


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

int main(void)
{
    int i,j,k,n,s;
    char a[201],b[201];
    
    while(1){
        scanf("%s\n%d",a,&n);
        if(!strcmp(a,"-")) break;
        
        for(i=0;i<n;i++){
            scanf("%d",&s);
            for(j=s;a[j]!='\0';j++)
                b[j-s]=a[j];
            for(k=0;k<s;k++)
                b[j-s+k]=a[k];
            
            for(j=0;a[j]!='\0';j++)
                a[j]=b[j];
    }
    printf("%s\n",a);
    }
    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

double Mcos(double k){return cos(k*atan(1.0)*4/180);}

string monmo(int a,int b,int c){
    if(b>a && c>b){
        return "Yes";
    }else{
        return "No";
    }
}

int main() {
    ll money=1000;
    ll hikae=0;
    int n;
    int flag=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int niti=0;
    while(niti<n){
        int i=niti;
        flag=0;
        niti++;
        int kabu=v[i];
        for(int j=i+1;j<n;j++){
            if(kabu>=v[j]){
                kabu=v[j];
                niti++;
            }else{
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<money;
            exit(0);
        }
        hikae=money/kabu;
        money=money%kabu;
        money+=hikae*v[niti];
    }
    cout<<money;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

	string S;
	cin >> S;
	S = '0' + S;
	int N = S.size();
	int ans = 0;
	int count = 0;
	for(int i=N-1;i>=1;i--){
		int x = S[i] - '0';
		int y = S[i-1] - '0';
		x += count;
		if(x < 5 || (x == 5 && y < 5)){
			ans += x;
			count = 0;
		}
		else{
			ans += 10 - x;
			count = 1;
		}
	}
	cout << ans + count << endl;
}

Measured memory_bytes: 2332
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	ll h, n;
	cin >> h >> n;
	ll m = 0;

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

	if (h<=m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;

int main(){

	int n;
	cin>>n;
	
	int k = 3;
	while(k--){
		if(n%10 == 7){
			cout<<"Yes\n";
			return 0;
		}
		n/=10;
	}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int max = 0;
    rep(i, n)
    {
        if (s[i] == 'I')
        {
            x++;
        }
        else if (s[i] == 'D')
        {
            x--;
        }
        if (x > max)
        {
            max = x;
        }
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
(K, N) = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(A[0]+K)
A_next = []

max = 0
result = 0
j = 0
k = 0
#print(A)
for x in range(1, len(A)):
  #print(x)
  #print(A[x]-A[x-1])
  #print(A[x-1])
  #print(A_next)
  A_next.append(abs(A[x] - A[x-1]))
  if max < A_next[j]:
    max = A_next[j]
    #print(max)
    k = j
  j += 1
#print(k)
#print(A_next)
for x in range(len(A_next)):
  if x == k:
    pass
  else:
    result += A_next[x]
print(result)


    

Measured memory_bytes: 26444
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

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

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && 0<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int x,y;
  cin>>x>>y;

  cout<<x+y/2<<endl;
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

int main(){
    int ans=0;
    int a;
    int ac=0,wa=0,tle=0,re=0;
    int N;
    string S;
    cin >> N;
    vector<ll>v;
    for(int i=0; i<N; i++){
        cin >> a;
        v.push_back(a);
    } 
    if(N < 3){
        cout << ans << endl;
        return 0;
    }
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            for(int k=j+1; k<N; k++){
                if(v[i]!=v[j] && v[k]!=v[j] && v[i]!=v[k]){
                    if(v[i]+v[k]>v[j] && v[k]+v[j]>v[i] && v[i]+v[j]>v[k]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        sc.close();

        long ans = 0;

        if (Math.abs(n - m) > 1) {
            System.out.println(ans);
            return;
        }

        long mod = 1000000007L;
        long tmp = fact(n, mod) * fact(m, mod);

        if (n == m) {
            tmp *= 2;
        }

        ans = tmp % mod;
        System.out.println(ans);

    }

    static long fact(long n, long mod) {
        long res = 1;
        while (n > 1) {
            res *= n;
            res %= mod;
            n--;
        }
        return res;
    }
}

Measured memory_bytes: 23252