akhauriyash/Code-Regression huggingface dataset:
N,K=map(int,input().split())
v=[]
for i in range(0,N):
    x,y=map(int,input().split())
    v.append([x,y])

v.sort()

ans=10**20
for i in range(0,N-1):
    for j in range(i+1,N):
        data=[]
        for k in range(i,j+1):
            x,y=v[k]
            data.append(y)
        data.sort()
        if K>len(data):
            continue
        else:
            for k in range(0,len(data)-K+1):
                w=v[j][0]-v[i][0]
                h=data[k+K-1]-data[k]
                test=w*h
                if ans>test:
                    ans=test

print(ans)

Measured memory_bytes: 40304
def find(i):
    x = i
    while x!=G[x][0]:
        x = G[x][0]
    return x
def union(i,j):
    ai = find(i)
    ni = G[ai][1]
    aj = find(j)
    nj = G[aj][1]
    if ai!=aj:
        if ni>=nj:
            G[aj][0] = ai
            if G[aj][1]==G[ai][1]:
                G[ai][1] += 1
            G[ai][2] += G[aj][2]
        else:
            G[ai][0] = aj
            G[aj][2] += G[ai][2]
N,M,K = map(int,input().split())
G = {i:[i,0,1] for i in range(1,N+1)}
A = {i:[] for i in range(1,N+1)}
B = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    union(a,b)
    A[a].append(b)
    A[b].append(a)
for _ in range(K):
    c,d = map(int,input().split())
    B[c].append(d)
    B[d].append(c)
C = []
for i in range(1,N+1):
    ai = find(i)
    n = G[ai][2]
    m = len(A[i])
    k = 0
    for j in B[i]:
        if ai==find(j):
            k += 1
    n = n-m-k
    C.append(n-1)
print(*C)

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 6784
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	cout << (min(K, N) * X + (max(K, N) - K) * Y) << endl;
	return 0;
}


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


using namespace std;

int main(int argc, char** argv) {
    int n;
    cin >> n;
    int highest{0};
    int count{0};

    for (int i = 1; i < n+1; ++i) {
        int h;
        cin >> h;
        if (h >= highest) {
            ++count;
            highest = h;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// n = 人数
	// k = ポイント
	// q = 正解者
	var n, k, q int
	fmt.Scan(&n, &k, &q)

	ap := make(map[int]int, 6)
	for i := 1; i <= q; i++ {
		var qq int
		fmt.Scan(&qq)

		ap[qq]++
	}

	for i := 1; i <= n; i++ {
		sum := k + ap[i] - q
		if 0 < sum {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 8320
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int[] a = new int[3];
		int count = 3;
		for(int i = 0; i < 3; i++){
			a[i] = scanner.nextInt();
		}
		Arrays.sort(a);
		if(a[0] == a[1] && a[1] == a[2]){
			System.out.println(1);
		}else if (a[0] == a[1]) {
			System.out.println(2);
		}else if(a[1] == a[2]){
			System.out.println(2);
		}else {
			System.out.println(3);
		}
	}
}


Measured memory_bytes: 21716
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<ld> m(a);
    for(int q=0; q<a; q++) cin>>m[q];
    vec<ld> dp(a+1);
    dp[0] = 1;
    for(int q=0; q<a; q++){
        vec<ld> nw(a+1);
        for(int w=0; w<=q+1; w++){
            nw[w] = dp[w] * (1-m[q]) + (w ? dp[w-1]*m[q] : 0);
        }
        dp = nw;
    }
    ld o = 0;
    for(int q=0; q<=a; q++) if(q > a-q) o += dp[q];
    cout.precision(12);
    cout<<fixed;
    cout<<o;
}

Measured memory_bytes: 512
#pragma warning (disable :4996)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 2e5 + 10;

const int MAX = 1010;
const int VMAX = 10010;

int n;       //本次最小成本排序所需应当所有元素均不相等 便于T记录
int s;       //s记录序列A中最小元素，以便于进行“借整体最小元素”操作
int A[MAX],B[MAX];  //A[MAX]记录元素读入的初始位置顺序，B[MAX]记录升序排序后元素
int T[VMAX + 1]; //T[VMAX+1]记录出现元素A[i]的目标位置（B中所处位置） T[B[i]]=i;


int solve() {
	bool V[MAX];  //V[MAX]记录序列中元素是否已发生交换到正确位置
	int ans = 0;
	for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; }
	sort(B, B + n);
	for (int i = 0; i < n; i++) { T[B[i]] = i; }  //记录初始元素应到位置
	for (int i = 0; i < n; i++) {
		if (V[i]) continue; //已正确摆放
		int cur = i;  //记录闭圆（需要交换所构成的圆）起点
		int S = 0; //闭圆中元素值的和
		int minn = VMAX; //记录闭圆中最小元素以便进行通过最小元素来移其他元素 （一共n个元素，移n-1次）
		int an = 0;  //记录闭圆中元素个数
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur]; //当前位置的元素值
			minn = min(minn, v);
			S += v;
			cur = T[v];   //指向下一个元素
			if (V[cur]) break; //形成闭圆
		}
		ans += min(S + (an - 2) * minn, minn + S + (an + 1) * s);
		//公式 ： 不借整体最小元素   S + (an - 2) * minn
		//借： S+(an-2)*minn+2*(minn+s)-(an-1)*(minn-s);
	}
	return ans;
}

int main() {
	cin >> n;
	s = VMAX;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	int ans = solve();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3176
use std::io;
fn main() {
    let mut l1 = String::new();
    let mut l2 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    stdin.read_line(&mut l2).unwrap();
    let trimed = l1.trim_end();
    let trimed2 = l2.trim_end();
    let mut itr = trimed.split_ascii_whitespace();
    let mut itr2 = trimed2.split_ascii_whitespace();
    let n = itr.next().unwrap().parse::<i64>().unwrap();
    let m = itr.next().unwrap().parse::<i64>().unwrap();

    let mut count = 0;
    for x in 0..m {
        count = count + itr2.next().unwrap().parse::<i64>().unwrap();
    }

    if (count <= n) {
        println!("{}", n - count);
    } else {
        println!("{}", -1);
    }
}


Measured memory_bytes: 2184
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
	public static void main(String[] a) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int[] mt = new int[10];
		try {
			for (int i = 0; i < mt.length; i++) {
				mt[i] = Integer.parseInt(br.readLine());
			}
		} catch (Exception e) {
		}

		Arrays.sort(mt);

		System.out.println(mt[9]);
		System.out.println(mt[8]);
		System.out.println(mt[7]);
	}
}

Measured memory_bytes: 24176
#include <iostream>
using namespace std;
int main(){
    int n,m,l;
    int a[101][101];
    int b[101][101];
    cin>>n>>m>>l;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            int d;
            cin>>d;
            a[i][j]=d;
        }
    }
    
    for (int i=1;i<=m;i++){
        for (int j=1;j<=l;j++){
            int d;
            cin>>d;
            b[i][j]=d;
        }
    }
    
    for (int i=1;i<=n;i++){
        for (int j=1;j<=l;j++){
            long long sum=0;
            for (int k=1;k<=m;k++){
                sum+=a[i][k]*b[k][j];
            }
            if(j==1){
                cout<<sum;
            }else{
                cout<<" "<<sum;
            }
        }cout<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	cin >> N;
	vecI A(N);

	rep(i, 0, N) {
		cin >> A[i];
	}

	ll ans = 0;
	rep(i, 1, N) {
		if (A[i - 1] <= A[i])continue;

		ans += A[i - 1] - A[i];
		A[i] = A[i - 1];
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 4048
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;

int R_range(int d, int w, int h) {
  int a, b, r;
  priority_queue<int> Q;
  Q.push(d); Q.push(w); Q.push(h); Q.pop();
  a = Q.top(); Q.pop();
  b = Q.top();
  r = a * a + b * b ;
  return r / 4;
}

int main() {
  int n, d, w, h, r, R;
  while( cin >> d >> w >> h ) {
    if (d == 0)  return 0;
    R = R_range(d, w, h);
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> r;
      if ( R < (r * r) ) { cout << "OK" << endl; }
      else { cout << "NA" << endl; }
    }
  }
}


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

using namespace std;

const int MAXN = 500005;
const int LOG = 20;

int n, q;
string s;
int dp[26][MAXN], p[MAXN], par[LOG][MAXN];

void precompute () {
    for (int i = 1; i <= n; i++) {
        if (p[i - 1] == n) par[0][i] = 0; else par[0][i] = p[i - 1] + 2;
    }
    for (int i = 1; i < LOG; i++) {
        for (int j = 1; j <= n; j++) {
            par[i][j] = par[i - 1][par[i - 1][j]];
        }
    }
}

bool upit (int x, int y) {
    for (int i = LOG - 1; i >= 0; i--) {
        if (par[i][x] != 0 && par[i][x] <= y) x = par[i][x];
    }
    return x == y;
}

int main () {
    cin >> s;
    n = s.size();
    for (int j = 0; j < 26; j++) dp[j][n] = n; p[n] = n;

    for (int i = n-1; i >= 0; i--) {
        int c = s[i] - 'a', curr = i;
        for (; c < 26; c++) {
            curr = dp[c][min(curr + 1, n)];
        }
        p[i] = curr;

        for (int j = 0; j < 26; j++) {
            int res = n;
            if (j - 1 >= 0) res = min(res, dp[j - 1][min(dp[j - 1][i] + 1, n)]);
            res = min(res, dp[j][min(p[i] + 1, n)]);
            if (s[i] - 'a' == j) res = min(res, i);
            dp[j][i] = res;
        }
    }
    precompute();
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        if (upit(a, b + 1)) cout << "Yes\n"; else cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 93188
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# n^p(mod m) -- START --
def powMod(n,p,m):
  if p==0:
    return 1
  if p%2==0:
    t=powMod(n,p//2,m)
    return t*t%m
  return n*powMod(n,p-1,m)%m
# n^p(mod m) --- END ---

def main():
  n,k=LI()
  ans=[0]*(k+1)
  for i in range(1,k+1)[::-1]:
    x=powMod((k//i),n,mod)
    for j in range(2,k//i+1):
      x-=ans[i*j]
    x%=mod
    ans[i]=x

  ret=0
  # print(ans)
  for i,x in enumerate(ans):
    ret+=x*i
    ret%=mod
  return ret

# main()
print(main())


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

bool prime(int n){
	if(n == 1) return false;
	for(int i = 2 ; i*i <= n ; i++){
		if(n%i == 0) return false;
	}
	 return true;
}

bool near2017(int n){
	if(n%2 == 0) return false;
	else if(prime(n) && prime((n+1)/2)) return true;
	
	return false;
}

int main() {
	vector<int> a(100000,0),s(100001,0);
	s[0] = 0;
	int q; cin >> q;
	for(int i = 0 ; i < 100000 ; i++){
		if(near2017(i)){
			a[i] = 1;
			// cout << "find" << endl;
		}
	}
	for(int i = 0 ; i < 100000 ; i++){
		s[i+1] = s[i] + a[i];
	}
	for(int i= 0 ; i < q ; i++){
		int l,r;
		cin >> l >> r;
		// cout << l << r << endl;
		cout << s[r+1] - s[l] << endl;
	}
}

Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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

const ll INF=1e9+7;

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


Measured memory_bytes: 3588
h,w = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)
d = gets.chomp.split(" ").map(&:to_i)
s = Array.new(h){Array.new}
h.times do |i|
  s[i] = gets.chomp.split("")
end
visited = Array.new(h){Array.new(w,-1)}
visited[c[0]-1][c[1]-1] = 0
queue = [c[0]-1,c[1]-1]
queue2 = []
cnt = 0
map1x = [-1,1,0,0]
map1y = [0,0,1,-1]
map2x = [-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2,2]
map2y = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]
while !queue.empty? || !queue2.empty?
  while !queue.empty?
    a,b = queue[0],queue[1]
    queue.shift
    queue.shift
    queue2 << a
    queue2 << b
    4.times do |i|
      v0,v1 = a+map1x[i],b+map1y[i]
      if 0 <= v0 && v0 < h && 0 <= v1 && v1 < w
        if visited[v0][v1] == -1 && s[v0][v1] == "."
          visited[v0][v1] = cnt
          queue << v0
          queue << v1
        end
      end
    end
  end
  cnt += 1
  while !queue2.empty?
    a = queue2[0]
    b = queue2[1]
    queue2.shift
    queue2.shift
    20.times do |i|
      v0,v1 = a+map2x[i],b+map2y[i]
      if 0 <= v0 && v0 < h && 0 <= v1 && v1 < w
        if visited[v0][v1] == -1 && s[v0][v1] == "."
          visited[v0][v1] = cnt
          queue << v0
            queue << v1
        end
      end
    end
  end
end
puts visited[d[0]-1][d[1]-1]

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

int main() {
   int n;
   while (scanf("%d", &n) != EOF) {
      int cnt = 0;
      for (int i = 0; i < 10; i++)
         for (int j = 0; j < 10; j++)
            for (int k = 0; k < 10; k++)
               for (int l = 0; l < 10; l++)
                  if (i+j+k+l == n) cnt++;

      cout << cnt << endl;
   }

   return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    int n;
    cin >> n;
    string a, b;
    cin >> a; cin >> b;
    string ans;
    for(int i = 0; i < n; i++){
        ans += a[i];
        ans += b[i];
    }
    cout << ans << endl;
    return 0;
}

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

class DisjointSet{
  public:
    vector<int> rank, p;
    
    DisjointSet() {}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i=0; i < size; i++) makeSet(i);
    }
    
    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }
    
    void link(int x, int y){
        if ( rank[x] > rank[y] ){
            p[y] = x;
        }
        else{
            p[x] = y;
            if ( rank[x] == rank[y] ){
                rank[y]++;
            }
        }
    }
    
    int findSet(int x){
        if ( x != p[x] ){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, a, b, q;
    int t;
    
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    
    for ( int i = 0; i < q; i++ ){
        cin >> t >> a >> b;
        if ( t == 0 ) ds.unite(a, b);
        else if ( t == 1 ){
            if ( ds.same(a, b) ) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3180
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		double d = sc.nextInt();
      double t = sc.nextDouble();
      double s = sc.nextInt();

      double kakaruhun = Math.ceil(d/s);

		if(kakaruhun <= t){
			// 出力
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}
}

Measured memory_bytes: 37364
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#define pb push_back
#define INF 1000000000

using namespace std;
typedef pair<int,int> P;
int w,h;
bool inf(int y,int x){
	if(y>=0&&y<h&&x>=0&&x<w)
	return true;
	return false;
}
int main(){
	
	int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	while(cin>>w>>h,w||h){
		vector<string> s(h);
		vector<vector<int> > d(h,vector<int>(w,INF));
		queue<P> que;
		for(int i=0;i<h;i++){
			cin>>s[i];
			for(int j=0;j<h;j++){
				for(int k=0;k<w;k++){
					if(s[j][k]=='@'){
						d[j][k]=0;
						que.push(P(j,k));
					}
				}
			}
		}
		while(!que.empty()){
			P q=que.front();
			que.pop();
			int x=q.second,y=q.first;
			for(int i=0;i<4;i++){
				int ny=dy[i]+y,nx=dx[i]+x;
				if(inf(ny,nx)&&s[ny][nx]!='#'&&d[ny][nx]>d[y][x]+1){
					d[ny][nx]=d[y][x]+1;
					que.push(P(ny,nx));
				}
			}
			
			
		}
		int cnt=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(d[i][j]!=INF)
					cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
def div_by_two(n):
  if n % 2 == 1:
    return 0
  else:
    return div_by_two(n / 2) + 1
  
N = int(input())
count = 0
res = 1
for i in range(1, N+1):
  tmp = div_by_two(i)
  if tmp > count: 
    res = i
    count = tmp 

print(res)

Measured memory_bytes: 9256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}


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

    if(s == "SUN"){
        cout << 7 << endl;
    }else if(s == "MON"){
        cout << 6 << endl;
    }else if(s == "TUE"){
        cout << 5 << endl;
    }else if(s == "WED"){
        cout << 4 << endl;
    }else if(s == "THU"){
        cout << 3 << endl;
    }else if(s == "FRI"){
        cout << 2 << endl;
    }else if(s == "SAT"){
        cout << 1 << endl;
    }

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORR(x, arr) for (auto& x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N;
int A[114514], B[114514], C[114514];
ll bc[114514];
ll sum[114514];

void solve() {
    cin >> N;
    REP(i, N) { cin >> A[i]; }
    REP(i, N) { cin >> B[i]; }
    REP(i, N) { cin >> C[i]; }

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    REP(i, N) { bc[i] = N - (upper_bound(C, C + N, B[i]) - C); }
    sum[0] = 0;
    ll t = 0;
    REP(i, N) {
        t += bc[i];
        sum[i + 1] = t;
    }

    ll ans = 0;
    REP(i, N) {
        int idx = upper_bound(B, B + N, A[i]) - B;
        ll a = sum[N] - sum[idx];
        ans += a;
    }

    cout << ans << endl;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    int dp[n + 1][3];
    rep(j, 3) dp[0][j] = 0;
    rep(i, n)
    {
        dp[i + 1][0] = max({dp[i][0], dp[i][1] + a[i], dp[i][2] + a[i]});
        dp[i + 1][1] = max({dp[i][0] + b[i], dp[i][1], dp[i][2] + b[i]});
        dp[i + 1][2] = max({dp[i][0] + c[i], dp[i][1] + c[i], dp[i][2]});
    }

    OP(max({dp[n][0], dp[n][1], dp[n][2]}));
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
	ll a, b, c;
  	cin >> a >> b >> c;
  	cout << max(a+b , max(a-b, a*b));
	
}
int main()
{
		    ios_base::sync_with_stdio(false);
			cin.tie(NULL);
	int t = 1; 
	//cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn gcd(a: i32, b: i32) -> i32{
    if b == 0 {
        a
    }else {
        gcd (b, a % b)
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for _ in 0..n {
        let a: i32 = iter.next().unwrap().parse().unwrap();
        ans = gcd(a, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k, n; cin >> k >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int mx = 0;
    ll sm = 0;
    int tmp;
    rep(i, n-1) {
        tmp = a[i+1]-a[i];
        chmax(mx, tmp);
        sm += tmp;
    }
    tmp = k-a[n-1]+a[0];
    chmax(mx, tmp);
    sm += tmp;
    sm -= mx;
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 1792
l=list(map(int,input()))
le=len(l)
p1,p2=[],[]
a,b=1,0
for i in range(le):
    p1.append(a)
    p2.append(b)
    a,b=b,a
m1,m2=0,0
for i in range(le):
    m1+=abs(l[i]-p1[i])
    m2+=abs(l[i]-p2[i])
print(min(m1,m2))

Measured memory_bytes: 5516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(begin(a),end(a));
	ll b=a[n/2];
	ll ans=0;
	rep(i,n){
		ans+=abs(a[i]-b);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int t[5];
    for (int i = 0; i < 5; ++i)
        cin >> t[i];

    int min = 10;
    int x = 0;
    for (int i = 0; i < 5; ++i)
    {
        int mod = t[i] % 10;
        if (mod == 0)
            mod = 10;
        if (mod < min)
        {
            x = i;
            min = mod;
        }
    }

    int result = 0;
    for (int i = 0; i < 5; ++i)
        if (i != x)
            result += (t[i] + 9) / 10 * 10;
        else
            result += t[i];

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int R,G,B;
  cin>>R>>G>>B;
  int n;
  cin>>n;
  ll ans = 0;

  REP(i,n/R+1){
    REP(j,n/G+1){
      ll now = i*R + j*G;
      if(now<=n){
        if((n-now)%B==0){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
 

  return 0;
}

Measured memory_bytes: 256
import decimal
decimal.getcontext().prec = 100
def sum1(pre,l,r):
    l=max(l,0)
    if(l==0):
        return pre[r]
    return pre[r] - pre[l - 1]

y=(raw_input())
x=list(y)

r=0
l=0
ans=[]
flag=0
for i in x:
    if(i=="R"):
        if(flag==1):
            if((l+r)%2==0):
                ans.append([(l+r)/2,(l+r)/2])
            else:
                if(l%2==0):
                    ans.append([(l+r)/2+1,(l+r)/2])
                else:
                    ans.append([(l+r)/2,(l+r)/2+1])    
            r=0
            l=0
            flag=0

        r=r+1
    elif(i=='L'):
        l=l+1
        flag=1    
if((l+r)%2==0):
    ans.append([(l+r)/2,(l+r)/2])
else:
    if(l%2==0):
        ans.append([(l+r)/2+1,(l+r)/2])
    else:
        ans.append([(l+r)/2,(l+r)/2+1])    
    
p=y.split("RL")
s=""
# print p
# print ans
for i in range(len(p)):
    try:
        s=s+"0 "*len(p[i])+str(ans[i][0])+" "+str(ans[i][1])+" "
    except:    
        s=s+"0 "*len(p[i])
print s
# ans=[1]*len(x)
# for i in range(10):
#     temp=ans[:]

#     for j in range(len(x)):
#         if x[j]=="R":
#             if(ans[j]!=0):
#                 temp[j+1]+=ans[j]

#                 temp[j]=temp[j]-ans[j]
#         else:
#             if(ans[j]!=0):
#                 temp[j-1]+=ans[j]
#                 temp[j]=temp[j]-ans[j]
#     ans=temp[:]
#     print ans
# print "".join(map(str,ans))

Measured memory_bytes: 12852
N = int(input())
rest = []
for k in range(N):
    i, j = map(str, input().split())
    rest.append([i, int(j), k+1])


rest.sort(key=lambda x: x[1])
rest.reverse()
rest.sort(key=lambda y: y[0])

for i, j, k in rest:
    print(k)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>

#include <cassert>
#include <set>

using namespace std;
typedef long long ll;

ll sign(ll x){
    if(x > 0){
        return 1;
    }else if(x < 0){
        return -1;
    }else{
        return 0;
    }
}

void move_y(ll y1, ll y2, ll x, vector<array<ll, 4>>& moves){
    ll cy = y1;
    while(cy != y2){
        array<ll, 4> tmp = {cy, x, cy + sign(y2 - cy), x};
        moves.push_back(tmp);
        cy += sign(y2 - cy);
    }
}

void move_x(ll x1, ll x2, ll y, vector<array<ll, 4>>& moves){
    ll cx = x1;
    while(cx != x2){
        array<ll, 4> tmp = {y, cx, y, cx + sign(x2 - cx)};
        moves.push_back(tmp);
        cx += sign(x2 - cx);
    }
}

void calc_move(
    ll y1, ll x1, ll y2, ll x2,
    vector<array<ll, 4>>& moves
){
    bool y1e = (y1 % 2 == 0);
    bool y2e = (y2 % 2 == 0);
    bool x1le = (x2 >= x1);
    if((y1e && x1le) || (!y1e && !x1le)){
        // cout << "type1 " << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << endl;
        move_x(x1, x2, y1, moves);
        move_y(y1, y2, x2, moves);
    }else if((y1e && !y2e && !x1le) || (!y1e && y2e && x1le)){
        // cout << "type2 " << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << endl;
        move_y(y1, y2, x1, moves);
        move_x(x1, x2, y2, moves);
    }else{
        // cout << "type3 " << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << endl;
        move_y(y1, y1 + 1, x1, moves);
        move_x(x1, x2, y1 + 1, moves);
        move_y(y1 + 1, y2, x2, moves);
    }
}

int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a.at(i).at(j);
        }
    }

    vector<pair<ll, ll>> odds;
    for(int y = 0; y < h; ++y){
        if(y % 2 == 0){
            for(int x = 0; x < w; ++x){
                if(a.at(y).at(x) % 2 == 1){
                    odds.push_back(make_pair(y, x));
                }
            }
        }else{
            for(int x = w - 1; x >= 0; --x){
                if(a.at(y).at(x) % 2 == 1){
                    odds.push_back(make_pair(y, x));
                }
            }
        }
    }

    vector<array<ll, 4>> moves;
    for(int k = 0; k + 1 < odds.size(); k += 2){
        calc_move(
            odds.at(k).first, odds.at(k).second,
            odds.at(k + 1).first, odds.at(k + 1).second,
            moves);
    }

    // set<pair<ll, ll>> visits;
    cout << moves.size() << endl;
    for(array<ll, 4>& t : moves){
        cout << t.at(0) + 1 << ' ' << t.at(1) + 1 << ' ' <<
            t.at(2) + 1 << ' ' << t.at(3) + 1 << endl;

        // assert(abs(t.at(0) - t.at(2)) + abs(t.at(1) - t.at(3)) == 1);
        // assert(visits.count(make_pair(t.at(0), t.at(1))) == 0);
        // visits.insert(make_pair(t.at(0), t.at(1)));
    }
    return 0;
}


Measured memory_bytes: 13676
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

	int x;
	cin>>x;
	if (x<=599) cout<<"8\n"; else
	if (x<=799) cout<<"7\n"; else
	if (x<=999) cout<<"6\n";else
	if (x<=1199) cout<<"5\n";else
	if (x<=1399) cout<<"4\n";else
	if (x<=1599) cout<<"3\n";else
	if (x<=1799) cout<<"2\n";else
	if (x<=1999) cout<<"1\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int N,L,org=0,ans,d,temp;
    cin>>N>>L;

    for(int i=1;i<=N;i++){
        org+=L+i-1;
    }
    d=org;
    for(int i=1;i<=N;i++){
        temp=org-(L+i-1);
        if(abs(temp-org)<abs(ans-org)){
            ans=temp;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std ;
int main(int argc, char** argv) {
	int n , elements ;
	cin >> n ;
	int arr[n] ;
	for ( int i = 0 ; i < n ; i++ ) {
		cin >> arr[i] ;
	}
	sort ( arr , arr + n ) ;
	elements = unique( arr , arr + n ) - arr ;
	if ( elements % 2 == 0 ) {
		elements -- ;
	}
	cout << elements ;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
	long long s;
	cin>>s;

	const int v=1000000000;

	int x=(v-(s%v))%v;
	int y=(s+x)/v;

	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    rep(i,N)cin >> s[i] >> t[i];
    string X;cin >> X;
    int tmp = 0;
    rep(i,N){
        if(s[i] == X)tmp = i;
    }
    int ans = 0;
    for(int j = tmp + 1;j < N;j++){
        ans += t[j];
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main()
{
  int N;
  cin >> N;
  string W[N];
  for (int i = 0; i < N; i++)
    cin >> W[i];
  set<string> st;
  st.insert(W[0]);
  char last = W[0].back();
  string ans = "Yes";
  for (int i = 1; i < N; i++)
  {
    if (st.find(W[i]) != st.end())
      ans = "No";
    if (last != W[i].front())
      ans = "No";
    st.insert(W[i]);
    last = W[i].back();
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    string s;cin>>s;
    string good="ATCG";
    int ans=0;
    rep(i,(int)s.size()){
        //i文字目からスタート
        int cnt=0;
        for(int j=i;j<(int)s.size();j++){
            //j文字目までokか
            bool ok=false;
            rep(k,4){
                if(s[j]==good[k])ok=true;
            }
            if(!ok)break;
            else{
                cnt++;
                ans=max(ans,cnt);
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cards = [list(map(int, input().split())) for i in range(M)]
cards = sorted(cards, key=lambda x: x[1], reverse=True)

n = 0
for card in cards:
   A += [card[1]] * card[0]
   n += card[0]
   if n >= N:
       break

A.sort(reverse=True)
print(sum(A[:N]))


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

int main()
{
	int h, w;
	cin >> h >> w;
	auto m = vector<string>(h + 2);
	m[0] = m[h + 1] = string(w + 2, '0');
	for(auto i = 0; i < h; ++i){
		string s;
		cin >> s;
		s = '.' + s + '.';
		for(auto& c : s) if(c == '.') c = '0';
		m[i + 1] = s;
	}
	for(auto i = 1; i <= h; ++i){
		for(auto j = 1; j <= w; ++j){
			if(m[i][j] == '#'){
				static int d[][2] = {{0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}};
				for(auto k = 0; k < 8; ++k){
					int x = j + d[k][0];
					int y = i + d[k][1];
					if(m[y][x] != '#') m[y][x] += 1;
				}
			}
		}
	}
	for(auto i = 1; i <= h; ++i){
		for(auto j = 1; j <= w; ++j){
			cout << m[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e3 + 5;
const int maxw = 1e4 + 5;
struct TNode
{
    int w , s , v;
}a[maxn];
int n;
ll dp[maxw];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i].w >> a[i].s >> a[i].v;
    sort(a + 1 , a + n + 1 , [](const TNode & x , const TNode & y){
            return x.w + x.s < y.w + y.s;
         });
    ll res = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
//        cout << a[i].s << " " << a[i].w << endl;
        for(int j = a[i].s ; j >= 0 ; --j)
        {
            if(j + a[i].w <= (int)1e4)
                dp[j + a[i].w] = max(dp[j + a[i].w] , dp[j] + a[i].v);
            else res = max(res , dp[j] + a[i].v);
        }
    }
    for(int i = 1 ; i <= 1e4 ; ++i)res = max(res , dp[i]);
    cout << res;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

string ss;
bool translate(int n, string s, string in);

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if(translate(n, s, "WS"))
		cout << ss << endl;
	else if(translate(n, s, "WW"))
		cout << ss << endl;
	else if(translate(n, s, "SS"))
		cout << ss << endl;
	else if(translate(n, s, "SW"))
		cout << ss << endl;
	else
		cout << "-1" << endl;
	return 0;
}



bool translate(int n, string s, string in)
{
	ss = in;
	s = s + s[0];
	for(int i=1; i<n+1; i++) {
		if(ss[i] == 'S') {
			if(s[i] == 'o')
				ss = ss + ss[i-1];
			else {
				char ch = 'W' ^ 'S' ^ ss[i-1];
				ss = ss + ch;
			}
		}
		else {
			if(s[i] == 'o') {
				char ch = 'W' ^ 'S' ^ ss[i-1];
				ss = ss + ch;
			}
			else
				ss = ss + ss[i-1];
		}
	}

	if(ss[0] == ss[n] && ss[1] == ss[n+1])
		ss = ss.substr(0, n);
	else
		return false;
	return true;
}


Measured memory_bytes: 1152
#include <stdio.h>
#define N 100


int selection(int A[N], int n){

	int i,j,min,tmp,k;
	int count = 0;

	for(i = 0; i < n-1; i++){
		min = i;
		for(j = i+1; j < n; j++){
			if(A[j] < A[min]){
				min = j;
			}
		}

		if(A[i] > A[min]){
			tmp = A[i];
			A[i] = A[min];
			A[min] = tmp;
			count++;
		}
	}
	return count;
}


int main(){

	int A[N],n,i,count;

	scanf("%d",&n);

	for(i = 0; i < n; i++){
		scanf("%d",&A[i]);
	}

	count = selection(A,n);

	for ( i = 0; i < n; ++i){
		printf("%d",A[i]);
		if( i != n-1) printf(" ");
	}
	printf("\n%d\n",count);

	return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <vector>

using namespace std;

struct result {
    int exchange;
    vector<int> a;
};

struct result bubble_sort(vector<int> v) {
    int tmp, fin = 0;
    bool change = true;
    struct result res;
    
    res.exchange = 0;

    while(change) {
        change = false;
        
        for(int i = 0;i < v.size() - 1 - fin;i++) {
            if(v[i] > v[i + 1]) {
                res.exchange++;
                
                tmp = v[i];
                v[i] = v[i + 1];
                v[i + 1] = tmp;
                
                change = true;
            }
        }
        
        fin++;
    }
    
    res.a = v;
    
    return res;
}

void print_attr(vector<int> v) {
    for(int i = 0;i < v.size();i++) {
        cout << v[i];
        
        if(i < v.size() - 1) 
            cout << " ";
    }
    
    cout << endl;
}

int main() {
    int n;
    vector<int> v;
    struct result res;
    
    cin >> n;
    
    v.resize(n);
    
    for(int i = 0;i < n;i++) {
        cin >> v[i];
    }
    
    res = bubble_sort(v);
    
    print_attr(res.a);
    cout << res.exchange << endl;
    
    return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A, B;
    cin >> A >> B;

    A = (A + 11) % 13;
    B = (B + 11) % 13;

    if(A > B){
        cout << "Alice" << endl;
    }else if(A < B){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }   

    return 0;
}

Measured memory_bytes: 3512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 500005, M = 20005, CH = 26;

int n, m;
char s[N];
si q[CH];

void gao() {
    rep (i, CH) q[i].clear();
    rep (i, n) q[s[i] - 'a'].insert(i);

    int cmd, l, r, p, id;
    char ch;
    in(m);
    while (m--) {
        in(cmd);
        if (cmd == 1) {
            scanf("%d %c", &p, &ch), p--;
            if (s[p] == ch) continue;
            q[s[p] - 'a'].erase(p);
            q[ch - 'a'].insert(p);
            s[p] = ch;
        } else {
            in2(l, r), l--, r--;
            int ans = 0, x;
            rep (i, CH) {
                if (q[i].empty()) continue;
                if (*q[i].rbegin() < l) continue;
                p = *q[i].lower_bound(l);
                ans += (p >= l && p <= r);
            }
            printf("%d\n", ans);
        }
    }
}

int main() {
    // si a;
    // a.insert(1), a.insert(3);
    // cout << *a.lower_bound(9) << '\n';
    while (~in(n)) {
        scanf("%s", s);
        gao();
    }
    return 0;
}


Measured memory_bytes: 24192
$n=<>;
push@$_,$i++for<>=~/./g;
$\=0;
for$i(1..$n){
	$s=0;
	(grep$_<$i,@$_)&&(grep$_>=$i,@$_)&&$s++for a..z;
	$\+=$-=$s-$\
}
print

Measured memory_bytes: 512
import math
N = int(input())
rN = math.ceil(math.sqrt(N))
rN = int(rN)
li = []
if N == 1:
    exit()
for i in range(1,rN+1):
    if N % i == 0:
        li.append( i +(N//i))
print(min(li)-2)


Measured memory_bytes: 40300
#include<stdio.h>
int main(void) {
	int n;
	int i,m,e,j;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d%d%d",&m,&e,&j);
			if(m==100||e==100||j==100){
				printf("A\n");
			}else if(m+e>=180){
				printf("A\n");
			}else if(m+e+j>=240){
				printf("A\n");
			}else if(m+e+j>=210){
				printf("B\n");
			}else if(m+e+j>=150&&(m>=80||e>=80)){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1744