akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long

void solve() {
	int n;
	cin >> n;
	if (n % 2 == 0 || n % 5 == 0) {
		cout << "-1\n";
		return;
	}
	int count = 7 % n;
	int ans = -1;
	for (int i = 1; i < 1e6 + 1; i++) {
		if (count == 0) {
			ans = i;
			break;
		}
		else {
			count *= 10;
			count += 7;
			count %= n;
		}
	}
	cout << ans << "\n";
}

int32_t main() {
	_ __
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}
int main() {
    int n,x;
    cin >> n >> x;
    vector<int>dist(n+1);
    for(int i=0;i<n;i++){
        cin >> dist[i];
    }
    dist[n]=x;
    sort(dist.begin(),dist.end());
    int ans=dist[1]-dist[0];
    for(int i=0;i<n;i++){
        ans = gcd(ans,dist[i+1]-dist[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3768
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			String word = sc.next(); // 全て小文字へ
			int count = 0;
			for(String line = sc.next(); !line.equals("END_OF_TEXT"); line = sc.next()) {
				String[] tokens = line.split(" ");
				for(String t: tokens) {
					if(t.equalsIgnoreCase(word)) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}



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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(a: int, b: int, c: int):
    k = int(c - a - b)
    if k <= 0:
        print(NO)
    elif 4 * (a * b) < k*k:
        print(YES)
    else:
        print(NO)
    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()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP1(i,n) for(ll i=1;i<=(ll)(n);i++)

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

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

ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}

int main() {
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);

    ll n,m;
    cin >> n >> m;
    ll a, sum;
    sum = 0;
    REP(i,m){
        cin >> a;
        sum += a;
    }

    if( sum > n){
        cout << -1 << endl;
    } else {
        cout << n-sum << endl;
    }
   
}


Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for(int i = 0 ; i < n ; i++) {
			int a = sc.nextInt();
			if(!map.containsKey(-a)) map.put(-a, 1);
			else map.put(-a, map.get(-a) + 1);
		}
		int x = -1;
		for(int key : map.keySet()) {
			if(x == -1 && map.get(key) >= 4) {
				System.out.println(1L * key * key);
				return;
			} else if(x != -1 && map.get(key) >= 2) {
				System.out.println(1L * x * key);
				return;
			} else if(map.get(key) >= 2) {
				x = key;
			}
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 63616
#include <stdio.h>
int main(){
   
    int n, A[100], i;
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++){
        scanf("%d", &A[i]);
    }
    
    for(i=n-1; i>0; i--){
        printf("%d ", A[i]);
    }
    
    printf("%d\n", A[0]);
return 0;
}

Measured memory_bytes: 596
s = gets.chomp
# num = ('a'..'z').to_a.map{|a| [a,0]}.to_h
# s.chars.each_with_index do |b,i|
#   num[b] = i 
# end
s = s.chars
s.each_with_index do |b,i|
  if b == s[i + 1]
    puts i+1,i+2
    exit 
  elsif b == s[i + 2]
    puts i+1,i+3
    exit
  end 
end
puts "-1 -1"


Measured memory_bytes: 6908
from bisect import *
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = a[-1]/2
b = bisect_left(a,ans)
if abs(ans-a[b]) < abs(ans-a[b-1]):
  print(a[-1],a[b])
else:
  print(a[-1],a[b-1])

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    int n;
    cin >> n;
    n  = n%10;
    if (n == 3) cout << "bon" << endl;
    else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
	ans = 1
elif N == 1 and M >= 2:
	ans = M - 2
elif N >= 2 and M == 1:
	ans = N - 2
else:
	ans = (N - 2) * (M - 2)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<map>

using namespace std;

int main(){
	unsigned long long ans = 1;
	int n,k;

	cin >> n >> k;
	
	for(int i = 0; i < n;i++){
		if(i == 0)ans *= k;
		else ans *= k-1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

Int calc(vector<Int>& a, Int b, Int N) {
	Int sum = 0;
	for (Int i = 0; i < N; i++) {
		sum += abs(a[i] - b);
	}
	return sum;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> Man(N);

	Int temp = 0;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		Man[i] = temp - (i + 1);
	}

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

	Int ans = 0;
		ans = calc(Man, Man[N / 2], N);
		cout << ans << endl;
		return 0;

}

Measured memory_bytes: 1792
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,ans=0;
  std::cin>>n;

  bool flag=false;

  std::vector<ll> a(n);
  rep(i,0,n){
    std::cin>>a[i];
    if(a[i]>=n)flag=true;
  }

  while(flag){
    ll temp=0;
    rep(i,0,n)temp+=a[i]/n;
    rep(i,0,n){
      ll now=a[i];
      a[i]-=(now/n)*n;
      a[i]+=(temp-(now/n));
    }

    ans+=temp;

    flag=false;
    rep(i,0,n)if(a[i]>=n)flag=true;
  }

  std::cout<<ans;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int ac, char **av) {
  char buf[256];
  int n, i;
  unsigned long m;
  while(fgets(buf, 256, stdin) != NULL) {
    m = 100000L;
    sscanf(buf, "%d", &n);
    for(i = 0; i < n; i++) {
      m *= 1.05;
      m = ((m + 999)/1000) * 1000;
    }
    printf("%ld\n", m);
  }
  return 0;
}

Measured memory_bytes: 600
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    mi = 0
    ans = 0
    for a in A:
        if a <= mi+1:
            mi = max(mi, a)
            continue
        ans += (a-1)//(mi+1)
        mi = max(mi, 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50008
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;

int main() {
	
		int a, b, k; cin >> a >> b >> k;
		for (int i = a; i <= b; i++) {
			if (i<a + k || i>b - k) cout << i << endl;
		}
		int o;
		cin >> o;
	return 0;
}

Measured memory_bytes: 256
import unittest


def is_ある時刻での判定(t, d):
    # 時刻t >= d でないと実現不可能
    if t < d:
        return True

    # 偶奇が一致しないと実現不可能
    if not (t % 2 == d % 2):
        return True

    return False


def can_not_realize(N, t_list, x_list, y_list) -> bool:
    # 各時刻ごとの判定
    for t, x, y in zip(t_list, x_list, y_list):
        d = x + y

        if is_ある時刻での判定(t, d):
            return True

    # t_n と t_n+1 間 での移動判定
    for i in range(N):
        if i + 1 >= N:
            break

        t = t_list[i + 1] - t_list[i]
        diff_x = abs(x_list[i + 1] - x_list[i])
        diff_y = abs(y_list[i + 1] - y_list[i])

        d = diff_x + diff_y

        if is_ある時刻での判定(t, d):
            return True

    return False


def actual(N, t_list, x_list, y_list):
    if can_not_realize(N, t_list, x_list, y_list):
        return 'No'

    return 'Yes'

N = int(input())

t_list, x_list, y_list = [], [], []
for _ in range(N):
  t, x, y = list(map(int, input().split()))
  t_list.append(t)
  x_list.append(x)
  y_list.append(y)
  
print(actual(N, t_list, x_list, y_list))
  

Measured memory_bytes: 14388
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
    mut    a:[i64;n],
    }
    a.sort();
    let mut sum = a[n - 1] - a[0];
    for i in 1..n / 2 {
        sum += a[n - i - 1] - a[i - 1] + a[n - i] - a[i];
    }
    if n % 2 == 1 {
        sum += max(a[n / 2 + 1] - a[n / 2], a[n / 2] - a[n / 2 - 1]);
    }
    println!("{}", sum);
}


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

pre_t=0
pre_x=0
pre_y=0
for i in range(n):
    t, x, y=map(int, input().split())
    delta_t=t-pre_t
    delta_x=abs(x-pre_x)
    delta_y=abs(y-pre_y)
    if delta_t<delta_x+delta_y:
        print("No")
        exit()
    elif (delta_x+delta_y+delta_t)%2==1:
        print("No")
        exit()
    pre_t=t
    pre_x=x
    pre_y=y
print("Yes")


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

int main() {
  int N,sum=0;
  cin >> N;
  int a=N;
  while (a>0) {
    sum+=a%10;
    a/=10;
  }
  if (N%sum==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1000001;
struct node{
    int v,nxt,cost;
}edge[N];
int head[N],k,tot;
int q[N],l,r,u,v;
int dist[N];
void addEdge(int u,int v,int val) {
    edge[++tot].v=v;
    edge[tot].cost=val;
    edge[tot].nxt=head[u];
    head[u]=tot;
}
int main() {
    //freopen("out.txt","w",stdout);
    scanf("%d",&k);
    for (int i=0;i<k;++i) {
        addEdge(i,i+1==k?0:i+1,1);
        addEdge(i,i*10%k,0);
        dist[i]=N;
    }
    dist[1]=0;
    l=-1;
    r=0;
    q[0]=1;
    while (l<r) {
        u = q[++l];
        for (int i=head[u];i;i=edge[i].nxt) {
            v=edge[i].v;
            if (dist[u]+edge[i].cost<dist[v]) {
                dist[v]=dist[u]+edge[i].cost;
                q[++r]=v;
            }
        }
    }
    printf("%d\n",dist[0]+1);
    return 0;
}


Measured memory_bytes: 12928
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int cnt[26], n;
const ll p = 1e9 + 7;
char s[maxn];
template <class T> void read (T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  read(n), scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    cnt[s[i] - 'a']++;
  }
  ll ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = ans * (cnt[i] + 1) % p;
  }
  printf("%lld\n", (ans - 1 + p) % p);
  return 0;
}

Measured memory_bytes: 384
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  map<string, int> M;
  loop(i,0,n) {
    string s; cin >> s;
    M[s]++;
  }
  cout << "AC x " << M["AC"] << endl;
  cout << "WA x " << M["WA"] << endl;
  cout << "TLE x " << M["TLE"] << endl;
  cout << "RE x " << M["RE"] << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
int n, c = 1;
cin >> n;
for (int i = 0; i <= n/7; ++i) {
        if ((n - 7*i) % 4 == 0) {
                c = 0;
                cout << "Yes" << endl;
                break;
        }   
}
if (c) cout << "No" << endl;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

int main(){
  int i,j,cnt=0;
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  if(a1+a2+a3>=22)cout<<"bust";
  else cout<<"win";
}

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

int main(){
	string s;
	long long int K,L;
	cin >> s;
	cin >> K;
	L = s.length();
	for(int i=0;i<L;i++){
		if(s[i]=='a'&&i!=L-1) continue;
		if(i!=L-1){
			if(K-(26-(s[i]-'a'))>=0){
				K-=(26-(s[i]-'a'));
				s[i]='a';
			}
		}else{
			if((s[i]-'a')+K>=26){
				K=((s[i]-'a')+K)%26;
				s[i]='a'+K;
			}else{
				s[i]=s[i]+K;
			}
		}
		//cout << s << " K= "<< K<< endl;
	}
	cout << s << endl;
return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int check(vector<vector<int>> &E,int from){
	vector<int> V;
	for(int i=0;i<E[from].size();i++){
		V.push_back(check(E,E[from][i])+1);
	}
	
	sort(V.begin(),V.end());
	int now = 0;
	
	for(int i=0;i<V.size();i++){
		now++;
		if(V[i]>now)now=V[i];
	}
	
	return now;
	
	
}
int main(){
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int k;
		cin>>k;
		k--;
		E[k].push_back(i+1);
	}
	
	cout<<check(E,0)<<endl;
	
		
	
	return 0;
}


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

Measured memory_bytes: 596
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,a[N],v[N];
int main() {
  scanf("%d",&n);int x=0,st=0;
  for(int i=1;i<=n;i++)scanf("%d",a+i),v[a[i]]++,x=__gcd(x,a[i]);
  for(int i=2;i<=1000000;i++){
    int y=0;
    for(int j=i;j<=1000000;j+=i){
      y+=v[j];
    }
    if(y>=2){
      st=1;
      break;
    }
  }
  if(!st)cout<<"pairwise coprime\n";
  else if(st && x==1)cout<<"setwise coprime\n";
  else cout<<"not coprime\n";
  return 0;
}


Measured memory_bytes: 11468
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 1000000
#define NIL -1

class Node{
	public:
	int location;
	int p,l,r;
	Node(){}
};

class Point{
	public:
	int id,x,y;
	Point(){}
	Point(int id,int x,int y): id(id),x(x),y(y){}
	bool operator < (const Point &p)const{
		return id <p.id;
	}
	void print(){
		printf("%d\n",id);
	}
};

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessx(const Point &p1,const Point &p2){ return p1.x<p2.x; }
bool lessy(const Point &p1,const Point &p2){ return p1.y<p2.y; }

int makeDTree(int l,int r,int depth){
	if(l>=r)	return NIL;
	int mid=(l+r)/2;
	int t=np++;
	if(depth%2==0)	sort(P+l,P+r,lessx);
	else 			sort(P+l,P+r,lessy);
	T[t].location=mid;
	T[t].l=makeDTree(l,mid,depth+1);
	T[t].r=makeDTree(mid+1,r,depth+1);
	return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
	int x=P[T[v].location].x;
	int y=P[T[v].location].y;
	if(sx<=x&&x<=tx&&sy<=y&&y<=ty)	ans.push_back(P[T[v].location]);
	if(depth%2==0){
		if(T[v].l!=NIL){
			if(sx<=x)	find(T[v].l,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[v].r!=NIL){
			if(x<=tx)	find(T[v].r,sx,tx,sy,ty,depth+1,ans);
		}
	}
	else{
		if(T[v].l!=NIL){
			if(sy<=y)	find(T[v].l,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[v].r!=NIL){
			if(y<=ty)	find(T[v].r,sx,tx,sy,ty,depth+1,ans);
		}
	}
}

int main(){
	int x,y;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d %d",&x,&y);
		P[i]=Point(i,x,y);
		T[i].l=T[i].r=T[i].p=NIL;
	}
	np=0;
	int root=makeDTree(0,N,0);
	int q;	scanf("%d",&q);
	int sx,sy,tx,ty;
	vector<Point> ans;
	for(int i=0;i<q;i++){
		scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		ans.clear();
		find(root,sx,tx,sy,ty,0,ans);
		sort(ans.begin(),ans.end());
		for(int j=0;j<(int)ans.size();j++){
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}

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

int task_C (unsigned int len_sequence, unsigned int val_sequence[])
{
	// variables for this function
	register unsigned int maxval_1st;
	register unsigned int maxval_2nd;
	register unsigned int maxval_answer;

	// support variables for this function
	register size_t itr;

	// STEP.01
	// initialize the variables to store the maximum values of given sequence
	maxval_1st = 0U;
	maxval_2nd = 0U;

	// STEP.02
	// search the maximum values of given sequence
	for (itr = 0; itr < len_sequence; itr++)
	{
		if (maxval_1st < val_sequence[itr])
		{ 
			maxval_2nd = maxval_1st;
			maxval_1st = val_sequence[itr];
		}
		else if (maxval_2nd < val_sequence[itr])
		{
			maxval_2nd = val_sequence[itr];
		}
		else
		{
			continue;
		}
	}

	// STEP.03
	// output the answer of this task
	for (itr = 0; itr < len_sequence; itr++)
	{
		if ( val_sequence[itr] != maxval_1st ) { maxval_answer = maxval_1st; }
		else                                   { maxval_answer = maxval_2nd; }
		
		printf("%d\n", maxval_answer);
	}

	// STEP.END
	return EXIT_SUCCESS;
}

#define len_sequence_max 200000U

int main (void)
{
	// variables for main process
	unsigned int N;
	unsigned int A[len_sequence_max];

	// support variables for main process
	int rtvl;

	// STEP.01
	// read out the given data
	// (the length of the given sequence)
	rtvl = scanf("%d", &N);

	// STEP.02
	// read out the given data
	// (the values of the given sequence)
	for (register size_t itr = 0; itr < N; itr++) { rtvl = scanf("%d", &A[itr]); }

	// STEP.03
	// calculate & output the answer of the task
	rtvl = task_C(N, A);

	// STEP.END
	return EXIT_SUCCESS;
}

Measured memory_bytes: 2304
N = int(input())
A = []
B = []
s = 0
for x in range(N):
    a, b = input().split()
    a = int(a)
    b = int(b)
    A.append(a)
    B.append(b)
for i in range(N):
    if A[i] == B[i]:
        s = s+1
    else:
        if s >= 3:
            s = s + 0
        else:
            s = 0
if s >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int DP(int n,int t,vector<int>a,vector<int>b){
    int x=0;
    vector<vector<int>>dp(n+1,vector<int>(t,-1000000000));
    //i番目まで見てj分かけたときの美味しさの最大値
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<t;j++){
            //食べる
            if(j+a[i]<t)dp[i+1][j+a[i]]=max(dp[i][j]+b[i],dp[i+1][j+a[i]]);
            //食べない
            dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
            x=max(dp[i+1][j],x);
        }
    }
    return x;
}
int main(){
    int n,t;
    cin>>n>>t;
    int a[n],b[n];
    vector<pair<int,int>>p1(n);
    vector<pair<int,int>>p2(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        p1[i]={a[i],b[i]};
        p2[i]={b[i],a[i]};
    }
    sort(p1.begin(),p1.end());
    sort(p2.begin(),p2.end());
    vector<int>a1(n-1);
    vector<int>b1(n-1);//最も時間かかるものを除いた
    vector<int>a2(n-1);
    vector<int>b2(n-1);//最も美味しいものを除いた
    vector<int>a3(n-1);
    vector<int>b3(n-1);//2番目に時間かかるものを除いた
    vector<int>a4(n-1);
    vector<int>b4(n-1);//2番目に美味しいものを除いた
    for(int i=0;i<n-2;i++){
        a1[i]=p1[i].first;
        b1[i]=p1[i].second;
        a2[i]=p2[i].second;
        b2[i]=p2[i].first;
        a3[i]=p1[i].first;
        b3[i]=p1[i].second;
        a4[i]=p2[i].second;
        b4[i]=p2[i].first;
    }
    a1[n-2]=p1[n-2].first;
    b1[n-2]=p1[n-2].second;
    a2[n-2]=p2[n-2].second;
    b2[n-2]=p2[n-2].first;
    a3[n-2]=p1[n-1].first;
    b3[n-2]=p1[n-1].second;
    a4[n-2]=p2[n-1].second;
    b4[n-2]=p2[n-1].first;
    cout<<max({DP(n-1,t,a1,b1)+p1[n-1].second,DP(n-1,t,a2,b2)+p2[n-1].first
              ,DP(n-1,t,a3,b3)+p1[n-2].second,DP(n-1,t,a4,b4)+p2[n-2].first})<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    cout<<std::setprecision(10);
    ios::sync_with_stdio(false);
    ll n,ans=0;
    cin>>n;
    Vec p(n);
    Vec ind(n);
    rep(i,n){
        int tmp;
        cin>>tmp;
        tmp--;
        p[i]=tmp;
        ind[tmp]=i;
    }
    multiset<int> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(n);
    st.insert(n);
    per(i,n-1){
        int id = ind[i];
        st.insert(id);
        Vi l(2,-1);
        Vi r(2,n);
        auto it = st.find(id);
        --it;
        l[0]=*it;
        --it;
        l[1]=*it;
        it = st.find(id);
        it++;
        r[0] = *it;
        it++;
        r[1] = *it;
        int l1 = id-l[0];
        int r1 = r[0]-id;
        int l2 = l[0]-l[1];
        int r2 = r[1]-r[0];
        ans += (i+1) * (l1*r2 + l2*r1);
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 6528
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$a = (int)$input[0];
$b = (int)$input[1];

if ($a < 10 && $b < 10) {
	echo $a * $b;
}else{
	echo '-1';
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

struct Circ {
    double x, y, r;
};

typedef pair<int, double> pid;
typedef pair<double, int> pdi;
const double EPS = 1e-10;
Circ C[1024];
double adj[1024][1024];

double circ_dist(Circ c1, Circ c2){
    double d = max(0.0, hypot(c1.x - c2.x, c1.y - c2.y) - c1.r - c2.r);
    return d;
}

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

    cin >> C[0].x >> C[0].y >> C[1].x >> C[1].y;
    C[0].r = C[1].r = 0.0;
    int n; cin >> n;
    n += 2;
    for (int i = 2; i < n; i++){
        cin >> C[i].x >> C[i].y >> C[i].r;
    }
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            adj[i][j] = adj[j][i] = circ_dist(C[i], C[j]);
        }
    }
    // dijkstra
    priority_queue<pdi, vector<pdi>, greater<pdi>> pq;
    vector<double> dist(n, -1.0);
    dist[0] = 0.0;
    pq.emplace(0.0, 0);
    while (!pq.empty()){
        auto p = pq.top(); pq.pop();
        if (p.X > dist[p.Y] + EPS) continue;
        for (int v = 0; v < n; v++){
            if (p.Y == v) continue;
            double nd = p.X + adj[p.Y][v];
            if (dist[v] < -0.5 || nd < dist[v] - EPS){
                dist[v] = nd;
                pq.emplace(nd, v);
            }
        }
    }
    cout << fixed << setprecision(10) << dist[1] << endl;
}


Measured memory_bytes: 12528
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
g = 0
lcm = 1
for x in a:
  g = gcd(lcm, x)
  lcm *= x // g
lcm %= mod
res = 0
for x in a:
  res += lcm * pow(x, mod - 2, mod) % mod
  res %= mod
print(res)

Measured memory_bytes: 67288
#include <iostream>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int r, d, x;
    cin >> r >> d >> x;
    rep(i, 0, 10){
        cout << r*x - d << endl;
        x = r*x - d;
    }
    return 0;
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && A == C){
        cout << "No" << endl;
    } else if (A != B && B != C && C !=A) { 
        cout << "No" << endl;        
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}



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


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    py_list = []
    x = 0
    for m in range(M):
        py_list.append([P[m], Y[m], m, x])

    #sort p
    py_list = sorted(py_list)

    #excute x
    x = 1
    for m in range(M):
        p_i = py_list[m][0]
        if m != 0 and py_list[m-1][0] != py_list[m][0]:
            x = 1
        py_list[m][3] = x
        x += 1

    #sort m
    py_list = sorted(py_list, key=lambda x:x[2])

    for m in range(M):
        p = py_list[m][0]
        x = py_list[m][3]
        print("{:06}".format(p) + "{:06}".format(x))
    
# 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()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()


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


int main(){
    ios::sync_with_stdio(0);	//解决c++输入输出流被卡问题
    ll n,m,sum;
    cin >> n >> m >> sum;
    _for(i,0,m){
        cout << sum << " ";
    }
    _for(i,0,n-m){
        if(sum != 1000000000){
            cout << sum + 1 << " ";
        }
        else
        {
            cout << sum - 1 << " ";
        }
        
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3600
s = input()

if s == s[::-1]:
    print(0)
else:
    t = s.replace('x', '')
    if t != t[::-1]:
        print(-1)
    else:
        f = 0
        b = len(s) - 1
        count = 0
        while True:
            if s[f] == s[b]:
                f += 1
                b -= 1
            else:
                count += 1
                if s[f] == "x":
                    f += 1
                elif s[b] == "x":
                    b -= 1
            if f >= b:
                break
        print(count)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;

int main()
{
    int h, w, d;
    cin >> h >> w >> d;
    vector<tiii> num_xy;
    rep(i, 0, h)
    rep(j, 0, w)
    {
        int a;
        cin >> a;
        num_xy.emplace_back(a, i, j);
    }
    sort(num_xy.begin(), num_xy.end());

    vector<int> costs(h * w);
    rep(i, 0, h * w)
    {
        if (i - d < 0)
            costs[i] = 0;
        else
        {
            int x1, y1, x2, y2, a;
            tie(a, x1, y1) = num_xy[i];
            tie(a, x2, y2) = num_xy[i - d]; 
            costs[i] = costs[i - d] + abs(x1 - x2) + abs(y1 - y2);
        }
    }

    int q;
    cin >> q;
    rep(i, 0, q)
    {
        int l, r;
        cin >> l >> r;
        cout << costs[r - 1] - costs[l - 1] << endl;;
    }

    return 0;
}

Measured memory_bytes: 2548
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        s: Chars,
    }
    let mut ans = 0;
    for i in 0..s.len()-1 {
        if s[i]!=s[i+1] {
            ans += 1;
        }
    }

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


Measured memory_bytes: 2488
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin, (v).end);


typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    
    string in;
    
    //入力
    cin >> in;
    if(in == "SUN") cout << "7" << endl;
    if(in == "MON") cout << "6" << endl;
    if(in == "TUE") cout << "5" << endl;
    if(in == "WED") cout << "4" << endl;
    if(in == "THU") cout << "3" << endl;
    if(in == "FRI") cout << "2" << endl;
    if(in == "SAT") cout << "1" << endl;


    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
dic = {}
ban = {}
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]

    if dic.get(a):
        dic[a] = max(dic[a], h[b - 1])
    else:
        dic[a] = h[b - 1]

    if dic.get(b):
        dic[b] = max(dic[b], h[a - 1])
    else:
        dic[b] = h[a - 1]
ans = 0
for i in range(n):
    if dic.get(i + 1):
        if dic[i + 1] < h[i]:
            ans += 1
    else:
        ans += 1
print(ans)


Measured memory_bytes: 103548
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, M;

// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
	  // 最初は全てのデータiがグループiに存在するものとして初期化
	  for(int i = 0; i < n; i++){
		  par[i] = i;
	  }
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main(){
	cin >> N >> M;
	UnionFind uf(N+M+5);

	for(int i = 0; i < N; i++){
		long K;
		cin >> K;
		for(int j = 0; j < K; j++){
			long lidx;
			cin >> lidx;
			lidx--;
			uf.unite(lidx + N, i);
		}
	}

	for(int i = 1; i < N; i++){
		if(!uf.same(0, i)){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()

int main(){
    int x; cin>>x; if(x==7||x==5||x==3)cout<<"YES"<<endl; else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
h = LIST()
dp = [INF] * (N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
# print(dp)
print(dp[N-1])
# N = INT()
# h = LIST()
# dp = [INF] * N
# dp[0] = 0
# dp[1] = abs(h[1] - h[0])
# # for i in range(2, N):
# #     a = abs(dp[i-2] + abs(h[i] - h[i-2]))
# #     b = abs(dp[i-1] + abs(h[i] - h[i-1]))
# #     dp[i] = min(a, b)
# # print(dp[-1])

# for i in range(2, N):
#     a = dp[i-2] + abs(h[i] - h[i-2])
#     b = dp[i-1] + abs(h[i] - h[i-1])
#     dp[i] = min(a, b)
# print(dp[-1])



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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; }

const ll INF = 1LL<<60;
int MAX_N = 110;
int MAX_V = 100100;

int main()
{   
    int N;
    ll W;
    vll w(MAX_N), v(MAX_V);

    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    vvll dp(MAX_N, vll(MAX_V, INF));
    dp[0][0] = 0;

    rep(i, N) rep(j, MAX_V) {
        chmin(dp[i+1][j], dp[i][j]);
        if(dp[i][j] + w[i] <= W) chmin(dp[i+1][j+v[i]], dp[i][j] + w[i]);
    }

    int ans = 0;
    rep(i, MAX_V) if(dp[N][i] <= W) ans = i;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 91180
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 

 int main(){
 ll n ; cin>> n ;
 vector<ll> A(n) ; rep(i,n) cin>>A[i] ;
 ll ans= 0;
 rep(i,n){
  if((i%2==0)&&(A[i]%2==1)) ans++ ;
 }
 cout<<ans<<endl ;
   return 0 ;
 }



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi; 
typedef pair<pair<ll ,ll >,ll > pii; 

int main(){
    
    ll A, B, T;
    cin >> A >> B >> T;
    ll ans = 0;
    ll cn = 1;
    while(cn * A <= T){
        ans += B;
        cn++;
    }

    cout << ans << endl;

}

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

a, b, q = [int(x) for x in input().split()]
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
ans = []

import bisect
ans = []
for _ in range(q):
    x = int(input())
    idx_s = bisect.bisect_left(s, x)
    idx_t = bisect.bisect_right(t, x)
    s_ = []
    t_ = []
    if idx_s < a:
        s_.append(s[idx_s])
    if idx_t < b:
        t_.append(t[idx_t])
    if idx_s - 1 >= 0:
        s_.append(s[idx_s - 1])
    if idx_t - 1 >= 0:
        t_.append(t[idx_t - 1])
    res = float("inf")
    for i in s_:
        for j in t_:
            if (i >= x and j >= x) or (i <= x and j <= x):
                res = min(res, max(abs(i - x), abs(j - x)))
            else:
                res = min(res, abs(i - x) + abs(i - j), abs(j - x) + abs(i - j))
    ans.append(res)
for i in ans:
    print(i)



Measured memory_bytes: 16372
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    String[] line = br.readLine().split(" ");

	    int r = Integer.parseInt(line[0]);
	    int c = Integer.parseInt(line[1]);

	    int[][] matrix = new int[r + 1][c + 1];

	    for (int i = 0; i < r; i++) {
	    	line = br.readLine().split(" ");

	    	for (int j = 0; j < line.length; j++) {
		    	matrix[i][j] = Integer.parseInt(line[j]);

		    	// row sum
		    	matrix[i][c] += matrix[i][j];
		    	// col sum
		    	matrix[r][j] += matrix[i][j];

		    	if (j == line.length - 1) {
			    	// all sum
			    	matrix[r][c] += matrix[i][c];
		    	}
	    	}
	    }

	    StringBuilder sb = new StringBuilder();
	    for (int i = 0; i < r + 1; i++) {
	    	for (int j = 0; j < c + 1; j++) {
	    		sb.append(matrix[i][j]);
	    		if (j < c) {
	    			sb.append(" ");
	    		}
	    	}
	    	sb.append("\n");
	    }
    	System.out.print(sb.toString());
	}
}

Measured memory_bytes: 27544
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define 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;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll maxv = -1;
  rep(i, n){
    cin >> a[i];
    chmax(maxv, a[i]);
  }
  auto f = [&](ll v){
    ll count = 0;
    for (ll i = 0; i < n; i++) {
      count += (a[i]-1)/v;
      // count += a[i]/v;
      // count += a[i] % v != 0;
    }
    // if(count <= k) chmin(maxv, v);
    return count <= k;
  };

  ll ng = 0;
  ll ok = LLONG_MAX / 2;
  // if(k == 0) {
  //   return 0;
  // }
  while (ok - ng > 1) {
    ll mid = (ng + ok) / 2;
    if(f(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;
}


Measured memory_bytes: 4764
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define F first
#define S second
const int INF=1000000000;
typedef long long int lli;
typedef pair<int,int> P;

const int mod=10007;
int dp[1000][1<<3];

int hoge(char c){
	if(c=='J') return 1;
	if(c=='O') return 2;
	if(c=='I') return 4;
}

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	memset(dp,0,sizeof(dp));
	for(int i=1; i<=7; ++i){
		if(s[0]=='J'){
			if((i&1)==0) continue;
			dp[0][i]=1;
		} else if(s[0]=='O'){
			if((i&(1<<1))==0||(i&1)==0) continue;
			dp[0][i]=1;
		} else {
			if((i&(1<<2))==0||(i&1)==0) continue;
			dp[0][i]=1;
		}
	}
	for(int i=1; i<n; ++i){
		for(int j=1; j<=7; ++j){
			if((hoge(s[i])&j)==0) continue;
			for(int k=1; k<=7; ++k){
				if((j&k)==0) continue;
				dp[i][j]+=dp[i-1][k]%mod;
			}
		}
	}
	int ans=0;
	for(int i=1; i<=7; ++i){
		ans+=dp[n-1][i]%mod;
	}
	cout << ans%mod << "\n";
	return 0;
}

Measured memory_bytes: 1252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;

    // B > A and C > B
    // C > B > A
   
    for (int i=0; i<K; i++){
        
        if (C<=B) C*= 2;
        else if (B <= A)B*= 2;
        
        if (B > A and C > B){
        cout << "Yes" << endl;
        return 0;
        } 
    }
    cout << "No" << endl;

}

Measured memory_bytes: 3620
#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
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

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

LL N, K;

int main(void) {
    cin >> N >> K;
    if (K == 0) {
        cout << N * N << endl;
        return 0;
    }
    LL ans = 0;
    FOR(b, K + 1, N + 1) {
        ans += ((N + 1) / b) * (b - K);
        LL tmp = (N + 1) % (b);
        ans += max(0LL, tmp - K);
        //DEBUG(ans)
    }
    cout << ans << endl;
}


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

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

  int ans = 0;
  for(int i = 0; i < n - 2; i++) {
    string substring = s.substr(i, 3);
    if(substring.compare("ABC") == 0) ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
 
    int co=0;
    for(int i=0;i+2<n;i++){
        if(s.at(i)=='A'){
            if(s.at(i+1)=='B'){
                if(s.at(i+2)=='C'){
                    co++;
                }
            }
        }
    }
 
    cout<<co<<endl;
}

Measured memory_bytes: 256
s = input()
N = len(s)
K = int(input())
ords = [ord(_s) for _s in s]
order_set = sorted(list(set(ords)))
d = set()
def add_string(o):
  for i in range(N):
    if ords[i] == o:
      for k in range(1, K+1):
        d.add(s[i:i+k])

add_string(order_set[0])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[1])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[2])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	ll ans=0;
	for(int k=0; k<(1<<n); k++){
		string t1, t2;
		for(int i=0; i<n; i++){
			if(k&(1<<i)) t1+=s[i];
			else t2+=s[i];
		}
		ll dp[19][19]={};
		int m=t1.size();
		dp[0][0]=1;
		for(int i=1; i<=n; i++){
			for(int j=0; j<=m; j++){
				if(j>=1 && s[n+i-1]==t1[m-j]) dp[i][j]+=dp[i-1][j-1];
				if(i>=j+1 && s[n+i-1]==t2[n-m-i+j]) dp[i][j]+=dp[i-1][j];
			}
		}
		ans+=dp[n][m];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int R, S, P;

int tokuten(char t){
  if(t == 'r') return R;
  if(t == 's') return S;
  if(t == 'p') return P;
}

char kachite(char t){
  if(t == 'r') return 'p';
  if(t == 's') return 'r';
  if(t == 'p') return 's';
}

string dasute(int R, int S, int P){
  int a[] = {R, S, P};
  int m;
  string s = {"rsp"};
  char c;

  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      if(a[j]>a[j+1]){
        m=a[j];
        c=s[j];
        a[j]=a[j+1];
        s[j]=s[j+1];
        a[j+1]=m;
        s[j+1]=c;
      }
    }
  }

  return s;
}

int main(void){

  int N, K;
  int x = 0;
  string T;
  string te, l;

  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;

  l = dasute(R, S, P);

  for(int i=0; i<N; i++){
    if(i<K || kachite(T[i])!=te[i-K]){
      te+=kachite(T[i]);
      x+=tokuten(te[i]);
    }
    else{
      for(int j=0; j<3; j++){
        if(l[j]!=te[i-K] && l[j]!=kachite(T[i+K])){
          te+=l[j];
          break;
        }
      }
    }
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 640