akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

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

int x,n;
cin>>x>>n;

int arr[n+1];
set<int>s;
for(int i=0;i<n;i++){
    cin>>arr[i];
    s.insert(arr[i]);
}
int a=x;
int b=x;
int ans;
while(1){

    int l=s.count(a);
    int m=s.count(b);

    if(l==0){
      ans=a;
      break;
    }
    else if(m==0){
        ans=b;
        break;
    }
    a--;
    b++;

}

cout<<ans;

}


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

int main() {
  long long int h,w,ans;
  ans=0;
  cin>>h>>w;
  if(h==1||w==1){
    ans=1;
  }else if(h*w%2==0){
    ans=h*w/2;
  }else{
    ans=h*w/2+1;
  }
  cout<<ans<<endl;
}


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

using namespace std;

//int compare(int a, int b){
//    if (a>b) return b;
//    else return a;
//}
int main() {
    vector<int> array = {};
    int nb;
    for (int i = 0; i<10; i++) {
        scanf("%d", &nb);
        array.push_back(nb);
    }
    sort(array.begin(),array.end());
    reverse(array.begin(),array.end());
    for (int i = 0; i<3; i++){
        printf("%d\n", array[i]);
    }
}

Measured memory_bytes: 3208
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// -------------------------------------------------------------------------------------

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep1(i, n+1) {
    ans = (ans * i) % MOD;
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e5+5;
int  a[N];

int main()
{
	IOS;
	string s;
	cin >> s;
	int cnt = 0;
	for(int i =0; i < s.size();i++)
	{
		if(i%2 == 0 && s[i] == '0')
		{
			cnt++;
		}
		else if(i%2 and s[i] == '1')
		{
			cnt++;
		}
	}
	int cnt1 = 0;
	for(int i =0; i < s.size();i++)
	{
		if(i%2 == 0 && s[i] == '1')
		{
			cnt1++;
		}
		else if(i%2 and s[i] == '0')
		{
			cnt1++;
		}
	}
	cout << min(cnt,cnt1);
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int x;
	scanf("%d",&x);
	for(int a=1;a<=x;a++){
		if(a%3==0){
			printf(" %d",a);
		}
		else{
			int b=a;
			while(b>0){
				if(b%10==3){
					printf(" %d",a);
					break;
				}
				b=b/10;
			}
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  n--;
  string ans;
  while(n >= 26){
    int alpa = n % 26;
    n /= 26;
    n--;
    if(alpa == 0){
      ans += char('a' + alpa);
    }
    else{
      ans += char('a' + alpa);
    }
  }
  if(n == 0){
      ans += char('a' + n);
      n--;
    }
  else{
    ans += char('a' + n);
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3608
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll a,b,n;
  cin >> a >> b >> n;
  ll x = min(b-1,n);
  cout << (a*x)/b + a * (x/b)<<endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<map>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const long long maxn = 1e18+7;
const int mod = 1e9+7;
map<long long, long long>dp;
long long func(long long x)
{
    if(dp[x])return dp[x];
    return dp[x] = (func(x/2) + func((x-1)/2) + func((x-2)/2))%mod;
}

int main()
{
    long long n;
    cin >> n;
    dp[0] = 1;
    dp[1] = 2;
    cout << func(n) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = inp[0];
        int b = inp[1];
        int k = inp[2];
        int c = 0;
        for (int i = Math.Min(a, b); ; i--)
        {
            if (a % i == 0 && b % i == 0)
                c++;
            if (c == k)
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}


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

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
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 c = sc.nextInt();
		if(a+b+c>=22) {
			System.out.println("bust");
		}else {
			System.out.println("win");
		}
	}
}

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

struct Dice {
	int s[6];
	void roll(char c) {
		int b;
		if (c == 'E') {
			b = s[0];
			s[0] = s[3];
			s[3] = s[5];
			s[5] = s[2];
			s[2] = b;
		}
		else if (c == 'W') {
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
		else if (c == 'N') {
			b = s[0];
			s[0] = s[1];
			s[1] = s[5];
			s[5] = s[4];
			s[4] = b;
		}
		else if (c == 'S') {
			b = s[0];
			s[0] = s[4];
			s[4] = s[5];
			s[5] = s[1];
			s[1] = b;
		}
	}

	int top() {
		return s[0];
	}
};

int main(void) {
	Dice d;
	for (int i = 0; i < 6; i++) cin >> d.s[i];
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) d.roll(s[i]);
	cout << d.top() << endl;
	
	return 0;
}


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

int main(){
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if (vec[0] == 5 && vec[1]==5 && vec[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int ans = 0;
    for(int i = 0; i < 1000000; i++) {
        int a = y*i + z*(i+1);
        if(a <= x) ans = i;
        else break;
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
int h[100010];
bool g[100010];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>h[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		if(h[x]>=h[y])g[y]=1;
		if(h[x]<=h[y])g[x]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)if(g[i]==0)ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)
#define int long long

template <class T>
struct CumulativeSum {
   private:
    ::std::vector<T> data;

   public:
    CumulativeSum(){};
    CumulativeSum(int sz) : data(sz, 0){};
    CumulativeSum(::std::vector<T> v) { build(v); }

   private:
    T query(int k) {
        if(k < 0) return (0);
        return (data[std::min(k, (int)data.size() - 1)]);
    }

   public:
    T query(int l, int r) {
        if(l < 0 || r > data.size()) return (0);
        return query(r - 1) - query(l - 1);
    }
    void add(int k, T x) { data[k] += x; }
    void build() {
        for(int i = 1; i < data.size(); i++) data[i] += data[i - 1];
    }
    void build(::std::vector<T> &v) {
        data = v;
        for(int i = 1; i < data.size(); i++) data[i] += data[i - 1];
    }
};

void solve() {
    int n;
    scanf("%d", &n);
    std::vector<i64> a(n);
    rep(i, n) scanf("%lld", &a[i]);
    CumulativeSum<i64> s(a);
    std::vector<std::pair<i64, i64>> left(n), right(n);
    int ok, ng;
    std::vector<int> ans;
    repeat(i, 2, n - 1) {  // iで真ん中をぶった切る
        i64 sum_of_left = s.query(0, i);
        i64 sum_of_right = s.query(i, n);
        ok = i, ng = -1;
        while(ok - ng > 1) {
            int mid = ng + (ok - ng) / 2;
            if(s.query(0, mid) > sum_of_left / 2) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        if(abs(s.query(0, ok) - (sum_of_left - s.query(0, ok))) > abs(s.query(0, ng) - (sum_of_left - s.query(0, ng)))) {
            left[i].first = s.query(0, ng);
            left[i].second = sum_of_left - s.query(0, ng);
        } else {
            left[i].first = s.query(0, ok);
            left[i].second = sum_of_left - s.query(0, ok);
        }
        ok = n, ng = i;
        while(ok - ng > 1) {
            int mid = ng + (ok - ng) / 2;
            if(s.query(i, mid) > sum_of_right / 2) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        if(abs(s.query(i, ok) - (sum_of_right - s.query(i, ok))) > abs(s.query(i, ng) - (sum_of_right - s.query(i, ng)))) {
            right[i].first = s.query(i, ng);
            right[i].second = sum_of_right - s.query(i, ng);
        } else {
            right[i].first = s.query(i, ok);
            right[i].second = sum_of_right - s.query(i, ok);
        }
        // printf("%lld %lld %lld %lld\n", left[i].first, left[i].second, right[i].first, right[i].second);
        ans.emplace_back(std::max({left[i].first, left[i].second, right[i].first, right[i].second}) - std::min({left[i].first, left[i].second, right[i].first, right[i].second}));
    }
    printf("%lld\n", *std::min_element(begin(ans), end(ans)));
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
  string d="AIDUNYAN";
  string z="AIZUNYAN";
  string str;
  cin>>str;

  for(int i=0;i<str.size();i++){
    int cnt[1<<8]={};
    for(int j=0;j<8;j++) cnt[str[i+j]]++;
    int check=0;
    for(int j=0;j<8;j++) if(cnt[d[j]]) cnt[d[j]]--,check++;
    if(check==8){
      for(int j=0;j<8;j++) str[i+j]=z[j];
      i+=7;
    }
  }
  cout <<str<<endl;

}

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

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;

    string t,ci;
    int ty,fi;
    rep(i,q){
        cin >> ty;
        if(ty==1){
            swap(s,t);
        }else{
            cin >> fi >> ci;
            if(fi==1){
                t += ci;
            }else{
                s += ci;
            }
        }
    }
    reverse(t.begin(),t.end());
    t += s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1128
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, ans;
vector<P>v[16];
int h[16];
int main() {
	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			P p; cin >> p.first >> p.second;
			--p.first;
			v[i].push_back(p);
		}
	}
	rep(i, (1 << n)) {
		bool can = true;
		int cnt = 0;
		rep(j, n) {
			h[j] = (bool)(i & (1 << j));
			if (h[j]) ++cnt;
		}
		rep(j, n) {
			if (h[j] == 0) continue;
			rep(k, v[j].size()) {
				if (h[v[j][k].first] != v[j][k].second) {
					can = false; break;
				}
			}
			if (!can) break;
		}
		if (can) ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n = input();
    int a = input(), b = input();
    int sw = false;
    for(int i = 1; n*i <= b; ++i){
        if(a <= n*i and n*i <= b){
            sw = true;
            break;
        }
    }
    (sw)? puts("OK"): puts("NG");
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s;
    int k;
    cin >> s >> k;
    char c = 'z';
    rep(i, s.length())
    {
        if (c > s[i])
        {
            c = s[i];
        }
    }

    setstr st;
    rep(i, s.length())
    {
        for (int j = 1; j < min((int)s.length() - i, 6) + 1; ++j)
        {
            st.insert(s.substr(i, j));
        }
    }
    auto itr = st.begin();
    rep(i, k - 1)
    {
        itr = next(itr);
    }
    cout << *itr << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a){
        cout << k << endl;
    }else if(k <= a + b){
        cout << a << endl;
    }else{
        cout << a - (k - a - b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3664
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner fs = new Scanner(System.in);
        int n = fs.nextInt();
        long[] inp = new long[n];
        for(int i=0 ; i<n ; i++){
            inp[i] = fs.nextLong();
        }

        int ans = 0 ;

        for(int i=0 ; i<n ; i++){
            for(int j=i+1 ; j<n ; j++){
                if(inp[i]==inp[j]){
                    continue;
                }
                for(int k= j+1 ; k<n ; k++){
                    if(inp[k]==inp[i] || inp[k]==inp[j]){
                        continue;
                    }else{
                        long a = inp[i];
                        long b = inp[j];
                        long c = inp[k];
                        if((a+b > c) && (b+c>a) && (c+a>b)){
                            ans++;
                        }
                    }
                }
            }
        }

        System.out.println(ans);

    }
}


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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(N+1, vector<int>(2));
  A[0][0] = 0;
  A[0][1] = 0;
  for (int i = 1; i < N+1; ++i){
    int t, x, y; cin >> t >> x >> y;
    A[i][0] = t, A[i][1] = x + y;
  }
  
  
  bool judge;
  rep(i, N){
    int t_diff = abs(A[i+1][0] - A[i][0]);
    int sum_diff = abs(A[i+1][1] - A[i][1]);
    if (t_diff >= sum_diff && t_diff % 2 == sum_diff % 2) judge = 1;
    else {
      judge = 0;
      break;
    }
  }
  
  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 5760
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

int main() {
   
   int A, B, K;
   std::cin >> A >> B >> K;
   for (int i = A; i <= B; i++) {
      if (i < A + K || i > B - K) std::cout << i << std::endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int n,m;
    cin>>n>>m;
    vpi vt;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        vt.push_back(make_pair(a,b));
    }
    sort(all(vt));
    int l=vt[0].first;
    int r=vt[0].second;
    for(int i=1;i<m;i++){
        int x=vt[i].first;
        int y=vt[i].second;
        l=max(x,l);
        r=min(r,y);
        if(l>r){
            out(0);
            return;
        }
    }
    out(r-l+1);
    return;

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
	cout << a << "\n";
}

int main(int argc, const char * argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll>> sc;
    for(ll i=0; i< m; ++i){
        ll a,b;
        cin >> a >> b;
        sc.emplace_back(a,b);
        if(n>=2 && a==1 && b==0){
            cout << -1 << endl;
            return 0;
        }
    }

    sort(sc.begin(),sc.end(),greater< pair<ll,ll> >());
    sc.erase(unique(sc.begin(),sc.end()),sc.end());
    ll out=0;
    for(auto p : sc){
        if(out > ll(pow(10,n-p.first))){
            cout << -1 << endl;
            return 0;
        }
        out += p.second * ll(pow(10,n-p.first)); //1
    }
    if(out / ll(pow(10,n-1)) == 0)
        if(n==1){
            cout << 0 << endl;
        }else{
            cout << out+ll(pow(10,n-1)) << endl;
        }
    else
        cout << out << endl;


	return 0;
}



Measured memory_bytes: 384
N = int(input())
C = input()
S = [0]*(N+1)
for i in range(1, N+1):
    if C[i-1] == "R":
        S[i] = S[i-1]+1
    else:
        S[i] = S[i-1]

R_cnt = S[-1]
print(R_cnt - S[R_cnt])

Measured memory_bytes: 16756
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[100010], num;
vector<P> vec;
ll n, k;

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

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n >> k;
	if (n * (n - 1) / 2 - (n - 1) < k)
	{
		cout << -1 << endl;
	}
	else
	{
		ll unite = (n - 2) * (n - 1) / 2 - k;
		cout << unite + n - 1 << endl;
		for (int i = 2; i <= n; i++)
		{
			cout << 1 << ' ' << i << endl;
		}
		for (ll i = 3; i <= n; i++)
		{
			if (unite <= 0)
			{
				break;
			}
			for (int j = 0; j < min(unite, i - 2); j++)
			{
				cout << j + 2 << ' ' << i << endl;
			}
			unite -= i - 2;
		}
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var xkd = Console.ReadLine().Split();
            long x = Math.Abs(long.Parse(xkd[0]));
            long k = long.Parse(xkd[1]);
            long d = long.Parse(xkd[2]);

            var data = new Program();
            Console.WriteLine(data.MinimumAb(x, k, d));

        }

        public long MinimumAb(long x, long k, long d)
        {
            if(x / d > k)
            {
                return x - k * d;
            }
            else
            {
                long minCandidate = x % d;
                long leftMoveCount = k - x / d;

                if(x % d > d - x % d && leftMoveCount > 0)
                {
                    minCandidate = d - x % d;
                    leftMoveCount -= 1;
                }

                if(leftMoveCount % 2 == 0)
                {
                    return minCandidate;
                }
                else
                {
                    return Math.Min(Math.Abs(minCandidate - d), Math.Abs(minCandidate + d));
                }
            }
        }
    }
}


Measured memory_bytes: 27496
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = np.array(lr())

P_diff = np.diff(P)
P_diff = P_diff > 0
series = P_diff[:-1] == P_diff[1:]
answer = series.sum()
print(answer)
# 23

Measured memory_bytes: 12500
#include <iostream>

long long x;

using namespace std;

int main()
{
	cin >> x;
	for (long long a = 0; a <= 120; a++)
	for (long long b = 0; b <= 120; b++)
	if (a * a * a * a * a - b * b * b * b * b == x) cout << a << " " << b, exit(0);
    for (long long a = 0; a <= 120; a++)
	for (long long b = 0; b <= 120; b++)
	if (a * a * a * a * a + b * b * b * b * b == x) cout << a << " " << -b, exit(0);
}


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

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int main() {
    long long n, ret = 0;
    const auto mod = 1000000007ll;
    std::cin >> n;
    std::vector<long long> fact(n + 1), inv(n + 1);
    fact[0] = 1;
    for (auto i = 1ll; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (auto i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
    auto pre = 0ll;
    for (auto i = (n + 1) / 2; i < n; i++) {
        auto t = fact[i - 1] * inv[n - 1 - i] % mod * inv[2 * i - n] % mod * fact[i] % mod * fact[n - 1 - i] % mod;
        ret = (ret + (t - pre + mod) % mod * i) % mod;
        pre = t;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,x,y,kin1,kin2;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	x=0;	y=0;
	kin1=0;	kin2=0;
	while(1){
		x+=a;
		kin1+=b;
		if(x>=n)	break;
	}
	while(1){
		y+=c;
		kin2+=d;
		if(y>=n)	break;
	}
	if(kin1<=kin2)	printf("%d\n",kin1);
	else	printf("%d\n",kin2);
	return 0;
}



Measured memory_bytes: 2140
#include <iostream>
    #include <queue>
    #include <functional>
    #include <cstring>
    using namespace std;
    #define MAX_V 10240
     
    // ?????¶???from????????¶???to????????????cost??????
    typedef struct edge
    {
    	int to, distance, cost;
    	edge(){}
    	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}
    };
     
    // first ???????????????????????????second????????¶?????????
    typedef pair<int, int> P;
     
    // ???
    vector<edge> G[MAX_V];
     
    // ????????????
    int d[MAX_V];
    // V?????¶?????°
    int V;
     
    // ?±??§£?????¶???s????????°?????????????????????????????¶???????°???±?´????
    void dijkstra(int s)
    {
    	priority_queue<P, vector<P>, greater<P> > que;
    	memset(d, 0x3f, sizeof(d));
    	d[s] = 0;
    	que.push(P(0, s));
     
    	while (!que.empty())
    	{
    		P p = que.top(); que.pop();
    		int v = p.second;
    		if (d[v] < p.first) continue;
    		for (int i = 0; i < G[v].size(); ++i)
    		{
    			edge e = G[v][i];
    			if (d[e.to] > d[v] + e.distance)
    			{
    				d[e.to] = d[v] + e.distance;
    				que.push(P(d[e.to], e.to));
    			}
    		}
    	}
    }
     
    ///////////////////////////SubMain//////////////////////////////////
    int main(int argc, char *argv[])
    {
     
    	int /*N = V,*/ M;
    	while (cin >> V >> M && V)
    	{
    		for (int i = 0; i < V; ++i)
    		{
    			G[i].clear();
    		}
    		for (int i = 0; i < M; ++i)
    		{
    			int u, v, d, c;
    			cin >> u >> v >> d >> c;
    			--u, --v;
    			G[u].push_back(edge(v, d, c));
    			G[v].push_back(edge(u, d, c));
    		}
    		// ?????????0???
      		dijkstra(0);
    		int ans = 0;
    		for (int i = 1; i < V; ++i)
    		{
    			int min_cost = 0x3f3f3f3f;
    			// ??????????¶????????????????????????¶????´???¨???????????£??????????´???¨
    			for (int j = 0; j < G[i].size(); ++j)
    			{
    				if (d[G[i][j].to] + G[i][j].distance == d[i] && G[i][j].cost < min_cost)
    				{
    					min_cost = G[i][j].cost;
    				}
    			}
    			ans += min_cost;
    		}
    		cout << ans << endl;
    	}
     
    	return 0;
    }

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<vector<int>> t(n);
    int a[n - 1], b[n - 1];
    rep(i, 0, n - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        t[a[i]].push_back(b[i]);
        t[b[i]].push_back(a[i]);
    }
    int c[n];
    rep(i, 0, n) cin >> c[i];

    sort(c, c + n, greater<int>());

    int d[n] = {};

    queue<int> q;
    q.push(0);
    int cnt = -1;
    int reached[n] = {};
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        cnt++;
        if (cnt == n) break;
        d[now] = c[cnt];
        reached[now] = 1;
        rep(i, 0, (int)t[now].size()) {
            int next = t[now][i];
            if (reached[next]) continue;
            q.push(next);
        }
    }

    //rep(i, 0, n) cout << d[i] << endl;
    ll score = 0;
    rep(i, 0, n - 1) {
        score += min(d[a[i]], d[b[i]]);
    }

    cout << score << endl;
    rep(i, 0, n) {
        cout << d[i];
        if (i != n - 1) cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod=1e9+7;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

ll gcd(ll a,ll b)
{
	return b? gcd(b,a%b):a;
}

ll pow(ll a, ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2) res=(res*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

int ugabuga()
{

	int n,k;
	cin>>n>>k;

	vector<int>a(n);
	for(int i=0;i<n;i++) cin>>a[i];

	vector<int>dp(n,2e9);
	dp[0]=0;

	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
			if(j<n)
			{
				dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
			}
	}

	cout<<dp[n-1];

	return 0;
}


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

    int t=1;
    //cin>>t;
    while(t--)
    {
        ugabuga();
    }

}

Measured memory_bytes: 1024
from collections import deque
n = int(input())
aList = deque(map(int, input().split()))
sList = []
s = 0
for ra in reversed(aList):
    s += ra
    sList.append(s)
sList.reverse()
aList = deque(aList)
sList = deque(sList)

def main():
    c = 1
    a = aList.popleft()
    s = sList.popleft()
    if a > 0 and n != 0:
        return -1
    if n == 0 and a == 1:
        return 1
    su = c
    for i in range(n):
        a = aList.popleft()
        s = sList.popleft()
        t = min(c * 2, s)
        su += t
        if t < a:
            return -1
        else:
            c = t - a
    if c == 0:
        return su
    else:
        return -1

print(main())

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int x ; 
  cin >> x ;
  cout << 8- ((x-400)/200) <<endl ;
  

}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=5050;
//↑templete
map<ll,ll> pam;
void fnc(ll A){
	ll B=A;
	for(ll i=2;i*i<=B;i++){
		if(A%i==0){
			pam[i]++;
		}
		while(A%i==0)
			A/=i;
	}
	pam[1]++;
	if(A!=1)
		pam[A]++;
}
int main() {
	ll A,B;
	cin>>A>>B;
	ll ans=0;
	fnc(A);
	fnc(B);
	for(auto p:pam){
		if(p.second==2)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
typedef pair<int,P> PP;
 
struct edge{ int u,v,cost; };
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int par[100000];
int rnk[100000];

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

void init(int n){
	for(int i = 0;i < n;i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

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

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rnk[x] < rnk[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}

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

signed main(){
	int n,x[100000],y[100000];
	vector<PP> a,b;
	vector<edge> es;
	cin >> n;
	init(n);
	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i];
		a.push_back(mp(x[i],mp(y[i],i)));
		b.push_back(mp(y[i],mp(x[i],i)));
	}
	sort(all(a));
	sort(all(b));
	for(int i = 0;i < n - 1;i++){
		es.push_back({a[i].second.second,a[i + 1].second.second,a[i + 1].first - a[i].first});
		es.push_back({b[i].second.second,b[i + 1].second.second,b[i + 1].first - b[i].first});
	}
	sort(all(es),comp);
	int ans = 0;
	for(int i = 0;i < es.size();i++){
		edge e = es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			ans += e.cost;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 1e6 + 5, M = 1e9 + 7;

int x[N], y[N], v[N];

ll a[3005][3005], dp[3005][3005][5];

void solve() {            
    int r, c, k;
    cin >> r >> c >> k;
    for (int i = 1; i <= k; ++i) {
        cin >> x[i] >> y[i] >> v[i];
        a[x[i]][y[i]] = v[i];
    }
    for (int i = 1; i <= r; ++i) {
        for (int j = 1; j <= c; ++j) {
            dp[i][j][0] = max(max({dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3]}), dp[i][j - 1][0]);
            dp[i][j][1] = max(max({dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3]}) + a[i][j], max(dp[i][j - 1][1], dp[i][j - 1][0] + a[i][j]));
            dp[i][j][2] = max(dp[i][j - 1][2], dp[i][j - 1][1] + a[i][j]);
            dp[i][j][3] = max(dp[i][j - 1][3], dp[i][j - 1][2] + a[i][j]);
        }
    } 
    cout << max({dp[r][c][0], dp[r][c][1], dp[r][c][2], dp[r][c][3]});
}

main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
        cout << '\n';
    }
    return 0;
}

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

struct segtree {
  int id; // identity element
  vector<int> node;
  function<int(int, int)> f;
  static const int N = 1 << 18;

  segtree(int id, function<int(int, int)> f) : id(id), f(f), node(2 * N, id){}

  void init(vector<int> &v) {
    for (int i = 0; i < v.size(); ++i) {
      node[i + N - 1] = v[i];
    }
    for (int i = N - 2; i >= 0; --i) {
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  int find(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return id;
    if (a <= l && r <= b) return node[k];
    return f(
      find(a, b, 2 * k + 1, l, (l + r) / 2),
      find(a, b, 2 * k + 2, (l + r) / 2, r)
    );
  }

  int find(int a, int b) {
    return find(a, b, 0, 0, N);
  }

  void update(int k, int x) {
    k += N - 1;
    node[k] = x;
    while (k) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  void add(int k, int x) {
    k += N - 1;
    node[k] += x;
    while (k) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
};

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

  segtree seg(0, [&](int a, int b) { return a + b; } );
  while (q--) {
    int f, a, b;
    cin >> f >> a >> b;

    if (f) cout << seg.find(a, b + 1) << endl;
    else seg.add(a, b);
  }
}

Measured memory_bytes: 4976
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: i64 = sc.read();
    let k: i64 = sc.read();
    let x = n % k;

    let ans = cmp::min(x, k - x);
    println!("{}", ans);
}

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

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> a(N);
  vector<int> m(3);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) <= A) {
      m[0]++;
    } else if (a.at(i) <= B) {
      m[1]++;
    } else {
      m[2]++;
    }
  }
  int min = 34;
  for (int i = 0; i < 3; i++) {
    if (min > m[i]) {
      min = m[i];
    }
  }
  cout << min << endl;
  
}


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

int main() {
int A,B;
cin >> A >> B;
int C = A + B;
if(C < 24){
    cout << C <<endl;
}
else if(C == 24){
    cout << 0 <<endl;
}
else if(C > 24){
    cout << C - 24 <<endl;
}

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		int m[99][99],i,j,k;
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				cin>>m[i][j];
		for(i=0;i<n;i++){
			k=0;
			for(j=0;j<n;j++){
				k+=m[i][j];
				if(j+1==n)
					m[i][n]=k;}}
		for(i=0;i<n;i++){
			k=0;
			for(j=0;j<n;j++){
				k+=m[j][i];
				if(j+1==n)
					m[n][i]=k;}}
		k=0;
		for(i=0;i<n;i++)
			k+=m[i][n];
		m[n][n]=k;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++)
				cout<<setw(5)<<m[i][j];
			cout<<endl;}}
	return 0;}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll k, s;
	cin >> k >> s;

	ll res{0};
	for (ll x = 0; x <= k; ++x)
	{
		for (ll y = 0; y <= k; ++y)
		{
			ll z = s - x - y;
			if (z < 0 || z > k) continue;
			++res;
		}
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[]){
    int x, a,b;
    cin >> x >> a >> b;
    if(abs(a-x)<abs(b-x)){
        cout << "A"<< endl;
    }else{
        cout << "B" << endl;
    }
  return 0;
}


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	if(count(a.begin(),a.end(),0)>0) return puts("0"),0;

	lint ans=1;
	rep(i,n){
		if(ans>lint(2e18)/a[i]) return puts("-1"),0;
		ans*=a[i];
	}
	printf("%lld\n",ans<=lint(1e18)?ans:-1);

	return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define chmin(a,b) a=min(a,b)
const int N=1e4+5;

int h,n,ans;
int a[N],b[N];
int dp[N];

int main()
{
	
	cin>>h>>n;
	memset(dp,60,sizeof(dp));
	ans=1e9; dp[0]=0;
	for(int i=1;i<=n;i++)	
		cin>>a[i]>>b[i];
	for(int i=0;i<=h;i++)
	for(int j=1;j<=n;j++)
		if(i+a[j]>=h) chmin(ans,dp[i]+b[j]);
		else chmin(dp[i+a[j]],dp[i]+b[j]);
	cout<<ans<<'\n';
		
	return 0;
}

Measured memory_bytes: 384
using AtCoderBeginnerContest150.Questions;
using AtCoderBeginnerContest150.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest150.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var s = inputStream.ReadLine();

            var subString = new Queue<char>(s.Take(2));

            int count = 0;
            foreach (var c in s.Skip(2))
            {
                subString.Enqueue(c);
                if (subString.SequenceEqual("ABC"))
                {
                    count++;
                }
                subString.Dequeue();
            }

            yield return count;
        }
    }
}


namespace AtCoderBeginnerContest150
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest150.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest150.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int x;
  cin >> x;
  for (int i = 1; i < n; ++i) {
    int y;
    cin >> y;
    x = __gcd(x, y);
  }
  cout << x << endl;
}


Measured memory_bytes: 3556
function main(arg) {
    var num = parseInt(arg.split(/\s+/g));
    var kekka = false;
    for(i=0;i<10;i++){
    	if(num%i==0&&num/i==Math.floor(num/i)&&num/i<10){
    		kekka = true;
    	}
    }
    if(kekka==true){
        console.log("Yes");
    }else{
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<iostream>
#include<vector>
#include<map>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int w,h;while(cin>>w>>h,w){
		int sy,sx,gy,gx,py[5][1000]={0},px[5][1000]={0},np[5]={0};
		rep(i,h){
			char buf[1001];cin>>buf;
			rep(j,w){
				if(buf[j]=='S')sy=i,sx=j;
				if(buf[j]=='G')gy=i,gx=j;
				if('0'<buf[j]&&buf[j]<'6'){
					int e=buf[j]-'1';
					py[e][np[e]]=i,px[e][np[e]]=j;
					np[e]++;
				}
			}
		}
		int cost[5][5][1000],ans=1<<20,ae;
		rep(i,5)rep(j,5)rep(k,1000)cost[i][j][k]=1<<20;
		for(int s_=1;s_<6;s_++){
			int s=s_%5;
			rep(i,np[s])cost[s][s][i]=abs(py[s][i]-sy)+abs(px[s][i]-sx);
			rep(i_,3){
				int i=(s+i_)%5,ni=(i+1)%5;
				rep(j,np[ni])rep(k,np[i])cost[s][ni][j]=min(cost[s][ni][j],
					cost[s][i][k]+abs(py[ni][j]-py[i][k])+abs(px[ni][j]-px[i][k])
				);
			}
			int l=(s+3)%5;
			rep(i,np[l]){
				int c=cost[s][l][i]+abs(gy-py[l][i])+abs(gx-px[l][i]);
				if(ans>c)ae=s,ans=c;
			}
		}
		if(ans==1<<20)cout<<"NA"<<endl;
		else cout<<(ae+4)%5+1<<" "<<ans<<endl;
	}
	return 0;
}

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

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

const ll INF = 1LL << 60;



//大文字小文字気をつけろ

int main(){
  int n;
  cin >> n;
  int x[1000000],b[1000000];
  FOR(i,n){
    cin >> x[i];
    b[i]=x[i];
  }

  sort(b,b+n);
  
  int v=n/2;


FOR(i,n){
  if(x[i]<=b[v-1]){
    cout << b[v] << endl;
  }else{
    cout << b[v-1] << endl;
  }
}

  
}


Measured memory_bytes: 8320