akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

   int A,B,C,D;
   int[] num = {-1,1};

   public String toOp(int n){
       if (n == 1) {
           return "+";
       } else {
           return "-";
       }
   }

    private void solve() {
        char[] ch = next().toCharArray();
        A = ch[0]-'0';
        B = ch[1]-'0';
        C = ch[2]-'0';
        D = ch[3]-'0';

        for(int i = 0;i < 2;i++) {
            for(int j = 0;j < 2;j++) {
                for(int k = 0;k < 2;k++) {

                    int ans = A + B * num[i] + C * num[j] + D * num[k];

                    if (ans == 7) {
                        out.println(A + toOp(i) + B + toOp(j) + C + toOp(k) + D + "=7");
                        return;
                    }

                }
            }
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    rep(i, 0, n) {
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;

const long long mod = 1000000007;
long long inv[100] = { 0,1 }, ifact[100] = { 1,1 };

long long comb(int n, int k)
{
	if (n < 0 || k < 0 || n < k) return 0;
	long long r = ifact[k];
	for (int i = 0; i < k; i++) r = r * (n - i) % mod;
	return r;
}

long long geo(int n, int k)
{
	if (n < 0) return 0;
	return comb(n + k - 1, k - 1);
}

vector<long long> mul(vector<long long> a, vector<long long> b)
{
	vector<long long> c(a.size() + b.size() - 1);
	for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) c[i + j] = (c[i + j] + a[i] * b[j]) % mod;
	return c;
}

int main()
{
	for (int i = 2; i < 100; i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		ifact[i] = ifact[i - 1] * inv[i] % mod;
	}

	int Test; scanf ("%d", &Test); while (Test--){
		int u = 5, n; scanf ("%d", &n);
		long long ans = 0;
		for (int o = 0; o <= u; o++){
			int np = n + o; np /= 2;
			vector<long long> poly = { comb(u, o) };
			for (int i = 0; i < o; i++) poly = mul(poly, { 0, 1, 1 });
			for (int i = o; i < u; i++) poly = mul(poly, { 0, 2 });
			for (int i = 0; i < poly.size(); i++) ans = (ans + poly[i] * geo(np - i, 3 * u + 1)) % mod;
		}
		printf ("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3204
#include "bits/stdc++.h"
#include <math.h>
using namespace std;
int n;
int size;
vector<int>d(100010);
set<int>s;
vector<int>data(100010);
long long ans;
long long num = 998244353;//これで割る

void solve(){
    size = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> d.at(i);
        s.insert(d.at(i));//setに入れる
        if(s.size() != size){//進出の距離のとき
            data.at(d.at(i)) = 1;
            size++;
        }
        else{//既出の距離のとき
            data.at(d.at(i)) ++;
        }
    }//入力完了
    if(d.at(0) != 0 || data.at(0) != 1){
        ans = 0;
    }
    else {
        ans = 1;
        for(int i = 1; i < size; i++){//1から最大値まで
            for(int j = 0; j < data.at(i); j++){//1つ前の数の分だけかける
            ans *= data.at(i - 1);
            ans = ans % num;
            }
        }
    }
    cout << ans << endl;
}
int main(){
    solve();
    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int count[n+1] = {};
    for(int i = 0; i < m + m; i++){
        int a;
        cin >> a;
        count[a-1] += 1;
    }
    for(int i = 0; i < n; i++){
        cout << count[i] << endl;
    }
    return 0;
}



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

int main(void) {
	int P, Q, R;
	cin >> P >> Q >> R;

	int min = 300;
	if (P + Q < min)
		min = P + Q;

	if (Q + R < min)
		min = Q + R;

	if (R + P < min)
		min = R + P;

	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<functional>
#include<string.h>
#include<set>

const int MAXN = 1e5;
const int MAX_E = 5e5;
const long long INF = ((long long)1<<62) - 1;
struct Edge
{
	int vx;
	long long w;

	bool operator < (const Edge& e) {
		return w < e.w;
	}
};

struct NodeInfo {
	int vx;
	long long *d;

	bool operator < (const NodeInfo& node) {
		return (*d) < *(node.d);
	}
};

std::vector<Edge> graph[MAXN];
long long dist[MAXN];
int pre_vx[MAXN];
int visit[MAXN];
int V, E, r;

void init() {
	int n = V;
	while (n--) {
		dist[n] = INF;
	}
	memset(pre_vx, -1, sizeof(pre_vx));
	memset(visit, 0, sizeof(pre_vx));
}

void input() {
	scanf("%d%d%d", &V, &E, &r);
	for (int i = 0; i < E; i++) {
		int s, t, w;
		scanf("%d%d%d", &s, &t, &w);
		graph[s].push_back({ t, w });
	}
}

void dij_sp() {
	dist[r] = 0;
	std::set< std::pair<long long, int> > setds;
	setds.insert(std::make_pair(dist[r], r));
	while (!setds.empty()) {
		std::pair<long long, int> fir = *(setds.begin());
		setds.erase(setds.begin());
		//
		int u = fir.second;
		if (dist[u] == INF) { return; }
		for (std::vector<Edge>::iterator it = graph[u].begin(); it != graph[u].end(); it++) {
			int v = it->vx;
			if (visit[v]) { continue; }
			if (dist[v] > dist[u] + it->w) {
				if (dist[v] != INF) {
					setds.erase(setds.find(std::make_pair(dist[v], v)));
				}
				//update the set
				dist[v] = dist[u] + it->w;
				setds.insert(std::make_pair(dist[v], v));
			}
		}
		//mark visited
		visit[u] = 1;
	}
}

void output() {
	for (int i = 0; i < V; i++) {
		if (i == r) {
			printf("0\n");
		}
		else {
			if (dist[i] == INF) {
				printf("INF\n");
			}
			else {
				printf("%lld\n", dist[i]);
			}
		}
	}
}

/**
*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
*/
int main() {
	input();
	init();
	dij_sp();
	output();
	return 0;
}


Measured memory_bytes: 21072
#include <iostream>
#include <cstdlib>
#include <list>
using namespace std;
 
class POS{
 public:
	int x;
 	int y;
 	bool operator ==(POS p) {
 		return (this->x==p.x)&&(this->y==p.y);
 	}
 	POS(int ix, int iy) {
 		this->x = ix;
 		this->y = iy;
 	}
 	POS() {
 		POS(0,0);
 	}
 	POS operator +(POS p) {
 		POS a(this->x+p.x,this->y+p.y);
 		return a;
 	}
 	POS operator -(POS p) {
 		POS a(this->x-p.x,this->y-p.y);
 		return a;
 	}
 };
 
int main() {
  int N,i,j,k,l,cost,cost_min;
  POS *r;
  POS pq;
  POS zero;
  zero.x=0; zero.y=0;
  
  cin >> N;
  r = new POS[N];
  
  for(i=0;i<N;i++) {
  	cin >> r[i].x >> r[i].y;
  }
  
  cost_min = N;
  for(i=0;i<N-1;i++) {
  	for(j=i+1;j<N;j++) {
  		pq = r[i] - r[j];
  		cost = N;
  		for(k=0;k<N-1;k++) {
  			for(l=k+1;l<N;l++) {
  				if(r[l]-r[k]+pq==zero || r[l]-r[k]-pq==zero) cost--;
  			}
  		}
  		if(cost < cost_min) cost_min = cost;
  	}
  }
  
  cout << cost_min;
  
  return 0;
}

Measured memory_bytes: 256
arr = gets.chomp.split(' ').map(&:to_i)
ene = gets.chomp.split(' ').map(&:to_i)
if arr[0] <= arr[1]
  print 0
else
  ene.sort!
  i = 0
  sum = 0
  while i < arr[0] - arr[1] 
    sum += ene[i]
    i += 1
  end
  print sum
end

Measured memory_bytes: 31628
#include<bits/stdc++.h>
using namespace std;
#define pi pair<ll,ll>
#define fr freopen("in.txt","r",stdin)
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define f first
#define s second
#define maxn 200011

int F[1111][20];
int P[1111][20];
ll c[1111];
int main() {
    int N;
    cin >> N;
    rep(i,N) {
        rep(j,10) {
            cin >> F[i][j];
        }
    }
    rep(i,N) {
        rep(j,11) {
            cin >> P[i][j];
        }
    }
    ll ans = INT_MIN;
    rep(mask,(1<<10)) {
        if(mask==0) continue;
        rep(j,N) {
            c[j] = 0;
        }
        
        
        rep(i,10) {
            if(mask&(1<<i)) {
                rep(j,N) {
                    if(F[j][i]) c[j]++;
                }
            }
        }
        ll cur = 0;
        rep(j,N) {
            cur += P[j][c[j]];
        }
        ans = max(ans, cur);
    }
    cout << ans << "\n";
}

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

using int64 = long long;

int main() {
    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<int> nextUnZero(N);
    int unzero_i = N;
    for (int i = N - 1; i >= 0; i--) {
        nextUnZero[i] = unzero_i;
        if (A[i] > 0) unzero_i = i;
    }

    int64 ans = 0;
    for (int l = 0; l < N; l++) {
        int sum  = A[l],
            exor = A[l],
            r    = l;
        // 一致してたら進めたい
        while (sum == exor and r < N) {
            r = nextUnZero[r];
            if (r < N) {
                sum  += A[r];
                exor ^= A[r];
            }
        }
        ans += r - l;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
N, A, B = map(int, input().split())
S = input()
#A = list(map(lambda x: int(x)*(-1), input().split()))
#A = [int(input()) for i in range(N)]
#C = [list(map(int, input().split())) for i in range()]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a 
ab = A+B
b = B
for s in S:
    if s == 'a' and ab > 0:
        print('Yes')
        ab -= 1
    elif s == 'b' and ab > 0 and b > 0:
        print('Yes')
        ab -= 1
        b -= 1
    else:
        print('No')



Measured memory_bytes: 4016
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


h,w = gi
m = []
rep h do
  m << gc
end
s = '#'
ans = darray h,w, 0
rep h do |i|
  rep w do |j|
    if m[i][j] == s
      ans[i][j] = s
      next
    end

    des = [1,2,3,4,5,6,7,8]

    if i == 0
      des.delete 1
      des.delete 2
      des.delete 3
    end

    if i == h-1
      des.delete 5
      des.delete 6
      des.delete 7
    end

    if j == 0
      des.delete 1
      des.delete 7
      des.delete 8
    end

    if j == w-1
      des.delete 3
      des.delete 4
      des.delete 5
    end

    des.each do |k|
      case k
      when 1
    ans[i][j] += 1 if m[i-1][j-1] == s
      when 2
    ans[i][j] += 1 if m[i-1][j] == s
      when 3
    ans[i][j] += 1 if m[i-1][j+1] == s
      when 4
    ans[i][j] += 1 if m[i][j+1] == s
      when 5
    ans[i][j] += 1 if m[i+1][j+1] == s
      when 6
    ans[i][j] += 1 if m[i+1][j] == s
      when 7
    ans[i][j] += 1 if m[i+1][j-1] == s
      when 8
    ans[i][j] += 1 if m[i][j-1] == s
      end
    end
  end
end
ans.each do |a|
 puts a.join
end


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

int main(){
  int a,b;
  cin>>a>>b;
  if(a*2>b||b>a*4){
      cout<<"No"<<endl;
      return 0;
  }
  if(b%2==0){
      cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
 

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#define roop(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;

signed main() {
	int a, b, c, d, e[100], f[100],out;
	cin >> a >> b >> c >> d;
	roop(i, a)cin >> e[i];
	roop(i, b)cin >> f[i];
	sort(e,e+a);
	sort(f,f+b);
	out = e[a-1]+1;
	if (out <= f[0]&&out<=d&&out>c) {
		cout << "No War" << endl;
	}
	else cout << "War" << endl;
}


Measured memory_bytes: 256
from sys import stdin
#from collections import deque
#from math import ceil


def ii(): return int(stdin.readline())


def fi(): return float(stdin.readline())


def mi(): return map(int, stdin.readline().split())


def fmi(): return map(float, stdin.readline().split())


def li(): return list(mi())


def lsi():
    x=list(stdin.readline())
    x.pop()
    return x


def si(): return stdin.readline()


def sieve(x):
    a=[True]*(x+1)
    sq=floor(sqrt(x))
    for i in range(3, sq+1, 2):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]=False
    if x>1:
        p=[2]
    else:
        p=[]
    for i in range(3, x+1, 2):
        if a[i]:
            p.append(i)
    return p
#vowel={'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}
pow=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808]
############# CODE STARTS HERE #############
n=ii()
p=0
for i in pow:
    if i>n:
        break
    p+=i
print(p)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	int M;
	cin >> M;
	vector<int> P(M);
	vector<int> X(M);
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
	}
	int time = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			time += T[j];
		}
		time = time + X[i] - T[P[i] - 1];
		cout << time << endl;
		time = 0;
	}

	return 0;
}

Measured memory_bytes: 3644
class Mint
  MOD = 1_000_000_007

  attr_reader :x

  def initialize(x)
    @x = ((x % MOD) + MOD) % MOD
  end

  def to_s
    @x.to_s
  end

  def -@
    Mint.new(-@x)
  end

  def +(a)
    Mint.new(@x).add(a)
  end

  def -(a)
    Mint.new(@x).sub(a)
  end

  def *(a)
    Mint.new(@x).mul(a)
  end

  def /(a)
    Mint.new(@x).div(a)
  end

  def add(a)
    @x += a.x
    @x -= MOD if @x >= MOD
    self
  end

  def sub(a)
    @x += MOD - a.x
    @x -= MOD if @x >= MOD
    self
  end

  def mul(a)
    @x = (@x * a.x) % MOD
    self
  end

  def pow(t)
    return Mint.new(1) if t.zero?
    a = pow(t >> 1)
    a = a.mul(a)
    a = a.mul(self) if (t % 2) == 1
    a
  end

  def inv
    pow(MOD - 2)
  end

  def div(a)
    self.mul(a.inv)
  end

  def factorial
    return Mint.new(1) if @x.zero?
    (1..@x).map{|v| Mint.new(v)}.inject(:mul)
  end

  def permutation(k)
    return Mint.new(1) if k.zero?
    (@x - k + 1..@x).map{|v| Mint.new(v)}.inject(:mul)
  end

  def combination(k)
    permutation(k).div(Mint.new(k).factorial)
  end
end

N, A, B = gets.chomp.split(" ").map(&:to_i)
a = [A, N-A].min
b = [B, N-B].min
n = Mint.new(N)

puts Mint.new(2).pow(N) - n.combination(a) - n.combination(b) - Mint.new(1)


Measured memory_bytes: 41468
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
   
    int N;
    vector<int> a;
    
    cin >> N;
    int tempInt;
    for(int i = 0; i < N; i++){
        cin >> tempInt;
        a.push_back(tempInt);
    }
    sort(a.rbegin(), a.rend());
    int alice, bob;
    alice = bob = 0;
    
    for(int i = 0; i < N; i++){
        if(i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }
    
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

long long int f(long long int mid, long long int a, long long int b){
	long long int p = a * mid;
	int d = 1;
	while (mid / 10)
	{
		d++;
		mid /= 10;
	}
	p += b * d;
	return p;
}

//深さ優先探索のテンプレ.デフォルトでは参照渡ししたsetに探索済みの頂点が格納される.
//graphは隣接リスト.vは探索開始地点.seenは空のセット
void dfs(vector<vector<pair<int, int>>> &graph, vector<int> &ans, int v, int c = -1, int p = -1)
{
	int k = 1;
	for (int i = 0; i < graph[v].size(); i++)
	{
		int nxt = graph[v][i].first;
		int ei = graph[v][i].second;
		if (nxt == p) continue;
		if (k == c)
			k++;
		ans[ei] = k;
		dfs(graph, ans, nxt, k, v);
		k++;
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	reverse(all(s));
	vector<int> ans;
	int now = 0;
	while(now != n)
	{
		int step = min(m,n-now);
		while(s[now+step] == '1')
			step--;
		if(step == 0){
			cout << -1 << endl;
			return 0;
		}
		ans.push_back(step);
		now += step;
	}
	reverse(all(ans));
	print(ans);

	return 0;
}

Measured memory_bytes: 1528
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N;
int S[606][606];

bool sym(int R, int C) {
  for (int r = 0; r < N; ++r) {
    for (int c = 0; c < N; ++c) {
      if (S[R + r][C + c] != S[R + c][C + r]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  N = in();
  for (int i = 0; i < N; ++i) {
    char buf[303];
    scanf("%s", buf);
    for (int j = 0; j < N; ++j) {
      S[i][j] = S[N + i][j] = S[i][N + j] = S[N + i][N + j] = buf[j] - 'a';
    }
  }

  int res = sym(0, 0) ? -N : 0;
  for (int r = 0; r < N; ++r) {
    res += sym(r, 0) ? (N - r) : 0;
  }
  for (int c = 0; c < N; ++c) {
    res += sym(0, c) ? (N - c) : 0;
  }

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

  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n;
signed main() {
	cin >> n;
	if (n == 1) {
		cout << "Yes" << endl;
		cout << 2 << endl << 1 << " " << 1 << endl << 1 << " " << 1 << endl;
		endre;
	}
	else {
		for (int i = 0; i < n; i++) {
			if (i*(i + 1) / 2 == n) {
				cout << "Yes" << endl;
				cout << i + 1 << endl;
				for (int j = 0; j < i; j++) {
					if (!j) {
						cout << i;
						int ans = 1;
						for (int k = 1; k <= i; k++) {
							cout << " " << ans;
							ans += k;
						}
						cout << endl;
						ans = 1;
						cout << i;
						for (int k = 1; k <= i; k++) {
							ans += k;
							cout << " " << ans - 1;
						}
						cout << endl;

					}
					else {
						int ans = j * (j + 1) / 2 + 1;
						cout << i;
						for (int k = 0; k < j + 1; k++) {
							cout << " " << ans;
							ans++;
						}
						ans--;
						for (int k = j + 1; k < i; k++) {
							ans += k;
							cout << " " << ans;
						}
						cout << endl;

					}
				}
				endre;
			}
		}
	}
	cout << "No" << endl;
	endre;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
using namespace std;
int main() {
	int n;
	int ans = 0;
	string s, t;
	cin >> n;
	cin >> s >> t;
	for (int j = 1; j <= n; j++) {
		if (s.substr(n - j, j) == t.substr(0, j)) {
			ans = j;
		}
	}
	ans = n - ans;
	int ans1 = s.size();
	ans += ans1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		out.println((N-1)*(M-1));
		out.flush();	
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int X,T,N,ans;
cin >> N >> X >> T;
  
if (N < X || N == X){
 ans = T;
}else if (N % X ==0){
ans = (N / X ) * T; 
}else{
 ans = (N / X + 1) * T;  
}  
cout << ans << endl;  
}

Measured memory_bytes: 3632
package main

import (
  "fmt"
  "sort"
)

type runeSlice []rune
func (p runeSlice) Len() int           { return len(p) }
func (p runeSlice) Less(i, j int) bool { return p[i] < p[j] }
func (p runeSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func sortedString(s string) string {
  runes := runeSlice([]rune(s))
  sort.Sort(runes)
  return string(runes)
}

func main() {
  var s string; fmt.Scan(&s)
  ans := "No"
  if sortedString(s) == "abc" {ans = "Yes"}
  fmt.Println(ans)
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    while(1){
        int maxiNum=999999,maxi=-1;
        rep(i,5){
            int a,b;
            cin>>a>>b;
            if(i==0 && a==0 && b==0)goto end;
            
            if(a+b>maxi){
                maxiNum=i;
                maxi=a+b;
            }
            
        }
        char num[]={'A','B','C','D','E'};
        cout<<num[maxiNum]<<" "<<maxi<<endl;
    }
end:;

    return 0;
}

Measured memory_bytes: 1156
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = 100001, D = 9;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     int n = 1;

//     while (tc--)
//     {
    	
//     	int n = rand()%N + 1, m = rand()%N + 1;

//     	int a[n][m];
//     	for(int i=0;i<n;i++)
//     	{
//     		for(int j=0;j<m;j++)
//     		{
//     			int flag = rand()%4;
//     			if(flag==0)
//     				a[i][j] = -1;
//     			else
//     				a[i][j] = rand()%MAXI;
//     		}
//     	}

//     	a[n-1][0] = rand()%MAXI;

//     	cout << n << " " << m << "\n";
//     	for(int i=0;i<n;i++){
//     		for(int j=0;j<m;j++)
//     			cout << a[i][j] << " ";
//     		cout << "\n";
//     	}

//     	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
//  int n, a[N];

// int MEM(int ind, vector<int> &v)
// {
// 	if(ind==n)
// 	{
// 		// o(n)
// 	}

// 	int ans = 0;
// 	if(a[ind]==-1)
// 	{
// 		for(int i=0;i<n;i++)
// 		{
// 			if(i!=ind)
// 			{
// 				v[ind] = i;
// 				ans += MEM(ind+1, v);
// 				if(ans>=mod)
// 					ans %= mod;
// 			}
// 		}
// 	}
// 	else
// 		ans = MEM(ind+1, v);

// 	return ans;

// }
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 

//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(3e17+10)
#define N 1005




// Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	cout.tie(NULL);

	
	int n, ans = 0;
	cin >> n;

	for(int i=2;i*i<=n;i++)
	{
		int c = 0;

		while(n%i==0)
		{
			c++;
			n/=i;
		}

		int k = 1;
		while(c>=k)
		{
			ans++;
			c-=k;
			k++;
		}
	}

	if(n>1)
		ans++;

	cout << ans;
	
    return 0;
 
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    vector<int> start(26,-1);
    vector<int> goal(26,-1);
    rep(i,n) {
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if (start[a] != -1 || goal[b] != -1) {
            if (start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        goal[b] = a;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int count_digit(int N, int K, int count){
    int d = N/K;
    int q = N%K;
    count ++;

    if (d==0) return count;
    return count_digit(d, K, count);

}


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

    int N, K, count = 0;
    cin >> N >> K;

    cout << count_digit(N, K, 0) << endl;    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void dsolve(){
    ll x;
    cin >> x;
    ll a,b;
    for(ll i=1;i<=2000;i++){
        for(ll j=-2000;j<2000;j++){
            ll score=pow(i,5)-pow(j,5);
            if(score==x){
                a=i;
                b=j;
                break;
            }
        }
    }
    cout << a <<" "<< b<< endl;
}

void bsolve(){
    ll n,k;
    cin >> n >>k;
    ll w[n];
    rep(i,n) w[i]=0;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin >>a;
            a--;
            w[a]++;
        }
    }
    ll ans=0;
    rep(i,n){
        if(w[i]==0){
            ans++;
            //kaku(i);
        }
    }
    kaku(ans);
}

void asolve(){
    string s;
    cin >>s;
    if(s=="ABC"){
        cout <<"ARC" << endl;
    }
    else{
        cout <<"ABC" << endl;
    }
}

void csolve(){
    ll n,m;
    cin >> n >>m;
    ll h[n];
    rep(i,n) cin >> h[i];
    vector<ll> g[n];
    Pair ma[n];
    rep(i,n) ma[i]=make(h[i],1);
    rep(i,m){
        ll a,b;
        cin >>a >>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
        if(ma[a].first<h[b]) ma[a]=make(h[b],1);
        else if(ma[a].first==h[b]) ma[a]=make(h[b],0);
        if(ma[b].first<h[a]) ma[b]=make(h[a],1);
        else if(ma[b].first==h[a]) ma[b]=make(h[a],0);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(ma[i].first==h[i]&& ma[i].second==1) ans++;
    }
    kaku(ans);
}
int main() {
   bsolve();
}






Measured memory_bytes: 3724
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    char C; cin >> C;
    cout << (char)(C+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, N,a=0,w=0,t=0,r=0;
  char S[4];
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",S);
	if(S[0]=='A') a++;
	if(S[0]=='W') w++;
	if(S[0]=='T') t++;
	if(S[0]=='R') r++;
  }
  printf("AC x %d\n",a);
  printf("WA x %d\n",w);
  printf("TLE x %d\n",t);
  printf("RE x %d\n",r);
  
  return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int test; cin >> test;
	long double ara[test];
	long double sum = 1;
	for (int i = 0; i < test; ++i)
	{
		cin >> ara[i];
		if (ara[i] == 0)
		{
			cout << "0" << endl;
			return 0;
		}
	}
	int i = 0;
	while ( sum <= 1000000000000000000)
	{
		sum = sum * ara[i];
		if (i < test)
		{
			i++;
		}
		if (i == test)
		{
			if (sum <= 1000000000000000000)
			{
				printf("%.0Lf\n", sum);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

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

typedef long long ll;

char table[] = {'M', 'A', 'R', 'C', 'H'};

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    unordered_map<char, ll> mp;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        switch (s[0]) {
        case 'M': case 'A': case 'R': case 'C': case 'H':
            mp[s[0]]++;
            break;
        default:
            break;
        }
    }
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += mp[table[i]] * mp[table[j]] * mp[table[k]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int n;
ll t, mem;
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}
int main(){
	cin >> n;
	cin >> t;
	lp(n - 1) {
		cin >> mem;
		t = lcm(t, mem);
	}
	cout << t << endl;
	return 0;
}

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

int main() {
	int num, tmp, sum = 0;
	cin >> num;
	tmp = num;
	while(tmp > 0) {
		sum += tmp % 10;
		tmp /= 10;
	}

	if(num % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

bool rec(vector<vector<pair<int,int>>>&e,vector<array<ll,2>>&v,vector<array<bool,2>>&vis,int i=0,bool f=0){
    for(auto&p:e[i]){
        ll a=p.second-v[i][f];
        if(vis[p.first][!f]){
            if(v[p.first][!f]!=a) return true;
        }
        else{
            vis[p.first][!f]=true;
            v[p.first][!f]=a;
            if(rec(e,v,vis,p.first,!f)) return true;
        }
    }
    return false;
}

class EGraph {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,m,a,b,s;
        in>>n>>m;
        vector<vector<pair<int,int>>> e(n);
        fr(i,m){
            in>>a>>b>>s;--a,--b;
            e[a].emplace_back(b,s);
            e[b].emplace_back(a,s);
        }
        vector<array<ll,2>> v(n);
        vector<array<bool,2>> vis(n);
        vis[0][0]=true;
        v[0][0]=0;
        if(rec(e,v,vis)){
            out<<0<<endl;
            return;
        }
        if(vis[0][1]){
            if(v[0][1]&1){
                out<<0<<endl;
                return;
            }
            fr(i,n){
                ll A=v[0][1]/2;
                fr(j,n){
                    if(A+v[j][0]<=0||A+v[j][0]!=v[j][1]-A){
                        out<<0<<endl;
                        return;
                    }
                }
                out<<1<<endl;
                return;

            }
        }
        ll p=LLONG_MAX,q=LLONG_MAX;
        fr(i,n){
            if(vis[i][0]) p=min(p,v[i][0]);
            else q=min(q,v[i][1]);
        }
        out<<max(0ll,p+q-1)<<endl;
    }
};

int main() {
    EGraph solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main() {
  int n,k; cin >> n >> k;
  vector<int> vec(n);
  int count =0;
  
  for(int i=0; i < n; i++){
    int x; cin >> x ;
    vec.at(i) = x;
  }
  
  for(int i=0; i < n; i++){
    if(vec.at(i) >= k){
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int N;
  scanf("%d", &N);
  if(N >= 105){
     if(N >= 135){
       if(N >= 165){
         if(N >= 189){
           if(N >= 195){
             printf("5\n");
           }
           else{
             printf("4\n");
           }
         }
         else{
           printf("3\n");
         }
       }
       else{
         printf("2\n");
       }
     }
     else{
       printf("1\n");
     }
   }
  else{
    printf("0\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long dp[100],n;
int main()
{
    cin>>n;
    dp[1]=6;
    for(int i=2;i<=n;i++)
        dp[i]=2*dp[i-1]+2;
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())

S=[]
for i in range(1,N+1):
    tmp=list(map(int,str(i)))
    S.append(sum(tmp))

Ans=0
for i in range(N):
    if S[i] >= A and S[i]<=B:
        Ans+=i+1
print(Ans)

Measured memory_bytes: 3188
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;

int dig(int n){
    int sum = 0;
    while(n){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(){
        _
        int n,a,b; cin >> n >> a >> b;
        ll sum =0;
        for(int i = 1; i<=n; i++){
            if(dig(i)<=b and dig(i)>=a)sum+=i;
        }
        cout<<sum<<endl;


return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define MAX 100
#define INF (1<<30)

using namespace std;
enum state{
  BLACK,
  WHITE
};

int main(){
  vector<int> v[MAX];
  vector<int> c[MAX];
  state s[MAX];
  int d[MAX];
  int n; cin>>n;

  for(int i=0;i<n;i++){
    int u; cin>>u;
    int k; cin>>k;
    for(int j=0;j<k;j++){
      int tmp,tmp2; cin>>tmp>>tmp2;
      v[u].push_back(tmp);
      c[u].push_back(tmp2);
    }
  }

  for(int i=0;i<n;i++){
    s[i] = WHITE;
    d[i] = INF;
  }
  s[0]=BLACK;
  d[0]=0;

  vector<int> blacklist;
  blacklist.push_back(0);

  while(1){
    int& last = blacklist.back();
    for(int i = 0;i<v[last].size();i++){
      if(d[v[last][i]]>d[last]+c[last][i]){
        d[v[last][i]]=d[last]+c[last][i];
      }
    }

    int minv=-1;
    int mind=INF;
    for(int b:blacklist){
      for(int i=0;i<v[b].size();i++){
        if(s[v[b][i]]!=BLACK && d[v[b][i]]<mind){
          minv=v[b][i];
          mind=d[v[b][i]];
        }
      }
    }
    if(minv!=-1){
      s[minv]=BLACK;
      blacklist.push_back(minv);
    }else{
      break;
    }
  }

  for(int i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}

Measured memory_bytes: 3208
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,a[100000],cnt=0,ans=0,b=1000000000;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(a[i]<0) {
      a[i]=abs(a[i]);
      cnt++;
    }
    b=min(b,a[i]);
    ans+=a[i];
  }
  if(cnt%2==1) {
    ans-=b*2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

const int MAX = 210000;
int N, M;
int num[MAX];
bool can[MAX];

int main() {
    while (cin >> N >> M) {
        memset(num, 0, sizeof(num));
        memset(can, 0, sizeof(can));
        for (int i = 0; i < N; ++i) num[i] = 1;
        can[0] = true;
        for (int i = 0; i < M; ++i) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            
            if (can[a]) {
                if (num[a] == 1) {
                    can[a] = false;
                    can[b] = true;
                }
                else if (num[a] >= 2) {
                    can[b] = true;
                }
            }
            --num[a];
            ++num[b];
            
            //for (int i = 0; i < N; ++i) cout << num[i] << ", ";
            //for (int i = 0; i < N; ++i) cout << can[i] << ", ";
            //cout << endl << endl;
        }
        
        int res = 0;
        for (int i = 0; i < N; ++i) if (can[i]) ++res;
        cout << res << endl;
    }
}



















Measured memory_bytes: 1280
#include<stdio.h>

int bubbleSort(int A[], int N){
	int temp = 0;
	int times = 0;
	int btimes = -1;
	int i = 0;
	while( times > btimes ){
		btimes = times;
		for( i = N-1; i > 0; i-- ){
			if( A[i] < A[i-1] ){
				temp = A[i];
				A[i] = A[i-1];
				A[i-1] = temp;
				times++;
			}
		}
	}
	return times;
}



int main(){
	int N = 0;;
	int A[1000];
	int i = 0;
	int re = 0;
	scanf("%d", &N);
	for( i = 0; i < N; i++ ){ scanf("%d", &A[i]); }
	re = bubbleSort(A, N);
	printf("%d", A[0]);
	for( i = 1; i < N; i++ ){
		printf(" %d", A[i]);
	}
	printf("\n");
	printf("%d\n", re);
	return 0;
}

Measured memory_bytes: 608
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var H = ReadArrayInt();
            var chk = H[0];
            for (int i = 1; i < N; i++)
            {
                if (H[i] > chk) chk = H[i] - 1;
                else if (H[i] < chk)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 32220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define ll int64_t
using namespace std;

ll colar(ll n,ll k){
    if(n==1) return k;
    else return k*(ll)pow((k-1),(n-1));
}

int main(){
    ll n,k;
    cin>>n>>k;
    cout<<colar(n,k)<<endl;
    return 0;
}



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

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

int dx[4],dy[4];
int t[4][4];

int solve(int rem){
	int i;
	int x,y,nx,ny;
	int res = 0;

	if(rem == 0) return 1;

	rep(y,4) rep(x,4){
		if(t[y][x]) continue;
		t[y][x] = 1;

		rep(i,4){
			nx = x + dx[i];
			ny = y + dy[i];
			if(nx>=0 && nx<4 && ny>=0 && ny<4 && !t[ny][nx]){
				t[ny][nx] = 1;
				res += solve(rem-1);
				t[ny][nx] = 0;
			}
		}

		t[y][x] = 0;

		if(res > 0) return res;
	}

	return 0;
}

int main(void){
	int i;

	while(1){
		for(i=0;i<4;i++) if(scanf("%d%d",&dx[i],&dy[i]) != 2) return 0;
		memset(t,0,sizeof(t));
		printf("%d\n",solve(8));
	}
}

Measured memory_bytes: 0
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter
def main():
    n, k = map(int, input().split())
    p = []
    for _ in range(k):
        d = int(input()) 
        a = [int(i) for i in input().split()]
        for i in a:
            p.append(i)   
    dd = Counter(p)    
    cnt = 0
    for i in range(1, n+1):
        if dd[i] == 0:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9468
n = gets.to_i
S = gets.split.map(&:to_i)

$inf = 1.0 / 0.0
$count = 0

def merge_sort(arr)
  left = arr[0..(arr.length / 2 - 1)]
  right = arr[(arr.length / 2)..(arr.length - 1)]
  left = merge_sort(left) unless left.length <= 1
  right = merge_sort(right) unless right.length <= 1
  left.push($inf)
  right.push($inf)
  res = []
  l, r = 0, 0
  while !(l == left.length || r == right.length)
    $count += 1
    if left[l] < right[r]
      res.push(left[l])
      l += 1
    else
      res.push(right[r])
      r += 1
    end
  end
  $count -= 1
  res.pop
  return res
end

puts merge_sort(S).join(' ')
puts $count



Measured memory_bytes: 69736