akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_003;

alias Pair = Tuple!(int, "x", int, "y");

void main() {
    int n;
    scan(n);

    auto x = new int[](n);
    auto y = new int[](n);

    foreach (i ; 0 .. n) {
        scan(x[i], y[i]);
    }

     sort(zip(x, y));

    debug {
        writeln(x);
        writeln(y);
    }

    if (n == 1) {
        writeln(1);
        return;
    }

    int[Pair] cnt;

    foreach (i ; 0 .. n) {
        foreach (j ; i + 1 .. n) {
            auto p = Pair(x[i] - x[j], y[i] - y[j]);
            cnt[p]++;
        }
    }

    auto cm = cnt.values.reduce!max;

    debug {
        writeln(cnt);
    }

    int ans = n - cm;

    writeln(ans);
}

















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 380
import java.util.Scanner;

//import jdk.internal.org.jline.utils.InputStreamReader;

//import java.io.*;

public class Main{
        public static void main(final String[] args){
            Scanner scanner = new Scanner(System.in);
            while(true){
                String cards = scanner.next();
                if(cards.equals("-")){
                    break;
                }
                int m = scanner.nextInt();
                int sum = 0;
                for(int i = 0; i < m; i++){
                    int h = scanner.nextInt();
                    cards = cards.concat(cards.substring(sum, sum + h));
                    sum += h;
                }
                System.out.println(cards.substring(sum));
            }
            scanner.close();
        }
         

}


Measured memory_bytes: 26376
R, G, B, N = map(int, input().split())
count = 0

for i in range(N+1):
    r = R*i
    for j in range(N+1):
        g = G*j
        k = int((N-r-g)/B)
        if 0 <= k and r+g+(B*k) == N:
            count += 1

print(count)

Measured memory_bytes: 41708
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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

template <typename T>
struct Graph_ {
  int n;
  vector<vector<pair<int, T> > > edge;
  vector<T> dis;
  Graph_(int ns) {
    n = ns;
    edge.resize(n);
    dis.resize(n);
  }
  void dijkstra(int s){
    dijkstra(s, 0);
  }
  T dijkstra(int s, int t){
    // initialize
    fill(dis.begin(), dis.end(), -1);
    vector<bool> used;
    used.resize(n);
    fill(used.begin(), used.end(), false);
    dis[s] = 0;
    // dijkstra
    priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > q;
    q.push(make_pair(0, s));
    while(!q.empty()){
      pair<T, int> p = q.top(); q.pop();
      int at = p.second;
      T distance = p.first;
      if(used[at])continue;
      used[at] = true;
      for(auto itr = edge[at].begin(); itr != edge[at].end(); ++itr){
        int to = (*itr).first;
        T cost = (*itr).second;
        if(used[to])continue;
        if(dis[to] == -1 || dis[to] > distance + cost){
          q.push(make_pair(distance + cost, to));
          dis[to] = distance + cost;
        }
      }
    }
    return dis[t];
  }
  void adde(int at, int to, T cost){
    edge[at].push_back(make_pair(to, cost));
  }
  [[deprecated("This function takes O(edge[at].size()).")]]
    void remove(int at, int to){
      int index = -1;
      for(int i = 0; i < edge[at].size(); i++){
        if(edge[at][i].first == to){
          index = i;
          break;
        }
      }
      edge[at].erase(edge[at].begin() + index);
    }
};

typedef struct Graph_<int> GraphI;
typedef struct Graph_<ll> GraphL;
typedef struct Graph_<double> GraphD;

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  GraphI graph(k);
  for(int i = 0; i < k; i++){
    graph.adde(i, (i+1)%k, 1);
    graph.adde(i, (10*i)%k, 0);
  }
  cout << graph.dijkstra(1, 0) + 1 << endl;
	return 0;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

int main(){
  int N; cin >> N;
  unordered_map<int,int> Adic;
  int A[N+1];
  for (int i=1;i<=N;i++){
    cin >> A[i];
    Adic[A[i]]++;
  }

  ll cnt = 0;
  for (auto p:Adic){
    ll k = p.second;
    cnt += k*(k-1)/2;
   }
 
  for (int i=1;i<=N;i++){
    cout << cnt - (Adic[A[i]]-1) << endl;
  }
  
  return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t root(vector<int64_t>& g, int64_t v) {
    if (g[v] != v) {
        g[v] = root(g, g[v]);
    }

    return g[v];
}

void merge(vector<int64_t>& g, int64_t v, int64_t u) {
    g[root(g, v)] = root(g, u);
}

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

    unordered_set<int64_t> langs;
    vector<int64_t> g(m);
    iota(g.begin(), g.end(), 0L);
    for (auto _ : irange(0L, n)) {
        int64_t k;
        cin >> k;

        int64_t l0;
        cin >> l0;
        --l0;
        langs.insert(l0);
        for (auto _ : irange(0L, k - 1)) {
            int64_t l;
            cin >> l;
            --l;
            merge(g, l0, l);
            langs.insert(l);
        }
    }

    auto l0 = *langs.begin();
    for (auto l : langs) {
        if (root(g, l0) != root(g, l)) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 4492
A, B = map(int, input().split())
ans = [[False] * 100 for _ in range(50)] + [[True] * 100 for _ in range(50)]
A -= 1
B -= 1

for h in range(0, 50, 2):
    for w in range(0, 100, 2):
        if A > 0:
            ans[h][w] = True
            A -= 1

for h in range(51, 100, 2)[:: -1]:
    for w in range(0, 100, 2):
        if B > 0:
            ans[h][w] = False
            B -= 1

print(100, 100)
for line in ans:
    a = ['.' if s else '#' for s in line]
    print(''.join(a))

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

int main(){
	int a,b,c;
	int ans;
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
import sys
readline = sys.stdin.readline

class WeightedUnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0] * n
        # 根への距離を管理
        self.weight = [0] * n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            y = self.find(self.parents[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.parents[x]]
            self.parents[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.parents[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.parents[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

def main():
    N, M = map(int, readline().rstrip().split())    
    uf = WeightedUnionFind(N)

    for _ in range(M):
        l, r, d = map(int, readline().rstrip().split())
        l -= 1
        r -= 1
        if uf.same(l, r):
            if uf.diff(l, r) != d:
                print('No')
                return

        uf.union(l, r, d)
    
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 15736
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);


LL a[200005], b[200005];
LL k;
int n, m;
int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &m);
  cin >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  LL s = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    s += b[i];
  }

  int ans = 0;

  int j = m - 1;
  while (s > k && j >= 0) {
    s -= b[j];
    j -= 1;
  }
  if (s <= k) ans = max(ans, j + 1);

  for (int i = 0; i < n; i++) {
    s += a[i];
    while (s > k && j >= 0) {
      s -= b[j];
      j -= 1;
    }
    if (s <= k) {
      ans = max(ans, j + 1 + i + 1);
    }
  }
  printf("%d\n", ans);

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 6884
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int n;
vector<int> a,b,c;
int tmp;
ll sum = 0;

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&tmp);
    a.push_back(tmp);
  }
  REP(i,n){
    scanf("%d",&tmp);
    b.push_back(tmp);
  }
  REP(i,n){
    scanf("%d",&tmp);
    c.push_back(tmp);
  }
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  REP(i,n){
    //printf("%d %d\n",upper_bound(a.begin(),a.end(),b[i])-a.begin(),n-(upper_bound(c.begin(), c.end(),b[i])-c.begin()));
    sum += (lower_bound(a.begin(),a.end(),b[i])-a.begin()) * (n-(upper_bound(c.begin(), c.end(),b[i])-c.begin()));
  }
  printf("%lld\n",sum);
}

/*
int n;
vector<int> a,b,c;
int tmp;
int dp[2][100010];


int main(){
  scanf("%d",&n);
  REP(j,n){
    dp[0][j] = 0;
    dp[1][j] = 0;
    scanf("%d",&tmp);
    a.push_back(tmp);
  }
  REP(j,n){
    scanf("%d",&tmp);
    b.push_back(tmp);
  }
  REP(j,n){
    scanf("%d",&tmp);
    c.push_back(tmp);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  int now = 0;
  REP(i,n){
    if(b[now]>a[i]){
      dp[0][now]++;
    }else{
      while(++now<n){
        dp[0][now] = dp[0][now-1];
        if(b[now]<=a[i]) continue;
        dp[0][now]++;
        break;
      }
    }
  }
  FOR(i,now+1,n){
    dp[0][i] = dp[0][i-1];
  }
  now = 0;
  REP(i,n){
    if(c[now]>b[i]){
      dp[1][now]+=dp[0][i];
    }else{
      while(++now < n){
        dp[1][now] = dp[1][now-1];
        if(c[now]<=b[i]) continue;
        dp[1][now] += dp[0][i];
        break;
      }
    }
  }
  FOR(i,now+1,n){
    dp[1][i] = dp[1][i-1];
  }

  int sum=0;
  REP(i,n){
    sum += dp[1][i];
  }
  printf("%d\n",sum);
  return 0;
}
*/


Measured memory_bytes: 1784
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())

s = set()
for i in range(K):
    d = int(input())
    s |= set(map(int, input().split()))

print(N - len(s))

Measured memory_bytes: 9692
n = int(input())
data = [0 for i in range(5)]
for i in range(n):
    k = input()
    if k[0] == 'M':
        data[0] += 1
    elif k[0] == 'A':
        data[1] += 1
    elif k[0] == 'R':
        data[2] += 1
    elif k[0] == 'C':
        data[3] += 1
    elif k[0] == 'H':
        data[4] += 1
total = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            total += data[i] * data[j] * data[k]
print(total)


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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  REP(i, N){
    cin >> S[i];
  }
  int ans = 0;
  auto check = [&](int di){
    vector<string> board = S;
    REP(i, N){
      REP(j, N){
        int y = (i+di) % N, x = j;
        board[y][x] = S[i][j];
      }
    }
    REP(i, N){
      REP(j, N){
        if(board[i][j] != board[j][i]){
          return false;
        }
      }
    }
    return true;
  };
  REP(d, N){
    if(check(d)){
      ans+= N;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int ans=1;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
data = input().split()
H = int(data[0])
W = int(data[1])

str = []
for i in range(H):
	data = input()
	str.append(data[:W])

for j in range(W+2):
	print("#", end="")
print("")
for i in range(H):
	print("#", end="")
	print("".join(str[i]), end="")
	print("#")
for j in range(W+2):
	print("#", end="")



Measured memory_bytes: 3064
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = input().strip()

t = list(S)
t.reverse()

if "".join(t) ==  S:
    print("Yes")
else:
    print("No")

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

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

    int n;
    cin >> n;
    vector<int> ds(n);
    for (int i = 0; i < n; i++) {
        cin >> ds[i];
    }
    sort(ds.begin(), ds.end());
    cout << ds[n / 2] - ds[n / 2 - 1] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 1e5+1;
ll f, s[N], a;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  f = 1;
  FOR(i, 1, n+1){
    f = f * i % mod;
    s[i] = (modpow(i, mod-2, mod) + s[i-1]) % mod;
  }
  ll ans = 0;
  FOR(i, 0, n){
    cin >> a;
    ans += (s[i+1]+s[n-i]+mod-1) * a % mod;
  }
  cout << ans % mod * f % mod << endl;
  return 0;
}

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

int main(){
    int d;
    cin >> d;
    cout << "Christmas";
    rep(i,25 - d) cout << " Eve";
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	Scanner sc=new Scanner(System.in);

	public void run() {
		int a=sc.nextInt(),b=sc.nextInt();
		
		ln(a*b + " "+2*(a+b));
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
	public static void pr(Object o) {
		System.out.print(o);
	}
	
	public static void ln(Object o) {
		System.out.println(o);
	}
	
	public static void ln() {
		System.out.println();
	}
}

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

int main()
{
  ll a,b,k;
  cin >> a >> b >> k;
  
  int x[k*2];
  int c = 0;
  for(int i = a; i <= b; i++){
    if(i < a+k || b-k < i){
      cout << i << endl;
    }
  }
  
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;

const long long inf = 1LL<<62;

long long sum(long long t, const vector<long long>&v)
{
  long long ret = 0;
  for(int i = 0; i < (int)v.size(); ++i){
    ret += llabs(v[i]-t);
  }
  return 2*ret;
}

const int dt[2][9] = { {-1,-1,-1,0,0,0,1,1,1},
                       {-1, 0, 1,-1,0,1,-1,0,1} };

int main()
{
  long long w,h;
  while(EOF!=scanf("%lld%lld", &w, &h)){
    int n;
    long long res = inf;
    long long res_coord[2];
    vector<long long> coord[2], org[2];
    
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < 2; ++j){
        long long t; scanf("%lld", &t); coord[j].push_back(t);
      }
    }

    org[0] = coord[0];
    org[1] = coord[1];
    sort(coord[0].begin(),coord[0].end());
    sort(coord[1].begin(),coord[1].end());

    long long minc[2] = {inf,inf};
    long long ind[2];
    for(int i = n/2-1; i <= n/2+1; ++i){
      if( i < 0 || i >= n ) continue;
      for(int j = 0; j < 2; ++j){
        long long tm = sum(coord[j][i],coord[j]);
        if( minc[j] > tm ){ minc[j] = tm; ind[j] = i; }
      }
    }
    
    for(int i = 0; i < 9; ++i){
      bool inv = false;
      long long tind[2];
      long long tsum[2] = {0,0};
      for(int j = 0; j < 2; ++j){
        tind[j] = ind[j]+dt[j][i];
        if( tind[j]<0 || tind[j]>=n ){ inv = true; continue; }
        tsum[j] = sum(coord[j][tind[j]],coord[j]);
      }
      if( inv ) continue;
      for(int k = 0; k < n; ++k){
        long long t[2];
        for(int j = 0; j < 2; ++j){
          t[j] = tsum[j] - llabs(org[j][k]-coord[j][tind[j]]);
        }
        if( res > t[0] + t[1] ){
          res = t[0] + t[1];
          for(int j = 0; j < 2; ++j){
            res_coord[j] = coord[j][tind[j]];
          }
        }
      }
    }

    printf("%lld\n%lld %lld\n", res, res_coord[0], res_coord[1]);    
  }
  return 0;
}

Measured memory_bytes: 4148
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);

    while(true){
      int m = scan.nextInt();
      int f = scan.nextInt();
      int r = scan.nextInt();
      if(m==-1 && f==-1 && r==-1) break;

      if(m==-1 || f==-1){
        System.out.println("F");
        continue;
      }
      int sum=m+f;
      if(sum<30) System.out.println("F");
      else if(sum<50){
        if(r>=50){
          System.out.println("C");
        }else{
          System.out.println("D");
        }
      }else if(sum<65) System.out.println("C");
      else if(sum<80) System.out.println("B");
      else System.out.println("A");
    }
  }
}



Measured memory_bytes: 26248
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n,m = mi()
    h = li()
    e = [1 for i in range(n)]

    for i in range(m):
        a,b = mi()
        a-=1
        b-=1
        if h[a] <= h[b]:
            e[a] = 0
        if h[b] <= h[a]:
            e[b] = 0

    print(sum(e))



main()




Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define FAIL { puts("Impossible"); return 0; }

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

const int N = (int) 1e2 + 10;
int n, a[N], c[N];

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    memset(c, 0, sizeof c);
    for (int i = 1; i <= n; ++i) c[a[i]]++;
    int d = *max_element(a + 1, a + 1 + n);
    int k = (d + 1) / 2;
    if (c[d] < 2) FAIL;

    c[d] -= 2;
    for (int i = k; i <= d - 1; ++i) {
        int v = (i + i == d) ? 1 : 2;
        if (c[i] < v) FAIL;
        c[i] -= v;
    }

    for (int i = 1; i <= k; ++i) if (c[i] > 0) FAIL;
    puts("Possible");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  double x1,x2,y1,y2,xp,yp;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xp,&yp)!=EOF){
    double th1 = atan2(y2-y1,x2-x1);
    double th2 = atan2(yp-y1,xp-x1);
    double th = 2*th1 - th2;
    double r = (xp-x1)?(xp-x1)/cos(th2):(yp-y1)/sin(th2);
    printf("%lf %lf\n", x1+r*cos(th),y1+r*sin(th));
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			char[] s = in.next().toCharArray();
			int i = 0;
			int j = s.length - 1;
			int ans = 0;
			while (i < j) {
				if (s[i] == s[j]) {
					++i;
					--j;
					continue;
				}
				if (s[i] == 'x') {
					++ans;
					++i;
					continue;
				}
				if (s[j] == 'x') {
					++ans;
					--j;
					continue;
				}
				out.println(-1);
				return;
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

	}
}



Measured memory_bytes: 23380
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  string s;
  cin >> s;
  vector<string> vec = {"eraser","dreamer","dream","erase"};
  int id = (int)s.size()-1;
  bool ans = true;
  while(id>0){
    REP(i,4){
      if(id+1>=(int)vec[i].size()&&s.substr(id+1-(int)vec[i].size(),vec[i].size())==vec[i]){
        id -= (int)vec[i].size();
        break;
      }
      if(i==3){
        ans = false;
        break;
      }
    }
    if(!ans) break;
  }
  cout << (ans?"YES":"NO") << endl;
}



Measured memory_bytes: 512
n, k = map(int, input().split())

d = [0]*k
a = [0]*k

for i in range(k):
    d[i] = int(input())
    a[i] = list(map(int, input().split()))

k = 0

b = sum(a, [])
    
for i in range(n):
    if i+1 not in b:
        k = k + 1

print(k)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define INF 200000000000 
using namespace std;

int main()
{
int V,E;scanf("%d %d",&V,&E);
vector<vector<long long>> G(V,vector<long long>(V,INF));
for(int i=0;i<V;i++)G[i][i]=0;
for(int i=0,s,t,d;i<E;i++)
{
  scanf("%d %d %d",&s,&t,&d);
  G[s][t]=d;
}
for(int k=0;k<V;k++)for(int i=0;i<V;i++)for(int j=0;j<V;j++)
{
  if(G[i][k]==INF||G[k][j]==INF)continue;
  G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
}
for(int i=0;i<V;i++)if(G[i][i]<0){printf("NEGATIVE CYCLE\n");return 0;}
for(int i=0;i<V;i++)
{
  for(int j=0;j<V;j++)
  {
    if(G[i][j]>=INF)printf("INF");
    else printf("%d",G[i][j]);
    if(j<V-1)printf(" ");
  }
  printf("\n");
}
}


Measured memory_bytes: 3332
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

double a,b,c;
const double PI=3.1415926535897932384626;

int main()
{
	scanf("%lf%lf%lf",&a,&b,&c);
	if(c>=a*a*b/2)
	{
	   double v1=a*a*b;
	   double v2=c;
	   double dv=v1-v2;
	   double dh=(dv*2)/(a*a);
	   printf("%.10lf",(atan(dh/a)*180.0)/PI);
    }
    else
    {
    	double dh=(c*2)/(a*b);
    	printf("%.10lf",(atan(b/dh)*180.0)/PI);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int t,s[128],n,i,j,h;
    while(scanf("%d",&n) , n != 0){
        for(i=1;i<=n;i++){
            scanf("%d",&s[i]);
        }
        t = 0;
        for(i=n;i>=2;i--){
            for(j=1;j<=i-1;j++){
                if(s[j]>s[j+1]){
                    h = s[j];s[j] = s[j+1];s[j+1] = h;t++;
                }
            }
        }
        printf("%d\n",t);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] w = new int[n];
        for(int i = 0; i < n; i++){
            w[i] = Integer.parseInt(sc.next());
        }
        
        int left = 0;
        int right = 1000000000;
        while(left < right){
            int mid = (left + right) / 2;
            if(load(w, k, mid) == n){
                right = mid;
            }else{
                left = mid + 1;
            }
        }
        
        System.out.println(left);
    }
    
    static int load(int[] w, int k, int p){
        
        int count = 0;
        for(int i = 0; i < k; i++){
            int truck = 0;
            while(count < w.length && truck + w[count] <= p){
                truck += w[count];
                count++;
            }
        }
        
        return count;
    }
}


Measured memory_bytes: 70920
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007



using namespace std;

//check for corner cases(for n==1)
// check for int overflow
// run on some sample cases before submitting
  const  ll N=1e5 + 5;
int main()
{
  fast;
       ll n;
       cin>>n;
       ll a[n];
       forin cin>>a[i];
       ll z=0;
       forin
       z^=a[i];
       for(int i=0;i<n;i++)
       {
           ll x=z;
           x^=a[i];
           cout<<x<<" ";
       }

}


Measured memory_bytes: 5152
N, M = map(int, input().split())
Bridge= [[int(i) for i in input().split()] for _ in range(M)]
Parent = [int(i) for i in range(N)]
Rank = [1] * N
 
def find(x):
    if x == Parent[x]: return x
    else:
        Parent[x] = y = find(Parent[x])
        return y
 
def unite(x, y, Total):
    rx, ry = find(x), find(y)
    if rx == ry: return Total
    else:
      Total -= Rank[rx] * Rank[ry]
      if Rank[rx] < Rank[ry]:
        Parent[rx] = ry
        Rank[ry] += Rank[rx]
      else:
        Parent[ry] = rx
        Rank[rx] += Rank[ry]
      return Total
 
Total = N * (N - 1) // 2
Ans = [Total] * M
for i in reversed(range(1, M)):
    A, B = Bridge[i]
    Total = unite(A-1, B-1, Total)
    Ans[i-1] = Total  
 
print("\n".join(map(str, Ans)))

Measured memory_bytes: 36420
S = list(input())
T = list(input())
dic = {}
ans='Yes'
for s,t in zip(S,T):
  if not s in dic:
    if t in dic.values():
      ans = 'No'
      break
    else:
      dic[s]=t
    
  else:
    if dic[s]!=t:
      ans = 'No'
      break
      
print(ans)

Measured memory_bytes: 70348
n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))

left_a_list = [a for a in a_list if a < x]
right_a_list = [a for a in a_list if a > x]
min_cost = min(len(left_a_list), len(right_a_list))

print(min_cost)

Measured memory_bytes: 3060
<?php

$stack = array();
while (TRUE) {
    fscanf(STDIN, "%d", $i);
    if (feof(STDIN)) {
        break;
    }
    if ($i === 0) {
        if (!count($stack)) {
            break;
        }
        echo (string) array_pop($stack);
        echo PHP_EOL;
    } else {
        $stack[] = $i;
    }
}

Measured memory_bytes: 6576
import fractions
import math

A, B = map(int, input().split())
gcd = fractions.gcd(A, B)
saidai = gcd

kosuu = 1  # 1

if saidai % 2 == 0:
    kosuu += 1

while saidai % 2 == 0:
    saidai = saidai // 2

# sqrt = int(math.sqrt(gcd))
# for i in range(3, sqrt+1+1, 2):
#     if saidai <= 1:
#         break

#     if saidai % i == 0:
#         kosuu += 1

#     while saidai % i == 0:
#         saidai = saidai // i

i = 3
while True:
    if saidai <= 1:
        break

    if i > math.sqrt(saidai):
        break

    if saidai % i == 0:
        kosuu += 1

    while saidai % i == 0:
        saidai = saidai // i

    i += 2

if saidai != 1:
    kosuu += 1

print(kosuu)


Measured memory_bytes: 5176
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
int a[N],b[N],n,res,c[N];
int main() {
	ll A=0,B=0;
	read(n);rep(i,1,n)read(a[i]),A+=a[i];
	rep(i,1,n)read(b[i]),B+=b[i];
	if(B>A){puts("-1");return 0;}
	int len=0;rep(i,1,n)if(a[i]>=b[i])c[++len]=a[i]-b[i];
	sort(c+1,c+len+1);ll now=A-B;
	rep(i,1,len)if(now>=c[i])now-=c[i],res++;else break;
	res=n-res;cout<<res;
	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main(){
	int n[2][10],i,j,k,x;
	for(i=0;i<2;i++){
		for(j=0;j<10;j++){
			scanf("%d",&n[i][j]);
		}
	}
	for(i=0;i<2;i++){
		for(j=0;j<10;j++){
			for(k=j;k<10;k++){
				if(n[i][j]<n[i][k]){
					x=n[i][j];
					n[i][j]=n[i][k];
					n[i][k]=x;
				}
			}
		}
	}
	for(i=0;i<2;i++){
		x=0;
		for(j=0;j<3;j++){
			x=x+n[i][j];
		}
		printf("%d",x);
		if(i==0)printf(" ");
		else printf("\n");
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }

  bool push[n];  // 一度でも押したか
  for (int i = 0; i < n; i++) {
    push[i] = false;
  }

  int pos = 0;
  for (int i = 0; i < n; i++) {
    if (push[pos]) {
      puts("-1");
      return 0;
    }
    if (a[pos] == 1) {
      cout << i + 1 << endl;
      return 0;
    } else {
      pos = a[pos];
    }
  }

  puts("-1");
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
const long long INF = 1LL << 60;
 
int main()
{
    ll N, X;
    cin >> N >> X;
 
    vector<ll> x(N + 1), diff(N);
    rep(i, N) cin >> x[i];
 
    x[N] = X;
    sort(x.begin(), x.end());
 
    repd(i, 1, N + 1) {
        diff[i - 1] = x[i] - x[i - 1];
    }
 
    sort(diff.begin(), diff.end());

    ll div = diff[0];
    repd(i, 1, N) {
        div = gcd(div, diff[i]);
    }
 
    cout << div << endl;

    return 0;
}

Measured memory_bytes: 1792
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], a = tmp[1], b = tmp[2];

    writeln(min(a, b), " ", max(0, a+b-n));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
import scala.io.StdIn
import scala.collection.mutable._

object Main extends App {

  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val graph = Array.fill(n+1)(ListBuffer.empty[Int])
  Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => graph(e(0)) += e(1))

  val isPossible = {
    var visited = false
    def dfs(pos:Int, cnt:Int):Unit = {
      if(cnt < 0) return
      if(pos == n) visited = true
      else {
        for(i <- graph(pos)) {
          if(!visited) dfs(i, cnt-1)
          else return
        }
      }
    }
    dfs(1,2)
    visited
  }
  val ans = if(isPossible) "POSSIBLE" else "IMPOSSIBLE"
  println(ans)
}

Measured memory_bytes: 81464
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7   
N = readline().decode().rstrip()
K = int(readline())
L = len(N)
# 桁DP
dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(L+1)]
dp[0][0][0] = 1
for i in range(L):
    for j in range(4):
        for k in range(2):
            nd = int(N[i])
            for d in range(10):
                ni = i + 1; nj = j; nk = k
                if d != 0:
                    nj += 1
                if nj > K:
                    continue
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]
print(dp[L][K][0]+dp[L][K][1])

Measured memory_bytes: 9292
#include <iostream>

using namespace std;

int main(void){
	
 int k;
 cin >> k;
  
  if( k%2 == 0){
    int ans = (k/2)*(k/2);
  	cout << ans;
  }
  
  else{
  	
    int ans = (k/2)*( (k/2) + 1);
  	cout << ans;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ull = unsigned long long;

int main() {
	ull A, B, K;
	cin >> A >> B >> K;
	
	if(A + B < K) {
		cout << 0 << " " << 0;
	} else if(A > K) {
		cout << A - K << " " << B;
	} else {
		cout << 0 << " " << B + A - K;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i, a, n) for(long long int i = a; i < n; i++)
int main(){
  long long int a, b, c, x;
  cin >> x;
  rep(i, -118, 120){
    rep(j, -119, 119){
      c = i * i * i * i * i - j * j * j * j * j;
      if(c == x){
        a = i;
        b = j;
        break;
      }
    }
  }
  
  cout << a << ' ' << b;
}

Measured memory_bytes: 3560
#include <stdio.h>

int main(){
    int n,b,f,r,v;
    scanf("%d",&n);
    int o[3][10] = {};//1棟
    int p[3][10] = {};//2棟
    int q[3][10] = {};//3棟
    int t[3][10] = {};//4棟
    for(int k = 1; k <= n; k++){
        scanf("%d%d%d%d",&b,&f,&r,&v);
        if(b==1){
            o[f-1][r-1] = o[f-1][r-1] + v;
            if(o[f-1][r-1] < 0){
                o[f-1][r-1] = 0;
            }
        }
        else if(b==2){
            p[f-1][r-1] = p[f-1][r-1] + v;
            if(p[f-1][r-1] < 0){
                p[f-1][r-1] = 0;
            }
        }
        else if(b==3){
            q[f-1][r-1] = q[f-1][r-1] + v;
            if(q[f-1][r-1] < 0){
                q[f-1][r-1] = 0;
            }
        }
        else{
            t[f-1][r-1] = t[f-1][r-1] + v;
            if(t[f-1][r-1] < 0){
                t[f-1][r-1] = 0;
            }
        }
    }
    for(int k = 1; k <= 4;k++){
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++){
                if(k == 1){
                    printf(" %d",o[i][j]);
                }
                else if(k == 2){
                    printf(" %d",p[i][j]);
                }
                else if(k == 3){
                    printf(" %d",q[i][j]);
                }
                else {
                    printf(" %d",t[i][j]);
                }
            }
            printf("\n");
        }
        if(k != 4){
            printf("####################\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2712
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	char number[9];
	int value;
};

void func(int n,int m){
	Info info[n];

	for(int i = 0; i < n; i++)scanf("%s %d",info[i].number,&info[i].value);

	int sum = 0;
	char tmp[9];
	bool FLG;

	for(int i = 0; i < m; i++){
		scanf("%s",tmp);

		for(int k = 0; k < n; k++){
			FLG = true;
			for(int p = 0; p < 8; p++){
				if(tmp[p] >= '0' && tmp[p] <= '9' && info[k].number[p] >= '0' && info[k].number[p] <= '9' && tmp[p] != info[k].number[p]){
					FLG = false;
					break;
				}
			}
			if(FLG){
				sum += info[k].value;
				break;
			}
		}
	}

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

}


int main(){

	int n,m;

	while(true){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)break;

		func(n,m);
	}


	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int X,t;
  cin>>X>>t;
  
  cout<<((X-t>=0)?(X-t):0);

  return 0;
}


Measured memory_bytes: 256
a=int(input())
count=1
if a==1:
  count+=3
elif a==2:
  count+=3
else:
  count+=1
  while a!=1:
    if a%2==0:
        a=a/2
        count+=1
    else:
        a=3*a+1
        count+=1
print(count)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    T = [[] for _ in range(N+1)]
    cost = [None] * (N+1)
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        T[a].append((b,c))
        T[b].append((a,c))
    Q, K = map(int, input().split())
    cost[K] = 0
    stack = [K]
    while stack:
        x = stack.pop()
        d = cost[x]
        for y, c in T[x]:
            if cost[y] is None:
                cost[y] = d + c
                stack.append(y)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(cost[x]+cost[y])

if __name__ == "__main__":
    main()

Measured memory_bytes: 43440
//ritik_patel05

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <bits/stdc++.h>
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
// const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

int fast_power(int a, int b){
    int res = 1;
    while(b){
        if(b&1) res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    int total = 0;
    for(auto &x: a){
        cin >> x;
        mp[x]++;
        total += x;
    }
    int q; cin >> q;
    for(int i = 0; i < q; ++i){
        int old, nw; cin >> old >> nw;
        int old_cnt = mp[old];
        int before_add = old_cnt * old;
        total -= before_add;
        total += nw * old_cnt;
        mp[nw] += old_cnt;
        mp[old] -= old_cnt;
        cout << total << '\n';
    }
    


}


int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}

/*
Sample inp
*/


Measured memory_bytes: 10096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;


int main() {
    int N;
    while(cin >> N, N) {
        vector<pair<double, string>> v(N);
        for(int i=0; i<N; ++i) {
            string L;
            int P, A, B, C, D, E, F, S, M;
            cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
            int total_time = A + B + C + (D + E) * M;
            v[i] = make_pair(static_cast<double>(F * S * M - P) / total_time, move(L));
        }
        sort(v.begin(), v.end(), [](auto const& p1, auto const& p2) {
            if(p1.first != p2.first) return p1.first > p2.first;
            else                     return p1.second < p2.second;
        });

        for(auto& x : v) {
            cout << x.second << endl;
        }
        cout << "#" << endl;
    }
}


Measured memory_bytes: 3036
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1];

    return 0;
}

Measured memory_bytes: 3568