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

int main(){
    int N, Q; cin >> N >> Q;
    vector<vector<int>> G(N);
    vector<pair<int, int>> A;
    vector<long> C(N, 0);
    for (int i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i=0; i<Q; i++){
        int p, x; cin >> p >> x;
        p--;
        C[p]+=x;
    }
    queue<int> pos;
    vector<bool> check(N,false);
    pos.push(0);
    check[0] = true;
    while(!pos.empty()){
        int from = pos.front(); pos.pop();
        for(int to: G[from]){
            if(!check[to]){
                check[to] = true;
                C[to] += C[from];
                pos.push(to);
            }
        }
    }
    for(int i=0; i<N; i++){
        if(i!=N-1) cout << C[i] << " ";
        else cout << C[i] << endl;
    }
}


Measured memory_bytes: 16372
#include <iostream>
using namespace std;
int main(){
    long long a, b, x, tmp;
    cin >> a >> b >> x;
    if(a%x==0&&b%x==0){
        printf("%lld\n",b/x-a/x+1);
    }else if(a%x==0){
        tmp = b%x;
        b -= tmp;
        printf("%lld\n",b/x-a/x+1);
    }else{
        tmp = a%x;
        a += x-tmp;
        tmp = b%x;
        b -= tmp;
        printf("%lld\n",b/x-a/x+1);
    }
    return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>
int main()
{
    int n,i,mod, odd = 0;
    scanf("%d",&n);
    for( i = 1;i<=n;i++ )
 {
    int a = i;
    int count = 0;
    while(a !=0)
    {
        mod = a%10;
        a = a/10;
        count++;
    }
    if(count  % 2 != 0)
    {
        odd++;
    }
 }
 printf("%d\n", odd);
}


Measured memory_bytes: 1736
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {
	ll N, M, C;
	cin >> N >> M >> C;
	vll B(M);
	vector<vll> A(N, vll(M));
	rep(i, M) cin >> B[i];
	rep(i, N) rep(j, M) cin >> A[i][j];

	ll ans = 0;
	rep(i, N) {
		ll val = 0;
		rep(j, M) val += A[i][j] * B[j];
		val += C;
		if (val > 0) ++ans;
	}

	cout << ans << endl;
}

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

int main()
{
	int h,w;
	string c[100];
	cin>>h>>w;
	for(int i=0;i<h;i++) cin>>c[i];
	
	for(int i=0;i<h;i++){
		cout<<c[i]<<"\n"<<c[i]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        b();
    }

    private static void b() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int c = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int h = Integer.parseInt(sc.next());
            if (h >= max) {
                c++;
                max = h;
            }
        }
        p(c);
    }

    private static void p(Object x) {
        System.out.println(x.toString());
    }
}


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

int main(void)
{
  int map[101];
  int tmp;
  int max;
  int i;

  memset(map, 0, sizeof(map));

  while(scanf("%d", &tmp) != EOF){
    map[tmp]++;
  }
  
  max = 0;

  for (i = 1; i <= 100; i++){
    if (max < map[i]){
      max = map[i];
    }
  } 

  for (i = 1; i <= 100; i++){
    if (max == map[i]){
      printf("%d\n", i);
    }
  }

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+1==c&&d==1){
    cout << 1<<endl;
  }
  else{
    cout << 0 <<endl;
  }
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define MOD (1000000007l)

using namespace std;

long N, M;
vector<pair<long, long> > requests;

bool compair(pair<long, long> &i, pair<long, long> &j) {
  return i.second < j.second;
}

int main(void) {
  cin >> N >> M;
  for (long i = 0; i < M; i++) {
    long a, b;
    cin >> a >> b;
    requests.push_back(pair<long, long>(a, b));
  }
  sort(requests.begin(), requests.end(), compair);
  long last_removed = 0;
  long ans = 0;
  for (auto r: requests) {
    if (r.first < last_removed) continue;
    last_removed = r.second;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{ 
  int x,i,j,k,ans;
  cin>>x;
  if(x==1){cout<<"2"<<endl;return 0;}
  while(1)
  {
    i=2;
    while(1)
    {
      if(x%i==0&&x/i!=1){x++;break;}
      if(i*i>x){cout<<x<<endl;return 0;}
      i++;
    }
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	s[1]=='B'?cout<<"ARC":cout<<"ABC";

	


	return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), asc);
    int ans = 0;
    int x = 1;
    for (i = 1; i < n; i++)
    {
        if (a[i] == a[i - 1])
            x++;
        else
        {
            if (x % 2 == 1)
                ans++;
            x = 1;
        }
    }
    if (x % 2 == 1)
        ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 892
n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
m = h[k-1] - h[0]
for i in range(1,n-k+1):
  x = h[k-1+i] - h[i]
  if x < m:
    m = x
print(m)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 123451

int n;
ll pre[100001 * 3], en[100001 * 3], el[100001 * 3];
priority_queue<int> l1, l2;

int main() {

        cin >> n;
        lp (i, 0, n * 3) {
                cin >> el[i];
        }
        pre[0] = el[0];
        l1.push(-el[0]);
        for (int i = 1; i < n; i++) pre[i] = el[i] + pre[i - 1], l1.push(-el[i]);
        for (int i = n; i < n * 2; i ++) {
                l1.push(-el[i]);
                pre[i] = pre[i - 1] + el[i] + l1.top();
                l1.pop();
        }
        en[3 * n - 1] = el[3 * n - 1];
        l2.push(el[3 * n - 1]);
        for (int i = 3 * n - 2; i >= 2 * n; i--) en[i] = el[i] + en[i + 1], l2.push(el[i]);
        for (int i = 2 * n - 1; i >= n; i--) {
                l2.push(el[i]);
                en[i] = en[i + 1] + el[i] - l2.top();
                l2.pop();
        }
        ll ans = -1e18;
        for (int i = n - 1; i < 2 * n; i++) {
                ans = max(ans, pre[i] - en[i + 1]);
        }
        cout << ans;
        return 0;
}


/*
long long
constrain N
*/


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef unsigned long long ull;

const ull base1 = 9973ULL;
const ull base2 = 100000007ULL;
int H,W,P;
char field[1100][1100],pattern[1100][1100];
ull tmp[1100][1100],hash[1100][1100];

vector<string> rotate90(const vector<string>& piece){
  vector<string> ret;
  int h = piece[0].size(), w = piece.size();
  ret.resize(h);
  for(int i=0;i<h;i++)ret[i].resize(w);
  for(int y=0;y<ret.size();y++){
    for(int x=0;x<ret[0].size();x++){
      ret[y][x] = piece[ret[0].size()-1-x][y];
    }
  }
  return ret;
}

int toInt(char c){
  if( 'A' <= c && c <= 'Z' ) return 0  + (c-'A');
  if( 'a' <= c && c <= 'z' ) return 26 + (c-'a');
  if( '0' <= c && c <= '9' ) return 52 + (c-'0');
  return (c=='+')?62:63;
}


void compute_hash(char a[1100][1100],int h,int w){

  ull t1 = 1ULL, t2 = 1ULL;
  rep(i,P) t1 = t1 * base1, t2 = t2 * base2;

  rep(i,h) {
    ull e = 0ULL;
    rep(j,P) e = e * base1 + a[i][j];
    for(int j=0;j+P-1<w;j++){
      tmp[i][j] = e;
      e = e * base1 - t1 * a[i][j] + a[i][j+P];
    }
  }
  
  for(int i=0;i+P-1<w;i++){
    ull e = 0ULL;
    rep(j,P) e = e * base2 + tmp[j][i];
    for(int j=0;j+P-1<h;j++) {
      hash[j][i] = e;
      e = e * base2 - t2 * tmp[j][i] + tmp[j+P][i];
    }
  }
}


int main(){

  while( cin >> W >> H >> P, H|W|P ){
    rep(i,H) rep(j,ceil(W/6.0)) {
      char c;
      cin >> c;
      int ic = toInt(c);
      rep(k,6) field[i][j*6+5-k] = (char)(('0'+((ic>>k)&1)));
    }

    rep(i,P)rep(j,ceil(P/6.0)){
      char c;

      cin >> c;
      int ic = toInt(c);

      rep(k,6) pattern[i][j*6+5-k] = (char)(('0'+((ic>>k)&1)));
    }

    compute_hash(field,H,W);
    map<ull,int> counter;
    for(int i=0;i+P-1<H;i++) for(int j=0;j+P-1<W;j++) counter[hash[i][j]]++;

    vector<string> vec(P);
    rep(i,P){
      vec[i] = "";
      rep(j,P) vec[i] += pattern[i][j];
    }

    set<ull> S;
    rep(_,2){
      rep(i,4) {
        compute_hash(pattern,P,P);
        S.insert(hash[0][0]);
        vec = rotate90(vec);
        rep(y,P) rep(x,P) pattern[y][x] = vec[y][x];
      }
      rep(i,P) reverse(vec[i].begin(),vec[i].end());
      rep(y,P) rep(x,P) pattern[y][x] = vec[y][x];
    }

ull sum = 0;
    for(set<ull>::iterator it = S.begin(); it != S.end(); it++) sum += counter[*it];
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 55036
import string
strings = string.ascii_lowercase
clues = [(19, 7, 8, 18), (19, 7, 0, 19), (19, 7, 4)]
while True:
    try:
        data = input()
    except:
        break
    for word in data.split():
        if len(word) == 4 or 3:
            dif = 19 - (ord(word[0]) - 97)
            enc = ["" for _ in range(26)]
            for k, v in zip([i for i in range(dif, dif+26)], strings):
                enc[k%26] = v
            candidate = tuple(enc.index(c) for c in word)
            try:
                clues.index(candidate)
            except:
                continue
            break
    ans = ""
    for c in data:
        try:
            ans += strings[enc.index(c)]
        except:
            ans = ans + "." if c == "." else ans + " "
    print(ans)



Measured memory_bytes: 6684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	while (1) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) { break; }
		if (a > b) { swap(a, b); }
		cout << a << " " << b << endl;
	}
}


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

int main()
{
  int x, y;

  cin >> x >> y;

  int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

  if (group[x] == group[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define int long long

signed main(void){
    int a,b; cin >> a >> b;
    if(a < b){
        string tmp = "";
        for(int i=0;i<b;i++) tmp += to_string(a);
        cout << tmp << endl;
    }else{
        string tmp = "";
        for(int i=0;i<a;i++) tmp += to_string(b);
        cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//??\??????????????????????????????Scanner???????????§???????????????
		Scanner scan = new Scanner(System.in);
		
		//??¢???????????????????????¨???????????????
		int[] count = new int[26];

		//?¬?????????????????????????????????°
		while(scan.hasNext()){
			//?¬?????????????????????????
			String text = scan.next();
			
			//char??????????????????????????\?????????
			char[] cArray = text.toCharArray();
			//??\??£???char?????°?????????
			for(int i = 0; i < cArray.length; i++){
				//??¢???????????????????????????????????§??????
				for(int j = 0; j < 26 ; j++){
					//??§??????????????°
					if(cArray[i] == j + 65){
						count[j]++;
					//?°???????????????°
					} else if (cArray[i] == j + 97){
						count[j]++;
						
					}	
				}
			}
		}
		//??¨???
		for(int i = 0; i < 26; i++){
			System.out.println((char)('a'+ i) + " : " + count[i]);
		}
	}

}

Measured memory_bytes: 26008
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

string bin(int H, int A[], int n) {
    for (int i = 0; i < n; ++i) {
        H -= A[i];
        if (H <= 0) return "Yes";
    }
    return "No";
}

int main() {
    cio;
    int H, N;
    cin >> H >> N;
    int A[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    cout << bin(H, A, N);
    cn;
}


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

const int MAXV = 305;
const int INF = (1<<28);

struct Edge {int to, cap, rev; };

int N, M;
vector<Edge> G[MAXV];
bool used[MAXV];
vector<pair<int,int> > roads;

void init() {
  for(int i = 0; i < MAXV; ++i) G[i].clear();
  roads.clear();
}

void addEdge(int from, int to, int cap) {
  G[from].push_back((Edge){to, cap, G[to].size()});
  G[to].push_back((Edge){from, 0, G[from].size() - 1});

  swap(from, to);
  G[from].push_back((Edge){to, cap, G[to].size()});
  G[to].push_back((Edge){from, 0, G[from].size() - 1});

  roads.push_back(make_pair(from, G[from].size()-1));
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < G[v].size(); ++i) {
    Edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  for(;;) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main() {
  int tc = 0;
  while(cin >> N >> M && (N|M)) {
    init();
    for(int i = 0; i < M; ++i) {
      int a, b;
      cin >> a >> b;
      --a; --b;
      addEdge(a, b, 1);
    }
    int s, t;
    cin >> s >> t;
    --s; --t;
    int res = maxFlow(s, t);
    if(tc++) cout << endl;
    cout << res << endl;
    vector<int> v;
    for(int i = 0; i < roads.size(); ++i) {
      if(G[roads[i].first][roads[i].second].cap == 0) {
        v.push_back(i+1);
      }
    }
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); ++i) {
      cout << v[i] << endl;
    }
  }
  return 0;
}

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

int main() {
  int N , n ,f , A ;
  cin >> N;
  n = N;
  f = 0 ;
  for ( int i=8 ; i >= 0 ;i-- ){
    A = n/std::pow(10 , i) ;
    f += A ;
    n -= (A*std::pow(10 , i));
  }
 
  if( N % f == 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  priority_queue<int64_t> q;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    q.emplace(a);
  }
  while (!q.empty()) {
    const int64_t t = q.top();
    q.pop();
    const int64_t n = q.top();
    if (n == 0) {
      q.emplace(t);
      break;
    }
    q.emplace(t % n);
  }
  cout << q.top() << endl;
  return 0;
}


Measured memory_bytes: 4252
import Data.List

elsemax :: [Integer] -> [Integer]
elsemax [] = []
elsemax [a] = [a]
elsemax as = map (\x -> if x == bs!!0 then bs!!1 else bs!!0) as
    where bs = reverse $ sort as

main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getContents :: IO [Integer]
  mapM (putStrLn . show) $ elsemax as


Measured memory_bytes: 50428
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int next = 0;
    int pop = 0;
    bool judge = false;
    for (int i = 0; i < N; i++)
    {
        pop++;
        if (a[next] == 2)
        {
            judge = true;
            break;
        }
        else
        {
            next = a[next] - 1;
        }
    }
    if (judge)
    {
        cout << pop << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    cin>>N>>M;
    priority_queue<ll> Q;
    for(int i=0;i<N;i++) {
        ll tmp;
        cin>>tmp;
        Q.push(tmp);
    }
    
    for(int count=0;count<M;count++){
        ll a=Q.top();
        Q.pop();
        a/=2;
        Q.push(a);
    }
    
    ll ans=0;
    while(Q.size()>0){
        ans+=Q.top();
        Q.pop();
    }
    cout<<ans<<endl;
        
    return 0;
}


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

using namespace std;

typedef long long LL;
const LL MO=1e9+7;

LL qmi(LL a,LL b) {
    LL res=1;
    while(b) {
        if (b&1) {
            res=res*a%MO;
        }
        a=a*a%MO;
        b>>=1;
    }
    return res;
}

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

    if (1==n) {
        cout<<0<<'\n';
    } else if (2==n) {
        cout<<2<<'\n';
    } else {
        cout<<((qmi(10ll,n)-2*qmi(9ll,n)+qmi(8ll,n))%MO+MO)%MO<<'\n';
    }

    return 0;
}


Measured memory_bytes: 3632
N = int(input())
A = [int(input()) for i in range(N)]

A_sort = sorted(A)
A_max = A_sort[-1]
A_max2 = A_sort[-2]

for i in range(N):
    if A[i]==A_max:
        print(A_max2)
    else:
        print(A_max)

Measured memory_bytes: 90776
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    int n;
    ll c;
    cin >> n >> c;
    
    vector<ll> dist(n+1), value(n+1), vsum(n+1);
    REP(i, n){
        cin >> dist[i+1] >> value[i+1];
        vsum[i+1] = vsum[i] + value[i+1];
    }

    vector<pair<ll,ll>> cost(n+1);
    for(int i=1; i<=n; i++){
        cost[i].first = max(cost[i-1].first, vsum[i] - dist[i]);
    }
    for(int i=n; i>0; i--){
        cost[i].second = max(cost[(i+1)%(n+1)].second, vsum[n] - vsum[i-1] - (c - dist[i]));
    }

    ll ans = 0;
    
    for(int i=1; i<=n; i++){
        ans = max(ans, cost[i].first + max(0ll, -dist[i] + cost[(i+1)%(n+1)].second));
        ans = max(ans, cost[i].second + max(0ll, -(c - dist[i]) + cost[i-1].first));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

ll MOD = INF + 7;
ll dp[100100][2];

int main(){
    int n, k;
    cin >> n >> k;
    queue<P> que;
    if(k > (n - 1) * (n - 2) / 2)cout << -1 << endl;
    else {
        REP(i, 2, n){
            que.emplace(1, i);
        }
        int cnt = (n - 1) * (n - 2) / 2 - k;
      
        int now = 2;
        for(int i = 2; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
              if(cnt == 0)break;
                que.emplace(i, j);
                cnt--;
                if(cnt == 0)break;
            }
            if(cnt == 0)break;
        }
        cout << que.size() << endl;
    while(!que.empty()){
        cout << que.front().first << " " << que.front().second << endl;
        que.pop();
    }
    }
    
}


Measured memory_bytes: 384
using System;
using System.Linq;

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var ps = new int[h[1]].Select(_ => Read());

		var uf = new UF(n + 1);
		foreach (var p in ps)
			uf.Unite(p[0], p[1]);
		Console.WriteLine(uf.ToGroups().Length - 2);
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
	public int[][] ToGroups() => Enumerable.Range(0, p.Length).GroupBy(GetRoot).Select(g => g.ToArray()).ToArray();
}


Measured memory_bytes: 42964
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n, w;
  cin >> n >> w;
  ll w1;
  vector<vector<ll>> wv(4, vector<ll>());
  rep(i, n) {
    ll w, v;
    cin >> w >> v;
    if (i == 0) w1 = w;
    wv[w - w1].push_back(v);
  }

  rep(i, 4) sort(ALL(wv[i]), greater<ll>());

  vector<vector<ll>> sv(4, vector<ll>());  // 重さ w_i の物の価値を降順に並べたときの累積和
  rep(i, 4) {
    sv[i].resize(wv[i].size() + 1, 0);
    rep(j, wv[i].size()) {
      sv[i][j+1] = sv[i][j] + wv[i][j];
    }
  }

  ll ans = 0;

  for (int i = 0; i < wv[0].size() + 1; i++) {  // w1 を選ぶ数
    ll weight = w1 * i;
    if (weight > w) continue;
    ll value = sv[0][i];  // w0 を i 個選んだときの価値
    chmax(ans, value);
    for (int j = 0; j < wv[1].size() + 1; j++) {  // w2 を選ぶ数
      ll weight2 = weight + (w1 + 1) * j;
      if (weight2 > w) continue;  // 重量オーバー
      ll value2 = value + sv[1][j];
      chmax(ans, value2);
      for (int k = 0; k < wv[2].size() + 1; k++) {
        ll weight3 = weight2 + (w1 + 2) * k;
        if (weight3 > w) continue;
        ll value3 = value2 + sv[2][k];
        chmax(ans, value3);
        for (int l = 0; l < wv[3].size() + 1; l++) {
          ll weight4 = weight3 + (w1 + 3) * l;
          if (weight4 > w) continue;
          ll value4 = value3 + sv[3][l];
          chmax(ans, value4);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
let arr_of_str_i s = Array.init (String.length s) (fun i -> i, s.[i])
let () =
  let s = Scanf.scanf "%s" arr_of_str_i in
  let b = s
  |> Array.map (fun (i, c) -> Array.fold_left (fun b (j, d) -> b && (i = j || c <> d)) true s)
  |> Array.fold_left (&&) true in
  print_endline @@ if b then "yes" else "no"


Measured memory_bytes: 384
n,k,q = gets.chomp.split(" ").map(&:to_i)

a_arr = q.times.map{gets.to_i}

hash = {}
a_arr.each do |a|
  hash[a] ||= 0
  hash[a] += 1
end

(1..n).each do |i|
  if k - q + (hash[i] || 0) <= 0 then
    puts "No"
  else
    puts "Yes"
  end
end


Measured memory_bytes: 6908
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
int a,b,c,ans,N,M,tt;
char x[7];
int main(){
	scanf("%s",x);
	if(x[0]==x[1]||x[1]==x[2]||x[2]==x[3]) printf("Bad\n");
	else printf("Good\n");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, M, X, a[100]; cin >> N >> M >> X;
  int p = 0, q = 0;
  REP(i, M) {
    cin >> a[i];
    if(a[i] < X) p++;
    if(a[i] > X) q++;
  }
  cout << min(p, q) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

string s,t;

int dp[3100][3100] = {0};

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

    rep(i,(int)s.size()){
        rep(j,(int)t.size()){
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string res="";
    int i=(int)s.size(), j=(int)t.size();
    while(i>0&&j>0){

        if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else{
            res = s[i-1]+res;
            i--;
            j--;
        }
    }
    cout<<res<<endl;

}

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

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

int main(){
  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define all(x) x.begin(),x.end()
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long MOD=1e9+7;
const long long LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=300050;

ll a[MAXN];
struct Node
{	
	ll mx,lz_sum;
}tr[4*MAXN+10];
ll in[MAXN+10];
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
/*ll max(ll a,ll b)
{
	if(a>=b)return a;
	else return b;
}
ll min(ll a,ll b)
{
	if(a>=b)return b;
	else return a;
}*/
void build(int p,int l,int r)
{
	if(r==l)
	{
		tr[p].mx=in[l];
		tr[p].lz_sum=0;
		return;
	}
	build(p*2,l,(l+r)/2);
	build(p*2+1,(l+r)/2+1,r);
	tr[p].mx=max(tr[p*2].mx,tr[p*2+1].mx);
}
void change(ll val,int l,int r,int p,int lb,int rb)
{
	if(lb==l&&rb==r)
	{
		tr[p].mx=val;
		return;
	}
	int mid=(l+r)/2;
	if(lb<=mid)change(val,l,mid,p*2,lb,rb);
	if(rb>=mid+1)change(val,mid+1,r,p*2+1,lb,rb);
	tr[p].mx=max(tr[p*2].mx,tr[p*2+1].mx);
}
ll query_max(int p,int l,int r,int lb,int rb)
{
	if(lb<=l&&rb>=r)return tr[p].mx;
	int mid=(l+r)/2;
	ll temp=0;
	if(lb<=mid&&rb>mid)temp=max(query_max(p*2,l,mid,lb,rb),query_max(p*2+1,mid+1,r,lb,rb));
	else if(lb>mid)temp=query_max(p*2+1,mid+1,r,lb,rb);
	else if(rb<=mid)temp=query_max(p*2,l,mid,lb,rb);
	return temp;
}
void solve(int T){
	ll N,l,r,k;
	N=read();
	k=read();
	ll maxx=0;
	for(int i=1;i<=N;i++){
		a[i]=read();
		maxx=max(a[i],maxx);
	}
	build(1,0,N);
	ll tmp=0;
	for(int i=1;i<=N;i++){
		tmp=query_max(1,0,maxx,max(0ll,a[i]-k),a[i]+k);
		change(tmp+1,0,maxx,1,a[i],a[i]);
	}
	printf("%lld",query_max(1,1,N,1,N));
}	
signed main(){
	int t=1;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//scanf("%d",&t); 
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

Measured memory_bytes: 22500
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,he=0,i,j;
cin>>n;
string s[n],x;
int t[n];
for(i=0;i<n;i++)
{
	cin>>s[i];
	cin>>t[i];
}
cin>>x;
for(i=0;i<n;i++){
if(s[i]==x){
	for(j=i+1;j<n;j++)he=he+t[j];
	cout<<he;
	return 0; 
}
}

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	string s; cin >> s;
	vi ws(n,0), bs(n,0);
	if(s[0]=='.') ws[0]++; else bs[0]++;
	rep(i,n-1){
		ws[i+1] = ws[i];
		bs[i+1] = bs[i];
		if(s[i+1]=='.') ws[i+1]++; else bs[i+1]++;
	}
	int ans = INF;
	ans = min(ans,ws[n-1]);
	ans = min(ans,bs[n-1]);
	rep(i,n){
		int w = bs[i];
		int b = ws[n-1]-ws[i];
		ans = min(ans,w+b);
	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
    string str;cin >> str;
    str.erase(unique(str.begin(),str.end()),str.end());

    if((count(str.begin(),str.end(),'E')== 0) == (0 == count(str.begin(),str.end(),'W')) && (count(str.begin(),str.end(),'N')==0) == (0== count(str.begin(),str.end(),'S'))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

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

fastio _fast_io;

const int N = 2e5 + 5;
int a[N];
int n;
ll ans, sum, cur;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    ans = LLONG_MAX;
    for (int i = 0; i < n - 1; ++i) {
        cur += a[i];
        ans = min(ans, abs(sum - cur - cur));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	ll a, b, k;
	cin >> a >> b >> k;
	ll l = min(k, b-a);
	for(int i = 0; i < l; i++)cout << a+i << endl;
	for(int i = min(b-a-l, k-1); i+1; i--)cout << b-i << endl;
    return 0;
}

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


public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        HashSet<Integer> s = new HashSet<>();
        s.add(A);
        s.add(B);
        s.add(C);
        if(s.size()==2) out.println("Yes");
        else out.println("No");


        out.flush();
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
#include<cassert>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds; 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX
const int N=2e5+5;
const int M=1e9+7;
 
ll dp[N][3];
 
ll minim=-1ll*(1e17);
 
void solve(){
	int n;
	sfi(n)
 
	vector<ll> v(n);
 
	ll sum1=0,sum2=0;
 
	f(i,0,n){
		sfl(v[i])
 
		if(i&1)
			sum1+=v[i];
		else
			sum2+=v[i];
	}
 
	//cout<<sum1<<" "<<sum2<<endl;
 
	
 
	dp[0][0]=v[0];
	dp[0][1]=minim;
	dp[0][2]=minim;
 
	dp[1][0]=v[1];
	dp[1][1]=minim;
	dp[1][2]=minim;
 
	f(i,2,n){
		dp[i][0]=v[i]+dp[i-2][0];
 
		dp[i][1]=minim;
		dp[i][2]=minim;
 
		dp[i][1]=max(dp[i][1],v[i]+dp[i-2][1]);
		dp[i][2]=max(dp[i][2],v[i]+dp[i-2][2]);
 
		if(i==2){
			dp[i][1]=v[2];
			//continue;
		}
 
		for(int j=i-3;j>=max(i-4,0);j--){
 
			if(j==(i-3)){
				dp[i][1]=max(dp[i][1],v[i]+dp[j][0]);
			}
 
			if(j==i-4){
				if(i==26){
					//cout<<j<<" "<<dp[j][0]<<endl;
				}
				dp[i][2]=max(dp[i][2],v[i]+dp[j][0]);
			}
			else if(j==i-3){
				if(i==26){
					//cout<<j<<" "<<dp[j][1]<<endl;
				}
				dp[i][2]=max(dp[i][2],v[i]+dp[j][1]);
			}
		}
	}

	ll ans=-1ll*llinf;
 	
 	if(n%2==1){
 		ans=dp[n-1][2];
		ans=max(ans,dp[n-1][1]);
		ans=max(ans,dp[n-2][0]);
		ans=max(ans,dp[n-2][1]);
		ans=max(ans,dp[n-3][0]);
 	}
	
 	else{
 		ans=dp[n-1][1];
 		ans=max(dp[n-1][0],ans);
 		ans=max(dp[n-2][0],ans);
 	}

	f(i,0,n){

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

Measured memory_bytes: 9620
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define ld long double
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const ll maxn = 2e5 + 50 , N = 60000 + 20 , mod = 1e9 + 7 , INF = 1e9 + 1 , lg = 32;

int main() {
	FAST
	string s;
	cin >> s;
	int n = s.size();
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += (ll)(s[i] - '0');
	}
	if((sum % 9) == 0) {
		cout << "Yes" << '\n';
	}
	else {
		cout << "No" << '\n';
	}
}


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

using namespace std;

int main ()
{
	unsigned int N , K , X , Y ,a;
	cin >>N >> K >> X >> Y;
	if (K > N) {
		a = N * X ;
	}
	else a = K * X + (N - K) * Y;
	cout << a <<endl;
}

Measured memory_bytes: 256
import Control.Monad (replicateM)
import Data.Functor ((<$>))
import Data.List (transpose)

main :: IO ()
main = do
  [n, m, _] <- map read . words <$> getLine
  ma <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  mb <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  let mc = ma `matrixMult` mb
  putStr . unlines . map (unwords . map show) $ mc
  where ma `matrixMult` mb = [ [ sum (zipWith (*) va vb) | vb <- transpose mb ] | va <-  ma ]



Measured memory_bytes: 12212
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
// syakyou
using namespace std;

int main(int argc, char *argv[]){
  int N; cin>>N;
  int dp[100010];
  for(int i=0; i<100010; i++) dp[i]=N;
  dp[0]=0;
  for(int i=1; i<=N; i++){
    for(int pow6=1; pow6<=i; pow6*=6){
      dp[i]=min(dp[i],dp[i-pow6]+1);
    }
    for(int pow9=1; pow9<=i; pow9*=9){
      dp[i]=min(dp[i],dp[i-pow9]+1);
    }
  }
  cout<<dp[N]<<endl;
}
	
		
    


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,e;
  double ans;
  double t[110];
  while(1){
    ans = 1000000;
    cin >> d >> e;
    if(d==0 && e==0) break;
    for(int i=0; i<=d; i++){
      for(int j=0; j<=d; j++){
        if(i+j==d) t[i] = pow(i,2) + pow(j,2);
      }
    }
    for(int i=0; i<=d; i++){
      ans = min(abs(sqrt(t[i])-e),ans);
    }
    cout << ans << endl;
  }
 return 0;
}




Measured memory_bytes: 3240
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val h = readLine()!!.split(" ").map { it.toInt() }
    println(n - (1..m).map {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() - 1 }
        if (h[a] > h[b]) listOf(b) else if (h[a] < h[b]) listOf(a) else listOf(a, b)
    }.flatten().filter { it != -1 }.toSet().size)
}


Measured memory_bytes: 67712
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int l;
  cin>>l;
  int a[1000];
  rep(i,l) cin>>a[i];
  stack<int> cat;
  int flag[101]={0};
  rep(i,l){
    if(a[i]>0){
      if(flag[a[i]]==1){cout<<i+1<<endl;return 0;}
      cat.push(a[i]);
      flag[a[i]]=1;
    }else{
      if(cat.empty()){cout<<i+1<<endl;return 0;}
      if(cat.top()!=abs(a[i])){cout<<i+1<<endl;return 0;}
      cat.pop();
      flag[abs(a[i])]=0;
    }
  }
  cout<<"OK"<<endl;
  return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[200010], b[200010];
vector<int> vec[200010];
ll ans;

signed main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].push_back(b[i]);
		vec[b[i]].push_back(a[i]);
	}
	for (int i = 1; i <= n; i++)ans += (ll)i * (n - i + 1);
	for (int i = 1; i < n; i++) ans -= (ll)min(a[i], b[i])*(n - max(a[i], b[i]) + 1);
	cout << ans << endl;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
//	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	ll x, y;
	cin >> x >> y;
	int ans = 0;
	while (x <= y) {
	 	x *= 2;
	 	ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
int euclid(int a, int b)
{
	if (a < b)swap(a, b);
	if (b == 0)return a;
	else return euclid(b, a%b);
}
char hoge(int a)
{
	return 'a' + a;
}
bool check(string a)
{
	if (a.find("that", 0) != string::npos || a.find("this", 0) != string::npos)
	{
		return true;
	}
	return false;
}
int main()
{
	int n;
	cin >> n; cin.ignore();
	while (n--)
	{
		string str;
		bool ok = true;
		getline(cin, str);
		for (int a = 0; ok; a++)
		{
			if (euclid(a, 26) != 1)continue;
			for (int b = 0; ok&& b < 26; b++)
			{
				string ans = "";
				for (int i = 0; i < str.size(); i++)
				{
					if (str[i] == ' ') {
						ans += " "; continue;
					}
					for (int y = 0; y < 26; y++)
					{
						int num = (a*y + b) % 26;
						if (hoge(num) == str[i])
						{
							ans += hoge(y);
							break;
						}
					}
				}
				if (check(ans))
				{
					cout << ans << endl;
					ok = false;
				}
			}
		}
	}
}

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

long long N, A, B;
long long answer = 0;
long long total = 0;
long long total_div = 0;
int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin >> N >> A >> B;

	if (A != 0) {
		if (B == 0) {
			cout << N;
			return 0;
		}

		total = N / (A + B);
		total_div = N % (A + B);

		answer = total * A;
		if (total_div >= A) {
			answer += A;
		}
		else
			answer += total_div;
	}
	else {
		cout << 0;
		return 0;
	}

	cout << answer;
	return 0;
}

Measured memory_bytes: 256