akhauriyash/Code-Regression huggingface dataset:
x, n = map(int, input().split())
p_list = list(map(int, input().split()))


def num(x, p_list):
    if n == 0:
        return x
        
    p_num = x 
    m_num = x 
    p_list_max = max(p_list)
    p_list_min = min(p_list)

    while p_num <= p_list_max:
        if p_num not in p_list:
            break
        else:
            p_num += 1

    while m_num >= p_list_min:
        if m_num not in p_list:
            break
        else:
            m_num -= 1
    
    if abs(p_num - x) >= abs(x - m_num):
        return m_num
    else:
        return p_num

print(num(x, p_list))

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, ans = 0; cin >> n;
    vector<bool> exist(1000005, false);
    bool dup = false;
    ll number = n;
    rep(i, n) {
        ll a; cin >> a;
        if(exist[a] && a != 1) {
            dup = true;
            number--;
        }
        else {
            exist[a] = true;
        }
    }
    n = number;

    for(ll i = 2; i <= 1000000; i++) {
        ll num = 0;
        for(ll j = i; j <= 1000000; j += i) {
            if(exist[j]) num++;
        }
        if(num == n) {
            cout << "not coprime" << endl;
            return 0;
        }
        else if(ans < num) ans = num;
    }

    if(dup) cout << "setwise coprime" << endl;
    else if(ans <= 1) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
    
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define N 505
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,k,a[N],sum;
int t,ans=1;
long long f[N],g[N];
bool cmp(int a,int b) {
	return a%t<b%t;
}
void solve(int x) {
	t=x;
	sort(a+1,a+1+n,cmp);
	for(int i=1; i<=n; i++)f[i]=a[i]%x+f[i-1];
	for(int i=n; i>=1; i--)g[i]=x-a[i]%x+g[i+1];
	for(int i=0; i<=n; i++)if(max(f[i],g[i+1])<=k)return ans=max(ans,x),void();
}
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++)scanf("%d",&a[i]),sum+=a[i];
	for(int i=1; 1ll*i*i<=sum; i++) {
		if(sum%i)continue;
		solve(i),solve(sum/i);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
# solution

nim, mike = map(int, input().split())

P = []

C = []

ans = 10 ** 9

for i in range(nim):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)

for i in range(2 ** nim):
    a = 0
    b = 0
    for j in range(nim):
        if (i >> j) & 1 :
            a += 100 * P[j] * (j + 1) + C[j]
            b += P[j]
    for k in range(nim - 1, -1, -1):
        if (i >> k) & 1:
            continue
        if a >= mike:
            break
        for l in range(P[k] + 1):
            a += 100 * (k + 1)
            b += 1
            if a >= mike:
                break
    ans = min(ans, b)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,n;cin >>a  >>b  >> n;
    ll d=min(n,b-1);
    
    cout << (((a*d)/b)*b)/b;
    }

Measured memory_bytes: 3580
N=int(input())
P=list(map(int,input().split()))

ans_ls=[0]
ans=1

for i  in range(1,N):
    if P[ans_ls[-1]]>P[i]:
        ans+=1
        ans_ls.append(i)
    
    '''
    if P[i-1]<P[i]:
        pass
    
    elif P[i-1]>P[i] and ans[-1]==(i-1):
        ans.append(i)
        
    elif ans[-1]==
    '''
    
print(ans)

Measured memory_bytes: 24744
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
    int n;
    vector<int> primes;
    bool isprime[1 << 15];

    memset(isprime, true, sizeof(isprime));
    for(int i=2;i<(1<<15);++i){
        if(isprime[i]){
            primes.push_back(i);
            for(int j=2;i*j<(1 << 15);++j){
                isprime[i*j] = false;
            }
        }
    }
    int m = primes.size();
    vector<int> sums;
    for(int i=0;i<m;++i){
        for(int j=i;j<m;++j){
            sums.push_back(primes[i]+primes[j]);
        }
    }
    sort(sums.begin(), sums.end());
    while(cin >> n && n){
        cout << upper_bound(sums.begin(), sums.end(), n) - lower_bound(sums.begin(), sums.end(), n) << endl;
    }
}

Measured memory_bytes: 29000
#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 mp       make_pair
#define pb       push_back
#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 dp[100][100] = {{0}};
std::vector<int> r;
std::vector<int> c;
int N;

int dfs(int i, int j) {
	if (dp[i][j] != 0) {return dp[i][j];}
	if (j == i) {
		return 0;
	}
	if (j - i == 1) {
		return dp[i][j] = r[i] * c[i] * c[j];
	}
	int ans = 1000000000;
	for (int k = i; k < j; ++k) {
		ans = std::min(ans, dfs(i, k) + dfs(k + 1, j) + r[i] * c[k] * c[j]);
	}
	return dp[i][j] = ans;
}

int main(int argc, char const *argv[]) {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		r.push_back(a);
		c.push_back(b);
	}
	int ans = dfs(0, N - 1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1256
/*input
3
5
5
1
6
3
1
4
1
5
9
5
6
8
1
2
3
*/
#include <bits/stdc++.h>
#define db(x) cout<<#x<<"="<<(x)<<" "
#define el cout<<endl
using namespace std;
const int MXN = 1e6 + 10;

int M, N;
long long ans;
int a[MXN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> N; // n = N;
    for (int i = 1; i <= N; ++i)
    {
        cin >> a[i];
    }
    sort(a + 1, a + N + 1);
    int m = (N + 1) / 2;
    for (int i = 1; i <= N; ++i)
    {
        if (i * 2 <= N + 1)
            ans -= a[i] * 2;
        if (i * 2 >= N + 1)
            ans += a[i] * 2;
    }
    //db(ans) ,el;
    if (N & 1)
    {
        ans -= min(a[m] - a[m - 1], a[m + 1] - a[m]);
    } else {
        ans -= a[m + 1] - a[m];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;

int main()
{
    int k=0,n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(x%2==1)
        {
            k=1;
        }
    }
    if(k==0)
    {
        cout<<"second"<<endl;
    }
    else
    {
        cout<<"first"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cctype>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
int abs(int x){return x>0?x:-x;}
int main()
{
	int a=read(a),b=read(b);
	if(a<=0&&b>=0)puts("Zero");
	else if(a<0&&b<0&&abs(b-a)%2==0)puts("Negative");
	else puts("Positive");
	return 0;
}


Measured memory_bytes: 128
st=input().split()
N=int(st[0]);C=int(st[1])
s=[0 for i in range(N)];t=[0 for i in range(N)];c=[0 for i in range(N)]
MT=0
for i in range(N):
    st=input().split()
    s[i]=int(st[0])-1;t[i]=int(st[1])-1;c[i]=int(st[2])-1
for i in range(N):
    if t[i]>MT:
        MT=t[i]
CBC=[[0 for i in range(MT+1)] for i in range(C)]
for i in range(N):
    for j in range(s[i]-1,t[i]):
        CBC[c[i]][j]=1
MaxC=0
for i in range(MT+1):
    NowC=0
    for j in range(C):
        if CBC[j][i]==1:
            NowC+=1
    if NowC>MaxC:
        MaxC=NowC
print(MaxC)

Measured memory_bytes: 35376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    int n, k;
    cin >> n >> k;
    if (n == k) {
        cout << 1 << endl;
    } else {
        cout << (n - k - 1) / (k - 1) + 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int x,a;
	cin>>x;
	a=x/100;a=a*100+a*10+a;
	if(a>=x) cout<<a;
	else cout<<a+111;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ui unsigned int
#define ll __int128
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define PII std::pair<int,int>
#define PLL std::pair<ll,ll>
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=500+10,MAXM=1000000+10;
int n,vis[MAXM],prime[MAXM],cnt,p;
ll G[MAXN][MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void init()
{
	memset(vis,1,sizeof(vis));
	vis[0]=vis[1]=0;
	REP(i,2,MAXM-1)
	{
		if(vis[i])prime[++cnt]=i;
		for(register int j=1;j<=cnt&&i*prime[j]<MAXM;++j)
		{
			vis[i*prime[j]]=0;
			if(i%prime[j]==0)break;
		}
	}
}
inline bool check(int x,int y)
{
	if(G[x][y]%G[x-1][y]!=1)return false;
	if(G[x][y]%G[x+1][y]!=1)return false;
	if(G[x][y]%G[x][y-1]!=1)return false;
	if(G[x][y]%G[x][y+1]!=1)return false;
	return true;
}
int main()
{
	read(n);init();int x,y;
	REP(i,0,n+1)REP(j,0,n+1)G[i][j]=1;
	REP(i,0,n+1)if(i&1)
	{
		x=0,y=i,++p;
		while(x<=n+1&&y>=0)G[x][y]*=prime[p],x++,y--;
	}
	REP(i,1,n+1)if(i%2==n%2)
	{
		x=n+1,y=i,++p;
		while(x>=0&&y<=n+1)G[x][y]*=prime[p],x--,y++;
	}
	REP(i,0,n+1)if(i%2==n%2)
	{
		x=n+1,y=i,++p;
		while(x>=0&&y>=0)G[x][y]*=prime[p],x--,y--;
	}
	REP(i,1,n+1)if(i&1)
	{
		x=0,y=i,++p;
		while(x<=n+1&&y<=n+1)G[x][y]*=prime[p],x++,y++;
	}
	REP(i,1,n)REP(j,1,n)if((i+j)%2==0)
	{
		G[i][j]=G[i-1][j]*G[i+1][j]+1,assert(check(i,j));
	}
	REP(i,1,n)
	{
		REP(j,1,n)assert(G[i][j]<=1e15),write(G[i][j],' ');puts("");
	}
	return 0;
}


Measured memory_bytes: 14976
import statistics

n = int(input())
A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
am = statistics.median(A)
bm = statistics.median(B)
#print(am, bm)
if n % 2 == 0:
    print(int(bm * 2 - am * 2 + 1))
else:
    print(int(bm - am + 1))


Measured memory_bytes: 28948
import java.util.Scanner;

public class Main {
	
	static char [][]grid;
	static int [][]ans;

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		
		int k = Integer.parseInt(sc.next());
		
		grid = new char[h][w];
		ans = new int [h][w];
		
		for(int i = 0 ;i < h ; i++) {
			String s = sc.next();
			for(int j = 0 ; j < w ; j++) {
				grid[i][j] = s.charAt(j);
			}
		}
		
		int firstH = -1;
		boolean first = false;
		int id = 1;
		
		for(int y = 0 ; y < h ; y++) {
			boolean exsitX = false;
			
			for(int x = 0 ; x < w ; x++) {
				if(grid[y][x] == '#') {
					if(firstH == -1) {
					firstH = y;
					}
					first = true;
					exsitX = true;
				}
			}
			if(exsitX) {
				int lastX = -1;
				for(int x = 0 ; x < w ; x++) {
					ans[y][x] = id;
					if(grid[y][x] == '#') {
						id++;
						lastX = x;
					}
				}
				for(int x = lastX + 1 ; x < w ; x++) {
					ans[y][x]--;
				}
			}
			else {
				if(first) {
					for(int x = 0 ; x < w ; x++) {
					ans[y][x] = ans[y-1][x];
				}
			}	
		}
	}	
			for(int i = firstH -1 ; i >= 0 ; i--) {
				for(int j = 0 ; j < w ; j++) {
					ans[i][j] = ans[i+1][j];
				}
			}
			
			for(int i = 0 ; i < h ; i++) {
				for(int j = 0 ; j < w ; j++) {
					System.out.print(ans[i][j]+" ");
				}
				System.out.println();
			}
		
			
			}
		
		


	}




Measured memory_bytes: 47672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	int n;
	cin >> n;
	cout << 32 * n << endl;
}



Measured memory_bytes: 3124
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {

  string s;
  cin >> s;
  char b = 'B', w = 'W';
  int n = s.length();
  int cnt=0;
  rep(i,1,n){
      if(s[i]!=s[i-1])cnt++;
  }
  cout<<cnt;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    string s1 = s.substr(0, (n-1)/2);
    string s2 = s.substr((n-1)/2+1, n);
    bool ok = true;
    rep(i, s1.size()/2) {
        if (s1[i] != s[n-i-1]) {
            ok = false;
        }
    }
    if (ok && s1 == s2) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	if (N == 0){
		if (A[0] == 1){
			cout << 1 << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}

	//累積和
	vector <ll> S(N);
	S[N-1] = A[N];
	for (int ii = N-2; ii >= 0; --ii){
		S[ii] += S[ii+1] + A[ii+1];
	}

	bool ok = true;
	if (A[0] != 0){
		ok = false;
	}

	ll ans = 1;
	ll prev = 1;
	if (ok && (N > 0)){
		for (int ii = 1; ii <= N; ++ii){
			ll tmp = 2 * prev;
			if (tmp < A[ii]){
				ok = false;
				break;
			} else {
				if (ii < N){
					if (S[ii] + A[ii] < tmp){
						tmp = S[ii] + A[ii];
					}
					ans += tmp;
					prev = tmp - A[ii];
				} else {
					ans += A[ii];
				}
			}
		}		
	}
	
	if (ok){
		cout << ans << "\n";
	} else {
		cout << -1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 4840
L,R = map(int,input().split())

if R - L >= 2018:
    print(0)
else:
    min = 2020
    for i in range(L,R):
        for j in range(i+1,R+1):
            mod = i * j % 2019
            if mod <= min:
                min = mod
    print(min)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
p, n = [], []

for Ai in A:
    if Ai>=0:
        p.append(Ai)
    else:
        n.append(Ai)

if len(n)==N and K%2==1:
    n.sort(reverse=True)
    ans = 1
    
    for ni in n[:K]:
        ans *= ni
        ans %= MOD
    
    print(ans)
    exit()

if K==N and len(n)%2==1:
    ans = 1
    
    for Ai in A:
        ans *= Ai
        ans %= MOD
    
    print(ans)
    exit()

p.sort(reverse=True)
n.sort()
l = []

if K%2==1:
    ans = p[0]
    p = p[1:]
else:
    ans = 1
    
for i in range(len(p)//2):
    l.append(p[2*i]*p[2*i+1])
    
for i in range(len(n)//2):
    l.append(n[2*i]*n[2*i+1])
    
l.sort(reverse=True)
    
for li in l[:K//2]:
    ans *= li
    ans %= MOD
    
print(ans)


Measured memory_bytes: 115320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n, k;
    cin >> n >> k;
    ll ans = LINF;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    rep(i, n - k + 1) {
        chmin(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string s; cin >> s;
    int N = s.size();
    bool f = true;
    if(s[0] == '0' || s[N - 1] == '1') f = false;
    FOR(n, 1, N) if(s[n - 1] != s[N - n - 1]) f = false;
    if(!f){
        cout << -1;
        return 0;
    }

    int v = N;
    vector<Pii> ans(N - 1);
    int i = 0;
    IFOR(n, 1, N){
        ans[i] = Pii(v, n);
        if(s[n - 1] == '1') v = n;
        i++;
    }

    REP(i, N - 1) cout << ans[i].first << " " << ans[i].second << endl;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

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

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

    int coin = max(A, B);

    if(coin == A) {
        A--;
        } else {
            B--;
        }
    coin += max(A, B);
    
    cout << coin << endl;

    return 0;
}

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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		long n=in.nextLong();
		long a=in.nextLong();
		long b=in.nextLong();
		long q=a+b;
		long m=0;
		if(n%q<=a)
		{
			m=n%q;
		}
		else
		{
			m=a;
		}
		System.out.println((n/q)*a+m);
	}
}
	

Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
import bisect
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


ans = [-1] * (2*10**5+1)


@mt
def slv(N, A, UV):
    A.insert(0, -1)
    g = [list() for _ in range(0, N+1)]
    for u, v in UV:
        g[u].append(v)
        g[v].append(u)

    def dfs(u, p, dp):
        global ans

        for v in g[u]:
            if v == p:
                continue

            i = bisect.bisect_left(dp, A[v])
            if len(dp) <= i:
                dp.append(A[v])
                ans[v] = len(dp)
                dfs(v, u, dp)
                dp.pop()
            else:
                b = dp[i]
                dp[i] = A[v]
                ans[v] = len(dp)
                dfs(v, u, dp)
                dp[i] = b
    dp = [A[1]]
    dfs(1, 0, dp)

    ans[1] = 1
    for i in range(1, N+1):
        print(ans[i])

    # return ans[:N]


def main():
    N = read_int()
    A = read_int_n()
    UV = [read_int_n() for _ in range(N-1)]
    (slv(N, A, UV))


if __name__ == '__main__':
    main()


Measured memory_bytes: 551636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int n,k,sum=1;
	while(cin>>n>>k)
	{
		int i;
		for(i=0;i<n;i++)
		{
			sum=min(sum*2,sum+k);
		}
		cout<<sum<<endl;
		sum=1;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main(){
  int n;
  cin >> n;
  int dp[10001];
  memset(dp,0,sizeof(dp));
  dp[0] = 1;
  int s;
  for(int i = 0;i < n;i++){
    cin >> s;
    for(int j = 10000;j >= 0;j--){
      if(dp[j]) dp[j+s] = 1;
    }
  }
  for(int i = 10000;i >= 0;i--){
    if(dp[i] && i%10 != 0){
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    cout << 2 * r * M_PI << endl;
    return 0;
}



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

#define MOD 1000000007

long long Calc(long long a, long long b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		long long c = Calc(a, b / 2);
		return (c * c) % MOD;
	}
	return (a * Calc(a, b - 1)) % MOD;
}


int main() {
	long long N, M, ans = 1;
	map<long long, long long> mp;
	cin >> N >> M;
	for (long long i = 2; i <= M; i++) {
		if (M % i == 0) {
			mp[i]++;
			M /= i;
			i = 1;
		}
		if (M == 1) break;
	}
	for (auto it = mp.begin(); it != mp.end(); it++) {
		long long x = it->second;
		for (long long i = N; i < N + x; i++) {
			ans *= i;
			ans = ans % MOD;
		}
		for (long long i = 1; i <= x; i++) {
			ans *= Calc(i, MOD - 2);
			ans = ans % MOD;
		}
	}
	cout << ans;
}

Measured memory_bytes: 384
import java.math.BigInteger;
import java.util.*;
import java.io.*;
import java.text.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = (long) 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long sub(long a, long b) {
        return ((a % mod - b % mod) + mod) % mod;
    }

    static int maxn = 1000005;

    static int pow(int n) {
        return (int) (Math.log10(n) / Math.log10(2));
    }

    static long modpow(long x, long y) {
        long res = 1l;
        x %= mod;
        while (y > 0) {
            if (y % 2 != 0)
                res = pro(res, x);
            x = pro(x, x);
            y /= 2;
        }
        return res;
    }

    static class pair {
        String a;
        int b;

        pair(String x, int y) {
            a = x;
            b = y;
        }
    }

    static long modInverse(long n) {
        BigInteger n1 = new BigInteger(Long.toString(n));
        String s = (n1.modInverse(new BigInteger(Long.toString(mod)))).toString();
        return Long.parseLong(s);
    }

    static boolean v[] = new boolean[1000005];

    static void seive() {
        v[1] = true;
        for (int i = 2; i < 1000005; i++) {
            if (!v[i]) {
                for (int j = 2 * i; j < 1000005; j += i)
                    v[j] = true;
            }
        }
    }

    static boolean isprime(long n) {
        if (n == 1)
            return false;
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static DecimalFormat df=new DecimalFormat("0.000000000000000000000");
    static void solve() {
        int a = ni();
        int b = ni();
        int h = ni();
        int m = ni();
        double alpha = (30.0 * h) - ((11.0 * m) / 2.0);
//        out.println(Math.cos(Math.toRadians(270)));
        double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(alpha)));
        out.println(df.format(ans));
    }
}



Measured memory_bytes: 36404
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll n,cnt = 0;
	cin >> n;
	ll a[n],b[n];
	
	rep(i,0,n){
		cin >> a[i] >> b[i];
	}
	
	rep(i,0,n){
		a[n-i-1] += cnt;
		if(a[n-i-1] % b[n-i-1])cnt += b[n-i-1] - (a[n-i-1] % b[n-i-1]);
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int N, C; cin >> N >> C;
	vector<vector<int>> cnt(C, vector<int>(100002, 0));
	for (int i = 0; i < N; i++) {
		int s, t, c; cin >> s >> t >> c;
		c--;
		cnt[c][s] += 1;
		cnt[c][t] -= 1;
	}
	for (int i = 1; i <= 100000; i++) {
		for (int t = 0; t < C; t++) {
			cnt[t][i] += cnt[t][i - 1];
		}
	}
	for (int i = 100000; i >= 1; i--) {
		for (int t = 0; t < C; t++) {
			if (cnt[t][i - 1] >= 1) cnt[t][i] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i <= 100000; i++) {
		int s = 0;
		for (int t = 0; t < C; t++) {
			s += cnt[t][i];
		}
		ans = max(ans, s);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1 << 18;
const ll INF = 1LL << 55;

template <class T>
struct fenwick_tree{
	int n;
	std::vector<T> x;
	fenwick_tree(int n_ = 0) : n(n_), x(n + 1, 0){}
	int size() const{ return n; }
	T sum(int r) const{
		T S = 0;
		for(r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
		return S;
	}
	T sum(int l, int r) const{ return sum(r) - sum(l); }
	void add(int k, const T &a){
		for(; k < n; k |= k + 1) x[k] += a;
	}
	void set(int k, const T &a){ add(k, a - sum(k, k + 1)); }
};

template <class T>
struct fenwick_tree_range{
	fenwick_tree<T> a, b;
	fenwick_tree_range(int n = 0) : a(n), b(n){}
	int size() const{ return a.size(); }
	T sum(int r) const{ return a.sum(r) + b.sum(r) * r; }
	T sum(int l, int r) const{ return sum(r) - sum(l); }
	void add(int r, const T &x){
		a.add(r, x * r);
		b.add(r, -x);
	}
	void add(int l, int r, const T &x){
		add(l, -x);
		add(r, x);
	}
};

fenwick_tree_range<ll> bit(200010);

deque<int> p[26];

int cnt[26];
int N;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;
	N = s.size();

	for(int i = 0; i < N; i++){
		int c = s[i] - 'a';
		p[c].push_back(i);
		cnt[c]++;
	}

	string sl;
	int Lpos = 0, Rpos = N - 1;
	ll ans = 0;
	for(int i = 0; i < N / 2; i++){
		int usec;
		int l, r;
		int sum = 1e9;
		for(int c = 0; c < 26; c++){
			if(cnt[c] <= 1) continue;
			int L = p[c].front();
			L += bit.sum(L, L + 1);
			int R = p[c].back();
			R += bit.sum(R, R + 1);

			int cost = abs(L - Lpos) + abs(R - Rpos);
			if(sum > cost){
				sum = cost;
				l = L;
				r = R;
				usec = c;
			}
		}

		if(sum == 1e9){
			cout << -1 << endl;
			return 0;
		}

		sl += char('a' + usec);
		cnt[usec] -= 2;
		bit.add(0, p[usec].front(), 1);
		bit.add(p[usec].back(), N, -1);
		p[usec].pop_front();
		p[usec].pop_back();
		Lpos++;
		Rpos--;

		ans += sum;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4500
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a;
	int i;
	int n;

	a = 100000;

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		a *= 1.05;
		if (0 != a % 1000){
			a /= 1000;
			a += 1;
			a *= 1000;
		}
	}

	printf("%d\n", a);


	return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int INF = 10e8;
const int maxN = 300010;
const int maxM = 100010;
 
char c[maxN];
int w;
int main()
{
	scanf("%s",c+1);
	scanf("%d",&w);
	int len = strlen(c+1);
	int pos = 0;
	while((1+pos*w)<=len)
	{
		printf("%c",c[1+pos*w]);
		pos++;
	}
	printf("\n");
	return 0;
}  

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

public class Main {
    
    private static PrintWriter out;
    
    private static <T> void mprintln(T ... ar){
        for(T i: ar) out.print(i + " ");
        out.println();
    }
    
    public static void main(String[] args) throws FileNotFoundException{

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }
    
    private static void getAns(MyScanner sc){
        int n = sc.ni(), k = sc.ni();
        
        double ans = 0;
        
        for(int i = 1; i <= n; i++){
            double cur = 1.0 / n;
            int score = i;
            while(score < k){
                score <<= 1;
                cur /= 2.0;
            }
            ans += cur;
        }
        
        out.printf("%.10f\n", ans);
    }
    
    static class MyScanner{
        BufferedReader br;
	StringTokenizer st;

	MyScanner(FileReader fileReader){
            br = new BufferedReader(fileReader);
	}

	MyScanner(){
            br = new BufferedReader(new InputStreamReader(System.in));
	}

	String nn(){
            while(st == null || !st.hasMoreElements()){
		try{
                    st = new StringTokenizer(br.readLine());
		}catch(IOException e){
                    e.printStackTrace();
		}
            }
            return st.nextToken();
	}
        
        String nextLine(){
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

	char nc(){
            return nn().charAt(0);
	}

	int ni(){
            return Integer.parseInt(nn());
	}

	long nl(){
            return Long.parseLong(nn());
	}

	double nd(){
            return Double.parseDouble(nn());
	}

	int[] niArr0(int n){
            int[] ar = new int[n];
            for(int i = 0; i < n; i++) ar[i] = ni();
            return ar;
	}

        int[] niArr1(int n){
            int[] ar = new int[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = ni();
            return ar;
	}

        long[] nlArr0(int n){
            long[] ar = new long[n];
            for(int i = 0; i < n; i++) ar[i] = nl();
            return ar;
        }

        long[] nlArr1(int n){
            long[] ar = new long[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = nl();
            return ar;
        }
    }
}

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

int N;
string s;

void output(vector<bool> sw){
    string ans="";
    for(int i=1; i<=N; i++){
        if(sw[i]) ans += "S";
        else ans += "W";
    }
    cout << ans << endl;
}

bool judge(bool tn, bool t1){
    vector<bool> sw(N+2);
    sw[0] = tn;  sw[N] = tn;
    sw[1] = t1;  sw[N+1] = t1;
    for(int i=2; i<=N+1; i++){
        if(sw[i-1] && s[i-1]=='o') sw[i] = sw[i-2];
        if(sw[i-1] && s[i-1]=='x') sw[i] = !sw[i-2];
        if(!sw[i-1] && s[i-1]=='o') sw[i] = !sw[i-2];
        if(!sw[i-1] && s[i-1]=='x') sw[i] = sw[i-2];
    }

    if(sw[N]==tn && sw[N+1]==t1){
        output(sw);
        return true;
    }

    return false;
}

int main(){
    cin >> N >> s;
    s = "#" + s;
    if(judge(true,true) || judge(true,false) || judge(false,true) || judge(false,false)){
        return 0;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 636
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#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'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
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); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}
 
const int N = 2e5 + 5;
ll dp[N][2];
 
void solve()
{
	int n;
	cin >> n;
	v64 arr(n + 1, 0);
	for (int i = 1; i < n + 1; i++)
		cin >> arr[i];
	memset(dp, 0, sizeof(dp));
	dp[2][1] = arr[2];
	dp[2][0] = arr[1];
	for (int i = 3; i < n + 1; i++)
	{
		if (i & 1)
		{
			ll temp = max({dp[i - 3][1], dp[i - 3][0], dp[i - 2][1], dp[i - 2][0]});
			dp[i][1] = arr[i] + temp;
			dp[i][0] = max({arr[i - 1] + dp[i - 2][0], arr[i - 1] + dp[i - 3][1], arr[i - 1] + dp[i - 3][0], arr[i - 2] + dp[i - 3][0]});
		}
		else
		{
			dp[i][1] = arr[i] + max({dp[i - 2][1], dp[i - 2][0], dp[i - 1][0]});
			dp[i][0] = arr[i - 1] + dp[i - 2][0];
		}
	}
	cout << max(dp[n][1], dp[n][0]) << ln;
	return;
}
 
int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}

Measured memory_bytes: 7908
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N, M;	cin >> N >> M;
	vector<string> A(N);
	vector<string> B(M);
	int sameNUM;

	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i <= N - M; ++i) {
		for (int j = 0; j <= N - M; ++j) {
			sameNUM = 0;
			for (int k = 0; k < M; ++k) {
				for (int l = 0; l < M; ++l) {
					if (A[i + k][j + l] == B[k][l]) {
						sameNUM++;
					}
				}
			}
			if (sameNUM == M*M) {
				cout << "Yes" << endl;
				cin >> N;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	cin >> N;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
using namespace std;
using ll = long long int;

pair<int, int> calc_first(ll &N) {
    int d, A;
    for(d = 2; d < 60; d++) {
        for(A = 1; A <= 9; A++) {
            ll vari = 9 * ( (1LL << (d - 1)) - 1 );
            if(vari >= N) return make_pair(d, A);

            // N > 0
            N -= vari;
        }
    }
    return make_pair(-1, -1);
}

void calc_num(ll N, int A, int d, string &ans) {
    for(int B=0; B<=9; B++) {
        ll vari;
        if(A == B) {
            vari = 9 * ( (1LL << (d - 2)) - 1 );
            if(vari >= N) {
                ans += (char)('0' + A);
                calc_num(N, A, d-1, ans);
                return;
            }
            N -= vari;
        }
        else {
            vari = 1LL << (d - 2);
            if(vari >= N) {
                ans += (char)('0' + B);

                N--;
                int z = min(A, B), o = max(A, B);

                for(int i=d-3; i>=0; i--) {
                    int num = (N >> i & 1) ? o : z;
                    ans += (char)('0' + num);
                }
                return;
            }
            N -= vari;
        }
    }
}

void solve(ll N) {
    int d, A; tie(d, A) = calc_first(N);

    // printf("d = %d, A = %d, N = %lld\n", d, A, N);
    string ans(1, (char)('0' + A));
    calc_num(N, A, d, ans);

    printf("%s\n", ans.c_str());
}

int main() {
    ll N;
    while(1) {
        scanf("%lld", &N);
        if(N == 0) break;
        else solve(N);
    }
}


Measured memory_bytes: 2704
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::*;

use std::string::*;

struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }

    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }

    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let s: String = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();

        return s.parse::<T>().ok().unwrap();
    }

    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn prime_factorization(n: i64) -> HashMap<i64, i64> {
    let mut n = n;
    let mut res = HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            let count = res.entry(i).or_insert(0);
            *count += 1;
        }
        i += 1;
    }

    if n > 1 {
        res.insert(n, 1);
    }

    return res;
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n = sc.read();
    let m = 100000000000000003i128;
    let mut a: Vec<i128> = sc.vec(n);
    let mut ans = 1;
    if a.contains(&0) {
        println!("{}", 0);
    } else {
        for aa in a {
            ans *= aa;
            if ans > 1e18 as i128 {
                println!("-1");
                return;
            }
        }
        println!("{}", ans);
    }
}

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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll power(ll a,ll b,ll m){
	ll x=1%m; a%=m;
	while(b){
		if((1&b)) x = x * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return x;
}

char mat[105][105];

void build(int a,int b){
	for(int i=0;i<100;i++) mat[i][100]='\0';
	// by default paint entire with small one
	char small = (a<=b)?'.':'#';
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++) mat[i][j]=small;
	}
	char bada = (a>b)?'.':'#';
	int mx = max(a,b);
	int mn = min(a,b) - 1;
	for(int i=0;i+2<100;i+=4){
		for(int j=0;j+2<100;j+=4){
			if(!mx) break;
			mx--;
			for(int ii=i;ii<i+3;ii++){
				for(int jj=j;jj<j+3;jj++) mat[ii][jj]=bada;
			}
			if(mn){
				mn--;
				mat[i+1][j+1]=small;
			}
		}
	}
}

int main(){
	int a,b;
	sd(a);sd(b);
	build(a,b);
	printf("100 100\n");
	for(int i=0;i<100;i++){
		printf("%s\n",mat[i]);
	}
}

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

int main(){
	string s;
	int i,j;
	
	cin >> s;
	i = 0;
	j = s.size()-1;
	while(s[i]!='A') i++;
	while(s[j]!='Z') j--;
	cout << j - i + 1;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    1000100
#define   pb    push_back
#define   py    printf("Yes\n")
#define   pn    printf("No\n")
#define   sc(a) scanf("%lld",&a)
#define   p    1000000007
const  double pi=acos(-1);

using namespace std;


ll bigmod(ll x,ll y)
{
    ll res=1;
    x=x%p;

    while(y>0)
    {
        if(y&1)
        {
            res=(res*x)%p;

        }
        y=y>>1;
        x=(x*x)%p;
    }

    return res;

}

ll find_ncr(ll n, ll r)
{
    ll m=max(r,n-r);
    ll i,j,s,d=1,k;
    s=1;

    for(i=m+1;i<=n;i++)
    {
       // s=((s%p)*(i%p))%p;
       s=(s*i)%p;
    }

    m=min(r,n-r);

    for(i=1;i<=m;i++)
    {
        d*=bigmod(i,p-2);
        d%=p;
    }

    //k=(s%p*(d%p))%p;

    return s*d;
}

int main()
{

    ll n,m,a,b,x,y,c,i,j,d,k,tw;

    cin>>n>>a>>b;

    tw=bigmod(2LL,n)-1;



    a=find_ncr(n,a);
    b=find_ncr(n,b);

    tw=(tw%p-(a%p+b%p)%p)%p;
    tw=(tw+p)%p;

    cout<<tw<<endl;


    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){

int G,N;
while(1){
scanf("%d",&G);if(G==0)break;

scanf("%d",&N);
int s,f;
for(int i=0;i<N;i++)
{
scanf("%d %d",&s,&f);
f-=s;
G-=f;
//if(G<=0)break;
}
if(G<=0)printf("OK\n");
else printf("%d\n",G);
}
return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef pair<int,int> pii;
const int N=100005;

int n,m,tot;
int vis[N],low[N];
vector<int>G[N];
vector<pii>ans;

void dfs(int u,int p) {
    vis[u]=low[u]=++tot;
    for (int v:G[u]) {
        if (v == p) continue;
        if (!vis[v]) {
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if (low[v]>vis[u]) ans.pb({min(u,v),max(u,v)});
        }
        low[u]=min(low[u],vis[v]);
    }
}

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    while (m--) {
        int u,v; cin>>u>>v,
        G[u].pb(v),
        G[v].pb(u);
    }
    for (int i=0;i<n;++i) if (!vis[i]) dfs(i,-1);
    sort(ans.begin(),ans.end());
    for (auto p:ans) cout<<p.ff<<' '<<p.ss<<'\n';
}




Measured memory_bytes: 7232
N = int(input())
ac_num = 0
tle_num = 0
wa_num = 0
re_num = 0
for i in range(N):
  result = input()
  if result == "AC":
    ac_num += 1
  elif result == "TLE":
    tle_num += 1
  elif result == "WA":
    wa_num += 1
  else:
    re_num += 1
    
print("AC x " + str(ac_num))
print("WA x " + str(wa_num))
print("TLE x " + str(tle_num))
print("RE x " + str(re_num))


Measured memory_bytes: 9172