akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int	main(void)
{
	int n, m;
	int sum = 0;
	cin >> n >> m;

	vector<int> homework_day(m);
	
    for (int i = 0; i < m; i++)
    {
      	cin >> homework_day[i];
      	sum += homework_day[i];
    }

	if ((n - sum) >= 0)
		cout << (n - sum) << endl;
	else
		cout << -1 << endl;

	return (0);
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(void){
	int X;
	cin >> X;
	int max = 0;
	if(X == 1){
		cout << "1" << endl;
		return 0;
	}
	for(int i=2; i < sqrt(X); i++){
		int tmp =i;
		while(tmp*i <= X){
			tmp *= i;
		}
		if(max < tmp){
			max = tmp;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <cmath>
int sumD(int n);
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a;
  cin>>a;
  cout<<a+pow(a,2)+pow(a,3);

}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 100009;
int n, m;
vector<int> graph[N];
int ans[N];

int main() {

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

    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queue<int> q;
    q.push(1);

    while(!q.empty()) {
        int cur = q.front(); q.pop();
        for(int child : graph[cur]) {
            if(ans[child] == 0) {
                ans[child] = cur;
                q.push(child);
            }
        }
    }

    cout << "Yes\n";
    for(int i = 2; i <= n; ++i) {
        cout << ans[i] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 10492
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,q = map(int,input().split())
U = Unionfind(n)
for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        U.union(u,v)
    else:
        print(int(U.same(u,v)))

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

#define ll long long 

int t,m,n,a[60];
ll f[60],ans;

void dfs(int x,int n,ll sum){
    if(x==n/2+1){
        if(sum==m){
            ll now=a[1]>=0?(9-a[1]):(9+a[1]);
            for(int i=2;i<x;i++)now=now*(a[i]>=0?(10-a[i]):(10+a[i]));
            ans+=n&1?now*10:now;
        }
        return;
    }
    if(sum+10ll*(f[n-x]-f[x-1])<m||sum-10ll*(f[n-x]-f[x-1])>m) return ;
    for(int i=-9;i<10;i++){
        a[x]=i;
        dfs(x+1,n,sum+1ll*a[x]*(f[n-x]-f[x-1]));
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin>>m;
	t=m;
	f[0]++;
    while(t){
    	n++;
    	t/=10;
	}
    for(int i=1;i<=18;i++) f[i]=f[i-1]*10;
    for(int i=n;i<=18;i++) dfs(1,i,0);
    cout<<ans;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int n,ans=0; cin>>n;
    rep(i,n)ans+=i+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for j in range(i+1, n):
        k = 2*j-i
        if k<n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1
print(ans)

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            Console.WriteLine(a >= 3200 ? s : "red");
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int t = 0;
for(int i = a; i<=b; ++i)
{
if( 0 == c%i)
++t;
}
printf("%d\n",t);
return 0;
}

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

const long long INF = 1LL << 60;
int MOD = 1000000007;
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; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >

int GetDigit(int num) { return log10(num) + 1; }
int gcd(int a, int b) {
	while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; }
	return a;
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int A[9];
int N;

int main() {

	rep(i, 9)cin >> A[i];
	cin >> N;
	rep(i, N) {
		int b;
		cin >> b;
		rep(i, 9) if (A[i] == b) A[i] = 0;
	}

	int judge = (A[0] + A[1] + A[2]) * (A[3] + A[4] + A[5]) *
		(A[6] + A[7] + A[8]) * (A[0] + A[3] + A[6]) * (A[1] + A[4] + A[7]) *
		(A[2] + A[5] + A[8]) * (A[0] + A[4] + A[8]) * (A[2] + A[4] + A[6]);

	if (judge == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int A, B, C, X, Y, a, b, c, d, e;
  cin >> A >> B >> C >> X >> Y;
  a = C * 2 * max(X, Y);
  b = A * X + B * Y;
  // c = max(0, X - Y) * C * 2 + max(0, Y - X) * B;
  // d = max(0, X - Y) * A + max(0, Y - X) * C * 2;
  e = min(X, Y) * C * 2 + max(0, Y - X) * B + max(0, X - Y) * A;

  cout << min(a, min(b, e)) << endl;
}


Measured memory_bytes: 3156
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>

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

int a, b;
char k[23][23];//0:?????????
int memo[23][23];

int dp(int x, int y) {
	if (x == 1 && y == 1) return 1;
	if (k[x][y]) return 0;
	if (memo[x][y] != -1) return memo[x][y];
	if (x == 1) return memo[x][y] = dp(x, y - 1);
	if (y == 1) return memo[x][y] = dp(x - 1, y);
	return memo[x][y] = dp(x, y - 1) + dp(x - 1, y);
}

int main() {
	for (;;) {
		scanf("%d %d", &a, &b);
		if (!a && !b) break;
		memset(k, 0, sizeof(k));
		memset(memo, 0xFF, sizeof(memo));
		int n;
		scanf("%d", &n);
		rep(i, n) {
			int x, y;
			scanf("%d %d", &x, &y);
			k[x][y] = 1;
		}
		printf("%d\n", dp(a, b));
	}
	return 0;
}

Measured memory_bytes: 2684
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    long N = scan.nextInt();
    long total = 0;
    
    for(int i = 0; N != i; N--){
      if(N%3 != 0&&N%5 != 0){
        total += N;
      }
    }
    System.out.print(total);
    }
  }






Measured memory_bytes: 35540
// dictionary prog
// command "insert" or "find"
#include<iostream>
#include<string>
typedef struct dictionary{
  struct dictionary *A, *C, *G, *T;
  bool a, c, g, t;
} dictionary;
void insert(void);
void find(void);
void init(dictionary*);
dictionary *Dic;
int main(){
  int n;
  std::string func, ins="insert", fin="find";
  init(Dic = new dictionary);
  std::cin >> n;
  for(int i=0; i<n; i++){
    std::cin >> func;
    if(func == ins) insert();
    else if(func == fin) find();
  }
  return 0;
}
void insert(void){
  std::string in;
  dictionary *n, *temp=Dic;
  std::cin >> in;
  for(int i=0; i<in.length() ; i++){
    switch(in[i]){
      case 'A':
      if(temp->A == NULL) init(n = new dictionary), temp->A = n;
      if(i == in.length()-1) temp->a = true;
      temp = temp->A;
      break;
      case 'C':
      if(temp->C == NULL) init(n = new dictionary), temp->C = n;
      if(i == in.length()-1) temp->c = true;
      temp = temp->C;
      break;
      case 'G':
      if(temp->G == NULL) init(n = new dictionary), temp->G = n;
      if(i == in.length()-1) temp->g = true;
      temp = temp->G;
      break;
      case 'T':
      if(temp->T == NULL) init(n = new dictionary), temp->T = n;
      if(i == in.length()-1) temp->t = true;
      temp = temp->T;
      break;
      default:
      break;
    }
  }
}
void find(void){
  std::string in;
  dictionary *temp=Dic;
  std::cin >> in;
  for(int i=0; i!=in.length() ; i++){
    switch(in[i]){
      case 'A':
      if(temp->A == NULL || (in[i+1] == '\0' && !temp->a)){
        std::cout << "no" << std::endl;
        return;
      }
      temp = temp->A;
      break;
      case 'C':
      if(temp->C == NULL || (in[i+1] == '\0' && !temp->c)){
        std::cout << "no" << std::endl;
        return;
      }
      temp = temp->C;
      break;
      case 'G':
      if(temp->G == NULL || (in[i+1] == '\0' && !temp->g)){
        std::cout << "no" << std::endl;
        return;
      }
      temp = temp->G;
      break;
      case 'T':
      if(temp->T == NULL || (in[i+1] == '\0' && !temp->t)){
        std::cout << "no" << std::endl;
        return;
      }
      temp = temp->T;
      break;
      default:
      break;
    }
  }
  std::cout << "yes" << std::endl;
}
void init(dictionary *n){
  n->A = n->C = n->G = n->T = NULL, n->a = n->c = n->g = n->t = false;
}

Measured memory_bytes: 19460
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

#define size_t int


int main(int argc, char const *argv[]) {
  int N[4];
  for (size_t i = 0; i < 4; i++) {
    scanf("%d", &N[i]);
  }
  sort(N, N + 4);
  if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int result = 0;
  for (int i = 0; i < 2; i++) {
    result += max(a, b);
    if (a > b) {
      a--;
    } else {
      b--;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
n, m, l = list(map(lambda x: int(x), input().split(" ")))
A = list()
for i in range(n):
    A.extend([list(map(lambda x: int(x), input().split(" ")))])
B = list()
for i in range(m):
    B.extend([list(map(lambda x: int(x), input().split(" ")))])
C = list([[0 for l_ in range(l)]for n_ in range(n)])
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
for a in C:
    print("%d" % a[0], end="")
    for b in a[1:]:
        print(" %d" % b, end="")
    print()

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

int main(){
	int n,field[100000];
	vector<int> kougo;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> field[i];
	int cnt = 1;
	for(int i = 0;i < n - 1;i++){
		if(field[i] == field[i + 1]){
			kougo.push_back(cnt);
			cnt = 1;
		}
		else cnt++;
		if(i == n - 2) kougo.push_back(cnt);
	}
	int ma = 0;
	if(kougo.size() <= 2){
		for(int i = 0;i < kougo.size();i++) ma += kougo[i];
	}
	else for(int i = 0;i < kougo.size() - 2;i++){
		ma = max(ma,kougo[i] + kougo[i + 1] + kougo[i + 2]);
	}
	cout << ma << endl;
	return 0;	
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(void)
{
	int n;
	int i;
	int k,p;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&k,&p);
		k=k%p;
		if(k!=0){
			printf("%d\n",k);
		}
		else {
			printf("%d\n",p);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var N, W int
	fmt.Scan(&N, &W)
	w := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&w[i], &v[i])
	}

	row := make([]int64, W+1)
	for i := 0; i < W; i++ {
		row[i] = 0
	}

	for i := 0; i < N; i++ {
		nextRow := make([]int64, W+1)
		for j := 0; j <= W; j++ {
			if j-w[i] == 0 || (j-w[i] > 0 && row[j-w[i]] > 0) {
				nextRow[j] = Max(row[j], row[j-w[i]]+int64(v[i]))
				nextRow[j] = Max(row[j], row[j-w[i]]+int64(v[i]))
			} else {
				nextRow[j] = row[j]
			}
		}
		// fmt.Printf("%v\n", nextRow)
		row = nextRow
	}

	ans := int64(0)
	for _, value := range row {
		if value > ans {
			ans = value
		}
	}

	fmt.Printf("%v\n", ans)
}

// Max returns the larger of x or y.
func Max(x, y int64) int64 {
	if x < y {
		return y
	}
	return x
}


Measured memory_bytes: 8576
a = int(input())
l = []
for i in range(a):
    dist = [int(i) for i in input().split()]
    l.append(dist)
 
start = [0,0,0]
flg = True
for i in l:
    i[0] = i[0] -start[0]
    i[1] = i[1] -start[1]
    i[2] = i[2] -start[2]
    if (i[1]+ i[2])%2 != i[0]%2:
        print('No')
        flg = False
        break
    elif i[0] < abs(i[1]) + abs(i[2]):
        print('No')
        flg = False
        break
    else:
        start = [i[0],i[1],i[2]]
if flg:
    print('Yes')  

Measured memory_bytes: 21156
n, k = gets.chomp.split(' ').map(&:to_i)
r, s, p = gets.chomp.split(' ').map(&:to_i)
t = gets.chomp.split('')

point_map = {'s' => r, 'p' => s, 'r' => p}
point = 0
seq_list = {'r' => [], 's' => [], 'p' => []}

t.each_with_index do |i, j|
  if j - k >= 0 && i == t[j - k]
    seq_list[i] << j - k
    seq_list[i] << j
  end
  point += point_map[i]
end
seq_map = {}
seq_list.each do |key, arr|
  seq_map[key] = arr.uniq.group_by {|i| i % k}
end

seq_map.each do |key, map|
  map.each do |_, arr|
    tmp = []
    idx = 0
    prev = arr[0]
    tmp[idx] = 1
    (1...arr.count).each do |i|
      current = arr[i]
      if current - prev == k
        tmp[idx] += 1
      else
        idx += 1
        tmp[idx] = 1
      end
      prev = current
    end
    tmp.each do |i|
      point -= point_map[key] * (i / 2)
    end
  end
end

puts point

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

class Program
{
	public static void Main(String[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

		var N = input[0];
		var M = input[1];

		var answer = new Dictionary<int, int>();

		for (int i = 0; i < N; i++)
		{
			// スペース区切りの整数の入力
			var inputFood = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			for (int x = 1; x <= inputFood[0]; x++)
			{
				if (answer.ContainsKey(inputFood[x]))
					answer[inputFood[x]]++;
				else
					answer.Add(inputFood[x], 1);
			}
		}

		var counter = 0;
		for (int i = 1; i <= M; i++)
		{
			if (answer.ContainsKey(i))
			{
				if (answer[i] == N)
					counter++;
			}
		}

		Console.WriteLine(counter);
	}
}



Measured memory_bytes: 13396
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

struct Hashi{
	int a,b,t;
};

vector<Hashi> hashi;
int shima[100];
int d[100];

int main() {
	int n;
	while(n=in()){
		hashi.clear();
		memset(shima,0,sizeof(shima));
		Hashi buf;
		int i,res=0;
		for(i=0;i<n-1;i++){
			cin>>buf.a>>buf.b>>buf.t;
			hashi.push_back(buf);
			shima[buf.a]++;
			shima[buf.b]++;
			res+=buf.t*2;
		}
		for(i=2;i<=n;i++){
			if(shima[i]==1){
				int j;
				for(j=0;j<n-1;j++){
					if(hashi[j].a==i)res-=2*hashi[j].t;
					if(hashi[j].b==i)res-=2*hashi[j].t;
				}
			}
		}
		for(i=1;i<=n;i++){
			d[i]=100100100;
		}
		d[1]=0;
		for(i=1;i<=n;i++){
			int j;
			for(j=0;j<n-1;j++){
				chmin(d[hashi[j].b],d[hashi[j].a]+hashi[j].t);
				chmin(d[hashi[j].a],d[hashi[j].b]+hashi[j].t);
			}
		}
		int m=0;
		for(i=1;i<=n;i++){
//cout<<i<<" "<<d[i]<<endl;
			if(shima[i]>1)chmax(m,d[i]);
		}
		res-=m;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string s,str="keyence";
int main()
{
    cin>>s;
    int flag=0;
    if(s.substr(s.length()-7)==str){
        printf("YES");
        flag=1;
    }
    if(!flag){
        if(s.substr(7)==str){
            printf("YES");
            flag=1;
        }
    }
    if(!flag){
        for(int i=1;i<=6;i++){
            string ss=s.substr(0,i)+s.substr(s.length()-7+i);
            if(ss==str){
                printf("YES");
                flag=1;
            }
            if(flag==1)
                break;
        }
    }
    if(!flag)
        printf("NO");
    return 0;
}


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

int main() {
	int K, S;
	cin >> K >> S;
	
		
	 int ans = 0;
	
		 for (int x = 0; x <= K; ++x) {
		 for (int y = 0; y <= K; ++y) {
			 int z = S - x - y;
			 if (0 <= z and z <= K) {
			 ans += 1;
				
			}
			
		}
		
	}
	
		 cout << ans << endl;
	 return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] p = new int[n];
        int min = n+1;
        int sum = 0;
        for(int i=0;i<n;i++){
            p[i] = fs.nextInt();
            if(p[i] <= min){
                sum++;
                min = p[i];
            }
        }
        System.out.println(sum);
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 35588
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <algorithm>
#include <climits>
#include <string>
#include <cstdlib>
#include <sstream>
#include <cmath>
#include <cassert>
#include <iomanip> // cout << setprecision(9) << fixed;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int j = 0; j < N; j++) {
        cin >> a[j];
    }

    // int c = 1;
    ll count = 0;
    bool cont = true;
    ll c = 1;
    bool inc_c;
    int ii = 0;
    while (cont) {
        cont = false;
        inc_c = true;
        while (inc_c) {
            inc_c = false;
            for (int i = ii; i < N; i++) {
                if (a[i] == c) {
                    inc_c = true;
                    c++;
                    ii = i;
                    break;
                } else if (a[i] > c) {
                    count += ((a[i] - 1) / c);
                    a[i] = 1;
                    cont = true;
                    ii = i;
                    break;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;

    ll pre_max = 0;
    for(int i = 0; i < N;i++){
        if(A[i] < pre_max){
            res += pre_max - A[i];
        }
        pre_max = max(pre_max,A[i]);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    vl x, y;
    NREP() {
        ll t;
        cin >> t;
        x.push_back(t);
        cin >> t;
        y.push_back(t);
    }

    vl model;
    NREP() {
        model.push_back(i + 1);
    }

    double sum = 0;
    ll cnt = 0;
    do {
        double dist = 0;
        REP(i, n) {
            REP(j, n) {
                if (model[i] + 1 == model[j]) {
                    dist += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
                }
            }
        }
        sum += dist;
        cnt++;
    } while (next_permutation(ALL(model)));

    MSG(fixed << setprecision(15) << sum / (double) cnt)
}


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

int main()
{
  string S;
  cin >> S;
  if (S.substr(5,2)=="04" || S.substr(5,2)=="03" || S.substr(5,2)=="02" || S.substr(5,2)=="01") cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                            }
        int b = 0;		
        for(int i=0;i<a-1;i++){for(int j=i+1;j<a;j++){b+=in[i]*in[j];                             
                                                     }
                              }      
		System.out.println(b);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

using ll = long long;
struct Line { ll a, b; ll get(ll x) { return a * x + b; } };

static const int MAX = 2e5 + 9;
const ll INFL = 1e17;

struct LiChaoTree
{
	int N;
    Line a[MAX << 2];
    ll h[MAX];

    void init (ll _h[MAX], int _N)
    {
    	N = _N;
    	copy (_h, _h + N, h);
    	for (int i = 0; i < (N << 2); ++i) a[i] = {0, INFL};
    }

    void upd (Line ln)
    {
        int root = 1, lo = 0, hi = N;
        while (true) {
			int mid = (lo + hi) >> 1;
            if (ln.get(h[mid]) < a[root].get(h[mid])) swap (ln, a[root]);
//            cerr << '[' << h[lo] << ", " << h[hi-1] << "]: " << a[root].a << ' ' << a[root].b << endl;
            if (lo + 1 >= hi) return;
            if (ln.get(h[lo]) < a[root].get(h[lo])) root = root << 1, hi = mid;
            else root = root << 1 | 1, lo = mid;
        }
    }

    ll get (int x)
    {
        int root = 1, lo = 0, hi = N; ll ans = INFL;
        while (true) {
        	int mid = (lo + hi) >> 1;
            ans = min(ans, a[root].get(h[x]));
            if (lo + 1 >= hi) return ans;
            if (x < mid) root = root << 1, hi = mid;
            else root = root << 1 | 1, lo = mid;
        }
    }

} tree;

int N;
ll C, h[MAX], f;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> C;
    for (int i = 0; i < N; ++i) cin >> h[i];
    tree.init(h, N);

    for (int i = 0; i < N; ++i) {
        f = (i == 0) ? 0ll : (tree.get(i) + h[i] * h[i] + C);
        if (i == N-1) return cout << f << endl, 0;
//        cout << f << ' ';
        tree.upd({-2 * h[i], f + h[i] * h[i]});
    }
}


Measured memory_bytes: 15872
/*
2020-05-05
atcoder ABC
*/

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    int matched_cnt = 0;
    int p_rank;
    int q_rank;
    int cnt = 0;
    vector<int> p_array(N);
    vector<int> q_array(N);
    rep(i, N){
        cin >> p_array[i];
    }
    rep(i, N){
        cin >> q_array[i];
    }
    vector<int> numbers(N);
    rep(i, N){
        numbers[i] = i + 1;
    }
    do{
        if(numbers == p_array){
            p_rank = cnt;
            matched_cnt++;
        }
        if(numbers == q_array){
            q_rank = cnt;
            matched_cnt++;
        }
        if(matched_cnt == 2) break;
        cnt++;
    }while(next_permutation(numbers.begin(), numbers.end()));

    cout << abs(p_rank - q_rank) << endl;
    
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define trav(it, a) for(auto& it : a)
#define allin(it, a) for(auto it : a)
#define read(v, a, b) for(int i=(a); i<(b); i++) scanf("%d", &v[i]);
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl

const int maxn = 3e3 + 100;

char s[maxn], t[maxn];
int S = 0, T = 0;

int dp[maxn][maxn];

int solve(int a=0, int b=0){
	if(a >= S || b >= T) return dp[a][b] = 0;
	
	if(dp[a][b] != -1) return dp[a][b];
	
	if(s[a] == t[b])		
		return dp[a][b] = 1 + solve(a+1, b+1);
	
	if(solve(a+1, b) > solve(a, b+1))
		return dp[a][b] = solve(a+1,b);
	
	else
		return dp[a][b] = solve(a, b+1);
}

string find(int a=0, int b=0){
	if(a >= S || b >= T) return "";
	
	//if(dp[a+1][b+1] +1 >= dp[a+1][b] && dp[a+1][b+1] + 1 >= dp[a][b+1] && s[a] == t[b]){
		//return s[a] + find(a+1, b+1);
	//}
	
	if(s[a] == t[b]){
		return s[a] + find(a+1, b+1);
	}
	
	if(dp[a+1][b] > dp[a][b+1])
		return find(a+1, b);
	else
		return find(a, b+1);
}

int main(){
	FAST;
	cin >> s >> t;
	trav(it, s){
		if(it - 'a' < 0 || it - 'z' > 0) break;
		S++;
	}
	
	trav(it, t){
		if(it - 'a' < 0 || it - 'z' > 0) break;
		T++;
	}
	
	clr(dp, -1);
	solve();
	
	if(dp[0][0] == 0) puts("");
	else cout << find() << '\n';
	//cout << find() << '\n';
}


Measured memory_bytes: 38144
N = int(input())
A = list(map(int, input().split()))


if N % 2 == 0:
  latter = A[0:N:2]
  former = A[1:N:2][::-1]
  print(*(former + latter))
else:
  former = A[0:N:2][::-1]
  latter = A[1:N:2]
  print(*(former + latter))

Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
vector<int> to[N];
int a[N];
void dfs(int no,int p){
	for(auto s:to[no]){
		if(s==p)continue;
		a[s]+=a[no];
		dfs(s,no);
	}
}
int main(){
	int n,q;
    cin>>n>>q;
    REP(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    REP(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        a[p]+=x;
    }
    dfs(0,-1);
    REP(i,n){
        OUT(a[i]);
    }
	return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i)   for(int i##_to_ = (t), i = (f); i <  i##_to_; i++)
#define downto(f, t, i)  for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i >  i##_to_; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

//constexpr long MOD = 1000000007;

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    string s; cin >> s;
    int a = 0, b = 0, c = 0;
    for(char ch : s) {
        if(ch == 'a') ++a;
        if(ch == 'b') ++b;
        if(ch == 'c') ++c;
    }
    if(debug) cout << a sp << b sp << c ln;

    cout << (max({a, b, c}) - min({a, b, c}) <= 1 ? "YES" : "NO") ln;

    return 0;
}


Measured memory_bytes: 512
def minValue(a,b):
    return b if a > b else a

def getSum(arr):
    return sum(list(arr))

def calculate(arr,n):

    ret = []

    for i in range(n):
        if i == 0:
            ret.append(arr[0])
        elif i == len(arr):
            ret.append(arr[i-1])
        else:
            ret.append(minValue(arr[i],arr[i-1]))

    return ret


N = int(input())
S = input().split()

arr = list(map(int, list(S)))
result = calculate(arr,N)
ret = getSum(list(result))
print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int INF = 1e9+10;
int main()
{
    ll n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    reverse(a.begin(), a.end());
    vector<vector<int>> d(n, vector<int>(n, 0));
    for(int i = 0; i < n; i++)
    {
        int v = INF;
        for(int j = 0; j < n; j++)
        {
            v = min(v, a[(i+j) % n]);
            d[i][j] = v;
        }
    }
    ll ans = 1e15;
    for(int cnt = 0; cnt < n; cnt++)
    {
        ll tmp = x * cnt;
        for(int i = 0; i < n; i++)
        {
            tmp += d[i][cnt];
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 19092
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  cin >> A >> B;
  if(B >= A){
    cout << A << endl;
  }
  else{
    cout << A - 1 << endl;
  }
}

Measured memory_bytes: 764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATwoAbbreviations solver = new ATwoAbbreviations();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATwoAbbreviations {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            long n = in.longs(), m = in.longs();
            String s = in.string(), t = in.string();
            long lcm = IntMath.lcm(n, m);
            long gcd = n * m / lcm;
            int x = 0, y = 0;
            for (int i = 0; i < gcd; i++) {
                if (s.charAt(x) != t.charAt(y)) {
                    out.println(-1);
                    return;
                }
                x += n / gcd;
                y += m / gcd;
            }
            out.println(lcm);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public long longs() {
            return Long.parseLong(string());
        }

    }

    static final class IntMath {
        private IntMath() {
        }

        public static long lcm(long a, long b) {
            long ans = a * b;
            ans /= gcd(a, b);
            return ans;
        }

        public static long gcd(long a, long b) {
            long t;
            while (a % b > 0) {
                t = b;
                b = a % b;
                a = t;
            }
            return b;
        }

    }
}



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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);
constexpr long double eps = 1e-9;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    cout << a*b<< endl;
    return 0;
}


Measured memory_bytes: 3636
N=int(input())
dic={}
for _ in range(N):
  S=input()
  if S in dic:
    dic[S]+=1
  else:
    dic[S]=1
ls=list(dic.items())
ls.sort()
ls=sorted(ls, key=lambda x:-x[1])
a=ls[0][1]
for i in range(len(ls)):
  if ls[i][1]==a:
    print(ls[i][0])

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

using namespace std;

int main() {
	while (1) {
		double edges[3];
		cin >> edges[0] >> edges[1] >> edges[2];

		if (edges[0] == 0 && edges[1] == 0 && edges[2] == 0){ 
      break;
    }

    double p_c1 = pow(edges[1],2.0);
    double p_c2 = pow(edges[2],2.0);
    double cheese = p_c1 + p_c2;
    double c_cheese = sqrt(cheese);

		int n;
		cin >> n;
		
		for (int i = 0; i < n; i++) {
			double r;
			cin >> r;
      double s = r * 2.0;
		
      if(c_cheese < s){
			  cout<<"OK"<<endl;
      }
      else{
        cout<<"NA"<<endl;
      }
		}
	}
	return 0;
}


Measured memory_bytes: 3208
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll inf = 1000000001;

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

    int n; cin>>n;
    vector<double>d;
    rep(i,n){
        double a; cin>>a;
        d.push_back(a);
    }
    sort(all(d));
    
    int center = d[n/2] - d[n/2-1];
    int ans = 0;
    if(center!=0) ans = center;
    
    cout << ans << ln;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int,int> > c(N);
    for(int i=0;i<N;i++){
        int a,b; cin >> a >> b;
        c[i]=make_pair(a,b);
    }
    sort(c.begin(),c.end());
    int cnt=0;
    long long ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<c[i].second;j++){
            ans+=c[i].first;
            cnt++;
            if(cnt==M) break;
        }
        if(cnt==M) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
  int a,b;
  cin>>a>>b;
  vector<int>v1(a);
  vector<int>v2(a);
  for(int i=0;i<a;i++){
    cin>>v1.at(i);
  }
  v2=v1;
  for(int j=0;j<b;j++){
    int c,d,e,f;
    cin>>c>>d;
   e=v1.at(c-1);
    f=v1.at(d-1);
    if(e>f){
      if(v2.at(d-1)>0){
      v2.at(d-1)*=(-1);
      }
    }
    else if(f>e){
      if(v2.at(c-1)>0){
      v2.at(c-1)*=(-1);
      }
    }
    else if(f==e){
      if(v2.at(d-1)>0){
      v2.at(d-1)*=(-1);
      }
       if(v2.at(c-1)>0){
      v2.at(c-1)*=(-1);
      }
    }
  }
  int count=0;
  for(int k=0;k<a;k++){
    if(v2.at(k)<0){
      count++;
    }
  }
  cout<<a-count<<endl;
}

Measured memory_bytes: 4052
#include <stdio.h>
#include <stdlib.h>

int
comp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}

int
main()
{
	int data[10];
	int i,j;
	int max;
	for(i=0; i<10; i++){
		scanf("%d", &data[i]);
	}

	qsort(data, 10, sizeof(int), comp);

	for(i=0; i<3; i++){
		printf("%d\n", data[i]);
	}
	return(0);
}

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

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll x,y;
  cin >> x >> y;
  if(y==x)
  {
    cout << 0 << endl;
  }
  else if(y==-x)
  {
    cout << 1 << endl;
  }
  else if(y==0&&x<0)
  {
    cout << y - x << endl;
  }
  else if(y==0&&x>0)
  {
    cout << x + 1 << endl;
  }
  else if(x==0&&y>0)
  {
    cout << y << endl;
  }
  else if(x==0&&y<0)
  {
    cout << 1 - y << endl;
  }
  else if(y>=0&&x<=0)
  {
    cout << abs(abs(x)-abs(y)) + 1 << endl;
  }
  else if(y<=0&&x>=0)
  {
    cout << abs(abs(x)-abs(y)) + 1 << endl;
  }
  else if(y>x&&x>0)
  {
    cout << y - x << endl;
  }
  else if(y>x&&y<0)
  {
    cout << y - x << endl;
  }
  else if(y<x&&y>0)
  {
    cout << x - y + 2 << endl;
  }
  else if(y<x&&x<0)
  {
    cout << x - y + 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
x, n = map(int, input().split())
flag = False
if n is not 0:
    A = list(map(int, input().split()))
    flag = True
if flag and (x not in A):
    print(x)
elif flag:
    i=1
    while(True):
        if x-i not in A:
            print(x-i)
            break
        if x+i not in A:
            print(x+i)
            break
        i += 1
else:
    print(x)


Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

// ユークリッドの互除法でGCD(A1 ... ANを求めれば良い)
ll GCD(ll a, ll b) {
    return b ? GCD(b, a%b) : a ;
}

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

    ll res = GCD(A[0], A[1]);
    for(ll i=2; i<N; ++i) {
        res = GCD(res, A[i]);
    }
    cout << res << endl;

}


Measured memory_bytes: 1024
N, M = map(int, input().split())
L = 1
R = N

for i in range(M):
    l, r = map(int, input().split())
    
    if l > L:
        L = l
#        print('L ' + str(L))
    if r < R:
        R = r
#        print('R ' + str(R))
        
if L > R:
    print(0)
else:
    print(R - L + 1)
    

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	map<int,int> mp1;
	map<int,int> mp2;
	for(int i = 0;i < n;i++){
		int v;
		cin >> v;
		if(i % 2 == 0)mp1[v]++;
		else mp2[v]++;
	}

	int mx11 = 0,mx11_value = 0;
	for(auto p:mp1){
		if(p.second > mx11){
			mx11 = p.second;
			mx11_value = p.first;
		}
	}

	int mx12 = 0,mx12_value = 0;
	for(auto p:mp1){
		if(p.second > mx12 && p.first != mx11_value){
			mx12 = p.second;
			mx12_value = p.first;
		}
	}

	int mx21 = 0,mx21_value = 0;
	for(auto p:mp2){
		if(p.second > mx21){
			mx21 = p.second;
			mx21_value = p.first;
		}
	}

	int mx22 = 0,mx22_value = 0;
	for(auto p:mp2){
		if(p.second > mx22 && p.first != mx21_value){
			mx22 = p.second;
			mx22_value = p.first;
		}
	}

	/*
	printf("%d:%d\n",mx11,mx11_value);
	printf("%d:%d\n",mx12,mx12_value);
	printf("%d:%d\n",mx21,mx21_value);
	printf("%d:%d\n",mx22,mx22_value);
	*/

	int ans = n;
	if(mx11_value != mx21_value){
		ans = min(ans,n-mx11-mx21);
	}
	if(mx11_value != mx22_value){
		ans = min(ans,n-mx11-mx22);
	}
	if(mx12_value != mx21_value){
		ans = min(ans,n-mx12-mx21);
	}
	if(mx12_value != mx22_value){
		ans = min(ans,n-mx12-mx22);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys

A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
def solve(K: int):
    print(A[K-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int max(int a,int b)
{
	if(a>b)return a;
	return b;
}
int main(){
 	int n,mx=0,s=0;
 	cin>>n;
 	int m;
 	cin>>m;
	 for(int i=2;i<=n;++i)
	 {
	 	int d;
	 	cin>>d;
	 	if(m>=d){s++;m=d;}
	 	else {s=0;m=d;}
		mx=max(mx,s);
	 }
	 cout<<mx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint a[201];
int main(){
    int n;
    int ni,di;
    while(cin>>n,n){
        int mnx=0,mny=0,mxx=0,mxy=0;
        FOR(i,1,n){
            cin>>ni>>di;
            int x=a[ni].first,y=a[ni].second;
            if(di==0) --x;
            else if(di==1) --y;
            else if(di==2) ++x;
            else if(di==3) ++y;
            mnx=min(mnx,x);
            mny=min(mny,y);
            mxx=max(mxx,x);
            mxy=max(mxy,y);
            a[i]={x,y};
        }
        cout<<mxx-mnx+1<<" "<<mxy-mny+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define IOS; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define MX 100001
    #define line cout << endl
    int main()
    {
        IOS;
        int n;
        cin>>n;
        string a;
        cin>>a;
        int cnt=0;
        for(int i=0;i<n-2;i++)
        {
            if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
                cnt++;
        }
        cout<<cnt;
    }



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


Measured memory_bytes: 256