akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{    
    int x[3];
    cin >> x[0] >> x[1] >> x[2];

    int min_cnt = 1 << 29;
    rep(i,52)
    {
        int tmp_cnt = 0;
        rep(j,3)
        {
            if(x[j] >= i) tmp_cnt += x[j]-i;
            else tmp_cnt += (i-x[j])/2 + 2*int((i-x[j])%2!=0);
        }
        min_cnt = min(min_cnt,tmp_cnt);
    }

    cout << min_cnt << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }
  else if(a>=6){
    cout<<b/2<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

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

    int a[10] = {0};
    rep(i,n){
        int x;
        cin >> x;
        a[min(x / 400,8)]++;
    }

    int cnt = 0;
    rep(i,8) if(a[i] != 0) cnt++;

    cout << max(cnt,1) << ' ' << a[8] + cnt << endl;
}


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

int main() {
    string N, ans = "No";
    cin >> N;
    if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int cnt=0;
   if(s=="RSR"){
    cout<<"1"<<endl;
    return 0;
   }else{
     for(int i=0;i<s.size();i++){
        if(s[i]=='R')
            cnt++;
    }
   }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3620
s = input()
n = len(s)
c = 0
ans = 0
box = [0] * (n + 1)
for i in range(n):
        if s[i] == "<":
            c += 1
            box[i+1] = c
        else:
            c = 0
c = 0
for i in range(n):
        if s[n-1-i] == ">":
            c += 1
            box[n-1-i] = max(box[n-1-i],c)
        else:
            c = 0

for  i in range(n+1):
    ans += box[i]

print(ans)
  

Measured memory_bytes: 23380
#include<iostream>
using namespace std;
 
int main()
{
	string n;
	cin >> n;
	for (int i = 0; i < n.length(); i++) {
		if (n[i] == '1') {
			n[i] = '9';
		} else if (n[i] == '9') {
			n[i] = '1';
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

struct edge{
    int v,nx;
    ll a,b;
}e[210];
int head[60],cnt;
ll c[60],d[60];
ll dis[60][3000];
void add(int u,int v,ll a,ll b){
    e[++cnt].v=v;
    e[cnt].a=a;
    e[cnt].b=b;
    e[cnt].nx=head[u];
    head[u]=cnt;
}
struct node{
    int u;
    ll s,t;
    bool operator <(const node &x)const{
        return t>x.t;
    }
};
ll dis1[100];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m;
    ll s;
    cin>>n>>m>>s;
    for(int i=1;i<=m;i++){
        int u,v;
        ll a,b;
        cin>>u>>v>>a>>b;
        add(u,v,a,b);
        add(v,u,a,b);
    }
    for(int i=1;i<=n;i++)cin>>c[i]>>d[i];
    if(s>2500){
        for(int i=1;i<=n;i++)dis1[i]=inf*inf;
        dis1[1]=0;
        priority_queue<pii,vector<pii>,greater<pii> > q;
        q.push(mp(0,1));
        while(!q.empty()){
            pii p=q.top();
            q.pop();
            int u=p.se;
            if(dis1[u]<p.fi)continue;
            for(int i=head[u];i;i=e[i].nx){
                int v=e[i].v;
                if(dis1[v]>dis1[u]+e[i].b){
                    dis1[v]=dis1[u]+e[i].b;
                    q.push(mp(dis1[v],v));
                }
            }
        }
        for(int i=2;i<=n;i++)
            cout<<dis1[i]<<endl;
        return 0;
    }
    priority_queue<node> q;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=50*n;j++)
            dis[i][j]=1e18;
    dis[1][s]=0;
    q.push((node){1,s,0});
    while(!q.empty()){
        node p=q.top();
        q.pop();
        int u=p.u;
        if(p.t>dis[u][p.s])continue;
        for(int i=head[u];i;i=e[i].nx){
            int v=e[i].v;
            if(p.s>=e[i].a&&dis[v][p.s-e[i].a]>dis[u][p.s]+e[i].b){
                dis[v][p.s-e[i].a]=dis[u][p.s]+e[i].b;
                q.push((node){v,p.s-e[i].a,dis[u][p.s]+e[i].b});
            }
        }
        ll ts=min(p.s+c[u],50ll*n);
        if(dis[u][ts]>dis[u][p.s]+d[u]){
            dis[u][ts]=dis[u][p.s]+d[u];
            q.push((node){u,ts,dis[u][p.s]+d[u]});
        }
    }
    for(int i=2;i<=n;i++){
        ll ans=1e18;
        for(int j=0;j<=50*n;j++)
            ans=min(ans,dis[i][j]);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 7560
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
vector<vector<int>> v(201);

int target[201];
int res[201];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i)
    {
        cin >> target[i];
        target[i]--;
    }

    for (int i = 0; i < M; ++i)
    {
        int fail = 0;
        for (int j = 0; j < N; ++j)
        {
            int a;
            cin >> a;
            a--;
            if (a == target[i])
                res[j]++;
            else
                fail++;
        }

        res[target[i]] += fail;
    }

    for (int i = 0; i < N; ++i)
    {
        cout << res[i] << endl;
    }
    return 0;
}



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

using namespace std;
#pragma GCC optimize("O3")

typedef long long ll;
typedef long double ld;
int lst;
int sz = 0;
const int mod = 998244353;
const int maxN = 500000 + 40;
const int pt[2] = {228, 1337};
int pw[2][maxN];
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int pww(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pww(a, b - 1));
    int res = pww(a, b / 2);
    return mult(res, res);
}
int n;
int hsh[2][maxN];
char c[maxN];
int pos[maxN];
int inv[2][maxN];
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < 2; i++) {
        pw[i][0] = 1;
        inv[i][0] = 1;
        int inv_val = pww(pt[i], mod - 2);
        for (int j = 1; j < maxN; j++) {
            pw[i][j] = mult(pw[i][j - 1], pt[i]);
            inv[i][j] = mult(inv[i][j - 1], inv_val);
        }
    }
    const int SHIFT = maxN / 2;
    int CUR = 0;
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
        for (int j = 0; j < 2; j++) {
            hsh[j][i] = hsh[j][i - 1];
        }
        if (c[i] == '>') CUR++;
        else if (c[i] == '<') CUR--;
        else if (c[i] == '+') {
            for (int j = 0; j < 2; j++) {
                hsh[j][i] = sum(hsh[j][i], pw[j][CUR + SHIFT]);
            }
        }
        else if (c[i] == '-') {
            for (int j = 0; j < 2; j++) {
                hsh[j][i] = sub(hsh[j][i], pw[j][CUR + SHIFT]);
            }
        }
        else {
            assert(false);
        }
        pos[i] = CUR;
    }
    //diff
    map < pair < int, int >, int > mp;
    ll ans = 0;
    for (int suf = n; suf >= 1; suf--) {
        mp[make_pair(hsh[0][suf], hsh[1][suf])]++;
        int t[2] = {0, 0};
        for (int j = 0; j < 2; j++) {
            if (pos[suf - 1] >= 0) {
                t[j] = sum(hsh[j][suf - 1], mult(hsh[j][n], pw[j][pos[suf - 1]]));
            }
            else {
                t[j] = sum(hsh[j][suf - 1], mult(hsh[j][n], inv[j][-pos[suf - 1]]));
            }
        }
        ans += mp[make_pair(t[0], t[1])];
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 45696
#include<bits/stdc++.h>
#define int long long
#define dd second
#define ff first
#define mp make_pair
#define pb push_back
using namespace std;
int n;
int tab[100005];
int poz1,poz2;
int mod = 1e9+7;

int sil[100005];

int poww(int x, int y)
{
	if(y == 0) return 1; if(y == 1) return x;
	if(y & 1) return poww(x,y-1)*x % mod;
	int k = poww(x,y/2);
	return k*k%mod;
}

int newton(int a, int b)
{
	if(b > a) return 0;
	if(b < 0) return 0;
	if(b == 0) return 1;
	return (sil[a]*poww(sil[b],mod-2)%mod)*poww(sil[a-b],mod-2) % mod;
}

int count(int dl)
{
	return (mod+newton(n+1,dl) - newton(poz1-1+n+1-poz2, dl-1))%mod;
}

main()
{
	ios_base::sync_with_stdio(false);
 	cin >> n;
	sil[0] = 1; for(int i = 1; i < 100005; ++i) sil[i] = sil[i-1]*i % mod;
	for(int i = 0; i <=n; ++i) tab[i] = -1;
	for(int i = 1; i <= n+1; ++i)
	{
		int temp; cin >> temp;
		if(tab[temp] != -1)
		{
			poz1 = tab[temp]; poz2 = i;
		}
		tab[temp] = i;
	}

	for(int i = 1; i <= n+1; ++i)
	{
		cout << count(i) << endl;
	}
}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;
int main()
{
	int n, sum = 0, min;
	string s;
	cin >> n >> s;
	for(int i = 1; i < n; i++)
		if( s[i] == 'E' )
			sum++;
	min = sum;
	for(int i = 0; i < n-1; i++)
	{
		if( s[i] == 'W' )
			sum++;
		if( s[i+1] == 'E' )
			sum--;
		if( min > sum )
			min = sum;
	}
	cout << min;
}

Measured memory_bytes: 3896
n = int(input())
A = [0 for i in range(n)]
B = [0 for i in range(n)]
C = [0 for i in range(n)]

for i in range(n):
        A[i], B[i], C[i] = map(int, input().split())

dp = [[0 for i in range(3)] for j in range(n)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]
for i in range(1, n):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B[i]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[n - 1]))


Measured memory_bytes: 36136
#include <iostream>
#include <set>

using namespace std;

int main(){
    
    int N;
    cin>>N;
    string s[N];
    
    set<string> names;
       
      
    
    for(int i=0;i!=N;++i){
        cin>>s[i];
         names.insert(s[i]);
    }
   
    
    cout<<names.size()<<endl;
    return 0;
}

Measured memory_bytes: 25476
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

    vector<pii> p;
    rep(i, 0, n)
    {
        int pi;
        cin >> pi;
        p.emplace_back(pi, i);
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    
    multiset<int> points;
    points.insert(n);
    points.insert(n);
    points.insert(-1);
    points.insert(-1);
    ll ans = 0;
    rep(i, 0, n)
    {
        int num, j;
        tie(num, j) = p[i];

        multiset<int>::iterator itr = points.lower_bound(j);

        int l2, l1, r1, r2;
        r1 = *itr;
        advance(itr, 1);
        r2 = *itr;
        advance(itr, -2);
        l1 = *itr;
        advance(itr, -1);
        l2 = *itr;
        ll cnt = 0;
        cnt += (r2 - r1) * (j - l1);
        cnt += (l1 - l2) * (r1 - j);
        ans += (ll) cnt * num;

        // cout << ans << ' ' << cnt << ' ' << num << endl;
        // cout << (r2 - r1) * (i - l1) << ' ' << (l1 - l2) * (r1 - i) << endl;
        points.insert(j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

long long inf = 1e18 + 5;
long long mod = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> g(n+2);
    vector<vector<int> > G(n+2, vector<int>(m+2, 0));
    string s = "";
    for(int i = 0; i < m+2; i++) {
        s.push_back('#');
    }
    g[0] = s;
    for(int i = 1; i < n+1; i++) {
        string ss;
        cin >> ss;
        ss = '#' + ss + '#';
        g[i] = ss;
    }
    g[n+1] = s;
    G[1][1] = 1;
    for(int i = 1; i < n+1; i++) {
        for(int j = 1; j < m+1; j++) {
            if(g[i][j] == '.' && (i != 1 || j != 1)) {
                G[i][j] = G[i-1][j] + G[i][j-1];
                G[i][j] %= mod;
            }
        }
    }
    cout << G[n][m];
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int max_a = a[max_element(a, a + n) - a];
    int b[n];
    for (int i = 0; i < n; i++) {
        b[i] = (a[i] == max_a) ? -1 : min(max_a - a[i], a[i]);
    }
    int max_b = a[max_element(b, b + n) - b];
    cout << max_a << ' ' << max_b << endl;
    return 0;
}


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

int main()
{
	vector<int> ans = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
	vector<int> s(9);
	for (int i = 0; i < 9; i++) {
		cin >> s[i];
	}
	map<vector<int>, int> mp; mp[s] = 1;
	queue<vector<int>> q; q.push(s);
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		if (p == ans) {
			cout << mp[p] - 1 << endl;
			break;
		}
		int zero;
		for (int i = 0; i < 9; i++) {
			if (p[i] == 0) {
				zero = i;
				break;
			}
		}
		auto cp = p;
		if ((zero + 1) % 3 != 0) {
			swap(cp[zero], cp[zero + 1]);
			if (mp[cp] == 0) {
				mp[cp] = mp[p] + 1;
				q.push(cp);
			}
			swap(cp[zero], cp[zero + 1]);
		}
		if (zero % 3 != 0) {
			swap(cp[zero], cp[zero - 1]);
			if (mp[cp] == 0) {
				mp[cp] = mp[p] + 1;
				q.push(cp);
			}
			swap(cp[zero], cp[zero - 1]);
		}
		if (zero < 6) {
			swap(cp[zero], cp[zero + 3]);
			if (mp[cp] == 0) {
				mp[cp] = mp[p] + 1;
				q.push(cp);
			}
			swap(cp[zero], cp[zero + 3]);
		}
		if (zero >= 3) {
			swap(cp[zero], cp[zero - 3]);
			if (mp[cp] == 0) {
				mp[cp] = mp[p] + 1;
				q.push(cp);
			}
			swap(cp[zero], cp[zero - 3]);
		}
	}
	return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 1e6 + 10;
const int Mod = 1e9 + 7;

void add(int &x, int y){
	x += y;
	if(x >= Mod) x -= Mod;
}

int mul(long long x, int y){
	return x * y % Mod;
}

int n, f[N];

int main(){
	scanf("%d", &n);

	f[0] = 1;
	int sum = 0;
	For(i, 1, n){
		f[i] = sum;
		add(f[i], f[i - 1]);
		if(i > 1) add(sum, f[i - 2]);
	}

	int ans = f[n];
	add(ans, mul(f[n - 1], n - 1));
	add(ans, mul(sum, mul(n - 1, n - 1)));
	For(i, 0, n - 2) add(ans, mul(f[i], i + 1));

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e6 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int r;
main() {
    file("censor");
    ios;
    cin >> r;
    cout << r * r;
//    cout << (PI * r * r) / (pi);
    return 0;
}
/**

*/


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



 int main(){
    int n;
    cin>>n;
  
  
    vector<int>k;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        k.push_back(x);
       }
       sort(k.begin(),k.end());
        float avg=k[0];
       for(int i=0;i<n;i++){
          avg=(k[i]+avg)/2;
         
       }
      
cout<< avg;
}

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

int main() {
  long n,nn,aaa=0;
  char a;
  string ans="";
  cin >> n;
  n--;
  nn=n;
  a=n%26+'a';
  ans=a+ans;
  n-=26;
  for(long i=26;true;i*=26) {
    aaa+=i;
    if(aaa>nn) break;
    a=n/i%26+'a';
    ans=a+ans;
    n-=i*26;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

long long N, A, B;

long long ans = 0;

int main()
{
    cin >> N >> A >> B;

    if((N == 1 && A != B) || A > B)
    {
        ans = 0;
    }
    else if(A == B)
    {
        ans = 1;
    }
    else
    {
        ans = 1 + (B - A) * (N - 2);
    }

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {	
	public void start() {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); 
		try {
			String str = input.readLine();
			int x = Integer.parseInt(str);
			System.out.println((int)Math.pow(x,3));
		}
		catch(IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.start();
	}
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
int main(){long N,x=0;cin>>N;
           for(long i=2;i<sqrt(N)+1;i++)
           {if(N%i==0){int a=0;while(N%i==0){a++;N/=i;}
int b=1,c=1;while(a>b){c++;b+=c;}if(a!=b)c--;x+=c;
                      }}if(N!=1)x++;cout<<x<<endl;}                 

Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
ll n,k;
int decode(ll x,ll y){
	x-=n/2+1;y-=n/2+1;
	ll t;
	if((x-y)*(x+y+(n+1)%2)>=0){
		if(x<0)t=n/2-abs(x);
		else t=(n-1)/2-x;
	}else{
		if(y<0)t=n/2-abs(y);
		else t=(n-1)/2-y;
	}
	return t%3+1;
}
int main()
{
	cin>>n>>k;
	while(k--){
		ll x,y;cin>>x>>y;
		printf("%lld\n",decode(x,y));
	}
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    string s;
    cin>>s;
    char atc[4]={'A','T','G','C'};

    int ans=-1;
    int now=0;
    rep(i,s.size()){
        rep(k,4){
            if(s[i]==atc[k]){
                now++;
                break;
            }
            else if(k==3){
                now=0;
            }
        }
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 256
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var h = int.Parse(s[0]);
            var a = int.Parse(s[1]);

            Console.WriteLine(h % a == 0 ? h / a : h / a + 1);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using ll = std::int_fast64_t;
const ll MOD = 1000000007;

ll inv(ll a){
        ll b = MOD, u = 1, v = 0;
        while(b){
                ll t = a/b;
                a -= t*b; std::swap(a, b);
                u -= t*v; std::swap(u, v);
        }
        u %= MOD;
        if(u<0) u += MOD;
        return u;
}

int main(){
        ll n, a, b;
        scanf("%ld %ld %ld", &n, &a, &b);

        ll ans = 1, p = 2, m = n;
        while(m>0){
                if(m&1) ans = ans * p %MOD;
                p = p * p % MOD;
                m >>= 1;
        }
        ans --;

        std::vector<ll> comb(2e5+1);
        comb[0] = 1;
        for(ll i=1; i<=2e5; i++){
                comb[i] = (comb[i-1] * (n-i+1) % MOD) * inv(i) % MOD;
        }

        ans -= comb[a] + comb[b];
        while(ans<0) ans += MOD;
        printf("%ld\n", ans);
        return 0;
}

Measured memory_bytes: 1792
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using PII = pair<int,int>;

// void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
// void vvprn(vector<vector<int>> &vv){
// 	rp(i,0,vv.size()){
// 		printf("%d) ",i);
// 		if(vv[i].size()>0) vprn(vv[i]);
// 		else puts("");
// 	}
// }
// void vp_print(vector<PII> &v){
// 	rp(i,0,v.size()){
// 		printf("%d:(%d,%d)\n",i,v[i].first, v[i].second);
// 	};
// }//


string solve(int N, int M, vi &A, vi &B){
	vvi tree(N+1, vi());
	rp(i,1,M+1){
		tree[A[i]].push_back(B[i]);
		// tree[B[i]].push_back(A[i]);
	}

	// printf("N %d M %d\n",N,M);//
	// vprn(A);//
	// vprn(B);//
	// vvprn(tree);//

	int count = 0;
	for(int c:tree[1]){
		for(int goal:tree[c]){
			// printf("c %d g %d\n",c,goal);//
			if(goal==N){
				count = 2;
			}
		}
	}
	return count==2? "POSSIBLE":"IMPOSSIBLE";
}

int main(){
	int N,M; cin>>N>>M;
	vi A(M+1), B(M+1);
	rp(i,1,M+1) cin>>A[i]>>B[i];
	ote(solve(N, M, A, B));
}


Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
const ll MOD =998244353;
template<typename T>
struct SegmentTree{
private:
    int n;
    vector<T> node;
public:
    T merge(T x,T y){
        return (x+y)%MOD;
    }
    SegmentTree(vector<T> v){
        int sz=(int)v.size();
        n=1; while(n<sz)n*=2;
        node.resize(2*n-1,0);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--){
            node[i]=merge(node[2*i+1],node[2*i+2]);
        }
    }
    void update(int x,T val){
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=merge(node[2*x+1],node[2*x+2]);
        }
    }
    T query(int a,int b,int idx=0,int l=0,int r=-1){ /* get [a,b) */
        if(r<0) r=n;
        if(r<=a||b<=l) return 0;
        if(a<=l&&r<=b) return node[idx];
        T vl=query(a,b,2*idx+1,l,(l+r)/2);
        T vr=query(a,b,2*idx+2,(l+r)/2,r);
        return merge(vl,vr);
    };
};
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<P> v(k);
    rep(i,k){
        cin >> v[i].fi >> v[i].se;
    }
    vector<ll> ans(n,0);
    ans[0]=1;
    SegmentTree<ll> dp(ans);
    for(int i=1;i<n;i++){
        ll res=0;
        rep(j,k){
            int l=i-v[j].se,r=i-v[j].fi+1;
            chmax(l,0);
            chmin(r,n);
            res+=dp.query(l, r);
            res%=MOD;
        }
        dp.update(i,res);
    }
    ll out=dp.query(n-1,n);
    out%=MOD;
    cout << out << endl;
    
    
}




Measured memory_bytes: 10324
# ITP1_2_D
# Circle in a Rectangle
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_D
# encode : utf-8
W, H, x, y, r = map(int, input().split())
if r <= x <= (W-r) and r <= y <= (H-r):
    print('Yes')
else :
    print('No')


Measured memory_bytes: 5592
using System;
using System.Collections.Generic;
using System.Text;
using static System.Math;
using static System.Console;

namespace AtTest.D_Challenge
{
    class ABC_035
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk=ReadInts();
            int n=nk[0];
            int k=nk[1];
            int res=0;
            while(n>0)
            {
                res++;
                n/=k;
            }
            WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
    int r,c;
    cin >> r >> c;
    vector<vector<int> > t(r+1, vector<int>(c+1,0));
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin >> t[i][j];
            t[r][j] += t[i][j];
            t[i][c] += t[i][j];
            t[r][c] += t[i][j];
        }
    }

    for(int i=0; i<=r; i++){
        for(int j=0; j<c; j++){
            cout << t[i][j] << " ";
        }
        cout << t[i][c] << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
#include <stdio.h>
#include <ctype.h>
int main (void)
{
    char A[1000] = {0};
    char B[1000] = {0};
    char C[1000] = {0};

    scanf("%s %s %s",A,B,C);
    A[0] = toupper(A[0]);
    B[0] = toupper(B[0]);
    C[0] = toupper(C[0]);
    printf("%c%c%c\n",A[0],B[0],C[0]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    ll taka = a, aoki = b;
    rep(i, k) {
        if(i%2 == 0) {
            if(taka%2 == 1) {
                taka--;
            }
            aoki += taka/2;
            taka /= 2;
        }
        else {
            if(aoki%2 == 1) {
                aoki--;
            }
            taka += aoki/2;
            aoki /= 2;
        }
    }

    cout << taka << " " << aoki << endl;
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	ll ans = 0;
	vector<int> s(n);
	map<int, int> mapp;
	for(int i = 0; i < n; i++)
	{
		int a; cin >> a;
		s[i] = i + a + 1;
		mapp[i - a + 1]++;
	}
	for(int i = 0; i < n; i++) ans += mapp[s[i]];
	cout << ans;

	return 0;
}

Measured memory_bytes: 21004
#include <stdio.h>

int main(void){
    int go,st;
    int a[3];

    scanf("%i %i %i",&a[0],&a[1],&a[2]);

    for(int i=0; i<3;i++){
        if(a[i]==5) go++;
        else if(a[i]==7) st++;
    }

    if(go==2 && st==1){
        puts("YES");
    }else{
        puts("NO");
    }

}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a,b;
    cin >> a >> b;
    VL aa(b), bb(a);
    FOR(i,0,b){
        aa.at(i) = a;
    }
    FOR(i,0,a){
        bb.at(i) = b;
    }

    if(a == b){
        FOR(i,0,b){
            cout << aa.at(i);
            }
            cout <<endl;

    }else if(a > b){
        FOR(i,0,a){
            cout << bb.at(i);
        }
        cout << endl;
    }else if(a < b){
        FOR(i,0,b){
            cout << aa.at(i);

        }
        cout << endl;

    }
    

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn = 100100;


int main()
{
	int a;
	cin >> a;
	int f1 = a / 100;
	int f2 = a - 100 * f1;
	//cout << f1<<' '<<f2<<endl;
	if ((1 <= f1)&& (f1<= 12))
	{
	
		if ((1 <= f2) && (f2 <= 12))
			cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	else
	{
		if ((1 <= f2) && (f2 <= 12))
			cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}

	//system("pause");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class ABC117D
    {
        // https://atcoder.jp/contests/abc177/tasks/abc177_d

        static int[] ls;

        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split();
            int N = Int32.Parse(NM[0]);
            int M = Int32.Parse(NM[1]);

            ls = new int[N];
            for (int i = 0; i < N; i++)
            {
                ls[i] = -1;
            }

            for (int i = 0; i < M; i++)
            {
                var AB = Console.ReadLine().Split();
                int A = Int32.Parse(AB[0]) - 1;
                int B = Int32.Parse(AB[1]) - 1;

                bool a = hasFriend(A);
                bool b = hasFriend(B);

                int C = A;
                int D = B;

                if (a && b)
                {
                    C = getParent(A);
                    D = getParent(B);

                    if (C == D)
                    {
                        continue;
                    }
                }
                else if (a)
                {
                    C = getParent(A);
                }
                else if (b)
                {
                    C = getParent(B);
                    D = A;
                }

                ls[C] += ls[D]; // 人数加算
                ls[D] = C; // setParent
            }

            int max = 1;
            for (int i = 0; i < N; i++)
            {
                max = Math.Max(max, -ls[i]);
            }

            Console.WriteLine(max);
        }

        static int getParent(int A)
        {
            if (ls[A] > -1)
            {
                ls[A] = getParent(ls[A]);
                return ls[A];
            }
            return A;
        }

        static bool hasFriend(int A)
        {
            return (ls[A] != -1);
        }
    }
}


Measured memory_bytes: 46816
using System;

namespace Exa2019B
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            long red = 0;
            long blue = 0;
            for (int i = 0; i < N; i++)
            {
                if (s[i] == 'R')
                {
                    red++;
                }
                else
                {
                    blue++;
                }
            }
            Console.WriteLine(red > blue ? "Yes" : "No");
        }
    }
}

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

int main(){
  int cn=0;
  string s;cin>>s;
  int q;cin>>q;
  
  vector<char> data(0);
  for(int i=0;i<s.size();i++){
    data.push_back(s[i]);
  }
  
  vector<char> datat(0);
  vector<char> datab(0);
  
  for(int i=0;i<q;i++){
    int a;cin>>a;
    if(a==1){cn+=1;cn%=2;}
    else {
      int b;cin>>b;
      char c;cin>>c;
      if(b==2&&cn==0)datab.push_back(c);
      else if(b==2&&cn==1)datat.push_back(c);
      else if(b==1&&cn==0)datat.push_back(c);
      else if(b==1&&cn==1)datab.push_back(c);
    }
  }
  
  if(cn==0){
    for(int i=datat.size()-1;i>=0;i--)cout<<datat[i];
    for(auto x:data)cout<<x;
    for(int i=0;i<datab.size();i++)cout<<datab[i];cout<<endl;
  } else {
    for(int i=datab.size()-1;i>=0;i--)cout<<datab[i];
    for(int i=data.size()-1;i>=0;i--)cout<<data[i];
    for(int i=0;i<datat.size();i++)cout<<datat[i];cout<<endl;
  }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;


int main() {
  int n, ma = 0;
  cin >> n;
  map<string, int> memo;
  REP(i,n) {
    string s;
    cin >> s;
    if (memo.count(s)) ++memo[s];
    else memo[s] = 1;
    if (ma < memo[s]) ma = memo[s];
  }
  for (auto s : memo) {
    if (s.second == ma) cout << s.first << "\n";
  }
}

Measured memory_bytes: 25216
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node T[MAX];

int getDepth(int u){
  int d = 0;
  while(T[u].p != NIL){
    u = T[u].p;
    d++;
  }
  return d;
}

int getHeight(int u){
  int h1=0,h2=0;
  if (T[u].l != NIL) h1 = getHeight(T[u].l)+1;
  if (T[u].r != NIL) h2 = getHeight(T[u].r)+1;

  if(h1 > h2) return h1;
  else return h2;
}

int getSibling(int u){
  int sib;
  if (T[u].p == NIL) sib = NIL;
  else if (T[T[u].p].l != NIL && T[T[u].p].r != NIL){
    if (T[T[u].p].l == u) sib = T[T[u].p].r;
    if (T[T[u].p].r == u) sib = T[T[u].p].l;
  }
  return sib;
}

void print(int u){
  int degree = 0;
  
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].p,getSibling(u));
  if (T[u].l != NIL) degree++;
  if (T[u].r != NIL) degree++;
  printf("degree = %d, depth = %d, height = %d, ",degree,getDepth(u),getHeight(u));

  if(T[u].p == NIL) printf("root\n");
  else if(T[u].l == NIL && T[u].r == NIL) printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i;
  int n,id,l,r;

  scanf("%d",&n);

  for(i=0; i<n; i++) T[i].p = NIL;

  for(i=0; i<n; i++){
    scanf("%d%d%d",&id,&l,&r);
    T[id].l = l;
    T[id].r = r;
    if (l != NIL) T[l].p = id;
    if (r != NIL) T[r].p = id;
  }

  for(i=0; i<n; i++) print(i);

  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<long long> a(n),b(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	long long s=0;
	for(int i=0;i<30;i++){
		long long c=0;
		long long t=1LL<<i;
		vector<long long> x(n),y(n);
		for(int j=0;j<n;j++){
			x[j]=a[j]%(2*t);
			y[j]=b[j]%(2*t);
		}
		sort(y.begin(),y.end());
		for(int j=0;j<n;j++)
			c+=lower_bound(y.begin(),y.end(),4*t-x[j])-lower_bound(y.begin(),y.end(),3*t-x[j])+lower_bound(y.begin(),y.end(),2*t-x[j])-lower_bound(y.begin(),y.end(),t-x[j]);
		if(c%2==1)
		s+=t;
	}
	cout<<s;
}

Measured memory_bytes: 9544
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
const int N = 14;
const int INF = 1000000000;
string str[N],s[N];
int dp[N][1<<N],d[N][N],n;
int check(int x,int y)
{
	int i,j,r=0,l1=s[x].size(),l2=s[y].size();
	for(i=0;i<l1;i++)
	{
		for(j=0;i+j<l1&&j<l2;j++)if(s[x][i+j]!=s[y][j])break;
		if(i+j==l1&&r<j)r=j;
	}
	return r;
}
bool ck(int x,int y)
{
	int l1=str[x].size(),l2=str[y].size();
	int i,j;
	for(i=0;i<l2;i++)
	{
		for(j=0;j<l1&&i+j<l2;j++)if(str[x][j]!=str[y][i+j])break;
		if(j==l1)return true;
	}
	return false;
}
int dfs(int x,int zt)
{
	//printf("~!@ x:%d zt:%d \n",x,zt);
	if(dp[x][zt]!=-1)return dp[x][zt];
	dp[x][zt]=INF;
	int i;
	for(i=0;i<n;i++)
	{
		if((zt&(1<<i))&&i!=x)
		{
			int t=dfs(i,zt-(1<<x))+s[x].size()-d[i][x];
			//printf("x:%d zt:%d i:%d t:%d size:%d d:%d \n",x,zt,i,t,s[x].size(),d[i][x]);
			if(dp[x][zt]>t)dp[x][zt]=t;
		}
	}
	//printf("x:%d zt:%d dp:%d \n",x,zt,dp[x][zt]);
	return dp[x][zt];
}
int main()
{
	int i,j,k;
	while(~scanf("%d",&n))
	{
		if(!n)break;
		for(i=0;i<n;i++)cin >> str[i];
		k=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(i!=j&&ck(i,j))break;
			}
			if(j==n)s[k++]=str[i];
		}
		//puts("what");
		n=k;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				d[i][j]=check(i,j);
				//printf("i:%d j:%d d:%d \n",i,j,d[i][j]);
			}
		}
		memset(dp,-1,sizeof(dp));
		for(i=0;i<n;i++)dp[i][1<<i]=s[i].size();
		int L=(1<<n)-1;
		for(i=0;i<n;i++)dfs(i,L);
		int r=INF;
		for(i=0;i<n;i++)if(r>dp[i][L])r=dp[i][L];
		printf("%d\n",r);
	}
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << x << '\n'
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int INF = 1e9 + 5;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for (int& i : h)
    cin >> i ;

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

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

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

int N;
const int max_N = 303;
double dp[max_N][max_N][max_N];
double cal(int i,int j,int k){
    if(i == 0&&j == 0&&k == 0){
        return 0.0;
    }
    if(dp[i][j][k] > 0){
        return dp[i][j][k];
    }
    int l = i + j + k;
    double A = 1.0*N/l;
    if(i){
        A += 1.0*i/l*cal(i-1,j,k);
    }
    if(j){
        A += 1.0*j/l*cal(i+1,j-1,k);
    }
    if(k){
        A += 1.0*k/l*cal(i,j+1,k-1);
    }
    dp[i][j][k] = A;
    return A;
}
int main()
{
    cin >> N;
    double a[4] = {};
    for(int i = 0;i < N;i++){
        int count;
    cin >> count;
        a[count]++;
    }
    for(int i = 0;i < max_N;i++){
        for(int j = 0;j < max_N;j++){
            for(int k = 0;k < max_N;k++){
                dp[i][j][k] = 0.0;
            }
        }
    }
    cout << fixed << setprecision(11) << cal(a[1],a[2],a[3]) << endl;


}


Measured memory_bytes: 217600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
const int MX = 100005;
 
int main(){
  int n;
  cin >> n;
  string S;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for(int i=0; i < n; i++){
    cin >> S;
    if(S=="AC"){
      ac++;
    }else if(S=="WA"){
      wa++;
    }else if(S=="TLE"){
      tle++;
    }else if(S=="RE"){
      re++;
    }
  }
  cout << "AC x "<< ac << endl;
  cout << "WA x "<< wa << endl;
  cout << "TLE x "<< tle << endl;
  cout << "RE x "<< re << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void B_task();

int main()
{
	B_task();
	
	fflush(stdout);
	return 0;
}

typedef std::pair<int, int> Formula;

class Point {
public:
	int x = 0;
	int y = 0;

	static bool sort_dsc(const Point& a, const Point& b) {
		bool ret = false;
		if (a.x > b.x) {
			ret = true;
		}
		else if (a.x == b.x) {
			if (a.y > b.y) {
				ret = true;
			}
		}
		return ret;
	}

};

static void B_task()
{
	int N;
	Point pt[51];

	scanf(" %d", &N);
	for (int i = 0; i < N; i++) {
		scanf(" %d %d", &(pt[i].x), &(pt[i].y));
	}

	std::sort(pt, pt + N, Point::sort_dsc);

	std::map<Formula, int> pqList;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			Formula fml;
			fml.first = pt[i].x - pt[j].x;
			fml.second = pt[i].y - pt[j].y;

			if (pqList.find(fml) != pqList.end()) {
				pqList[fml]++;
			}
			else {
				pqList[fml] = 1;
			}
		}
	}

	int maxPq = 0;
	for (auto pqIt = pqList.begin(); pqIt != pqList.end(); pqIt++) {
		maxPq = std::max(maxPq, pqIt->second);
	}

	printf("%d\n", (N - maxPq));
}


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

int main() {
	static long long N, M, A[100010] = {};
	map<long long, long long, greater<long long> > mp;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	for (int i = 0; i < M; i++) {
		long long B, C;
		cin >> B >> C;
		mp[C] += B;
	}
	static long long X[100010] = {};
	int Count = 0;
	for (auto i = mp.begin(); i != mp.end(); i++) {
		for (int j = 0; j < i->second; j++) {
			X[Count] = i->first;
			Count++;
			if (Count == N) break;
		}
		if (Count == N) break;
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += max(A[i], X[i]);
	}
	cout << ans << endl;
}

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

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> tree(n + 1);
    int a, b;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    sort(c.rbegin(), c.rend());
    int tmp = 0;
    int idx = 0;
    vector<int> ans(n + 1, 0);
    for (int i = 1; i < tree.size(); ++i) {
        if(tree[i].size() > tmp){
            idx = i;
            tmp = tree[i].size();
        }
    }
    priority_queue<P> que;
    que.push(make_pair(tmp, idx));
    int j = 0;
    vector<int> visited(n + 1, 0);
    visited[idx] = 1;
    ll summ = -c[0];
    while(!que.empty()){
        P p = que.top();
        que.pop();
        ans[p.second] = c[j];
        summ += c[j];
        j++;
        for (int i = 0; i < tree[p.second].size(); ++i) {
            if(visited[tree[p.second][i]] == 0) {
                visited[tree[p.second][i]] = 1;
                que.push(make_pair(tree[tree[p.second][i]].size(), tree[p.second][i]));
            }
        }
    }
    cout << summ << endl;
    for (int i = 1; i < ans.size(); ++i) {
        if(i == 1) cout << ans[i];
        else cout << ' ' << ans[i];
    }cout << endl;
}

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

using namespace std;
int a[1234],n,m;
int main(){
  cin>>n>>m;
  for (int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  for (int i=0;i<n;i++) m-=a[i];
  cout<<n+(int)m/a[0];
  return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n, m = map(int, input().split())
    max = 0
    min = n

    for i  in range(m):
        l,r = map(int, input().split())
        if l > max:
            max = l
        if r < min:
            min = r


    if max <= min:
        print(min - max +1)
    else:
        print(0)






Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x!=0)
        cout<<(n/x+1)*t<<endl;
    else
        cout<<(n/x)*t<<endl;
    return(0);
}

Measured memory_bytes: 3620
def s(n):
    sum = 0
    while True:
        sum += n % 10
        if n < 10:
            break
        n = n//10
    return sum


def calc(n, a, b):
    sum = 0
    for i in range(1, n+1):
        k = s(i)
        if a <= k <= b:
            sum += i
    return sum


n, a, b = list(map(int, input().split()))
r = calc(n, a, b)
print(r)


Measured memory_bytes: 3060