akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;


bool compare(char a[], char b[], int a_start, int len_a, int len_b){
    int j=0;
    for(int i=a_start; i <= len_a-1; i++){
        if(a[i] != b[j]){
            return false;
        }
        j++;
    }
    for(int i=0; i < a_start; i++){
        if(a[i] != b[j]){
            return false;
        }
        j++;
    }
    return true;
}

int main()
{
    char a[100];
    char b[100];
    cin>>a;
    cin>>b;
    int len_a = strlen(a);
    int len_b = strlen(b);
    if(len_a == 0 && len_b == 0){
        cout << "No";
        return 0;
    }
    for(int i = len_a-1; i>=0; i--){
        int result = compare(a,b,i,len_a, len_b);
        if(result == true){
           cout << "Yes";
           return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  string s;
  cin >> s;
  long long k;
  cin >> k;
  vector<int> used(s.length(), 0);
  vector<int> subused(s.length(),0);
  long long cnt = 0;
  long long subcnt = 0;
  for(int i = 1; i < s.length(); i++){
    if(s[i] == s[i-1]){
      cnt++;
      used[i] = 1;
      i++;
    }
  }
  for(int i = 0; i < s.length(); i++){
    if(i == 0 && used[s.length()-1] == 0 && s[0] == s[s.length()-1]){
      subcnt++;
      subused[i]= 1;
      i++;
      continue;
    }
    if(i == 0) continue;
    if(s[i] == s[i-1]){
      subcnt++;
      subused[i] = 1;
      i++;
    }
  }

  if(s.length() == 1){
    cout << k/2 << endl;
  }
  else if(s[0] != s[s.length()-1]){
    cout << cnt*k << endl;
  }
  else{
    if(subused[0] == 1 && subused[s.length()-1] == 0){
      cout << cnt + subcnt*(k-1) << endl;
    }
    else if(used[s.length()-1] == 1){
      cout << cnt*k<< endl;
    }
    else cout << cnt*(k - k/2) + subcnt*(k/2)  << endl;
  }
  // cout << cnt << ' ' << (k - k/2) <<' ' << subcnt << ' ' << k/2<< endl;
}


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

long long n, a, b;

int main(){
	cin >> n >> a >> b;
	if ((b-a)%2) cout << min(a+((b-a-1)/2),(n-b+1)+((b-a-1)/2)) << "\n";
	else cout << (b-a)/2 << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int max = Math.max(Math.max(a, b), c);
		int min = Math.min(Math.min(a, b), c);
		System.out.println(max - min);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define foreach(c,itr) for(auto itr = c.begin(); itr!= c.end(); itr++)
#define pb push_back
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int>;
using vll = vector<ll>;

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

   string S;
   int K;
   cin >> S >> K;

   set<string> a;
   for(int i = 0 ; i < S.size(); i++) {
      for(int j = 0; j <= K && i+j <= S.size(); j++) {
	 a.insert(S.substr(i,j));
	  
      }
   }

   auto c = a.begin();
   for(int i = 0; i <= K; i++, c++) {
      if(i == K) cout << *c << endl;
       
   }

   return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define fi first
#define se second
#define maxn 1003
#define mod 1000000007
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> pi;

struct mydata {
	int r,c,d;
};

mydata newData(int r , int c , int d) {
	mydata s;
	s.r = r;
	s.c = c;
	s.d = d;
	return s;
}

bool operator<(const mydata& a , const mydata& b) {
	return a.d > b.d;
}

int n,m,ax,ay,bx,by;
int dist[maxn][maxn];
string s[maxn];
int dir[4] = {0,1,0,-1};
priority_queue<mydata> Q;

int main() {
	scanf("%d%d%d%d%d%d",&n,&m,&ax,&ay,&bx,&by);
	for( int i = 0 ; i < n ; i++ )
		cin >> s[i];
	ax--,ay--,bx--,by--;
	memset(dist,-1,sizeof(dist));
	Q.push(newData(ax,ay,0));
	while(!Q.empty()) {
		mydata temp = Q.top();
		Q.pop();
		int r = temp.r;
		int c = temp.c;
		int d = temp.d;
		dist[r][c] = d;
		if(r == bx && c == by)
			break;
		for( int i = 0 ; i < 4 ; i++ ) {
			int x = r+dir[i];
			int y = c+dir[i^1];
			if(x < 0 || x >= n || y < 0 || y >= m)
				continue;
			if(dist[x][y] != -1 || s[x][y] == '#')
				continue;
			Q.push(newData(x,y,d));
		}
		for( int x = r-2 ; x <= r+2 ; x++ )
			for( int y = c-2 ; y <= c+2 ; y++ ) {
				if(x < 0 || x >= n || y < 0 || y >= m)
					continue;
				if(dist[x][y] != -1 || s[x][y] == '#')
					continue;
				Q.push(newData(x,y,d+1));
			}
	}
	printf("%d\n",dist[bx][by]);
	return 0;
}

Measured memory_bytes: 13680
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str=input.readLine();
	String str_ary[]=str.split(" ");
	
	int a[]=new int[str_ary.length];
	for(int i=0;i<str_ary.length;i++)
	    {
		for(int j=0;j<str_ary.length;j++)
		    {
			if(str_ary[i].equals(str_ary[j]))a[i]++;
		    }
	    }
	int max=0;

	
	
	for(int i=0;i<a.length;i++)
	    {
		if(max<a[i])max=i;
	    }
	System.out.print(str_ary[max]+" ");
	max=0;
	int y=0;
	
	int b[]=new int[str_ary.length];
	for(int j=0;j<str_ary.length;j++)
	    {
		b[j]=str_ary[j].length();
		if(max<b[j])
		    {
			max=b[j];
			y=j;
		    }
	    }
	
	
	System.out.println(str_ary[y]);
    }
}

Measured memory_bytes: 16904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#define MAX_N 1000000000
typedef long long ll;
using namespace std;
int main(){
  string s1,s2;
  cin>>s1;
  cin>>s2;
  if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]){
    cout<<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
  return 0;
}


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

int main(){
  int K,X; cin >> K >> X;
  vector<int>ans;
  for(int i=X-K+1;i<X+K;i++){
    if(i != X+K-1)  cout << i << ' ';
    else  cout << i << endl;
  }
}


Measured memory_bytes: 256
/* ****TCIITB**** */

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

#define N  100005

int main()
{
	
	io

	ll n;
	cin>>n;
	std::vector<ll> b(n-1),a(n,-1);
	std::vector<pii> tmp;
	rep(i,0,n-1)
	{
		cin>>b[i];
		tmp.pb({b[i],i});
	}
	sort(all(tmp));
	rep(i,0,n-1)
	{
		ll val=tmp[i].F;
		ll idx=tmp[i].S;
		if(a[idx]==-1 && a[idx+1]==-1)
		{
			a[idx]=val;
			a[idx+1]=val;
			continue;
		}
		if(a[idx]==-1 && a[idx+1]!=-1)
		{
			a[idx]=val;
			continue;
		}
		if(a[idx]!=-1 && a[idx+1]==-1)
		{
			a[idx+1]=val;
			continue;
		}
		if(max(a[idx],a[idx+1])<=b[i])
			continue;
	}
	ll res=0;
	rep(i,0,n)
	res+=a[i];
	cout<<res;

	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a,b,s[201],t[201],ans,tmp;
int main(void){
    while(1){
    cin>>n>>a>>b;
    if(n==0)return 0;
    ans=0;
    tmp=0;
    
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=1;i<n;i++){
        t[i]=s[i-1]-s[i];
    }
    for(int i=a;i<=b;i++){
        if(tmp<=t[i]){tmp=t[i];ans=i;}
    }
    cout<<ans<<endl;
    }
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define ll long long
#define MAX 1e9+7
#define MIN -MAX
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
#define NO_OF_CHARS 256
using namespace std;
int countDivisors(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int main(){
ll a;
cin>>a;
string s;
cin>>s;
if(a>=3200)cout<<s;
else cout<<"red";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		int in = 0;
		int ou = 0;
		for(int i = 0; i < n; i++) {
			if(s.charAt(i) == 'a' && (a+b) > (in+ou)) {
				System.out.println("Yes");
				in++;
			}
			else if(s.charAt(i) == 'b' && (a+b) > (in+ou) && b-1 >= ou) {
				System.out.println("Yes");
				ou++;
			}
			else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 50256
#include <iostream>

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

int main() {
    std::string s, t;
    bool f = true;
    std::cin >> s >> t;
    rep(i, s.size()) f &= s[i] == t[i];

    std::cout << (f ? "Yes" : "No") << std::endl;
    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) > (c + d))
    cout << "Left";
  else if ((a + b) < (c + d))
    cout << "Right";
  else 
    cout << "Balanced";
}

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

using namespace std;

int main(){
    long long int N,K;
    cin >> N;
    cin >> K;

    long long int temp =N;

    for(long long int i=0;i<10000;i++){
        N=N%K;
        if(temp>N){temp=N;}
        if(N<K){N=K-N;}
    }
    cout << temp << endl;

}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
    int x, y, z;
    int k, s;
    cin >> k >> s;
    int c = 0;
    for(int i = 0; i <= k; i++) {
        for(int j = 0; j <= min(k, s - i); j++){
            if(s - (i + j) <= k)
                c++;
        }
    }
cout << c;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define for(i,n) for(int i=0;i<n;i++)
#define test(t) int t;cin>>t;while(t--)
#define ll long long
#define mod 1000000007
int main()
{
  ll int n,k;
   cin>>k>>n;
   int a[n];int b[n];
   for(i,n)
    cin>>a[i];
   for(i,n-1)
   {
       b[i]=a[i+1]-a[i];
   }
   b[n-1]=k-a[n-1]+a[0];
   sort(b,b+n);
   cout<<k-b[n-1];



}




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

int main() {
  char c;cin>>c;
  bool ans=false;
  for(char a:{'a','i','u','e','o'}){
    if(a==c) ans = true;
  }

  if(ans) cout << "vowel" << endl;
  else cout<<"consonant"<<endl;
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	int n, ans=0;
	cin >>n;
	
	VI x(n), y(n), h(n);
	rep(i,n) cin >>x[i] >>y[i] >>h[i];
	
	rep(i,101) rep(j,101){
		int sv=-1, sw=1;
		rep(k, n) if(h[k]>0){
			int w = abs(x[k]-i) + abs(y[k]-j) + h[k];
			if(sv==-1){sv = w; continue;}
			if(w != sv ){
				sw=0;
				break;
			}
		}
		if(sw==0) continue;
		rep(k, n) if(h[k]==0){
			if(sv > abs(x[k]-i) + abs(y[k]-j)){sw=0; break;}
		}
		if(sw==1){
			cout << i <<" "<<j<<" " << sv<<"\n";
			return 0;
		}
	}
	
	
	
	cout << ans <<"\n";
}


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

N, M = map(int, input().split())
PY = [map(int, input().split()) for i in range(M)]
PYI = sorted((p, y, i+1) for i, (p, y) in enumerate(PY))
def gen():
  pre = -1
  count = -1
  for p, y, i in PYI:
    if p == pre:
      count += 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
    else:
      count = 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
      pre = p
print('\n'.join(i[1] for i in sorted(gen())))
     

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

bool check(int a[], int b[], int len) {
  for(int i=0; i<len; i++) {
    if(a[i]!=b[i]) return false;
  }
  return true;
}

int main() {
  int n,a,b,j;

  cin >> n;
  vector<int>v(n);
  rep(i,n) v[i] = i+1;

  vector<int>p(n);
  rep(i,n) cin >> p[i];

  vector<int>q(n);
  rep(i,n) cin >> q[i];

  j = 0;
  do {
    j++;
    if(p == v) a=j;
    if(q == v) b=j;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(a - b) << endl;

  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    ll min = INF;
    REP(i, 27)
    {
        //! 文字'a'+iに変える
        char c = 'a' + i;
        string s = S;
        for (ll j = 0;; ++j)
        {
            bool f = true;
            REP(k, s.length() - 1)
            {
                if (s[k] != s[k + 1])
                    f = false;
            }
            if (f)
            {
                min = std::min(j, min);
                break;
            }

            string tmp = "";
            REP(k, s.length() - 1)
            {
                if (s[k] == c || s[k + 1] == c)
                    tmp.push_back(c);
                else
                    tmp.push_back(s[k]);
            }
            s = tmp;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    s = input()
    t = input()
    n = len(s)
    d = defaultdict(set)
    for i in range(n-1):
        if t[i] != t[i+1] and s[i] == s[i+1]:
            print("No")
            return
        d[t[i]].add(s[i])
    d[t[-1]].add(s[-1])

    for c in d:
        if len(d[c]) > 1:
            print("No")
            return
            
    print("Yes")
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""


Measured memory_bytes: 10228
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    cout << fixed << setprecision(20);
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double sum_min = 60*H + M;
    double h = 0.5 * sum_min;
    double m = M * 6;
    double deg = m - h;
    double rad = deg * (3.141592653589793238462/180);
    double ans = sqrt(A*A + B*B - 2*A*B*cos(rad));
    cout << ans;
}

Measured memory_bytes: 4256
#include "iostream"

using namespace std;
long long int H,W;
char name[6];
int x, y;

int main() {
	cin >> H>>W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> name;
			if (name[0] == 's'&&name[1] == 'n'&&name[2] == 'u'&&name[3] == 'k'&&name[4] == 'e') {
				x = j;
				y = i;
			}
		}
	}
	cout << char('A' + x - 1) << y << "\n";
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;
namespace _0567
{
    class Program
    {
        static void Main(string[] args)
        {
            int syurui = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int kizinedan = x[0];
            int toppingnedan = x[1];
            int kizikarori = int.Parse(Console.ReadLine());
            int[] toppingkarori = new int[syurui];
            for (int i = 0; i < syurui; i++)
            {
                toppingkarori[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(toppingkarori);
            Array.Reverse(toppingkarori);
            int nowkarori = kizikarori;
            int nownedan = kizinedan;
            int nowpizza = nowkarori / nownedan;
            int j = 0;
            while (true)
            {
                if (syurui == j)
                {
                    break;
                }
                nowkarori += toppingkarori[j];
                nownedan += toppingnedan;
                if (nowpizza > nowkarori / nownedan)
                {
                    break;
                }
                else
                {
                    nowpizza = nowkarori / nownedan;
                }
                j++;
            }
            Console.WriteLine(nowpizza);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9636
N,M = map(int,input().split())
edges=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
S,T = map(lambda x:int(x)-1,input().split())

N3=N*3
adj=[set() for _ in range(N3)]

for a,b in edges:
    for i in range(3):
        start = a+N*i
        dst = b+N*(i+1)
        adj[start%N3].add(dst%N3)


Q=[S]
visited={S}
dist=[-1]*N3
dist[S]=0

while Q:
    tmp=[]
    for q in Q:
        for i in adj[q]:
            if i in visited:
                continue
            else:
                dist[i]=dist[q]+1
                visited.add(i)
                tmp.append(i)
    Q = tmp
print(dist[T] if dist[T]==-1 else dist[T]//3)



Measured memory_bytes: 126312
import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int answer = 0;
		int n = Integer.parseInt(scanner.nextLine());
		int[] data1 = new int[n];
		for(int i = 0; i < n; i++){
			data1[i] = scanner.nextInt();
		}
		String nothing = scanner.nextLine();

		int q = Integer.parseInt(scanner.nextLine());
		int[] data2 = new int[q];
		for(int i = 0; i < q; i++){
			data2[i] = scanner.nextInt();
		}

		for(int i = 0; i < q; i++){
		    int left = 0;
    		int right = n;
    		int middle = 0;
			while(left < right){
				middle = (left + right) / 2;

				if(data1[middle] == data2[i]){
					answer ++;
				// 	System.out.println(data2[i]);
					break;
				}else if(data1[middle] > data2[i]){
					right = middle;
				}else{
					left = middle+1;
				}
			}
		}
		
		System.out.println(answer);

	}
}

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

N,M,L=map(int,input().split())

E=[[] for i in range(N+1)]

for i in range(M):
    a,b,cost=map(int,input().split())

    E[a].append((b,cost))
    E[b].append((a,cost))


Q=int(input())
Query=[list(map(int,input().split())) for i in range(Q)]

ANS=[[(N+10,0) for i in range(N+1)] for j in range(N+1)]

from collections import deque
import heapq

for start in range(1,N+1):

    ANS[start][start]=(0,0)

    checking=[((0,0),start)]

    while checking:
        #print(checking)
        c,checktown=heapq.heappop(checking)
        h,cost0=c

        if ANS[start][checktown]<c:
            continue

        for to,cost in E[checktown]:
            
            if cost0+cost<=L and (h,cost0+cost)<ANS[start][to]:
                ANS[start][to]=(h,cost0+cost)
                heapq.heappush(checking,((h,cost0+cost),to))

            elif cost<=L and (h+1,cost)<ANS[start][to]:
                ANS[start][to]=(h+1,cost)
                heapq.heappush(checking,((h+1,cost),to))

for x,y in Query:
    if ANS[x][y][0]==N+10:
        print(-1)
    else:
        print(ANS[x][y][0])
    


Measured memory_bytes: 100224
#include <iostream>
#include <string>
using namespace std;
int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;
    for (int i = 0; i < S.size(); i++)
        if (S[i] != S[K-1]) S[i] = '*';
    cout << S << endl;
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

#define mod 1000000007
#define MAXX  1e18
#define MINN -1e18
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pi pair<ll, ll>
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lb(a, key) lower_bound(all(a), key) - a.begin();
#define ub(a, key) upper_bound(all(a), key) - a.begin();
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define add(a, b) (((a)%mod + (b)%mod + mod)%mod)
#define mul(a, b) (((a)%mod * (b)%mod) % mod)
#define endl cout<<"\n";
#define debug(vari) cerr<< "["<< #vari << " " << (vari) << "]";endl;
#define read(a) for(auto &i: a) cin >> i;
#define out(a)  for(auto i: a) cout << i << " ";endl
#define ordered_set tree<ll, null_type, std::less<ll>, rb_tree_tag, tree_order_statistics_node_update>





using namespace __gnu_pbds;
using namespace std;

struct point {
    int x;
    int y;
};

bool cmp(point p, point q) {
    if(p.x == q.x) return p.y < q.y;
    return p.x < q.x;
}

int main() {
    fastio
    ll a, b; cin >> a >> b;
    if(a > b) swap(a, b);
    while(b--) {
        cout << a;
    }
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,sum=0, a;
  string ans;
  cin >> n >> m;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);
    sum += v.at(i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(),v.end());
  if(v.at(m-1) >= sum/(4*double(m))){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,G; cin>>N>>G;
    vint p(N),c(N);
    REP(i,N) cin>>p[i]>>c[i];

    int ans=1e18;
    for(int S=0;S<(1<<N);S++){
        int score=0,cnt=0;
        REP(i,N){
            if(S>>i&1){
                score+=100*(i+1)*p[i]+c[i];
                cnt+=p[i];
            }
        }
        for(int i=N-1;i>=0;i--){
            if(S>>i&1) continue;
            REP(j,p[i]-1){
                if(score<G){
                    score+=100*(i+1);
                    cnt++;
                }
            }
        }
        if(score>=G) ans=min(ans,cnt);
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
def print(s, a, b)
  puts s[a..b]
end

def reverse(s, a, b)
  chunk = s[a..b]
  s[a..b] = chunk.reverse
  s
end

def replace(s, a, b, p)
  s[a..b] = p
  s
end

s = gets.chomp
q = gets.chomp.to_i

q.times do
  c = gets.chomp.split
  c[1] = c[1].to_i
  c[2] = c[2].to_i
  case c[0]
  when "print" then print(s, c[1], c[2])
  when "reverse" then s = reverse(s, c[1], c[2])
  when "replace" then s = replace(s, c[1], c[2], c[3])
  end
end

Measured memory_bytes: 6152
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if(k>a){
        k=k-a;a=0;
    }
    else{
        a=a-k;
        cout<<a<<" "<<b<<endl;
        return 0;
    }
    if(k>b){
        k=k-b;b=0;
    }
    else b=b-k;
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using ordered_multiset = tree <T, null_type, less_equal <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int siz = 2e2 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "1";

vector <vector <int> > edges;
int cap[siz][siz], prv[siz];
int s, t;

void add(int u, int v, int c, bool d) {
    edges[u].push_back(v);
    edges[v].push_back(u);
    cap[u][v] = c;
    if (!d) {
        cap[v][u] = c;
    }
}

int bfs() {
    queue <ii> qu;
    memset(prv, -1, sizeof(prv));
    prv[s] = 0;
    qu.push(ii(s, MAXX));

    while (!qu.empty()) {
        int u, f;
        tie(u, f) = qu.front();
        qu.pop();

        if (u == t) {
            return f;
        }

        for (auto &v : edges[u]) {
            if (prv[v] == -1 && cap[u][v] > 0) {
                prv[v] = u;
                qu.push(ii(v, min(f, cap[u][v])));
            }
        }
    }
    return 0;
}

int maxflow() {
    int f = 0;
    while (int nf = bfs()) {
        f += nf;
        int u = t;
        while (u != s) {
            int v = prv[u];
            cap[v][u] -= nf;
            cap[u][v] += nf;
            u = v;
        }
    }
    return f;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int h, w;
    cin >> h >> w;
    s = 0, t = h + w + 1;
    edges.resize(h + w + 2);
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            char c;
            cin >> c;

            if (c == 'o') {
                add(i, j + h, 1, 0);
            }
            else if (c == 'S') {
                add(s, i, MAXX, 1);
                add(s, j + h, MAXX, 1);
            }
            else if (c == 'T') {
                add(i, t, MAXX, 1);
                add(j + h, t, MAXX, 1);
            }
        }
    }

    int ans = maxflow();
    if (ans > h * w - 2) {
        ans = -1;
    }

    cout << ans << "\n";


//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


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

using namespace std;

bool haveOkashi[102];

int main(){
    int N,K,d,a, cnt=0;
    cin >> N >> K;
    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++){
            cin >> a;
            haveOkashi[a] = true;
        }
    }
    for(int i=1; i<=N; i++){
        if (haveOkashi[i]==false){
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pb push_back
using namespace std;

vector<ll> factor(pow(10, 6) + 1, 0);
//=============prime_factor============================
void prime_factor(ll N)
{
  for (ll i = 2; i * i <= N; ++i) {
    if (N % i == 0) {
      ll cnt = 0;
      while (N % i == 0) {
        N /= i;
        cnt += 1;
      }
      factor.at(i) = max(factor.at(i), cnt);
    }
  }
  if (N != 1) {
    factor.at(N) = max(factor.at(N), 1ll);
  }
}
//=================================================
//=============modinv============================
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//=================================================

//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================



int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    prime_factor(A.at(i));
  }
  ll lcm = 1;
  for (ll i = 1; i < pow(10, 6) + 1; ++i) {
    lcm *= modpow(i, factor.at(i), mod);
    lcm %= mod;
  }
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    ans += lcm * modinv(A.at(i), mod) % mod;
    ans %= mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 10976
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  int h,w;
  cin>>h>>w;
  char a[h][w];
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin>>a[i][j];
    }
  }
  int l[h][w];//left
  int r[h][w];//right
  int d[h][w];//down
  int u[h][w];//up
  
  //lwft
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[i][j]=='#'){
        l[i][j]=0;
      }
      else{
        if(j==0){
          l[i][j]=1;
        }
        else{
          l[i][j]=l[i][j-1]+1;
        }
      }
    }
  }

  //right
  for(int i = 0; i < h; i++){
    for(int j = w-1; j >= 0; j--){
      if(a[i][j]=='#'){
        r[i][j]=0;
      }
      else{
        if(j==w-1){
          r[i][j]=1;
        }
        else{
          r[i][j]=r[i][j+1]+1;
        }
      }
    }
  }
  
  //up
  for(int j = 0; j < w; j++){
    for(int i = 0; i < h; i++){
      if(a[i][j]=='#'){
        u[i][j]=0;
      }
      else{
        if(i == 0){
          u[i][j]=1;
        }
        else{
          u[i][j]=u[i-1][j]+1;
        }
      }
    }
  }
  
  //down
  for(int j = 0; j < w; j++){
    for(int i = h-1; i >= 0; i--){
      if(a[i][j]=='#'){
        d[i][j]=0;
      }
      else{
        if(i == h-1){
          d[i][j]=1;
        }
        else{
          d[i][j]=d[i+1][j]+1;
        }
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
     ans = max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3); 
    }
  }
  cout<<ans<<endl;
  return 0;
}




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

#define cnd(c, a, b) (c ? a : b);
#define fl(x,y,z) for(int x=y;x<z;x++)
#define fe(x,y,z) for(int x=y;x<=z;x++)
#define fge(x,y,z) for(int x=y;x>=z;x--)

#define debug(x) std::cerr << #x << " --> " << x << "\n";
#define fastIO std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define pb push_back
#define pob pop_back
 
#define ln '\n'
typedef long long int ll;

ll mod=1e9+7;

void decrypt() {
	ll d, t, s;
	cin>>d>>t>>s;
	cout<<cnd((d*1.0)/s <=t, "Yes\n", "No\n");
	return;
}

int main() {
    fastIO
    int t = 1;
    // cin >> t;
    fl(i,0,t) {
    	// cout << "Case #"<< i+1 <<": ";
    	decrypt();
    }
    return 0;
}

Measured memory_bytes: 3612
import std.stdio;
import std.string;
import std.conv;
void main(){
	int n;
	string s,t;
	readf("%d\n%s\n%s\n",&n,&s,&t);
	for(int i=0;i<n;++i){
		if(s[i..n] == t[0..n-i]){
			(s[0..i]~t[0..n]).length.writeln;
			return;
		}
	}
	(n*2).writeln;
}


Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int p, q, r;
    cin >>p >>q >>r;
    cout <<min(min(p+q, q+r), p+r);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define pi pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912

const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int N,K; cin >> N >> K;
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(i+1 == K){
            char tmp = tolower(s[i]);
            cout << tmp;
        }
        else cout << s[i];
    }
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

vector<int> toposo(vector<vector<int>>& g) {
	vector<int> h(g.size());
	for (int i = 0; i < g.size(); i++) {
		for (int j = 0; j < g[i].size(); j++) {
			h[g[i][j]]++;
		}
	}
	//入次数が0の頂点の集合
	stack<int> st;

	//入次数が0の頂点であればstに追加
	for(int i = 0; i < g.size(); i++) if (h[i] == 0) st.push(i);

	//ソートされた後のグラフ
	vector<int> ans;
	//stがなくなるまでループ
	while (st.size()) {
		//stの集合のから一つ取り出す
		int i = st.top(); st.pop();
		ans.push_back(i);
		for (auto& j : g[i]) {
			//隣接する頂点の入次数をマイナス1
			h[j]--;
			//これによって入次数が0になればstに追加
			if (h[j] == 0) st.push(j);
		}
	}
	return ans;
}

int main() {
	io_init;
	int N;
	cin >> N;
	vector<vector<int>> A(N, vector<int>(N - 1));
	for (int i = 0; i < N; i++) for (int j = 0; j < N - 1; j++) {
		cin >> A[i][j];
		A[i][j]--;
	}
	vector<vector<int>> g(N * (N - 1) / 2);
	vector<vector<int>> par(N * (N - 1) / 2);
	vector<vector<int>> conv(N, vector<int>(N, -1));
	for (int i = 0, n = 0; i < N - 1; i++)for (int j = i + 1; j < N; j++, n++) {
		conv[i][j] = n;
		conv[j][i] = n;
	}
	for (int i = 0; i < N; i++)for (int j = 0; j < N - 2; j++) {
		g[conv[i][A[i][j]]].push_back(conv[i][A[i][j + 1]]);
		par[conv[i][A[i][j + 1]]].push_back(conv[i][A[i][j]]);
	}
	for (int i = 0; i < g.size(); i++) {
		sort(g[i].begin(), g[i].end());
		g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
		sort(par[i].begin(), par[i].end());
		par[i].erase(unique(par[i].begin(), par[i].end()), par[i].end());
	}
	auto tp = toposo(g);

	if (tp.size() != g.size()) {
		cout << -1 << endl;
		return 0;
	}

	vector<ll> dp(N * (N - 1) / 2, 0);
	for (int i = 0; i < tp.size(); i++) {
		ll mx = -1;
		for (int j = 0; j < par[tp[i]].size(); j++) {
			mx = max(mx, dp[par[tp[i]][j]]);
		}
		dp[tp[i]] = mx + 1;
	}
	cout << *max_element(dp.begin(), dp.end()) + 1 << endl;
}

Measured memory_bytes: 68820
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b[300005] = {}, c[300005] = {}, d[300005] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a, c[a]++;
    sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++) d[c[i]]++;
    for (int i = 1; i <= n; i++) d[i] += d[i - 1];
    for (int i = 1; i <= n; i++) c[i] += c[i - 1];
    for (int i = 1; i <= n; i++) b[i] = c[d[i]] + (n - d[i]) * i;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; ; j++) {
            if (b[j] < i * j) {
                cout << j - 1 << '\n';
                break;
            }
        }
    }
}


Measured memory_bytes: 7172
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n;
	cin >> n;
	vec(a,n);
	REP(i,n){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	cout << a[n-1]-a[0] << endl;
 
    return 0;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int a,b;
    cin >> a >> b;

    int ans=0;
    for (int i = a; i <= b; i++) {
        int c,d,e,f;
        c = i % 10;
        d = i / 10000;
        e = (i/1000) % 10;
        f = (i/10) % 10;
        if (c == d && e == f) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector


// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#ifdef LOCAL
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}
#else
#define what_is(x)
#define debug(v)
#endif

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	vi a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	int s = accumulate(all(a), 0);
	set<int> factors;
	for (int i = 1; i * i <= s; i++) {
		if (s % i == 0) {
			factors.insert(i);
			factors.insert(s/i);
		}
	}

	int answer = 1;
	for (int f : factors) {
		int op = 0;
		vi r(n);
		for (int i = 0; i < n; i++) r[i] = a[i] % f;
		sort(all(r));
		for (int i = 0, j = n-1; i < j; i++) {
			op += r[i];
			while (r[j]+r[i] > f) {
				r[i] -= f - r[j];
				r[j] = f;
				j--;
			}
			if (r[i] > 0) {
				r[j] += r[i];
				r[i] = 0;
			}
		}

		if (op <= k) answer = max(answer, f);
	}
	printf("%d\n", answer);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int H,W,i,j,k;
    char a[100][100];

    scanf("%d%d",&H,&W);
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
        	if(j==0){
        		getchar();
        	}
            scanf("%c",&a[i][j]);
        }
    }
    for(k=0;k<W+2;k++){
        printf("#");
        if(k==W+1){
            printf("\n");
        }
    }
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if(j==0){
                printf("#%c",a[i][j]);
            }else{
                printf("%c",a[i][j]);
            }
            if(j==W-1){
                printf("#\n");
            }
        }
    }
    for(k=0;k<W+2;k++){
        printf("#");
        if(k==W+1){
            printf("\n");
        }
    }
    return 0;
}

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

int main(){
	int n;	cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i){
		cin >> h[i];
	}
	int dp[n+10];
	fill(dp, dp+n+10, 1e9+10);
	dp[0] = 0;
	for (int i = 0; i < n; ++i){
		dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
		dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, K, ans;

int main() {
    fastio();
    cin >> N >> K;
    ll cnt = (N - 1) * (N - 2) / 2 - K;
    if(cnt < 0) cout << "-1\n";
    else {
        cout << N - 1 + cnt << "\n";
        FOR(i, 2, N) cout << "1 " << i << "\n";
        FOR(i, 2, N) {
            if(cnt == 0) break;
            FOR(j, i+1, N) {
                if(cnt == 0) break;
                cout << i << " " << j << "\n";
                cnt--;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;


const int MAX_N = 100005;

int n,k,h[MAX_N],dp[MAX_N];

int main()
{
	scanf("%d %d",&n,&k);
	for (int i=1; i<=n; i++)
		scanf("%d",h+i);
	for (int i=2; i<=n; i++)
	{
		dp[i]=2000000000;
		for (int j=max(1,i-k); j<i; j++)
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
	}
	printf("%d\n",dp[n]);
	return 0;
}


Measured memory_bytes: 896
import java.util.*;
import java.math.*;

class Main{
  public static void main(String args[]){

    BigInteger n, m, tmp1, tmp2;
    tmp1 = new BigInteger(String.valueOf(10000));
    tmp2 = new BigInteger(String.valueOf(0));
    Scanner sc = new Scanner(System.in);
    int a, b;

    String t[] = {"", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
      "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"};

    while(true){
      a = Integer.parseInt(sc.next());
      b = Integer.parseInt(sc.next());
      if(a == 0) break;

      n = new BigInteger(String.valueOf(a));
      n = n.pow(b);

      String ans = "";
      int p = 0;

      while(!n.equals(tmp2)){
        m = n.remainder(tmp1);
        long temp = m.longValue();
        if(temp != 0){
          ans = String.valueOf(temp) + t[p] + ans;
        }
        n = n.divide(tmp1);
        p++;
      }

      System.out.println(ans);
    }
  }
}




Measured memory_bytes: 26724
n,m = map(int,input().split())
ab_list = [list(map(int,input().split())) 
           for nesya in range(m)]
start = set()
end = set()
for ab in ab_list:
  if ab[0] == 1:
    start.add(ab[1])
  if ab[1] == n:
    end.add(ab[0])
ans = start&end
if len(ans) > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 58896
s=str(input())
s=list(s)
ans=[0]*len(s)
t=0
r=0
l=0
for i in range(len(s)-1):
  if s[i]=="L" and s[i+1]=="R":
    for j in range(t,i+1):
      if s[j]=="R" and s[j+1]=="L":
        if (i+1-t)%2==0:
          ans[j]=ans[j]+(i+1-t)//2
          ans[j+1]=ans[j+1]+(i+1-t)//2
        else:
          if t%2==j%2:
            ans[j]=ans[j]+(i+1-t)//2+1
            ans[j+1]=ans[j+1]+(i+1-t)//2
          else:
            ans[j+1]=ans[j+1]+(i+1-t)//2+1
            ans[j]=ans[j]+(i+1-t)//2
        t=i+1
        break
for j in range(t,len(s)):
  if s[j]=="R" and s[j+1]=="L":
    if (len(s)-t)%2==0:
      ans[j]=ans[j]+(len(s)-t)//2
      ans[j+1]=ans[j+1]+(len(s)-t)//2
    else:
      if t%2==j%2:
        ans[j]=ans[j]+(len(s)-t)//2+1
        ans[j+1]=ans[j+1]+(len(s)-t)//2
      else:
        ans[j+1]=ans[j+1]+(len(s)-t)//2+1
        ans[j]=ans[j]+(len(s)-t)//2
print(" ".join(map(str,ans)))

Measured memory_bytes: 17728
#include <stdio.h>
#include <stdlib.h>
//isatty
#if defined(WIN32) || (!defined(__GNUC__) && !defined(__clang__))
	#include <io.h>
#else
	#include <unistd.h>
#endif

int solve(long long n,long long starting,int base){
	n+=starting-2;
	long long digits=1;
	long long expbase=1;
	long long x;
	for(;(x=digits*expbase*(base-1))<=n;n-=x){
		digits++;
		expbase*=base;
	}
	//(digits)桁の数を並べた中のn桁目を求めれば良い
	long long num=expbase+n/digits;
	long long d=digits-1-n%digits;
	for(;d--;num/=base);
	return num%base;
}

int main(int argc,char **argv){
	long long starting=1;
	int base=10;
	if(isatty(fileno(stdin))){
		fprintf(stderr,"nthdigit [starting=%lld] [base=%d] [<nthdigit.txt]\n",starting,base);
	}

	if(argc>2)base=strtol(argv[2],NULL,10);
	if(argc>1)starting=strtoll(argv[1],NULL,base);

	long long n,k;
	for(;;){
		//if(isatty(fileno(stdin)))printf("input> ");
		if(!~scanf("%lld%lld",&n,&k)||!n)return 0;
		for(long long i=n;i<n+k;i++)printf("%d",solve(i,starting,base));
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2124