akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public class Edge {
			long cost;
			Node connectsTo;

			public Edge(long cost, Node connectsTo) {
				this.cost = cost;
				this.connectsTo = connectsTo;
			}
		}

		public class Node {
			public ArrayList<Edge> edges = new ArrayList<>();
			public long minDistansFromK = Long.MAX_VALUE;
			public boolean marked = false;
		}

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			Node[] nodes = new Node[n];
			for (int i = 0; i < n; i++) {
				nodes[i] = new Node();
			}
			for (int i = 1; i < n; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				int c = in.nextInt();
				nodes[a].edges.add(new Edge(c, nodes[b]));
				nodes[b].edges.add(new Edge(c, nodes[a]));
			}
			int nubmerQuery = in.nextInt();
			int k = in.nextInt() - 1;
			Queue<Node> q = new LinkedList<>();
			q.add(nodes[k]);
			nodes[k].marked = true;
			nodes[k].minDistansFromK = 0;
			while (!q.isEmpty()) {
				Node currentNode = q.poll();
				for (Edge e : currentNode.edges) {
					if (!e.connectsTo.marked) {
						q.add(e.connectsTo);
						e.connectsTo.marked = true;
						e.connectsTo.minDistansFromK = currentNode.minDistansFromK + e.cost;
					}
				}
			}
			for (int i = 0; i < nubmerQuery; i++) {
				int x = in.nextInt() - 1;
				int y = in.nextInt() - 1;
				out.println(nodes[x].minDistansFromK + nodes[y].minDistansFromK);
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

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

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

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

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

	}
}

Measured memory_bytes: 78148
<?php
fscanf(STDIN, "%d %d %d", $A, $B, $K);
$cnt = 0;
for ($i = min($A, $B); $i > 0; $i--) {
    if ($A % $i === 0 && $B % $i === 0) {
        $cnt++;
        if ($cnt === intval($K)) {
            echo $i;
        }
    }
}


Measured memory_bytes: 4856
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int ans = 1;
		int now = 1;
		
		for(int i = 0; i < n; i++) {
			if(sc.nextInt() == 1) now++;
			else {
				ans = Math.max(ans, now);
				now = 1;
			}
		}
		ans = Math.max(ans,now);
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 26332
A={io.read(1),io.read(1),io.read(1),io.read(1)}

for bit=0,8,1 do
  a=A[1]
  for i=0,2,1 do
    if (bit>>i)&1==1 then a=a-A[i+2] else a=a+A[i+2] end
  end
  if math.floor(a)==7 then
    ans=A[1]
    for i=0,2,1 do
      if (bit>>i)&1==1 then ans=ans.."-"..A[i+2] else ans=ans.."+"..A[i+2] end
    end
    print(ans.."=7")
    break
  end
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

// 根が1
template<typename Monoid>
struct segtree {
    using T = typename Monoid::T;
    int n;
    vector<T> dat;

    segtree(int n_) {
        n = 1;
        while(n < n_) n <<= 1;
        dat.assign(n*2, Monoid::id());
    }
    void build(vector<T> v) {
        REP(i, v.size()) dat[i+n] = v[i];
        for(int i=n-1; i>0; --i) dat[i] = Monoid::op(dat[i*2], dat[i*2+1]);
    }

    T query(int a, int b) {
        if(a >= b) return Monoid::id();
        T l = Monoid::id(), r = Monoid::id();
        for(a+=n, b+=n; a<b; a>>=1, b>>=1) {
            if(a&1) l = Monoid::op(l, dat[a++]);
            if(b&1) r = Monoid::op(dat[--b], r);
        }
        return Monoid::op(l, r);
    }
    void update(int i, T v) {
        i += n;
        dat[i] = v;
        while(i >>= 1) {
            dat[i] = Monoid::op(dat[i*2], dat[i*2+1]);
        }
    }

    friend ostream &operator <<(ostream& out,const segtree<Monoid>& seg){
        out << "---------------------" << endl;
        int cnt = 1;
        for(int i=1; i<=seg.n; i*=2) {
            REP(j, i) {
                out << seg.dat[cnt] << " ";
                cnt++;
            }
            out << endl;
        }
        out << "---------------------" << endl;
        return out;
    }
};

template<typename Tp>
struct minmax_monoid {
    using T = Tp;
    static constexpr Tp id() { return {INF, -INF}; }
    static Tp op(const Tp &a, const Tp &b) { 
        return PII{min(a.first, b.first), max(a.second, b.second)}; 
    }
};

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    segtree<minmax_monoid<PII>> seg(n);
    vector<PII> init(n);
    REP(i, n) init[i] = PII(a[i], a[i]);
    seg.build(init);

    ll last = 0;
    vector<ll> sorted(n);
    FOR(i, 1, n) {
        if(a[i] < a[i-1]) {
            FOR(j, last, i-k+1) sorted[j] = 1;
            last = i;
        }
    }
    FOR(i, last, n-k+1) sorted[i] = 1;
    vector<ll> rui(sorted);
    FOR(i, 1, n) rui[i] += rui[i-1];
    dump(sorted);

    ll type = 0;
    REP(i, n-k+1) {   
        bool cond1 = i>=0 && a[i-1] == seg.query(i-1, i+k-1).first && a[i+k-1] == seg.query(i, i+k).second;
        bool cond2 = i>=k-1 && sorted[i] && rui[i-k+1];
        if(!cond1 && !cond2) type++;
    }

    cout << type << endl;

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> vc(n);
	vector<int> sortvc(n);
	for (int i=0;i<n;i++){
		cin >> vc.at(i);
		sortvc.at(i) = vc.at(i);
	}
	sort(sortvc.begin(), sortvc.end());
	for (int i=0;i<n;i++){
		if (vc.at(i)==sortvc.at(n-1)){
			cout << sortvc.at(n-2) << endl;
		}
		else{
			cout << sortvc.at(n-1) << endl;
		}
	}
}

Measured memory_bytes: 3200
/*input
7 11
1 2 2
1 3 1
2 4 2
2 5 2
2 6 1
3 4 1
3 5 1
3 6 1
4 7 2
5 7 2
6 7 1
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 1505
#define bit(x,y) ((x>>y)&1LL)

int n, m;
vector<vector<pair<int, int> > > a(N);
int dis[N][N];

bool inqueue[N];
deque<int> q;
int mxans = 0;
int mx[N];

void SPFA(int root) {
	dis[root][root] = 0;
	q.push_back(root); inqueue[root] = true;
	while (!q.empty()) {
		int u = q.front(); q.pop_front(); inqueue[u] = false;
		for (auto v : a[u]) {
			if (dis[root][v.fi] > dis[root][u] + v.se) {
				dis[root][v.fi] = dis[root][u] + v.se;
				if (!inqueue[v.fi]) {
					inqueue[v.fi] = true;
					if (!q.empty() && dis[root][v.fi] < dis[root][q.front()]) {
						q.push_front(v.fi);
					}
					else q.push_back(v.fi);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) mxans = max(mxans, dis[root][i]);
}

bool visited[N]; bool mark[N];
void dfs(int u, int root) {
	if (visited[u]) return;
	visited[u] = true;
	mx[u] = dis[root][u];
	for (auto v : a[u]) {
		if (dis[root][v.fi] == dis[root][u] + v.se) {
			dfs(v.fi, root); mx[u] = max(mx[u], mx[v.fi]);
		}
	}
	if (mx[u] == mxans)
		mark[u] = 1;
}

vector<int> order;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef in1code
	freopen("1test.inp", "r", stdin);
#endif
	memset(dis, 127, sizeof(dis));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		a[u].push_back(mp(v, c));
		a[v].push_back(mp(u, c));
	}
	for (int i = 1; i <= n; i++) SPFA(i);
	for (int i = 1; i <= n; i++) {
		memset(visited, 0, sizeof(visited)); dfs(i, i);
	}
	for (int i = 1; i <= n; i++) {
		if (!mark[i]) order.push_back(i);
	}
	cout << order.size() << endl;
	for (auto it : order) cout << it << endl;
}


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

int n;
vector<int> a, k;

int solve();

int main() {
  cin >> n;
  a.resize(n);
  k.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i] >> k[i];
  if (solve())
    cout << "Takahashi" << endl;
  else
    cout << "Aoki" << endl;
  return 0;
}

int solve() {
  int res = 0;
  for (int i = 0; i < n; ++i) {
    while (1) {
      int p = a[i] / k[i];
      a[i] = (a[i] - p * k[i]) % (p + 1);
      if (!a[i]) {
        res ^= p;
        break;
      }
      a[i] += p * k[i] - p - 1;
    }
  }
  return res;
}

Measured memory_bytes: 3648
str=input()
s=list(str)
q=int(input())
for i in range(q):
    Q=input()
    l=list(Q)
    if 'print' in Q:
        for p in range(6):
            l.pop(0)
        for X in range(len(l)):
            if l[X]==' ':
                x=X
        A=l[0:x]
        a=''.join(A)
        a=int(a)
        B=l[x+1:len(l)]
        b=''.join(B)
        b=int(b)+1
        t=s[a:b]
        str=''.join(t)
        print(str)
    elif 'reverse' in Q:
        for v in range(8):
            l.pop(0)
        for Y in range(len(l)):
            if l[Y]==' ':
                y=Y
        A=l[0:y]
        a=''.join(A)
        a=int(a)
        B=l[y+1:len(l)]
        b=''.join(B)
        b=int(b)+1
        t=s[a:b]
        t.reverse()
        s[a:b]=t
    elif 'replace' in Q:
        for r in range(8):
            l.pop(0)
        for Z in range(len(l)):
            if l[Z]==' ':
                z=Z
                break
        N=0
        while True:
            if l[z+N+1]==' ':
                n=z+N+1
                break
            else:
                N+=1
        A=l[0:z]
        a=''.join(A)
        a=int(a)
        B=l[z+1:n]
        b=''.join(B)
        b=int(b)+1
        t=l[n+1:len(l)]
        s[a:b]=t


Measured memory_bytes: 5656
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

    int main(){
        int price[11],allprice,Ans;

        while(1){
        for(int i=0;i<11;i++){
        price[i]=0;
        }
        cin>>allprice;
        if(allprice==0)break;

        for(int i=0;i<9;i++){
            cin>>price[i];
        }
        for(int i=0;i<9;i++){
            price[10]+=price[i];
        }
        Ans=allprice-price[10];
        cout<<Ans<<endl;
        }
     return 0;
    }

Measured memory_bytes: 1160
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]

dp = [[0] * w for i in range(h)]
    
for i in range(h):
    for j in range(w):
        if i == j == 0:
            if maze[i][j] == "#":
                dp[i][j] += 1
                
        if i == 0 and j != 0:
            if maze[0][j] != maze[0][j - 1]:
                dp[0][j] = dp[0][j - 1] + 1
            else:
                dp[0][j] = dp[0][j - 1]
        
        if j == 0 and i != 0:
            if maze[i][0] != maze[i - 1][0]:
                dp[i][0] = dp[i - 1][0] + 1
            else:
                dp[i][0] = dp[i - 1][0]
        
        if i != 0 and j != 0:
            dp[i][j] = min(dp[i - 1][j] + (1 if maze[i][j] != maze[i - 1][j] else 0), dp[i][j - 1] + (1 if maze[i][j] != maze[i][j - 1] else 0))
        
        if i == h - 1 and j == w - 1:
            if maze[i][j] == "#":
                dp[i][j] += 1
                
ans = dp[h - 1][w - 1] // 2

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#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 T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n;
string str;

string conv(string str) {
    string res = "";
    str += "a";
    char c = str[0]; 
    int con = 0;
    for (int i = 0; i < str.size(); ++i) {
        if (str[i] != c) {
            stringstream sout;
            sout << con << c;
            res += sout.str();
            con = 1;
            c = str[i];
        }
        else ++con;
    }
    //cout << str << " : " << res << endl;
    return res;
}

int main() {
    while (cin >> n) {
        if (n == 0) break;
        cin >> str;
        for (int i = 0; i < n; ++i) str = conv(str);
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 1360
#include <iostream>
#include <cstdio>
    
using namespace std;
    
int main(){
int a,b,c,d;
double e;
    
cin >> a >> b;
    
c = a/b;
d = a%b;
e = (double)a/(double)b;
    
printf("%d %d %.5f\n", c,d,e);
}


Measured memory_bytes: 3188
import java.io.PrintWriter

fun main() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val pw = PrintWriter(System.out)
    var l = 0
    var r = 1
    for (i in 0 until m step 2) {
        pw.println("${l + 1} ${r + 1}")
        l = (l + n - 1) % n
        r = (r + 1) % n
    }

    if (n % 2 == 0) {
        l = (l + n - 1) % n
    }

    for (i in 1 until m step 2) {
        pw.println("${l + 1} ${r + 1}")
        l = (l + n - 1) % n
        r = (r + 1) % n
    }
    pw.flush()
}


Measured memory_bytes: 48964
#include <stdio.h>
int main (){
	int N,K;
	scanf ("%d %d", &N, &K);
	int arr[N];
	for (int i=0 ; i<N ; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (int i=0 ; i<N-K; i++)
	{
		if (arr[i]<arr[i+K]){
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
return 0;
}


Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=100000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 233333;
int T;

ll n,x,y;

int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//    cin >> T;
    T =1;
    while(T--)
    {
        cin >>n >>x >> y;
        ll cnt = (n-1)/x + 1;
        ll ans = cnt * y;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define N 100
#define INF 2001
#define WHITE 0
#define BLACK 1
int n,M[N][N];
int d[N],p[N],color[N];

void prim();

int main() {
  int i,j,sum = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){ 
      scanf("%d",&M[i][j]);
    }
  }
  prim();
  for(i = 0; i < n; i++)
    if(p[i] != -1) sum += d[i];
  printf("%d\n",sum);
  return 0;
}

void prim(){
  int u,minv,i;

  for(i = 0; i < n; i++){
    d[i] = INF;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1) { 
    minv = INF;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }

    if(minv == INF) break;
    color[u] = BLACK;
    for(i = 0; i < n; i++){
      if(M[i][u] != -1){
	if(color[i] != BLACK && M[i][u] < d[i]){
	  p[i] = u;
	  d[i] = M[i][u];
	}
      }
    }
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    //freopen("in.txt","r",stdin);
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d %d %d\n",c,a,b);
    return 0;
}

Measured memory_bytes: 256
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        x: u64,
    }

    let mut answer = x / 11 * 2;
    let m = x % 11;

    if m != 0 {
        if m <= 6 {
            answer += 1;
        } else {
            answer += 2;
        }
    }

    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5, MOD = 998244353;
int a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    int mx = 0;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;

        if (i == 0 && x != 0) {
            cout << "0\n";
            return 0;
        }
        
        a[x]++;
        mx = max(mx, x);
    }

    if (a[0] != 1) {
        cout << "0\n";
        return 0;
    }

    ll ans = 1;

    for (int i = 1; i <= mx; i++) {
        for (int j = 0; j < a[i]; j++)
            ans = ans * a[i - 1] % MOD;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;
int main(){
  int a,s,d,truthy=0;
cin >>a;
for (s=1;s<10;s++){
d=a/s;
 // cout <<s*d <<endl;
if(a==s*d&&d<10){
truthy=1;
break;}}
if(truthy==1){
cout <<"Yes"<<endl;}
else{cout <<"No"<<endl;}

}

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

using namespace std;

int main()
{
  int M, Nmin, Nmax, P[200];

  while(cin >> M >> Nmin >> Nmax, M) {
    for(int i = 0; i < M; i++) {
      cin >> P[i];
    }

    int gap = numeric_limits< int >::max();
    for(int i = Nmax; i >= Nmin; i--) {
      gap = min(gap, P[i] - P[i - 1]);
    }
    for(int i = Nmax; i >= Nmin; i--) {
      if(P[i] - P[i - 1] == gap) {
        cout << i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3048
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		long[]a=new long[n],b=new long[n];
		Arrays.setAll(a,i->s.nextInt());
		Arrays.setAll(b,i->s.nextInt());
		
		if(Arrays.stream(a).sum()<Arrays.stream(b).sum()) {
			System.out.println(-1);
			return;
		}
		
		long[]d=new long[n];
		Arrays.setAll(d,i->a[i]-b[i]);
		Arrays.sort(d);
//		System.err.println(Arrays.toString(d));
		
		long sd=0,r=0;
		for(int i=0;i<n&&d[i]<0;++i) {
			++r;
			sd+=d[i];
		}
		for(int i=n-1;i>=0&&sd<0;--i) {
			++r;
			sd+=d[i];
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 94992
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
constexpr int mod = 1e9 + 7;

int add (int a, int b) {
    return ((a += b) >= mod) ? a - mod : a;
}

int mul (int a, int b) {
    return 1LL * a * b % mod;
}

int power (int a, int b) {
    int res = 1;
    for ( ; b > 0 ; b >>= 1, a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res;
}

/**
    side node.
    a', b', c', d', e' > 0
    2a + 2b + 2c + 2d + 2e + a' + b' + c' + d' + e' <= N
    n-th term of this polynomial
    (1 + x^2 + x^4 + x^6 +....)^5 (x + 2x^2 + 3x^3 + ....)^5 (1 + x + x^2 +...)
        ^ choose a                  ^ choose a'             ^prefix sum
    simplify by taylor's like thing
    1 / (1-x^2)^5 * x(1+2x+3x^2+...)
                    x(1+x+x^2+...)'<- derivative
        d / dx (1 / (1-x)) = -(1)/(1-x)^2
    -x^5/(1-x^2)^5 * 1/(1-x)^11
    x^5/ (1-x)^11(1+x)^5
    ignore x^5 for now, it's just degree shifting
    (x+1)^11 / (1-x^2)^16

    expand 1/(1-x)^k

    (15, 15) + (16, 15)x + (17, 15)x^2 + ....
    substitute x -> x^2
    (15, 15) + (16, 15)x^2 + (17, 15)x^4 + ...

    now loop over coefficient in (x + 1) ^ 11
    multiply them,
*/



int ncr (int N, int R) {
    if (R > N) return 0;
    int res = 1;
    for (int i = 0 ; i < R ; ++ i) {
        res = mul(res, N - i);
    }

    int fac = 1;
    for (int j = 2 ; j <= R ; ++ j)
        fac = mul(fac, j);
    return mul(res, power(fac, mod - 2));
}

int get_coeff (int i) {
    if (i % 2 || i < 0) return 0;
    return ncr(15 + i / 2, 15);

}

void solve () {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int j = 0 ; j <= 11 ; ++ j) {
        int coeff = ncr(11, j);
      //  printf("j %d coeff %d\n", j, coeff);
        ans = add(ans, mul(get_coeff(n - 5 - j), coeff));
    }

    printf("%d\n", ans);
}

int main () {
    int T;

    for (scanf("%d", &T) ; T -- ; ) {
        solve();
    }
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3812
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    int n, cnt = 0;
    cin >> n;
    vector<int> l(n);
    rep(i, n) { cin >> l[i]; }
    rep(i, n) rep(j, i) rep(k, j) {
        if (l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
        if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string s,t;
  cin >> s>>t;

int ans = t.size();

for (int start = 0; start <= s.size() - t.size(); start++)  {
        int diff = 0;
        for (int i = 0; i < t.size(); i++)
        {
            if (t[i] != s[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }


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


Measured memory_bytes: 3624
// 2011Í[à\I A. koukyoukoukokukikou

#include <iostream>
#include <string>

using namespace std;

int main(){
	string str;
	int a[26] = { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 };
	while(cin >> str){
		if(str == "#") break;
		int res = 0, prev = a[str[0]-'a'];
		for(int i=1;i<str.size();i++){
			if(prev!=a[str[i]-'a']) res++;
			prev = a[str[i]-'a'];
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool in_range(int a, int b, int c){
	return (a <= c && c <= b);
}

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

	int A, B, C; cin >> A >> B >> C;

	bool ok = in_range(A, B, C);

	cout << (ok ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int INF = 1<<30;

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<vector<int>> dp(n+1, vector<int>(h+1, INF));
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= h; j++){
            int next = min(h, j+a[i]);
            dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
            dp[i+1][next] = min(dp[i+1][next], dp[i+1][j]+b[i]);
        }
    }
    cout << dp[n][h] << endl;
}

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

int main(void) {
	int a, b, c, max, min, middle;
	cin >> a >> b >> c;
	if (a > b) {
		if (a > c) {				//a_is_the_largest
			max = a;
			if (b > c) {
				middle = b;
				min = c;
			}
			else {
				middle = c;
				min = b;
			}
		}
		else {
			max = c;
			middle = a;
			min = b;
		}

	}
	else if(b > c) {					//b>a
		max = b;
		if (a > c){
			middle = a;
			min = c;
		}
		else {
			middle = c;
			min = a;
		}
	}
	else {
		max = c;
		middle = b;
		min = a;
	}
	cout << min << " " << middle << " " << max << endl;
	return 0;
}


Measured memory_bytes: 3048
#define FNAME ""

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}


int a[200000];
int n;

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

	scanf("%d", &n);
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	int ans = 0;
	forn(i, n) {
		ans += a[a[i]] == i && a[i] != i;		
	}
	printf("%d\n", ans / 2);
}



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

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


int main() {
	int n, x, o,t;
	cin >> n >> x >> t;
	o = ((n / x) ) * t;
    if(n%x!=0){
    o=o+t;
    }
	cout << o << endl;
	return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;

/////////////////////////////////

int const MAX = 2e5 + 41;

int pos[MAX];
int n;
int a[MAX];
int ans[MAX];
pii b[MAX];

void solve() {
	fi(1, n) {
		b[i] = mp(a[i], i);
	}
	sort(b + 1, b + n + 1);
	fi(1, n) {
		pos[b[i].second] = i;
	}
	fi(1, n) {
		int p = pos[i];
		err("i = %d p = %d\n", i, p);
		if (p <= n / 2) {
			ans[i] = b[n / 2 + 1].first;
		} else {
			ans[i] = b[n / 2].first;
		}
	}
	fi(1, n) {
		printf("%d\n", ans[i]);
	}
}

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

	scanf("%d", &n);
	fi(1, n) {
		scanf("%d", &a[i]);
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 1e9
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

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

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

signed main() {
    int X;
    cin >> X;
    int ans = X % 100;
    int kaisu = X / 100;
    int count = 0;
    for (int i = 0; i <= kaisu; i++) {
        for (int j = 0; j + i <= kaisu; j++) {
            for (int k = 0; i + j + k <= kaisu; k++) {
                for (int l = 0; i + j + k + l <= kaisu; l++) {
                    for (int n = 0; n + i + j + k + l <= kaisu; n++) {
                        if (i + j * 2 + k * 3 + l * 4 + n * 5 == ans) {
                            cout << "1" <<endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << "0" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    typedef long long ll;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define take(a,n) f(i,0,n)cin>>a[i];
    #define show(a,n) f(i,0,n){cout<<a[i]<<" ";}
    #define ashow(a)  for(auto i:a)cout<<i<<" ";
    #define khtm     cout<<endl;
    #define all(s) s.begin(),s.end()
    #define len(a) a.length()
    #define INF 1e18
    #define MAXN 2000009
    const double pi=3.14159265358979323;
    const int mod=1e9+7;
    int ng(int n){
      int i=0;
      while(n>pow(2,i))
        i++;
      i--;
      return pow(2,i)-1-n;

    }
     signed main() {
     // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1;
    // cin>>t;
    while(t--)
    {
        int n,k,x=0,y=0;
        int mx=-1,mi=INF,mn=INF;
        int tm=0;
        vector<int>ans;
        // string s;

     cin>>x>>n;
     set<int>s;
     for(int i=0;i<1000;i++)
      s.insert(i);
     for(int i=0;i<n;i++){
      cin>>k;
      s.erase(k);}
      if(s.count(x))cout<<x<<endl;
      else {s.insert(x);
      auto pos=s.find(x);
      pos--;
      auto it1=pos;
      pos=s.find(x);
      pos++;
      auto it2=pos;
      if(abs(*it1-x)>abs(*it2-x))cout<<*it2<<endl;
      else cout<<*it1<<endl;
}

         


        }


 }

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

#define llf float
#define piii 3.1415926535
bool ok=true;
int arr[5]={0};


int main()
{

int n;
cin>>n;
n=n%10;
if(n==3)
cout<<"bon";
else if(n==0||n==1||n==6||n==8)
cout<<"pon";
else
cout<<"hon";
cout<<endl;
}


Measured memory_bytes: 3620
M, D = list(map(int, input().split()))
count = 0
for month in range(1,M+1):
    for day in range(1,D+1):
        d10,d1 = divmod(day, 10)
        if (d10 >= 2) & (d1 >= 2) & (d10 * d1 == month):
            count = count + 1
print(count)
         
        

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

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

int main(){
	int k;
	cin>>k;
	long long res=0;
	for (int i=1;i<=k;i++)
		for (int j=1;j<=k;j++)
			for (int l=1;l<=k;l++){
				int a1=gcd(i,j);
				int a2=gcd(a1,l);
				res+=a2;
			}
	cout<<res<<endl;			
	return 0;
}

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


long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

ll COM(ll n, ll k) {
    ll x = 1;
    for(ll i=n-k+1; i<=n; i++) {
        x = x*i%MOD;
    }

    ll y = 1;
    for(ll i=1; i<=k; i++) {
        y = y*i%MOD;
    }
    y = modpow(y, MOD-2);

    return x*y%MOD;
}

int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll ans = modpow(2,n)-1;
    ans%=MOD;
    ans -= (COM(n,a)+COM(n,b))%MOD;
    ans%=MOD;
    if(ans<0) ans+=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[12345678], cost[1234][1234];
signed main() {
	vector<int> v; map<string, int> mn;
	int n, m, q, a, b, c, cnt = 0, ans = 0; string s, t;
	cin >> n >> m;
	for (int h = 0; h < m; h++) {
		cin >> a;
		for (int i = 0; i < a; i++) {
			cin >> b; test[b]++;
		}
	}
	for (int h = 1; h <= n; h++) {
		if (test[h] == 0) { ans++; }
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 0;
int n,m,q,potato;


int main()
{
	cin >> n >> m;
	if(n==1) n = 14;
	if(m==1) m = 14;
	
	if(m==n) cout << "Draw" << endl;
	else if(n > m) cout << "Alice" << endl;
	else cout << "Bob" << endl;
}








Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    if(n>=2&&m>=2)
    {
        if((n*m)%2==0) cout<<n*m/2;
        else cout<<n*m/2+1;
    }
    else cout<<1;
    return 0;
}


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

/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/

using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool isSame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A--, B--;
        uf.merge(A, B);
    }
    int ans = 0;
    vector<int> cnt(N);
    for (int i = 0; i < N; i++)
    {
        cnt[uf.root(i)]++;
    }
    for (int i = 0; i < N; i++)
        ans = max(ans, cnt[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4724
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 100005;

int vst[MX][15];
int C[MX];
vector<int> G[MX];
vector<t3> E;

void bfs(int st, int d, int color){
	if( vst[st][d] ) return;
	queue<pii> Q;
	Q.emplace(st, d);
	if( !C[st] ) C[st] = color;
	while(Q.size()){
		pii p = Q.front(); Q.pop();
		int x = p.first, y = p.second;
		if( !y ) continue;
		for(int c : G[x]){
			if( !C[c] ) C[c] = color;
			if( vst[c][y-1] ) continue;
			Q.emplace(c, y-1); vst[c][y-1] = 1;
		}
	}
}

int main()
{
	int N, M, Q;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		E.emplace_back(a, b, c);
	}
	reverse(E.begin(), E.end());
	for(t3 e : E){
		int a, b, c;
		tie(a, b, c) = e;
		bfs(a, b, c);
	}
	for(int i = 1; i <= N; i++) printf("%d\n", C[i]);
}


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

int ans = 1;
  
vector<string> s(n);
for(int i = 0; i<n ; i++)
  cin >> s.at(i);

sort(s.begin() , s.end());
for(int i = 1; i < n; i++){
  if (s.at(i-1) != s.at(i)) ans++;
}
cout << ans << endl;

}

Measured memory_bytes: 9596
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;



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

    ll ans = INF;
    rep(i,1<<N){
        vector<ll> buy;
        rep(j,N){
            int bit = (i >> j);
            if ((bit & 1) == 1){
                buy.push_back(j);
            }
        }

        vector<ll> understand(M,0);
        ll money = 0;
        for(auto b : buy){
            money += C[b];
            for(int j = 0; j < M; j++){
                understand[j] += A[b][j];
            }
        }
        bool isOK = true;
        rep(j,M){
            if (understand[j] < X) isOK = false;
        }

        if(isOK) ans = min(ans, money);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

}

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

// Begin {{{
using namespace std;

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

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

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

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

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

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

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

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

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

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

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

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

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

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, A, B, C);
  OUTL((A * C <= B) ? C : B / A);
  return 0;
}


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

const double PI=acos(-1.0);

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        int tmp = i;
        int sum = 0;
        while(tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if(a <= sum && sum <= b) cnt += i;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <limits>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i];
  }
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  vector<int> l(m - 1);
  int ans = 0;
  for (int i = 0; i + 1 < m; i++) {
    l[i] = v[i + 1] - v[i];
  }
  sort(l.begin(), l.end());
  for (int i = 0; i < m - 1 - (n - 1); i++)
    ans += l[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')

parent = lambda i: math.floor(i / 2)
left = lambda i: 2 * i
right = lambda i: 2 * i + 1


def max_heapify(A, H, i):
    l = left(i) + 1
    r = right(i) + 1

    largest = i
    if l < H and A[l] > A[i]:
        largest = l
    if r < H and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, H, largest)


def build_max_heap(A, H):
    for i in reversed(range(H // 2)):
        max_heapify(A, H, i)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H = ii()
    heap = il()
    build_max_heap(heap, H)
    print('', *heap)


if __name__ == '__main__':
    main()



Measured memory_bytes: 56464