akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin >> H >> W;
  vector<string> G(H+2);
  G[0] = string(W+2,'#');
  G[H+1] = string(W+2,'#');
  for(int i=1; i<=H; i++){
    cin >> G[i];
    G[i] = "#" + G[i] + "#";
  }
  for(int i=0; i<H+2; i++){
    cout << G[i] << "\n";
  }

  return 0;
}

Measured memory_bytes: 3608
$_=<>;
chomp;
my($n,$l)=split/ /;
my$dlsum=(2*$l+$n-1)*$n/2;
if(0<$l){
 $dlsum-=$l;
}elsif($l+$n-1<0){
 $dlsum-=($l+$n-1);
}
print$dlsum;


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long

int main(){
  int x;
  cin >> x;
  if(x<1200){
    cout << "ABC" << endl;
  }else{
    cout << "ARC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 

void solve() {
    int MAX = 1010101;
    vector<int> is_Prime(MAX,1);
    is_Prime[0] = 0, is_Prime[1] = 0;
    rep(i,2,MAX){
        if(is_Prime[i] == 0) continue;
        for(int j = 2*i; j < MAX; j += i){
            is_Prime[j] = 0;
        }
    }

    vector<int> a(MAX, 0);
    rep0(i, MAX){
        if(is_Prime[i] && is_Prime[(i+1)>>1]) a[i] =1;
    }
    
    vector<int> cum_a(MAX+1, 0);
    cum_a[0] = 0;
    rep0(i, MAX){
        cum_a[i+1] = cum_a[i]+a[i];
    }
    
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << cum_a[r] - cum_a[l] << endl;
    }
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 12544
mod = pow(10,9)+7
N,K = map(int,input().split())

A = sorted(list(map(int,input().split())))
B = A[::-1]
n= N

fac = [1]*(n+1)
inv = [1]*(n+1)
for i in range(1,n+1):
  fac[i] = (fac[i-1]*i) % mod  
inv[n] = pow(fac[n], mod-2, mod)
for i in range(n, 0, -1):
  inv[i-1] = (inv[i]*i) % mod
    
def nCr(n,r):  
  if r < 1:
    return 1
  return (((fac[n] * inv[r])%mod) * inv[n-r]) % mod

counter_min=0
counter_max=0
for i in range(N-K+1): #i=0 1 2 
    counter_max += A[N-1-i] * nCr(N-1-i,K-1)
    counter_min += B[N-1-i] * nCr(N-1-i,K-1)

print((counter_max-counter_min)%mod)


Measured memory_bytes: 89264
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    int h,w,n;cin>>h>>w>>n;
    int maxi=max(h,w);
    int res=0;
    if(n%maxi==0)res=n/maxi;
    else res=n/maxi+1;
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n; 
int main(){
	cin>>n;
	cout<<(n+1)/2;
	return 0;
}


Measured memory_bytes: 256
#入力
N = int(input())
height = list(map(int,input().split()))

#DP配列を用意
dp = [0] * N

#初期条件
dp[0] = 0

for i in range(N):
    if i > 0:
        dp[i] = dp[i-1] + abs(height[i]-height[i-1])
        if i > 1:
            dp[i] = min(dp[i], dp[i-2] + abs(height[i]-height[i-2]))

print(dp[N-1])

Measured memory_bytes: 13980
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

string s;
int n;

int main(){
    ll const MOD = 1e9+7;
    cin >> n >> s;
    vector<ll> cnt(26,1);
    REP(i,n){
        cnt[s[i]-'a']++;
    }
    ll res = 1;
    REP(i,26){
        cnt[i]=cnt[i]%MOD;
        res *= cnt[i];
        res = res%MOD;
    }
    put(res-1);
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define xfor(i, a, b) for (int i = a; i < b; i++)
#define ifor(i, a, b) for (int i = a; i <= b; i++)
#define rxfor(i, b, a) for (int i = b; i > a; i--)
#define rifor(i, b, a) for (int i = b; i >= a; i--)
#define foreach(v, c) for (typeof((c).begin()) v = (c).begin(); v != (c).end(); ++v)
#define all(a) a.begin(), a.end()
#define in(a, b) ((b).find(a) != (b).end())
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;

int main()
{
    int n;
    long long sum = 0;
    cin >> n;
    ifor(i, 1, n)
    {
        ifor(j, 1, n)
        {
            ifor(k, 1, n)
            {
                sum += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3584
N,T=map(int,input().split())

listA=[] #appendのために宣言が必要
for i in range(N):
    a,b=input().split()
    listA.append([int(a), int(b)])

for i in range(len(listA)):
    if(T<listA[i][1]):
        listA[i][0]=9999

minc=9999
index=9999
for i in range(len(listA)):
    if(minc>listA[i][0]):
        minc=listA[i][0]
        index=i
if(minc==9999):
    print('TLE')
    exit(0)
print(minc)



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

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i=0; i<N; i++)  cin >> s[i];

  int M;
  cin >> M;
  vector<string> t(M);
  for(int i=0; i<M; i++)  cin >> t[i];
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
 
  int ans = 0;
  int k = 0;
  for(int i=0; i<N; i++){
    string ss = s[i];
    int count = 1;
    for(int j=i+1; j<N; j++){
      if(ss == s[j]){
      	 count++;
     	 i = j;
      }//if
    }//for
    for(int j=k; j<M; j++){
      if(ss == t[j]){
      	count--;
      	k = j;
      }//if
    }//for
  ans = max(ans, count);
  }//for

  cout << ans << "\n";
}//main


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    string a;
    string b;
    string A, B;
    int X, Y;
    cin >> a >> b;
    X = stoi(a);
    Y = stoi(b);  
    for (int i = 0; i < Y; i++) {
        A = A + a;
    }
    for (int i = 0; i < X; i++) {
        B = B + b;
    }
    if (X > Y) {
        cout << B << endl;
    }
    else if (X < Y) {
        cout << A << endl;
    }
    else {
        cout << A << endl;
    }
}

Measured memory_bytes: 256
def factorize(N):  # 素因数分解
    p, PRIME = 2, set()
    while p * p <= N:
        if N % p == 0:
            N //= p
            PRIME.add(p)
        else:
            p += 1
    if N > 1:
        PRIME.add(N)
    return PRIME


a, b = map(int, input().split())

ans = factorize(a) & factorize(b)
print(len(ans) + 1)


Measured memory_bytes: 62828
#include <iostream>

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

	int ans = x;
	for( int i = 0; i < n; i++ ) {
		int a;
		std::cin >> a;
		for( int j = 1 ; j <= d; j += a ) {
			ans += 1;
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<numeric>
using namespace std;
int main(){
    int N,M;cin>>N>>M;
    long x[N],y[N],z[N],ans=0L;
    vector<long>v(N);
    for(int i=0;i<N;i++)cin>>x[i]>>y[i]>>z[i];
    for(int bit=0;bit<8;bit++){
        bitset<3>b(bit);
        for(int i=0;i<N;i++)v[i]=x[i]*(b[0]?-1:1)+y[i]*(b[1]?-1:1)+z[i]*(b[2]?-1:1);
        sort(v.begin(),v.end(),greater<long>());
        ans=max(ans,accumulate(v.begin(),v.begin()+M,0L));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    ans = 10000
    value = 100000
    for i in range(-1000,1000):
        if i in P:
            continue
        if ans > abs(X - i):
            ans = abs(X-i)
            value = i

    print(value)
            




if __name__ == "__main__":
    main()

Measured memory_bytes: 63992
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

const int MAXN = (int)2e5;
int n, a[MAXN + 5];
ll br[MAXN + 5];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i){
	cin >> a[i];
	br[a[i]]++;
}
ll sol = 0;
for(int i = 1 ; i <= n ; ++i){
	sol += (br[i] * (br[i] - 1)) / 2LL;
}
for(int i = 1 ; i <= n ; ++i){
	int x = a[i];
	sol -= (br[x] * (br[x] - 1)) / 2LL;
	br[x]--;
	sol += (br[x] * (br[x] - 1)) / 2LL;
	cout << sol << endl;
	sol -= (br[x] * (br[x] - 1)) / 2LL;
	br[x]++;
	sol += (br[x] * (br[x] - 1)) / 2LL;
}

return 0;
}



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

const int N = 2e5 +500;

int n, q;
long long a[N], f[N], ans[N], m, x, j, k;
int main() {
	scanf("%d%d", &n, &q), a[++m] = n;
	for (int i = 1; i <= q; i++) {
		scanf("%lld", &x);
		while (x <= a[m] && m > 0) m--; a[++m] = x;
	}
//	for (int i = 1; i <= m; i++) printf("%d ", a[i]); printf("\n");
	f[m] = 1;
	for (int i = m; i >= 1; i--) {
		k = a[i], j = lower_bound(a + 1, a + i, k) - a - 1;
		while (j > 0) {
//			cout << i << " " << j << " " << k << endl;
			f[j] += (k / a[j]) * f[i], k %= a[j];
			j = lower_bound(a + 1, a + j, k) - a - 1;
		}
//		cout << ":" << k << endl; 
		ans[1] += f[i], ans[k + 1] -= f[i];
	}
	for (int i = 1; i <= n; i++) {
		ans[i] += ans[i - 1];
		printf("%lld\n", ans[i]);
	}
	return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  vector<int> a(n); cin >> a;
  int ans = 0;
  for (int i = 0; i < n; ++i){
    if(i&1^1 and a[i]&1)  ans++;
  }
  cout << ans << "\n";
  return 0;
}

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

int main(void) {
  int a, b;
  string s;
  bool f = true;
  cin >> a >> b >> s;
  for (int i = 0; i < s.length(); ++i) {
    if (i < a or i > a) {
      if (s[i] >= '0' and s[i] <= '9') {} else {f = false;}
    }
    else if (i == a) {
      if (s[i] == '-') {} else {f = false;}
    }
  }
  cout << (f ? "Yes" : "No") << endl;
}

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

int keta(unsigned long long a){
	int k=1;
	while(a>=10){
		a /= 10;
		k++;
	}
	return k;
}

int main(){
	int ans = 11;
	unsigned long long n;
	cin >> n;
	double a;
	for(a=1; a<=sqrt(n); a++){
		unsigned long long b = n/a;
		if(a*b==n) ans = min(ans, keta(b)); 
	}
	cout << ans << endl;
}

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

int n=2,m=4;
int _a[2][4];
int b[2100000];

int next(){
	return scanf("%d %d %d %d %d %d %d %d",&_a[0][0],&_a[0][1],&_a[0][2],&_a[0][3],&_a[1][0],&_a[1][1],&_a[1][2],&_a[1][3]);
}

int getoi(){
	int x = 0;
	for(int i = 0; i < n; i++ ) {
		for(int j = 0; j < m; j++ ) {
			x<<=3;
			x|=_a[i][j];
		}
	}
	return x;
}

int geti(int x){
	int i=0;
	for(;i<8;i++){
//		printf("\t\t int geti i:%d  x&7 = %d\n",i,x&7);
		if(x&7){
			x>>=3;
		}else {
			return i;
		}
	}
	return i;
}

int change(int x,int i,int j){
//	printf("\t\tchagestart:(%d,%d,%d)\n",x,i,j);
	int a = (x&(7<<j))>>j;
//	printf("\t\t\tto a:%d\n",a);
	int y = x&(~(7<<j));
//	printf("\t\t\tto y:%d\n",y);
	y |= a<<i;
//	printf("\t\t\tto y:%d\n",y);
	return y;
}

int main(){
	while(~next()) {
		memset(b,0,sizeof(b));
		queue<int> q;
		queue<int> direction;
		q.push(getoi());
		b[getoi()&2097151] = 1;
//		printf("oi:%d   %d\n",getoi(),b[getoi()&2097151]);
		while(!q.empty()){
			int x = q.front();
			q.pop();
//			printf("x = %d    %d\n",x,b[x&2097151]);
			if(x==342391)break;
			int oi = geti(x);
			direction.push(change(x,oi*3,((4+oi)&7)*3));
			if(oi%4!=0)direction.push(change(x,oi*3,(oi-1)*3));
			if(oi%4!=3)direction.push(change(x,oi*3,(oi+1)*3));
			while(!direction.empty()){
				int y = direction.front();
//				printf("\ty = %d\n",y);
				direction.pop();
				if(b[y&2097151]==0){
					b[y&2097151] = b[x&2097151] + 1;
					q.push(y);
				}
			}
		}
		if(b[342391] == 0)
			cout<<"error"<<endl;
		else  
			cout<<b[342391]-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 11408
N = int( input() )
X = list( map( int, input().split() ) )

m = min( X )
M = max( X )
v_min = 10 ** 18
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_min = min( v, v_min )
print( v_min )

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

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int Erat(int x) {
  VI a(x*2);
  REP(i,x*2){
    a.at(i) = 1;
  }
  
  for(int i = 2; i < sqrt(x*2); i++){
    if(a.at(i)) {
      for(int j = 0; i*(j+2) < (x*2); j++) {
        a.at(i*(j+2)) = 0;
      }
    }
  }
  
  for(int i = x; i < (x*2); i++){
    if(a.at(i)) {
      return i;
    }
  }
}

int main() {
  int X;
  cin >> X;
  cout << Erat(X) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    long long N,M;
    cin >> N >> M;
    cout << abs((N-2LL)*(M-2LL)) << endl;

    



}


Measured memory_bytes: 256
using System;
using System.Text;

namespace _172_b
{
    internal class MinorChange
    {
        private static void Main(string[] args)
        {
            var input1 = GetInputString();
            var input2 = GetInputString();
            var length = input1.Length;

            var identicalCount = 0;
            for (var i = 0; i < length; i++)
            {
                if (input1[i] < 'a' || input1[i] > 'z') break;

                if (input1[i] != input2[i])
                {
                    identicalCount++;
                }
            }

            Console.WriteLine(identicalCount);
        }

        private static string GetInputString()
        {
            var sb1 = new StringBuilder();
            while (true)
            {
                var ch = Convert.ToChar(Console.Read());
                sb1.Append(ch);
                if (ch == '\n') break;
            }
            return sb1.ToString();
        }
    }
}


Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint n;
string s;

bool check(lint len) {
    bool ok = false;
    for(lint i = 0; i + len < n; i++) {
        string sub = s.substr(i, len);
        if(s.substr(i+len).find(sub) != string::npos)  ok = true;
    }
    return ok;
}

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

    lint ok = 0;
    lint ng = n;
    while( abs(ok - ng) > 1 ) {
        lint m = (ok + ng) / 2;
        (check(m) ? ok : ng) = m;
    }

    cout << ok << endl;
}

Measured memory_bytes: 256
N,K =map(int,input().split())

LIST=[[0,0] for i in range(N)]

for i in range(N):
    LIST[i][0],LIST[i][1]=map(int,input().split())

LIST=sorted(LIST)

c=0
for i in range(N):
    c+=LIST[i][1]
    if(c>=K):
        print(LIST[i][0])
        exit()



Measured memory_bytes: 20804
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int a[n],b[m];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    rep(i,m)cin>>b[i];
    sort(b,b+m);
    if(a[n-1]>b[0]){
        cout<<"War"<<endl;
        return 0;
    }else{
        for(int i=a[n-1]+1;i<=b[0];i++){
            if(i>x&&i<=y){
                cout<<"No War"<<endl;
                return 0;
            }
        }
        cout<<"War"<<endl;
        
    }

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
typedef long long ll;
using namespace std;

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> X(N), cnt(100001), md(M), dob(M);
	for(int i = 0; i < N; ++i){
		cin >> X[i];
		cnt[X[i]]++;
		md[X[i]%M]++;
	}
	for(int i = 1; i < 100001; ++i){
		dob[i%M] += cnt[i] / 2;
	}
	int res = md[0] / 2;
	if(M % 2 == 0){
		res += md[M / 2] / 2;
	}
	for(int i = 1; i <= M / 2; ++i){
		if(M % 2 == 0 && i == M / 2) continue;
		int u = i, v = M - i;
		if(md[u] > md[v]){
			swap(u,v);
		}
		int n = md[u];
		//cout << n << endl;
		res += n;
		res += min(md[v]-n, 2 * dob[v]) / 2;
	}
	cout << res << endl;
	return 0;
}


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

int main() {
	long long N, A[100], X[100] = {}, MIN, MAX;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], X[A[i]]++;
	sort(A, A + N);
	MIN = A[0], MAX = A[N - 1];
	if (MIN * 2 - 1 == MAX) {
		if (X[MIN] != 2) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	else if (MIN * 2 == MAX) {
		if (X[MIN] != 1) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	else {
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = MIN + 1; i <= MAX; i++) {
		if (X[i] < 2) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	cout << "Possible" << endl;
}

Measured memory_bytes: 256
X_INDEX = 0
Y_INDEX = 1


def solve():
    number_of_balls = int(input())
    red_points = [list(map(int, input().split())) for _ in range(number_of_balls)]
    blue_points = [list(map(int, input().split())) for _ in range(number_of_balls)]

    from operator import itemgetter
    blue_points.sort(key=itemgetter(X_INDEX))  # 青玉をx座標の昇順でソート
    red_points.sort(key=itemgetter(Y_INDEX), reverse=True)  # 赤玉をy座標の降順でソート

    # 青玉：x座標の小さいものからペアを作っていく
    # 赤玉：青玉のx座標よりも小さいものの中で、y座標が最大のものをペアとする
    number_of_pairs = 0  # 仲良しペアの数
    used_red_points = [False for _ in range(number_of_balls)]  # 使用済み赤玉情報
    # used_blue_points = [False for _ in range(number_of_balls)]  # 使用済み青玉情報
    for blue_i, blue_point in enumerate(blue_points):
        for red_i, red_point in enumerate(red_points):
            if red_point[X_INDEX] < blue_point[X_INDEX] and \
                    red_point[Y_INDEX] < blue_point[Y_INDEX] and \
                    not used_red_points[red_i]:
                number_of_pairs += 1
                used_red_points[red_i] = True
                break

    print(number_of_pairs)


solve()

Measured memory_bytes: 39280
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0) ans+=i;
  }
  COUT(ans);
}

Measured memory_bytes: 3636
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int H =sc.nextInt();
        int W =sc.nextInt();
        String[][] S =new String[H][W];
        
        boolean[] b1 =new boolean[H];
        boolean[] b2 =new boolean[W];
        
        for(int i=0;i<H;i++) {
            
            S[i]=sc.next().split("");
            for(int j=0;j<W;j++) {
                
                if(S[i][j].equals("#")) {
                    
                    b1[i]=true;
                    b2[j]=true;
                }
            }
        }
    
        for(int i=0;i<H;i++){
            
            
            if(b1[i]) {
                
                for(int j=0;j<W;j++) {
                    
                    if(b2[j]) {
                        System.out.print(S[i][j]);
                    }
                }
            System.out.println("");
        }
    }

        
    }
    
} 

Measured memory_bytes: 40108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int s,w;
  cin >> s >> w;
  if(w>=s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  
  
  return 0;
    

}


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

typedef long long ll;

const int MN = 100010;

int N, E, T;
int X[MN];

struct BIT {
    vector<ll> tree;
    void init() {
        tree = vector<ll>(4 * MN, 1e18);
    }
    void upd(int idx, ll val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] = min(tree[n], val);
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = min(tree[2*n], tree[2*n + 1]);
    }
    ll quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 1e18;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        ll L = quer(a, b, l, m, 2*n);
        ll R = quer(a, b, m + 1, r, 2*n + 1);
        return min(L, R);
    }
} bit1, bit2;

ll dp[MN];

int main() {
    scanf("%d %d %d", &N, &E, &T);

    for(int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
    }
    X[N] = E;

    bit1.init();
    bit2.init();

    dp[N] = 0;
    bit1.upd(N, dp[N] + 2 * X[N - 1] + X[N], 0, MN - 1, 1);
    bit2.upd(N, dp[N] + X[N], 0, MN - 1, 1);

    for(int i = N - 1; i >= 0; i--) {

        int s = i + 1, e = N, p = -1;
        while(s <= e) {
            int m = (s + e)>>1;

            if(T > 2 * (X[m - 1] - X[i])) {
                p = m;
                s = m + 1;
            }
            else e = m - 1;
        }

        dp[i] = bit1.quer(p + 1, N, 0, MN - 1, 1) - 3LL * X[i];
        dp[i] = min(dp[i], bit2.quer(i + 1, p, 0, MN - 1, 1) - X[i] + T);

        bit1.upd(i, dp[i] + 2 * (i? X[i - 1] : 0) + X[i], 0, MN - 1, 1);
        bit2.upd(i, dp[i] + X[i], 0, MN - 1, 1);
    }

    printf("%lld", dp[0] + X[0]);
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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



const ll INF = 1LL << 60;
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

Graph G;
vector<ll> d; //distance;

// d[v] に頂点 s からの頂点 v の距離を入れる関数
void dijkstra(int s){
  fill(all(d), INF);
  d[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    if(d[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(d[nv] > d[v] + w){
        d[nv] = d[v] + w;
        pq.push(P(d[nv], nv));
      }
    }
  }
}

int main(){
  int n,m; cin >> n >> m;
  G.resize(n);
  rep(i, m){
    int l,r,c; cin >> l >> r >> c;
    l--; r--;
    G[l].pb(Edge(r,c));
  }
  rep(i, n-1) G[i+1].pb(Edge(i,0));

  d.resize(n);
  dijkstra(0);

  std::cout << (d[n-1] != INF ? d[n-1] : -1) << '\n';
}


Measured memory_bytes: 7928
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
char s[N];
int n;
int num[N];
signed main(void){
	scanf("%s",s+1);
	n = strlen(s+1);
	for(int i = 1 ; i <= n ; i ++) {
		if(s[i]=='L')
			continue;
		int sum[2];
		sum[0]=sum[1]=0;
		int depth=0;
		int zz = i + 1;
		bool cp = 1;
		sum[0]=1;
		depth=1;
		while(zz<=n){
			bool pc=(s[zz]=='R'?1:0);
			if((pc^cp) == 0){
				sum[depth&1]++;
				depth++;
			}
			else if ((pc^cp) == 1){
				num[zz-1] += sum[(depth-1)&1];
				num[zz] += sum[(depth)&1];
				i = zz;
				depth=0;
				break;
			}
			zz++;
		}
	}
	for(int i=n;i>=1;i--){
		if(s[i]=='R')
			continue;
		int sum[2];
		sum[0]=sum[1]=0;
		int depth=0;
		int zz=i - 1;
		bool cp=(s[i]=='R'?1:0);
		sum[0]=1;
		depth=1;
		while(zz<=n){
			bool pc=(s[zz]=='R'?1:0);
			if((pc^cp)==0){
				sum[depth&1]++;
				depth++;
			}
			else if ((pc^cp)==1){
				num[zz+1]+=sum[(depth-1)&1];
				num[zz]+=sum[(depth)&1];
				i = zz;
				depth=0;
				break;
			}
			zz--;
		}
	}
	for(int i=1;i<=n;i++)
		printf("%d ",num[i]);
	return 0;
}
//+1s

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

using namespace std;

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

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 3e3;


string s, t;

int dp[MAX][MAX];
int f(int i, int j) {
    if (i == -1 or j == -1) {
        return 0;
    }
    int &res = dp[i][j];
    if (dp[i][j] != -1) return dp[i][j];
    if (s[i] == t[j]) {
        res = f(i - 1, j - 1) + 1;
    }
    else {
        res = max(res, f(i, j - 1));
        res = max(res, f(i - 1, j));
    }
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    memset(dp, -1, sizeof dp);
    cin >> s >> t;
    f(s.size() - 1, t.size() - 1);
    stack<char> res;
    for (int i = s.size() - 1, j = t.size() - 1; i >= 0 and j >= 0;) {
        if (s[i] == t[j]) {
            res.push(s[i]);
            i--, j--;
        }
        else {
            if (f(i - 1, j) >= f(i, j - 1)) 
                i--;
            else 
                j--;
        }
    }
    while (!res.empty()) {
        cout << res.top();
        res.pop();
    }
    cout << '\n';
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

int f(i64 a,i64 b){
    int x=0,y=0;
    while(a>0){
        a/=10;
        ++x;
    }
    while(b>0){
        b/=10;
        ++y;
    }
    return max(x,y);
}

void solve(){
    i64 n;
    cin >> n;
    int ans=inf;
    for(i64 i=1; i*i<=n; ++i){
        if(n%i!=0) continue;
        ans=min(ans,f(i,n/i));
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX 100006
#define f first
#define s second
#define N 1e18+10
void solve()
{
    int n;  cin>>n;
    if(n>=30)  cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    return 0;
}


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

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i=0; i<N; i++) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1, vector<ll>(100100, 1e12));
    dp[0][0] = 0;
    
    for (int i=0; i<N; i++) {
        for (int j=0; j<100100; j++) {
            if (j - v[i] >= 0) {
                if (dp[i+1][j] > dp[i][j - v[i]] + w[i]) dp[i+1][j] = dp[i][j - v[i]] + w[i];
            }

            if (dp[i+1][j] > dp[i][j]) dp[i+1][j] = dp[i][j];
        }
    }
    
    ll ans = 0;
    for (int j=0; j<100100; j++) {
        if (dp[N][j] <= W) ans = j;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 80256
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

MOD = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)
    
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % MOD
  
ans = 0
for i in range(1, n+1):
    if 1 <= i <= n - k + 1:
        ans -= (cmb(n-i, k-1) * a[i-1] % MOD) % MOD
    if k <= i <= n:
        ans += (cmb(i-1, k-1) * a[i-1] % MOD) % MOD
print(ans%MOD)

Measured memory_bytes: 20304
using System;

public class Hello
{
    public static void Main()
    {
        var x = int.Parse(Console.ReadLine().Trim());
        var t = gcd(360, x);
        Console.WriteLine(360 / t);
    }
    static int gcd(int a, int b)
    {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 27500
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============BIT============================
const ll MAX_N = 1e5;
ll n;
vector<ll> bit(MAX_N + 1, 0);

ll sum(ll i) {
  ll s = 0;
  while (i > 0) {
    s += bit.at(i);
    i -= i & -i;
  }
  return s;
}

void add(ll i, ll x) {
  while (i <= n) {
    bit.at(i) += x;
    i += i & -i;
  }
}
//=================================================

int main() {
  ll q;
  cin >> n >> q;
  for (ll i = 0; i < q; ++i) {
    ll com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      add(x, y);
    }
    else {
      ll minus = 0;
      if (x != 1) {
        minus = sum(x - 1);
      }
      cout << sum(y) - minus << "\n";
    }
  }
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
};
signed main(){
    int n,m,p[100000],ans=0;
    cin>>n>>m;
    Union_Find tree(n);
    rep(i,n)cin>>p[i];
    rep(i,m){
        int x,y;
        cin>>x>>y;
        tree.Union(x,y);
    }
    rep(i,n){
        if(tree.same(i+1,p[i]))ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2796
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ull N;

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    for(int i=0;i<n;++i) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;
  }

  void unite(pair<int,int> p) {
    unite(p.first,p.second);
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  bool same(pair<int,int> p) {
    return same(p.first,p.second);
  }

  int size(int x) {
    return sizes[find(x)];
  }
};

void fillmap(vector<pair<int,int>> xs, map<pair<int,int>,int> &m){
  for(auto it=xs.begin();it+1!=xs.end();++it) {
    int diff = abs(it->first-(it+1)->first);
    int t = it->second, n = (it+1)->second;
    auto key = t<n ? make_pair(t,n) : make_pair(n,t);
    m[key] = m.count(key) ? min(diff, m[key]) : diff;
  }
}

int main (int argc, char const *argv[])
{
  cin >> N;
  vector< pair<int,int> > xs,ys;
  for(int i=1;i<=N;++i) {
    int x,y;cin >> x >> y;
    xs.push_back(make_pair(x,i));
    ys.push_back(make_pair(y,i));
  }

  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());

  map< pair<int,int>,int > m;
  fillmap(xs,m);
  fillmap(ys,m);

  priority_queue< pair< int, pair<int,int> > > pq;

  for(auto &&kv:m) pq.push(make_pair(-kv.second,kv.first));

  auto uf = UnionFind(N+1);
  ll ans=0;
  while(pq.size()) {
    auto t = pq.top(); pq.pop();
    // cout << t.first << " : " << t.second.first << "," << t.second.second << endl;
    if(uf.same(t.second)) continue;
    uf.unite(t.second);
    ans += -t.first;
  }

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


Measured memory_bytes: 17116
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

int main() {
  int i,j,k,n,m;
  while(scanf("%d %d", &n, &m), n|m) {
    vector<int> p(n);
    rep(i,n) {
      scanf("%d", &p[i]);
    }

    vector<int> f2;
    rep(i,n) {
      REP(j,i,n) {
	f2.push_back(p[i]+p[j]);
      }
      f2.push_back(p[i]);
    }
    f2.push_back(0);
    f2.push_back(0);

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

    int ans = 0;
    vector<int>::iterator it;
    rep(i,f2.size()) {
      if(f2[i] > m) break;
      if(f2[i] == m) ans = m;
      it = upper_bound(f2.begin(), f2.end(), m-f2[i]);
      ans = max(ans, *(it-1)+f2[i]);
    }

    printf("%d\n", ans);
  }
}

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


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	cin>>t;
	if(t==1)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<1<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	set<int> s;
	for(int i = 0; i < n; i++) {
		int id, x;
		scanf("%d%d", &id, &x);
		if(id == 0) {
			s.insert(x);
			printf("%lu\n", s.size());
		}else if(id == 1) {
			printf("%lu\n", s.count(x));
		}else if(id == 2) {
			s.erase(x);
		}else if(id == 3) {
			int y;
			scanf("%d", &y);
			auto itr = s.lower_bound(x);
			for(; itr != s.end() && *itr <= y; itr++)
				printf("%d\n", *itr);
		}
	}
}



Measured memory_bytes: 12436
#pragma GCC optimize("03")

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

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(v) cout << #v << ":\t" << v << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	vector<ll> a;	
	for (ll i = 1; i <= 3; ++i) {
		ll x; cin >> x;
		a.pb(x);
	}
	sort(all(a));
	
	cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

mod = 10 ** 9 + 7
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

##### Settings
unit = 1
merge = lambda a, b: a * b % mod
adj_bu = lambda a, i: a * inv(SIZE[i]) % mod
adj_td = lambda a, i, p: a * inv(N-SIZE[i]) % mod
adj_fin = lambda a, i: a * fa[N-1] % mod
#####

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod

inv = lambda i: fainv[i] * fa[i-1] % mod

SIZE = [1] * N
for i in R[1:][::-1]:
    SIZE[P[i]] += SIZE[i]

ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in R[1:][::-1]:
    XX[i] = adj_bu(ME[i], i)
    p = P[i]
    ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_fin(ME[R[0]], R[0])

for i in R:
    ac = TD[i]
    for j in X[i]:
        TD[j] = ac
        ac = merge(ac, XX[j])
    ac = unit
    for j in X[i][::-1]:
        TD[j] = adj_td(merge(TD[j], ac), j, i)
        ac = merge(ac, XX[j])
        XX[j] = adj_fin(merge(ME[j], TD[j]), j)

print(*XX, sep = "\n")

Measured memory_bytes: 111380
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll n, tt=0, mx = 0;
    cin>>n;
    REP(i,n)
    {
        ll x;
        cin>>x;
        tt += x;
        mx = max(mx, x);
    }
    if(mx * 2 < tt)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 K, N, i;
  cin >> K >> N;
  vi A(N);
  REP(0, N, i) {
    cin >> A[i];
  }
  sort(all(A));
  i64 ans = K - (A.back() - A[0]);
  REP(0, N-1, i) {
    ans = max(ans, A[i+1] - A[i]);
  }
  cout << K - ans << endl;
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
tmp = [0,0,0]
data = [0,0,0]
flag = True
for i in range(N):
  tmp = list(map(int,(input()).split()))
  if (tmp[0] - data[0])%2 == (tmp[1] + tmp[2] - data[1] - data[2]) % 2 + 1 or (tmp[1] - data[1] + tmp[2] - data[2] > tmp[0] - data[0]):
    flag = False
    break
  else:
    data = tmp

if flag:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3064
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
    #require 'rbconfig';RUBY=File.join(RbConfig::CONFIG['bindir'],RbConfig::CONFIG['ruby_install_name'])
    require 'rubygems';RUBY=Gem.ruby
    exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},RUBY,$0) #100MB
end

N = gets.to_i

NONE = -1
$t = {}

def type(u)
  if $t[u][:p].nil?
    'root'
  elsif $t[u][:l].nil?
    'leaf'
  else
    'internal node'
  end
end

def child(u)
  a = []
  is_first = true
  c = $t[u][:l]
  s = '['

  while !c.nil?
    s << ', ' unless is_first
    s << c.to_s

    c = $t[c][:r]
    is_first = false
  end
  s << ']'
end

def print()
  (0...N).each do |u|
    puts "node #{u}: parent = #{$t[u][:p].nil? ? NONE : $t[u][:p]}, depth = #{$t[u][:d]}, #{type(u)}, #{child(u)}"
  end
end

def rec(u, p)
  $t[u][:d] = p
  rec($t[u][:r], p) unless $t[u][:r].nil?
  rec($t[u][:l], p + 1) unless $t[u][:l].nil?
end

(0...N).each do |i|
  $t[i] = {p: nil, l: nil, r: nil, d: nil}
end

N.times do |_|
  a = gets.split.map(&:to_i)

  if a[2].nil?
    next
  end

  v = a[0]
  d = a[1]
  l = 0

  (0...d).each do |i|
    c = a[i + 2]

    if i == 0
      $t[v][:l] = c
    else
      $t[l][:r] = c
    end

    l = c
    $t[c][:p] = v
  end
end

(0...N).each do |i|
  if $t[i][:p].nil?
    $r = i
  end
end

rec($r, 0)
print()


Measured memory_bytes: 51252
N = int(input())
pieces = {}
X = list(map(int, input().split()))
for p in range(N):
    pieces.setdefault(p+1, X[p])
M = int(input())
move = list(map(int, input().split()))
for i in range(M):
    destination = pieces[move[i]] + 1
    if destination > 2019 or destination in pieces.values():
        continue
    pieces[move[i]] = destination
for i in range(N):
    print(pieces[i+1])


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

int main(){
  int a[50],s;
  cin>>s;
  a[0]=1;
  a[1]=1;
  for(int i=2;i<=s;i++){
    a[i]=a[i-1]+a[i-2];
  }
  cout<<a[s]<<endl;
  return 0;
}

Measured memory_bytes: 3076