akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;

using namespace std;

class MaximumMoves {
 public:
    long getMaximumMoves(long x, long y) {
        if (x + 2 > y) {
            return -1;
        }
        return (y - x) / 2;
    }
};

struct Matrix {
    explicit Matrix() : a(26, vector<ll>(26, 0)) {
    }
    vector<vector<ll>> a;

    vector<ll> &operator[](int i) {
        return a[i];
    }

    const vector<ll> &operator[](int i) const {
        return a[i];
    }

    Matrix operator*(const Matrix &rhs) {
        Matrix res;
        for (int i = 0; i < 26; ++i) {
            for (int k = 0; k < 26; ++k) {
                for (int j = 0; j < 26; ++j) {
                    if (1.0 * a[i][j] * rhs[j][k] > 1e15) {
                        res[i][k] = 1e15 + 1;
                    } else {
                        res[i][k] += a[i][j] * rhs[j][k];
                    }
                }
                if (res[i][k] > 1e15) {
                    res[i][k] = 1e15;
                }
            }
        }
        return res;
    }

};

//Matrix pow(const Matrix &a, int pw) {
//    if (pw == 0) {
//        return a;
//    }
//    Matrix res = pow(a, pw / 2) * pow(a, pw / 2);
//    if (pw % 2 == 1) {
//        res = res * a;
//    }
//    return res;
//}

vector<ll> MultPerm(const vector<int> &a, ll pow) {
    if (pow == 0) {
        vector<ll> res(26);
        for (int i = 0; i < 26; ++i) {
            res[i] = i;
        }
        return res;
    }
    auto pow_div2 = MultPerm(a, pow / 2);
    auto res = pow_div2;
    for (int i = 0; i < 26; i++) {
        res[i] = pow_div2[res[i]];
    }
    if (pow % 2 == 1) {
        for (int i = 0; i < 26; ++i) {
            res[i] = a[res[i]];
        }
    }
    return res;
}
vector<Matrix> pw(60, Matrix());

ll length(char x, int pow) {
    ll ret = 0;
    for (int i = 0; i < 26; ++i) {
        ret += pw[pow][i][x - 'a'];
    }
    if (ret > 1e15) {
        return 1e15 + 1;
    } else {
        return ret;
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
   // freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    int  n;
    cin>>n;
    cout<<(n-1)/2;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
//#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}

string binaryStr(int n,int d){
	string s;
	while(n>0){
		if(n%2==0){
			s.push_back('0');
		}else{
			s.push_back('1');
			n--;
		}
		n/=2;
	}
	while(s.size()!=d){
		s.push_back('0');
	}
	reverse(s.begin(),s.end());
	return s;
}

int main(){
	
	int d,g;
	cin>>d>>g;
	g/=100;
	vector<int> p(d),c(d);
	rep(i,d){
		cin>>p[i]>>c[i];
		c[i]/=100;
	}
	int a[11];
	int ans=INF;
	rep(za,POW(2,d)){
		int x=0;
		int m=0;
		string s = binaryStr(za,d);
		rep(i,d){
			if(s[i]=='1'){
				x+=p[i]*(i+1)+c[i];
				m+=p[i];
			}
		}
		if(x>=g){
			ans=min(ans,m);
			continue;
		}
		rrep(i,d){
			if(s[i]=='0'){
				if(g-x<=(i+1)*p[i]){
					if((g-x)%(i+1)!=0) ans=min(ans, m+((g-x)/(i+1))+1);
					else ans=min(ans, m+((g-x)/(i+1)));
				}else{
					x+=(i+1)*p[i];
					m+=p[i];
				}
				if(x>=g){
					ans=min(ans,m);
					continue;
				}
			}
		}
	}
	cout<<ans<<endl;
				
		


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define all(x) (x).begin(),(x).end()

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


Measured memory_bytes: 256
require 'prime'

th = 10**9 + 7
n = gets.to_i
h = Hash.new(0)
(2..n).each do |i|
  Prime.prime_division(i).each do |k, v|
    h[k] += v
  end
end
puts h.values.inject(1) { |sum, i| sum * (i + 1)} % th

Measured memory_bytes: 14364
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	int result = 0;

	char curr = S.back();
	for (int i = S.size() - 2; i >= 0; i--)
	{
		if (S[i] != curr)
		{
			curr = S[i];
			result++;
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    } 
    int ans = mp.size();
    ans -= 1 - ans%2;

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

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main()
{
	int N,W;
	cin >> N >> W;
	int v[N],w[N];
	for(int i=0;i<N;i++){
		cin >> v[i] >> w[i];
	}
	int DP[N+1][W+1];
	for(int i=0;i<=W;i++){
		DP[0][i] = 0;
	}
	for(int j=0;j<=N;j++){
		DP[j][0] = 0;
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=W;j++){
			if(j<w[i-1])
				DP[i][j] = DP[i-1][j];
			else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
					DP[i][j] = DP[i-1][j];
				else
					DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
			}
		}
	}
	cout << DP[N][W] << endl;
	return 0;
}
 
		

Measured memory_bytes: 5108
from collections import Counter
n=int(input())
x=[]
for i in range(n):
    x.append(input())
x=Counter(x)    
x=x.most_common()
max_count=x[0][1]
max_list=[x[0][0]]
if len(x)>1:
    for i in range(1,n):
        if x[i][1] < max_count:
            break
        else:
            max_list.append(x[i][0])

#y=max_list.sort()
max_list=sorted(max_list)
for w in max_list:
    print(w)

Measured memory_bytes: 43476
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int y3 = y2 - (x1 - x2);
	int x3 = x2 - (y2 - y1);
	int x4 = x1 - (y2 - y1);
	int y4 = y1 - (x1 - x2);
	cerr << x1 - x2 << " " << y2 - y1 << endl;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
struct node {
	int x;
	int y;
	int n;
	int ar;
};
bool operator < (node a,node b) {
	return a.n < b.n;
}
bool operator > (node a,node b) {
	return a.n > b.n;
}
priority_queue<node, vector<node>, greater<node>> q;
char s[105][105];
int dis[105][105];
int h, w;
int ans = INF;
int f(char a) {
	if (a=='#') {
		return 1;
	}
	else {
		return 0;
	}
}
int main() {
	//std::ios::sync_with_stdio(false);
	int wnum = 0;
	for (int i = 0; i < 105;i++) {
		for (int j = 0; j < 105;j++) {
			dis[i][j] = INF;
		}
	}
	scanf("%d %d",&h,&w);
	for (int i = 1; i <= h;i++) {
		getchar();
		for (int j = 1; j <= w;j++) {
			scanf("%c",&s[i][j]);
			if (s[i][j]=='.') {
				wnum++;
			}
		}
	}
	node x;
	x.x = 1;
	x.y = 1;
	if (s[1][1]=='#') {
		x.n = 1;
		x.ar = 1;
	}
	else {
		x.n = 0;
		x.ar = 0;
	}
	dis[1][1] = x.ar;
	q.push(x);
	int ans = INF;
	while (!q.empty()) {
		node a = q.top();
		q.pop();
		if (a.ar>dis[a.x][a.y]) {
			continue;
		}
		if (a.x==h&&a.y==w) {
			ans = min(ans, a.ar);
		}
		if (a.x+1<=h) {
			node b;
			b.x = a.x + 1;
			b.y = a.y;
			b.n = a.n + f(s[a.x + 1][a.y]);
			if (f(s[a.x][a.y]) == 1 || (f(s[a.x][a.y]) == 0 && f(s[b.x][b.y]) == 0)) {
				b.ar = a.ar;
			}
			else {
				b.ar = a.ar + 1;
			}
			if (b.ar<dis[a.x + 1][a.y]) {
				dis[b.x][b.y] = b.ar;
				q.push(b);
			}
		}
		if (a.y+1<=w) {
			node b;
			b.x = a.x;
			b.y = a.y + 1;
			b.n = a.n + f(s[a.x][a.y + 1]);
			if (f(s[a.x][a.y]) == 1 || (f(s[a.x][a.y]) == 0 && f(s[b.x][b.y]) == 0)) {
				b.ar = a.ar;
			}
			else {
				b.ar = a.ar + 1;
			}
			if (b.ar < dis[b.x][b.y]) {
				dis[b.x][b.y] = b.ar;
				q.push(b);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
std=[]
tgt=[]
for _ in range(n):
    std.append(list(map(int,input().split())))
for _ in range(m):
    tgt.append(list(map(int,input().split())))
for i in range(n):
    lt=100000000000000000
    li=0
    for j in range(m):
        if abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])<lt:
            lt=abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])
            li=j
    print(li+1)


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

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

    vector<vector<char>> a(n, vector<char>(n));
    vector<vector<char>> b(m, vector<char>(m));

    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
    for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) cin >> b[i][j];
    
    int p = n - m;
    
    bool can = false;
    // start point
    for (int i = 0; i < p + 1; i++) {
        for (int j = 0; j < p + 1; j++) {

            bool equal = true;
            for (int y = i; y < m + i; y++) {
                for (int x = j; x < m + j; x++) {
                    if (a[x][y] != b[y - i][x - j]) {
                        equal = false;
                    }
                }
            }
            
            if (equal) {
                cout << "Yes" << endl;
                return 0;            
            }

        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    fp((s[0] == '9')||(s[1] == '9'));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int  main ()
{
    long long n,d,num,sum;
    cin>>n>>d;
    sum=n/(2*d+1);
    num=n%(2*d+1);
    if(num>0)
        cout<<sum+1<<endl;
    else
        cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

//xより以下の要素へのindex
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素へのindex
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int comb(int n,int k){
    int ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> a(m+1);
    FOR(i,1,m+1){
        cin>>a[i];
    }
    int cl=0;
    int cr=0;
    FOR(i,1,x){
        if(find(a.begin(),a.end(),i)!=a.end()){
            cl++;
        }
    }
    FOR(i,x+1,n){
        if(find(a.begin(),a.end(),i)!=a.end()){
            cr++;
        }
    }
    cout<<min(cr,cl)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if (2*a-1>=2*b-1&&2*a-1>=a+b) {cout<<2*a-1<<endl;return 0;}
	if (2*b-1>=2*a-1&&2*b-1>=a+b) {cout<<2*b-1<<endl;return 0;}
	if (a+b>=2*a-1&&a+b>=2*b-1) {cout<<a+b<<endl;return 0;}
	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, q, a, b, c, d, x, y, u, v, depth[100009], idx[100009], ori[100009];
vector<pair<int, pair<int, int> > > vec[100009];
vector<pair<int, int> > dat;
vector<int> sp;
bool mk[100009];
pair<int, int> sta[350][100009];
pair<int, pair<int, int> > par[100009];
int par2[20][100009];

void dfs(int cur, int from, int de, int cc, int dd)
{
	par[cur].fi = from;
	par[cur].se.fi = cc;
	par[cur].se.se = dd;
	if (cur) ori[cur] = ori[from] + dd;
	depth[cur] = de;
	dat.pb(make_pair(depth[cur], cur));
	for (int i = 0; i < (int)vec[cur].size(); i++) {
		if (vec[cur][i].fi != from) {
			dfs(vec[cur][i].fi, cur, de + 1, vec[cur][i].se.fi, vec[cur][i].se.se);
		}
	}
}

int fun(int cc, int dd, int cur)
{
	int cnt = 0, sum = 0;
	int t_cur = cur;
	while (1) {
		if (cur == 0) break;
		if (mk[cur]) {
			cnt += sta[idx[cur]][cc].se;
			sum += sta[idx[cur]][cc].fi;
			break;
		}
		else {
			if (par[cur].se.fi == cc) {
				cnt++;
				sum += par[cur].se.se;
			}
		}
		cur = par2[0][cur];
	}
	int retval = ori[t_cur] - sum + cnt * dd;
	return retval;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b >> c >> d;
		a--; b--;
		vec[a].pb(make_pair(b, make_pair(c, d)));
		vec[b].pb(make_pair(a, make_pair(c, d)));
	}
	dfs(0, -1, 0, 0, 0);
	sort(dat.begin(), dat.end());
	reverse(dat.begin(), dat.end());
	for (int i = 0; i < (int)dat.size(); i++) {
		bool ok = false;
		int tmp = dat[i].se;
		for (int j = 0; j < (int)sqrt(n); j++) {
			if (mk[tmp]) {
				ok = true;
				break;
			}
			else {
				tmp = par[tmp].fi;
			}
			if (tmp == -1) break;
		}
		if (!ok && tmp != -1) {
          	if (!mk[tmp])
          		sp.pb(tmp);
			mk[tmp] = true;
		}
	}
	for (int i = 0; i < (int)sp.size(); i++) {
		int t = sp[i];
		idx[sp[i]] = i;
		while (1) {
			if (t == 0) break;
			sta[i][par[t].se.fi].fi += par[t].se.se;
			sta[i][par[t].se.fi].se++;
			t = par[t].fi;
		}
	}
	memset(par2, 0xff, sizeof(par2));
	for (int i = 0; i < n; i++) par2[0][i] = par[i].fi;
	for (int i = 1; i < 17; i++) {
		for (int j = 0; j < n; j++) {
			par2[i][j] = par2[i - 1][par2[i - 1][j]];
		}
	}
	while (q--) {
		cin >> x >> y >> u >> v;
		u--; v--;
		int tu = u, tv = v, lca;
		if (depth[u] < depth[v]) swap(u, v);
		for (int i = 0; i < 17; i++) {
			if (((depth[u] - depth[v]) >> i) & 1) {
				u = par2[i][u];
			}
		}
		for (int i = 16; i >= 0; i--) {
			if (par2[i][u] != par2[i][v]) {
				u = par2[i][u];
				v = par2[i][v];
			}
		}
		if (u == v) lca = u;
		else lca = par2[0][u];
		int ans = fun(x, y, tu);
		ans += fun(x, y, tv);
		ans -= 2 * fun(x, y, lca);
		cout << ans << E;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 273140
N = int(input())
a = list(map(int, input().split()))

ans = 0
color = [False] * 8
free = 0
for n in a:
    if n < 400:
        color[0] = True
    elif n < 800:
        color[1] = True
    elif n < 1200:
        color[2] = True
    elif n < 1600:
        color[3] = True
    elif n < 2000:
        color[4] = True
    elif n < 2400:
        color[5] = True
    elif n < 2800:
        color[6] = True
    elif n < 3200:
        color[7] = True
    else:
        free += 1

colors = len([i for i in color if i])
mini = max(1, colors)
maxi = colors + free
print(mini, maxi)

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

#define ll long long

using namespace std;

int main()
{
	// just get the max(graph1, graph2, etc) i think
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n, vector<int>());
	for(int i = 0; i < m; i++)
	{
		int ai, bi;
		cin >> ai >> bi;
		ai--;
		bi--;
		adj[ai].push_back(bi);
		adj[bi].push_back(ai);
	}
	int maxsize=0;
	set<int> visited;
	for(int i = 0; i < n; i++)
	{
		if(visited.count(i))
			continue;
		queue<int> Q;
		Q.push(i);
		int cnt=0;
		while(Q.size())
		{
			int v = Q.front();
			Q.pop();
			if(visited.count(v))
				continue;
			visited.insert(v);
			cnt++;
			vector<int> &ns = adj[v];
			for(int ne : ns)
				Q.push(ne);
		}
		maxsize = max(maxsize, cnt);
	}
	cout << maxsize << endl;
}


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

void xy(ll x, ll y, char e){cout<<x<<" "<<y<<e;}

int main(){
	ll S; cin>>S;
	ll xa = 1e9, xb = 1, yb = (S+xa-1)/xa, ya = xa*yb - S;
	xy(0,0,' '); xy(xa,ya,' '); xy(xb,yb,'\n');
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
unsigned long long int dp[11][1001];

void solve()
{
	dp[0][0] = 1;
	for(int i = 0; i < 101; ++i)
	{
		for(int j = 9; j >= 0; --j)
		{
			for(int k = 0; k + i < 1001; ++k)
			{
				 dp[j + 1][k + i] += dp[j][k];
			}
		}
	}

	int n, s;
	while(cin >> n >> s, n || s)
	{
		cout << dp[n][s] << endl;
	}
}

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

Measured memory_bytes: 1232
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// min
int main(void){
  int sx, sy, tx, ty;
  int h = 0, w = 0;
  
  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);

  if(sx >= 0 && tx >= 0){
    w = tx - sx;
  }else if(sx < 0 && tx >= 0){
    w = (-1) * sx + tx;
  }else if(sx < 0 && tx < 0){
    w = (-1) * sx - (-1) * tx;
  }

  if(sy >= 0 && ty >= 0){
    h = ty - sy;
  }else if(sy < 0 && ty >= 0){
    h = (-1) * sy + ty;
  }else if(sy < 0 && ty < 0){
    h = (-1) * sy - (-1) * ty;
  }

  //  printf("h = %d, w = %d\n", h, w);
  // 内側
  // (tx - sx) * R
  for(int i = 0; i < w; i++){
    printf("R");
  }
  // (ty - sy) * U
  for(int i = 0; i < h; i++){
    printf("U");
  }
  // (tx - sx) * L
  for(int i = 0; i < w; i++){
    printf("L");
  }
  // (ty - sy) * D  
  for(int i = 0; i < h; i++){
    printf("D");
  }

    
  // 外側
  // D, ((tx - sx) + 1) * R
  printf("D");
  for(int i = 0; i < w + 1; i++){
    printf("R");
  }
  // ((ty - sy) + 1) *  U, L
  for(int i = 0; i < h + 1; i++){
    printf("U");
  }
  printf("L");
  // U, ((tx - sx) + 1) * L
  printf("U");
  for(int i = 0; i < w + 1; i++){
    printf("L");
  }
  // ((ty - sy) + 1) * D, R
  for(int i = 0; i < h + 1; i++){
    printf("D");
  }
  printf("R\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, k, h[100100], d[100100];

int solve(){
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> h[i];
    
    for(int i = 1; i < n; ++i){
        d[i] = inf + inf;
        for(int j = i - 1; j >= max(0, i - k); --j)
            d[i] = min(d[i], abs(h[i] - h[j]) + d[j]);
        // cout << d[i] << " ";
    }
    return d[n - 1];
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

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

	int N, cnt = 0;
	cin >> N;
	vector<int> a(N+1);
	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
	}

	for (int i = 1; i <=N; i++)
	{
		if (a[i] == 0 || a[a[i]] == 0)continue;
		if (a[i] == a[a[a[i]]]) {
			a[a[i]] = 0;
			a[i] = 0;
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 640
h,w=map(int,input().split())
import math
if h%3==0 or w%3==0:
    print(0)
    exit()
w_i=w//2
ans=[]
for i in range(1,h):
    sa=i*w
    sb=(h-i)*w_i
    sc=(h-i)*(w-w_i)
    ans.append(max(sa,sb,sc)-min(sa,sb,sc))
v=min(ans)
ans_3=[]
for l in range(1,h):
    h_half=(h-l)//2
    sa=w*l
    sb=w*h_half
    sc=w*((h-l)-h_half)
    ans_3.append(max(sa,sb,sc)-min(sa,sb,sc))
v_3=min(ans_3)
ans_i=[]
h_i=h//2
for j in range(1,w):
    sa=j*h
    sb=(w-j)*(h_i)
    sc=(w-j)*(h-h_i)
    ans_i.append(max(sa,sb,sc)-min(sa,sb,sc))
v_i=min(ans_i)
ans_2=[]
for k in range(1,w):
    w_half=(w-k)//2
    sa=h*k
    sb=h*w_half
    sc=h*((w-k)-w_half)
    ans_2.append(max(sa,sb,sc)-min(sa,sb,sc))
v_2=min(ans_2)
print(min(v,v_i,v_2,v_3))
#86 5


Measured memory_bytes: 18920
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
	#define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
	#define debug(x...)
	#define light_debug(x) 
#endif


using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int MOD = 998244353;


ll dp[3001][3001];

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	dp[A][B] = 1;

	rep2(a, A, C)
		rep2(b, B, D)
			if(a != A || b != B) dp[a][b] = (b * dp[a - 1][b] % MOD + a * dp[a][b - 1] % MOD - (a - 1) * (b - 1) * dp[a - 1][b - 1] % MOD + MOD) % MOD;
	cout << dp[C][D] << '\n';

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}


Measured memory_bytes: 73828
N = int(input())
data = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N):
    t = 0
    while i < N-1:
        if t < data[i][1]:
            t = data[i][1]
        if (t-data[i][1]) % data[i][2] != 0:
            t += data[i][2] - (t-data[i][1]) % data[i][2]
        t += data[i][0]
        i += 1
    print(t)

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

int main(void){
  int x, n;
  cin >> x >> n;
  vector<bool> ng(102,false);
  rep(i,n){
    int p;
    cin >> p;
    ng[p] = true;
  }
  P ans(99999,-1);
  rep(i,102){
    if(ng[i]) continue;
    int dif = abs(x-i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		char S[] = sc.next().toCharArray();

		ArrayList<Integer>Nums = new ArrayList<>();
		int now = 1;
		int cnt = 0;
		for(int i=0; i<N; i++) {
			if(S[i] == (char)('0' + now)) {
				cnt++;
			}else {
				Nums.add(cnt);
				now = 1 - now;
				cnt = 1;
			}
		}
		if(cnt>0) Nums.add(cnt);

		if(Nums.size()%2==0) Nums.add(0);

		ArrayList<Integer>sums = new ArrayList<Integer>();
		sums.add(0);
		for(int i=0; i<Nums.size(); i++) {
			sums.add(i+1, sums.get(i) + Nums.get(i));
		}

		int add = 2 * K + 1;
		int ans = 0;
		for(int i=0; i<Nums.size(); i+=2) {
			int left = i;
			int right = Math.min(i + add, Nums.size());
			ans = Math.max(ans, sums.get(right) - sums.get(left));
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 30192
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]

counter = {i: 0 for i in range(-1, 10)}
for i in range(H):
    tmp = list(map(int, input().split()))
    for j in range(W):
        counter[tmp[j]] += 1
MAX = 10**4
INF = float("inf")
def f(start):
    if start == 1:
        return 0
    dp = [[INF]*MAX for _ in range(10)]
    dp[start][0] = 0
    for i in range(1, MAX):
        for new in range(10):
            dp[new][i] = min(dp[num][i-1] + c[num][new] for num in range(10))
    return min(dp[1])

ans = 0
for i in range(10):
    if counter[i] == 0:
        continue
    else:
        ans += counter[i] * f(i)
print(ans)

Measured memory_bytes: 82728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

int dp[2003][2003] , cnt[4003][2][2003] , N , arr[4003] , col[4003] , pos[2][2003];

int main(){
	cin >> N; memset(dp , 0x3f , sizeof(dp)); dp[0][0] = 0;
	for(int i = 1 ; i <= 2 * N ; ++i){
		char c; int id; cin >> c >> id; bool flg = c == 'B';
		pos[flg][id] = i; col[i] = flg; arr[i] = id;
		for(int j = 1 ; j < i ; ++j) ++cnt[i][col[j]][arr[j]];
		for(int j = 0 ; j < 2 ; ++j)
			for(int k = 1 ; k <= 2000 ; ++k)
				cnt[i][j][k] += cnt[i][j][k - 1];
	}
	for(int i = 0 ; i <= N ; ++i)
		for(int j = 0 ; j <= N ; ++j){
			int id = pos[0][i + 1];
			dp[i + 1][j] = min(dp[i + 1][j] , dp[i][j] + id - 1 - cnt[id][0][i] - cnt[id][1][j]);
			id = pos[1][j + 1];
			dp[i][j + 1] = min(dp[i][j + 1] , dp[i][j] + id - 1 - cnt[id][0][i] - cnt[id][1][j]);
		}
	cout << dp[N][N]; return 0;
}

Measured memory_bytes: 78592
def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)

for i in range(N):
    if A[i] == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
const ll MAX = 50;

ll N;
ll X[100005];
ll D[100005][MAX];

ll solve(ll a, ll b) {
    if (a > b)
        swap(a, b);
    ll ret = 0;
    for (ll x = MAX - 1; x >= 0; --x) {
        ll nxt = D[a][x];
        if (nxt < 0 || nxt > b)
            continue;
        ret |= (1LL << x);
        a = nxt;
    }
    if (a < b)
        ret++;
    return ret;
}

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

    cin >> N;
    REP(i, N) {
        cin >> X[i];
    }
    ll L;
    cin >> L;

    memset(D, -1, sizeof(D));
    ll n = 0;
    REP(i, N - 1) {
        while (n < N && X[n + 1] - X[i] <= L)
            n++;
        D[i][0] = n;
    }

    FOR(x, MAX, 1) {
        REP(i, N - 1) {
            if (D[i][x - 1] < 0)
                continue;
            D[i][x] = D[D[i][x - 1]][x - 1];
        }
    }

    ll Q;
    cin >> Q;

    REP(_, Q) {
        ll a, b;
        cin >> a >> b;
        cout << solve(a - 1, b - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 43488
#include <iostream>
using namespace std;
long long s,n,i,b[100001],a,l,r,q;
int main()
{
	cin >> n;
	for ( i = 0 ; i < n ; i++ )
	{
		cin >> a;
		b[a]++;
		s+=a;
	}
	cin >> q;
	for ( i = 0 ; i < q ; i++ )
	{
		cin >> l >> r;
		b[r]+=b[l];
		s+=b[l]*(r-l);
		b[l] = 0;
		cout << s << endl;
	}
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main(){
   int n, k;
   cin >> n >> k;
   int h[n], s[n];
   for(int i = 0; i < n; i++) {cin >> h[i]; s[i] = MOD;}
   s[0] = 0;
   for(int i = 0; i < n; i++){
       for(int j = 1; j <= k && i + j < n; j++){
           s[i + j] = min(s[i + j], s[i] + abs(h[i + j] - h[i]));
       }
   }
   cout << s[n - 1] << endl;
}


Measured memory_bytes: 1024
sn,sk,sq = input().split(" ")
n = int(sn)
k = int(sk)
q = int(sq)

l = [k for i in range(n)]

m =[0 for i in range(n)]

for i in range(q):
  sa = input()
  s = int(sa)
  m[s-1] += 1

for i in range(n):
  l[i] = l[i] - (q - m[i])
  
  if l[i] > 0:
    print("Yes")
  
  else:
     print("No")

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
char a[1005][1005];int n,m,ans,f[1005][1005];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
    f[1][1]=1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if((i!=1||j!=1)&&a[i][j]!='#') f[i][j]=(f[i-1][j]+f[i][j-1])%1000000007;
    printf("%d",f[n][m]);
    return 0;
}

Measured memory_bytes: 5120
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
R,C,K = ma()
V = [[0 for i in range(R+1)] for j in range(C+1)]
for i in range(K):
    r,c,v = ma()
    V[c][r] = v
dp_prev = [[0]*4 for i in range(C+1)]
dp_nex = [[0]*4 for i in range(C+1)] #dp[h][k] h列目でmax kこまで選んだ時の最大値
for r in range(1,R+1):
    for c in range(1,C+1):
        v = V[c][r]
        for k in range(4):
            if k==0:
                dp_nex[c][0] = max(dp_prev[c][3],dp_nex[c-1][0])
            elif k >0:
                dp_nex[c][k] = max(dp_nex[c-1][k],dp_nex[c-1][k-1]+v,dp_prev[c][3]+v)
    dp_prev,dp_nex = dp_nex,dp_prev
    #print(dp_prev)


print(dp_prev[C][3])


Measured memory_bytes: 156544
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,b,x=0;
	scanf("%d%d",&n,&b);
	x=n%(b*2+1);
	if(x==0) printf("%d\n",n/(b*2+1));
	else printf("%d\n",n/(b*2+1)+1);
	return 0;
}


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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

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

double ki(double a){
    int su = 0;
    for(int i = 1; i <= a; i++) su += i;
    return su / a;
}

int main(){
int n, x;
cin >> n >> x;
int sum = 0;
int ans = n + 1;
REP(i, n){
    int a;
    cin >> a;
    sum += a;
    if(sum > x) {
        ans = i + 1;
        break;
    }
}
print(ans);
}


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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int a[N];
int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
  	return 0;
}


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

}


Measured memory_bytes: 640
import numpy as np

n,k=map(int,input().split())
sum=0
k=k

for i in range(k,n+2):
  #print(i,i*n-i*(i-1)+1)
  sum=sum+i*n-i*(i-1)+1
  
#print(int(sum))
print(int(int(sum)%(1e9+7)))

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define what_is(x) cout << #x << " is: " << x << endl;
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define ll long long int

#define vi vector<int>
#define pii pair<int,int>
#define vl vector<ll>
#define pll pair<ll, ll>

template<typename T>
T extgcd(T a, T b, T &x, T &y) { if (b == 0) {x = 1;y = 0;return b;}T x1, y1;T g = extgcd(b, a % b,x1, y1);x = y1; y = x1 - (a/b)*y1;return g;}
template<typename T>
T fast_power(T a, T b){T res = (T)1;while( b ){if( b & 1 ) res = res * a;b >>= 1;a *= a; } return res;}
template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}
template<typename T>
T LCM(T a, T b){ T gd = __gcd(a, b); T ml = a * b; return ml/ gd;}

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

const int MAXN = 3003;
int n, t;
pii p[MAXN];
int dp[MAXN][MAXN];
 
int solve(int time, int dish) {
    if (time >= t or dish >= n) {
        return 0;
    }
 
    int& res = dp[time][dish];
    if (res != -1)
        return res;
 
    return res = max(solve(time, dish + 1), p[dish].second + solve(time + p[dish].first, dish + 1));
}
 
int main() {
    FAST
 
    cin >> n >> t;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
    }
 
    sort(p, p + n);
 
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0) << '\n';
    
    return 0;
}



Measured memory_bytes: 35712
n = int(input())
a = list( map(int, input().split()))

p =10**9+7

cnt= [0]*n
cnt[0]=1
ans = 3

if a[0]!=0:
    print(0)
    exit()

for i in range(1,n):
    if a[i]==0:
        ans *= (3-cnt[a[i]])
    else:
        ans *= (cnt[a[i]-1] - cnt[a[i]])
        if cnt[a[i]-1]==0:
            print(0)
            exit()

    ans%=p
    cnt[a[i]] += 1
    if cnt[a[i]]>3:
        print(0)
        exit()

print(ans%p)


Measured memory_bytes: 14396
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn prime_factor(mut n: i64) -> HashMap<i64, i64> {
    let mut res: HashMap<i64, i64> = HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            let v = match res.get(&i) {
                Some(v) => *v + 1,
                None => 1,
            };
            res.insert(i, v);
            n /= i;
        }
        i += 1;
    }
    if n != 1 {
        res.insert(n, 1);
    }
    res
}

fn main() {
    input!{
        s: i64,
    }

    let mut s_ = (s as f64).sqrt();

    
    let x_1 = 0;
    let y_1 = 0;
    let x_2 = 1000000000;
    let y_2 = 1;
    let x_3 = (x_2 - s % x_2) % x_2;
    let y_3 = (s + x_3) / x_2;

    println!("{} {} {} {} {} {}", x_1, y_1, x_2, y_2, x_3, y_3);
    
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void) {
  char s[101],p[101], ss[202];
  int i, j, k = 0;
  int s_num = 0, p_num = 0;
  int count = 0;
  int result = 0;

  scanf("%s", s);
  scanf("%s", p);

  while(1) {                     //p_length
    p_num++;
    if (p[p_num] == '\0')
      break;
  }
  
  for (i = 0; i < 2;i++) {       //ss = s s
    s_num = 0;
    while(1) {
      if (s[s_num] == '\0')
	break;
      ss[j] = s[s_num];
      j++;
      s_num++;
    }
    }

  for (i = 0; i < j / 2; i++) {
    count = 0;
    k = 0;
  while(p[k] != '\0') {
    if (p[k] == ss[k + i])
      count++;
    k++;
  }
  if (count == p_num) {
    result = 1;
    break;
  }   
  }

  if (result == 1)
    printf("Yes\n");
  else
    printf("No\n");

  
  return 0;
}


Measured memory_bytes: 2108
def func():
    input_line = list(str(input('')))
    flag = 0
    for i in range(len(input_line)):
        for j in range(i+1,len(input_line)):
            if input_line[i] == input_line[j]:
                flag += 1
    if flag == 2:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    func()
                

Measured memory_bytes: 3060
import java.util.*;

class Main{
    //149b
    static final int DIV = 100000007;
    static final int MAX = 2000000000;
    static long[] num = new long[20];
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        a -= c;
        if(a >= 0){
            System.out.println(a + " " + b);
            return;
        }else{
            b += a;
            if(b < 0)b = 0;
            System.out.println("0 " + b);
        }
    }
    
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#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 pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
    string s;
    int ans = 0;
    cin >> s;
    
    REP(i,s.length()-1){
        if(s[i] != s[i+1]) ans++;
    }
    
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
@n = gets.to_i
@a = STDIN.read.lines.map{ |l| l.split.map(&:to_i) }
@dp = [[0]*@n, [0]*@n]
def solve(x, y)
  return @dp[y][x] if @dp[y][x] > 0
  return @a[y][x] if x == @n-1 && y == 1

  res = 0
  if y == 0 && x < @n-1
    res = [solve(x+1, y), solve(x, y+1)].max
  elsif y == 1 && x < @n-1
    res = solve(x+1, y)
  else
    res = solve(x, y+1)
  end

  @dp[y][x] = res + @a[y][x]

  @dp[y][x]
end

puts solve(0, 0)


Measured memory_bytes: 1788
a, b, x = map(int, input().split())

start = 0
end = b
if a > x:
    if a % x == 0:
        start = a
    else:
        start = x * (a // x + 1)
else:
    start = x

if start > end:
    result = 0
else:
    result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)


Measured memory_bytes: 3060
s = gets.chomp
t = gets.chomp
n = s.length

sh = Hash.new{|hash, key| hash[key] = []}
th = Hash.new{|hash, key| hash[key] = []}

for i in 0..n-1 do
  sh[s[i]] << i
  th[t[i]] << i
end


if sh.values == th.values
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 7268
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;

ll n,x,m,again,idx=1,vis[100001],a[100001],ans=0;

int main(){
  cin>>n>>x>>m;
  if(n<=1e5){
    ll a2=x,idx2=1;
    ans+=a2;
    while(idx2<n){
      idx2++;
      a2=(a2*a2)%m;
      ans+=a2;
    }
    cout<<ans<<endl;
    return 0;
  }
  a[1]=x;
  vis[a[1]]=idx;
  ans+=x;
  n--;
  while(1){
    idx++;
    a[idx]=(a[idx-1]*a[idx-1])%m;
    if(vis[a[idx]]>0){again=idx;break;}
    n--;
    vis[a[idx]]=idx;
    ans+=a[idx];
  }
  ll period=again-vis[a[idx]];
  ll periodsum=0;
  for(int i=idx-period;i<idx;i++){
    periodsum+=a[i];
  }
  ans+=(n/period)*periodsum;
  n=n-(n/period)*period;
  for(int i=idx-period;i<idx-period+n;i++){
    ans+=a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 2e5+10;
const int mod = 1e9+7;
LL fac[maxn],inv[maxn];
LL qpow(LL a,int n){LL ans = 1; for (;n;n>>=1, a = a * a % mod) if (n & 1) ans = ans * a % mod; return ans;}
void init(){
    fac[0] = 1;
    for (int i=1;i<maxn;i++) fac[i] = fac[i-1] * i % mod;
    inv[maxn-1] = qpow(fac[maxn-1], mod-2);
    for (int i=maxn-2;i>=0;i--) inv[i] = inv[i+1] * (i+1) % mod;
}
void up(LL &x,LL y){
    x += y;
    if (x >= mod) x -= mod;
}
LL C(int n, int m){
    return fac[n] * inv[m] % mod * inv[n-m] % mod;
}
int main(){
    init();
    int n,m,k;
    cin>>n>>m>>k;
    LL sumn = 0, summ = 0;
    for (int i=2;i<=n;i++) up(sumn , 1LL * (i-1) * (n-i+1) % mod);
    for (int j=2;j<=m;j++) up(summ , 1LL * (j-1) * (m-j+1) % mod);

//    cout<<sumn<<" "<<summ<<endl;
    sumn = sumn * m % mod * m % mod;
    summ = summ * n % mod * n % mod;
//    cout<<sumn<<"\t"<<summ<<endl;

    LL p = C(n*m-2, k-2);
//    cout<<"p = "<<p<<endl;
    LL ans = (sumn + summ) % mod * p % mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328