akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

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

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e7 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int n, x, a[N];

void solve() {
	cin >> x >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	set <int> s;
	for (int i = 0; i < 102; i++)
		s.insert(i);
	for (int i = 0; i < n; i++)
		s.erase(a[i]);
	int diff = INF, ans = -1;
	for (int y : s) {
		if (abs(x - y) < diff)
			diff = abs(x - y), ans = y;
	}
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}
	
#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3652
MOD = 10 ** 9 + 7
 
N, K = map(int, input().split())
l = list(map(int, input().split()))
pos = []
neg = []
z = 0
 
for v in l:
    if v > 0:
        pos.append(v)
    elif v < 0:
        neg.append(v)
    else:
        z += 1
pos.sort()
neg.sort()
 
if N - z < K:
    print(0)
elif N - z == K:
    if len(neg) % 2 and z:
        print(0)
    else:
        out = 1
        for v in neg + pos:
            out *= v
            out %= 10 ** 9 + 7
        print(out)
elif len(pos) == 0:
    if K % 2:
        if z:
            print(0)
        else:
            neg.reverse()
            out = 1
            for i in range(K):
                out *= neg[i]
                out %= 10 ** 9 + 7
            print(out)
    else:
        out = 1
        for i in range(K):
            out *= neg[i]
            out %= 10 ** 9 + 7
        print(out)
else:
    out = 1
    neg.reverse()
    if K % 2:
        out = pos.pop()
        K -= 1
    while K:
        if len(pos) >= 2:
            nP = pos[-1] * pos[-2]
        else:
            nP = 0
 
        if len(neg) >= 2:
            nN = neg[-1] * neg[-2]
        else:
            nN = 0
 
        if nP > nN:
            pos.pop()
            pos.pop()
            out *= nP
        else:
            neg.pop()
            neg.pop()
            out *= nN
        out %= MOD
        K -= 2
    print(out)


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

int main() {
  ll n;
  cin >>n;
  ll diff = n-1;
  for(int i = 2; i<=n/i; i++){
    if(n%i==0){ 
      ll curDif = abs(i-2+n/i);
      if(curDif<diff) diff = curDif;
    }
  }
  cout << diff << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static void Main()
    {
        string input = Console.ReadLine();
        bool flag = true;
        for (int i = 0; i < input.Length / 2; i++)
        {
            if (input[i] != input[input.Length - i - 1] || input[i] != input[input.Length / 2 - i - 1] || input[input.Length - 1 - i] != input[input.Length/2 + 1+ i]) flag = false;
        }
        if (flag) { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100005,maxm=400005;
int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;
void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}
int main(){
	int n,m,x,y;
	while(cin>>n>>m){
		ll I=0,P=0,Q=0;
		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));
		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));
		for(int i=1;i<=m;++i){
				scanf("%d%d",&x,&y);add(x,y);add(y,x);
		}
		for(int i=1;i<=n;++i)if(!vis[i]){
				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;
				bool flag=1;
				while(head<tail){
    	              int u=q[++head];
    	              for(int j=last[u];j;j=pre[j]){
    	                     int v=other[j];
    	                     if(!vis[v]){
            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;
           	              	 }
							 else{
								 if((cal[v]-cal[u])%2==0)flag=0;
							 }
                       }
	            }
	  			if(head==1){++I;continue;}
	  			if(flag)++Q;
	  			else ++P;
		}
		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;
    }
	return 0;
}


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



int main(){
	int n,ans=0;
	char cr,c;
	cin>>n;
	for(int i=0; i<n; i++){
		if(i==0) cin>>cr;
		else{
			cin>>c;
			if(c!=cr){
				ans++;
				cr=c;
			}
		}
	}
	cout<<ans+1<<endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    LL n;
    cin >> n;
    LL lc = 1;
    for( int i = 0; i < n; ++i ) {
        LL a;
        cin >> a;
        lc = lcm(lc, a);

    }
    cout << lc << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n, k; cin >> n >> k;
    int cnt = 1;
    rep(i, n){
        cnt = min(2*cnt, cnt+k);
    }
    out(cnt);
}

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

int main() {
    int n,x=0;
    cin >> n;
    int n2 = n;
    while (n > 0) {
        x += n % 10;
        n = n / 10;
    }
    if (n2%x == 0)cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

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

MOD = 998244353

class BIT:
  def __init__(self, n):
    self.size = n
    self.tree = [0 for _ in range(n+1)]
    self.p = 2**(n.bit_length() - 1)
    self.dep = n.bit_length()

  def get(self, i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self, i, x):
    while i <= self.size:
      self.tree[i] += x
      i += (i & -i)

  def bl(self, v):
    if v <= 0:
      return -1
    s = 0
    k = self.p
    for _ in range(self.dep):
      if s + k <= self.size and self.tree[s+k] < v:
        s += k
        v -= self.tree[s+k]
      k //= 2
    return s + 1


def compress(L):
  L2 = list(set(L))
  L2.sort()
  C = {v: k for k, v in enumerate(L2, 1)}
  return L2, C


def main():
  n = int(input())
  ans = n * pow(2, n-1, MOD) % MOD
  xy = []
  for _ in range(n):
    xy.append(tuple(map(int, input().split())))
  xy.sort()
  py = [_xy[1] for _xy in xy]
  _, Cy = compress(py)
  py = [Cy[p] for p in py]
  BIT1 = BIT(n)

  for i in range(n):
    y = py[i]  # 注目する点
    c = BIT1.get(y)  # 左下
    d = y - c - 1  # 右下
    a = i - c  # 左上
    b = n - 1 - a - c - d  # 右上
    a2 = pow(2, a, MOD)
    b2 = pow(2, b, MOD)
    c2 = pow(2, c, MOD)
    d2 = pow(2, d, MOD)
    ans += (a2-1) * b2 * c2 * (d2-1)  # 絶対に左上右下は含む
    ans += a2 * (b2-1) * (c2-1) * d2  # 絶対に右上左下は含む
    ans -= (a2-1) * (b2-1) * (c2-1) * (d2-1)  # 数えすぎ
    ans %= MOD
    BIT1.add(y, 1)

  print(ans)


if __name__ == '__main__':
  main()

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

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<char> t(q);
    vector<char> d(q);
    for (int i = 0; i < q; i++) cin >> t[i] >> d[i];
    int ok = n;
    int ng = - 1;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        int now = mid;
        bool flag = true;
        for (int i = 0; i < q; i++){
            if (t[i] == s[now]){
                if (d[i] == 'L') now--;
                else now++;
            }
            if (now < 0) flag = false;
        }
        if (flag) ok = mid;
        else ng = mid;
    }
    int left = ok;
    ok = - 1;
    ng = n;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        int now = mid;
        bool flag = true;
        for (int i = 0; i < q; i++){
            if (t[i] == s[now]){
                if (d[i] == 'L') now--;
                else now++;
            }
            if (now >= n) flag = false;
        }
        if (flag) ok = mid;
        else ng = mid;
    }
    int right = ok;
    cout << right - left + 1 << endl;
}

Measured memory_bytes: 900
h,n = map(int,input().split())

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

max_d = max(a for a,b in ab_input)

dp =[0]*(h+max_d)
for i in range(1,h+max_d):
    dp[i]=min(dp[i-a]+b for a,b in ab_input)
print(dp[h])


Measured memory_bytes: 9508
#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np
import math
import sys
input = sys.stdin.readline
n,m= map(int,input().split())
A = []
B = []
for i in range(m):
    x,y = map(int,input().split())
    if x==1:
        A.append(y)
    elif y==1:
        A.append(x)
    elif x==n:
        B.append(y)
    elif y==n:
        B.append(x)
s  ="IMPOSSIBLE" if len(set(A + B)) ==len(A)+len(B) else "POSSIBLE"
print(s)



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

int main()
{
	int n; cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; ++i) cin >> v[i];
	int mini = v[0];
	int ans = 0;
	for(int i = 0; i < n; ++i)
	{
		if(v[i] <= mini)
		{
			++ans; 
			mini = v[i];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 n;
    cin >> n;
    string s;
    cin >> s;
    int allE = 0;int allW = 0;
    for(int i = 0;i<s.size();i++) {
        if(s[i] == 'E') allE++;
        else allW++;
    }
    int ans = s.size();
    int curE = 0;int curW = 0;
    for(int i = 0;i<s.size();i++) {
        if(s[i] == 'E') allE--;
        ans = min(ans,allE+curW);
        if(s[i] == 'W') curW++;
    }
    cout << ans << endl;
}

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

class AtCoder {
  public static void Main() {
    var inputs = Console.ReadLine().Trim().Split(' ');
    int N = int.Parse(inputs[0]);
    int K = int.Parse(inputs[1]);
    inputs = Console.ReadLine().Trim().Split(' ');
    int R = int.Parse(inputs[0]); // グーで勝ったときの得点、s（チョキ）のときに出す
    int S = int.Parse(inputs[1]); // チョキで勝ったときの得点、p（パー）のときに出す
    int P = int.Parse(inputs[2]); // パーで勝ったときの得点、r（グー）のときに出す
    string T = Console.ReadLine().Trim();
    int answer = 0;
    char[] c = T.ToCharArray();
    
    for(var i = 0; i < N; i++) {
      if(i - K >= 0 && c[i] == c[i - K]) {
        c[i] = 'x';
        continue;
      }
      if(c[i] == 's') {        
        answer += R;        
      }
      else if(c[i] == 'p') {        
        answer += S;        
      }
      else if(c[i] == 'r') {
        answer += P;
      }
      //Console.WriteLine(answer);
    }              
    Console.WriteLine(answer);
  }
}

Measured memory_bytes: 11488
using System;

namespace ABC070B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int A = int.Parse(bufs[0]);
            int B = int.Parse(bufs[1]);
            int C = int.Parse(bufs[2]);
            int D = int.Parse(bufs[3]);

            int res = Math.Min(B, D) - Math.Max(A, C);

            Console.WriteLine(res > 0 ? res : 0);
        }
    }
}


Measured memory_bytes: 13140
s = input()

left = int(s[:2])
right = int(s[2:])

if 0 < left <= 12 and 0 < right <= 12:
    print('AMBIGUOUS')
elif 0 < left <= 12 < right or right == 0 < left <= 12:
    print('MMYY')
elif 0 < right <= 12 < left or left == 0 < right <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int n;
    cin >> n;
    vector<i64> a(n);
    int mi = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (iabs(a[i]) > iabs(a[mi])) {
            mi = i;
        }
    }

    vector<pair<int, int>> res;
    for (int i = 0; i < n; ++i) {
        if (i != mi) {
            res.emplace_back(mi, i);
            a[i] += a[mi];
        }
        cerr << a[i] << ' ';
    }
    cerr << endl;

    if (a[mi] > 0) {
        for (int i = 0; i < n - 1; ++i) {
            res.emplace_back(i, i + 1);
            a[i + 1] += a[i];
        }
    } else {
        for (int i = n - 2; i >= 0; --i) {
            res.emplace_back(i + 1, i);
            a[i] += a[i + 1];
        }
    }
    for (int i = 0; i < n; ++i) {
        cerr << a[i] << ' ';
    }
    cerr << endl;

    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first + 1 << ' ' << p.second + 1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int ans = 0;
    int n;
    cin >> n;
    VII arr(n);
    for(auto &x:arr)
        cin >> x;

    for (int i = 0; i < n;i+=2)
        ans += arr[i] % 2;

    cout << ans;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000
int main(){
    ll N;
    cin >> N;
    ll a[N];
    for(ll i = 0; i < N; i++) cin >> a[i];
    ll x = a[0];
    ll y = accumulate(a, a + N, 0LL) - x;
    ll ans = abs(x-y);
    for(ll i = 1; i < N - 1; i++){
        x += a[i];
        y -= a[i];
        ans = min(ans,abs(x-y));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	long long n,t[100],m,p,x,sum=0;
	cin>>n;
	for(long long i=0;i<n;i++){
		cin>>t[i];
		sum+=t[i];
	}
	cin>>m;
	for(long long i=0;i<m;i++){
		cin>>p>>x;
		cout<<sum-(t[p-1]-x)<<endl;
	}
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
    vector<int> a(3);
    vector<int> b(3);
    rep(i, 3) cin >> a[i] >> b[i];

    vector<set<int>> g(5, set<int>());
    rep(i, 3){
        g[a[i]].insert(b[i]);
        g[b[i]].insert(a[i]);
    }
    
    rep(i, 5){
        if(g[i].size() == 3){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  int hantei=0;
  for(int i=n-1;i>0;i--){
    if(h[i-1]>h[i]){
      h[i-1]--;
    }
    if(h[i-1]>h[i]){
      hantei = 1;
      break;
    }
  }
  if(hantei == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

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

using namespace std;

bool isTriangle(long long a, long long b, long long c){
    bool cond1 = a < b + c;
    bool cond2 = b < c + a;
    bool cond3 = c < a + b;
    if(cond1 && cond2 && cond3){
        return true;
    }
    else {
        return false;
    }
}
 
int main(){
    long long N;
    cin >> N;
    vector<long long> sticks(N);
    for (long long i = 0; i < N; i++){
        cin >> sticks[i];
    }
    sort(sticks.begin(), sticks.end());
    int ans = 0;
    for (int i = 0; i < N - 1; i++){
        for (int j = i + 1; j < N; j++){
            int r  = lower_bound(sticks.begin(), sticks.end(), sticks[i] + sticks[j]) - sticks.begin();
            int l = j + 1;
            ans += r - l;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef struct {
    int no;
    char s[11];
    int p;
} rest;

int cmp( const void *p, const void *q ) {
    int n;
    n = strcmp(((rest*)p)->s ,((rest*)q)->s);
    if( n == 0 )  n = ((rest*)q)->p - ((rest*)p)->p;
    return n;
}

int main() {
    int i, j;
    int n, m;
    rest lst[101];

    scanf("%d\n", &n);
    for(i = 0; i < n; i++){
        scanf("%s %d\n", lst[i].s, &lst[i].p);
        lst[i].no = i+1;
    }

    qsort( lst, n, sizeof(rest), cmp );
    
    for(i = 0; i < n; i++){
        printf("%d\n", lst[i].no);
    }

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
    int X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}
int c[3005][3005];
int b[3005][3005];
char str1[3005],str2[3005];
int LCSLength()
{
    int length1,length2,len;
    length1=strlen(str1);
    length2=strlen(str2);
    for(int i=1;i<length1+1; i++)
    {
        for(int j=1;j<length2+1;j++)
        {
            if(str1[i-1]==str2[j-1])
            {
                c[i][j]=c[i-1][j-1]+1;
                b[i][j]=0;
            }
            else if(c[i-1][j]>c[i][j-1])
            {
                c[i][j]=c[i-1][j];
                b[i][j]=1;
            }
            else
            {
                c[i][j]=c[i][j-1];
                b[i][j]=-1;
            }
        }
    }
    len=c[length1][length2];
    return len;
}
void PrintLCS(int i, int j)
{
    if(i==0 or j==0)
        return ;
    if(b[i][j]==0)
    {
        PrintLCS(i-1, j-1);
        cout<<str1[i-1];
    }
    else if(b[i][j]==1)
        PrintLCS(i-1, j);
    else
        PrintLCS(i, j-1);
}
 
int main(void)
{
    int length1,length2,len;
    cin>>str1>>str2;
    length1=strlen(str1);
    length2=strlen(str2);
    len=LCSLength();
    PrintLCS(length1,length2);
    return 0;
}


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



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  ll c = n/(a+b);
  if(n-c*(a+b) > a)
    cout << (c+1)*a << "\n";
  else
    cout << n -c*b << "\n";

}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	vector<int> c(m);
	for (int i = 0; i < m; ++i) 
	{
		cin >> a[i] >> b[i];
		for (int j = 0; j < b[i]; ++j)
		{
			int input;
			cin >> input;
			input--;
			c[i] += (1 << input);
		}
	}

	const int INF = 1000000000;
	vector<int> dp(5000, INF);
	dp[0] = 0;
	for(int i = 0; i < m; i++)
	{
		int now = c[i];
		for(int mask = 0; mask < (1 << n); mask++)
		{
			dp[mask | now] = min(dp[mask | now], dp[mask] + a[i]);
		}
	}
	cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]);

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	String A=sc.next();
    	String B=sc.next();

    	int lengthA=A.length();
    	int lengthB=B.length();
    	
    	String result="";

    	if(lengthA>lengthB) {
    		result="GREATER";
    	}else if(lengthA<lengthB) {
    		result="LESS";
    	}else {
    		
    		if(A.compareTo(B)>0) {
    			result="GREATER";
    		}else if(A.compareTo(B)<0) {
    			result="LESS";
    		}else {
    			result="EQUAL";
    		}
    		
    	}

    	System.out.println(result);
    }

}



Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N;
        cin >> N;

        vector<ll> A(N);
        rep(i, 0, N) cin >> A[i];
        int minus = 0;

        for (int i = 0; i < N; ++i) {
            if (A[i] < 0) {
                minus++;
                A[i] = -A[i];
            }
        }
        sort(all(A));
        ll ans = accumulate(all(A), 0ll);
        if (minus % 2) {
            ans -= 2 * A[0];
        }

        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

using namespace std;

struct A {
    int place_n;
    int get;
    A() { get = 0; }
    bool operator<(const A& a) const {
        return (get < a.get);
    }
    static bool biggerA(const A& a, const A& b) {return (a.get > b.get);}
};

int main() {
    int n, m;
    while (cin >> n >> m, (n != 0 && m != 0)) {
        A a[m];
        for (int i = 0; i < m; i++) a[i].place_n = i+1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int wanna_go; cin >> wanna_go;
                if (wanna_go) a[j].get++;
            }
        }
        stable_sort(a, a+m, A::biggerA);
        cout << a[0].place_n;
        for (int i = 1; i < m; i++) {
            cout << ' ' << a[i].place_n;
        }
        cout << endl;
    }
    return 0;
}
            

Measured memory_bytes: 912
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };



int main() {
	int n;
	string s;
	cin >> n >> s;
	string abc = "ABC";
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s.substr(i, 3) == abc)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
void insertionSort(int * ,int);
int main(){
  int i,j,k;
  int A[N];
  scanf("%d",&k);
  for(i=0;i<=k-1;i++)
    scanf("%d",&A[i]);

  for(j=0;j<=k-1;j++){
    if(j==k-1) printf("%d",A[j]);
    else printf("%d ",A[j]);
     
      
    
    }
  printf("\n");
    insertionSort(A,k);

    
  
  return 0;
}

void insertionSort(int *A,int n){
  int i,v,j,k;
  for(i=1;i<=n-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
    j--;
    }
    A[j+1]=v;

    // output

    for(k=0;k<=n-1;k++){
       if(k==n-1) printf("%d",A[k]);
    
    else printf("%d ",A[k]);
     
    }
    printf("\n");
     
  }
 
}



Measured memory_bytes: 2708
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readLong()
    val f = primeFactor(n)
    var ans = 0L
    for (c in f.values) {
        var sum = 0L
        var i = 1L
        while (true) {
            sum += i
            if (sum > c) break

            ans++
            i++
        }
    }

    out.println(ans)
}

/**
O(n^(1/2)) // n * n <= Long.MAX_VALUE n <= 10^8 or more
if n == 1, return emptyMap
 */
fun primeFactor(n: Long): Map<Long, Long> {
    val factorMap = mutableMapOf<Long, Long>()
    var target = n
    var i = 2L
    while (i * i <= target) {
        while (target % i == 0L) {
            factorMap[i] = factorMap.getOrElse(i) { 0L } + 1L
            target /= i
        }
        i++
    }

    if (target != 1L) { factorMap[target] = 1 }
    return factorMap
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

using namespace std;

#define fr first
#define sc second
#define pii pair < int, int >
#define pb push_back
#define ll long long
#define int ll

const int inf = (int)1e18 + 7;

pii ar[5234];
int dp[5234];
int x;

bool comp (const pii &a, const pii &b) {
    return a.fr + a.sc < b.fr + b.sc;
}

main () {
    int n; scanf ("%lld", &n);
    for (int i = 1; i <= n; i++) {
        int a, b; scanf ("%lld %lld", &a, &b);
        ar[i] = {a, b};
    }
    for (int i = 0; i <= n; i++) {
        dp[i] = inf;
    }
    sort(ar + 1, ar + n + 1, comp);
    dp[0] = x;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j >= 1; j--) {
            if (ar[i].fr >= dp[j - 1]) {
                dp[j] = min(dp[j], dp[j - 1] + ar[i].sc);
            }
        }
    }
    vector < int > ans;
    while (dp[n] == inf) n--;
    printf ("%lld\n", n);
    return 0;
    while (n > 1) {
        for (int i = n - 1; i >= 1; i--) {
            if (dp[n] == dp[i] + ar[i].sc) {
                cout << i << ' ';
                n = i;
                break;
            }
        }
    }
    for (int to : ans) {
        printf ("%d ", to);
    }
}


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

int main(){
    string s;
    cin>>s;
    vector<bool> check(s.size()-1,false);
    ll ans=0;
    for(int bit=0;bit<(1<<s.size()-1);bit++){
      for(int i=0;i<s.size()-1;i++)check.at(i)=false;
        for(int i=0;i<s.size()-1;i++){
            if(bit&(1<<i)){
                check.at(i)=true;
            }
        }
        ll tmp=s.at(0)-'0';
        for(int j=0;j<s.size()-1;j++){
            if(check.at(j)){
                ans+=tmp;
                tmp=(s.at(j+1)-'0');
            }
            else tmp=tmp*10+(s.at(j+1)-'0');
        }
        if(tmp>0) ans+=tmp;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int a[100100],dp[100100];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%d",&a[1]);
	scanf("%d",&a[2]);dp[2]=max(a[1],a[2])-min(a[1],a[2]);
	for(int i=3;i<=n;i++){;
		scanf("%d",&a[i]);
		dp[i]=min(dp[i-1]+(max(a[i],a[i-1])-min(a[i],a[i-1])),dp[i-2]+(max(a[i],a[i-2])-min(a[i],a[i-2])));
	}
	printf("%d",dp[n]);
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,a=7,i=1;
  cin>>k;
  a=a%k;
  while(a!=0&&i<=k){
    a=(10*a+7)%k;
    i++;
  }
  if(i==k+1) i=-1;
    cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 3552
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
         Scanner sc = new Scanner(System.in);
         int a = sc.nextInt();
         int b = sc.nextInt();
         int c = sc.nextInt();
         
         int []d = {a,b,c};
         Arrays.sort(d);
         
         System.out.println(d[0] +" "+ d[1] + " " +d[2]);
         
         
         
	}}

Measured memory_bytes: 26376
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=310;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int f[N][N][N];
char s[N];
int main()
{
	//cout<<sizeof(f)/1024/1024<<endl;return 0;
	scanf("%s",s+1);
	int n=strlen(s+1),l,r,k,lim=gi(),ans=0;
	for (l=1;l<=n;l++)
		for (r=n;r>=l;r--)
			for (k=0;k<=lim;k++) {
				if (k||s[l]==s[r])
					upmax(f[l][r][k],f[l-1][r+1][k-(s[l]!=s[r])]+1+(l!=r));
				upmax(f[l][r][k],f[l-1][r][k]);
				upmax(f[l][r][k],f[l][r+1][k]);
				upmax(ans,f[l][r][k]);
			}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 114560
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

double dist(double a,double b,double c,double d){
	return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> x(n),y(n);
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
	}
	vector<int> v(n);
	int vv=1;
	for(int i=1;i<=n;i++){
		vv*=i;
	}
	for(int i=0;i<n;i++){
		v[i]=i;
	}
	double ans=0;
	do{
		double sum=0;
		for(int i=0;i<n-1;i++){
			sum+=dist(x[v[i]],y[v[i]],x[v[i+1]],y[v[i+1]]);
		}
		ans+=sum;
		//cout << sum << endl;
	}while(next_permutation(v.begin(),v.end()));
	//cout << ans << endl;
	printf("%.8f\n",(double)ans/vv );
} 


Measured memory_bytes: 384
#include <stdio.h>
 
int main()
{
    int a[3];
    int n, i, j, max;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
      
      max = 0;
      
      for(j = 0; j < 3; j++){
        scanf("%d", &a[j]);
        if(a[max] < a[j])
          max = j;
      }
      
      if(2*a[max]*a[max] == (a[1]*a[1]) + (a[2]*a[2]) + (a[0]*a[0]))
        puts("YES");
      else
        puts("NO");
    }
    
    return 0;
}

Measured memory_bytes: 2556
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 102
#define MAX 100005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"

const int inf = (int)1e18 + 10;

int dp[404][404];
int a[404] , pre[404];
signed main(){
  fast;
 int  n ; 
 cin >> n;
 for(int i = 1 ; i<=n ; i++)
 	for(int j = i ; j<=n ; j++)
 		dp[i][j] = inf;
 for(int i =1  ; i <= n ; i++) cin >> a[i]  , pre[i] = pre[i-1] + a[i];
 for(int l = 1 ; l<=n ; l++) 
 	for(int i = 1 ; i <= (n- l + 1) ; i++){
 		int j = i + l-1;
 		if(l == 1){
 		     dp[i][i] = 0;
 		     continue;
 	       }
 	      else if(l == 2){
 		      dp[i][j] = a[i] + a[j];
 		      continue;
 	          }
 		for(int k = i ; k< j ; k++)
 			dp[i][j] = min(dp[i][j] ,pre[j] - pre[i-1] +  dp[i][k] + dp[k + 1][j]);

 		// cout << i << " "<< j << " "<< dp[i][j]<<endl;
 	}




 	cout << dp[1][n]<<endl;


}	

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;

int main(){
  ULL a;
  cin>>a;
  if(a&1) cout<<0;
  else{
    a/=2;
    ULL ans=0;
    ULL p=5;
    ULL val=a/p;
    while(val){
      ans+=val;
      p*=5;
      val=a/p;
    }

    // p=50;
    // val=a/p;
    // while(val){
    //   ans+=val;
    //   p*=50;
    //   val=a/p;
    //}
    cout<<ans;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
    char s[101];
    scanf("%s",s);
    int flag=1;
    for(int i=0;i<strlen(s);i+=2){
        if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
            flag=0;
            break;
        }
    }
    for(int i=1;i<strlen(s);i+=2){
        if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
            flag=0;
            break;
        }
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
    return 0;

}


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

using namespace std;

#define MAX 1299710
#define SQRTMAX 1141

bool prime[1299709];

int main()
{
    prime[0] = prime[1] = false;
    fill(prime+2, prime+MAX, true);
    for(int p=2; p<SQRTMAX; p++)
    {
        if(prime[p])
        {
            for(int i=2*p; i<MAX; i+=p)
            {
                prime[i] = false;
            }
        }
    }

    int n;
    while(cin >> n, n)
    {
        if(prime[n])
        {
            cout << 0 << endl;
        }
        else
        {
            int f = n;
            int t = n;
            while(!prime[f]) f--;
            while(!prime[t]) t++;
            cout << t - f << endl;
        }

    }
}

Measured memory_bytes: 4304
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
    int l; cin>>l;
    int b[21]={};
    int k=0,s=0;
    FOR(i,0,21){
        if((l>>i)&1){
            b[i]++;
            s++; 
            k=i;
        }
    }
    int n=k+1,m=k*2+s-1;
    printf("%d %d\n",n,m);
    FOR(i,0,k){
        printf("%d %d %d\n",i+1,i+2,0);
        printf("%d %d %d\n",i+1,i+2,(1<<(k-1-i)));
    }
    int t=(1<<k);
    b[k]=0;
    ROF(i,0,21){
        if(b[i]){
            printf("%d %d %d\n",1,n-i,t);
            t+=(1<<i);
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

}

Measured memory_bytes: 72356
import sys
n = int(raw_input())

building_a = [[0 for j in range(11)] for i in range(4)]
building_b = [[0 for j in range(11)] for i in range(4)]
building_c = [[0 for j in range(11)] for i in range(4)]
building_d = [[0 for j in range(11)] for i in range(4)]

for i in range(n):
    b, f, r, v = map(int, raw_input().split())
    if b == 1:
        building_a[f][r] += v
    elif b == 2:
        building_b[f][r] += v
    elif b == 3:
        building_c[f][r] += v
    elif b == 4:
        building_d[f][r] += v
        
for i in range(1, 4):
    print "",
    for j in range(1, 11):
        print building_a[i][j],
    print 
for i in range(20):
    sys.stdout.write("#")
print

for i in range(1, 4):
    print "",
    for j in range(1, 11):
        print building_b[i][j],
    print 
for i in range(20):
    sys.stdout.write ("#")
print

for i in range(1, 4):
    print "",
    for j in range(1, 11):
        print building_c[i][j],
    print 
for i in range(20):
    sys.stdout.write("#")
print

for i in range(1, 4):
    print "",
    for j in range(1, 11):
        print building_d[i][j],
    print

Measured memory_bytes: 6372
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k){
		cout << s;
	}else{
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout << "...";
	}
}


Measured memory_bytes: 3628
st=input()
B=[1 if st[0]=='B' else 0]
tot=0
for i in range(1,len(st)):
    if st[i]=='B':
        B.append(B[i-1]+1)
    else:
        B.append(B[i-1])
        tot+=B[i-1]
print(tot)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int, int>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int n; cin >> n;
  vector<int> A(n); REP(i, n) cin >> A[i];
  int q; cin >> q;
  vector<int> m(q); REP(i, q) cin >> m[i];
  vector<string> a(q, "no");
  for(int bit = 0; bit < (1 << n); ++bit) {
    int sum = 0;
    for(int i = 0; i < n; ++i) {
      if(bit & (1 << i)) {
        sum += A[i];
      }
    }
    REP(i, q) {
      if(m[i] == sum) a[i] = "yes";
    }
  }
  REP(i, a.size()) {
    cout << a[i] << endl;
  }
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;
static const ll MOD = 1000000007;


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

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

    deque<int> d;
    rep(i, n) {
        int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (p == 0) {
            d.push_front(a[i]);
        } else {
            d[p - 1] = a[i];
        }
    }

    int ans = d.size();
    cout << ans << endl;

}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=110;
int n,x;
int a[maxn];

int main() {
    scanf("%d%d",&n,&x);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=0;
    for (int i=0;i<n;i++) {
        x-=a[i];
        if (x<0) break;
        ans++;
    }
    printf("%d\n", x>0?ans-1:ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cctype>

using namespace std;

int main(){
	
	int a[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	int x,y;
	cin>>x>>y;
	
	
	if(a[x]==a[y]){
		cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
	
	
return 0;
}

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

int y[1000010];
int same[1000010];

bool divisor(int n)
{
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (y[i] == 1 || y[n / i] == 1)
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int a[200010];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    memset(y, 0, sizeof y);
    memset(same, 0, sizeof same);
    for (int i = 0; i < n; i++)
    {
        same[a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (divisor(a[i]) == true && same[a[i]] <= 1)
        {
            ans++;
        }
        y[a[i]] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12168