akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    int res = 0;
    char prev = ' ';
    in.online<char>(N, [&](char x) {
        if (prev != x) {
            res++;
            prev = x;
        }
    });
    out << res;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,Y;
  cin >> X >> Y;
 
    if (Y >= 2*X && Y <= 4*X && Y%2 == 0){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }

    
  
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=10010;
map<char,int> m;
int main()
{
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++) m[s[i]]++;
  if(m.size()!=2)
  {
    cout<<"No\n";
    return 0;
  }
  for(auto i:m)
  {
    if(i.second!=2)
    {
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

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

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
int n, x, t;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> x >> t;
	if (n % x == 0){
		cout << (n/x)*t << endl;
	} else {
		cout << (n + x)/x*t << endl;
	}
}

//cout.flush()
//cout << fixed << setprecision(9) << x << endl;

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

int main() {
    ll n, m;
    cin >> n >> m;

    ll ans = 0;
    if (2 * n <= m) {
        ans += n;
        m -= n * 2;
        ans += m / 4;
    } else {
        ans += m / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define li long long int
using namespace std;

int main() {
	li n;
	cin>>n;
	vector<long long int >a(n),b(n);
	 for(li i = 0; i < n; i++ )
	 {
	 	cin>>a[i];
	 	b[i] = a[i];
	 }
	 sort(a.begin(),a.end());
	 for(li i = 0 ; i < n ; i++){
	 	if(b[i]==a[n-1])
	 	cout<<a[n-2]<<endl;
	 	else 
	 	cout<<a[n-1]<<endl;
	 }
	return 0;
}


Measured memory_bytes: 4736
def main():
    int(input())
    S = [int(i) for i in input().split()]
    int(input())
    T = [int(i) for i in input().split()]

    count = 0
    for t in T:
        if t in S:
            count += 1

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6340
n=int(input())
d=list(map(int,input().split()))
d.sort()
half=n//2
group1=d[0:half]
group2=d[half:]
#共通の要素がなければおｋ
if len(set(group1)&set(group2))==0: print(group2[0]-group1[-1])
else: print(0)

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

int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<long long int>> dp(h,vector<long long int> (w,0));
    char a[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    dp[0][0]=0;
    int l=0,k=0;
    for(int i=0;i<h;i++)
    {
        if(l!=0)
        dp[i][0]=INT_MIN;
    if(l==0)
    {
    dp[i][0]= 1;
    if(a[i][0]=='#')
    {
    dp[i][0]=INT_MIN;
    l++;
    }
    }
    }
    for(int j=0;j<w;j++)
    {
        if(k!=0)
        dp[0][j]=INT_MIN;
        if(k==0)
        {
        dp[0][j]=1;
        if(a[0][j]=='#')
        {
            dp[0][j]=INT_MIN;
            k++;
        }
        }
    }
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(a[i][j]=='#')
            dp[i][j]= INT_MIN;
            else
            {
                int x=0;
                int y= 0;
                if(dp[i][j-1]!=INT_MIN)
                x=dp[i][j-1];
                if(dp[i-1][j]!=INT_MIN)
                y=dp[i-1][j];
            dp[i][j]= (x + y)%(1000000000+7);
            }
        }
    }
    cout<<dp[h-1][w-1];
	return 0;
}

Measured memory_bytes: 9088
import math
n,m=map(int,input().split())

ns=math.factorial(n)
ms=math.factorial(m)
mod=10**9+7
if abs(n-m)>=2:
  print(0)
elif abs(n-m)==1:
  print((ns*ms)%mod)
else:
  print((ns*ms*2)%mod)


Measured memory_bytes: 5180
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

bool v[1024][10];
string str[1024];
int main() {
	string s; cin >> s;
	ll p = 1 << s.size() - 1;

	for (int i = 0; i < p; i++) {
		ll t = i;
		ll digit = 0;
		while (t) {
			if (t & 1) {
				v[i][digit] = true;
			}
			t = t >> 1;
			digit++;
		}
	}

	rep(i, 0, p) {
		string x;
		repe(t, 1, s.size()) {
			x += s[t - 1];
			x += ((v[i][t - 1]) ? "+" : "");
		}
		str[i] = x;
	}

	ll ans = 0;
	rep(i, 0, p) {
		ll st = 0;
		//cout << str[i] << endl;
		repe(j, 0, str[i].size()) {
			if (str[i][j] == '+') {
				string num = str[i].substr(st, j - st);
				st = j + 1;
				ans += stoll(num);
			}
			else if (j == str[i].size()) {
				string num = str[i].substr(st, j - st);
				ans += stoll(num);
			}
		}
	}
	cout << ans << 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);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A == 1) {
			A = 14;
		}
		if (B == 1) {
			B = 14;
		}
		if (A > B) {
			System.out.println("Alice");
		}else if (A == B){
			System.out.println("Draw");
		}else {
			System.out.println("Bob");
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


bool can_put(const int position, const std::string& str) {
	if (str[position] != '.') return false;
	int left = position - 1;
	while (left >= 0 && str[left] == 'W') --left;
	int right = position + 1;
	while (right < str.size() && str[right] == 'W') ++right;
	return  (left < 0 || str[left] == '.') || (right >= str.size() || str[right] == '.');
}
int count_remove_block(const int position, const std::string& str) {
	if (!can_put(position, str)) return 0;
	int left = position - 1;
	while (left >= 0 && str[left] == 'B') --left;
	int right = position + 1;
	while (right < str.size() && str[right] == 'B') ++right;
	if (left >= 0 && position - left != 1 && str[left] == 'W') return position - left - 1;
	if (right < str.size() && right - position != 1 && str[right] == 'W') return right - position - 1;
	return 0;
}
int main() {
	int n; std::cin >> n;
	std::string str; std::cin >> str;
	int max = 0;
	for (auto i = 0; i < n; ++i) {
		max = std::max(max, count_remove_block(i, str));
	}
	std::cout << max << std::endl;
}




Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
int n,k,a[N],b[N];
int main(){
	cin>>n>>k;
	for (int i=1;i<=n;i++)cin>>a[i];
	while (k--){
		for (int i=1;i<=n;i++)b[max(1,i-a[i])]++,b[min(n+1,i+a[i]+1)]--;
		for (int i=1;i<=n;i++)b[i]+=b[i-1],a[i]=b[i];
		for (int i=1;i<=n;i++)b[i]=0;
		int cp=0;
		for (int i=1;i<=n;i++)if (a[i]!=n)cp=1;
		if (cp==0)break;
	}
	for (int i=1;i<=n;i++)cout<<a[i]<<' ';cout<<endl;
	return 0;
}

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

int main()
{
    int n;
    int m;
    cin>>n>>m;
    if(n>=1 && n<=100)
    {
        if(m>=0 && m<=n)
        {
            if(n==m)
            {
                cout<<"Yes";
            }
            else{
                    cout<<"No";
            }
        }
    }


    return 0;
}


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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

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

const int N = 200179;

struct Foun {
    int x, y;
};

int sx, sy, tx, ty, n;
Foun f[N];

int main()
{
    ios::sync_with_stdio(false);

    scanf("%d%d%d%d%d", &sx, &sy, &tx, &ty, &n);
    for (int i = 0; i < n; ++i)
        scanf("%d%d", &f[i].x, &f[i].y);

    if (sx > tx) {
        sx = -sx; tx = -tx;
        for (int i = 0; i < n; ++i)
            f[i].x = -f[i].x;
    }
    if (sy > ty) {
        sy = -sy; ty = -ty;
        for (int i = 0; i < n; ++i)
            f[i].y = -f[i].y;
    }

    tx -= sx;
    ty -= sy;
    for (int i = 0; i < n; ++i) {
        f[i].x -= sx;
        f[i].y -= sy;
    }
    sx = 0;
    sy = 0;

    vector < ipair > a;
    for (int i = 0; i < n; ++i) {
        int x = f[i].x;
        int y = f[i].y;
        if (x < 0 || y < 0 || x > tx || y > ty)
            continue;
        a.push_back({x, y});
    }

    sort(a.begin(), a.end());
    static int d[N];
    d[0] = -IINF;
    int n = sz(a);
    for (int i = 1; i <= n; ++i)
        d[i] = IINF;
    for (int i = 0; i < n; ++i) {
        int j = upper_bound(d, d + n, a[i].Y) - d;
        if (d[j-1] < a[i].Y && a[i].Y < d[j])
            d[j] = a[i].Y;
    }

    int m = 0;
    for (int i = 0; i <= n; ++i)
        if (d[i] != IINF)
            m = i;
    
    if (m == sz(a) && sz(a) == min(tx, ty) + 1) {
        printf("%.13lf\n", 100.0*(tx+ty) + (m-1)*(5.0*PI - 20.0) + (10.0*PI - 20.0));
    } else {
        printf("%.13lf\n", 100.0*(tx+ty) + m*(5.0*PI - 20.0));
    }

    return 0;
}


Measured memory_bytes: 4336
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    //~ freopen("file.in", "r", stdin);
    int a,b,c;
    ll k;
    scanf("%d%d%d%lld",&a,&b,&c,&k);
    if(k&1)
		printf("%d\n",b-a);
	else
		printf("%d\n",a-b);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  }
}


Measured memory_bytes: 86016
#include <iostream>
using namespace std;
 
int main() {
	int A, B;
	cin>>A>>B;
	if(A>=13){
		cout<<B;
	} else if(A>=6 && A<=12){
		cout<<B/2;
	} else{
		cout<<0;
	}
	return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

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

int main() {
    LL n;
    cin >> n;
    LL p = 0;
    for (LL i = 1; i * i <= n; i++) {
        p = i;
    }
    cout << p * p << endl;

    return 0;
}


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

int main()
{
  char str[10006];
  scanf("%s",str);
  int len = strlen(str);
  int ans = 0;
  for (int i=0;i<len/2;i++)
  {
    if (str[i]!=str[len-1-i]) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	VE ans(100010);
	int cnt = 0;
	for (int i = 1; i <= 100000; i++) {
		if (i%2!=0&&prime(i) && prime((i + 1) / 2))cnt++;
		ans[i] = cnt;
	}
	int q; cin >> q;
	rep(i, q) {
		int l, r; cin >> l >> r; l--;
		cout << ans[r] - ans[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;
bool l[15];

long long calc(vector<int> a, int s) {

	int la = a[0];
	long long ans = 0;
	for (int i = 0; i < s; i++) {
		if (l[i]) {
			if (a[i+1] <= la) {
				int d = la - a[i+1] + 1;
				ans += d;
				a[i+1] += d;
				la = a[i + 1];
			}
		}
		la = max(la, a[i + 1]);
	}

	return ans;

}

long long func(vector<int>& a, int s, int n, int k) {
	
	if (n == s) {

		return calc(a,s);

	}
	else {

		long long na = -1, nb = -1;
		if (s - n > k) {
			l[n] = 0;
			na = func(a, s, n + 1, k);
		}
		l[n] = 1;
		nb = func(a, s, n + 1, k - 1);

		if (na == -1)
			return nb;
		else if (nb == -1)
			return na;
		else
			return min(na, nb);

	}

}

int main() {

	int n, k;
	cin >> n >> k;
	vector<int> a(n);

	for (auto &x : a) {
		cin >> x;
	}

	cout << func(a, n - 1, 0, k - 1) << endl;;

	return 0;

}

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

int main() {
  int n;
  cin >> n;
  
  int p = 0, w = 0, g = 0, y = 0;
  for (int i = 0; i < n; ++i) {
    string c;
    cin >> c;

    if (!p && c == "P") p++;
    if (!w && c == "W") w++;
    if (!g && c == "G") g++;
    if (!y && c == "Y") y++;
  }

  int n_patterns = p + w + g + y;

  if (n_patterns == 3) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;

class FermatCombination {
 private:
  vector<int> factrial;
  vector<int> inverse;
  int mod;

  int pow(int x, int n) {
    long long r = 1;
    while (n > 0) {
      if (n & 1) r = r * x % mod;
      x = (long long)x * x % mod;
      n >>= 1;
    }
    return r;
  }

 public:
  FermatCombination(int size, int mod) {
    this->factrial = vector<int>(size + 1);
    this->inverse = vector<int>(size + 1);
    this->mod = mod;

    factrial[0] = 1;
    inverse[0] = 1;
    for (int i = 1; i <= size; i++) {
      factrial[i] = (long long)factrial[i - 1] * i % mod;
      inverse[i] = pow(factrial[i], mod - 2);
    }
  }

  int operator()(int n, int k) {
    return (long long)factrial[n] * inverse[k] % mod * inverse[n - k] % mod;
  }
};

int main() {
  ll n, a[2], k;
  cin >> n >> a[0] >> a[1] >> k;
  sort(a, a + 2);
  FermatCombination c(n, mod);
  ll r = 0;
  for (ll i = 0; i <= n && i * a[1] <= k; i++) {
    ll j = (k - i * a[1]) / a[0];
    if (j <= n && i * a[1] + j * a[0] == k) {
      r = (r + (ll)c(n, i) * c(n, j)) % mod;
    }
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 2560
// abcdbbd       v[0]=1 , v[1] = 1,4,5 v[2]= 2 , v[3]= 3,6
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
   vector<set<int>> v(26);
   int n; cin >> n ;
   string s; cin >> s;
   for(int i=0 ; i < n ; i++){
   	    v[s[i]-'a'].insert(i);
   }
   int q ; cin >> q;
   while(q--){
   	int x; cin >> x;
   	if(x==1){
   		    int pos;
   		    char c,y; cin >> pos >> c;
   		    pos--;
   		    y = s[pos];
   		    v[y-'a'].erase(pos);
   		    s[pos] = c;
   		    v[c-'a'].insert(pos);
   		}
   	  else {
   	  	  ll count=0;
   	  	  int l,r;
   	  	  cin >> l >> r ;
   	  	  l-- , r--;
   	  	   for(int i=0 ; i < 26 ; i++){
   	  	   	      auto it = v[i].lower_bound(l);
   	  	   	      if(it!=v[i].end() and *it <= r)
   	  	   	         count++;
				}
			cout << count << endl;
		 }
   }
}

Measured memory_bytes: 27192
#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  std::int64_t N, X, M;
  std::cin >> N >> X >> M;
  std::vector<std::int64_t> A(M + 1);
  std::vector<int> index(M, -1);
  A[0] = X;
  index[A[0]] = 0;
  int end;
  for (end = 1; end <= M; ++end) {
    A[end] = A[end - 1] * A[end - 1] % M;
    if (index[A[end]] >= 0) break;
    index[A[end]] = end;
  }
  int begin = index[A[end]];
  if (N < begin) {
    std::int64_t sum = 0;
    for (int i = 0; i < N; ++i) {
      sum += A[i];
    }
    std::cout << sum << std::endl;
    return 0;
  }
  std::int64_t sum = 0, body = 0;
  for (int i = 0; i < begin; ++i) {
    sum += A[i];
  }
  for (int i = begin; i < end; ++i) {
    body += A[i];
  }
  const auto loops = (N - begin) / (end - begin);
  const auto remaining = N - begin - (end - begin) * loops;
  sum += body * loops;
  for (int i = begin; i < begin + remaining; ++i) {
    sum += A[i];
  }
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 4572
V, E = map(int, raw_input().split())
cost = [[10**9]*V for i in xrange(V)]
for i in xrange(E):
    s, t = map(int, raw_input().split())
    cost[s][t] = -1
for i in xrange(V):
    cost[i][i] = 0

for k in xrange(V):
    for i in xrange(V):
        for j in xrange(V):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
print any(cost[i][i]<0 for i in xrange(V))/1

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!
void fill_bingo(vec<vec<ll>> &A, ll b){
  rep(i,3) rep(j,3) if(A[i][j]==b) A[i][j] = 0;
}
bool check_bingo(vec<vec<ll>> &A){
  bool bingo = false;
  // 縦横
  rep(i,3){
    if(A[i][0]==0 && A[i][1]==0 && A[i][2]==0) bingo=true;
    if(A[0][i]==0 && A[1][i]==0 && A[2][i]==0) bingo=true;
  }
  // ななめ
  if(A[0][0]==0 && A[1][1]==0 && A[2][2]==0) bingo=true;
  if(A[0][2]==0 && A[1][1]==0 && A[2][0]==0) bingo=true;

  return bingo;
}
//

void solve(std::vector<std::vector<long long>> A, long long N,
           std::vector<long long> b)
{
  rep(i,N){
    fill_bingo(A,b[i]);
  }
  if(check_bingo(A)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      std::cin >> A[i][j];
    }
  }
  long long N;
  std::cin >> N;
  std::vector<long long> b(N);
  for (int i = 0; i < N; i++) {
    std::cin >> b[i];
  }
  solve(std::move(A), N, std::move(b));
  return 0;
}


Measured memory_bytes: 3628
N, M = map(int, input().split())
dish = [[] for i in range(N)]

for i in range(N):
    dish[i] = list(map(int, input().split()))

cnt = [0 for i in range(M)]

for i in range(N):
    for j in range(dish[i][0]):
        A = dish[i][j+1] - 1
        cnt[A] += 1

judge = 0
for i in range(M):
    if cnt[i] == N:
        judge += 1

print(judge)

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

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 1; i <= n; i++){
        int num = i;
        int f = 2;
        while(num>1){
            while(num%f==0){
                num /= f;
                mp[f]++;
            }
            f++;
        }
    }

    ll ans = 1;
    for (auto u =mp.begin(); u!=mp.end(); u++){
        ans *= u->second + 1;
        ans %= MOD;
    }
    
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 1000000
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
typedef struct{
    int x;
    int y;
    int turn;
}Point;
int mv[6][2]={{1,1},{1,0},{0,-1},{-1,-1},{-1,0},{0,1}};
int t,n;
Point queue[N];
int head,num,cnt;
void enqueue(int x,int y,int turn){
    if(num<N){
        queue[(head+num)%N].x=x;
        queue[(head+num)%N].y=y;
        queue[(head+num)%N].turn=turn;
        num++;
    }else{
        printf("エラー\n");
        exit(1);
    }
}
Point dequeue(){
    Point d={-1,-1};
    if(num>0){
        d=queue[head];
        head=(head+1)%N;
        num--;
    }
    return d;
}
int main(void){
    while(1){
        scanf("%d%d",&t,&n);
        if(n+t==0) break;
        int x,y;
        int block[1000][1000]={0};
        rep(i,n){
            scanf("%d%d",&x,&y);
            block[500+x][500+y]=1;
        }
        scanf("%d%d",&x,&y);
        block[500+x][500+y]=1;
        cnt=1; head=num=0;
        enqueue(500+x,500+y,0); block[500+x][500+y]=1;
        while(1){
            Point tmp=dequeue();
            if(tmp.x==-1) break;
            if(tmp.turn==t) continue;
            for(int i=0;i<6;i++){
                int nx=tmp.x+mv[i][0],ny=tmp.y+mv[i][1];
                int nt=tmp.turn+1;
                //if(nx<0||ny<0) continue;
                if(block[nx][ny]) continue;
                cnt++; block[nx][ny]=1;
                enqueue(nx,ny,nt);
            }
        }
        printf("%d\n",cnt);
    }
}



Measured memory_bytes: 5668
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

int64_t imos[100000];

int main(){
    int N;
    cin>>N;
    vector<int64_t> A(N);
    for(auto &a:A) cin>>a;
    sort(A.begin(), A.end());
    imos[0]=A[0];
    for(int i=1;i<N;i++){
        imos[i]=imos[i-1]+A[i];
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        int64_t S = A[i];
        int idx = upper_bound(A.begin(), A.end(), S*2)-A.begin();
        while(idx<N){
            S = imos[idx-1];
            if(idx == upper_bound(A.begin(), A.end(), S*2)-A.begin()) break;
            idx = upper_bound(A.begin(), A.end(), S*2)-A.begin();
        }
        if(idx==N){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2424
N,M=list(map(int,input().split()))
A=[]
B=[]
for i in range(N):
    A.append(list(input()))

for i in range(M):
    B.append(list(input()))
'''
for i in range(N):
    print(A[i])

for i in range(M):
    print(B[i])
'''
for i in range(N):
    for j in range(len(A[i])):
        flg=True
        for x in range(M):
            for y in range(len(B[x])):
                if i+x==N or j+y==len(A[i]):
                    flg=False
                    break
                if A[i+x][j+y]!=B[x][y]:
                    flg=False
                    break
            if flg==False:
                break
        if flg==True:            
            print("Yes")
            exit()
print("No")        




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

#define INF INT_MAX
#define N 100
#define W 100005

using namespace std;

int n, w;
int weight[N];
int value[N];
long long dp[N][W];
long long solve(int idx, int w){
    if(idx == n)
        return 0;
    if(~dp[idx][w])
        return dp[idx][w];
    if(weight[idx] <= w)
        dp[idx][w] = 0ll + value[idx]+solve(idx+1, w-weight[idx]);
    dp[idx][w] = max(dp[idx][w], solve(idx+1, w));
    return dp[idx][w];
}
int main()
{
    cin >> n >> w;
    for(int i=0; i<n; ++i)
        cin >> weight[i] >> value[i];
    memset(dp, -1, sizeof(dp[0][0]) * N * W);
    cout << solve(0, w);
    return 0;
}

Measured memory_bytes: 78336
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

input()
nums = list(map(int, input().split(' ')))


def avg(nums):
    avg = sum(nums)/len(nums)
    return round(avg)


def calc(nums, base):
    total = 0
    for n in nums:
        sub = n - base
        total += (sub * sub)
    return total


if __name__ == "__main__":
    base = avg(nums)
    c = calc(nums, base)
    print(c)


Measured memory_bytes: 3192
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map{it.toInt()}

    val avg = aa.average()

    var min = 100.0
    var frame = -1

    aa.forEachIndexed { index, a ->
        var diff = Math.abs(a-avg)
        if (diff < min) {
            min = diff
            frame = index
        }
    }

    println(frame)
}

Measured memory_bytes: 37776
import sys

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input()) - 1

step = 0
t = 0
seen = {0}
while True:
    t = a[t]
    step += 1
    if t == 1:
        print(step)
        sys.exit()
    if t in seen:
        print(-1)
        sys.exit()
    seen.add(t)


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

int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  long long sum=0;
  for(int r=0;r*R<=N;r++){
    for(int g=0;g*G<=N;g++){
      int k=N-r*R-g*G;
      if(k%B==0 && 0<=k)sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  ll sum=0;
  for(ll i=0;i<S.size();i++) {
sum+=(S[i]-'0');
  }
  ll N=stoll(S);
  if(N%sum==0) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <atcoder/segtree>

using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N, K;
vector<int> A;
inline void input(){
    fast_io();
    cin >> N >> K;
    A = fetch_vec<int>(N);
}

inline void chmax(int &a, int b){if(a<b) a=b;}

using S = int;
S op(S x, S y){return max(x,y);}
S e(){return 0;}

inline int solve(){
    vector<int> dp(N+2, 0);
    // dp[0] = 0;
    // dp[1] = 1;
    int ans = 0;
    atcoder::segtree<S, op, e> seg(300300);
    for (int i = 0; i < N; i++)
    {
        int _left = max(0, A[i]-K);
        int _right = min(300000, A[i]+K);
        int j = seg.prod(_left, _right + 1);
        dp[i] = j + 1;
        seg.set(A[i], dp[i]);
        // chmax(ans, dp[i]);
    }
    ans = seg.all_prod();
    cout << ans << endl;
    return 0;
}   

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


Measured memory_bytes: 10860
/* author   : mpily :-()
title : Competing.cpp
time :Sat May 16 10:36:41 2020

*/
#include<bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9+7;
bool isrot = false;
int64_t res[10000];
void init(){
	for(int i = 0; i < 10000; ++i) res[i] = 0;
}
int main(){
	init();
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int64_t ans = 0;
	int64_t p10 = 1;
	int md = 0;
	res[0] ++;
	if(p == 2){
		for(int64_t i = 0; i < n; ++i){
			if(s[i] == '0' || s[i] == '2' || s[i] == '4' || s[i] == '6' || s[i] == '8'){
				ans+=(i+1);
			}
		}
		cout << ans <<"\n";
		return 0;
	}
	if(p == 5){
		for(int64_t i = 0; i < n; ++i){
			if(s[i] == '0' || s[i] == '5'){
				ans+=(i+1);
			}
		}
		cout << ans <<"\n";
		return 0;
	}
	for(int i = n-1; i >= 0; --i){
		md +=(p10*(s[i]-'0'));
		md%=p;
		ans+=res[md];
		res[md]++;
		p10*=10;
		p10%=p;		
	}
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 644
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	ss := split(s)
	tt := split(t)
	min := 1000

	nocut := false
	for i := 0; i < len(ss);i++ {
		cnt := len(tt)
		for j := 0; j < len(tt); j++ {
			if i+j == len(ss) {
				// if i+j >= len(ss)-1 {
				nocut = true
				break
			}

			if ss[i+j] == tt[j] {
				cnt--
			}
		}
		if nocut {
			continue

		}
		if cnt <  min {
			min = cnt
		}
	}

	fmt.Println(min)
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 1888
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
/* *
 *
 * Author: OakenSh1eld
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b; cin>>a>>b;
	ll d = __gcd(a, b);
	int ans = 1;
	for(ll i = 2; i*i<=d; ++i){
		if(d%i==0){
			ans++;
			while(d%i==0) d/=i;
		}
	}
	if(d>1) ans++;
	cout<<ans;
	return 0;
}


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

int mp[N][N],dp[N][N];

int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}

int main(){
  int h,w;
  cin>>h>>w;

  int ans = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) scanf("%d",&mp[i][j]),Max(ans,!mp[i][j]);
  
  for(int i=0;i<h;i++) dp[i][0] = !mp[i][0];
  for(int j=0;j<w;j++) dp[0][j] = !mp[0][j];

  for(int i=1;i<h;i++)
    for(int j=1;j<w;j++){
      if(mp[i][j])continue;
      int val = 1e9;
      if(i) Min(val,dp[i-1][j]);
      if(j) Min(val,dp[i][j-1]);
      if(i&&j) Min(val,dp[i-1][j-1]);
      dp[i][j] = val+1;
      Max(ans,dp[i][j]);
    }
  
  cout<<ans*ans<<endl;
  return 0;
}

Measured memory_bytes: 16444
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  string s; cin >> s;
  int maxx = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      if (n - j <= maxx) break;
      if (s[i] == s[j] && s[i+maxx] == s[j+maxx]) {
        int local = 1, len = j - i - 1;
        if (len + 1 <= maxx) continue;
        if (maxx != 0) {
          if (s[i+maxx-1] != s[j+maxx-1]) continue;
        }
        int l = i+1, r = j+1;
        while (s[l] == s[r] && len-- > 0) {
          l++; r++; local++;
        }
        maxx = max(maxx, local);
      }
    }
  }
  cout << maxx << endl;
  return 0;
}

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

int main() {
  int N;
  bool M=true;
  int Z=0;
  cin >> N;
  vector<int>vec(N);
  for (int X=0; X<N; X++){
    cin >> vec.at(X);
  }
  for (int Y=0; M==true; Y++){
    for (int X=0; X<N; X++){
      if (vec.at(X)%2==0){
        vec.at(X)/=2;
      }
      else{
        M=false;
        break;
      }
      if (X==N-1){
        Z+=1;
      }
    }
  }
  cout << Z << endl;
}


Measured memory_bytes: 3592
N=list(input())
n=[int(s) for s in N]
if n[-1]==2 or n[-1]== 4 or n[-1]== 5 or n[-1]== 7 or n[-1]== 9:
    print('hon')
elif n[-1]==0 or n[-1]==1 or n[-1]== 6 or n[-1]== 8:
    print('pon')
else :
    print('bon')


Measured memory_bytes: 9192
#include<stdio.h>
int main(void)
{
	char str;
	int i;
	char scan[] = { 'a','i','u','e','o' };
	scanf("%c", &str);
	for (i = 0; i < 5; i++)
	{
		if (str == scan[i])
		{
			printf("vowel\n");
			break;
		}
		else if (i == 4 && str != scan[i])
		{
			printf("consonant\n");
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    YORN (a <= x && x <= a + b) {

    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int i,j,k,v;
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		int array[] = new int[n];

		for(i=0;i<n;i++)array[i] = Integer.parseInt(in.next());

	for(i=0;i<n;i++){
		v = array[i];
		j = i-1;
		while(j>=0 && array[j]>v){
			array[j+1] = array[j];
			j--;
		array[j+1] = v;
		}
	    for(k = 0;k<n-1;k++)System.out.print(array[k]+" ");
	    if(i<(n-1))System.out.println(array[k]);
	    else System.out.println(array[k]);
	}
	}

}

Measured memory_bytes: 32008
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new B().doIt();
    }
    class B{
    	class map{
    		int h,w,S;
    		public map(int h,int w,int S){
    			this.h = h;
    			this.w = w;
    			this.S = S;
    		}
    	}
        void doIt(){
        	ArrayList<map> array = new ArrayList<map>();
    		for(int i = 1;i < 152;i++){
    			for(int j = i+1;j < 152;j++){
    				array.add(new map(i,j,(i*i) + (j*j)));
    			}
    		}
    		int length = array.size();
    		for(int i = 1;i < length;i++){
    			for(int j = i;j > 0;j--){
    				if(array.get(j).S  < array.get(j-1).S){
    					map m = array.get(j);
    					array.set(j, array.get(j-1));
    					array.set(j-1, m);
    				}
    				else if(array.get(j).h < array.get(j-1).h){
    					map m = array.get(j);
    					array.set(j, array.get(j-1));
    					array.set(j-1, m);
    				}else break;
    			}
    		}
        	while(true){
        		int h = sc.nextInt();
        		int w = sc.nextInt();
        		if(h+w == 0)break;
        		map m = new map(h,w,(h*h) + (w*w));
        		for(int i = 0;i < length;i++){
        			if(array.get(i).h == m.h && array.get(i).w == m.w){
        				System.out.println(array.get(i+1).h+" "+array.get(i+1).w);
        				break;
        			}
        		}
        	}
        }
    }
}

Measured memory_bytes: 28716
N,M=map(int,input().split())

flag=True
ex=[False]*(N)
for i in range(M):
    S,C=map(int,input().split())
    if ex[S-1]==False or ex[S-1]==str(C):
        ex[S-1]=str(C)
    else:
        flag=False
        break

if N>1 and ex[0]==str(0):
    flag=False

if flag:
    for i in range(N-1):
        if ex[i+1]==False:
            ex[i+1]='0'
    if ex[0]==False and N>1:
        ex[0]='1'
    elif ex[0]==False:
        ex[0]='0'
    Ex=''.join(ex)
    print(Ex)
else:
    print(-1)

Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl().chars().vec();
    let K = read!(i64);

    let mut c = '1';
    for i in 0..(min(K, S.len() as i64) as usize) {
        if S[i] != '1' {
            c = S[i];
            break;
        }
    }

    println!("{}", c)
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<int> a(n);
    vector<P> ta(n);
    vector<int> b(n);
    vector<P> tb(n);
    rep(i,n){
        cin>> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int am,bm;
    int ans;
    if(n%2==0)
    {
        am = a[n / 2 - 1] + a[n / 2];
        bm = b[n / 2 - 1] + b[n / 2];
        ans = bm-am+1;

    }else
    {
        am = a[n / 2];
        bm = b[n / 2];
        ans = bm-am+1;
    }
    cout << ans << endl;

}

Measured memory_bytes: 7956
def add(a, w, d)
  while a <= $n
#    p "a: #{a}"
    d[a] += w
    a += a & -a
  end
end

def sum(i, d)
  ret = 0
  x = i
  while x > 0
    ret += d[x]
    x -= x & -x
  end
  return ret
end

$n, q = gets.split.map(&:to_i)
d = Array.new($n+1){0}
p = Array.new($n+1){0}

q.times{
  com, s, t, x = gets.split.map(&:to_i)
  case com
  when 0
    add(s, x, d)
    add(t+1, -x, d)
    add(s, -x*s, p)
    add(t+1, x*(t+1), p)
  when 1
    p sum(t, p) + sum(t, d)*(t+1) - sum(s, p) - sum(s, d) * s
  end
}

Measured memory_bytes: 10700
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<bitset>
#define inf 999999999
#define int long long
using namespace std;
int a[100001];
int b[100001];
signed main()
{
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+m+1);
	for(int i=1;i<m;i++)
		b[i]=a[i+1]-a[i];
	sort(b+1,b+m);
	int ans=0;
	for(int i=1;i<=m-n;i++)
		ans+=b[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std ; 
const int inf = 1012345678;

int main(){
  int64_t N  ;
  cin >> N ; 
  
  int64_t a , b , c , d , e ; 
  cin >> a >> b >> c >> d >> e ; 
  int64_t min_t = min( a , min( min(b,c),min(d,e) ) ) ; 
  //cout << min_t << endl ;
  
  if(N%min_t ==  0 ){
    cout << N/min_t + 4 << endl ; 
  }
  else{
  	cout << (N/min_t) + 4 + 1 << endl ;
  }

  //975529666566238
}

Measured memory_bytes: 3520
def resolve():
    A, B, C = list(map(int, input().split()))
    rems = []
    mul = 1
    while True:
        rem = (mul * A) % B
        if rem == C:
            print("YES")
            return
        if rem in rems:
            print("NO")
            return
        rems.append(rem) 
        mul += 1
    


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3060
def triangle?(a, b, c)
  a <= b + c && b <= c + a && c <= a + b
end

def valid?(a, b, c)
  triangle?(a, b, c) || triangle?(a + 1, b, c)
end

def calc(rear, front, west, east, north, south, best)
  path = ''
  loop do
    a = rear + front
    b = west + east
    c = north + south

    return path if a + b + c == 0

    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 'E'
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 'N'
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 'S'
    elsif west > 0 && valid?(b - 1, c, a)
      rear, front, west, east = west - 1, east, front, rear
      y = 'W'
    else
      throw 'error'
    end
    
    if best
      x = best[path.size]
      return best if x < y
      best = nil if x > y
    end
    path << y  
  end
end

def find(target)
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, best)
    end
  end
  best
end

loop do
  target = gets.split.map!(&:to_i)
  break if target.max == 0
  p, q = gets.split.map!(&:to_i)
  result = find(target)
  puts result ? result[p-1...q] : 'impossible'
end

Measured memory_bytes: 9832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll num[18];

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

    ll tmp = n;
    ll i = 0;
    while(tmp){
        num[i] = tmp % 10;
        tmp /= 10;
        i++;
    }

    ll sum = 0;
    rep(j, 0, i - 1){
        if(num[j] != 9){
            sum += 9;
            num[j + 1]--;
        }else{
            sum += num[j];
        }
    }
    sum += num[i - 1];

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256