akhauriyash/Code-Regression huggingface dataset:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    trans = [I(), I(), I(), I(), I()]
    ans = 0
    if n%min(trans) == 0:
        ans = n//min(trans) + 4
    else:
        ans = n//min(trans) + 5
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c<<endl;
	else if(a==c)cout<<b<<endl;
	else cout<<a<<endl;
}


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

// グラフ、頂点の入次数、頂点数を受け取り、そのトポロジカルソートを記録した配列を返す関数
vector<int> topological_sort(vector<vector<int>> &G, vector<int> &indegree, int V) {
    // トポロジカルソートを記録する配列
    vector<int> sorted_vertices;

    // 入次数が0の頂点を発見したら、処理待ち頂点としてキューに追加する
    queue<int> que;
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }

    // キューが空になるまで、操作1~3を繰り返す
    while (que.empty() == false) {
        // キューの先頭の頂点を取り出す
        int v = que.front();
        que.pop();

        // その頂点と隣接している頂点の入次数を減らし、0になればキューに追加
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        // 頂点vを配列の末尾に追加する 
        sorted_vertices.push_back(v);
    }

    // トポロジカルソートを返す
    return sorted_vertices;
}

int main(void) {
    // 頂点数と辺の本数
    int V, E;
    cin >> V >> E;

    // 隣接リストにより表現されるグラフ
    vector<vector<int>> G(V);
    // 頂点の入次数を記録する配列
    vector<int> indegree(V);
    for (int i = 0; i < E; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        indegree[v] += 1;
    }

    // トポロジカルソートする
    vector<int> sorted_vertices = topological_sort(G, indegree, V);

    // トポロジカルソートを出力
    for (int i = 0; i < sorted_vertices.size(); i++) {
        cout << sorted_vertices[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3760
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var params = input[0].split(' ');
    var n = parseInt(params[0], 10);
    var a = parseInt(params[1], 10);
    var b = parseInt(params[2], 10);

    if (a * n < b) {
        console.log(a * n);
    }
    else {
        console.log(b);
    }

    return 0;
}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

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 round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
target = 'keyence'

for i in range(len(target)+1):
    a = target[:i]
    b = target[i:]
    if re.match('^' + a + '.*' + b + '$', S):
        print('YES')
        exit()
print('NO')


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

using ll = long long;
using P = pair<ll, ll>;

constexpr ll INF = 1e18;

void dfs(int i, int const last, vector<P>& res, vector<P> const& input, ll diff, ll val) {
    if(i == last) {
        res.emplace_back(diff, val);
        return;
    }
    dfs(i+1, last, res, input, diff-input[i].first, val-input[i].second);
    dfs(i+1, last, res, input, diff, val);
    dfs(i+1, last, res, input, diff+input[i].first, val+input[i].second);
}

int main() {
    int N;
    ll D;
    cin >> N >> D;

    vector<P> input(N);
    for(int i=0; i<N; ++i) {
        cin >> input[i].first >> input[i].second;
    }

    int N1 = N/2;
    vector<P> v1, v2;
    v1.reserve((int)pow(3, N1));
    v2.reserve((int)pow(3, N-N1));
    dfs(0, N1, v1, input, 0, 0);
    dfs(N1, N, v2, input, 0, 0);
    sort(v1.rbegin(), v1.rend());
    sort(v2.begin(), v2.end());

    ll ans = -INF;
    int t = 0;
    deque<P> deq;
    for(int i=0; i<v1.size(); ++i) {
        while(t < v2.size() && v2[t].first + v1[i].first <= D) {
            while(!deq.empty() && deq.back().second <= v2[t].second) {
                deq.pop_back();
            }
            deq.push_back(v2[t]);
            ++t;
        }
        while(!deq.empty() && deq.front().first + v1[i].first < -D) {
            deq.pop_front();
        }
        if(!deq.empty()) {
            ans = max(ans, v1[i].second + deq.front().second);
        }
    }
    cout << ans << endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  int move = 0;
  int position;
  
  for (int i = 0; i < N; i++){
    cin >> position;
    if (position < K - position){
      move += 2*position;
    }
    else{
      move += 2*(K-position);
    }
  }
  cout << move << endl;
}

Measured memory_bytes: 256
# ....#..#..##.####
# まず、左端の.と右端の#は答えに影響しないので削除する。
# ....#..#..##.####
# #..#..##.
# この結果の文字列が0であればそこで終了
# そうでない場合、
# この結果に対して、黒と白のペアを作って数を数える
# [1,2][1,2][2,1]
# すべて黒にする場合、
# 2 + 2 + 1
# となる
# 白を選ぶ場所を一つずつずらすと、
# 1 + 2 + 1
# 1 + 1 + 1
# 1 + 1 + 2
# となり、1 + 1 + 1が最小値
# これを求める

N=int(input())
S=input()
from collections import deque
q=deque(list(S))
# print(q)

while q[0]==".":
  q.popleft()
  if len(q)==0:
    print(0)
    exit(0)
  
while q[-1]=="#":
  q.pop()
  if len(q)==0:
    print(0)
    exit(0)
  
S="".join(list(q))
pairs=S.replace(".#",". #").split()
# print(pairs)
datas=[[]]*len(pairs)
blackchange=0
for i in range(len(pairs)):
  white=pairs[i].count(".")
  datas[i] = [len(pairs[i])-white,white]
  blackchange+=white

# print(datas)
ans=blackchange
# print(ans)
for i in range(len(datas)):
  blackchange-=(datas[i][1]-datas[i][0])
  if ans > blackchange:
    ans = blackchange
print(ans)

Measured memory_bytes: 21768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int ans = 0;
    rep3(i, 1, n) {
        if ((s[i] == 'O' && s[i - 1] == 'X') || (s[i] == 'X' && s[i - 1] == 'O')) { ans++; i++; }
        
    }
    cout << ans << endl;
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  vector <ll> v(120, 0);
  ll n;
  cin >> n;
  ll a, b, c, d;
  rep(i, n) {
    cin >> a >> b >> c >> d;
    v.at(30*(a-1)+10*(b-1)+c-1) += d;
  }
  rep(i, 12) {
    if (i%3 == 2) {
      rep(j, 10) {
        cout << ' ' << v.at(10*i+j);
      }
      cout << endl;
      if (i != 11) {
        cout << "####################" << endl;
      }
    } else {
      rep(j, 10) {
        cout << ' ' << v.at(10*i+j);
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 3116
#include<queue>
#include<cstdio>
#include<algorithm>
#define MN 610000
#define INF 1000000000
#define l(x) x<<1
#define r(x) (x<<1)|1
using namespace std;

int read_p,read_ca,read_f;
inline int read(){
	read_p=0;read_ca=getchar();read_f=1;
	while (read_ca<'0'||read_ca>'9') read_f=read_ca=='-'?-1:read_f,read_ca=getchar();
	while (read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
	return read_p*read_f;
}
int H,W,h,w;
int main(){
	H=read();W=read();h=read();w=read();
	
	if ((H/h)*(W/w)*(1000*(h*w-1)+1)>=1000*(H*W-(H/h)*(W/w))) return puts("No"),0;
	puts("Yes");
	for (int i=1;i<=H;i++,puts(""))
	for (int j=1;j<=W;j++)
	if (i%h==0&&j%w==0) printf("%d ",-(1000*(h*w-1)+1));else printf("%d ",1000);
}

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

int T, n, k, ans;

int main() {
    scanf("%d", &T);
    while (T--) {
        function<int(int, int)> SG = [&](int n, int k) {
            if (n < k || !(n % k)) return n / k;
            int v = n / k + 1, bound = n - k * (n / k);
            return SG(n - (bound + v - 1) / v * v, k);
        };
        scanf("%d %d", &n, &k), ans ^= SG(n, k);
    }
    printf("%s\n", ans ? "Takahashi" : "Aoki");
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int A = int.Parse(s[0]);
            string op = s[1];
            int B = int.Parse(s[2]);

            if (op == "+")
            {
                Console.WriteLine(A+B);
            }
            else
            {
                Console.WriteLine(A - B);
            }
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n;
	cin >> n;
	cout << 3 * n * n;
}

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

int main(){
	long long int k,a,b;
	cin>>k>>a>>b;
	long long int c=0;
	if(b-a<2){
		cout<<1+k;
		return 0;
	}
	if(k<=a-1){
		cout<<1+k;
		return 0;
	}
	cout<<k+1-((k-a+1)/2)*2+((k-a+1)/2)*(b-a);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;

int mx[210],my[210],nx[1010],ny[1010];
int main(){
	int M,N,mix,mux,miy,muy,mixy,zrx,zry;
	int gex,gey,ocnt;
	while(1){
	cin>>M;
	if(M==0) break;
	for(int i=0;i<M;i++){
		cin>>mx[i]>>my[i];
	}
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>nx[i]>>ny[i];
	}

	//????°?????????§???
	mix=miy=INF;
	mux=muy=-1;
	for(int i=0;i<M;i++){
		miy=min(miy,my[i]);
		mux=max(mux,mx[i]);
		muy=max(muy,my[i]);
		if(mix>mx[i]){
			mix=mx[i];
			mixy=my[i];
		}
	}

	for(int i=0;i<M;i++){
		mx[i]-=mix;
		my[i]-=mixy;
	}
	zrx=-mix;
	zry=-mixy;
	miy-=mixy;
	mux-=mix;
	muy-=mixy;
	mix=0;
	mixy=0;

	//
	//cout<<mix<<" "<<mux<<" "<<miy<<" "<<muy<<" "<<zrx<<" "<<zry<<" "<<endl;
	//

	for(int i=0;i<N;i++){
		//???????????¶
		if(ny[i]>=(-miy)){
			gex=nx[i];
			gey=ny[i];
			ocnt=0;
			//?????§?????? cnt???????????????
			for(int j=0;j<M;j++){
				for(int k=0;k<N;k++){
					if(gex+mx[j]==nx[k]&&gey+my[j]==ny[k]){
						//cout<<" "<<gex<<"+"<<mx[j]<<"="<<nx[k]<<"  "<<gey<<"+"<<my[j]<<"="<<ny[k]<<endl;
						ocnt++;
					}
				}
			}
			if(ocnt==M){
				cout<<zrx+gex<<" "<<zry+gey<<endl;
				goto de;
			}
		}
	}
	cout<<"????????§????????£????????¨?????¨??????"<<endl;
de:;
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
const int maxV = 222222;
vector<int> G[maxV]; // 頂点情報のみのグラフ

// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離, 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
    // 距離と終点を更新
    if (dist > maxDist) {
        maxDist = dist;
        maxVertex = current;
    }

    for (auto to : G[current]) {
        // 逆流を防ぐ
        if (to == from) continue;
        treeDFS(current, to, dist + 1, maxDist, maxVertex);
    }
}

int getTreeDiameter() {
    int start = 0, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
		return maxDist;
}

signed main() {
	cin >> N;
	rep (i, N-1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int dia = getTreeDiameter();
	// int dia;
	// cin >> dia;
	
	dbg(dia)
	puts(dia % 3 == 1 ? "Second" : "First");


	return 0;
}


Measured memory_bytes: 27264
#include <iostream>
#include <queue>

using namespace std;

int main(void)
{
  int goods_count;
  int tickets_count;
  priority_queue<int> values;
  
  cin >> goods_count >> tickets_count;
  
  for(int i = 0; i < goods_count; i++){
    int v;
    cin >> v;
    values.push(v);
  }
  
  for(int i = 0; i < tickets_count; i++){
    int expensive = values.top();
    values.pop();
    values.push(expensive / 2);
  }
  
  long long total_value = 0;
  for(int i = 0; i < goods_count; i++){
    total_value += values.top();
    values.pop();
  }
  
  cout << total_value << endl;
  
  return 0;
}

Measured memory_bytes: 892
N, M = map(int, input().split())
a = {}
for i in range(M):
    a[int(input())] = 1

memo = {
    0: 1
}
queue = [0]
counter = 0
def step(height, n):
    if height + n not in memo:
        memo[height + n] = memo[height]
        queue.append(height + n)
    else:
        memo[height + n] += memo[height]


while counter < len(queue):
    # print(memo, queue, counter)
    item = queue[counter]
    counter += 1
    if item + 1 not in a and item + 1 <= N:
        step(item, 1)
    if item + 2 not in a and item + 2 <= N:
        step(item, 2)

if N not in memo:
    print(0)
else:
    print(memo[N] % 1000000007)

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

public class Hello
{
    public static void Main()
    {
    　　
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        string[] array = new string[N];
        bool ans = true;
        
        for(int i = 0; i < N; i++)
        {
            array[i] = Console.ReadLine();
        }
        
        for(int i = 0; i < N - 1; i++) //最後の文字と最初の文字が一致するかチェック
        {
            if(array[i][array[i].Length - 1] != array[i + 1][0])
            {
                ans = false;
            }
            
        }
        
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < i; j++)
            {
                if(array[i] == array[j])
                {
                    ans = false;
                }
            }
        }
        
        if(ans == true)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}


Measured memory_bytes: 13140
#include <climits>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
 
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int m, c, n; cin >> m >> c >> n && m;) {
		vector<unordered_map<int, int>> desks(m);
 
		queue<int> que;
		vector<int> index(n, 0);
		vector<vector<int>> books(n);
 
		for(int i = 0; i < n; ++i) {
			que.push(i);
 
			int k;
			cin >> k;

			books[i].reserve(k);
 
			for(int j = 0; j < k; ++j) {
				int b;
				cin >> b;
				books[i].emplace_back(b);
			}
		}
 
		int ans = 0;

		for(int t = 0; !que.empty(); ++t) {
			const int student = que.front();
			que.pop();
 
			const int id = books[student][index[student]];
			if(++index[student] < books[student].size()) {
				que.push(student);
			}

			int pos = m;
			for(int i = 0; i < m; ++i) {
				if(desks[i].count(id)) {
					desks[i].erase(id);
					pos = i;
					break;
				}
			}
 
			ans += pos + 1;
 
			int tmp = m;
			for(int i = 0; i < m; ++i) {
				if(desks[i].size() < c) {
					desks[i].insert({id, t});
					tmp = i;
					break;
				}
			}
 
			ans += tmp + 1;
 
			if(tmp != 0) {
				int r_id = -1;
				int r_time = INT_MAX;
 
				for(const auto &e : desks.front()) {
					if(r_time > e.second) {
						r_id = e.first;
						r_time = e.second;
					}
				}
 
				ans += 1;
				desks.front().erase(r_id);
 
				int to = m;
				for(int i = 1; i < m; ++i) {
					if(desks[i].size() < c) {
						desks[i].insert({r_id, r_time});
						to = i;
						break;
					}
				}
 
				ans += to + 1;
 
				if(tmp < m) desks[tmp].erase(id);
				ans += tmp + 1;
 
				desks.front().insert({id, t});
				ans += 1;
			}
		}
 
 
		cout << ans << endl;
	}
 
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 200010

int main(){
	IOS;
	tihs;

	ll n,a,b;cin>>n>>a>>b;
	ll dif=b-a;
	if(dif%2==0){
		cout<<dif/2;
		return 0;
	}
	cout<<min(a-1ll,n-b)+1+(dif-1)/2;
	


	return 0;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a,b;
	cin>>n>>a>>b;
	ll c=b-a+1;
	if(c&1)
	{
		cout<<c/2;
	}
	else
	{
		cout<< min(a-1,n-b)+1+(c-1)/2;
	}
    return 0;
}


//252908XL

Measured memory_bytes: 256
# XとYの二部グラフの最大マッチング X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}
#   edges[x]: xとつながるYの頂点のset
#   matched[y]: yとマッチングされたXの頂点(暫定)
 
def dfs(v, visited):
    """
    :param v: X側の未マッチングの頂点の1つ
    :param visited: 空のsetを渡す（外部からの呼び出し時）
    :return: 増大路が見つかればTrue
    """
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False
 
 
# 標準入力からのグラフ読み取り
n = int(input())

r = [[0,0] for i in range(n)]
for i in range(n) :
  x,y = map(int,input().split())
  r[i][0],r[i][1] = x,y
  
b = [[0,0] for i in range(n)]
for i in range(n) :
  x,y = map(int,input().split())
  b[i][0],b[i][1] = x,y

edges = [set() for _ in range(n)]
matched = [-1] * n
  
for i in range(n) :
  for j in range(n) :
    if r[i][0] < b[j][0] and r[i][1] < b[j][1] :
      edges[i].add(j)
      
# 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる
print(sum(dfs(s, set()) for s in range(n)))

Measured memory_bytes: 3188
n = int(input())
li = list(map(int,input().split()))

a = li[0]
b = sum(li[1:])
ans = abs(b-a)
for i in range(1,n-1):
  a += li[i]
  b -= li[i]
  ans = min(ans,abs(b-a))
print(ans)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
using namespace std;
/*bool is(long long a){
    if(a==2) return true;
    if(a<=1||a%2==0) return false;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0) return false;
    }
    return true;
}*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout.setf(ios_base::fixed,ios_base::floatfield);
    int n,z=0,g=100000009;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int j=1;j<=100;j++){
        for(int i=0;i<n;i++){
            z+=abs(a[i]-j)*abs(a[i]-j);
        }
        g=min(g,z);
        z=0;
    }
    cout<<g<<'\n';
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mx 100005
#define INF 1000000007
using namespace std;

int d, g, p[12], c[12], ans = INF;

int main(){
  scanf("%d%d", &d, &g); g /= 100;
  for(int i = 0; i < d; i++) {
    scanf("%d%d", p+i, c+i); c[i] /= 100;
  }
  for(int i = 0; i < (1<<d); i++) {
    int tmp = 0, tsc = 0, k = 0, l = 0;
    for(int j = 0; j < d; j++) {
      if((i>>j)&1){
        tmp += p[j];
        tsc += (j+1)*p[j] + c[j];
      }else k = j;
    }
    while(tsc < g &&  p[k] > l) tsc += k+1, l++, tmp++;
    if(tsc >= g) ans = min(ans, tmp);
  }
  printf("%d\n", ans);
}


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 P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	ll a[2], b[2];
	rep(i, 2) cin >> a[i];
	rep(i, 2) cin >> b[i];
	ll ans = 0;
	int flg = 0;
	rep(i, 2) {
		rep(j, 2) {
			if (flg == 0) {
				ans = a[i] * b[j];
				flg = 1;
			}
			if (ans < a[i] * b[j]) {
				ans = a[i] * b[j];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
import time
from math import ceil
from collections import defaultdict, deque


def A(s):
  if s[-1] == 's':
    return s + 'es'
  return s + 's'


def D(n):
  pass


def main():
  s = input()
  print(A(s))


if __name__ == '__main__':
  main()


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

int main(){
    int n;
    cin >> n;
    vector<float> v(n);
    rep(i,n) cin >> v[i];
    sort(ALL(v), greater<float>());
    for(int i = n-1; 0 < i; --i){
        v[i-1] = (v[i]+v[i-1])/2;
    }
    cout << v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
N = input()
N = int(N)
A = list(map(int,input().split()))
B = [ i for i in A if i % 2 ==0]
C = [ d for d in B if  d % 3 == 0 or d % 5 == 0]
R = len(C)
Q = len(B)
if R == Q:
  print("APPROVED")
  
else:
  print("DENIED")
 

Measured memory_bytes: 3060
from itertools import combinations_with_replacement

N, M ,Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for i in range(Q)]
#ABCD = sorted(ABCD, key = lambda x: x[3], reverse = True)

def score(A, ABCD):
  ans = 0
  for i in range(Q):
    x = ABCD[i]
    if A[x[1] - 1] - A[x[0] - 1] == x[2]:
      ans += x[3]
  return ans


b = []
for i in range(M):
  b.append(i + 1)
  
A = list(combinations_with_replacement(b, N))

ans = 0
for i in A:
  B = list(i)
  ans = max(ans, score(B, ABCD))
print(ans)



Measured memory_bytes: 21620
#include<stdio.h>
int main(void)
{
	int t,m,s=0,i;
	for(i=0; i<4; i++)
	{
		scanf("%d", &t);
		s+=t;
	}
	m=s/60;
	s-=m*60;
	printf("%d\n%d\n", m, s);
	
	return 0;
}


Measured memory_bytes: 2108
from sys import stdin


# 最大化問題
def chmax(a,b):
    if a < b: return b
    else: return a


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    a_b_c_arr = []
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        a_b_c_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [[0] * 3 for _ in range(N+1)] # 最大化問題 (初期条件 dp=0)
    
    # 配るDP
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][k] = chmax(dp[i+1][k],dp[i][j]+a_b_c_arr[i][k])
    cnt = max(dp[N])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 95708
#include <stdio.h>
int main ()
{
	int X, A, B, num1, num2;
	scanf ("%d %d %d", &X, &A, &B);
	if (X>A){
		num1= X-A;
	} else if (X<A){
		num1 = A-X;
	}
	if (X>B){
		num2 = X-B;
	} else if (X<B){
		num2 = B-X;
	} 
	if ( num1 < num2 )
	{
		printf ("A");
	} else if ( num1 > num2 )
	{
		printf ("B");
	}
return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    ll ans = 0;
    for(ll i = 0; i < s.size(); i++)
    {
        ll temp = 0;
        for(ll k = i; k < s.size(); k++) {
            if (s[k] == 'A' || s[k] == 'T' ||s[k] == 'G' ||s[k] == 'C') {
                temp++;
            }
            else
            {
                break;
            }
            
        }
        ans = max(ans, temp);
    }
    
    cout << ans << endl;
}

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

int N, M, Q;
vi a(50), b(50), c(50), d(50);
vi st;

int dfs(vi &st){
  if(st.size() == N){
    int point = 0;
    for(int i=0; i<Q; i++){
      if(st[b[i]]-st[a[i]]==c[i])point+=d[i];
    }
    return point;
  }

  int ans = 0;
  int last = (st.empty()? 0: st.back());
  for(int i=last; i<M; i++){
    st.push_back(i);
    ans = max(ans, dfs(st));
    st.pop_back();
  }
  return ans;
}

int main(){
  cin>>N>>M>>Q;
  for(int i=0; i<Q; i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
  }

  int ans = dfs(st);

  cout<<ans<<endl;
}

Measured memory_bytes: 3572
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def std_in():
    return sys.stdin.readline().strip()


def main():
    n = int(std_in())
    a = list(get_ints())

    step = 0
    prev = a[0]
    for i in range(1, n):
        if prev > a[i]:
            tmp = prev - a[i]
            a[i] = prev
            step += tmp
        else:
            prev = a[i]
    print(step)


if __name__ == "__main__":
    main()


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

int main(){
    ll Q; cin >> Q;
    vector<pair<int,int> > qry(Q);
    rep(i, 0, Q){
        cin >> qry[i].first >> qry[i].second;
        if(qry[i].first > qry[i].second) swap(qry[i].first, qry[i].second);
    }
    rep(i, 0, Q){
        ll A = qry[i].first , B = qry[i].second;
        if(A == B){cout << A + B - 2 << endl; continue;}
        ll mul = A * B;
        ll ans = A - 1;

        ll lb = 0, ub = 1e9 + 1;
        while(ub-lb > 1){
            ll m = (lb + ub) / 2;
            if(m * m < mul) lb = m;
            else ub = m;
        }
        //cerr << i << " " << lb << endl;
        if(lb * (lb + 1) < mul) ans += lb + 1 + lb - 1 - A;
        else ans += lb + lb - 1 - A;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 19191919;
const int N = 222222;
const int A = 26;

int dp[N];
int memo[1<<A];

int main()
{
    string s;
    cin >>s;
    int S = s.size();

    fill(dp,dp+N,INF);
    fill(memo,memo+(1<<A),INF);

    vector<int> v;
    v.pb(0);
    rep(i,26) v.pb(1<<i);

    dp[0] = 0;
    memo[0] = 0;

    int ai = 0;
    rep(i,S)
    {
        int x = s[i]-'a';
        ai ^= (1<<x);

        for(int j:v) dp[i+1] = min(dp[i+1],memo[ai^j]+1);
        memo[ai] = min(memo[ai],dp[i+1]);
    }

    printf("%d\n", dp[S]);
    return 0;
}


Measured memory_bytes: 263556
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    c,d = map(int, input().split())
    e,f = map(int, input().split())
    c = Counter([a,b,c,d,e,f])
    a = 0
    b = 0
    for i in c.values():
        if i==1:
            a+=1
        if i==2:
            b+=1
    if a==2 and b==2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

int main(){
    int k, s;
    cin >> k >> s;
    int cnt=0;
    for(int i=0; i<=k; ++i){
        for(int j=0; j<=k; ++j){
            int z = s-i-j;
            if(!(z<0 || z>k))
                cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 305;
const int MOD = 1000000007;
vector < pair<int,int> > A[MAXN];
int dp[MAXN][MAXN][MAXN];
void mod_add(int &x, int y)
{
	x = (x + y)%MOD;
}
int main()
{
	int n,m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i)
	{
		int ty, l, r;
		scanf("%d %d %d", &l, &r, &ty);
		A[r].push_back(make_pair(l,ty));
	}
	dp[0][0][0] = 1;
	int ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			for (int k = 0; k <= n; ++k)
			{
				int pos[] = {i,j,k};
				sort(pos, pos+3);
				for (int ii = 0; ii < A[pos[2]].size(); ++ii)
				{
					int l = A[pos[2]][ii].first;
					int num = A[pos[2]][ii].second;
					if(num == 1 && pos[1] >= l)
						dp[i][j][k] = 0;
					if(num == 2 && (pos[0] >= l || pos[1] < l))
						dp[i][j][k] = 0;
					if(num == 3 && pos[0] < l)
						dp[i][j][k] = 0;
				}
				mod_add(dp[pos[2] + 1][j][k], dp[i][j][k]);
				mod_add(dp[i][pos[2] + 1][k], dp[i][j][k]);
				mod_add(dp[i][j][pos[2] + 1], dp[i][j][k]);
				if(pos[2] == n)
					mod_add(ans, dp[i][j][k]);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 110848
#include<iostream>
using namespace std;
int main()
{
	int t[5];
	for(int i=0;i<5;i++)
	t[i]=0;
	int a1,b1,a2,b2,a3,b3;
	cin>>a1>>b1>>a2>>b2>>a3>>b3;
	t[a1]++;
	t[b1]++;
	t[a2]++;
	t[b2]++;
	t[a3]++;
	t[b3]++;
	int res=0;
	for(int i=1;i<=4;i++)
	{
		if(t[i]==0) res=1;
		if(t[i]>2) res=1;
	}
	if(res) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int n;
  cin>>n;
  if(n%2==0){
    cout<<(n-2)/2;}
  else{
    cout<<(n-1)/2;}
  cout<<endl;
  return 0;
 
}
 

Measured memory_bytes: 256
import math
n,d = map(int, input().split())

x_list=[]

for i in range(n):
   x_list.append(list(map(int, input().split())))

ans=0
for i in range(n):
  for j in range(i+1,n):
    #print(i,j)
    tmp=0
    for s in range(d):
      #print(s)
      tmp+=(x_list[i][s]-x_list[j][s])**2
    kai=math.sqrt(tmp)
    if kai.is_integer():
      ans+=1
print(ans)      

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


int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    int x, y, z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int main()
{
	int h,w;
	char s[105];
	while(~scanf("%d%d",&h,&w)){
		for(int i = 1;i <= h;i++){
			scanf("%s",s + 1);
			puts(s + 1);
			puts(s + 1);
		}
	}
    return 0;
}

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

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  int res = 1 << 30;
  int cnt = 0;
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    res = min(res,abs(a[i]));
    if(a[i] < 0) cnt++;
    sum += abs(a[i]);
  }
  if(cnt%2 == 1) sum -= res * 2;
  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

var mat [][]int
var visited []bool
var ans []int
var outindex map[string]int
var k int

func dfs(cur, color int) {
	visited[cur] = true

	nexts := mat[cur]
	i, nxcolor := 0, 1
	for i < len(nexts) {
		if visited[nexts[i]] {
			i++
			continue
		}
		if nxcolor == color {
			nxcolor++
			continue
		}

		dfs(nexts[i], nxcolor)

		k = max(k, nxcolor)
		outi := outindex[strconv.Itoa(cur)+"-"+strconv.Itoa(nexts[i])]
		ans[outi] = nxcolor

		i++
		nxcolor++
	}
}

func main() {
	n := readInt()

	mat = make([][]int, n)
	for i := range mat {
		mat[i] = make([]int, 0)
	}

	outindex = make(map[string]int)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		mat[a] = append(mat[a], b)
		mat[b] = append(mat[b], a)

		aa, bb := strconv.Itoa(a), strconv.Itoa(b)
		outindex[aa+"-"+bb] = i
		outindex[bb+"-"+aa] = i

	}

	visited = make([]bool, n)
	visited[0] = true
	ans = make([]int, n-1)

	dfs(0, -1)

	fmt.Println(k)
	for i := range ans {
		fmt.Println(ans[i])
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 47360
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0,mins=n+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mins){
			ans+=mins-a[i]-1;
			mins=a[i];
		}
	}
	cout<<n-ans;
}

Measured memory_bytes: 5152
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[0] * W for _ in range(H)]
dpl = [[0] * W for _ in range(H)]
dpd = [[0] * W for _ in range(H)]
dpu = [[0] * W for _ in range(H)]

for i in range(H):
    s.append(input())

# to right
for i in range(H):
    for j in reversed(range(W)):
        if j == W-1 and s[i][j] == '.':
            dpr[i][j] = 1
        elif s[i][j] == '#':
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1

# to left
for i in range(H):
    for j in range(0, W):
        if j == 0 and s[i][j] == '.':
            dpl[i][j] = 1
        elif s[i][j] == '#':
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpl[i][j-1] + 1

# to down
for i in reversed(range(H)):
    for j in range(W):
        if i == H-1 and s[i][j] == '.':
            dpd[i][j] = 1
        elif s[i][j] == '#':
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1

# to up
for i in range(0, H):
    for j in range(W):
        if i == 0 and s[i][j] == '.':
            dpu[i][j] = 1
        elif s[i][j] == '#':
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 178312
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int r,b,w,g;
	cin>>r>>b>>w>>g;
	cout<<r+b+w+g<<endl;

	return 0;
}



Measured memory_bytes: 3120
w = input()
a = 0
for i in range(97, 124):
    cnt = 0
    for j in w:
        if j == chr(i):
            cnt += 1
    if cnt%2 != 0:
        print("No")
        break
    else:
        a += 1
        if a == 27:
            print("Yes")
            break

Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
vector<long long> ll_vec(int n) {
    vector<long long> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}
void PA(vector<long long> vec) {
    for (int i=0; i<vec.size()-1; i++) cout << vec.at(i) << " ";
    cout << vec.at(vec.size()-1) << endl;
    return;
}
map<long long, long long> CL(vector<long long> vec) {
    map<long long, long long> count;
    for (long long x: vec) {
        count[x] += 1;
    }
    return count;
}



int main() {
    using ll = long long;
    using vl = vector<long long>;

    ll n; cin >> n;

    ll low = 1;
    for (ll i=2; i*i<n+1; i++) {
        if (n%i == 0) {
            low = i;
        }
    }


    ll high = n/low;
    ll ans = low + high -2;

    cout << ans << endl;

}


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

int main() {
  ll w,h,x,y,c;
  double ans;
  cin >> w >> h >> x >> y;
  ans=(double)w * (double)h/2.0;
  c=(w==2*x && h==2*y);

  cout << ans << " " << c << endl; 
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    char[100] ans;
    long i;
    foreach (c; S)
    {
        if (c == 'B')
        {
            i = max(0, i - 1);
            continue;
        }
        ans[i++] = c;
    }
    writeln(ans[0 .. i]);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL f(LL M, LL N) {
    if (N == 0) return 1;
    if (N & 1) return M * f(M, N - 1) % MOD;
    LL t = f(M, N / 2) % MOD;
    return t * t % MOD;
}

void solve(int M) {
    int N;cin >> N;
    cout << f(M, N) << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3068
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] a = nextIntArray1origin(sc, N);

		sc.close();

		int k = 1;
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (a[i] != k) {
				ans++;
			} else {
				k++;
			}

		}

		if (ans == N) {
			out.println(-1);
		} else {
			out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 78420