akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

ll fp(ll x, ll y)
{
	ll res = 1;
	while (y)
	{
		if (y & 1)
			res = mul(res, x, 2019);
		y /= 2;
		x = mul(x, x, 2019);
	}
	return res;
}

void solve()
{
	string S;
	cin >> S;
	map<int, int> cnt;
	cnt[0] = 1;
	ll num = 0;
	int n = S.length();
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		ll temp = fp(10, n - i - 1);
		temp = mul(S[i] - '0', temp, 2019);
		num = add(num, temp, 2019);
		db(num);
		ans += cnt[num];
		cnt[num]++;
	}
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
    vector<char*> v({token});
    while(token = strtok(NULL,", ")) v.push_back(token);
    return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
    debug() << " [" << args.back() << ": " << H << "] ";
    args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main(){
    IOS;
    int n;
    cin>>n;
    ll ans=binpow(10,n,mod);
    ans-=(2*binpow(9,n,mod))%mod;
    if(ans<0) ans+=mod;
    ans+=binpow(8,n,mod);
    ans%=mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int H, W;
int c[10][10];

int cost[20][10][10];

void warshalfloyd() {
  repe(i, 0, 9) {
    repe(j, 0, 9) { cost[0][i][j] = c[i][j]; }
  }

  repe(k, 1, 10) {
    repe(i, 0, 9) {
      repe(j, 0, 9) {
        cost[k][i][j] = min(cost[k - 1][i][j],
                            cost[k - 1][i][k - 1] + cost[k - 1][k - 1][j]);
      }
    }
  }
}

int main() {
  cin >> H >> W;
  repe(i, 0, 9) {
    repe(j, 0, 9) { cin >> c[i][j]; }
  }

  warshalfloyd();

  int ans = 0;
  repe(i, 1, H) {
    repe(j, 1, W) {
      int a;
      cin >> a;
      if (a != -1) ans += cost[10][a][1];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3600
public class Main {
	public static void main(String[] args) {
        int hon[] = {2,4,5,7,9};
        int pon[] = {0,1,6,8};
        int N = new java.util.Scanner(System.in).nextInt();
        N = N%100;
        N = N%10;
        
        for(int i: hon){
            if(N == i) System.out.println("hon");
        }
        for(int i: pon){
            if(N == i) System.out.println("pon");
        }
        if(N == 3) System.out.println("bon");
    }
}

Measured memory_bytes: 35848
#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)++)
#define str string
#define s_vec(data,name,vertical,horizontal) vector<vector<(data)>> (name)((vertical),vector<(data)>((horizontal)));


int main(){
    int n,d,x;
    cin>>n>>d>>x;

    vector<int> a(n);

    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    
    int co = 0;
    for(int i=0;i<n;i++){
        co += ((d-1)/a.at(i))+1;
    }
    
    cout<<co+x<<endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
 
using namespace std;
 
int main()
{
 int H, W;
 while(scanf("%d %d", &H, &W), H!=0)
 {
  for (int i = 0; i < H; i++)
  {
   if (i == 0 || i == H - 1)
   {
    for (int j = 0; j < W; j++)
    {
     cout << "#";
    }
   }
   else
   {
    for (int j = 0; j < W; j++)
    {
     if (j == 0 || j == W - 1)
     {
      cout << "#";
     }
     else
     {
      cout << ".";
     }
    }
   }
   cout << endl;
  }
  cout << endl;
 }
}


Measured memory_bytes: 3156
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define M 200005

int n;
int A[M],ans[M];

int main(){
	scanf("%d",&n);
	int l=1,r=n;
	for(int i=1;i<=n;i++)scanf("%d",&A[n-i+1]);
	for(int i=1;i<=n;i++){
		int p=(i&1);
		if(p)ans[l++]=A[i];
		else ans[r--]=A[i];
	}
	for(int i=1;i<=n;i++)
		printf("%d ",ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;++i){
        double abdx,abdy,cddx,cddy;
        double x[4];
        double y[4];
        for(int j=0;j<4;++j){
            cin>>x[j]>>y[j];
        }
        abdx=x[0]-x[1];
        cddx=x[2]-x[3];
        abdy=y[0]-y[1];
        cddy=y[2]-y[3];
        if(abdy/abdx==cddy/cddx)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100000;
int n, a[N], mx1 = 0,mx2;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a[i];}
	sort(a, a + n);
	cout << a[n - 1] << ' ';
	int md = a[n - 1] / 2, md_ind = lower_bound(a, a + n - 1, md) - a;
	mx2 = a[max(0, md_ind - 1)];
	for (int i = max(0, md_ind - 1)+1; i < n - 1 && i < md_ind + 1; i++) {
		if (min(mx2, a[n-1] - mx2) < min(a[i], a[n-1] - a[i]))mx2 = a[i];
	}
	cout << mx2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
int d,t,s;
cin >> d >> t >> s;
if (d <= t*s) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}



Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, L[2000], ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> L[i];
	sort(L, L + N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			long long l = j, r = N;
			while (r - l > 1) {
				long long MID = (l + r) / 2;
				if (L[MID] < L[i] + L[j]) l = MID;
				else r = MID;
			}
			ANS += l - j;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    char a, b;
    cin >> a >> b;
    //cout << ans << endl;
    if (a<b) cout << "<" << endl;
    else if(a>b) cout << ">" << endl;
    else cout << "=" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    scanf("%d", &K);
    printf("%d\n", a[K-1]);
}

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

int bfs(string start);
bool isSameColor(string state);

int main(){
  string str;
  while(1){
    getline(cin,str);
    if(str=="0") break;

    int ans;
    ans=bfs(str);

    if(ans==-1) cout << "NA" << endl;
    else cout << ans << endl;
  }
  return 0;
}

bool isSameColor(string state){
  for(int i=1; i<state.size();i++){
    if(state[i-1]!=state[i]) return false;
  }
  return true;
}

int bfs(string start){
  queue<string> Q;
  map<string,int> data;
  map<string,bool> visited;
  string u, v;

  Q.push(start);
  data[start] = 0;
  visited[start] = true;

  while(!Q.empty()){
    u=Q.front(), Q.pop();
    if(isSameColor(u)) return data[u];
    for(int i=1;i<u.size();i++){
      if(u[i]!=u[i-1]){
	char firo;
        if(u[i]=='r'){
	  if(u[i-1]=='b') firo='g';
	  else if(u[i-1]=='g') firo='b';
	}
	else if(u[i]=='b'){
	  if(u[i-1]=='g') firo='r';
	  else if(u[i-1]=='r') firo='g';
	}
	else if(u[i]=='g'){
	  if(u[i-1]=='r') firo='b';
	  else if(u[i-1]=='b') firo='r';
	}

        v=u;
        v[i]=v[i-1]=firo;
        if(!visited[v]){
	  visited[v]=true;
	  data[v]=data[u]+1;
	  Q.push(v);
	}
      }
    }
  }
  return -1;
}

Measured memory_bytes: 2752
import bisect
import sys
sys.setrecursionlimit(10**9)

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

tree = [[] for i in range(N)]
for i in range(N-1):
  u, v = map(int, input().split())
  tree[u-1].append(v-1); tree[v-1].append(u-1)


ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]
stack = []
def dfs(node, par):
  global ans
  global dp
  global stack
  children = tree[node]
  for child in children:
    if child == par:
      continue
    num = A[child]
    idx = bisect.bisect_left(dp, num)
    stack.append([idx, dp[idx]])
    dp[idx] = num
    ans[child] = bisect.bisect_left(dp, INF)
    dfs(child, node)
    # 巻き戻し
    idx, num = stack.pop()
    dp[idx] = num

dfs(0, -1)
print(*ans, sep='\n')

Measured memory_bytes: 241016
#include<cstdio>
#include<cstring>
const int MAXN = 100;
int x[MAXN + 5], y[MAXN + 5], N;
int G[MAXN + 5][MAXN + 5];
int vis[MAXN + 5], mat[MAXN + 5];
bool dfs(int x) {
	for(int i=1;i<=N;i++) {
		if( vis[i] ) continue;
		if( G[x][i] ) {
			vis[i] = true;
			if( mat[i] == 0 || dfs(mat[i]) ) {
				mat[i] = x;
				return true;
			}
		}
	}
	return false;
}
int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d%d", &x[i], &y[i]);
	for(int i=1;i<=N;i++) {
		int x1, y1;
		scanf("%d%d", &x1, &y1);
		for(int j=1;j<=N;j++)
			if( x1 > x[j] && y1 > y[j] )
				G[i][j] = true;
	}
	int ans = 0;
	for(int i=1;i<=N;i++) {
		memset(vis, false, sizeof vis);
		if( dfs(i) )
			ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
  ll n, a, b, e, f;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0) {
    cout << ((b - a) / 2);
  } else {
    if (a - 1 > n - b) {
      e = n - b + 1; //調整するまでの回数
      f = a + e; //調整時の位置
      //cout << "up:"<< e<< "," << f << endl;
      cout << ((n - f + 1) / 2) + e;
    } else {
      e = a;
      f = b - e;
      //cout << "down:"<<e<< "," << f << endl;
      cout << (f / 2) + e;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int ans;
ll a,b;
cin >> a >> b;
if(a>=1)ans=0;
else if(a==0||b==0)ans=2;
else if(a<=0&&b>=0)ans=2;
else{
    if((a+b)%2==0)ans=1;
    else ans = 0;
}
if(ans==0)cout<<"Positive"<<endl;
if(ans==1)cout<<"Negative"<<endl;
if(ans==2)cout<<"Zero"<<endl;
}
 


Measured memory_bytes: 764
z[257],o[256];main(N,S,A,C,s,a,c,r,i){for(;scanf("%d",&N),N;printf("%d %d %d\n",S,A,C)){
	for(i=1;i<=N;i++)scanf("%d",z+i);
	double H=999999999,h,n=N;
	for(s=0;s<16;s++)for(a=0;a<16;a++)for(c=0;c<16;c++){
		memset(o,0,sizeof(o));
		for(r=s,h=0,i=1;i<=N;i++)o[(z[i]+(r=(a*r+c)%256))%256]++;
		for(i=0;i<256;i++)if(o[i])h-=o[i]/n*log(o[i]/n);
		if(h+1e-9<H)H=h,S=s,A=a,C=c;
	}
}exit(0);}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
        
    public static void main(String[] args) {
    Scanner scan = new Scanner (System.in);
    
        int i; 
        int a;
        int b;
        
        for(i=0; i<7; i++){
        a = scan.nextInt();
        b = scan.nextInt();
        System.out.println(a-b);
        }
    }
}




Measured memory_bytes: 26180
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1 << 29);

int main() {
    int n, m;
    int C[MMAX + 1];
    int T[NMAX + 1];
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> C[i];
    }
    for (int i = 0; i <= NMAX; i++) T[i] = INFTY;
    T[0] = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j + C[i] <= n; j++) {
            T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
        }
    }
    cout << T[n] << endl;
    return 0;
}


Measured memory_bytes: 3276
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
int D, G;
int p[10], c[10], s[10];
bool used[10];
 
int all_search(int d, int g)
{
    if(g >= G)
        return 0;
 
    if(d == D) {
        int m;
        for(m = D-1; used[m] && m >= 0; m--)
            ;
        if(g + 100*(m+1)*(p[m]-1) < G)
            return INF;
 
        return (int)ceil((double)(G-g) / (100 * (m+1)));
    }
 
    int ans = all_search(d+1, g);
    used[d] = true;
    ans = min(all_search(d+1, g+s[d])+p[d], ans);
    used[d] = false;
 
    return ans;
}
 
int main()
{
    cin >> D >> G;
    rep(i, D) {
        cin >> p[i] >> c[i];
        s[i] = 100*(i+1)*p[i] + c[i];
        used[i] = false;
    }
 
    cout << all_search(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	ll n,d;
	cin >> n >> d;
	vector<ll>a(n),p(n),q(n+1);
	rep(i,n)cin >> a[i];
	p[0] = d;
	for(int i=1;i<n;i++){
		if(abs(p[i-1])>=abs(p[i-1]-a[i-1])){
			p[i] = abs(p[i-1]-a[i-1]); 
		}else{
			p[i] = p[i-1];
		}
	}
	ll c = 0;
	for(int i=n-1;i>=0;i--){
		if(a[i]<=2*c+1){
			c += a[i];
		}
		q[i] = c;
	}
	// rep(i,n){
	// 	cerr << p[i] << " " << q[i+1] << endl;
	// }
	vector<bool>flag(n);
	rep(i,n){
		if(p[i]<=q[i+1]){
			flag[i] = true;
		}
	}
	int qq;
	cin >> qq;
	rep(tt,qq){
		int x;
		cin >> x;
		x--;
		if(flag[x]){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll n = min(abs(x/d),k);
    ll m = k-n;
    ll ans;
    if(x <= 0) ans = x+n*d;
    else ans = x-n*d;
    if(m == 0){
        cout << abs(ans) << endl;
        return 0;
    }
    
    if(m%2 == 0) cout << abs(ans) << endl;
    else{
        if(ans <= 0) cout << abs(ans+d);
        else cout << abs(ans-d);
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
n = gets.to_i
restaurants = []
n.times do |index|
  restaurants.push(gets.split(" ").map(&:to_s))
  restaurants[index][1] = restaurants[index][1].to_i
end
sorted_restaurants = restaurants.sort {|a, b| (a[0] <=> b[0]).nonzero? || (b[1] <=> a[1])}
# puts sorted_restaurants
sorted_restaurants.each_with_index do |sorted, index|
  restaurants.each_with_index do |restaurant, index2|
    if sorted == restaurant
      puts index2 + 1
      break
    end
  end
end

Measured memory_bytes: 1916
#include<stdio.h>
#include<stdlib.h>
typedef struct{
    int attr;
    int time;
}Data;
int comp(const void *a,const void *b){
    Data c = *(Data *)a;
    Data d = *(Data *)b;
    if(c.time<d.time) return -1;
    else if(c.time>d.time) return 1;
    else{
        if(c.attr==0) return 1;
        else return -1;
    }
    return 0;
}
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        getchar();
        Data d[20000];
        for(int i=0;i<n;i++){
            char a[10],b[10];
            scanf("%s%s",a,b);
            //printf("%s %s\n",a,b);
            int h,m,s;
            sscanf(&a[0],"%d",&h); sscanf(&a[3],"%d",&m); sscanf(&a[6],"%d",&s);
            //printf("%d %d %d\n",h,m,s);
            d[i*2].attr=0; d[i*2].time=3600*h+60*m+s;
            sscanf(&b[0],"%d",&h); sscanf(&b[3],"%d",&m); sscanf(&b[6],"%d",&s);
            d[i*2+1].attr=1; d[i*2+1].time=3600*h+60*m+s;
        }
        qsort(d,2*n,sizeof(Data),comp);
        int ans=0; int max=0;
        for(int i=0;i<2*n;i++){
            if(d[i].attr==0){
                ans++;
                if(max<ans) max=ans;
            }else{
                ans--;
            }
        }
        printf("%d\n",max);
    }
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,Q; cin>>N>>Q;
    string S; cin>>S;
    vector<int> a(N,0);
    int sum=0;
    for(int i=0;i<N-1;i++){
        if(S[i]=='A'&&S[i+1]=='C'){
            sum++;
        }
        a[i]=sum;
    }
    for(int i=0;i<Q;i++){
        int l,r; cin>>l>>r;
        cout<<a[r-2]-a[l-2]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int A, B, C;
	vector<int>vec;
	cin >> A >> B >> C;
	vec.push_back(A);
	vec.push_back(B);
	vec.push_back(C);
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	if (vec.size() == 1) {
		cout << "No" << endl;
	}
	else if(vec.size() == 2){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def main():
    sx,sy,tx,ty = na()
    ret = ""
    for i in range(tx-sx):
        ret += "R"
    for i in range(ty-sy):
        ret += "U"
    for i in range(tx-sx):
        ret += "L"
    for i in range(ty-sy):
        ret += "D"
    ret += "L"
    for i in range(ty-sy+1):
        ret += "U"
    for i in range(tx-sx+1):
        ret += "R"
    ret += "D"
    ret += "R"
    for i in range(ty-sy+1): ret += "D"
    for i in range(tx-sx+1): ret += "L"
    ret += "U"
    print(ret)
    pass


if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int n, m;

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	return 1;
}

void init() {
}

long solve() {
	if (n>m) swap(n, m);
	if (m<2) return 1;
	if (n<2) return m-2;
	return long(n-2)*(m-2);
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

void solve()
{
	int A, B, C, D, P;
	cin >> A >> B >> C >> D >> P;
	int sumA = A * P;
	int sumB = B;
	if (P > C)
	{
		sumB += (P - C) * D;
	}
	cout << min(sumA, sumB) << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,k,d = map(int,readline().split())

x = abs(x)

#連続な二分探索
def func(mid): #ここが関数部分
    if x-d*mid < 0:
        return True
    else:
        return False

def binary_search(): #2分探索
    ok = 10**18
    ng = -1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    if abs(x-d*ok) <= abs(x-d*ng):
        return ok
    else:
        return ng

if x-k*d >= 0:
    print(x-k*d)
else:
    times = binary_search()
    ans = abs(x-d*times)
    if even(k-times):
        print(ans)
    else:
        print(min(abs(ans+d),abs(ans-d)))


Measured memory_bytes: 62040
import math
N = int(input())
X = list(map(int, input().split()))
P1, P2 = math.ceil(sum(X) / N), int(sum(X) / N)
work1, work2 = 0, 0
for x in X:
    work1 += (x - P1)**2
    work2 += (x - P2)**2
print(min(work1, work2))

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

int main() {
    string s;
    int ans = 0;
    cin >> s;
    if (s == "SUN") ans = 7;
    if (s == "MON") ans = 6;
    if (s == "TUE") ans = 5;
    if (s == "WED") ans = 4;
    if (s == "THU") ans = 3;
    if (s == "FRI") ans = 2;
    if (s == "SAT") ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class Main
  while true
    str = gets.split(" ")
    a = str[0].to_i
    op = str[1]
    b = str[2].to_i
    case op
    when "+"
      puts a + b
    when "-"
      puts a - b
    when "*"
      puts a * b
    when "/"
      puts a / b
    else
      break
    end
  end
end


Measured memory_bytes: 6876
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,a[200010],b[200010],c,d;
  cin >>n;
  fr(i,n){cin>>a[i];b[i]=a[i];}
  sort(a,a+n);
  c=a[n/2];
  d=a[(n/2)-1];
  fr(i,n){
    if(b[i]>=c) cout<<d<<endl;
    else cout<<c<<endl;
  }
}

Measured memory_bytes: 5376
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =  new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    if (n == m){
      System.out.println("Yes");
    }
    else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21716
using System;
using System.Linq;

class A
{
	static void Main()
	{
		var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int h = s[0], w = s[1], a = s[2], b = s[3];

		for (int i = 0; i < b; i++) Console.WriteLine(new string('0', a) + new string('1', w - a));
		for (int i = 0; i < h - b; i++) Console.WriteLine(new string('1', a) + new string('0', w - a));
	}
}


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

int main()
{
    ll n,k;
    ll a,b,ans;

    cin >> n >> k;

    a = n / k;
    b = n - a * k;
    if (b == 0)
        ans = b;
    else {
        b -= k;
        if (b < 0) b *= -1;
        if (n < b)
            b = n;
        if (b == 0)
            ans = 0;
        else
            ans = b;
    }

    std::cout << ans << endl;

    return(0);
}


Measured memory_bytes: 3604
#include<stdio.h>
int main(void)
{
	int cnt,n,i,m,temp,a[11];
	while(1){
		scanf("%lld",&n);
		if(n<0)break;
		m=n;
		cnt=0;
		while(1){
			temp=m/4;
			if(temp<1)break;
			a[cnt]=m%4;
			m=temp;
			cnt++;
		}
		printf("%d",m);
		for(i=cnt-1;i>=0;i--){
			printf("%d",a[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main(){
    int n,j,v;
    int s[100]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        if(i==0) cout<<s[i];
        else  cout<<" "<<s[i];
    }
    cout<<endl;
    for(int i=1;i<n;i++){
        v=s[i];
        j=i-1;
        while(j>=0&&s[j]>v){
            s[j+1]=s[j];
            j--;
        }
        s[j+1]=v;
    for(int x=0;x<n;x++){
        if(x==0) cout<<s[x];
        else  cout<<" "<<s[x];
    }
    cout<<endl;
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int a[1010], n, p;
ll f[5100];
int main(){
    cin >> n >> p;
    int sum = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    f[0] = 1;
    for(int i = 1; i <= n; ++i){
        for(int j = sum; j - a[i] >= 0; --j){
            f[j] += f[j - a[i]];
        }
    }
    ll ans = 0;
    for(int i = 0; i <= sum; ++i)if(i % 2 == p){
        ans += f[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define il inline
#define mk make_pair
#define f first
#define s second
#define N 300004
using namespace std;

int w,h,n,ans,t1,t2;
pair<int,int> p[N],st1[N],st2[N];
int t[4*N],add[4*N];

il char gc()
{
	static char now[1<<20],*S,*T;
	if (T==S)
	{
		T=(S=now)+fread(now,1,1<<20,stdin);
		if (T==S) return EOF;
	}
	return *S++;
}

il int read()
{
	int res=0;
	char c;
	while ((c=getchar())<'0'||c>'9');
	res=(c^48);
	while ((c=getchar())>='0'&&c<='9') res=(res<<3)+(res<<1)+(c^48);
	return res;
}

il void pushdown(int k)
{
	add[k<<1]+=add[k],add[k<<1|1]+=add[k];
	t[k<<1]+=add[k],t[k<<1|1]+=add[k];
	add[k]=0;
}

il void uptqj(int k,int l,int r,int x,int y,int v)
{
	if (l>=x&&r<=y){add[k]+=v,t[k]+=v;return;}
	int mid=(l+r)>>1;
	pushdown(k);
	if (x<=mid) uptqj(k<<1,l,mid,x,y,v);
	if (y>mid) uptqj(k<<1|1,mid+1,r,x,y,v);
	t[k]=max(t[k<<1],t[k<<1|1]);
}

il void solve()
{
    sort(p+1,p+n+1),t1=t2=0;
    int i,last;
    for (i=1; i<=4*n; i++) t[i]=add[i]=0;
    
    for (i=1; i<=n; i++)
	{
        if (p[i].s<=h/2)
		{
            for (last=i-1; t1&&st1[t1].s<p[i].s; last=st1[t1--].f-1)
            	uptqj(1,1,n,st1[t1].f,last,st1[t1].s-p[i].s);
            if (last!=i-1) st1[++t1]=mk(last+1,p[i].s);
        }
		else
		{
			for (last=i-1; t2&&st2[t2].s>p[i].s; last=st2[t2--].f-1)
            	uptqj(1,1,n,st2[t2].f,last,p[i].s-st2[t2].s);
            if (last!=i-1) st2[++t2]=mk(last+1,p[i].s);
        }
        st1[++t1]=mk(i,0),st2[++t2]=mk(i,h);
        uptqj(1,1,n,i,i,h-p[i].f),ans=max(ans,t[1]+p[i+1].f);
    }
}

int main()
{
    w=read(),h=read(),n=read();
    int i;
    for (i=1; i<=n; i++) p[i].f=read(),p[i].s=read();
    p[++n]=mk(0,0),p[++n]=mk(w,h);
    
    solve();
	for (i=1; i<=n; i++) swap(p[i].f,p[i].s);
    swap(w,h),solve(),printf("%d",2*ans);
    
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

map<int,vi> link;
map<int,int> add;
vi ans;
vector<bool> visited;

void dfs(int v, int a) {
    // printf("v:%d a:%d\n",v,a);
    a += add[v];
    ans[v] += a;
    visited[v] = true;
    for(auto c : link[v]) {
        if(visited[c]) continue;
        dfs(c,a);
    }
}

int main() {
    int n,m; cin >> n >> m;
    // vi L(n),R(n);
    int lm=1,rm=n;
    rep(i,m) { 
        int l,r;
        cin >> l >> r;
        lm = max(lm,l);
        rm = min(rm,r);
    }
    cout << max(rm-lm+1,0) << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

//const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

const Int INF = 1e+18;
int N;

int main(){
	cin>>N;
	vector<Int> a(3*N);
	REP(i,3*N){
		cin>>a[i];
	}
	//left
	vector<Int> left_max(3*N),right_min(3*N);
	do{
		multiset<Int,less<Int> > s;
		Int sum = 0;
		REP(i,3*N){
			if(s.size()<N){
				left_max[i] = -1;
				s.insert(a[i]);
				sum+=a[i];
			}else{
				assert(s.size()==N);
				left_max[i] = sum;
				s.insert(a[i]);
				sum+=a[i];
				sum-=*s.begin();
				s.erase(s.begin());
			}
		}
	}while(0);
	do{
		multiset<Int,greater<Int> > s;
		Int sum = 0;
		for(int i=3*N-1;i>=0;i--){
			/*
			dump(i);
			dump(a[i]);
			dump(sum);
			cerr<<"[";
			for(auto &t:s){
				cerr<<t<<" ";
			}
			cerr<<"]"<<endl;
			*/

			if(s.size()<N){
				right_min[i] = -1;
				s.insert(a[i]);
				sum+=a[i];
			}else{
				assert(s.size()==N);
				right_min[i] = sum;
//				dump(right_min[i]);
				s.insert(a[i]);
				sum+=a[i];
				sum-=*s.begin();
				s.erase(s.begin());
			}
		}
	}while(0);
	Int ans = -INF;
	for(int i=0;i<3*N;i++){
		//i and i-1
		if(left_max[i] == -1 or right_min[i-1] == -1)continue;
		ans = max(ans,left_max[i]-right_min[i-1]);
//		cerr<<i<<" "<<left_max[i]<<" "<<right_min[i-1]<<endl;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 11904
#include <iostream>
#include <queue>
#include <cmath>

using namespace std;
#define inf 101010
#define mp make_pair
typedef pair<int,int> pii;
typedef pair<pii,int> pp;

int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0,-1};
int w, h;
int g[31][31];
int dp[31][31][4];
int c[4];

bool r(int y, int x) {
    if (y >= 0 && y < h && x >= 0 && x < w) return true;
    else return false;
}

int main(void){
    while (cin>>w>>h && w) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> g[i][j];
                for (int k = 0; k < 4; k++) dp[i][j][k] = inf;
            }
        }
        for (int i = 0; i < 4; i++) cin >> c[i];
        
        dp[0][0][1] = 0;
        queue<pp> que;
        que.push(mp(mp(0,0), 1));
        
        while (!que.empty()) {
            pp p = que.front(); que.pop();
            int ty = p.first.first, tx = p.first.second, td = p.second;
            for (int i = 0; i < 4; i++) {
                int nd = (td+i)%4;
                int ny = ty + dy[nd], nx = tx + dx[nd];
                if (!r(ny,nx)) continue;
                
                int cost = c[i];
                if (g[ty][tx] == i) cost = 0;
                
                if (dp[ny][nx][nd] > dp[ty][tx][td]+cost) {
                    dp[ny][nx][nd] = dp[ty][tx][td]+cost;
                    que.push(mp(mp(ny,nx), nd));
                }
            }
        }
        int ans = inf;
        for (int i = 0; i < 4; i++) ans = min(ans, dp[h-1][w-1][i]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3028
#include <cstdio>
int n,m,u,v,ans=1,fa[200005],sz[200005];
int get(int x){return fa[x]==x?fa[x]:fa[x]=get(fa[x]);}
int max(int x,int y){return x>y?x:y;}
void merge(int x,int y){
x=get(x);
y=get(y);
if(x==y) return;
sz[x]+=sz[y];
ans=max(sz[x],ans);
fa[y]=x;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++) fa[i]=i,sz[i]=1;
while(m--){
scanf("%d%d",&u,&v);
merge(u,v);
}
printf("%d",ans);
}

Measured memory_bytes: 3288
s = gets.strip
t = gets.strip

sl = s.length
tl = t.length
sc = s.chars
tc = t.chars

max = 0
(sl - tl + 1).times do |i|
  a = 0
  tl.times do |j|
    a += 1 if sc[i + j] == tc[j]
  end
  max = a if max < a
end

puts tl - max


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  // 和がn、非負、0のものがk個以下の長さnの整数列の数を求める
  mint ans = 0;
  combination combn = combination(n);
  rep (i, min(k + 1, n + 1)) {
    ans += combn(n, i) * combn(n - 1, n - i - 1);
  }

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


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int n, k;
long long int func(int num, vector<int> a) {
  long long int ret = 0;
  int mx = a[0];
  int cnt = 1;
  for(int i=1; i<a.size(); i++){
    int tmp = 1 << i;
    if ((tmp & num) == tmp) {
      ret += max(0, mx-a[i]+1);
      mx = max(mx+1, a[i]+1);
      cnt++;
    }else {
      if (mx < a[i]) cnt++;
      mx = max(mx, a[i]);
    }
  }
  if(cnt < k) return 1e15;
  cerr << num << " " << ret << endl;
  return ret;
}

int main() {
  cin >> n >> k;
  vector<int> a(n);
  inputV(a, n);

  int num = 1 << n;
  long long int ans = 1e15;
  for(int i=0; i<num; i++){
    ans = min(ans, func(i, a));
  }
  cout << ans << endl;

  return 0;
}




//


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

W = input()

try:
   S = 0
   while True:
      T = input()
      if T == "END_OF_TEXT":
         break
      T = T.lower()
      T = T.split(" ") #空白で区切られた文字列を分割する
      #print(T)
      
      for i in range(len(T)):
         if W == T[i]:
            S += 1
      
except EOFError:
   pass

print(S)
   



Measured memory_bytes: 5568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

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

int main()
{   
    int N; cin >> N;
    int S; cin >> S;
    int A[3005];
    REP(i, N) cin >> A[i];
    //sort(A, A+N);

    long mod = 998244353;
    long dp1[3005], dp2[3005];
    REP(i, S) dp1[i+1] = 0l;

    REP(i, N){
        REP(j, S) dp2[j+1] = 0l;
        dp2[A[i]] += modpow(2l, (long)i, mod);
        REP(j, S) if(j+1+A[i]<=S) dp2[j+1+A[i]] = dp1[j+1];
        REP(j, S){
            dp2[j+1] += (2l*dp1[j+1]) % mod; dp2[j+1] %= mod;
        }
        REP(j, S) dp1[j+1] = dp2[j+1];
        //REP(j, S) cout << dp1[j+1] << " ";
        //cout << endl;
    }   
    cout << dp1[S] << endl;

    return 0;
}






Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
int main()
{
    ll h,n;
    cin>>h>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    ll dp[h+1];
    for(int i=0;i<h+1;i++)
    {
        dp[i]=inf;
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>0)
            {
                dp[i]=min(dp[i-a[j]]+b[j],dp[i]);
            }
            else
            {
                dp[i]=min(dp[i],b[j]);
            }
        }
    }
    cout<<dp[h]<<'\n';
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  swap(a, b);
  int m = n;
  vector<int> v(b);
  if (n < a) {
    cout << -1 << endl;
    return 0;
  }
  v[0] = a;
  n -= a;
  for (int i = 1; i < b; i++) {
    if (n < 1) {
      cout << -1 << endl;
      return 0;
    }
    v[i] = 1;
    n--;
  }
  for (int i = 1; i < b; i++) {
    if (n > 0) {
      if (n > a - 1) {
        v[i] = a;
        n -= a - 1;
      } else {
        v[i] += n;
        n = 0;
      }
    }
  }
  if (n > 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans(m);
  int c = 0;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < v[i]; j++) {
      ans[c + j] = c + v[i] - j;
    }
    c += v[i];
  }
  cout << ans[0];
  for (int i = 1; i < m; i++) {
    cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>

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

const int MAXN = 1e3+1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FAILNO {printf("NO\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

	int a,b;
	scanf("%d %d", &a, &b);
	
	int ans = a+b;
	ans = max(ans, a+a-1);
	ans = max(ans, b+b-1);
	printf("%d\n", ans);

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

ll ans1(ll x) {
    ll cnt = 0;
    for(ll i = 2; i * i <= x; i ++) {
        if(x % i != 0) {continue;}
        ll cpy = x;
        while(cpy % i == 0) {
            cpy /= i;
        }
        if(cpy % i == 1) {
            cnt ++;
        }
    }
    return cnt;
}

ll ans2(ll x) {
    ll cnt = -1;
    for(ll i = 1; i * i <= x; i ++) {
        if(x % i != 0) {continue;}
        cnt ++;
        if(i * i != x) {cnt ++;}
    }
    return cnt;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    cout << ans1(n) + ans2(n - 1) + 1 << endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>

int H, W, N, K;
int ans_map[50][50];

void check4s(int h, int w, int num) {
	int i, j;
	int p;
	int c = 0;
	
	if(num == 4) {
		for(i=0;i<2;i++) {
			for(j=0;j<2;j++) {
				ans_map[h+i][w+j] = 1;
			}
		}
		return;
	}
	
	printf("? %d %d %d %d\n", h, w, h, w);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h][w] = p;
	c += p;
	if(c == num) return;
	
	printf("? %d %d %d %d\n", h, w+1, h, w+1);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h][w+1] = p;
	c += p;
	if(c == num) return;
	
	printf("? %d %d %d %d\n", h+1, w, h+1, w);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h+1][w] = p;
	c += p;
	if(c == num) return;
	
	ans_map[h+1][w+1] = 1;
}

void check4h(int h, int w, int num) {
	int i;
	int p;
	int c = 0;
	
	if(num == 4) {
		for(i=0;i<4;i++) {
			ans_map[h][w+i] = 1;
		}
		return;
	}
	
	for(i=0;i<3;i++) {
		printf("? %d %d %d %d\n", h, w+i, h, w+i);
		fflush(stdout);
		scanf("%d", &p);
		ans_map[h][w+i] = p;
		c += p;
		if(c == num) return;
	}
	
	ans_map[h][w+3] = 1;
}

void check4v(int h, int w, int num) {
	int i;
	int p;
	int c = 0;
	
	if(num == 4) {
		for(i=0;i<4;i++) {
			ans_map[h+i][w] = 1;
		}
		return;
	}
	
	for(i=0;i<3;i++) {
		printf("? %d %d %d %d\n", h+i, w, h+i, w);
		fflush(stdout);
		scanf("%d", &p);
		ans_map[h+i][w] = p;
		c += p;
		if(c == num) return;
	}
	
	ans_map[h+3][w] = 1;
}

void check25(int h, int w, int num) {
	int i, j;
	int p;
	int c = 0;
	
	if(num == 25) {
		for(i=0;i<5;i++) {
			for(j=0;j<5;j++) {
				ans_map[h+i][w+j] = 1;
			}
		}
		return;
	}
	
	for(i=0;i<2;i++) {
		for(j=0;j<2;j++) {
			printf("? %d %d %d %d\n", h+i*2, w+j*2, h+i*2+1, w+j*2+1);
			fflush(stdout);
			scanf("%d", &p);
			if(p > 0) {
				c += p;
				check4s(h+i*2, w+j*2, p);
				if(c == num) return;
			}
		}
	}
	
	printf("? %d %d %d %d\n", h+4, w, h+4, w+3);
	fflush(stdout);
	scanf("%d", &p);
	if(p > 0) {
		c += p;
		check4h(h+4, w, p);
		if(c == num) return;
	}
	
	printf("? %d %d %d %d\n", h, w+4, h+3, w+4);
	fflush(stdout);
	scanf("%d", &p);
	if(p > 0) {
		c += p;
		check4v(h, w+4, p);
		if(c == num) return;
	}
	
	ans_map[h+4][w+4] = 1;
}

int main() {
	int i, j;
	int p;
	int c = 0;
	long ans = 0;
	long pow = 1;
	
	scanf("%d %d %d %d", &H, &W, &N, &K);
	
	for(i=0;i<10;i++) {
		for(j=0;j<10;j++) {
			if(c == N) break;
			printf("? %d %d %d %d\n", i*5, j*5, i*5+4, j*5+4);
			fflush(stdout);
			scanf("%d", &p);
			if(p > 0) {
				c += p;
				check25(i*5, j*5, p);
			}
		}
	}
	
	for(i=0;i<H;i++) {
		for(j=0;j<W;j++) {
			if(ans_map[i][j]) ans += pow;
			pow *= 2;
			ans %= K;
			pow %= K;
		}
	}
	
	printf("! %ld\n", ans);
	
	return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def main():
    n = ii()
    a = lmi()
    a.sort()
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            break
    else:
        print(ans)
        return
    print(-1)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 84720