akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define inf 1e18
using namespace std;
int dp[3001][3001];

int solve(int *a,int i,int j){
    if(i>j){
        return 0;
    }
    if(dp[i][j]!=inf){
        return dp[i][j];
    }
    if(i==j){
        return dp[i][j]=a[i];
    }
    if(i==j+1){
        return dp[i][j]=max(a[i],a[j]);
    }
    int op1=a[i]+min(solve(a,i+2,j),solve(a,i+1,j-1));
    int op2=a[j]+min(solve(a,i,j-2),solve(a,i+1,j-1));
    return dp[i][j]=max(op1,op2);
}
int32_t main(){
    int n;
    cin>>n;
    int a[n+1];
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
      for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=inf;
        }
    }    
  
    int x=solve(a,1,n);
    int y=sum-x;
    int ans=x-y;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70784
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, T);
    FOR(t, T)
    {
        if (t == '?')
        {
            t = 'D';
        }
    }
    OUT(T);
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

long long a[100010];
int main() {
	int k; cin >> k;
	for (int i = 0; i < k; i ++) cin >> a[i];
	long long down = 2, up = 2;
	for(int i = k-1; i >= 0; i --) {
		long long s1 = down/a[i] + (down%a[i]!=0);
		long long s2 = up/a[i];
		if (s1 > s2) {
			cout << -1 << endl; return 0;
		}
		down = s1 * a[i];
		up = s2 * a[i] + a[i] - 1;
	} 
	cout << down << ' ' << up << endl;
	return 0;
} 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;  // (int,int)型
 
P f(int x) {
  int a = x%10;  // 末尾
  int b = 0;  //stoi(to_string(x)[0])
  while (x) {  // 0なら抜ける
    b = x;
    x /= 10;
  }
  return P(a,b);
}
 
int main() {
  int n;
  cin >> n;
  map<P,int> freq;  // 集計用
  for (int i = 1; i <= n; ++i) {
    P p = f(i);  // 1=1,1 2=2,2 10=1,1 11=1,1 12=1,2
    freq[p]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    P p = f(i);
    P q(p.second, p.first);  // 12=2,1
    ans += freq[q];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 3e3 + 10;

vector<double> DP(MAX, 0);

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

	int N;
	cin >> N;

	DP[0] = 1;

	for(int i = 1; i <= N; i++){
		double x;
		cin >> x;

		for(int j = i-1; j >= 0; j--){
			DP[j+1] += DP[j]*x;
			DP[j] *= (1 - x);
		}
	}

	double ans = 0;
	for(int i = (N + 1)/2; i <= N; i++) ans += DP[i];

	cout << fixed << setprecision(10);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3836
### INPUT
N = int(input())
A = list(map(int,input().split()))
cont = 0
b = N-1
MAX = 0
### MAIN
for i in range(b):
    if A[i]>=A[i+1] :
        cont = cont + 1
    else:
        cont = 0

    if cont > MAX:
        MAX = cont
### OUT
print(MAX)

Measured memory_bytes: 14252
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, K; cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)

string s,s1,s2;

int f(string s3)
{
    string ss=s3;
    reverse(ss.begin(),ss.end());
    if(ss==s3) return 1;
    else return 0;
}
int main()
{
        IO;
        long double i, j, n, m, k, l, mx=0;
        cin>>n; n/=3;
        cout<<setprecision(15)<<n*n*n<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int k,a,b,i,flag=0;

  scanf("%d%d%d", &k,&a,&b);

  for(i=1;i<=b;i++){
    if(i*k>=a && i*k<=b) flag=1;
  }
  if(flag==1) printf("OK");
  else printf("NG");

  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    long long int n,in,aa=1,bb=1,ta,tb,ma,mb;
    vector<long long int> a,b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>in;
        a.push_back(in);
        cin>>in;
        b.push_back(in);
    }
    for(int i=0;i<n;i++){
        ta=a[i];tb=b[i];
        ma=(aa-1)/a[i]+1;
        mb=(bb-1)/b[i]+1;
        ma=max(ma,mb);
        aa=ma*a[i];bb=ma*b[i];
        //cout<<aa<<" "<<bb<<endl;
    }
    cout<<aa+bb<<endl;
}

Measured memory_bytes: 256
import sys

N = int(input())
A = [int(x) for x in input().split()]
A.sort()

ma = max(A)

L = [(abs(A[i] - ma / 2), i) for i in range(N)]
lmin = min(L)

a = ma
b = A[lmin[1]]

print('{} {}'.format(a,b))


Measured memory_bytes: 19680
import math



N = int(raw_input())
A = map(int, raw_input().split())
B = [0] * N

# print A

bad = False

for a in A:
    if N % 2 == 0: # even
        if a % 2 == 0: 
            bad = True
            break

    else:
        if a % 2 == 1:
            bad = True
            break

    r = (a + N - 1) / 2
    leftbig = r
    rightbig = N-1-r



    if leftbig < N and B[leftbig] < 1:
        B[leftbig] = 1
    else:
        if rightbig >= N: 
            bad = True
            break

        if B[rightbig] < 1:
            B[rightbig] = 1
        else:
            bad = True
            break

if bad:
    print '0'
else:
    if N % 2 == 0:
        print pow(2, N/2, 10**9+7)
    else:
        print pow(2, (N-1)/2, 10**9+7)




Measured memory_bytes: 11304
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;

int main(void){
	ll L, R;

	cin >> L >> R;

	ll ans = INF;
	bool finished = false;
	for (ll i = L; i <= R; i++){
		for (ll j = L; j <= R; j++){
			if (i >= j)continue;
			if (i * j % 2019 == 0){
				ans = 0;
				finished = true;
				break;
			}
			ans = min(ans, i * j % 2019);
		}
		if (finished)break;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
deque<int>check(deque<int>k)
{
	int t=k.size()-1;
	while(t>=0&&k[t]==9)
	{
		k[t]=0;
		t--;
	}
	if(t==-1)
		k.push_front(1);
	else
		k[t]++;
	while(1)
	{
		int b=-1;
		for(int i=0;i<k.size()-1;i++)
		{
			if(abs(k[i]-k[i+1])>1)
			{
				b=i;
				break;
			}
		}
		if(b==-1)
			break;
		if(k[b+1]>k[b])
			k[b]++;
		int res=max(k[b]-1,0);
		for(int i=b+1;i<k.size();i++)
		{
			k[i]=res;
			res=max(res-1,0);
		}
	}
	return k;
}
int main()
{
	int n;
	cin>>n;
	deque<int>sum;
	for(int i=0;i<n;i++)
		sum=check(sum);
	for(int i=0;i<sum.size();i++)
		cout<<sum[i];

	return 0;
}

Measured memory_bytes: 256
from fractions import gcd

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

if K > max(A):
  print('IMPOSSIBLE')
  exit()
g = A[0]
for i in range(1,N):
  g = gcd(g,A[i])
m = (K-min(A))/g
print('POSSIBLE' if m.is_integer() else 'IMPOSSIBLE')


Measured memory_bytes: 88300
mod = 10**9+7

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m) (aとmは互いに素)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m


L = list(input())
n = len(L)-1

#これだとTLEする

'''
number = 1
many = 0
for i in range(1,n+1):
  if int(L[i]) == 1:
    many += 3**(n-i) * 2**number %div
    number += 1
many += 2**number + 3**n
'''

beki3 = 3**n % mod
many = beki3
beki2 = 2
for i in range(1,n+1):
  beki3 = (beki3%mod)*mod_inv(3,mod)%mod
  if int(L[i]) == 1:
    many += beki3*beki2 %mod
    beki2 = beki2*2 %mod
many += beki2 % mod
print(many%mod)


Measured memory_bytes: 49392
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& vec) {
    out << "[";
    for (int x : vec) out << x << ", ";
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
    #define dbg_var(x) cerr << #x << ": " << x << endl;
#endif

int main() {
    string s;
    int w;
    cin >> s >> w;
    for(int i=0; i<(int)s.size(); i++){
        if(i % w == 0) cout << s[i];
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
N = int(input())
counter = {}
for i in input().split():
    if i not in counter:
        counter[i] = 1
    else:
        counter[i] += 1

M = int(input())
for i in input().split():
    if i not in counter or counter[i] == 0:
        print('NO')
        exit()
    else:
        counter[i] -= 1
print('YES')



Measured memory_bytes: 46432
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value )
      A[k] = L[i++];
    else
      A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n - 1);

  for ( i = 0; i < n; i++ )
    if ( A[i].suit != B[i].suit ) stable = 0;

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    printf("%c %d\n", B[i].suit, B[i].value);

  return 0;
}


Measured memory_bytes: 4920
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    W = LI()
    cumsum = accumulate(W)
    S=sum(W)
    ans = inf
    for i, c in enumerate(cumsum):
        ans=min(ans,abs((S-c)-c))
    print(ans)
if __name__ == '__main__':
    main()

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

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    int cost;
    if (n > k) {
        cost = x * k + y * (n - k);
    } else {
        cost = x * n;
    }

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(obj) (obj).begin, (obj).end()

int main() {
  ll A,B,V,W,T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  if (V <= W) {
    cout << "NO" << endl;
    return 0;
  }else{
    ll d = abs(A-B);
    ll vel = V-W;
    if (d <= T * vel){
      cout << "YES" << endl;
      return 0;
    }
    
  }
  cout << "NO" << endl;
  return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  int x[n],h[n],ans;
  for(int i=0;i<n;i++){
    cin>>x[i];
    h[i]=abs(k-x[i]);
    ans+=min(2*x[i] , 2*h[i]);
  }
  cout<<ans;

  
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline().strip())
A = map(int, sys.stdin.readline().strip().split())

ans = 0
neg_count = 0
zero_count = 0
a_min = float("inf")
for a_i in A:
    ans += abs(a_i)
    a_min = min(a_min, abs(a_i))
    if a_i == 0:
        zero_count += 1
    elif a_i < 0:
        neg_count += 1

#print(ans)
if neg_count % 2 == 0 or zero_count > 0:
    print(ans)
else:
    #print(a_min)
    print(ans - 2 * a_min)

Measured memory_bytes: 11212
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if ((a < b) && (b < c)){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return (0);
}

Measured memory_bytes: 580
a,b= input().split()

int(a)
int(b)

if(a=='1'):
  a= 14

if(b=='1'):
  b= 14

if(int(a)-int(b)>0):
  print("Alice")
elif(int(a)-int(b)< 0):
  print("Bob")
else:
  print("Draw")

Measured memory_bytes: 3060
N=int(input())
A=list(map(int,input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

j=lcm(A[0],A[1])
for i in range(2,len(A)):
    j=lcm(j, A[i])

tmp=[]
for i in A:
    tmp.append((j-1)%i)
ans=sum(tmp)
print(ans)


Measured memory_bytes: 3316
a,b,k = map(int,input().split())
taka = a
aoki = b
recur = k
if taka>=k:
  print("{} {}".format(taka-k,aoki))
elif k>=taka and (aoki+taka)>=k:
  print("{} {}".format(0,aoki-(k-taka)))
elif (aoki+ taka)<=k:
  print("0 0")



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

int main() {

        int n;
        std::cin >> n;

        while (true) {
                std::string s = std::to_string(n);

                if (std::all_of(s.begin(), s.end(), [&s](char v) { return v == s[0]; })) {
                        std::cout << s << std::endl;
                        return 0;
                }
                ++n;
        }

        return 0;
}

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

int main() {
    string S;
    cin >> S;

    int ans = 0;
    rep(i,0,S.length()) {
        int len = 0;
        while (S[i+len] == 'A' || S[i+len] == 'C' || S[i+len] == 'G' || S[i+len] == 'T') {
            len++;
            if (i+len == S.length()) break;
        }
        ans = len > ans ? len : ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

n = int( sys.stdin.readline() )
cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 }
for i in range( n ):
	pattern, num = sys.stdin.readline().split( " " )
	cards[ pattern ][ int( num )-1 ] = True

for pattern in ( 'S', 'H', 'C', 'D' ):
	for i in range( 13 ):
		if not cards[ pattern ][ i ]:
			print( "{:s} {:d}".format( pattern, i+1 ) )

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

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

#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  int A[3],a=0,b=0;

  rep(i,3){
    cin>>A[i];
    if(A[i]==5)a++;
    if(A[i]==7)b++;
  }

  if(a==2 and b==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
X,N = list(map(int, input().split()))
if(N==0):
  print(X)
else:
  p = list(map(int, input().split()))
  now1 = X
  now2 = X
  while(1):
    if(now1 not in p):
      print(now1)
      break
    elif(now2 not in p):
      print(now2)
      break
    now1 -= 1
    now2 += 1

Measured memory_bytes: 9188
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

counter = 0
for i in range(n):
  d = min(A[i], B[i])
  A[i] -= d
  B[i] -= d
  counter += d
  d = min(A[i+1], B[i])
  A[i+1] -= d
  B[i] -= d
  counter += d
print(counter)

Measured memory_bytes: 82276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,tot;
ll k;
int a[N],b[N],hs[N],t[N<<2],vis[N];
void build(int l,int r,int k)
{
    if(l==r){t[k]=vis[l];return;}
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
    t[k]=t[k<<1]+t[k<<1|1];
}
int query(int l,int r,int k,ll x)
{
    if(hs[l]>x||!t[k]) return -1;
    if(l==r){t[k]--;return hs[l];}
    int m=l+r>>1;
    int ans=query(m+1,r,k<<1|1,x);
    if(ans==-1) ans=query(l,m,k<<1,x);
    t[k]=t[k<<1]+t[k<<1|1];
    return ans;
}
int querymn(int l,int r,int k)
{
    t[k]--;
    if(l==r) return hs[l];
    int m=l+r>>1;
    if(t[k<<1]) return querymn(l,m,k<<1);
    return querymn(m+1,r,k<<1|1);
}
bool judge(ll m)
{
    ll sum=k;build(1,tot,1);
    for(int i=n;i>=1;i--)
    {
        int x=query(1,tot,1,m/a[i]);
        if(x==-1)
        {
            x=m/querymn(1,tot,1);
            sum=sum-(a[i]-x);
            if(sum<0) return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]),hs[i]=b[i];
    sort(a+1,a+1+n);sort(hs+1,hs+1+n);
    tot=unique(hs+1,hs+1+n)-hs-1;
    for(int i=1;i<=n;i++)
    {
        b[i]=lower_bound(hs+1,hs+1+tot,b[i])-hs;
        vis[b[i]]++;
    }
    ll l=0,r=1e18,ans;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m)) ans=m,r=m-1;
        else l=m+1;
    }
    printf("%lld\n",ans);
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> v(n);
  for(ll i=0;i<n;i++) cin >> v[i];
  vector<bool> dp(k+2);
  for(ll i=0;i<=k;i++){
    for(int x : v){
      if(i >= x && !dp[i-x]) dp[i] = true;
    }
  }

  if(dp[k]) cout << "First" << endl;
  else cout << "Second" << endl;

  cin.get();cin.get();
}


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

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<int>> cnt(h, vector<int>(w));
    rep(i, h) {
        vector<int> done(w);
        rep(j, w) {
            if (s[i][j] == '#') continue;
            if (done[j]) continue;
            int l = 0;
            while (j + l < w) {
                if (s[i][j + l] == '#') break;
                ++l;
            }
            rep(k, l) {
                cnt[i][j + k] += l;
                done[j + k] = 1;
            }
        }
    }
    rep(j, w) {
        vector<int> done(h);
        rep(i, h) {
            if (s[i][j] == '#') continue;
            if (done[i]) continue;
            int l = 0;
            while (i + l < h) {
                if (s[i + l][j] == '#') break;
                ++l;
            }
            rep(k, l) {
                cnt[i + k][j] += l;
                done[i + k] = 1;
            }
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
    cout << ans << endl;
    return 0;
}


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

int gcd(int a, int b) {
  while (a && b) {
    (a < b) ? b %= a : a %= b;
  }
  return a + b;
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b;}

int main(){
  int N;
  cin >> N;
  cout << lcm(2, N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){int n,a = 0,b = 0; scanf("%d",&n); for(int i=1;i<=n;i++){ int c; scanf("%d",&c);
if(!(c % 4)) a++; else if(!(c % 2)) b++;}
if((b > 1 && a * 2 >= n - b) || (b <= 1 && a * 2 + 1 >= n)) printf("Yes"); else printf("No");}

Measured memory_bytes: 128
class dice:
    value = [0] * 6
    def __init__(self, list):
        self.value = list

    def dice_roll(self,dir):
        if dir == "S":
            prev = self.value
            self.value = [prev[4],prev[0],prev[2],prev[3],prev[5],prev[1]]
        elif dir == "N":
            prev = self.value
            self.value = [prev[1],prev[5],prev[2],prev[3],prev[0],prev[4]]
        elif dir == "W":
            prev = self.value
            self.value = [prev[2],prev[1],prev[5],prev[0],prev[4],prev[3]]
        elif dir == "E":
            prev = self.value
            self.value = [prev[3],prev[1],prev[0],prev[5],prev[4],prev[2]]

mydice = dice(list(map(int, input().split())))
x = str(input())
for i in x:
    mydice.dice_roll(i)
print(mydice.value[0])


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

using namespace std;

bool pri[55556];

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

	for(int i = 1; i < 55556; i++)pri[i] = true;
	for(int i = 2; i < sqrt(55556); i++)
	{
		if(pri[i])
		{
			for(int j = 0; i * (j + 2) < 55556; j++)
			{
				pri[i *(j + 2)] = false;
			}
		}
	}
	int n;
	cin >> n;
	int now = 2;
	while(n)
	{
		if(pri[now] && now % 5 == 1)
		{
			cout << now << (n > 1 ? " " : "");
			n--;
			if(n == 0)break;
		}
		now++;
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, T;
  cin >> n;
  cin >> T;

  int minc = 1001;

  for (int i = 0; i < n; i++) {
    int c, t;
    cin >> c;
    cin >> t;

    if (T < t)
      continue;

    if (c < minc) {
      minc = c;
    }
  }

  if (minc == 1001) {
    cout << "TLE" << endl;
  } else {
    cout << minc << endl;
  }
}



Measured memory_bytes: 256
while (1):
    h, w = map(int, input().split())
    if (h == 0) and (w == 0):
        break
    a = ["#." * (w // 2) + "#" * (w % 2), ".#" * (w//2) + "." * (w % 2)]
    for i in range(h):
        print(a[i % 2])
    print()


Measured memory_bytes: 5612
#include <atcoder/all>
#define INF 1e9
using namespace std;
using namespace atcoder;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int n,q,t,u,v;
    cin>>n>>q;
    dsu d(n);
    while (q--) {
        cin>>t>>u>>v;
        if(t == 0) d.merge(u,v);
        else cout<<d.same(u,v)<<endl;
    }
}

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

Measured memory_bytes: 4024
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

int main() {
    ll n, m, l = 1;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n){
        cin >> a.at(i);
        l = lcm(l, a.at(i));
    }
    sort(rall(a));
    a.erase(unique(all(a)), a.end());
    ll now = a[0]/2;
    while(m >= now){
        bool ok = true;
        rep(i, n){
            if((now-(a[i]/2))%a[i] != 0)ok = false;
            if(!ok)break;
        }
        if(ok)break;
        now += a[0];
        if(m < now){
            cout << 0 << endl;
            exit(0);
        }
    }
    cout << (m - now + l) / l << endl;
}


Measured memory_bytes: 1024
#import <stdio.h>
#import <stdlib.h>
int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main(){
    int A[3];
    scanf("%d",A);
    scanf("%d",A+1);
    scanf("%d",A+2);
    qsort(A, 3, sizeof(int), compare_int);
    int z = 0;
    int a = A[1]-A[0];
    int b = A[2]-A[0];
    int r = a%2;
    int s = b%2;
    int result = 0;
    if (r==1 && s==0) {
        z++;
        b++;
        result++;
    }
    if (r==0 && s==1) {
        z++;
        a++;
        result++;
    }
    if (r==1 && s==1) {
        a++;
        b++;
        result++;
    }
    result += (b-z)/2 + (b-a)/2;
    printf("%d",result);
}


Measured memory_bytes: 7116
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull MOD = 1000000007;
ull hash(vector<int> v1,vector<int> v2){
  ull res=0,k=MOD,i;
  for(i=0;i<26;i++) res=(res*k+(v1[i]-v2[i]));
  return res;
}
int main(){
  string s1,s2;cin>>s1>>s2;
  int i,j,k,l,ans=0;
  if(s1.size()>s2.size()) swap(s1,s2);
  vector<int> v1[s1.size()+1],v2[s2.size()+1],e(26);
  set<ull> s;
  v1[0].resize(26,0);
  for(i=0;i<s1.size();i++){
    v1[i+1]=v1[i];
    v1[i+1][s1[i]-'a']++;
  }
  v2[0].resize(26,0);
  for(i=0;i<s2.size();i++){
    v2[i+1]=v2[i];
    v2[i+1][s2[i]-'a']++;
  }
  for(i=s1.size();i>0;i--){
    s.clear();
    for(j=0;j+i<=s1.size();j++){
      s.insert(hash(v1[j+i],v1[j]));
    }
    for(j=0;j+i<=s2.size();j++){
      if(s.find(hash(v2[j+i],v2[j]))!=s.end()){
	ans=i;
      }
    }
    if(ans) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  rep(i, n+1) rep(j, m+1) {
    ll tmp = n*m - i*j - (n-i)*(m-j);
    if(tmp == k) {
      cout << "Yes" << endk;
      return 0;
    }
  }
  cout << "No" << endk;
  return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[1100];
int c[1100];
int main(){
	int T=0;
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%d",c+i);
		for(int i=0;i<1100;i++)dp[i]=1010101010;
		dp[0]=0;
		for(int i=0;i<a;i++){
			int now=0;
			for(int j=i;j<a;j++){
				now+=c[j];
				dp[j+1]=min(dp[j+1],dp[i]+max(b-now,now-b));
			}
		}
		int ret=1010101010;
		int sum=0;
		for(int i=a-1;i>=0;i--){
			sum+=c[i];
			ret=min(ret,dp[i]+max(0,sum-b));
		}
		printf("Case %d: %d\n",++T,ret);
	}
}

Measured memory_bytes: 1036
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;

int n;
int x[10], y[10];

int facctorialMethod(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx * dx + dy * dy, 0.5);
}

int main() {
	
	cin >> n;
	
	for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	double sum = 0.0;
	vector<int> v(n);
	for (int i = 0; i < n; i++) v[i] = i + 1;

	do {
		for (int i = 0; i < n - 1; i++) sum += dist(v[i], v[i + 1]);
	} while (next_permutation(v.begin(), v.end()));

	int den = facctorialMethod(n);
	
	cout << fixed << setprecision(10) << sum / den << endl;
	return 0;
}


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


int main()
{
	int mou[10], m1=0, m2=0, m3=0,a1=0,a2=0;
	for (int i = 0;i < 10;i++)
		cin >> mou[i];

	for (int a = 0;a < 10;a++) {
		if (m1 < mou[a])
			m1 = mou[a];
	}
	for (int b = 0;b < 10;b++) {
		if (m1 == mou[b])
			a1++;
	}
	if (a1 == 2)
		m2 = m1;
	if (a1 > 2) {
		m2 = m1;
		m3 = m1;
	}
	
	for (int c = 0;c < 10;c++) {
		if (m2 < mou[c] && mou[c] < m1)
			m2 = mou[c];
	}
	for (int e = 0;e < 10;e++) {
		if (m2 == mou[e])
			a2++;
	}
	if (a2 > 2 && m1 != m2)
		m3 = m2;

	for (int d = 0;d < 10;d++) {
		if (m3 < mou[d] && mou[d] < m2)
			m3 = mou[d];
	}

	cout << m1 << endl << m2 << endl << m3 << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int m, t, p, r;
    while(cin >> m >> t >> p >> r, m){
        vector<array<int, 3>> v(t);
        vector<vector<int>> u(t, vector<int>(p));
        for (int i = 0; i < t; ++i) {
            v[i][2] = i+1;
        }
        for (int i = 0; i < r; ++i) {
            int a, b, c, d;
            scanf("%d%d%d%d", &a, &b, &c, &d);
            if(d == 0){
                v[b-1][0]++;
                v[b-1][1] -= a+u[b-1][c-1];
            }else {
                u[b-1][c-1] += 20;
            }
        }
        sort(v.begin(), v.end(), greater<>());
        printf("%d", v[0][2]);
        for (int i = 1; i < t; ++i) {
            if(v[i-1][0] == v[i][0] && v[i-1][1] == v[i][1]) printf("=");
            else printf(",");
            printf("%d", v[i][2]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  string S;
  cin>>S;
  for(int i=0;i<3;i++){
  if(S.at(i)=='1')cout<<'9';
    else if(S.at(i)=='9')cout<<'1';
    else cout<<S.at(i);
  }
  cout<<endl;
}

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

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

bool check(string s) {
	int c3 = 0, c5 = 0, c7 = 0;
	REP(i, SZ(s)) {
		if (s[i] == '3')c3++;
		else if (s[i] == '5')c5++;
		else if (s[i] == '7')c7++;
	}
	return (c3 != 0 && c5 != 0 && c7 != 0);
}

vector<int> n357;

void dfs(string s) {
	if (check(s))n357.PB(stoi(s));
	if (SZ(s) != 9) {
		dfs(s + "3");
		dfs(s + "5");
		dfs(s + "7");
	}
}

int main() {
	int n; cin >> n;
	string s;
	dfs(s);
	SORT(n357);
	int ans = 0;
	for (auto i : n357) {
		if (i <= n)ans++;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
int f[210000];
int main(){
	cin>>n;
	int x;
	for(int i=1;i<n;++i){
		scanf("%d",&x);
		f[x]++;
	}
	for(int i=1;i<=n;++i)  printf("%d\n",f[i]);
	return 0;
}




Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI 3.141592653589793238
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("/home/pushkar/cpp/input.txt", "r", stdin);
    // freopen("/home/pushkar/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    n = n%1000;
    if (n)
    cout << 1000 - n;
    else
    cout << "0";
    return 0;
}

Measured memory_bytes: 3612
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[110][100100]={0};
long long w[110],v[110];



int main() {
    cin>>a>>b;
    rep(i,a){
        cin>>w[i]>>v[i];
    }
    rep(i,a){
        rep(j,b+1){
            if(j-w[i]>=0){
                chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
                chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout<<dp[a][b]<<endl;
}


Measured memory_bytes: 79360
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        int result;
        if (k % 2 == 0) {
            result = a - b;
        } else {
            result = b - a;
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23124
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, k = LI()

    if n <= k:
        ans = 1
        for i in range(n):
            ans *= (k - i)
            ans %= MOD
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 6808
S = list(input())
#print(S)
ans = 'WA'
S2 = S.copy()
chr = [chr(i) for i in range(97, 97+26)]  
if S[0] == 'A' and S[2:-1].count('C') ==1  :
  del S2[0]
  S2.remove('C')
  for i in S2:
    if i in chr:
      ans = 'AC'
    else:
      ans = 'WA'
      break
      
print(ans)  


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include<math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	int n; cin >>n;
	vector<int> a(n);
	cinf(n,a);
	ll ans=1e18;
	for(int i=-100;i<=100;i++){
		ll sum=0;
		for(int j=0;j<n;j++){
			sum+=abs(a[j]-i)*abs(a[j]-i);
		}
		ans=min(ans,sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int k = Integer.parseInt(sc.next());
    String s = sc.next();
    if (s.length() <= k) {
      pw.println(s);
      return;
    }
    pw.println(s.substring(0, k) + "...");
  }
}


Measured memory_bytes: 38524
#include<iostream>
#include<bits/stdc++.h>
#define optimize() ios_base::sync_with_stdio(0);cin.tie();cin.tie();
using namespace std;

int main()
{

    optimize();
    set<int>s;
   int n;
   cin>>n;
   int a,b;
   while(n-->0){
    cin>>a;
    if(a==0){
        cin>>b;
        s.insert(b);
        cout<<s.size()<<"\n";
    }
    else if(a==1){
            cin>>b;
        if(s.find(b) == s.end())
            cout<<0<<"\n";
        else
            cout<<1<<"\n";
    }

    }

    return 0;
}



Measured memory_bytes: 12536
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = Integer.parseInt(sc.next());
			int m = Integer.parseInt(sc.next());
			if (n == 0 && m == 0) break;
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = Integer.parseInt(sc.next());
			int max = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					if (a[i] + a[j] <= m)
						max = Math.max(max, a[i] + a[j]);
				}
			}
			if (max == 0)
				System.out.println("NONE");
			else
				System.out.println(max);
		}
	}
}


Measured memory_bytes: 42420
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s, t;
  cin >> s >> t;
  if (s == t.substr(0, sz(s))) puts("Yes");
  else
    puts("No");
  return 0;
}


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

 ll gsc(ll a,ll b,ll p)
{
    ll ans=0;
    while(b)
    {
        if(b&1)
            ans=(ans+a)%p;
        a=(a+a)%p;
        b>>=1;
    }
    return ans%p;
}

inline ll qp(ll a,ll b,ll p)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=gsc(res,a,p);
        }
        a=gsc(a,a,p);
        b>>=1;
    }
    return res%p;
}

inline ll ol(ll x)
{
    ll res=x;
    for(ll i=2; i*i<=x; i++)
    {
        if(x%i==0)
        {
            res=res/i*(i-1);
            while(x%i==0)
                x/=i;
        }
    }
    if(x!=1)
        res=res/x*(x-1);
    return res;
}

int main()
{
    ll l;
    ll ans;
    scanf("%lld",&l);
    ll t=__gcd(7ll,l);
    ll c=9ll*l/t;
    if(__gcd(c,10ll)!=1)
    {
        printf("-1\n");
    }
    else
    {
        ll cnt=ol(c);
        ll ans=cnt;
        for(ll i=1; i*i<=cnt; i++)
        {
            if(cnt%i==0)
            {
                if(qp(10ll,i,c)==1)
                    ans=min(ans,i);
                if(qp(10ll,cnt/i,c)==1)
                    ans=min(ans,cnt/i);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<int,ull> piu;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=5e5+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int n,w,h;
int sr,sc;
string s,t;

bool go_right(){
    int x=sr,y=sc;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            y++;
            if(y>w)return 1;
        }
        if(t[i]=='L' && y>1){
            y--;
        }
    }
    return 0;
}

bool go_left(){
    int x=sr,y=sc;
    for(int i=0;i<n;i++){
        if(s[i]=='L'){
            y--;
            if(y==0)return 1;
        }
        if(t[i]=='L' && y<w){
            y++;
        }
    }
    return 0;
}

bool go_down(){
    int x=sr,y=sc;
    for(int i=0;i<n;i++){
        if(s[i]=='D'){
            x++;
            if(x>h)return 1;
        }
        if(t[i]=='U' && x>1){
            x--;
        }
    }
    return 0;
}

bool go_up(){
    int x=sr,y=sc;
    for(int i=0;i<n;i++){
        if(s[i]=='U'){
            x--;
            if(x==0)return 1;
        }
        if(t[i]=='D' && x<h){
            x++;
        }
    }
    return 0;
}

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

    cin>>h>>w>>n;
    cin>>sr>>sc;
    cin>>s>>t;
    if(go_right()){
        cout<<"NO";
        return 0;
    }
    if(go_left()){
        cout<<"NO";
        return 0;
    }
    if(go_up()){
        cout<<"NO";
        return 0;
    }
    if(go_down()){
        cout<<"NO";
        return 0;
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 920
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      int A = sc.nextInt();
      int B = sc.nextInt();
      String result = "NG";
      
      // 判定
      for(int i = A; i <= B; i++){
        if(i % K == 0){
          result = "OK";
          break;
        }
      }
      
      // 出力
      System.out.println(result);
    }

}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

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

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 main(void){
    int N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];

    ll dp[N+1][3][2]; REP(i,N+1)REP(j,3)REP(k,2) dp[i][j][k] = -LINF;
    dp[0][1][0] = 0;
    REP(i,N)REP(j,3)REP(k,2){
        int t = i/2 + j + 1 - (i+1)/2;
        if(t < 3) chmax(dp[i+1][t][1], dp[i][j][0] + A[i]);
        if(t > 0) chmax(dp[i+1][t-1][0], dp[i][j][k]);
    }
    ll ans = max(dp[N][1][0], dp[N][1][1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d=1,ans=0;scanf("%d",&n);
	for(int i=1;n>=d;i++){
		d*=10;
		if(i&1){
			if(n>=d)ans+=d/10*9;
			else ans+=n%d-(d/10)+1;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}
string ans;

void f(ll n) {
  n--;
  ll r = n % 26;
  ll q = (n - r) / 26;
  ans+='a'+r;
  if(q==0) return;
  f(q);
}

int main() {
  ll n;cin >> n;
  f(n);
  reverse(rng(ans));
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3612