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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, d; cin >> n >> d;
    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        ll x, y; cin >> x >> y;

        if (x * x + y * y <= d * d) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int H, W;
    std::cin >> H >> W;

    char s[H+2][W+2];
    for (int i = 0; i < H+2; i++) {
        for (int j = 0; j < W+2; j++) {
            s[i][j] = '0';
        }
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            std::cin >> s[i][j];
        }
    }

    bool flag = true;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (s[i][j] == '#') {
                if (s[i-1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.' && s[i+1][j] == '.') {
                    flag = false;
                }

            }
        }
    }

    if (flag) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)

const int mxn = 1e5+5;
ll dp[mxn];
ll arr[mxn];
ll n;

ll solve(int i)
{
	if(i>=n) return 0;
	if(dp[i]!=-1) return dp[i];

	ll ret = 4e18;
	if(i==n-1) 
	{
		ll x = solve(i+1)+abs(arr[i]-arr[i+1]);
		ret = min(ret, x);
	}
	else
	{
		ll x = solve(i+1)+abs(arr[i]-arr[i+1]);
		ll y = solve(i+2)+abs(arr[i]-arr[i+2]);
		ret = min(ret, min(x, y));
	}
	return dp[i] = ret;
}
int main()
{
	//input;
	//output;

	cin >> n;

	for(int i = 1; i <= n; i++) cin >> arr[i];
	memset(dp, -1, sizeof dp);
	ll ans = solve(1);
	cout << ans << '\n';
 	return 0;
 	
}

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a <= 8  && b <= 8  ? "Yay!" : ":(") << endl;

    return 0;
}


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

long long gcd(long long a, long long b){
    if(b>a) swap(a,b);
    if(a%b ==0) return b;
    gcd(b, a%b);
}

bool check(long long a, long long b, long long c, long long d){
    // cout << "#" << a << "," << b << "," << c << "," << d << endl;
    if(a < b || d < b) return false;
    if(c >= b) return true;
    if(d%b == 0) return a%b <= c ? true : false;
    if(b - gcd(b,d) <= c){
        return true;
    }else{
        return false;
    }
}

int main()
{
    int t;
    cin >> t;
    while(t--){
        long long a, b, c, d;
        cin >> a >> b >> c >> d;
        if(check(a,b,c,d)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define P pair<int, int>
typedef long long int ll;
using namespace std;
#define N 1000005
int num[N];
int xdif[N];
int ydif[N];
 
int main(){
    ll n, z, w, ans = 0;
    cin>>n>>z>>w;
    for(int i=0;i<n;++i)
        cin>>num[i];

    if(n==1){
        cout << abs(num[0]-w) << '\n';
        return 0;
    }

    if(abs(num[n-2] - num[n-1]) > abs(w - num[n-1])) cout << abs(num[n-2]-num[n-1]) << '\n'; 
    else cout << abs(w-num[n-1]) << '\n';
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n;
    while (cin >> n, n)
    {
        int cnt = 0;
        for (int i = 0; i * i <= n; i++)
        {
            for (int j = i; i * i + j * j <= n; j++)
            {
                for (int k = j; i * i + j * j + k * k <= n; k++)
                {
                    for (int h = k; i * i + j * j + k * k + h * h <= n; h++)
                    {
                        if (i * i + j * j + k * k + h * h == n)
                            cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair <int, int> PII;
typedef pair <PII, PII> PPP;
typedef pair <int, PPP> NODE;
typedef priority_queue <NODE, vector<NODE>, greater<NODE> > QUEUE;
typedef vector <string> VS;

bool V[21][21][21][21][11];

void solve( int w, int h ) {
    VS M(h);
    for ( int i = 0; i < h; ++ i ) {
        cin >> M[i];
    }
    int sr, sc, gr, gc;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            if ( M[i][j] == 'A' ) {
                sr = i;
                sc = j;
            }
            if ( M[i][j] == 'B' ) {
                gr = i;
                gc = j;
            }
        }
    }
    string s;
    cin >> s;
    int n = s.size();
    QUEUE Q;
    NODE start( 0, PPP( PII( sr, sc ), PII( gr, gc ) ) );
    Q.push( start );
    for ( int i = 0; i < 21; ++ i ) {
        for ( int j = 0; j < 21; ++ j ) {
            for ( int k = 0; k < 21; ++ k ) {
                for ( int l = 0; l < 21; ++ l ) {
                    for ( int m = 0; m < 11; ++ m ) {
                        V[i][j][k][l][m] = false;
                    }
                }
            }
        }
    }

    while ( ! Q.empty() ) {
        NODE node = Q.top();
        Q.pop();

        int cost = node.first;
        int r1 = node.second.first.first;
        int c1 = node.second.first.second;
        int r2 = node.second.second.first;
        int c2 = node.second.second.second;
        if ( r1 == r2 && c1 == c2 ) {
            cout << cost << " " << r1 << " " << c1 << endl;
            return;
        }
        
        int ncost = cost + 1;
        int nr2 = r2;
        int nc2 = c2;
        if ( s[cost%n] == '8' ) {
            nr2 --;
        } else if ( s[cost%n] == '2' ) {
            nr2 ++;
        } else if ( s[cost%n] == '6' ) {
            nc2 ++;
        } else if ( s[cost%n] == '4' ) {
            nc2 --;
        }
        if ( nr2 < 0 || nr2 >= h ) nr2 = r2, nc2 = c2;
        if ( nc2 < 0 || nc2 >= w ) nr2 = r2, nc2 = c2;

        const int dr[5] = { 0, 0, 1, -1, 0 };
        const int dc[5] = { 1, -1, 0, 0, 0 };
        for ( int k = 0; k < 5; ++ k ) {
            int nr1 = r1 + dr[k];
            int nc1 = c1 + dc[k];
            if ( nr1 < 0 || nr1 >= h ) nr1 = r1, nc1 = c1;
            if ( nc1 < 0 || nc1 >= w ) nr1 = r1, nc1 = c1;
            if ( M[nr1][nc1] == '#' ) continue;
            if ( V[nr1][nc1][nr2][nc2][ncost%n] ) continue;
            V[nr1][nc1][nr2][nc2][ncost%n] = true;
            NODE next_node( ncost, PPP( PII( nr1, nc1 ), PII( nr2, nc2 ) ) );
            Q.push( next_node );
        }
    }

    cout << "impossible" << endl;
}

int main() {
    int h, w;
    while ( cin >> h >> w && h && w ) {
        solve( w, h );
    }
    return 0;
}

Measured memory_bytes: 3036
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
a_sum=0
for v in c.values():
  a_sum+=v*(v-1)//2
for i in range(n):
  s=a_sum
  t=c[a[i]]
  s-=t*(t-1)//2
  t-=1
  s+=t*(t-1)//2
  print(s)

Measured memory_bytes: 25644
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[200];
    cin >> s;
    int n = strlen(s);
    int n1 = (n-1)/2,n2 = (n+3)/2;
    int found = 1,found1 = 1,found2 = 1;
    for(int i = 0;i < n;i++)
    {
        if(s[i] != s[n-i-1])
        {
            found = 0;break;
        }
    }
    if(found == 0)cout << "No" << endl;
    else
    {
        for(int i = 0;i < n1;i++)
        {
            if(s[i] != s[n1-i-1])
            {
                found1 = 0;break;
            }
        }
        if(found1 == 0)cout << "No" << endl;
        else
        {
            for(int i = n2;i < n;i++)
            {
                if(s[i] != s[n-i-1])
                {
                    found2 = 0;break;
                }
            }
            if(found2 == 0)cout << "No" <<endl;
            else cout << "Yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
class fenwick_tree():
    def __init__(self, n:int, mod:int = 0):
        self.__mod = mod
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        if(self.__mod == 0):
            self.__add_mod0(p,x)
        else:
            self.__add_mod(p,x)

    def __add_mod0(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def __add_mod(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            self.__data[p-1] %= self.__mod
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        if(self.__mod == 0):
            return self.__sum_mod0(r) - self.__sum_mod0(l)
        else:
            return self.__sum_mod(r) - self.__sum_mod(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s

    def __sum_mod(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            s %= self.__mod
            r -= r & -r
        return s

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))

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

using namespace std;

#define bug(x) do{cerr<<#x<<": "<<x;}while(0) 
#define bugv(x) do{for(auto&e:x)cerr<<e<<" ";cerr<<"\n";}while(0) 
#define rep(i, a,b) for(int i=(a);i<=(b);++i)
#define _rep(i, a,b) for(int i=(a);i>=(b);--i)
#define fn1(e) [&](int p1){return (e);}
#define fn2(e) [&](int p1, int p2){return (e);}
#define iter(it) begin(it),end(it)
#define INF (0x3f3f3f3f)

#define MOD ((int)(1e9+7))
#define LIM (100*1000+10)

using ll=long long;


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

    int N; cin >> N;
    if (N==1) cout << "Hello World";
    else {
        int A, B;cin >> A>> B; cout << A + B;
    } cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int  A[200000];//入っている値。
int  B[200000];//Dみたいなもん。
struct Edge {
	int to;
	int id;
	Edge(int to, int id) :to(to), id(id) {}
};
vector<Edge>g[100005];

void dfs(int v, int p = -1) {
	for (Edge e : g[v]) {
		if (p == e.to) {
			continue;
		}
		//訪問済みなら
		if (-1 != B[e.to]) {
			A[e.to] = e.id - A[v];
			B[e.to] = B[v] + 1;
			continue;
		}
		A[e.to] = e.id - A[v];
		B[e.to] = B[v] + 1;
		dfs(e.to, v);
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>X(M);
	vector<int>Y(M);
	vector<int>Z(M);
	for (int n = 0; n < M; ++n) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		X[n] = a;
		Y[n] = b;
		Z[n] = c;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	for (int i = 1; i < N; ++i) {
		A[i] = -1;
		B[i] = -1;
	}
	A[0] = 0;
	B[0] = 0;
	dfs(0);

	bool f = false;
	int t = -1;
	for (int i = 0; i < M; ++i) {
		if ((A[X[i]] + A[Y[i]]) != Z[i]) {
			if ((B[X[i]] % 2) == (B[Y[i]] % 2)) {
				if ((Z[i] % 2) != ((A[X[i]] + A[Y[i]]) % 2)) {
					cout << 0 << endl;//★★
					return 0;
				}
				else {
					f = true;
					if (0 == B[X[i]] % 2) {
						t = (Z[i] - A[X[i]] - A[Y[i]]) / 2;
					}
					else {
						t = (A[X[i]] + A[Y[i]] - Z[i]) / 2;
					}
					break;
				}
			}
			else {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	if (f) {
		if (-1 == t) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 0; i < N; ++i) {
			if (0 == (B[i] % 2)) {
				A[i] += t;
			}
			else {
				A[i] -= t;
			}
			if (A[i] <= 0) {
				cout << 0 << endl;
				return 0;
			}
		}
		for (int i = 0; i < M; ++i) {
			if ((A[X[i]] + A[Y[i]]) != Z[i]) {
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
		return 0;
	}


	int min0 = 1e9;
	int min1 = 1e9;
	for (int i = 0; i < N; ++i) {
		if (0 == (B[i] % 2)) {
			min0 = min(min0, A[i]);
		}
		else {
			min1 = min(min1, A[i]);
		}
	}
	int ans = 0;
	min0 = 1 - min0;
	min1 = min1 - 1;
	if (min0 <= min1) {
		ans = min1 - min0 + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 18576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;string s;cin>>n>>s;
  int ans=0;
  for(int i=1;i<n-1;i++){
    vector<int> a(26),b(26);
    for(int j=0;j<i;j++)a[s[j]-'a']++;
    for(int j=i;j<n;j++)b[s[j]-'a']++;
    int cnt=0;
    rep(j,26)if(a[j]>0&&b[j])cnt++;
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
k=int(input())
_list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(_list[k-1])

Measured memory_bytes: 3060
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include"time.h"
#include<climits>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 100000
//データ作成
class Edge {
public:
	int t;
	LL w;
	Edge(){}
	Edge(int t,LL w):t(t),w(w){}
};
vector<Edge> G[N_MAX];
int N;
LL d[N_MAX];

void bfs(int s) {
	REP(i,N)d[i]= LLONG_MAX;
	queue<int> Q;
	Q.push(s);
	d[s]=0;
	int u;
	while (!Q.empty()) {
		u=Q.front();Q.pop();
		REP(i, G[u].size()) {
			Edge e = G[u][i];
			if (d[e.t] == LLONG_MAX) {
				d[e.t]=d[u]+e.w;
				Q.push(e.t);
			}
		}
	}
}

//問題文のとおり
int a,b;
LL c;
int Q,K;
int x,y;

int main() {
	cin>>N;
	REP(i, N-1) {
		cin>>a>>b>>c;
		a--;b--;
		G[a].push_back(Edge(b, c));
		G[b].push_back(Edge(a, c));
	}
	cin>>Q>>K;
	K--;
	bfs(K);

	REP(i,Q){
		cin >> x >> y;
		x--;y--;
		cout<<d[x]+d[y]<<endl;
	}
	//cin>>N;
	
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> number(N);
  for(int i=0;i<N;i++){
      cin >> number.at(i);
  }
  int j=0;
  bool flag = true;
  while(flag){
    for(int i=0;i<N;i++){
        if(number.at(i)%2 != 0){
            flag = false;
            break;
        }
        else number.at(i) /= 2;
      }
    j++;
  }
  cout << j-1 << endl;
}

Measured memory_bytes: 256
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n,k= map(int, input().split())
    cnt = (n-1) * (n-2) // 2
    if cnt < k:
        print(-1)
        return
    m = (n-1) + cnt-k
    print(m)
    for i in range(n-1):
        print(1, i+2)
    m -= n-1
    for i in range(2, n+1):
        if m == 0:
            return
        for j in range(i+1, n+1):
            if m == 0:
                return
            m -= 1
            print(i, j)


main()

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = INF + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 5e5 + 5, LOG = 20;

int P[N], T[N], X[N], Y[N];

bool CMP(int i, int j) { return T[i] < T[j]; }
int DIS(int i, int j) { return abs(X[i] - X[j]) + abs(Y[i] - Y[j]); }

int main() {
 
	sync;

	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> T[i] >> X[i] >> Y[i];
	for (int i = 1; i <= n; i++) P[i] = i;
	sort(P, P + n + 1, CMP);
	for (int i = 1; i <= n; i++) if ((T[P[i]] - T[P[i - 1]]) %  DIS(P[i], P[i - 1]) != 0) die("No");
	cout << "Yes" << endl;
	

	return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<math.h>
#define M 1000001
int MIN(int a,int b){
  if(a<b)return a;
  return b;
}
int MAX(int a,int b){
  if(a<b)return b;
  return a;
}
int m[1002][1002]={0};
char p[M]={1,1};
int X[]={0,1,0,-1};
int Y[]={-1,0,1,0};
int main(){
  int i,j,n,s,ny,nx,d=1,x=0,y=1,l,k,max;
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  for(i=0;i<1002;i++)m[0][i]=m[1001][i]=m[i][0]=m[i][1001]=1000002;
  for(i=1000000;i;i--){
    nx=x+X[d];
    ny=y+Y[d];
    if(m[ny][nx]){
      d=(d+1)%4;
      nx=x+X[d];
      ny=y+Y[d];
    }
    m[y=ny][x=nx]=i;
    }//*/
  //printf("%d\n",m[501][498+2]);
  while(scanf("%d %d",&n,&s),n||s){
    int dp[1002][1002]={0};//printf("a\n");
    for(i=l=0;i<1000000;i++){
      if(m[i/1000+1][i%1000+1]==s){
	y=i/1000+1;
	x=i%1000+1;
	break;
      }
    }//printf("%d %d b\n",y,x);
    dp[y][x]=max=1-p[s];//printf("d\n");
    if(max)l=s;
    d=sqrt(n)/2+1;//printf("%d\n",d);
    for(i=0;y+i<MIN(1000,501+d);i++){
      for(j=MAX(1,x-i);j<=MIN(1001,x+i);j++){
	for(k=0;k<3;k++){//printf("%d ",m[y+i+1][j+k-1]);
	  if(m[y+i+1][j+k-1]>n)continue;//printf("%d ",m[y+i+1][j+k-1]);
	  dp[y+i+1][j+k-1]=MAX(dp[y+i+1][j+k-1],dp[y+i][j]+1-p[m[y+i+1][j+k-1]]);
	  if(max==dp[y+i+1][j+k-1]&&1-p[m[y+i+1][j+k-1]]){
	    l=MAX(l,m[y+i+1][j+k-1]);
	  }
	  if(max<dp[y+i+1][j+k-1]){
	    max=dp[y+i+1][j+k-1];
	    l  = m[y+i+1][j+k-1];
	  }//printf("d\n");
	}
      }//printf("\n");
    }
    if(max==0)l=0;
    printf("%d %d\n",max,l);
  }
  return 0;
}  

Measured memory_bytes: 9428
import java.util.Scanner;

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

        int output = 0;
        for(int i=a; i<=b; i++) {
            int tmp = i;
            int[] num = new int[5];
            int loopCnt = 0;
            while(loopCnt < 5) {
                num[loopCnt] = tmp % 10;
                if(tmp / 10 > 0) {
                    tmp /= 10;
                } else {
                    break;
                }
                loopCnt++;
            }
            if(num[0] == num[4] && num[1] == num[3]) {
                output++;
            }
        }
        System.out.println(output);
    }
}


Measured memory_bytes: 25172
#include<cstdio>
#include<vector>
using namespace std;
const int MAXN=100005;

vector<int> adj[MAXN];
int deg[MAXN];

int dfs(int u,int fa=-1)
{
	int res=0,temp;
	bool flag=false;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(v==fa)
			continue;
		temp=dfs(v,u);
		if(temp==0&&flag==true)
			temp++;
		if(temp==0&&flag==false)
			flag=true;
		res+=temp;
	}
	return res;
}

int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0,u,v;i<N-1;i++)
	{
		scanf("%d%d",&u,&v);
		deg[u]++;
		deg[v]++;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int root=-1;
	for(int i=0;i<N;i++)
		if(deg[i]>=3)
		{
			root=i;
			break;
		}
	if(root==-1)
		puts("1");
	else
		printf("%d\n",dfs(root));
	return 0;
}


Measured memory_bytes: 9472
s = gets
n = gets.to_i
n.times do
  c = gets.split(" ")
  if c[0] == "print"
    puts s[c[1].to_i..c[2].to_i]
  elsif c[0] == "replace"
    s[c[1].to_i..c[2].to_i] = c[3]
  else
    s[c[1].to_i..c[2].to_i] = s[c[1].to_i..c[2].to_i].reverse
  end
end



Measured memory_bytes: 8920
#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>;

const ll INF = 1e18;
const int MX = 2005;

int main() {
  int n,m;
  cin >> n >> m;
  int ans;
  ans = (n * (n-1) + m * (m-1))/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    string we[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for(int i=0;i<7;i++)
    {
        if(s==we[i])
        {
            cout<<7-i<<endl;
            break;
        }
    }
    return 0;


}


Measured memory_bytes: 3404
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

bool used[26];
string s;
vector<string> ans;

void dfs(int n) {
	if (n == s.size()) {
		ans.push_back(s);
		return;
	}

	if (used[(s[n] - 'a' - 1 + 26) % 26]) {
		dfs(n + 1);
	}
	if (!used[s[n] - 'a']) {
		used[s[n] - 'a'] = true;
		s[n]++;
		dfs(n + 1);
		s[n]--;
		used[s[n] - 'a'] = false;
	}
}

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

	while (cin >> s , s != "#") {
		ans.clear();
		used[25] = true;
		dfs(0);

		cout << ans.size() << endl;
		if (ans.size() <= 10) {
			for (int i = 0; i < ans.size(); i++) {
				cout << ans[i] << endl;
			}
		}
		else {
			for (int i = 0; i < 5; i++) {
				cout << ans[i] << endl;
			}
			for (int i = ans.size() - 5; i < ans.size(); i++) {
				cout << ans[i] << endl;
			}
		}
	}
}

Measured memory_bytes: 2352
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    H,W,K=mi()
    C = [[""]*H for _ in range(W)]
    for h in range(H):
        t = list(input())
        for w in range(W):
            C[w][h] = t[w]
    
    WL = []
    for i in range(2**W):
        w_l = set()
        for j in range(W): 
            if ((i >> j) & 1):
                w_l.add(j)
        WL.append(w_l)

    HL = []
    for i in range(2**H):
        h_l = set()
        for j in range(H): 
            if ((i >> j) & 1):
                h_l.add(j)
        HL.append(h_l)


    def count(graph):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if graph[w][h] == "#":
                    cnt += 1

        return cnt

    def refill_and_count(wl,hl):
        newC = [[""]*H for _ in range(W)]
        for h in range(H):
            for w in range(W):
                if w in wl or h in hl:
                    newC[w][h] = "r"
                else:
                    newC[w][h] = C[w][h]

        # print(newC)
        return count(newC)

    ans = 0
    for wl in WL:
        for hl in HL:
            # print(wl,hl)
            black = refill_and_count(wl,hl)
            # print(black)
            if black == K:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 68832
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> pa;
int sq(int a,int b){
    return a*a+b*b;
}
bool com(pa p1,pa p2){
    int a=p1.first,b=p1.second,c=p2.first,d=p2.second;
    return sq(a,b)==sq(c,d)?a<c:sq(a,b)<sq(c,d);
}
int main(){
    int h,w;
    vector<pair<int,int> >v;
    for(int i=1;i<160;i++)
        for(int j=i+1;j<160;j++)
            v.push_back(make_pair(i, j));
    sort(v.begin(),v.end(),com);
    while(cin>>h>>w,h){
        pa p=make_pair(h,w);
        for(int m=0;m<v.size();m++){
            if(com(p,v[m])){
                cout<<v[m].first<<" "<<v[m].second<<endl;
                break;
            }
        }
    }
}

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

int main(){
    int a, b, c, X;
    cin >> a >> b >> c >> X;
    int count = 0 ;
    for(int i = 0; i < a+1 ; i++){
        for(int j = 0; j < b+1 ; j++){
            for(int k = 0; k < c+1; k++){

                int total = 500*i + 100*j + 50*k;

                if(total == X){

                    count++ ;

                }

            }

           
        }
    }

    cout << count << endl;

}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int N, K;
    cin >> N >> K;

    double win = 0;
    for (int r = 1; r <= N; r++) {
        double ch = 1;
        for (int t = r; t < K; t <<= 1)
            ch /= 2;
        win += ch;
    }

    printf("%.15f\n", win / N);

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

#define SIZE (10*10*10*10*10)
int64 H[SIZE+1];

int main()
{
  int cnt;
  int64 N;
  int64 i;
  int64 maxseq = 0;
  int64 seq = 0;
  int result = 0;

  get_N(&N);

  for (i=0; i<N; i++) {
    cnt = scanf("%lld", &H[i]);
    if (i == 0) continue;
    if (H[i] <= H[i-1]) {
      seq++;
    } else {
      if (seq > maxseq) {
        maxseq = seq;
      }
      seq = 0;
    }
  }
  if (seq > maxseq) {
    maxseq = seq;
  }
  printf("%lld", maxseq);

  return 0;
}



Measured memory_bytes: 896
from collections import defaultdict
A = input()
N = len(A)
d = defaultdict(int)
for a in A:
    d[a] += 1
cnt = 0
for k, v in d.items():
    cnt += v * (v - 1) // 2
ans = N * (N - 1) // 2 - cnt
print(ans + 1)


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

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> D(N, vector<int>(N));
  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    L--, R--;
    D[L][R]++;
  }

  vector<vector<int>> ans(N, vector<int>(N));
  for (int p = 0; p < N; p++) {
    for (int q = p; q < N; q++) {
      for (int k = p; k <= q; k++) {
        for (int l = k; l <= q; l++) {
          ans[p][q] += D[k][l];
        }
      }
    }
  }

  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    cout << ans[p][q] << endl;
  }
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=(n)-1;i>=0;--i)
#define SORT(a) sort(a,a+sizeof(a)/sizeof(a[0]))
using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  long long int sum = 0;
  REP(i,N){
    cin >> A[i];
    sum += A[i];
  }
  SORT(A);
  int ret;
  REPR(i,N){
    sum -= A[i];
    if(A[i] > sum * 2){
      ret = N - i;
      break;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
char s[N];
ll nm[N],nc[N],num[N];
int main(){
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='M'){
            nm[i]=nm[i-1]+1;
            nc[i]=nc[i-1];
            num[i]=num[i-1];
        }
        else if(s[i]=='C'){
            nm[i]=nm[i-1];
            nc[i]=nc[i-1]+1;
            num[i]=num[i-1]+nm[i];
        }
        else {
            nm[i]=nm[i-1];
            nc[i]=nc[i-1];
            num[i]=num[i-1];
        }
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int k;
        scanf("%d",&k);
        ll ans=0;
        for(int i=1;i<=n;i++){
            if(s[i]=='D'){
                int ed=min(n,i+k-1);
                ans+=num[ed]-num[i]-nm[i]*(nc[ed]-nc[i]);
            }
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 24832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()


int n; int a[4];
int l[8];
int flag[9]; // 0:not use, 1:for a, 2:for b, 3:for c
int min_cost;

int search(int m){
    if (m == 0){
        int foruse[4]={}; int count[4]={};
        rep(i, n){
            repn(j, 3){
                if(flag[i] == j){
                    foruse[j] += l[i];
                    count[j] ++;
                    break;
                }
            }
        }
        if (foruse[1] == 0 || foruse[2] == 0 || foruse[3] == 0) return 1e9;

        int ans = 0;
        repn(j, 3){
            ans += abs(foruse[j] - a[j]) + (count[j]-1)*10;
        }
        return ans;
    }

    rep(i, 4){
        flag[m-1] = i;
        int res = search(m-1);
        min_cost = min(min_cost, res);
    }
    return min_cost;
}

int main(){
    cin>>n>>a[1]>>a[2]>>a[3];
    rep(i, n) cin >> l[i];
    min_cost = 1e9;

    int res = search(n);
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char ss[1010];
char tt[1010];
char*s,*t;
int ans[1010];
int tn;

void f(char*s){
	//この位置からtを引く
	for(int i=0;i<tn;i++)s[i]-=t[i]-'0';
	for(int i=tn-1;i>=0;i--)if(s[i]<'0')s[i]+=10,s[i-1]--;
}

int main(){
	scanf("%s %s",ss,tt);
	int sm=(ss[0]=='-'),tm=(tt[0]=='-');
	s=ss+sm,t=tt+tm;
	tn=strlen(t);
	while(1){
		int sn=strlen(s);
		if(sn<tn)break;
		if(sn==tn){
			if(strcmp(s,t)<0)break;
			f(s);
			ans[sn-tn]++;
		}else{
			int flag=strcmp(s,t)<0;
			f(s+flag);
			ans[sn-tn-flag]++;
		}
		while(*s=='0')s++;
	}
	int digit=0;
	for(int i=0;i<1010;i++)if(ans[i])digit=i;
	if((sm^tm)&&(digit>0||ans[0]!=0))printf("-");
	for(int i=digit;i>=0;i--)printf("%d",ans[i]);
	puts("");
	
}


Measured memory_bytes: 2112
def sums(n)
  return n*(n+1)/2
end

s = gets.chomp.split("")
cmps = Array.new(0)
mark = Array.new(0)

cnt = 1
pre = s[0]
for i in 1..(s.length-1)
  if s[i] == pre
    cnt += 1
  else
    cmps.push(cnt)
    mark.push(pre)
    cnt = 1
  end
  pre = s[i]
end
cmps.push(cnt)
mark.push(pre)

ans = 0
if mark[0] == ">"
  ans += cmps[0]
end
for i in 0..(cmps.length-2)
  if mark[i] == "<"
    ans += [cmps[i],cmps[i+1]].max
  end
end
if mark[cmps.length-1] == "<"
  ans += cmps[cmps.length-1]
end
for i in 0..(cmps.length-1)
  ans += sums(cmps[i]-1)
end
puts ans

Measured memory_bytes: 49156
def readinput():
    n,m,x=list(map(int,input().split()))
    dat=[]
    for i in range(n):
        s=list(map(int,input().split()))
        c=s[0]
        a=s[1:]
        dat.append((c,a))
    return n,m,x,dat

def makeTableA(dat,n,m):
    tbl=[[0]*m]*n
    #print(n,len(tbl),m,len(tbl[0]))
    for i in range(n):
        tup=dat[i]
        a=tup[1]
        #print(a)
        #for j in range(m):
        #    tbl[i][j]=a[j]
        tbl[i]=list(a) 
        #print(tbl) 
    return tbl  


def main(n,m,x,dat):
    tblA=makeTableA(dat,n,m)
    #print(tblA)
    tblB=[[0]*(m+2)]*2**n  #
    #print(n,m,len(tblB), len(tblB[0]))  
    for i in range(2**n):
        tblB[i]=[0]*(m+2)
        b=1
        for j in range(n):
            if(i&b==b):
                for k in range(m):
                    #print(j,k)
                    tblB[i][k]+=tblA[j][k]
                    #print(tblB)
                tblB[i][m]+=dat[j][0]
                #print(tblB)
            b=b*2
        tblB[i][m+1]=min(tblB[i][0:m])
        #print(tblB)
    #print(tblB)
    # テーブルをスキャンする
    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


def readinput2():
    n,m,x = list(map(int,input().split()))
    tblA=[]
    c=[]
    for i in range(n):
        s=list(map(int,input().split()))
        c.append(s[0])
        tblA.append(s[1:])
    #print(c,tblA)
    return n,m,x,c,tblA

def main2(n,m,x,c,a):
    tblB = [[0 for j in range(m+2)] for i in range(2**n)]
    for i in range(2**n):
        nn=1
        for j in range(n):
            #print(i,nn)
            if (i&nn==nn):
                for k in range(m):
                    tblB[i][k]+=a[j][k]
                tblB[i][m]+=c[j]
            nn=nn*2
        tblB[i][m+1]=min(tblB[i][:m])
        #print(tblB)

    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


if __name__=='__main__':
    #n,m,x,dat=readinput()
    #ans=main(n,m,x,dat)
    n,m,x,c,tblA=readinput2()
    ans=main2(n,m,x,c,tblA)
    print(ans)


Measured memory_bytes: 11384
#include<stdio.h>
#include<math.h>

int main(void) {
    int h, w;

    scanf("%d %d", &h, &w);
    
    while(w != 0 || h != 0) {
        for(int i = 0; i < h; i++) {
            if(i % 2) {
                for(int j = 0; j < w; j++) {
                    if(j % 2) printf("#");
                    else printf(".");
                }
            }
            else {
                for(int j = 0; j < w; j++) {
                    if(j % 2) printf(".");
                    else printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &h, &w);
    }
    return 0;
}



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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void dump_(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(string, s);
  int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';

  if (a + b + c + d == 7) OUTN(a, '+', b, '+', c, '+', d, '=', 7, "\n");
  else if (a - b + c + d == 7) OUTN(a, '-', b, '+', c, '+', d, '=', 7, "\n");
  else if (a + b - c + d == 7) OUTN(a, '+', b, '-', c, '+', d, '=', 7, "\n");
  else if (a + b + c - d == 7) OUTN(a, '+', b, '+', c, '-', d, '=', 7, "\n");
  else if (a - b - c + d == 7) OUTN(a, '-', b, '-', c, '+', d, '=', 7, "\n");
  else if (a + b - c - d == 7) OUTN(a, '+', b, '-', c, '-', d, '=', 7, "\n");
  else if (a - b + c - d == 7) OUTN(a, '-', b, '+', c, '-', d, '=', 7, "\n");
  else if (a - b - c - d == 7) OUTN(a, '-', b, '-', c, '-', d, '=', 7, "\n");

  return 0;
}


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

int main(){
    int x,y;
    cin>>x>>y;
    if(x<y){
        swap(x,y);
    }
    while(1){
        if(x%y==0)break;
        x=x%y;
        if(x<y){
            swap(x,y);
        }
    }
    cout<<y<<endl;
    return 0;
}


Measured memory_bytes: 3100
buf = input()
buf_len = len(buf)

str_array = []
for i in range(buf_len):
    str_array.append(buf[i])

for i in range(buf_len):
    if str_array[i].isupper():
        str_array[i] = str_array[i].lower()
    else:
        str_array[i] = str_array[i].upper()

for i in range(buf_len):
    print("%s" % str_array[i], end="")

print()



Measured memory_bytes: 5716
#!/usr/bin/env ruby

X = gets.chomp.to_i

case X
when 400...600 then puts 8
when 600...800 then puts 7
when 800...1000 then puts 6
when 1000...1200 then puts 5
when 1200...1400 then puts 4
when 1400...1600 then puts 3
when 1600...1800 then puts 2
else puts 1
end


Measured memory_bytes: 14316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int n,k;
	cin>>n>>k;
	int p[n];
	in(p,n);
	sort(p,p+n);
	int sum=0;
	rep(i,k)sum+=p[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<math.h>

int main(void)
{
 int a,b,c,aux;
 scanf("%d %d %d", &a, &b, &c);
 if (a<b)
 {
   a = a + b;
   b = a - b;
   a = a - b;
 }
 if (a<c)
 {
   a = a + c;
   c = a - c;
   a = a - c;
 }
 if (b<c)
 {
   b = b + c;
   c = b - c;
   b = b - c;
 }
  printf("%d",10*a+b+c);
 return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def main():
    # input
    N,W = map(int,input().split())
    w,v = [0]*N,[0]*N
    for i in range(N):
        w[i],v[i] = map(int,input().split())
    
    # init dp
    v_max = sum(v)
    dp = [[float("inf") for i in range(v_max+1)] for _ in range(N)]
    dp[0][v[0]] = w[0]
    for i in range(N):
        dp[i][0] = 0

    for i in range(1,N):
        for j in range(v_max+1):
            if j<v[i]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i])
    ans = 0
    for i in range(v_max+1):
        if dp[-1][i]<=W:
            ans = i
        else:
            pass
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 420344
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    N, K = LI()
    TD = []
    for _ in range(N):
        TD.append(LI())

    TD.sort(key=lambda x: x[1], reverse=True)

    from collections import Counter
    import heapq

    counter = Counter()
    S = TD[:K]
    TD = TD[K:]
    queue = []
    for t, d in S:
        counter[t] += 1
        heapq.heappush(queue, (d, t))

    sum_ = sum([i[1] for i in S])
    maximum = sum_ + len(counter)**2
    while len(queue) > 0:
        d, t = heapq.heappop(queue)
        if counter[t] == 1:
            continue
        counter[t] -= 1
        sum_ -= d
        while len(TD) > 0:
            new_t, new_d = TD.pop(0)
            if counter[new_t] == 0:
                counter[new_t] += 1
                sum_ += new_d
                maximum = max(maximum, sum_ + len(counter)**2)
                break

    print(maximum)


main()

Measured memory_bytes: 32372
/*
Though leaves are many, the root is one;
Through all the lying days of my youth
I swayed my leaves and flowers in the sun,
Now many I wither into the truth.
-- William Butler Yeats
µ±»ªÃÀµÄÒ¶Æ¬Âä¾¡£¬ÉúÃüµÄÂöÂç²ÅÀúÀú¿É¼û
*/ 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
ll n;
ll d[100005];
map <ll,ll> m;
pair<ll,ll> p[100005];
ll sub[100005];
ll sz[100005];
vector <pair<ll,ll> >res;
vector <int>vec[100005];
ll dp[100005];

int dfs(int x,int p=-1)
{
	sz[x]=1;
	for(int i=0;i<vec[x].size();i++)
	{
		if(vec[x][i]==p) continue;
		sz[x]+=dfs(vec[x][i],x);
	}
	return sz[x];
}

int go(int x,int p=-1)
{
	dp[x]=sz[x]-1;
	for(int i=0;i<vec[x].size();i++)
	{
		if(vec[x][i]==p) continue;
		dp[x]+=go(vec[x][i],x);
	}
	return dp[x];
}

int main()
{
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>d[i];
		m[d[i]]=i;
		p[i].first=d[i];
		p[i].second=i;
		sz[i]=1;
	}
	sort(p,p+n);
	reverse(p,p+n);
	memset(sub,-1,sizeof(sub));
	for(ll i=0;i<n-1;i++)
	{
		ll de=p[i].first;
		ll x=p[i].second;
		sub[x]=n-sz[x]*2;
//		cout<<x+1<<'-'<<de<<'-'<<sub[x]<<'-'<<sz[i]<<endl;
		if(sub[x]==0) over("-1");
		if(m.find(de-sub[x])==m.end()) over("-1");
		ll par=m[de-sub[x]];
		sz[par]+=sz[x];
		dp[par]+=dp[x];
		res.push_back(mp(x,par));
	}
	for(int i=0;i<n-1;i++)
	{
		vec[res[i].first].push_back(res[i].second);
		vec[res[i].second].push_back(res[i].first);
	}
	dfs(p[n-1].second);
	go(p[n-1].second);
//	cout<<dp[p[n-1].second]<<endl;
	if(dp[p[n-1].second]!=p[n-1].first) over("-1");
	for(ll i=0;i<n-1;i++)
	{
		cout<<res[i].first+1<<' '<<res[i].second+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 22516
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
#define FOR(i,x,y) for(int i=(int)x; i<(int)y; ++i)
#define REP(i,y) FOR(i, 0, y)
constexpr int INF = 1<<30;
int N;
vector<vint> X(18, vint(2));
vint V_(18), V(18), Vb(18);
int search(int F){
  int tmp = 0;
  REP(i,N){
    V[i] = X[i][F%2];
    V_[i] = V[i];
    tmp += F%2;
    Vb[i] = F%2;
    F>>=1;
  }
  sort(V.begin(), V.begin()+N);
  int ans = 0;
  REP(i,N){
    FOR(j,i,N){
      if(!(V[i]==V_[j] && (j-i+Vb[j])%2==0)) continue;
      ans += j-i;
      for(int k=j-1; k>=i; --k){
        V_[k+1] = V_[k];
        Vb[k+1] = Vb[k]+1;
      }
      goto END;
    }
    return INF;
END:
    continue;
  }
  return tmp&1?INF:ans;
}
int main(){
  cin >> N;
  REP(i,N) cin >> X[i][0];
  REP(i,N) cin >> X[i][1];
  int ans=INF;
  REP(i,1<<N) ans = min(ans, search(i));
  cout << (ans==INF?-1:ans) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);

	return x * y / tmp;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	int n,m;
	cin >> n >> m;
	if(n==m){
		cout << "Yes"<<endl;
	}else{
		cout << "No"<<endl;
	}

	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N,Q;
vector<ll> a;

int main(){
  cin>>N>>Q;
  a.resize(Q+1);
  a[0]=N;
  rep(i,Q){
    cin>>a[i+1];
  }
  Q++;
  vector<ll> b;
  for(ll i=Q-1;i>=0;i--){
    if(b.size()>0&&b.back()<=a[i])continue;
    b.push_back(a[i]);
  }
  reverse(all(b));
  Q=b.size();
  vector<ll> t(Q+1,0),res(N+1,0);
  t[Q]=1;
  for(ll i=Q-1;i>=0;i--){
    ll k=b[i];
    while(1){
      ll j=upper_bound(b.begin(),b.begin()+i,k)-b.begin()-1;
      if(j<0||j>=i)break;
      t[j+1]+=t[i+1]*(k/b[j]);
      k%=b[j];
    }
    res[0]+=t[i+1];
    res[min(N,k)]-=t[i+1];
  }

  rep(i,N)res[i+1]+=res[i];
  rep(i,N)cout<<res[i]<<endl;

  return 0;
}


Measured memory_bytes: 4980
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n-1;i>=0;i--){
        printf("%d",a[i]);
        if(i>0){
            printf(" ");
        }
    }
    printf("\n");
}


Measured memory_bytes: 2104