akhauriyash/Code-Regression huggingface dataset:
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int n, k;

vector<int> group[3];
int d[31][31], costA[31], costB[31], costC[31], ret = 1e9;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n >> k;
    
    int a,b,c; a = b = c = 1e9;
    
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++) cin >> d[i][j];
    
    
    
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            int x;
            cin >> x;
            group[(i+j)%3].push_back(x);
        }
    
    for (int i = 1; i <= k; i++) //arbitrary color
    {
        for (auto e : group[0]) costA[i] += d[e][i];
        for (auto e : group[1]) costB[i] += d[e][i];
        for (auto e : group[2]) costC[i] += d[e][i];
    }
    
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int w = 1; w <= k; w++)
            {
                if (i == j || i == w || j == w) continue;
                ret = min(costA[i]+costB[j]+costC[w], ret);
            }
    
    cout << ret << '\n';
    
    return 0;
    
}




Measured memory_bytes: 1520
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	
	int C[VMAX+1];
	int n, i, j;
	scanf("%d",&n);
	
	A=malloc(sizeof(short)*n+1);
	B=malloc(sizeof(short)*n+1);
	
	for(i=0;i<=VMAX;i++)C[i]=0;
	
	for(i=0;i<n;i++){
		scanf("%hu",&A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i=1;i<=VMAX;i++)C[i]=C[i]+C[i-1];
	
	for(j=1;j<=n;j++){
		B[C[A[j]]]=A[j];
		C[A[j]]--;
	}
	
	for(i=1;i<=n;i++){
		if(i>1)printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 9584
#include <stdio.h>

int main(void)
{
    char S[4];
    int i,f=0;

    scanf("%s",S);

    for(i=0; i<3; i++){
        if(S[i] == S[i+1]){
            f=1;
        }
    }

    if(f==0){
        printf("Good\n");
    } else {
        printf("Bad\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;

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

	ll ans = 0;
	ans = n / (a + b) * a;
	if (n % (a + b) > 0 && n % (a + b) <= a)ans += (n % (a + b));
	else if (n % (a + b) > a)ans += a;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = s.nextInt();
        }
      // we are filling the dp from 0 to k , for the ans we check wheather at k
      // point First player is reachable or not...
        boolean[] dp = new boolean[k+1];
       Arrays.fill(dp,false);  // Initially all are unreachable state
        for(int i = 1; i <= k; i++){
            for(int j = 0; j < n; j++){
                if(i < a[j]) 
                    break;
              if(dp[i-a[j]]==false){ 
                dp[i]=true;    //it means this state is reachable 
                break;
              }         
            }
        }
        System.out.println(dp[k] ? "First" : "Second");
    }
}


Measured memory_bytes: 24020
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include <map>
#include <stack>

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


int main(){
  string s;
  cin >> s;
  long long k;
  cin >> k;
  char res;
  int n,i;
  rep(i,s.length()){
    if (s[i] != '1'){
      res = s[i];
      n = i;
      break;
    }
  }
  if (k <= n) cout << '1' << endl;
  else cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())	
ans=["Positive", "Negative", "Zero"]
if a > 0:
    print(ans[0])
elif a<=0 and b>=0:
    print(ans[2])
elif (b-a)%2 == 0:
    print(ans[1])
else:
    print(ans[0])



Measured memory_bytes: 2940
def enqueue(queue, item)
  queue << item
end
def dequeue(queue)
  queue.shift
end

n, q = gets.split.map(&:to_i)
queue = []
n.times do
  name, need = gets.split
  need = need.to_i
  queue << {name: name, need: need}
end
time = 0
until queue.empty?
  current = dequeue(queue)
  if current[:need] <= q
    puts "#{current[:name]} #{time + current[:need]}"
    time += current[:need]
  else
    current[:need] = current[:need] - q
    time += q
    enqueue(queue, current)
  end
end



Measured memory_bytes: 21620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
	int n, count = 0;
	cin >> n;
	vector<int> a(n);
	rep(i, n)
		cin >> a[i];
	for(int i=0;i<n-1;i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
					int	x = a[i];
					a[i] = a[minj];
					a[minj] = x;
					if(i!=minj)
					count++;
	}
		rep(i, n) {
			if (i != n - 1)
				cout << a[i] << " ";
			else
				cout << a[n - 1] << endl;
		}
		cout << count << endl;
	
}




Measured memory_bytes: 3120
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 5e5 + 6;

vector <int> g[N];
bool u[N];

vector <int> t;

void dfs(int v) {
  u[v] = true;
  for (int x : g[v]) {
    if (!u[x]) {
      dfs(x);
    }
  }
  t.push_back(v);
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == '<') {
      g[i].push_back(i + 1);
    } else {
      g[i + 1].push_back(i);
    }
  }
  int n = (int) s.size() + 1;
  for (int i = 0; i < n; i++) {
    if (!u[i]) {
      dfs(i);
    }
  }
  reverse(t.begin(), t.end());
  vector <int> dp(n);
  ll sm = 0;
  for (int v : t) {
    for (int j : g[v]) {
      dp[j] = max(dp[j], dp[v] + 1);
    }
    sm += dp[v];
  }
  cout << sm << endl;
}


Measured memory_bytes: 56468
#include<cstdio>
#include <vector>
#include <set>

inline int f(int n) {
    return n%2==0?n/2:3*n+1;
}

int main(){
    int i=1,s,ns;
    scanf("%d",&s);
    ns=s;
    std::set<int> ss;
    ss.insert(s);
    while(!ss.count(f(ns))){
        ss.insert(f(ns));
        ns=f(ns);i++;
    }
    printf("%d",i+1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(ll, a, v, b, w, t);
    CoutYN(abs(a-b) <= (v-w)*t);
}








Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
void dfs(vector<int> arr[], vector<bool> &vis, int s) {

	vis[s] = true;
	// cout << s << " ";
	for (auto i : arr[s]) {
		if (!vis[i]) {
			dfs(arr, vis, i);
		}
	}

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		vector<int> arr[n];
		for (int i = 0; i < m; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--;
			b--;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}

		vector<bool> vis(n, false);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (!vis[i]) {
				ans++;
				dfs(arr, vis, i);
				// cout << endl;
			}
		}
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 13820
#include <stdio.h>
#define MAX 100
#define INF 1<<21
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[MAX][MAX],dis[INF];
int head,tail,color[MAX];
int Q[MAX];

void bfs(void);
void enqueue(int);
int dequeue(void);

int main(){
  int i,j,u,v,k;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      A[u][v]=1;
    }
  }

  bfs();

  return 0;
}

void bfs(){
  int i,j,s=0;

  for(i=0;i<n;i++){
    color[i]=WHITE;
    dis[i]=INF;
  }
  dis[s]=0;
  head=0;
  tail=0;
  enqueue(s);
  
  while(head!=tail){
    i=dequeue();
    for(j=0;j<n;j++){
      if(A[i][j] && color[j]==WHITE){
	color[j]=GRAY;
	dis[j]=dis[i]+1;
	enqueue(j);
      }
      color[i]=BLACK;
    }
  }
  for(i=0;i<n;i++){
    if(dis[i]==INF) dis[i]=-1;
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i+1,dis[i]);
    }
}

void enqueue(int s){
   Q[tail]=s;
  if(tail+1==MAX){
    tail=0;
  }
  else tail++;
}

int dequeue(){
  int i;

  i=Q[head];
  if(head+1==MAX){
    head=0;
  }
  else head++;
  return i;
}

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

int i,j,l,m,n=INT_MAX,k,c=0;
l=s.length();
m=t.length();
for(i=0;i<=(l-m);i++){
    for(j=i,k=0;k<m;k++,j++){
        if(s[j]!=t[k]){
            c++;
        }
    }
    n=min(n,c);
    c=0;
}
cout<<n;
}


Measured memory_bytes: 3628
N,M = map(int,input().split())
A = []
B = []
for i in range(N):
	a = list(input())
	A.append(a)
for j in range(M):
	b = list(input())
	B.append(b)

ans = "No"

for i in range(N-M+1):
	for j in range(N-M+1):
		c = 0
		for k in range(M):
			for l in range(M):
				if A[i+k][j+l] == B[k][l]:
					c+=1
		if c == M**2:
			ans = "Yes"
			break

print(ans)

Measured memory_bytes: 3064
def main():
    n = int(input())
    l = list(input())
    ans = l.count('R') * l.count('G') * l.count('B')
    for c in range(n):
        center = l[c]
        for dif in range(n):
            if dif + c > n - 1 or c - dif < 0:
                continue
            left = l[c - dif]
            right = l[dif + c]
            if left != center and center != right and right != left:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 73644
import collections


class UnitDict(dict):

    def __init__(self, iterable=None, wrapper=lambda x: x):
        super().__init__(self)
        self.wrapper = wrapper
        if iterable is not None:
            self.update(iterable)

    def __missing__(self, key):
        self[key] = self.wrapper(key)
        return self[key]


class UnionFind(object):

    def __init__(self, nodes=None):
        self.par = UnitDict(wrapper=lambda x: x)
        self.rank = collections.defaultdict(int)
        self.groups = UnitDict(wrapper=lambda x: {x})
        if nodes is not None:
            for node in nodes:
                _, _, _ = self.par[node], self.rank[node], self.groups[node]

    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r

    def are_same(self, node1, node2):
        return self.root(node1) == self.root(node2)

    def elements(self, node):
        return self.groups[self.root(node)]

    def size(self, node):
        return len(self.elements(node))

    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            self.groups[x].update(self.groups[y])
            self.groups[y].clear()
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def grouper(self):
        roots = [x for x in self.par.keys()]
        groups = []
        for root in roots:
            if list(self.elements(root)) not in groups:
                groups.append(list(self.elements(root)))
        return groups


N, M = map(int, input().split())
P = list(map(int, input().split()))
XY = [list(map(int, input().split())) for i in range(M)]

graph = UnionFind(range(N))
for x, y in XY:
    graph.unite(P[x-1], P[y-1])

ans = 0
for i in range(N):
    if P[i] == i+1:
        ans += 1
    elif graph.are_same(i+1, P[i]):
        ans += 1

print(ans)

Measured memory_bytes: 150292
#include <cstdio>

int prim[10000000];

int main()
{

	int n, i, j;

	for( i = 2; i < 10000000 / 2; i++ ){

		for( j = 2; j < 10000000 / 2; j++ ){

			if( i * j > 10000000 || prim[i] == 1 ) break;
			
			prim[i*j] = 1;

		}

	}

	while( 1 ){

		scanf( "%d", &n );

		if( n == 0 ) break;

		for( i = n; n >= 0; i-- ){

			if( prim[i] == 0 ){

				if( prim[i-2] == 0 && prim[i-6] == 0 && prim[i-8] == 0 ){

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

					break;

				}

			}

		}

	}

	return 0;

}

Measured memory_bytes: 40088
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

//matp G(N);
void graphmake(ll E,matp &GA,matp &GB){
  rep(i,E){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    GA.at(a-1).push_back(P(b-1,c));
    GA.at(b-1).push_back(P(a-1,c));
    GB.at(a-1).push_back(P(b-1,d));
    GB.at(b-1).push_back(P(a-1,d));
  }
}
//vec d(N);
void dijkstra(ll s,vec &d, matp &G,ll V){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,V) d.at(i)=INF;
  d.at(s)=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d.at(v)<p.first) continue;
    rep(i,G.at(v).size()){
      P e=G.at(v).at(i);
      if(d.at(e.first)>d.at(v)+e.second){
        d.at(e.first)=d.at(v)+e.second;
        que.push(P(d.at(e.first),e.first));
      }
    }
  }
}

int main(){
  ll N,M,s,t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  matp GA(N),GB(N);
  vec dA(N),dB(N);
  graphmake(M,GA,GB);
  dijkstra(s,dA,GA,N);
  dijkstra(t,dB,GB,N);
  priority_queue<P> Q;
  rep(i,N){
    Q.push(P(-dA.at(i)-dB.at(i),i));
  }
  rep(i,N){
    while(Q.top().second<i){
      Q.pop();
    }
    cout << 1000000000000000+Q.top().first << endl;
  }
}

Measured memory_bytes: 22520
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main()
{
  int T, t[30], N, interview[101];
    
  while(cin >> T, T) {
    memset(interview, 0, sizeof(interview));
    
    for(int i = 0; i < T; i++) {
      cin >> t[i];
      t[i] = (1 << t[i]) - 1;
    }
    cin >> N;
    for(int i = 0; i < N; i++) {
      int D, M;
      cin >> D >> M;
      interview[D] |= 1 << M;
    }

    int dp[31];
    fill_n(dp, T, INF);
    dp[T - 2] = 0;
    for(int i = 0; i < 101; i++) {
      int reset = dp[T - 1];
      for(int j = T - 2; j >= 0; j--) {
        dp[j + 1] = t[j + 1] & interview[i] ? INF : dp[j];
        reset = min(reset, dp[j] + 1); 
      }
      dp[0] = reset;
    }
    cout << *min_element(dp, dp + T) << endl;
  }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;

    int c = 0;
    int res[SIZE] = {};
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'L') {
            res[i - 1] += c / 2 + c % 2;
            res[i] += c / 2;
            c = 0;

        } else {
            ++c;

        }
    }

    c = 0;
    for(int i = s.size() - 1; i >= 0; --i) {
        if(s[i] == 'R') {
            res[i + 1] += c / 2 + c % 2;;
            res[i] += c / 2;
            c = 0;

        } else {
            ++c;

        }
    }

    for(int i = 0; i < s.size(); ++i) {
        cout << res[i] << " ";

    }
    cout << endl;
    return 0;
}


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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    string s;
    cin >> k >> s;
    int sl = s.length();
    if (k >= sl) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


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

int main()
{
  string S, T;
  cin >> S >> T;
  
  int ST[3005][3005] = {};
  int len_S = S.length(), len_T = T.length();
  for (int i = 1; i <= len_S; i++)
  {
    for (int j = 1; j <= len_T; j++)
    {
      if(S[i - 1] == T[j - 1])
      {
        ST[i][j] = ST[i - 1][j - 1] + 1;
      }
      else
      {
        ST[i][j] = max(ST[i - 1][j], ST[i][j - 1]);
      }
    }
  }
  
  /*
  for (int i = 0; i <= len_S; i++)
  {
    for (int j = 0; j <= len_T; j++)
    {
      cout << ST[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  string ans = "";
  int L = ST[len_S][len_T];
  int a = len_S, b = len_T;
  while (L > 0)
  {
    if (S[a - 1] == T[b - 1])
    {
      ans = S[a - 1] + ans;
      L--; a--; b--;
    }
    else if (ST[a - 1][b] >= ST[a][b - 1])
    {
      a--;
    }
    else // ST[a - 1][b] < ST[a][b - 1]
    {
      b--;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//配列,座標
/*array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
array<int, 4>dir_x2 = { 0,0,1,-1 };
array<int, 4>dir_y2 = { 1,-1,0,0 };
char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };*/

//Union Find
/*class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};*/

//最大公約数,最小公倍数
/*LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}*/

//組み合わせ
/*long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}
long nHr(int n, int r) {
	n = n + r - 1;
	return nCr(n, r);
}*/

//素数判定
/*bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}*/

//桁数
/*LLI GetDigit(LLI num) {
	LLI digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}*/

//サンプル
/*const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}*/

//サンプル
/*vector<vector<int>>sub;
int dfs(int id) {
	if (sub[id].size() == 0) {
		return 1;
	}
	int minP = (int)1e9;
	int maxP = 0;
	for (int i : sub[id]) {
		int P = dfs(i);
		minP = min(minP, P);
		maxP = max(maxP, P);
	}
	return minP + maxP + 1;
}*/

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl
//cout << "Yes" << endl;
//cout << "No" << endl;



int main(void) {
	LLI N,res = 0;
	cin >> N;
	res += (N / 500) * 1000;
	N %= 500;
	res += (N / 5) * 5;
	cout << res << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      _n: usize,
      c: Bytes
   }
   let mut ans = 0;
   let r: usize = c.iter().map(|&b| if b == b'R' { 1 } else { 0 }).sum();
   for i in 0..r {
      if c[i] == b'W' {
         ans += 1;
      }
   }

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


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 200005;
const int mod = 1e9 + 7;

int n, m, p, q, fac[MAXN], inv[MAXN];

inline int C(int x, int y)
{
	return 1LL * fac[x + y] * inv[x] % mod * inv[y] % mod;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read(), p = Read(), q = Read(), fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i <= n + m; i ++)
		fac[i] = 1LL * fac[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 2; i <= n + m; i ++)
		inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
	int ans = C(n - 1, m - 1);
	for (int i = 1; i <= q; i ++)
		ans = (ans - 1LL * C(n - p - 1, i - 1) * C(p - 1, m - i) % mod + mod) % mod;
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

char str[200005];
char qq[200005][2];

int main(int argc, char* argv[])
{
    long n, q;
    scanf("%ld%ld\n", &n, &q);
    scanf("%s", str);

    long i;
    for(i=0; i<q; i++) {
        char str0[5]={0};
        scanf("%s", str0);
        qq[i][0]=str0[0];
        scanf("%s", str0);
        qq[i][1]=str0[0];
    }

    long curr=n;
    for(i=q-1; i>=0; i--) {
        if(curr>0 && str[curr-1]==qq[i][0] && qq[i][1]=='R') {
            curr--;
        }
        else if(str[curr]==qq[i][0] && qq[i][1]=='L') {
            curr++;
        }
    }

    long curr1=-1;
    for(i=q-1; i>=0; i--) {
        if(curr1==n-1) break;
        if(curr1<n-1 && str[curr1+1]==qq[i][0] && qq[i][1]=='L') {
            curr1++;
        }
        else if(str[curr1]==qq[i][0] && qq[i][1]=='R') {
            curr1--;
        }
    }
    //printf("%ld, %ld\n", curr, curr1);
    printf("%ld\n", MAX(curr-curr1-1, 0));
    return 0;
}


Measured memory_bytes: 768
def generatorDiv(int_list, power_of, exponent):
    for num in int_list:
        yield num//((power_of)**exponent)

n = int(input())
a = list(map(int, input().split()))
counter = 0
gen = generatorDiv(a, 2, counter)

while 1:
    binOR = 0
    for num in gen:
        binOR = binOR | num
    if (binOR & 1) == 0:
        counter += 1
        gen = generatorDiv(a, 2, counter)
    else:
        break;
        
print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.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() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    vector<int> sum_w(n);

    if(s[0] == 'W') sum_w[0] = 1;
    else sum_w[0] = 0;

    for(int i = 1; i < n; ++i) {
        if(s[i] == 'W') sum_w[i] = sum_w[i-1] + 1;
        else sum_w[i] = sum_w[i-1];
    }

    
    /*
    rep(i, n) {
        cout << sum_w[i] << " ";
    }
    cout << endl; 
    */
    

    int ans = 1001001001;

    rep(i, n) {
        int l_wcnt = 0;
        int r_wcnt = 0;
        int r_ecnt = 0;
        int now = sum_w[i];
        if(s[i] == 'W') {
            l_wcnt = now - 1;
            r_wcnt = sum_w[n-1] - now; // 右のW
            r_ecnt = (n - (i+1)) - r_wcnt;
        }
        else {
            l_wcnt = now;
            r_wcnt = sum_w[n-1] - now;
            r_ecnt = (n - (i+1)) - r_wcnt;
        }
        ans = min(ans, (l_wcnt+r_ecnt));

        // cout << l_wcnt << " " << r_wcnt << " " << r_ecnt << "        " << ans << endl;

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

Measured memory_bytes: 4772
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]x=new int[N];
		int max=0;int sum=0;
		for(int i=0;i<N;i++) {
			int p=sc.nextInt();
			x[i]=p;
			sum+=x[i];
		}
		max=x[0];
		for(int j=1;j<N;j++) {
			if(x[j]>max) {
				max=x[j];
			}
		}
		System.out.print(sum-max+max/2);

		sc.close();
	}

}

Measured memory_bytes: 21716
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXLEN = 20;

char s[MAXLEN + 1];
char ans[MAXLEN + 1];

void solve() {
	REP(i, 3) ans[i] = s[i]; ans[3] = '\0';
}

void run() {
	scanf("%s", s);
	solve();
	printf("%s\n", ans);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

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; }

const long long INF = 1LL << 60;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
ll n, m;
ll ma = 1000000000 + 7;
vector<vector<ll>> uv;
vector<bool> used;
int main() {
	string in;int res=0;
	cin >> in;bool flg = false;int n = 0;
	for (int i = 0;i < in.length();i++) {
		if (in[i] == 'A' || in[i] == 'T' || in[i] == 'G' || in[i] == 'C') {
			if (!flg) {
				n = 0;
			}
			n++;
			flg = true;
		}
		else {
			flg = false;
		}
		chmax(res, n);
	}
	cout << res << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int sz = 1 << 16;
typedef pair< unsigned short, int > Pi;
vector< Pi > seg[2 * sz + 1];
int x[500000], y[500000];
int sx[20000], sy[20000], tx[20000], ty[20000];
vector< pair< unsigned short, Pi > > buff;
vector< int > nums, nums2;
vector< int > ret;
void InitRange(int k, int l, int r) {
  if(l + 1 >= r) {
    return;
  } else {
    InitRange(2 * k + 1, l, (l + r) >> 1);
    InitRange(2 * k + 2, (l + r) >> 1, r);
    if(k >= 23) {
      seg[k].resize(seg[2 * k + 1].size() + seg[2 * k + 2].size());
      merge(seg[2 * k + 1].begin(), seg[2 * k + 1].end(), seg[2 * k + 2].begin(), seg[2 * k + 2].end(), seg[k].begin());
    }
  }
}
void PrintRange(unsigned short a, unsigned short b, unsigned short low, unsigned short high, int k, int l, int r) {
  if(a >= r || b <= l) {
    return;
  } else if(a <= l && r <= b && k >= 23) {
    for(vector< Pi >::iterator it = lower_bound(seg[k].begin(), seg[k].end(), Pi(low, -1)); it != seg[k].end() && it -> first < high; it++) { 
      ret.push_back(it -> second);
    }
  } else {
    PrintRange(a, b, low, high, 2 * k + 1, l, (l + r) >> 1);
    PrintRange(a, b, low, high, 2 * k + 2, (l + r) >> 1, r);
  }
}
  
int main() {
  int n, q;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
  }
  scanf("%d", &q);
  for(int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &sx[i], &tx[i], &sy[i], &ty[i]);
    nums.push_back(sx[i] - 1);
    nums.push_back(tx[i]);
    nums2.push_back(sy[i] - 1);
    nums2.push_back(ty[i]);
  }
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
  sort(nums2.begin(), nums2.end());
  nums2.erase(unique(nums2.begin(), nums2.end()), nums2.end());
  for(int i = 0; i < n; i++) {
    x[i] = lower_bound(nums.begin(), nums.end(), x[i]) - nums.begin();
    y[i] = lower_bound(nums2.begin(), nums2.end(), y[i]) - nums2.begin();
    buff.push_back(make_pair(x[i], make_pair(y[i], i)));
  }
  sort(buff.begin(), buff.end());
  for(int i = 0; i < n; i++) {
    seg[buff[i].first + sz - 1].push_back(buff[i].second);
  }
  InitRange(0, 0, sz);
 
  for(int i = 0; i < q; i++) {
    sx[i] = lower_bound(nums.begin(), nums.end(), sx[i]) - nums.begin();
    tx[i] = upper_bound(nums.begin(), nums.end(), tx[i]) - nums.begin();
    sy[i] = lower_bound(nums2.begin(), nums2.end(), sy[i]) - nums2.begin();
    ty[i] = upper_bound(nums2.begin(), nums2.end(), ty[i]) - nums2.begin();

    PrintRange(sx[i], tx[i], sy[i], ty[i], 0, 0, sz);
    sort(ret.begin(), ret.end());
    for(vector< int >::const_iterator it = ret.begin(); it != ret.end(); it++) {
      printf("%d\n", *it);
    }
    printf("\n");
    ret.clear();
  }
  
}

Measured memory_bytes: 62672
#include<bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define len(x) (int)(x).size()
#define rep(i,x) for(int i=0;i<x;++i)

typedef long long ll;
typedef long double ld;

using namespace std;

signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    vector < int > a(n);
    for(auto &i : a)cin >> i;
    sort(all(a));
    for(int i = 1;  i < n; ++i)
        if(a[i] == a[i - 1])return cout << "NO" , 0;
    cout <<  "YES";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int a,b,c,temp;
     cin>>a>>b>>c;
     temp=a;
     a=b;
     b=temp;
     temp=a;
     a=c;
     c=temp;
     cout<<a<<" "<<b<<" "<<c<<endl;
     return 0;
 }


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

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

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    int count5 = 0, count7 = 0;
    for(auto data : a){
        if(data == 5) count5++;
        else if(data == 7) count7++;
    }
    
    string ans = "NO";
    
    if(count5==2 && count7==1){
        ans = "YES";
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

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


void main() {
    int h, w;
    scan(h, w);

    auto c = new int[][](10, 10);
    iota(10).each!(i => c[i] = readln.split.to!(int[]));

    auto a = new int[][](h, w);
    iota(h).each!(i => a[i] = readln.split.to!(int[]));

    auto d = new int[][](10, 10);
    foreach (i ; 0 .. 10) {
        foreach (j ; 0 .. 10) {
            d[i][j] = c[i][j];
        }
    }

    foreach (k ; 0 .. 10) {
        foreach (i ; 0 .. 10) {
            foreach (j ; 0 .. 10) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans;

    foreach (i ; 0 .. h) {
        foreach (j ; 0 .. w) {
            if (a[i][j] > -1) {
                ans += d[a[i][j]][1];
            }
        }
    }

    writeln(ans);
}









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

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

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


Measured memory_bytes: 3452
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<cmath>
#include<stack>
#include<iomanip>
#include<cstdio>
using namespace std;
int isHuiwen(string s,int start,int end)
{
    //int len=s.length(),fin=len-1,use=len/2;
    int fin=end,use=(end+1)/2;
    
    for(int i = 0;i<use;i++,fin--)
    {
        if(s.at(i)!=s.at(fin))
            return 0;
    }
           return 1;
}
int main()
{
    long long int n,tmp,tool=0,min=200005,max=-1;
    unordered_map<long long int,long long int> hash;
    vector<long long int> all,ans;
    set<long long int> list;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>tmp;
        if(tmp<min)
            min=tmp;
        if(tmp>max)
            max=tmp;
        hash[tmp]++;
        list.insert(tmp);
        all.push_back(tmp);
    }
    int last;//用于记录上一次回去的数字
    //1次迭代，后续跟进就好咯！
    for(int i = 0;i<n;i++)
    {
        if(i==0)
            hash[all.at(i)]--;
        //下面要开始算数咯
        if(i==0)
        for (auto value :list) {
          // valueを使う
            if(hash[value]>=2)
                tool+=hash[value]*(hash[value]-1)/2;
        }
        else
        {
            if(hash[last]>1)
                tool+=hash[last]-1;
            hash[all.at(i)]--;
            if(hash[all.at(i)]>0)
                tool-=hash[all.at(i)];
        }
        ans.push_back(tool);
        hash[all.at(i)]++;
        last=all.at(i);
    }
    for(int i=0;i<n;i++)
       {
           cout<<ans.at(i);
           //if(i!=n-1)
               cout<<endl;
       }
    return 0;
}


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<vector<ll>> dp(2, vector<ll>(n));
    array<int, 3> happy;

    auto &cur = dp[0], &nxt = dp[1];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) cin >> happy[j];
        nxt[0] = happy[0] + max(cur[1], cur[2]);
        nxt[1] = happy[1] + max(cur[0], cur[2]);
        nxt[2] = happy[2] + max(cur[0], cur[1]);

        swap(cur, nxt);
    }

    cout << max({cur[0], cur[1], cur[2]}) << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	const LL INF = 1LL << 55;

	int n, m, s, t;
	cin >> n >> m >> s >> t;
	--s;
	--t;
	VV(pll) Gs[2];
	Gs[0].resize(n);
	Gs[1].resize(n);
	for(int i = 0; i < m; ++i){
		int u, v, c[2];
		cin >> u >> v >> c[0] >> c[1];
		--u;
		--v;
		for(int k = 0; k < 2; ++k){
			Gs[k][u].emplace_back(v, c[k]);
			Gs[k][v].emplace_back(u, c[k]);
		}
	}

	vector<LL> dss[2];
	for(int k = 0; k < 2; ++k){
		auto &G = Gs[k];
		auto &ds = dss[k];
		ds.assign(n, INF);
		int start = k == 0 ? s : t;
		priority_queue<pll> pq;
		pq.emplace(0, start);
		ds[start] = 0;
		while(!pq.empty()){
			LL d = -pq.top().first;
			int u = pq.top().second;
			pq.pop();
			if(ds[u] != d){ continue; }
			for(cauto e : G[u]){
				int v = e.first;
				LL nd = d + e.second;
				if(ds[v] > nd){
					ds[v] = nd;
					pq.emplace(-nd, v);
				}
			}
		}
	}

	LL base = 1000000000000000LL;
	LL minc = INF;
	vector<LL> ans(n);
	for(int i = n - 1; i >= 0; --i){
		chmin(minc, dss[0][i] + dss[1][i]);
		ans[i] = base - minc;
	}
	for(int i = 0; i < n; ++i){
		printf("%lld\n", ans[i]);
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 19012
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;

int main()
{
    int n;
    scanf("%d",&n);
    int sum;
    for(int i=1;;i++)
        if(i*1000>=n)
    {
        sum=i*1000;
        break;
    }
    printf("%d\n",sum-n);
    return 0;
}


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

int main() {
  ll A, B;
  ll V, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;

  if (V <= W) {
    cout << "NO" << endl;
    return 0;
  }

  if ((V-W) * T >= abs(A-B)) {
      cout << "YES" << endl;
  } else {
      cout << "NO" << endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  int Sum=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(x>K-x)
      Sum+=(K-x)*2;
    else
      Sum+=(x*2);
  }
  cout<<Sum<<endl;
}

Measured memory_bytes: 256
# ABC104 B-AcCepted
S = input()

c1 = False
c2 = False
c3 = False

if S[0]=="A":
    c1 = True

if S.count("C",2,-1) == 1:
    c2 = True

S = S.replace("A","").replace("C","")

if S.islower():
    c3 = True

if c1 == True and c2 == True and c3 == True:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#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 sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


string to_string(string s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(char ch) {
	return string("'")+ch+string("'");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class InputIterator>
string to_string (InputIterator first, InputIterator last) {
	bool start = true;
	string res = "{";
	while (first!=last) {
		if (!start) {
			res += ", ";
		}
		start = false;
		res += to_string(*first);
		++first;
	}
	res += "}";
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



const int mod=998244353;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
	return res;
	}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=300005;

   
void solve(){
int a,b;
cin>>a>>b;
if(a>=13)cout<<b;
else if(a>=6&&a<=12)cout<<(double)b/2;
else cout<<0;
}
	

int main()
{   
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//cin>>tc;
	
    for(int i=0;i<tc;i++)
	{
		//cout<<"Case #"<<i+1<<": "; 
        solve();
		}
	
	}
/* Intuition > Logic 
 * If you are not confident please dont submit
 * When you feel like Quitting: Remember why you started
 * Game Theory == Skip
 * If n== 1e18 apply binary or Matrix expo

 *  I see those tears in your eyes
   I feel so helpless inside
   Oh love, there's no need to hide
   Just let me love you when your heart is tired
   Cold hands, red eyes
   Packed your bags at midnight
   They've been there for weeks
   You don't know what goodbye means
   Just roll up a cigarette
   Just forget about this mess
   Waiting on the sidelines
   From the sidelines
 */


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

const int maxn=1e5+7;
int a[maxn],b[maxn],id[maxn],ans,n,m;
priority_queue<int,vector<int>,less<int> > q;

bool cmp(int i,int j)
{
	return a[i]<a[j];
}

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i) {
		scanf("%d %d",&a[i],&b[i]);
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	int t=1;
	for(int i=1;i<=m;++i) {
		while(a[id[t]]<=i&&t<=n) q.push(b[id[t]]),t++;
		if(q.empty()) continue;
		ans+=q.top(),q.pop();
	}
	printf("%d",ans);
}

Measured memory_bytes: 2044
#!/usr/bin/env python3
import sys

def solve(N: int, S: "List[str]"):
    print(len(set(S)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 103548