akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll n;
	cin >> n;
	vl h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vl ima(n, 0);
	ll a = -1;
	ll b = -1;
	bool one = true;
	bool two = true;
	ll ans = 0;
	for (int i = 0; i < 10000; i++) {
		for (int j = 0; j < n; j++) {
			if (one) {
				if (ima[j] < h[j]) {
					a = j;
					one = false;
				}
			}
		}
		if (a != -1) {
			for (int k = a; k < n; k++) {
				if (two) {
					if (ima[k] >= h[k]) {
						b = k - 1;
						two = false;
					}
				}
				if (k == n-1 && b == -1) {
					b = n - 1;
				}
			}
		}
		if (a != b && a != -1 && b != -1) {
			for (int l = a; l <= b; l++) {
				ima[l]++;
				if (l == b) {
					ans++;
				}
			}
		}
		else {
			if (a == b && a != -1 && b != -1) {
				ima[a]++;
				ans++;
			}
			else {
				break;
			}
		}
		one = two = true;
		a = b = -1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3696
N, M = map(int, input().split())
ab = []
ans = -1
for i in range(M):
    a, b = map(int, input().split())
    ab.append([min(a, b), max(a, b)])
root_1i = [0 for i in range(N)]
root_iN = [0 for i in range(N)]
ab.sort()
for i in ab:
    if i[0] == 1:
        root_1i[i[1] - 1] = 1          
    elif i[1] == N and root_1i[i[0] - 1] == 1:
        print("POSSIBLE")
        ans = 1
        break
#print(root_1i)
if ans == -1:
    print("IMPOSSIBLE")


Measured memory_bytes: 40220
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    int n;
    cin >> n;
    string s;
    map < string, int > cnt;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        sort(all(s));
        ++cnt[s];
    }
    ll ans = 0;
    for (auto &x: cnt) {
        ans += (1ll * x.S * (x.S - 1)) / 2;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 11264
#include<cstdio>
#include<vector>
#include<cstdlib>
using namespace std;

#define ll long long

struct node{
	int u,v;
} c[100005];

int i,t,j;
int n,nt,a,b,u,v,mx;
bool viu[100005],viv[100005];

vector<int> e[100005];

void dfsu(int id, int dis){
	if (viu[id]) return;
	
	c[id].u=dis;
	viu[id]=1;
	
	int j;
	for (j=0; j<(int)e[id].size(); ++j){
		dfsu(e[id][j],dis+1);
	}
}

void dfsv(int id, int dis){
	if (viv[id]) return;
	
	c[id].v=dis;
	viv[id]=1;
	
	int j;
	for (j=0; j<(int)e[id].size(); ++j){
		dfsv(e[id][j],dis+1);
	}
}

int main(){
	scanf("%d%d%d",&n,&u,&v);
	
	for (i=1; i<n; ++i){
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	
	dfsu(u,0);
	dfsv(v,0);
	
	for (i=1; i<=n; ++i){
		//printf("id:%d u:%d v:%d\n",i,c[i].u,c[i].v);
		
		if (c[i].v>c[i].u){
			mx=max(c[i].v,mx);
		}
	}
	printf("%d\n",mx-1);
	
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
   ll n;cin>>n;
   ll a[n];f(i,0,n)cin>>a[i];
   ll b[n];f(i,0,n)cin>>b[i];
   ll c[n-1];f(i,0,n-1)cin>>c[i];
   ll sum=0;
    f(i,0,n){
       if(i==0)sum+=b[a[i]-1];
       else {
           sum+=b[a[i]-1];
           if(a[i]==a[i-1]+1)sum+=c[a[i-1]-1];
       }
   }
   cout<<sum;
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  rep(i, N)
  {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  rep(i, N)
  {
    cout << S[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(int argc, char**argv){
  
  int n_num,x_num;
  std::cin>>n_num>>x_num;
  std::vector<int> l_num;
  l_num.resize(n_num);
  
  for(size_t i = 0 ; i < l_num.size() ; i++){
    std::cin>>l_num[i];
  }
  int bcount=0,pos=0;
  for(int i = 0 ; i < n_num ; i++){
    pos += l_num[i];
    if(pos<=x_num){
      bcount++;
    }
  }
  if(0<x_num){
    bcount++;
  }
  std::cout<<bcount<<std::endl;
 
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long num = sc.nextLong();
		long min = Long.MAX_VALUE;
		for(int i = 0; i < 5; i++) {
			long l = sc.nextLong();
			if(min > l)
				min = l;
		}
		long sum = num / min + 4;
		sum += num % min == 0 ? 0 : 1;
		System.out.println(sum);
		
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 1010;

int n,t;
int M[N],L[N],K[N];
int mod[N];

int c[N];
int ed[N];

const int INF = 191919;
inline bool check(int x){
    fill(c,c+N,INF);
    fill(ed,ed+N,0);
    int op = x;

    rep(i,t+1){
        // end operation
        op += ed[i];

        rep(j,n)if(c[j]==INF){
            if(i+M[j]>t) return false;

            int mt = i%mod[j];
            if(mt<=L[j] && op>0){
                --op;
                int et = i+M[j];
                c[j] = et;

                if(et<=t) ++ed[et];
            }
        }
    }

    rep(i,n)if(c[i]>t) return false;
    return true;
}

int main(){
    while(scanf(" %d %d", &n, &t),n){
        rep(i,n){
            scanf(" %d %d %d", &M[i], &L[i], &K[i]);
            mod[i] = (L[i]+K[i]);
        }

        int ok=1;
        while(ok<=n && !check(ok)) ++ok;
        printf("%d\n",ok);
    }
    return 0;
}



Measured memory_bytes: 3116
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <sstream>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

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

int main() {
    ios::sync_with_stdio(false);
    int x, n;
    cin >> x >> n;
    int p;
    int ans;
    vector v(102, 0);

    for (int i = 0; i < n; i++) {
        cin >> p;
        v[p] = 1;
    }

    if (n == 0) {
        ans = x;
    } else {
        if (v[x] == 0) {
            ans = x;
        }

        for (int i = 0; i < 100; i++) {
            if (i >= 0 && v[x - i] == 0) {
                ans = x - i;
                break;
            }
            if (i <= 101 && v[x + i] == 0) {
                ans = x + i;
                break;
            }
        }
    }

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


Measured memory_bytes: 3192
S, T = map(str,input().split())
A, B = map(int,input().split())
U = str(input())

if S == U:
    A -= 1
    l = [A,B]
    print(' '.join(map(str,l)))
elif T == U:
    B -= 1
    l = [A, B]
    print(' '.join(map(str, l)))

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int N, Q; string S;
    cin >> N >> S >> Q;
    
    vector<set<int>> vsi(26);
    for (int i = 0; i < S.size(); ++i) {
        vsi[S[i] - 'a'].insert(i);
    }
    for (int i = 0; i < Q; ++i) {
        int t; 
        cin >> t;
        if (t == 1) {
            int p; char c;
            cin >> p >> c; p--;
            char sc = S[p];
            vsi[sc - 'a'].erase(p);
            S[p] = c;
            vsi[c - 'a'].insert(p);
        } else {
            int l, r;
            cin >> l >> r; l--; r--;
            int ans = 0;
            for (char c = 0; c < 26; ++c) {
                auto it = vsi[c].lower_bound(l);
                if (it != vsi[c].end() && *it <= r) ans++;
            }
            cout << ans << endl;
        }
    }
}


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

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.rbegin(), a.rend());
  int ans = 0;
  int b, c;
  b = (a[0] - a[1])/2;
  c = (a[0]-a[2])/2;
  ans += b+c;
  a[1] += b*2;
  a[2] += c*2;
  if (a[1] != a[0] && a[2] != a[0]) ans++;
  else if ((a[1] != a[0] && a[2] == a[0]) || (a[1] == a[0] && a[2] != a[0])) ans +=2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
string s;
signed main(){
	 cin>>s;
	 if(s[0]==s[1]&&s[1]==s[2])cout<<"No"<<endl;
	 else cout<<"Yes"<<endl;
}


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

antip = set(range(-110,210)) - set(p)
dist = 1000
ans = 1000
for v in antip:
    can = abs(v - X)
    if(can < dist):
        dist = can
        ans = v
    if(can == dist):
        ans = min(ans, v)
print(ans)

Measured memory_bytes: 9168
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
typedef long long LL;
int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	if(a + k - 1 < b - k + 1)
	{
		for(int i = a; i <= a + k - 1; i++)
			printf("%d\n", i);
		for(int i = b - k + 1; i <= b; i++)
			printf("%d\n", i);
	}
	else
	{
		for(int i = a; i <= b; i++)
			printf("%d\n", i);
	}
	return 0;
}

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

int main()
{
char c1[3],c2[3];
cin>>c1[0]>>c1[1]>>c1[2];
cin>>c2[0]>>c2[1]>>c2[2];
if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0])
    cout<<"YES";
else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    vi C(N);
    vvi A(N, vi(M));
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        for (int j = 0; j < M; j++)
            cin >> A[i][j];
    }

    int min_cost = SINT_MAX;
    for (int bit = 0; bit < (1<<N); ++bit)
    {
        int cost = 0;
        vi rikai(M, 0);

        for (int i = 0; i < N; ++i)
        {
            if (bit & (1<<i))
            {
                cost += C[i];
                for (int j = 0; j < M; j++)
                {
                    rikai[j] += A[i][j];
                }
            }

        }

        if (all_of(begin(rikai), end(rikai), [X](int r){ return r >= X; }))
        {
            min_cost = min(min_cost, cost);
        }
    }

    if (min_cost == SINT_MAX)
    {
        min_cost = -1;
    }
    
    cout << min_cost << endl;
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int N;
	int i;
	int64_t mikakosi = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		int V;
		if (scanf("%d", &V) != 1) return 1;
		mikakosi += V - i;
	}
	printf("%" PRId64 "\n", mikakosi);
	return 0;
}



Measured memory_bytes: 2144
using System;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            char A = char.Parse(input[0]), T = char.Parse(input[1]);
            if (A == T)
            {
                Console.WriteLine("H");
            }
            else
                Console.WriteLine("D");
        }
    }
}

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

int main()
{
	int n;
	cin >> n;
	double p[n+1];
	for(int i=1;i<=n;i++)
		cin >> p[i];

	double dp[n+1][n+1];  ///prob of i coins tossed with j heads
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
			dp[i][j]=0;
	}
	dp[0][0]=1;

	for (int i = 1; i <=n; ++i)
	{
		dp[i][0] = (1-p[i])*dp[i-1][0];
		for(int j=1;j<=n;j++)
		{
			dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
		}
	}

	double ans=0;
	for(int i=1;i<=n;i++)
	{
		int tails = n-i;
		if(i>tails)
			ans+=dp[n][i];
	}

	printf("%.10f", ans);
	return 0;
}


Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();

		int count = 0;

		for (int i = 1; i * a <= t + 0.5; i++ ) {
			count = count + b;
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	char cc;
	bool aa = false, bb = false;
	for(int64 ii = 0;ii < 3;ii++)
	{
		cin >> cc;
		if(cc == 'A')
		{
			aa = true;
		}
		else
		{
			bb = true;
		}
	}
	if(aa && bb)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
    int n,a[105]={},p,s=0,smin=1e9;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(p=1;p<=100;p++){
        s=0;
        for(int i=1;i<=n;i++){
             
            s+=(a[i]-p)*(a[i]-p);

        }
        smin=min(s,smin);
    }
    cout<<smin;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    int N;
    cin >> N;
    int a = N - N / 2;
    // cout << (double)a / (double)N << endl;
    printf("%.10f\n", (double)a / (double)N);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, K; cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)

int main(){
	int a,b; 
	auto f = [](int x,int y){
		int ans=0,k=x+y;
		while(k){
			ans++;
			k /= 10;
		}
		return ans;
	};
	while(scanf("%d %d",&a,&b)!=EOF){
		cout << f(a,b) << endl;
	}
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<char>>M(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
  string S;
    cin>>S;
    for(int j=1;j<=W;j++){
   M[i][j]=S.at(j-1);
  }
  }
  for(int i=1;i<=H;i++){
  for(int j=1;j<=W;j++){
    int sum='0';
    if(M[i][j]=='.'){
    for(int I=i-1;I<=i+1;I++){
    for(int J=j-1;J<=j+1;J++){
    if(M[I][J]=='#')
      sum++;
    }
    }
   M.at(i).at(j)=sum;}
    }
  }for(int i=1;i<=H;i++){
  for(int j=1;j<=W;j++){
  if(j!=W)
    cout<<M.at(i).at(j);
    else
      cout<<M.at(i).at(j)<<endl;
  }
  }
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	using namespace __gnu_pbds;
	using namespace std;
	#define all(x)     		(x).begin(),(x).end()
	#define ub    			upper_bound
	#define lb 				lower_bound
	#define ins				insert
	#define int 			long long
	#define endl			'\n'
	#define ff              first
	#define ss              second
	#define ull				unsigned long long
	#define pb              push_back
	#define mp              make_pair
	#define pii             pair<int,int>
	#define vi              vector<int>
	#define si 				set<int>
	#define usi 			unordered_set<int>		
	#define mii             map<int,int>
	#define umii			unordered_map<int ,int>
	#define pqb             priority_queue<int>
	#define pqs             priority_queue<int,vi,greater<int> >
	#define rep(i,a,n)		for(int i=a;i<n;++i)
	#define repd(i,a,n)		for(int i=a;i>n;--i)
	#define setbits(x)      __builtin_popcountll(x)
	#define zerobits(x)      __builtin_ctzll(x)
	#define Mod             1000000007
	#define inf             1e18
	#define ps(x,y)         fixed<<setprecision(y)<<x
	#define mk(arr,n,type)  type *arr=new type[n];
	#define w(x)            int x; cin>>x; while(x--)
	#define deb(x)			cout<<#x <<"="<<x<<endl;
	#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
	mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
	int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
	int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
	int log(int x){return 64-__builtin_clzll(x)-1;}
	
	void c_p_p()
	{
		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	}
	struct Node
	{
		int a,b,c,d;
		
	};
	bool cmp(Node A,Node B)
	{
		return A.a<B.a;
	}
	const int Max=1e5+1;
	
	int32_t main()
	{
		c_p_p();
		int x,y;
		cin>>x>>y;
		if(y>4*x || y<2*x)cout<<"No";
		else
		{
			bool foo=0;
			while(x--)
			{
				if(y>=4)y-=4;
				else y-=2;
				if(y==0)foo=1;

			}
			if(foo)cout<<"Yes";
			else cout<<"No";
		}
		return 0;
	}
		


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] s = new int[n];
    	for (int i = 0; i < n; i++) {
    		s[i] = sc.nextInt();
    	}

//    	System.out.println(bubbleSort(s));
    	System.out.println(mergeSort(s, 0, n));

    	sc.close();
	}
	
	public static int bubbleSort(int[] a) {
		  int cnt = 0; // 反転数
		  for (int i = 0; i < a.length; i++) {
			  for (int j = a.length - 1; j > i; j--) {
				  if (a[j] < a[j - 1]) {
					  int temp = a[j];
					  a[j] = a[j - 1];
					  a[j - 1] = temp;
					  cnt++;
				  }
			  }
		  }

		  return cnt;
	}

	public static long mergeSort(int[] a, int left, int right) {
		long cnt = 0; // 反転数
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			cnt += mergeSort(a, left, mid);
			cnt += mergeSort(a, mid, right);
			cnt += merge(a, left, mid, right);
		}

		return cnt;
	}

	public static long merge(int[] a, int left, int mid, int right) {
		long cnt = 0; // 反転数
		int n1 = mid - left;
		int n2 = right - mid;
		int[] l = new int[n1 + 1];
		int[] r = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			l[i] = a[left + i];
		}
		for (int i = 0; i < n2; i++) {
			r[i] = a[mid + i];
		}
		l[n1] = Integer.MAX_VALUE;
		r[n2] = Integer.MAX_VALUE;
		
		for (int i = 0, j = 0, k = left; k < right; k++) {
			if (l[i] <= r[j]) {
				a[k] = l[i];
				i++;
			} else {
				a[k] = r[j];
				j++;
				cnt += n1 - i;
			}
		}
		
		return cnt;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;

		private Scanner() {
		}

		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}

		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return st.sval;
		}

		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return (int)st.nval;
		}

		void close() {
		}
	}
}

Measured memory_bytes: 48196
S = list(input())

ans = 0
cnt = 0
i = 0
while i < len(S):
    first = S[i]
    if first == 'A' or first == 'C' or first == 'G' or first == 'T':
        cnt += 1
        ans = max(ans, cnt)
    else:
        ans = max(ans, cnt)
        cnt = 0
    i += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int k=0;
  for(int i=0;i<n;i+=2)
    if(a[i]%2==1)
       k++;
  cout<<k<<endl;
  return 0;
} 

Measured memory_bytes: 3580
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int A, B; cin >> A >> B;
    string S; cin >> S;
    rep(i, 0, S.size()) {
      if ((i == A and S[i] != '-') or (i != A and (S[i] < '0' or S[i] > '9'))) {
        cout << "No" << endl;
        return 0;
      }
    }
  
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
def bubble_sort(A):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(len(A)-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                count += 1
    return A, count

if __name__ == '__main__':
    n = int(input())
    A = [int(x) for x in input().split()]
    result_A, count = bubble_sort(A)
    print(*result_A)
    print(count)


Measured memory_bytes: 5612
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    from collections import deque as d
    N, M = map(int, readline().split())
    m = map(int, read().split())
    AB = zip(m, m)
    graph = [[] for _ in range(N + 1)]
    for a, b in AB:
        graph[a].append(b)
        graph[b].append(a)
    que = d([1])
    ans = [0]*(N+1)
    while que:
        x = d.popleft(que)
        for i in graph[x]:
            if ans[i] != 0:
                continue
            ans[i] = x
            que.append(i)
    for a in ans[2:]:
        if a == 0:
            print('No')
            break
    else:
        print('Yes')
        print('\n'.join(map(str, ans[2:])))

    return

if __name__ == '__main__':
    main()


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

long long adj[101][101];
vector<vector<int>> edges;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    // edge a -> b should be a shortest path between a and b
    // but what if it isnt
    // a different shortest path :o

    int n, m, a, b, c; cin >> n >> m;

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            adj[i][j] = 1e9;

    for(int i = 0; i < m; ++i){
        cin >> a >> b >> c;
        --a; --b;
        adj[a][b] = adj[b][a] = c;
        edges.push_back({a, b, c});
    }

    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);

    long long tot = 0;

    for(auto i : edges)
        if(adj[i[0]][i[1]] != i[2])
            ++tot;

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int sum=0;
  for(int i=1;i<=n;i++){
    string s=to_string(i);
    int part=0;
    for(int j=0;j<s.size();j++){
      part+=s[j]-'0';
    }
    if(part>=a && part <=b)sum+=i;
  }
  cout<<sum<<endl;
}
    


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

int main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	int l,r;
	int i,j;
	int hoge=0,piyo=n;
	for(i=0;i<m;i++){
		scanf("%d %d",&l,&r);
		if(hoge<l)hoge=l;
		if(piyo>r)piyo=r;		
	}
	int ans=piyo-hoge+1;
	if(ans<0)ans=0;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 1e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	string s; cin>>s;
	int sum = 0;
	for(auto x: s) sum += x - '0';
	cout<<(sum%9 ? "No" : "Yes");
}

Measured memory_bytes: 3768
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Edge {
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using Ugraph = vector<vector<int>>;

vector<i64> bellmanFord(const Edges &es, int V, int src)
{
    vector<i64> dist(V, LINF);
    dist[src] = 0;

    bool updated = true;
    for (int i = 0; updated && i < V-1; ++i) {
        updated = false;
        for (const auto &e : es) {
            if (dist[e.src] == LINF) continue;
            updated |= chmin(dist[e.to], dist[e.src] + e.cost);
        }
    }

    return dist;
}

vector<bool> checkNegativeCycle(const Edges &es, int V, const vector<i64> &dist)
{
    vector<bool> negative(V, false);
    for (int i = 0; i < V; ++i) {
        for (const auto &e : es) {
            if (dist[e.src] < LINF) {
                if (dist[e.to] > dist[e.src] + e.cost) negative[e.src] = true;
                if (negative[e.src]) negative[e.to] = true;
            }
        }
    }
    return negative;
}

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

    int V, E;
    cin >> V >> E;

    Edges es;
    for (int i = 0; i < E; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        --s, --t;
        es.emplace_back(s, t, -c);
    }

    const auto dist = bellmanFord(es, V, 0);

    if (checkNegativeCycle(es, V, dist)[V-1]) {
        cout << "inf" << endl;
    } else {
        cout << -dist[V-1] << endl;
    }
    return 0;
}


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

int main(){
    int n, ac = 0, wa = 0, tle = 0, re = 0;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        string buf;
        cin >> buf;
        if (buf == "AC") {
            ac++;
        } else if (buf == "WA") {
            wa++;
        } else if (buf == "TLE") {
            tle++;
        } else if (buf == "RE") {
            re++;
        }
    }
    
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    
    return 0;
}


Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	private static final char A = 'A';
	private static final char B = 'B';
	private static final char C = 'C';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] count = new int['Z'];
			count[A] = scanner.nextInt();
			count[B] = scanner.nextInt();
			count[C] = scanner.nextInt();
			char[][] s = new char[n][];
			IntStream.range(0, n).forEach(i -> s[i] = scanner.next().toCharArray());
			List<String> answer = new ArrayList<>();
			boolean result = true;
			for (int i = 0; i < n; i++) {
				if (0 == count[s[i][0]] + count[s[i][1]]) {
					result = false;
					break;
				}
				if (count[s[i][0]] > count[s[i][1]]) {
					count[s[i][0]]--;
					count[s[i][1]]++;
					answer.add(String.valueOf(s[i][1]));
				} else if (count[s[i][0]] < count[s[i][1]]) {
					count[s[i][0]]++;
					count[s[i][1]]--;
					answer.add(String.valueOf(s[i][0]));
				} else {
					// count[s[i][0]] == count[s[i][1]]
					if (i < n - 1) {
						// 次のパターンで判定する
						if ((s[i][0] == s[i + 1][0]) && (s[i][1] == s[i + 1][1])) {
							// 次のパターンが同じとき
							count[s[i][0]]++;
							count[s[i][1]]--;
							answer.add(String.valueOf(s[i][0]));
						} else if ((s[i][0] == s[i + 1][0]) || (s[i][0] == s[i + 1][1])) {
							// 次のパターンと同じ文字のものを+1とする
							count[s[i][0]]++;
							count[s[i][1]]--;
							answer.add(String.valueOf(s[i][0]));
						} else {
							count[s[i][0]]--;
							count[s[i][1]]++;
							answer.add(String.valueOf(s[i][1]));
						}
					} else {
						count[s[i][0]]++;
						count[s[i][1]]--;
						answer.add(String.valueOf(s[i][0]));
					}
				}
			}
			System.out.println(result ? "Yes" : "No");
			if (result) {
				answer.forEach(System.out::println);
			}
		}
	}
}


Measured memory_bytes: 68400
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N, M = parseMap(split(readline()))
    A = parseMap(split(readline()))
    sort!(A, rev=true)
    if A[M] < sum(A)/(4*M)
        println("No")
    else
        println("Yes")
    end
end

main()

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

void show( int arr[], size_t size )
{
	cout<<arr[1];
	for( size_t i=2; i<size; i++ ){
		cout<<' '<<arr[i];
	}
	cout<<endl;
}

void bucketSort( int arr[], const size_t arr_s, const int min, const int max )
{
//	size_t cnt_s=max - min +1;
	size_t cnt_s=max+2;
	int *cnt=new int[cnt_s];

	for( size_t i=0; i<cnt_s; i++ ){//
		cnt[i]=0;
	}


	for( size_t i=1; i<arr_s; i++ ){//
		cnt[ arr[i] ]++;
	}


	for( size_t i=1; i<cnt_s; i++ ){
		cnt[i]= cnt[i] + cnt[i-1];
	}

	int *sorted=new int[arr_s];
	for( size_t i=arr_s-1; i>0; i-- ){//
		sorted[ cnt[ arr[i]]]= arr[i];
		cnt[ arr[i] ]--;
		
	}

	show(sorted, arr_s);
	
	/*
	for( size_t i=1; i<arr_s; i++ ){
		arr[i]=sorted[i];
	}
	*/

	

	delete[] cnt;delete[] sorted;

}



int main()
{
	//arr : ???????????????
	size_t arr_s;	cin>>arr_s;arr_s++;
	int *arr=new int[arr_s];

	int max=INT_MIN;
//	int min=INT_MAX;

	for( size_t i=1; i<arr_s; i++ ){
		cin>>arr[i];

//		if( arr[i] < min ) min=arr[i];
		if( arr[i] > max ) max=arr[i];
	}



	bucketSort( arr, arr_s, 0, max );
//	show(arr, arr_s);
	
	delete[] arr;


}

Measured memory_bytes: 16864
import qualified Data.Text as T
import qualified Data.Text.IO as TI
import Control.Applicative
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
import Control.Arrow
import Data.Maybe
import Control.Monad

read'::T.Text->Int
read'=read.T.unpack

game::(Num a,Ord a)=>(a,a)->(a,a)
game (a,b) = 
	if a > b then
		(a+b,0)
	else if a==b then
		(a,b)
	else
		(0,a+b)
		
tailMay::[a]->Maybe [a]	
tailMay (_:xs) = Just xs
tailMay [] = Nothing

add::Num a=>(a,a)->(a,a)->(a,a)
add (a,b) (c,d) = (a+c,b+d)

convert::Show a=>(a,a)->String
convert (a,b) = show a++" "++show b

(<$~>)::Functor f => f a -> (a -> b) -> f b 
(<$~>)=flip (<$>)
infixl 4 <$~>

checkMaybe::(a->Bool)->a->Maybe a
checkMaybe f v = if f v then Just v else Nothing

toTuple (a:b:[])=(a,b)
{-run::IO (Maybe ())
run = runMaybeT$
    lift TI.getContents<$~>
    T.lines>>=
    (MaybeT).return.checkMaybe ((/=T.pack "0").head)>>=
    (MaybeT).return.tailMay>>=
    fmap (T.split (==' '))<$~>
    fmap (fmap read')<$~>
    fmap toTuple<$~>return>>=
     (MaybeT).return.sequence>>=
    fmap game<$~>
    foldr add (0,0)<$~>
    convert<$~>return
    >>=lift.putStrLn-}
run = runMaybeT$ do{
	n<-read<$>lift getLine;
	if n==0 then 
		MaybeT$return$Nothing 
	else
		return ();
	lift (sequence (replicate n TI.getLine))<$~>
		fmap (T.split (==' '))<$~>
		fmap (fmap read')<$~>
		fmap toTuple<$~>
		fmap game<$~>
		foldr add (0,0)<$~>
		convert>>=
		lift.putStrLn;
}
whileMaybeM::Monad m=>m(Maybe a)->m ()
whileMaybeM f = do
	r<-f
	if isJust r then
		whileMaybeM f
	else
		return ()
main = whileMaybeM run

Measured memory_bytes: 8208
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int n,m,x;
	cin >> n >> m >> x;
	int a[m];
	for(int i = 0; i < m; i++) {
		cin >> a[i];
	}
	int mi = 0;
	for(int i = x; i >= 0; i--) {
		for(int j = 0; j < m; j++) {
			if(a[j] == i) mi++;
		}
	}
	int sum = 0;
	for(int i = x; i <= n; i++) {
		for(int j = 0; j < m; j++) {
			if(a[j] == i) sum++;
		}
	}
	cout << min(mi,sum) << endl; 

	
}


Measured memory_bytes: 256
from fractions import gcd
n=int(input())
a = [int(i) for i in input().split()]
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
ans=0
for x in a:
  ans+=lcm//x
print(ans%mod)

Measured memory_bytes: 6112
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
      if(abs(list_p[i] - x) < t):
        t = abs(list_p[i] - x)
        num = list_p[i]
      elif(abs(list_p[i] - x) == t):
        t = abs(list_p[i] - x)
        num = min(num, list_p[i])
print(num) 


Measured memory_bytes: 9108
#include <iostream>
#include <string>
int main() {
    std::string s, p, m = "Yes";
    std::cin >> s >> p;
    s += s;
    std::string::size_type i = s.find(p);
    if (i == std::string::npos) {
        m = "No";
    }
    std::cout << m << std::endl;
}



Measured memory_bytes: 3228
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
    int n, t;
    int maxi, mini;
    scanf("%d", &n);
    scanf("%d", &t);
    maxi = -1000000001; mini = t;
    for (int i = 1; i < n; i++) {
        scanf("%d", &t);
        // 先更新当前的最大值
        maxi = maxi < t - mini ? t - mini : maxi;
        // 再更新当前最小值
        mini= mini > t ? t : mini;
    }
    printf("%d\n", maxi);
}


Measured memory_bytes: 3220
from time import time
stime = time()

from copy import copy
from random import randint

def get_fav_contest(s, t):
    s = copy(s)
    t = copy(t)
    dc = 0
    d = len(t)
    for i in range(1, d):
        dc += s[i][t[i]]
        ca[t[i]] = i
        dc -= sum([c[i2] * (i - ca[i2]) for i2 in range(1, 27)])
    return dc

d = int(input())
c = [0] + list(map(int, input().split(' ')))

s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)]

t = 0 # 算出結果
tl = [0]

ca = [0] * (1 + 26) # 放置された不満の数々
cat = [] # 不満度の最適な算出のための一時配列
cat2 = []

for i in range(1, d + 1):
    cat = [0]
    for i2 in range(1, 27):
        cat2 = copy(ca)
        cat2[i2] = i
        cat.append(s[i][i2] + sum(c[i3] * (i - ca[i3]) for i3 in range(1, 27)))
    t = cat.index(max(cat))
    ca[t] = i
    tl.append(t)

default_t = get_fav_contest(s, tl)

ch = 0 # 適当に選んだ日
temp1 = 0 # 一時的に保存する場所
tempt = 0
while time() - stime < 1.95:
    ch = randint(1, 365)
    temp1 = tl[ch]
    tl[ch] = randint(1, 26)
    tempt = get_fav_contest(s, tl)
    if tempt < default_t:
        tl[ch] = temp1
    else:
        default_t = tempt
print('\n'.join(map(str, tl[1:])))

Measured memory_bytes: 9988
#include<cstdio>
#include<cstring>
#include<queue>

using namespace std;

char prime[200005];

int main(void) {
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = 0;
    for(int i=2; i<=1e5+1e3; i++) {
        if(!prime[i]) continue;
        for(int j=2; i*j<=1e5+1e3; j++)
            prime[i*j] = 0;
    }

    while(true) {
        int n,p;
        scanf("%d%d", &n, &p);
        if(n == -1) break;

        priority_queue<int,vector<int>,greater<int> > pool;
        for(int i=n+1; i < n+2000; i++) {
            if(!prime[i]) continue;
            for(int j=i; j < i+2000; j++) {
                if(!prime[j]) continue;
                pool.push(i+j);
            }
        }
        for(int i=0; i<p-1; i++)
            pool.pop();
        printf("%d\n", pool.top());

    }
}

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

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

  if (n%10 == 3) {
    cout << "bon" << endl;
  } else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}


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

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,n+1){
        if(i==0) continue;
        if(i%3==0) continue;
        if(i%5==0) continue;
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define EPS (1e-10)
int K;
double R,L;
double P,E,T;
double Q;
 
double rec(int depth,double l,double r){
  double m=(l+r)/2.0;
  if(depth==K)return ((T-E<m&&m<T+E)?1:0);
  if(r<T-E || T+E<l)return 0;
  if(T-E<l && r<T+E)return 1;
  double A=rec(depth+1,l,m);
  double B=rec(depth+1,m,r);
  if(m>=T)return A*Q+B*P;
  else return A*P+B*Q;
}
 
int main(){
  while(cin>>K>>R>>L){
    cin>>P>>E>>T;
    Q=1.0-P;
    printf("%.10f\n",rec(0,R,L));
  }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define re return

template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcount __builtin_popcount
#define mp make_pair
#define pb push_back
#define ins insert
#define sc second
#define fr first
#define endl "\n"
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)

int n, v[N], dp[N];
int f(int i){
    if(i==n-1)return 0;
    if(i>=n)return MOD;
    if(dp[i]!=-1)return dp[i];
    return dp[i] = min(abs(v[i]-v[i+1])+f(i+1) ,abs(v[i]-v[i+2])+f(i+2));

}
void solve(){
    cin >> n;
    clr(dp,-1);
    forn(i,0,n)cin >> v[i];
    cout << f(0) << endl;
}
int main(){_
    solve();
     /*
    int t; cin >> t;
    while(t--){
        solve();
    }
   */
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int N;
    int S;
    cin >> N >> S;
    // vector <int> v(N);
    const long long MOD = 998244353;

    vector <long long> dp1(S+1);
    // dp[n][v] = dp[n-1][v-vx] + dp[n-1][v]

    dp1[0] = 1;
    int sum = 0;

    for (int i = 0; i < N; ++i) {
        int v;
        cin >> v;

        vector <long long> dp2(S+1);

        for (int val = 0; val <= sum; ++val) {
            dp2[val] += dp1[val]*2;
            dp2[val] %= MOD;

            if (val+v <= S) {
                dp2[val+v] += dp1[val];
                dp2[val+v] %= MOD;
            }
        }

        sum = min(sum+v, S);
        dp1 = dp2;
        // cin >> v[i];
    }

    cout << dp1[S] << endl;

    return 0;
}

Measured memory_bytes: 3660