akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int a,b,c,x,y,z;
	
	scanf("%d%d%d",&a,&b,&c);
	
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	
	if(b>c){
		y=b;
		b=c;
		c=y;
	}
	
	if(a>b){
		z=a;
		a=b;
		b=z;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}
	

Measured memory_bytes: 596
N = int(input())
A = list(map(int, input().split()))

cnt = 0
even = 0
for i in A:
  if i % 2 == 0:
    even += 1
    if i % 3 == 0 or i % 5 == 0:
      cnt += 1
      
if cnt == even:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

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

#define fs first
#define sc second


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

    int res = 0;
    for(int i = 1; i < n-1; i++){
        if(p[i-1] > p[i] && p[i+1] < p[i]){
            res++;
        }
        else if(p[i-1] < p[i] && p[i+1] > p[i]){
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	ll a[4000];
	rep(i,n) scanf("%lld",a+i);

	vector<ll> h[4001];
	h[0].push_back(-(1LL<<61));
	rep(i,n){
		ll sum=0;
		for(int j=i;j<n;j++){
			sum+=a[j];
			h[j+1].push_back(sum);
		}
	}
	rep(i,n+1){
		sort(h[i].begin(),h[i].end());
		h[i].erase(unique(h[i].begin(),h[i].end()),h[i].end());
	}

	vector<int> dp[4001];
	vector< pair<int,int> > prev[4001];
	rep(i,n+1){
		dp[i].assign(h[i].size(),-INF);
		prev[i].resize(h[i].size());
	}
	dp[0][0]=0;
	rep(i,n){
		// h[i] の二分探索が正しく動くように, dp[i] を単調増加になるように修正
		int pos[4001]; // pos[j] := ( dp[i][j] の値はもともと dp[i][pos[j]] のもの ) ( 経路復元用 )
		rep(j,dp[i].size()) pos[j]=j;
		rep(j,(int)dp[i].size()-1){
			if(dp[i][j+1]<dp[i][j]){
				dp[i][j+1]=dp[i][j];
				pos[j+1]=pos[j];
			}
		}

		ll sum=0;
		for(int j=i;j<n;j++){
			sum+=a[j];
			int k=lower_bound(h[i].begin(),h[i].end(),sum)-h[i].begin()-1;
			if(k==-1) continue;

			int idx=lower_bound(h[j+1].begin(),h[j+1].end(),sum)-h[j+1].begin();
			if(dp[j+1][idx]<dp[i][k]+1){
				dp[j+1][idx]=dp[i][k]+1;
				prev[j+1][idx]=make_pair(i,pos[k]);
			}
		}
	}

	vector<int> ans;
	int i=n,j=max_element(dp[n].begin(),dp[n].end())-dp[n].begin();
	while(1){
		int tmp_i=prev[i][j].first;
		int tmp_j=prev[i][j].second;
		i=tmp_i;
		j=tmp_j;
		if(i==0) break;
		ans.push_back(i);
	}
	reverse(ans.begin(),ans.end());

	printf("%d\n",ans.size()+1);
	rep(i,ans.size()) printf("%d%s",ans[i],i+1<ans.size()?" ":"");
	puts("");

	return 0;
}

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

int a,b;
int main () {
	cin>>a>>b;
	if(a==b){
		cout<<"Draw";
	}else if(a==1 && b!= 1){
		cout<< "Alice";
	}else if(b==1 && a!= 1){
		cout<<"Bob";
	}else if(a<b){
		cout<<"Bob";
	}else{
		cout<<"Alice";
	}
}



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

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

using namespace std;

const long MOD = 998244353;
const int N = 1e6;

long fact[N + 1], inv[N + 1];

long fast_pow(long n, long k, long m) {
    n %= m;
    long res = 1;
    while (k) {
        if (k & 1) res = res * n % m;
        n = n * n % m;
        k >>= 1;
    }
    return res;
}

long choice(int n, int k) {
    return (fact[n] * inv[k]) % MOD * inv[n - k] % MOD;
}

long inv_choice(int n, int k) {
    return (inv[n] * fact[k]) % MOD * fact[n - k] % MOD;
}

void fill_facts() {
    fact[0] = 1;
    for (int i = 1; i <= N; ++ i) {
        fact[i] = fact[i - 1] * i % MOD;
    }

    inv[N] = fast_pow(fact[N], MOD - 2, MOD);
    for (int i = N - 1; i >= 0; i --) {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}

int main() {
    fill_facts();

    long n, m;
    scanf("%ld %ld", &n, &m);

    if (m < n) swap(m, n);


    // m >= n
    // res = m + sum_{k = 1}^{n}{C(2k, k)*C(m+n-2k, n-k)/2C(m+n,n)}

    long res = 0;
    for (int i = 1; i <= n; ++ i) {
        res += choice(2 * i, i) * choice(m + n - i - i, n - i) % MOD;
        res %= MOD;
    }
    res = res * inv[2] % MOD * inv_choice(m + n, n) % MOD;
    res = (res + m) % MOD;
    printf("%ld\n", res);

    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,c;
  cin>>n>>m>>c;
     vector<int> b(m);
   for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
 for (int j = 0; j < m; j++) {
 cin>>a[i][j];
}
}
int ans=0;
for (int i = 0; i < n; i++) {
  int sum=0;
 for (int j = 0; j < m; j++) {
 sum+=a[i][j]*b[j];
}
  sum+=c;
  if(sum>0){
    ans++;
  }
}                      
    cout<<ans<<endl;
 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	unsigned long long l,r;
	cin>>l>>r;
	if(r-l>=2018){
		cout<<0;
		return 0;
	}
	unsigned long long minv=-1;
	for(unsigned long long i=l;i<r;++i)
		for(unsigned long long j=i+1;j<=r;++j)
			minv=min(minv,i*j%2019);
	cout<<minv;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int d;

scanf("%d", &d);
if(d==25)
 printf("Christmas\n");
else if(d==24)
 printf("Christmas Eve\n");
else if(d==23)
 printf("Christmas Eve Eve\n");
else if(d==22)
 printf("Christmas Eve Eve Eve\n");

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

const double PI=3.14159265358979323846;

void solve(istream& cin, ostream& cout) {
  int r;
  cin >> r;
  double ans = r * 2 * PI;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

int main(){
  long long N,cnt=0;
  cin >> N;
  for(int a = 1;a<=sqrt(N);a++){
    if(N%a==0&&N/a-1>a){
      cnt += N/a-1;
    }
  }
  cout << cnt << endl;
}

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

int mp[15000000];
int Hash(string s) {
	int cnt = 0, t = 1;
	rep(i, s.size()) {
		cnt += s[i]*t;
		t *= 3;
	}
	return cnt;
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(mp, 0, sizeof(mp));
		string in(15, 0);
		rep(i, 3) {
			int len; scanf("%d", &len);
			rep(j, len) {
				int a; scanf("%d", &a);
				in[--a] = i;
			}
		}
		queue<string>que;
		mp[Hash(in)] = 1;
		que.push(in);
		while (!que.empty()) {
			string u = que.front(); que.pop();
			if (count(u.begin(), u.begin() + n, 0) == n ||
				count(u.begin(), u.begin() + n, 2) == n) {
				printf("%d\n", mp[Hash(u)] - 1);
				goto g;
			}
			if (mp[Hash(u)] > m)continue;
			rep(k, 2)rep(t, 2) {
				int i, j;
				if (t) { i = k, j = k + 1; }
				else { i = k + 1; j = k; }
				int fi = u.rfind(i, n - 1), fj = u.rfind(j, n - 1);
				if (fi == -1 || fi < fj)continue;
				string v = u;
				v[fi] = j;
				if (!mp[Hash(v)]) {
					mp[Hash(v)] = mp[Hash(u)] + 1;
					que.push(v);
				}
			}
		}
		puts("-1");
	g:;
	}
}

Measured memory_bytes: 61948
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll H, W;
ll dpl[2005][2005];
ll dpr[2005][2005];
ll dpu[2005][2005];
ll dpd[2005][2005];

int main(){
	cin >> H >> W;
	vector<string> S(H);
	rep(i, H) cin >> S[i];


	rep(i, H) {
		ll cur = 0;
		rep(j, W) {
			dpl[i][j] = cur;
			if(S[i][j] == '#') {
				cur = 0;
			} else {
				cur++;
			}
		}
	}

	rep(i, H) {
		ll cur = 0;
		for(ll j = W - 1; j >= 0; j--) {
			dpr[i][j] = cur;
			if(S[i][j] == '#') {
				cur = 0;
			} else {
				cur++;
			}
		}
	}


	rep(j, W) {
			ll cur = 0;
		rep(i, H) {
			dpu[i][j] = cur;
			if(S[i][j] == '#') {
				cur = 0;
			} else {
				cur++;
			}
		}
	}

	rep(j, W) {
			ll cur = 0;
		for(ll i = H - 1; i>= 0; i--){
			dpd[i][j] = cur;
			if(S[i][j] == '#') {
				cur = 0;
			} else {
				cur++;
			}
		}
	}

	ll ans = 0;
	rep(i, H) {
		rep(j, W) {
			if(S[i][j] == '#') continue;

			ans = max(ans, dpl[i][j] + dpr[i][j] + dpu[i][j] + dpd[i][j] + 1);

		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 136532
import java.util.Scanner;

//Alien Messages
public class Main{

	int w, h, C, si, sj, SD, ED;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
	int[] D = {5, 10, 3, 9, 12, 6};
	int[][] p = {{0,2},{1,3},{0,1},{0,3},{2,3},{1,2}};
	int[][] nx = {{0, 5, 4},{3, 1, 4},{2, 0, 3},{2, 5, 1}};
	int[][] map;
	
	boolean check(int pi, int pj){
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(map[i][j]==0){
			int c = 0;
			for(int k=0;k<4;k++){
				int ni = i+d[k][0], nj = j+d[k][1];
				if(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]==0)c++;
			}
			if(i==pi&&j==pj)c++;
			if(i==si+d[ED][0]&&j==sj+d[ED][1])c++;
//			System.out.println("C:"+c);
			if(c<2)return false;
		}
		return true;
	}
	
	boolean f(int i, int j, int c, int pd){
//		System.out.println(i+","+j+" "+c);
//		for(int y=0;y<h;y++){
//			for(int x=0;x<w;x++)System.out.printf("%3d", map[y][x]);
//			System.out.println();
//		}
		if(!check(i, j)){
//			System.out.println("Check OUT");
			return false;
		}
		if(si+d[ED][0]==i&&sj+d[ED][1]==j&&c<C){
//			System.out.println("C OUT");
			return false;
		}
		for(int k=0;k<3;k++){
			map[i][j] = D[nx[pd][k]];
			boolean ok = true;
			int ND = -1;
			for(int x=0;x<2;x++){
				int dir = p[nx[pd][k]][x];
				int ni = i+d[dir][0], nj = j+d[dir][1];
				if(!(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]!=-1)){
					ok = false; break;
				}
				if(map[ni][nj]==0){
					ND = dir;
				}
				else {
					int r = (dir+2)%4;
					if(((map[ni][nj]>>r)&1)==0){
						ok = false;
					}
				}
			}
			if(!ok)continue;
			if(ND==-1){
				if(c==C)return true;
			}
			else if(f(i+d[ND][0], j+d[ND][1], c+1, ND))return true;
		}
		map[i][j] = 0;
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			C = 0;
			map = new int[h][w];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				map[i][j]=sc.nextInt()==0?0:-1;
				C+=map[i][j]==0?1:0;
			}
			boolean res = false, con = true;
			for(int i=0;i<h&&con;i++)for(int j=0;j<w&&con;j++)if(map[i][j]==0){
				con = false;
				for(int k=0;k<6;k++){
					boolean ok = true;
					for(int x=0;x<2;x++){
						int ni = i+d[p[k][x]][0], nj = j+d[p[k][x]][1];
						if(!(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]==0)){
							ok = false;
						}
					}
					if(!ok)continue;
					map[i][j] = D[k];
					si = i; sj = j; SD = p[k][0]; ED = p[k][1];
//					System.out.println("SI:"+si+" SJ:"+sj+" SD:"+SD+" ED:"+ED);
					if(f(i+d[p[k][0]][0], j+d[p[k][0]][1], 2, SD)){
						res = true; break;
					}
				}
			}
			System.out.println(res?"Yes":"No");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);

bool is_prime(int n) {
    if (n==1) return false; 
    repr(i,2,int(sqrt(n)+1)) {
        if (n%i==0) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int k=7;
    vector<int> ans;
    while (k<=55555) {
        if (is_prime(k)) ans.push_back(k);
        k+=10;
    }
    rep(i,n) cout << ans[i] << endl;
     

    return 0;

}


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

public class P
{
    public int p { get; set; }
    public int s { get; set; }
    public int de { get; set; }
    public int dp { get; set; }
    public int h { get; set; }
    public string t { get; set; }
    public List<int> child { get; set; }
}

public class P2
{
    public int step { get; set; }
    public int id { get; set; }
}

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = getP(n);
        getDP(ps);
        getH(ps);
        print(ps);
    }
    public static void print(P[] ps)
    {
        var node = 0;
        foreach (var x in ps)
            Console.WriteLine("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}", node++, x.p, x.s, x.de, x.dp, x.h, x.t);
    }
    public static void getH(P[] ps)
    {
        for (int i = 0; i < ps.Length; i++)
        {
            if (ps[i].p == -1) ps[i].t = "root";
            if (ps[i].h != 0) ps[i].h = getH2(ps, i);
        }
    }
    public static int getH2(P[] ps, int id)
    {
        var q = new Queue<P2>();
        var ans = new List<int>();
        foreach (var x in ps[id].child) q.Enqueue(new P2 { id = x, step = 1 });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (ps[w.id].de > 0)
                foreach (var x in ps[w.id].child) q.Enqueue(new P2 { id = x, step = w.step + 1 });
            else ans.Add(w.step);
        }
        return ans.Max();
    }

    public static void getDP(P[] ps)
    {
        foreach (var x in ps)
        {
            if (x.p != -1)
            {
                var nroot = x.p;
                var count = 1;
                while (true)
                {
                    if (ps[nroot].p == -1) { x.dp = count; break; }
                    else { count++; nroot = ps[nroot].p; }
                }
            }
        }
    }
    public static P[] getP(int n)
    {
        var ps = new P[n];
        for (int i = 0; i < n; i++) ps[i] = new P { p = -1, s = -1, h = -1, t = "internal node", child = new List<int>() };
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var id = int.Parse(line[0]);
            var a = int.Parse(line[1]);
            var b = int.Parse(line[2]);
            if (a >= 0 && b >= 0) { ps[id].de = 2; ps[a].s = b; ps[b].s = a; ps[a].p = id; ps[b].p = id; ps[id].child.Add(a); ps[id].child.Add(b); }
            else if (a >= 0 && b == -1) { ps[id].de = 1; ps[a].s = -1; ps[a].p = id; ps[id].child.Add(a); }
            else if (a == -1 && b >= 0) { ps[id].de = 1;  ps[b].s = -1; ps[b].p = id; ps[id].child.Add(b); }
            else { ps[id].h = 0; ps[id].t = "leaf"; }
        }
        return ps;
    }
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int mod = 998244353;
const int N = 1 << 17;
long long dp[3][N];

void wh(long long* b, long long* e) {
	if (e == b + 1) {
		return;
	}
	long long *m = b + (e - b) / 2;
	wh(b, m);
	wh(m, e);
	while (m != e) {
		auto x = *b, y = *m;
		*b = x + y;
		*m = x - y;
		++b, ++m;
	}
}

int mex(vector<int> a) {
	make_unique(a);
	int res = 0;
	while (res < (int)a.size() && a[res] == res) {
		++res;
	}
	return res;
}

long long inv(long long a, long long b) {
	return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

int main() {
	int n = nxt();
	const long long rem = (long long)(1e18) % mod;
	vector<long long> deg(n + 1);
	deg[0] = 1;
	for (int i = 1; i <= n; ++i) {
		deg[i] = deg[i - 1] * rem % mod;
	}
	for (int i = 0; i < 3; ++i) {
		int m = nxt();
		vector<vector<int>> a(n);
		for (int j = 0; j < m; ++j) {
			int u = nxt() - 1, v = nxt() - 1;
			if (u > v) {
				swap(u, v);
			}
			a[u].push_back(v);
		}
		vector<int> gr(n);
		for (int j = n - 1; j >= 0; --j) {
			vector<int> grs;
			for (int x : a[j]) {
				grs.push_back(gr[x]);
			}
			gr[j] = mex(grs);
			dp[i][gr[j]] += deg[j + 1];
		}
		for (int j = 0; j < n; ++j) {
			dp[i][j] %= mod;
		}
	}

	for (int i = 0; i < 3; ++i) {
		wh(dp[i], dp[i] + N);
		for (int j = 0; j < N; ++j) {
			dp[i][j] %= mod;
			if (dp[i][j] < 0) {
				dp[i][j] += mod;
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		dp[0][i] *= dp[1][i];
		dp[0][i] %= mod;
		dp[0][i] *= dp[2][i];
		dp[0][i] %= mod;
	}
	wh(dp[0], dp[0] + N);
	dp[0][0] %= mod;
	if (dp[0][0] < 0) {
		dp[0][0] += mod;
	}
	cout << dp[0][0] * inv(N, mod) % mod << "\n";

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<char> bag(N);
  for (int i = 0; i < N; i++) {
  cin >> bag.at(i);
  }
  
  bool count = false;
  for (int i = 0; i<N; i++){
  if  (bag.at(i)=='Y') {
  count = true;
  }
  }
  if (count){

  cout << "Four" << endl;
  }
  
  else {
  
  cout << "Three" << endl;
  }
  
  
}




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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}

vi a;

pii solve(ll i, ll l, ll r){
    ll ceil = (l+a[i]-1)/a[i];
    ll val = ceil*a[i];
    ll floor = r/a[i];
    ll val1= floor * a[i];
    if(val <= r && val >= l) {
        if(i == 0){
            return {val, val1+a[i]-1};
        }
        else return solve(i-1,val,val1+a[i]-1);
    }
    return {-1,-1};
}


ll solveMin(ll i, ll l, ll r){
    ll ceil = (l+a[i]-1)/a[i];
    ll val = ceil*a[i];
    if(val <= r && val >= l) {
        if(i == 0) return val;
        else return solveMin(i-1,val, val+a[i]-1);
    }
    return -1;
}

ll solveMax(ll i, ll l , ll r){
    ll floor = (r/a[i]);
    ll val = floor * a[i];
    if(val <= r && val >= l){
        if(i == 0) return val + a[i]-1;
        else return solveMax(i-1,val,val+a[i]-1);
    }
    return -1;
}

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

    ll k;
    cin>>k;
    a.assign(k,0);
    rep(i,k) cin>>a[i];


    //minimum-
    pii ans = solve(k-1,2,2);

    ll lo = ans.X, hi = ans.Y;
    if(lo == -1 || hi==-1){
        assert(hi == -1);
        assert(lo == -1);
        cout<<-1<<endl;

    } else {
        cout<<lo<<" "<<hi<<endl;
    }


    timer();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  long A, B, ans; cin >> A >> B;
  for (int i=1; i<=B; i++){
    if ((A*i)%B == 0){
      ans = A*i;
      break;
    }    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
Ps = [nil] + gets.split.map(&:to_i)
XYs = readlines.map{|l| l.split.map(&:to_i)}

@p = Array.new(N + 1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

XYs.each{|x, y| unite(x, y)}
puts (1 .. N).count{|i| root(i) == root(Ps[i])}

Measured memory_bytes: 19212
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    int score = 0;
    int minNotx10 = 101;
    
    rep(i, 0, N) {
        int s;
        cin >> s;
        score += s;
        if (s%10 != 0) minNotx10 = min(minNotx10, s);
    }

    int res;
    if (score%10 != 0) res = score;
    else if (minNotx10 == 101) res = 0;
    else res = score-minNotx10;
    cout << res << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,n;
	cin>>a>>b>>n;
	int r=min(b-1,n);
	cout<<a*r/b<<endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int x;
    cin >> x;
    ll sum = 0;
    rep(i, 1e6) {
        sum += i+1;
        if (sum >= x) {
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Main
fn main(){
    input!{
        S: chars
    }
    let mut ans = 9999;
    let a = S.iter().map(|c| c.to_digit(10).unwrap()).collect::<Vec<u32>>();
    for i in 0..a.len()-2{
        ans = min(ans, (753 - (a[i]*100 + a[i+1]*10 + a[i+2]) as i32).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	Vec t(n), a(n);
	rep(i, n) cin >> t[i];
	rep(i, n) cin >> a[i];

	Vec h(n);
	rep(i, n){
		if(!i || t[i] != t[i-1]) h[i] = t[i];
	}
	repr(i, n){
		if(i == n-1 || a[i] != a[i+1]){
			if(!h[i] || h[i] == a[i]) h[i] = a[i];
			else{
				co(0);
				return 0;
			}
		}
	}

	rep(i, n){
		if(h[i] && t[i] < h[i] || a[i] < h[i]){
			co(0);
			return 0;
		}
	}

	ll ans = 1;
	rep(i, n){
		if(!h[i]){
			ans *= min(a[i], t[i]);
			ans %= MOD;
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];

ll modpow(ll a){
	ll res=1;
	int n=inf-2;
	while(n>0){
		if(n&1)res = res * a % inf;
		a=a*a % inf;
		n>>=1;
	}
	return res;
}
int main() {
	ll x,y;
	cin>>x>>y;
	if((x+y)%3>0||(2*y-x)<0||(2*y-x)%3>0||(2*x-y)<0||(2*x-y)%3>0){
		printf("0");
		return 0;
	}
	ll r=1;
	for(ll i=2;i<=(x+y)/3;++i){
		r*=i;
		r%=inf;
	}
	for(ll i=2;i<=(2*x-y)/3;++i){
		r*=modpow(i);
		r%=inf;
	}
	for(ll i=2;i<=(2*y-x)/3;++i){
		r*=modpow(i);
		r%=inf;
	}
	cout<<r;
	return 0;
}


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

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    srand((unsigned int)time(NULL));
    rep(i, 0, D){
        t[i] = (ll) (rand() % 26);
    }
    ll M = 1e6;
    vector<ll> rec(26, 0);
    /*
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        d[i] = (ll) (rand() % D);
        q[i] = (ll) (rand() % 26);
    }
    */
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    vector<ll> median(D);
    rep(i, 0, D){
        auto cp = s[i];
        sort(cp.begin(), cp.end());
        median[i] = cp[20];
    }
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        ll prev_res = res;
        ll d = (ll) (rand() % D);
        // ll d = m % D;
        ll q = (ll) (rand() % 26);
        // ll q = m % 26;
        if(rec[q] < c[q] * 150) continue; 
        if(s[d][q] < median[min(23LL, 26 * m / M)]) continue;
        res -= s[d][t[d]];
        res += s[d][q];
        res += rec[t[d]];
        res += rec[q];
        ll tdrec = 0, qrec = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d && t[i] == t[d]){
                lst = i;
            }
            res -= c[t[d]] * (i - lst);
            // rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
            tdrec +=  c[t[d]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d || t[i] == q){
                lst = i;
            }
            res -= c[q] * (i - lst);
            // rec[q[m]] += c[q[m]] * (i - lst);
            qrec += c[q] * (i - lst);
        }
        if(res > prev_res){
            rec[t[d]] = tdrec;
            rec[q] = qrec;
            t[d] = q;
        }else{
            res = prev_res;
        }
        // cout << res << endl;
    }
    rep(i, 0, D) cout << t[i]+1 << endl;
    return 0;
}

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

int main(){
  int K,T;
  cin>>K>>T;
  vector<int> a(T);
  for(int i=0;i<T;++i) cin>>a[i];
  priority_queue<pair<int,int>> que;
  for(int i=0;i<T;++i){
    que.push(make_pair(a[i],i+1));
  }

  vector<int> v;

  while(!que.empty()){
    if(que.size()==1){
      auto p=que.top();
      que.pop();
      for(int i=0;i<p.first;++i) v.push_back(p.second);
    }
    else{
      auto p=que.top();
      que.pop();
      v.push_back(p.second);
      auto q=que.top();
      que.pop();
      v.push_back(q.second);
      if(p.first>1) que.push(make_pair(p.first-1,p.second));
      if(q.first>1) que.push(make_pair(q.first-1,q.second));
    }
  }  

  int cnt=0;
  for(int i=1;i<K;++i){
    if(v[i]==v[i-1]) ++cnt;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>


int main(void) {
    int a, b, d, rectangles = 0, lozenges = 0;

    while (scanf("%d,%d,%d", &a, &b, &d) == 3) {
        if (a * a + b * b == d * d) {
            rectangles++;
        }
        else if (a == b && a + b > d) {
            lozenges++;
        }
    }
    printf("%d\n%d\n", rectangles, lozenges);

    return 0;
}

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

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


long long lcm(long long a, long long b){
    long long g = gcd(a, b);
    return a / g * b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long ans = 1LL;
    for(int i = 0; i < n; i++){
        long long t; cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

mat mul(mat &A, mat &B){
    mat C(A.size(), vll(B[0].size()));
    rep(i,A.size()){
        rep(k,B.size()){
            rep(j,B[0].size()){
                C[i][j]=(C[i][j]^(A[i][k]&B[k][j]));
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(), vll(A.size()));
    rep(i,A.size()){
        B[i][i]=(1ll<<32)-1;
    }
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    rep(i,s.size()-1){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using i64 = int64_t;

int main(){
    i64 x;
    cin >> x;
    i64 sum = 0;
    for(i64 i=1;i<=x;++i){
        sum += i;
        if(sum >= x){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

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

using pii = pair<int, int>;

constexpr int inf = 1e9;

template<typename Monoid>
class segment_tree {
    using T = typename Monoid::type;

public:
    segment_tree(std::vector<T> const& init)
        : sz(init.size()), n(expand(init.size()))
    {
        dat.assign(n*2, Monoid::id());
        std::copy(begin(init), end(init), begin(dat) + n);
        for(int i = n - 1; i >= 0; --i) {
            dat[i] = Monoid::op(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    segment_tree(int const n_, T const& init = Monoid::id())
        : segment_tree(std::vector<T>(n_, init))
    {}

    void update(int p, T val) {
        assert(0 <= p && p < sz);
        dat[p += n] = val;
        while(p /= 2) {
            dat[p] = Monoid::op(dat[p * 2], dat[p * 2 + 1]);
        }
    }

    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= sz);
        l += n, r += n;
        T res1 = Monoid::id(), res2 = Monoid::id();
        while(l != r) {
            if(l & 1) res1 = Monoid::op(res1, dat[l++]);
            if(r & 1) res2 = Monoid::op(dat[--r], res2);
            l /= 2, r /= 2;
        }
        return Monoid::op(res1, res2);
    }

private:
    int expand(int n_) const {
        assert(n_ >= 1);
        return n_ == 1 ? n_ : expand((n_ + 1) / 2) * 2;
    }

private:
    const int sz, n;
    std::vector<T> dat;
};

struct RMQ {
    using type = pii;
    static type id() {
        return make_pair(inf, inf);
    }
    static type op(type const& l, type const& r) {
        return std::min(l, r);
    }
};

struct RSQ {
    using type = int;
    static type id() { return 0; }
    static type op(type const& l, type const& r) { return l + r; }
};


int main() {
    string s; cin >> s;
    int k; cin >> k;
    const int n = s.size();
    segment_tree<RMQ> seg(n);
    segment_tree<RSQ> rsq(n, 1);
    for(int i = 0; i < n; ++i) {
        seg.update(i, make_pair(s[i] - 'a', i));
    }

    string ans;
    for(int i = 0; i < n; ++i) {
        int lb = 0, ub = n;
        while(ub - lb > 1) {
            const int mid = (lb + ub) / 2;
            (rsq.query(0, mid) <= k ? lb : ub) = mid;
        }
        auto p = seg.query(0, ub);
        ans += p.first + 'a';
        k -= rsq.query(0, p.second);
        seg.update(p.second, make_pair(inf, inf));
        rsq.update(p.second, 0);
    }

    cout << ans << endl;
}



Measured memory_bytes: 10144
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	N--;
	vector<int> B(N);
	rep(i, N) cin >> B.at(i);
	int ans = B.at(0);
	if (N > 1)
		rep(i, N - 1) ans += min(B.at(i), B.at(i + 1));
	ans += B.at(N - 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <queue>
#include <functional>
using namespace std;
int main()
{
	int n,k;
	int node[101][101];
	while(cin>>n>>k,n|k){
	
		for(int i=0; i<=n; i++)
			for(int j=0; j<=n; j++)
				node[i][j] = INT_MAX;
		
		while(k--){
			int m;
			cin>>m;
			if( m ){
				int c,d,e;
				cin>>c>>d>>e;
				node[c][d] = node[d][c] = min(node[c][d],e);
			}else{
				int a,b;
				cin>>a>>b;
				/*
				for(int i=1; i<=n; i++){
					for(int j=1; j<=n; j++)
						printf("%13d,",node[i][j]);
					puts("");
				}*/
				int memo[101];
				priority_queue< pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
				for(int i=0; i<=n; i++)memo[i]=INT_MAX;
				pq.push(make_pair(0,a));
				memo[a]=0;
				while( !pq.empty() ){
					pair<int,int> pi = pq.top();
					if( pi.second == b )break;
					pq.pop();
					for(int i=1; i<=n; i++){
						if( node[pi.second][i]!=INT_MAX &&
							 node[pi.second][i]+pi.first < memo[i] ){
							memo[i] = node[pi.second][i] + pi.first;
							pq.push(make_pair(memo[i],i));
						}
					}
				}
				printf("%d\n",memo[b]==INT_MAX?-1:memo[b]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 952
/*input
7
nikoandsolstice
*/

#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#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(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
 
#ifdef Voneone
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); 
    cout.write(names, comma - names) << " : " << arg1 << " | "; 
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 

 


 
void solve() 
{ 
 

    int k;cin >> k;
    string s; cin >> s;

    if(s.length() <= k){
        cout << s;
        return;
    }


    cout << s.substr(0, k) << "...";


 
} 
 
 
 
 
signed main()
{
 
    
    #ifdef _DEBUG
    inputFile;
    #endif
    #ifndef __CINP
    fast;
    #endif
 
 
    int T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
        
        
 
    }
    
    
    return 0;
 
}
 



Measured memory_bytes: 3656
#include <iostream>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define mp make_pair
#define fname ""
#define fi first
#define se second
#define sz(a) (int)a.size()
#define pb push_back
#define fo(i,k,n) for(int i=k; (int)i<n; ++i)
#define rep(i,n,k) for(int i=n; (int)i>=k; --i)
#define all(v) v.begin(), v.end()
#define it ::iterator
#define forit(it,v) for(__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)


const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 100100;

int n;
string s;
deque<char> q,ans;

int main(){
    
    cin>>n>>s;
    int cnt = 0;
   	
   	int l=0, r=0;
   	fo(i,0,n){
   		if(s[i] == '('){
   			l++;
   		}
   		else{
   			if(l)
   				l--;
   			else
   				r++;
   		}
   	}

   	while(r--)
   		cout<<'(';
   	cout<<s;
   	while(l--)
   		cout<<')';

    
    return 0;
}









Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[10];
	int i, j, max;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &a[i]);
	}
	
	for (i = 0; i < 9; i++){
		for (j = i + 1; j < 10; j++){
			if (a[i] < a[j]){
				max = a[j];
				a[j] = a[i];
				a[i] = max;
			}
		}
	}
	printf("%d\n", a[0]);
	printf("%d\n", a[1]);
	printf("%d\n", a[2]);
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,x;
    std::cin >> n >>x;
    int len=0;
    int ans=1;
    for (int i = 0; i < n; i++) {
        int tmp;
        std::cin >> tmp;
        len+=tmp;
        if(len<=x)ans++;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int n,k;
	cin >> n >> k;
	int s[n] = {};
	int d;
	int su;
	
	REP(i,k){
		cin >> d;
		REP(j,d){
			cin >> su;
			s[su-1]+=1;
		}
	}
	
	int ans=0;
	REP(i,n){
		if(s[i] == 0){
			ans++;
		}
	}
	
	cout << ans << endl;
	
	
	
	
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

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

const ll seica = 5001;

ll dp[seica][seica];

int main(){
	
	int n;cin >> n;
	vector<pair<ll,pair<ll,ll>>> v;
	
	REP(i,n){
		ll a,b;cin >> a >> b;
		v.PB(MP(a+b,MP(a,b)));
	}
	
	sort(ALL(v));
	
	REP(i,seica)REP(j,seica)dp[i][j] = LLINF;
	dp[0][0] = 0;
	
	REP(i,n){
		auto now = v[i].SE;
		REP(j,n){
			if(dp[i][j] != LLINF){
				dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
				if(now.FI >= dp[i][j]){
					dp[i+1][j+1] = min(dp[i][j] + now.SE,dp[i+1][j+1]);
				}
			}
		}
	}
	
	ll ans = 0;
	
	REP(i,seica){
		if(dp[n][i] != LLINF)ans = i;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 195904
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(num, mat) = readLine.split(" ").map(_.toInt)
    val data = for (i <- 1 to num) yield (readLine.split(" ").map(_.toInt).head)
    val matMin = data.sorted.head
    val dntMin = data.length
    val dnt = ((mat - data.sum) / matMin).toInt + dntMin
    println(dnt)
  }
}


Measured memory_bytes: 25416
N = int(input())
cards = list(map(int, input().split(" ")))

cards.sort()
cards.reverse()

p1 = 0
p2 = 0

for i in range(N):
    if i%2==0:
        p1+=cards[i]
    else:
        p2 += cards[i]

print(p1-p2)

Measured memory_bytes: 3060