akhauriyash/Code-Regression huggingface dataset:
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    /////////////////////
    // Write code below /
    /////////////////////
    int height, width;
    cin >> height >> width;
    vector<string> lines(height);
    for (int line_i = 0; line_i < height; line_i++) {
        cin >> lines.at(line_i);
    }
    
    // 上辺
    for (int i = 0; i < width + 2; i++) {
        cout << "#";
    }
    cout << endl;
    
    // 中段
    for (int line_i = 0; line_i < height; line_i++) {
        cout << "#" << lines.at(line_i) << "#" << endl;
    }
    
    // 下辺
    for (int i = 0; i < width + 2; i++) {
        cout << "#";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int Mod = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e5+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b, ll M)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans % M;
}


void task()
{
    //code here...
    
    int n, L;
    
    cin >> n >> L;
    vector<string> s(n);
    
    for(int K=0; K<n; K++){
		cin >> s[K];
	}
	
	sort(s.begin(), s.end());
	
	for(int K=0; K<n; K++) cout << s[K];
	cout << "\n";
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}



Measured memory_bytes: 3640
io = STDIN
n,x=io.gets.split.map(&:to_i)
$size={0=>1}
def size(n)
  return $size[n] if $size.has_key?(n)
  $size[n]=size(n-1)*2+3
end
def half_h(size)
  (size-3)/2
end
$f={}
def f(n,k)
  return 1 if n==0
  return $f[[n,k]] if $f.has_key?([n,k])
  h=size(n-1)+2
  return 0 if k==1
  if k<h
    rtn=f(n-1,k-1)
  elsif k==h
    rtn=f(n-1,h-2)+1
  else
    rtn=f(n-1,h-2)+1+f(n-1,k-h)
  end
  $f[[n,k]]=rtn
end
p f(n,x)


Measured memory_bytes: 3964
#include<stdio.h>
#define max 100

int main(){

  int n,i,j,l,k,m;

  scanf("%d",&n);

  int num[n][n];

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

  for(i = 0;i < n;i++){
    scanf("%d %d",&k,&m);
    for(j = 0;j < m;j++){
      scanf("%d",&l);
      num[k - 1][l - 1] = 1;
    }
  }
     
  for(i = 0;i < n;i++){
    for(j = 0;j < n -1;j++){
      printf("%d ",num[i][j]);
    }
    printf("%d",num[i][n-1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Qmax = 1e5;
int N, Q;
string S;
int L[Qmax], R[Qmax];

int main(){
	cin >> N >> Q >> S;
	for(int i=0; i<Q; i++) cin >> L[i] >> R[i];

	vector<int> cnt(N+1);
	for(int i=2; i<=N; i++){
		cnt[i] = cnt[i-1];
		if(S[i-2]=='A'&&S[i-1]=='C') cnt[i]++;
		//cout << i << " " << cnt[i] << endl;
	}

	for(int i=0; i<Q; i++){
		cout << cnt[R[i]]-cnt[L[i]] << endl;
	}

	return 0;
}


Measured memory_bytes: 2176
# -*- coding: utf-8 -*-

import sys

for line in sys.stdin.readlines():
    x, y = line.strip().split()

    if x == "0" and y == "0":
        break

    if int(x) < int(y):
        print("{} {}".format(x, y))
    else:
        print("{} {}".format(y, x))

Measured memory_bytes: 7792
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[[] for nn in range(n)]
for mm in range(m):
  a,b=map(int,input().split())
  ab[a-1].append(b-1)
  ab[b-1].append(a-1)
cnt=0
for i in range(n):
  hi=0
  for ll in ab[i]:
    hi=max(hi,h[ll])
  if hi<h[i]:
    cnt+=1
print(cnt)

Measured memory_bytes: 29480
#include<bits/stdc++.h>
#pragma GCC optimise ("0fast")
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void inline add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=100002;

bool f(int x){
	int cr=0;
	while(x){
		x/=10;
		cr++;
	}
	return cr&1;
}

void solve(){
	int ans=0;
	int n;
	cin>>n;
	int cur=1;
	for(int i=1;i<=n;i++){
		if(f(i))ans++;
		
	}
	cout<<ans;
	
}

 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void inline add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
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;
}
 
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;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}


Measured memory_bytes: 256
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int main(){
    int k; string s;
    cin >> k >> s;
    if(sz(s) <= k) cout << s << '\n';
    else{
        for(int i = 0;i < k; ++i) cout << s[i];
        cout << "..." << '\n';
    }
    return 0;
}

Measured memory_bytes: 3632
N,W=[int(x) for x in raw_input().split()]
A=[]
for i in range(N):
    w,v=[int(x) for x in raw_input().split()]
    A.append([w,v])
B=[[ 0  for i in range(W+1)] for j in range(N)]
B[0][W-A[0][0]]=A[0][1]

for i in range(1,N):
    w,v=A[i]
    for j in range(W-w+1):
        B[i][j]=max(B[i-1][j], B[i-1][j+w]+v)
    for j in range(W-w+1, W+1):
        B[i][j]=B[i-1][j]
print(max(B[-1]))


Measured memory_bytes: 111724
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXK 100005
#define MAXQ 100005
using namespace std;

int X, k, nrq, pos1, pos2, startVal, lastT, sign = -1;
int q[MAXQ], sol[MAXQ];
vector < pair <int, int> > v;

void update (int t) {
    int dif = sign * (t - lastT);
    lastT = t;

    startVal += dif;
    if (sign < 0) {
        if (startVal < 0) {
            pos1 = min (pos1 - startVal, X);
            startVal = 0;
        }
    }
    else {
        int endVal = startVal + pos2 - pos1;

        if (endVal > X)
            pos2 = max (pos2 - endVal + X, 0);
        startVal = min (startVal, X);
    }

    if (pos1 >= pos2)
        pos1 = pos2 = X;

    sign = -sign;
}

int query (int difT, int a) {
    int val;
    int endVal = startVal + pos2 - pos1;

    if (a <= pos1)
        val = startVal;
    else if (a >= pos2)
        val = endVal;
    else
        val = startVal + a - pos1;

    val += sign * difT;

    return max (min (val, X), 0);
}

int main () {
    ios::sync_with_stdio (0);

    cin >> X >> k;
    for (int i = 1; i <= k; ++i) {
        int t;
        cin >> t;
        v.push_back (make_pair (t, 0));
    }

    cin >> nrq;
    for (int i = 1; i <= nrq; ++i) {
        int t;

        cin >> t >> q[i];
        v.push_back (make_pair (t, i));
    }

    sort (v.begin (), v.end ());

    pos1 = 0, pos2 = X, startVal = 0;
    lastT = 0;
    for (auto x: v) {
        if (x.second == 0)
            update (x.first);
        else {
            sol[x.second] = query (x.first - lastT, q[x.second]);
        }
    }

    for (int i = 1; i <= nrq; ++i)
        cout << sol[i] << "\n";

    return 0;
}

Measured memory_bytes: 3696
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner (System.in);
		final int n = scan.nextInt();
		String[] str = new String[n];
		String[] str1 = new String[n];
		int[] number = new int[n];
		
		for ( int i = 0; i < n; i++) {
			str[i] = scan.next();
			str1[i] = str[i];
			number[i] = scan.nextInt();
		}
		scan.close();
		
		QuickSort (str, number, 0, n - 1);
		
		boolean flg = isStable (str, str1, number);
		
		if (flg) System.out.println("Stable");
		else System.out.println("Not stable");
		
		printArray (str, number);
		
	}
	
	static void QuickSort (String[] str, int[] data, int p, int r) {
		
		if (p < r) {
			int q = Partition (str, data, p, r);
			QuickSort (str, data, p, q - 1);
			QuickSort (str, data, q + 1, r);
		}
		
	}
	
	static int Partition (String[] str, int[] array, int p, int r) {
		int x = array[r];
		int i = p - 1;
		int temp;
		String strtemp;
		String strx = str[r];
		
		for (int j = p; j < r; j++) {
			if (array[j] <= x) {
				i++;
				temp = array[j];
				array[j] = array[i];
				array[i] = temp;
				
				strtemp = str[j];
				str[j] = str[i];
				str[i] = strtemp;
			}
		}
		
		array[r] = array[i + 1];
		array[i + 1] = x;
		
		str[r] = str[i + 1];
		str[i + 1] = strx;
		
		return i + 1;
	}
	
	static boolean isStable(String[] str, String[] array, int[] number) {
		int n = number.length;
		
		for ( int i = 0; i < n - 1; i++ ) {
			for ( int j = i + 1; j < n - 1; j++) {
				if (number[i] == number[j]) {
					for ( int a = 0; a < n ; a++) {
						if ( str[i] == array[a]) {
							for (int b = 0; b < n ; b++) {
								if (str[j] == array[b]) {
									if ( a > b ) {
										return false;
									}
								}
							}
						}
					}
				}
			}
		}
		
		return true;
	}
	
	static void printArray (String[] str, int[] data) {
		int n = data.length;
		for (int i = 0; i < n; i++) {
			System.out.println(str[i] + " " + data[i]);
		}
	}
}



Measured memory_bytes: 98528
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

class UFT{
public:
  vector<int> p;
  UFT(){}
  UFT(int N){
	p.resize(N,-1);
  }
  int par(int a){
	if(p[a]>=0){p[a]=par(p[a]);return p[a];}
	return a;
  }
  int size(int a){
	return -p[par(a)];
  }
  void unite(int a,int b){
	a=par(a);b=par(b);
	if(a==b)return;
	if(size(a)<size(b))swap(a,b);
	p[a]-=size(b);
	p[b]=a;
  }
};
int main(){
  int n,m;cin>>n>>m;
  int a[100001];
  int b[100001];
  for(int i=0;i<m;++i){
	cin>>a[i]>>b[i];
	a[i]--;b[i]--;
  }
  long long count[100001]={};
  count[m-1]=((long long)n*(n-1)/2);
  UFT uft(n);
  for(int i=m-1;i>0;--i){
	if(uft.par(a[i])==uft.par(b[i]))count[i-1]=count[i];
	else{
	  count[i-1]=count[i]-(uft.size(a[i])*uft.size(b[i]));
	  uft.unite(a[i],b[i]);
	}
  }
  for(int i=0;i<m;++i)
	cout<<count[i]<<endl;
  return 0;
}


Measured memory_bytes: 3328
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

/*
//https://algoogle.hadrori.jp/algorithm/prim.html
vector<int> prim(int root) {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    memset(used, 0, sizeof(used));
    que.push(pii(0,root));
    vector<int> T;
    int ret = 0;
    while(!que.empty()) {
        int cst = que.top().first, v = que.top().second;
        que.pop();
	//cout << "cur: " << v << endl;
        if(used[v]) continue;
	T.push_back(v);
        used[v] = 1;
        ret += cst;
        for(int i = 0; i < G[v].size(); i++)
            que.push(pii(G[v][i].first, G[v][i].second));
    }
    return T;
}
*/

//https://atcoder.jp/contests/nikkei2019-qual/submissions/4111304
#define MAX 100010
int n, m;
vector<int> v[MAX];
vector<int> tpv;
bool used[MAX];
int par[MAX];

//t: root
void tp(int t){
  used[t] = 1;
  REP(i, v[t].size()){
    //u: t -> i
    int u = v[t][i];
    if(used[u] == 1) continue;
    tp(u);
  }
  tpv.push_back(t);
  return;
}

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

  cin >> n >> m;
  vector<bool> bb(n+1, true);  
  REP(i, n+m-1){
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    bb[b] = false;
  }
  //leaf -> root
  FOR(i, 1, n+1) if(bb[i]) tp(i);
  /*
  for(auto itr = tpv.begin(); itr!=tpv.end(); itr++){
    cout << *itr << " ";
  }
  cout << endl;
  */
  //root -> leaf
  reverse(tpv.begin(), tpv.end());
  //各要素の親を設定
  REP(i, n){
    int t = tpv[i];
    REP(j, v[t].size()){
      int s = v[t][j];
      par[s] = t;
    }
  }
  REP(i, n) cout << par[i+1] << endl;
  
  return 0;
}


Measured memory_bytes: 12024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <bitset>
using namespace std;

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

    int N, C;
    cin >> N >> C;
    
    vector<tuple<int, int, int>> a(N);
    for(int i=0; i<N; i++){
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        a[i]=make_tuple(c, s, t);
    }

    sort(a.begin(), a.end());
    vector<tuple<int, int, int>> b;
    b.push_back(a[0]);
    for(int i=1; i<N; i++){
        if(get<0>(a[i]) == get<0>(b.back()) && get<1>(a[i]) - get<2>(b.back()) <= 1){
            int c = get<0>(b.back());
            int s = get<1>(b.back());
            int t = get<2>(a[i]);
            b.pop_back();
            b.push_back(make_tuple(c, s, t));
        }else{
            b.push_back(a[i]);
        }
    }

    vector<int> v(100010, 0);
    for(auto x : b){
        int c = get<0>(x);
        int s = get<1>(x);
        int t = get<2>(x);
        v[s] |= (1<<c);
        v[t+1] |= (1<<c);
    }

    vector<int> v2(100010, 0);
    for(int i=1; i<=100000; i++){
        v2[i] = v2[i-1] ^ v[i];
    }

    int ans = 0;
    for(int i=0; i<=100000; i++){
        int cnt = 0;
        for(int j=0; j<30; j++)
            if(v2[i] & (1<<j)) cnt++;
        ans = max(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main(){
    int n[20];
    int c[20][10];
    int l =0;
    int k;
    while(cin >> n[l]){
        if(n[l] == 0){break;}
        for (int i = 0; i< 10; i++){
            c[l][i] = 0;
        }
        for(int i= 0;i < n[l] ;i++){
            cin >> k;
            c[l][k] ++;
        }
        l ++;
    }
    for(int i = 0;i < l;i++){
        for(int j = 0;j<10;j++){
        if (c[i][j] == 0){
            cout << "-" << endl;
        }
        else{
            for(int w = 0;w < c[i][j];w++){
                cout << "*";
            }
            cout << endl;
        }
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 2.50 + c[j] * 16;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3700
###################################################
#                                                 #
#   author: raghav_0901 (Raghav Dalmia)           #
#   updated on: Sunday, 14-06-2020, 17:43:43 pm   #
#                                                 #
###################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


def main():
    x, n = _in()
    if(n == 0):
        print(x)
        return
    arr = _in()

    diff = 0
    while(True):
        l = x - diff
        if not(l in arr):
            print(l)
            return
        r = x + diff
        if not(r in arr):
            print(r)
            return
        diff = diff + 1


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    for _ in range(tt):
        main()


Measured memory_bytes: 9200
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, k;
int w[100001];

bool judge(int p){
	int a = 0;
	rep(i, k){
		a = upper_bound(w + a, w + n + 1, w[a] + p) - w - 1;
		if(a == n){
			return true;
		}
	}
	return false;
}

int main(){
	scanf("%d%d", &n, &k);
	rep(i, n){
		scanf("%d", w + i + 1);
	}
	rep(i, n){
		w[i + 1] += w[i];
	}
	int l = 0, r = 1e9;
	while(r - l > 1){
		int m = (r + l) / 2;
		if(judge(m)){
			r = m;
		}
		else{
			l = m;
		}
	}
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin>>n; int a[n+1];
    for (int i = 0; i < n; i++) cin>>a[i];
    int ans=0;
    for (int i = 0; i < n-1; i++){
        if(a[i]==i+1){
            swap(a[i],a[i+1]);
            i++; ans++;
        }
    }
    if(a[n-1]==n)ans++;
    cout<<ans<<'\n';
    }
    

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

#define LL long long

int main(){
	

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n,k;
	cin>>n>>k;

	LL a=0,b=0;

	for(int i=1;i<=n;i++){
		if(i%k == 0){a++;}
	}

	if(k%2 == 0){
		for(int i=1;i<=n;i++){
			if(i%k == k/2){b++;}
		}
	}

	cout<<(a*a*a + b*b*b)<<endl;
}

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

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

using namespace std;
using lint=long long;

int memo[51][51][51];

bool check(int x,int y,int k){
	int& res=memo[x][y][k];
	if(res!=-1) return res;

	if(x==y) return res=true;
	if(k==0) return res=false;
	return res=check(x,y,k-1)||check(x%k,y,k-1);
}

int main(){
	memset(memo,-1,sizeof memo);

	int n; scanf("%d",&n);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d",&a[i]);
	rep(i,n) scanf("%d",&b[i]);

	{
		bool ok=true;
		rep(i,n) if(!check(a[i],b[i],50)) ok=false;
		if(!ok){
			puts("-1");
			return 0;
		}
	}

	vector<lint> S(n);
	rep(i,n) S[i]=1LL<<a[i];

	lint ans=0;
	for(int k=50;k>0;k--){
		vector<bool> ok(n,true);
		rep(i,n){
			bool ok2=false;
			rep(x,51) if(S[i]>>x&1) {
				if(check(x,b[i],k-1)) ok2=true;
			}
			if(!ok2) ok[i]=false;
		}

		if(count(ok.begin(),ok.end(),false)>0){
			ans|=1LL<<k;
			rep(i,n){
				lint next=(ok[i]?S[i]:0);
				rep(x,51) if(S[i]>>x&1) next|=1LL<<x%k;
				S[i]=next;
			}
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 4320
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;

list<int> b;

int main() {
    int n;
    cin >> n;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        if(i%2==0) b.push_back(a[i]);
        else b.push_front(a[i]);
    }
    if(n%2==0){
        cout << b.front();
        b.pop_front();
        while(!b.empty()){
            cout << ' ' << b.front();
            b.pop_front();
        }
        cout << endl;
    }
    else{
        cout << b.back();
        b.pop_back();
        while(!b.empty()){
            cout << ' ' << b.back();
            b.pop_back();
        }
        cout << endl;
    }
}

Measured memory_bytes: 9984
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    if (A < 10 && B < 10)
    {
        cout << A * B;
    }
    else
    {
        cout << -1;
    }
    return 0;
}

Measured memory_bytes: 3164
#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;



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

    vector<long> a(n), b(n);
    vector<pair<long, long> > zz(2*n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld%ld", &a[i], &b[i]);
        zz[2*i]   = make_pair( a[i], 2*i );
        zz[2*i+1] = make_pair( b[i], 2*i+1);
    }
    sort( zz.begin(), zz.end() );

    vector<long>  id_save(n*2);
    for(i=0; i<2*n; i++) {
        id_save[zz[i].second] = i;
    }

    vector<ll> szz(2*n+1);
    szz[0]=0;
    for(i=0; i<n+2; i++) {
        szz[i+1] = szz[i] + zz[i].first;
    }

    // Select n items simply
    vector<long> cnt(n); 
    long cnt2[2]={0, 0};
    for(i=0; i<n; i++) {
        cnt[zz[i].second /2] ++;
        cnt2[zz[i].second %2] ++;
    }

    if(cnt2[0]==0 || cnt2[1]==0) {
        printf("%lld\n", szz[n]); return 0;
    }

    for(i=0; i<n; i++) {
        if(cnt[i]==0) {
            printf("%lld\n", szz[n]); return 0;
        }
    }

    // Select n items, avoiding 1 vertex
    ll ans = LINF;
    for(i=0; i<n; i++) {
        long id0 = id_save[2*i];
        long id1 = id_save[2*i+1];

        if(id0<n && id1>=n) {
            if(id1>n) {
                ans = MIN(ans, szz[n]-zz[id0].first+zz[n].first);
            }
            else {
                ans = MIN(ans, szz[n]-zz[id0].first+zz[n+1].first);
            }
        }
        else if(id0>=n && id1<n) {
            if(id0>n) {
                ans = MIN(ans, szz[n]-zz[id1].first+zz[n].first);
            }
            else {
                ans = MIN(ans, szz[n]-zz[id1].first+zz[n+1].first);
            }
        }
        else {
            printf("internal error\n");
        }
    }
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 8832
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	no1 := 0
	no2 := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
		if as[i] > no1 {
			no1 = as[i]
			///////
		} else if as[i] <= no1 && as[i] > no2 {
			no2 = as[i]
		}
	}

	if no1 == no2 {
		for i := 0; i < len(as); i++ {
			fmt.Println(no1)
		}
	} else {
		for i := range as {
			if as[i] == no1 {
				fmt.Println(no2)
			} else {
				fmt.Println(no1)
			}
		}
	}
}


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

using namespace std;

int main() {

	long x;
	long a, b;

	cin >> x;

	a = 0;
	b = 0;
	a = int(x/500);
	b = int((x - a* 500) / 5);

	cout << a * 1000 + b * 5;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    #A*B + A * C = A*(B+C)で計算
    right -= number
    result += (number * right) % mod
print(result % mod)

Measured memory_bytes: 31604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int N,ans=0;
bool used[100]={0};
pair<int,int> x[100],y[100];
int main() {
	cin>>N;
	for(int i=0;i<N;i++)cin>>x[i].first>>x[i].second;
	for(int i=0;i<N;i++)cin>>y[i].first>>y[i].second;
	sort(x,x+N);
	sort(y,y+N);
	for(int i=N-1;i>=0;i--){
		int k=999;
		int c=-1;
		for(int j=0;j<N;j++){
			if(x[i].first<y[j].first&&x[i].second<y[j].second&&k>y[j].second&&!used[j]){
				c=j;
				k=y[j].second;
			}
		}
		if(c!=-1){
			used[c]=1;
			ans++;	
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
S=input()
 
ans=[1]*len(S)
for i in range(1,len(S)):
  if S[i-1]==S[i]=='R':
    ans[i+1]+=ans[i-1]
    ans[i-1]=0
for i in range(len(S)-2,0,-1):
  if S[i+1]==S[i]=='L':
    ans[i-1]+=ans[i+1]
    ans[i+1]=0
print(*ans)

Measured memory_bytes: 6392
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define FOR for(lo i = 0 ; i < n ; i++)
#define FORV for(lo i = 0 ; i < (lo)v.size() ; i++)
lo a,b,d,e,x,y,n,p,m,t,a1[500005],a2[500000],c;
lo k;
string s1,s2,s3;
queue <pair<lo,lo> > q;
priority_queue <lo> pq;
map <lo,lo> mp1;
vector <lo> v;
lo vis[100000];
lo top;
int main(){
	// atcoder contest
	// freopen("gir.gir","r",stdin);
	// freopen("cik.cik","w",stdout);
	cin >> n;
	for(lo i = 0 ; i < n ; i++){
		cin >> a1[i];
		if(a1[i] % 2 == 0 && (a1[i] % 3 != 0 && a1[i] % 5 != 0) ){
			cout << "DENIED\n";
			return 0;
		}
	}
	cout << "APPROVED\n";
	return 0;
}


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

int main()
{
  int a, b, c;
  cin>> a >> b >> c;
  if(a==b){
    if(b==c){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    if(a <= c && c <= b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,vector<int>> graph;
void dfs(int node,vector<int>&dist,vector<int>&visited,vector<int>&indegree){
    visited[node]=1;
    for(auto neigh:graph[node]){
        //visited[neigh]=1;
        dist[neigh]=max(dist[neigh],1+dist[node]);
        indegree[neigh]--;
        if(indegree[neigh]==0)
            dfs(neigh,dist,visited,indegree);
        
    }
}
int main() {
	// your code goes here
	graph.clear();
	int n,m;
	cin>>n>>m;
	
	int u,v;
	vector<int> indegree(n+1,0);
	for(int i=0;i<m;i++){
	    cin>>u>>v;
	    graph[u].push_back(v);
	    indegree[v]++;
	    //graph[v].push_back(u);
	}
	vector<int> dist(n+1,0),visited(n+1,0);
	for(int i=1;i<=n;i++){
	    if(!visited[i] and indegree[i]==0){
	        dfs(i,dist,visited,indegree);
	    }
	}
// 	for(int i=1;i<=n;i++)
// 	    cout<<dist[i]<<" ";
// 	  cout<<endl;
	int res=0;
	for(int i=1;i<=n;i++)
	    res = max(res,dist[i]);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 16420
#include<stdio.h>
#include<stdlib.h>
typedef long long int ll;
int cmpfunc(const void *a,const void *b){
    if(*(long long int*)a==*(long long int*)b) return 0;
    else if(*(long long int*)a>*(long long int*)b) return 1;
    else return -1;
}
int main()
{
    int n,flag=1;
    scanf("%d",&n);
    ll a[n],mul=1;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(a[i]==0)flag=0;}
    qsort(a,n,sizeof(ll),cmpfunc);
    if(!flag){printf("0");return 0;}
    for(int i=0;i<n;i++)
    {
        if((1000000000000000000/mul)<a[i])
        {
            printf("-1");
            return 0;
        }
        mul*=a[i];
    }
    printf("%lld",mul);
}


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

if B==1:
    print(0)

elif A >= B:
    print(1)
elif(2*A-1) >=B:
    print(2)
elif(3*A-2)>=B:
    print(3)
elif(4*A-3)>=B:
    print(4)
elif(5*A-4)>=B:
    print(5)
elif(6*A-5)>=B:
    print(6)
elif(7*A-6)>=B:
    print(7)
elif(8*A-7)>=B:
    print(8)
elif(9*A-8)>=B:
    print(9)
elif(10*A-9)>=B:
    print(10)
elif(11*A-10)>=B:
    print(11)
elif(12*A-11)>=B:
    print(12)
elif(13*A-12)>=B:
    print(13)
elif(14*A-13)>=B:
    print(14)
elif(15*A-14)>=B:
    print(15)
elif(16*A-15)>=B:
    print(16)
elif(17*A-16)>=B:
    print(17)
elif(18*A-17)>=B:
    print(18)
elif(19*A-18)>=B:
    print(19)
elif(20*A-19)>=B:
    print(20)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N; cin >> N;
    int A[N+1]; REP(i, N+1) cin >> A[i];
    int B[N]; REP(i, N) cin >> B[i];

    ll ret1 = 0;
    for (int i=N-1; i>=0; --i)
    {
        int b = B[i];

        ll n1 = min(A[i+1], b);
        ret1 += n1; b -= n1;

        ll n0 = min(A[i+0], b);
        ret1 += n0; A[i+0] -= n0;
    }

    cout << ret1 << endl;
    return 0;
}

Measured memory_bytes: 1024
// 5/28
// 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    string ans;
    rep(i, N) {
        ans += S[i];
        ans += T[i];
    }

    cout << ans << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
constexpr ll INF = 1LL<<60;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}

template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int r,c,k;
  cin>>r>>c>>k;
  auto dp = vec<ll>(5,r,c);
  auto a = vec<ll>(r,c);
  rep(_,k){
    int i,j,v;
    cin>>i>>j>>v;
    i--;j--;
    chmax<ll>(a[i][j],v);
  }

  ll ans = 0;
  rep(i,r){
    rep(j,c){
      if(j-1>=0){
        chmax(dp[1][i][j],max(dp[0][i][j-1]+a[i][j],dp[1][i][j-1]));
        chmax(dp[2][i][j],max(dp[1][i][j-1]+a[i][j],dp[2][i][j-1]));
        chmax(dp[3][i][j],max(dp[2][i][j-1]+a[i][j],dp[3][i][j-1]));
      }
      if(i-1>=0){
        chmax(dp[0][i][j],dp[0][i-1][j]);
        chmax(dp[0][i][j],dp[1][i-1][j]);
        chmax(dp[0][i][j],dp[2][i-1][j]);
        chmax(dp[0][i][j],dp[3][i-1][j]);
      }
      chmax(dp[1][i][j],dp[0][i][j]+a[i][j]);
      chmax(ans,max({dp[0][i][j],dp[1][i][j],dp[2][i][j],dp[3][i][j]}));
    }
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 425824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("YES\n")
#define outn printf("NO\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
/*------------------------------------------------------------*/

int main(){
	ll n;
	inl(n);
	ll ans=sqrt(n);
	outl(ans*ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(b>a){
  }
  else if(2*b>a){
    b=2*b;
    k=k-1;
  }
  else if(4*b>a){
    b=4*b;
    k=k-2;
  }
  else if(8*b>a){
    b=8*b;
    k=k-3;
  }
  else if(16*b>a){
    b=16*b;
    k=k-4;
  }
  else if(32*b>a){
    b=32*b;
    k=k-5;
  }
  else if(64*b>a){
    b=64*b;
    k=k-6;
  }
  else if(128*b>a){
    b=128*b;
    k=k-7;
  }
  if(c>b){
  }
  else if(2*c>b){
    k=k-1;
  }
  else if(4*c>b){
    k=k-2;
  }
  else if(8*c>b){
    k=k-3;
  }
  else if(16*c>b){
    k=k-4;
  }
  else if(32*c>b){
    k=k-5;
  }
  else if(64*c>b){
    k=k-6;
  }
  else if(128*c>b){
    k=k-7;
  }
  if(k<0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }

}

Measured memory_bytes: 3584
#include <unordered_set>
#include <iostream>
#include <cassert>
#include <vector>
#include <bitset>
using namespace std;

inline int lowbit( int x ) {
	return x & ( -x );
}
void go( int, int, int, vector< int >&, unordered_set< int >& );

int main() {
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	int n, a, b; cin >> n >> a >> b;
	if ( __builtin_popcount( a ^ b ) % 2 == 0 ) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	unordered_set< int > able;
	for ( int i = 0 ; i < n ; ++ i )
		able.insert( i );
	vector< int > ans;
	go( n - 1, a, b, ans, able );
	for ( size_t i = 0 ; i < ans.size() ; ++ i )
		cout << ( ans[ i ] ) << " \n"[ i + 1 == ans.size() ];
	return 0;
}

void go( int n, int a, int b, vector< int >& ret, unordered_set< int >& st ) {
	if ( not n ) {
		ret.push_back( a );
		ret.push_back( b );
		return;
	}
	int bt = -1;
	for ( auto p : st ) {
		if ( ( a ^ b ) & ( 1 << p ) ) {
			bt = p;
			break;
		}
	}
	st.erase( bt );
	int aa = min( a, a ^ ( 1 << bt ) );
	int bb = min( b, b ^ ( 1 << bt ) );
	int lb = *st.begin();
	go( n - 1, aa, aa ^ ( 1 << lb ), ret, st );
	go( n - 1, aa ^ ( 1 << lb ), bb, ret, st );
	int n2 = 1 << n;
	for ( int i = 1 ; i <= n2 ; ++ i )
		ret[ ret.size() - i - n2 * ( a != aa ) ] ^= 1 << bt;
	st.insert( bt );
}

Measured memory_bytes: 1652
class PQueue
  def initialize(data = [], &cmp)
    @data = [nil] + data.sort(&cmp)
    @cmp = cmp
  end
  def size; @data.size - 1; end
  def empty?; @data.size == 1; end
  def peek; empty? ? nil : @data[1]; end

  def push(el)
    j = @data.size
    @data << el
    while j > 1
      break if @cmp.call(@data[j / 2], @data[j]) < 0
      
      @data[j] = @data[j / 2]
      @data[j / 2] = el
      j /= 2
    end
    self
  end
  alias_method :<<, :push
  
  def shift
    return nil if empty?
    return @data.pop if size == 1
    
    el = @data[1]
    tail = @data.pop
    
    @data[1] = tail
    j = 1
    while 2 * j < @data.size
      i = 2 * j
      i += 1 if i + 1 < @data.size && @cmp.call(@data[i + 1], @data[i]) < 0

      break if @cmp.call(@data[j], @data[i]) < 0
      
      @data[j] = @data[i]
      @data[i] = tail
      j = i
    end
    return el
  end
end
# dp[s][c] : 駅sをコインc枚以上もって、出発するときの最小時間
# dp[v][j] = min{ dp[u][j + a] + b } (j >= 0)
def min(a,b); a < b ? a : b; end
def max(a,b); a > b ? a : b; end
INF = Float::INFINITY

N,M,S = gets.split.map(&:to_i)
dp = Array.new(N + 1){ Array.new(2520, INF) }

E = Array.new(M)
V = Array.new(N + 1)

M.times do |i|
  E[i] = gets.split.map(&:to_i)
end
(1 .. N).each do |i|
  V[i] = gets.split.map(&:to_i)
end

G = Array.new(N + 1){ [] }
max_a = 0

E.each do |(u, v, a, b)|
  max_a = max(max_a, a)
  G[u] << [v, a, b]
  G[v] << [u, a, b]
end
A_MAX = max_a * N

q = PQueue.new{|a,b| [a[0],-a[1]] <=> [b[0],-b[1]] }
q << [0, min(S, A_MAX), 1]
used = Array.new(N + 1)

until q.empty? || (1 .. N).all?{|i| used[i] }
  t,w,v = q.shift
  c,d = V[v]
  
  used[v] = true
  
  next if t >= dp[v][w]
  w.downto(0) do |w_|
    if dp[v][w_] > t
      dp[v][w_] = t 
    else
      break
    end
  end
  
  G[v].each do |u,a,b|
    q << [t + b, w - a, u] if w >= a && dp[u][w - a] > t + b
  end
  q << [t + d, min(w + c, A_MAX), v] if dp[v][min(w + c, A_MAX)] > t + d
end
puts (2 .. N).map{|i| dp[i][0] }


Measured memory_bytes: 15644
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;

int main() {
  cin >> s;
  auto N = s.size();
  if (s.at(0) == s.at(1)) {
    cout << 1 << ' ' << 2 << endl;
    return 0;
  }

  for(int i=0; i<N-2; i++) {
    if (s.at(i) == s.at(i+1) || s.at(i) == s.at(i+2) || s.at(i+1) == s.at(i+2)) {
      cout << i+1 << ' ' << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 512
N = input()
num_list = list(N)
op = ["+", "-"]
flag = False
for i in range(len(op)):
    for j in range(len(op)):
        for k in range(len(op)):
            eq = num_list[0] + op[i] + num_list[1] + \
                op[j] + num_list[2] + op[k] + num_list[3]
            ans = eval(eq)
            if ans == 7:
                flag = True
                break
        if flag == True:
            break
    if flag == True:
        break
print(eq + "=" + str(ans))


Measured memory_bytes: 61476
s = input()
n = len(s)

t = input()
m = len(t)

dp = tuple([0] * (m + 1) for _ in range(n + 1))

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

rest = dp[n][m]
ans = ''

i = n
j = m
while rest > 0:
    if s[i - 1] == t[j - 1]:
        ans = s[i - 1] + ans
        rest -= 1
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        j -= 1
print(ans)


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

int main(){
    int n, q;
    double S[10000];
    double T[500];
    int a = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> S[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> T[i];
    }
    for(int i = 0; i < q; i++){
        for (int j = 0; j < n; j++){
            if (T[i] == S[j]){
                a++;
                break;
            }
        }
    }
    cout << a << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    int maxv = *max_element(a, a + n);
    int half = maxv / 2;
    int back = lower_bound(a, a + n, half) - a;
    int front = back - 1;

    int r = back;
    if (abs(a[back] - half) > abs(a[front] - half) || back == n - 1) r = front;

    cout << maxv << ' ' << a[r] << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
//a:パスタ,b:ジュース
int a,b,a1,a2,a3,b1,b2;

cin >> a1 >> a2 >> a3 >> b1 >> b2;

if(a1<100||2000<a1){
      cout << "エラー" << endl;
      return 0;
}
if(a2<100||2000<a2){
      cout << "エラー" << endl;
      return 0;
}
if(a3<100||2000<a3){
      cout << "エラー" << endl;
      return 0;
}
if(b1<100||2000<b1){
      cout << "エラー" << endl;
      return 0;
}
if(b2<100||2000<b2){
      cout << "エラー" << endl;
      return 0;
}

if((a1>=a2)&&(a2>=a3)){
   a = a3;
}
if((a2>=a1)&&(a1>=a3)){
   a = a3;
}
if((a1>=a3)&&(a3>=a2)){
   a = a2;
}
if((a3>=a1)&&(a1>=a2)){
   a = a2;
}
if((a3>=a2)&&(a2>=a1)){
   a = a1;
}
if((a2>=a3)&&(a3>=a1)){
   a = a1;
}
if(b1<b2){
   b = b1;
}
else{
   b = b2;
}

cout << (a+b)-50 << endl;

/*
if(a>b&&b>c){
      if(d>e){
       cout << c+e-50 << endl;
}
if(a>b&&b>c){
      if(e>d){
       cout << c+d-50 << endl;
}          
if(b>c&&){
      if(d>e){
       cout << c+e-50 << endl;
}
*/
return 0;
}

Measured memory_bytes: 1160
/*

            ░   ▒▓█  𝕿𝖆𝖑𝖐 𝖎𝖘 𝖈𝖍𝖊𝖆𝖕. 𝕾𝖍𝖔𝖜 𝖒𝖊 𝖙𝖍𝖊 𝖈𝖔𝖉𝖊 █▓▒░
   */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define si(x) (ll)((x).size())
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).resize(unique(all(x))-(x).begin())
const int  N = 2e5 + 10;
ll m = 1e9 + 7;
void solve()
{
    string s;
    cin>>s;
    for(auto i:s)if(i=='7')
    {
        cout<<"Yes";
            return;
    }

    cout<<"No";
}
int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);



    int t = 1, n, x, ans;
    // cin >> t;

    while(t--)
    {
        solve();

    }


}


Measured memory_bytes: 3648
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int k = sc.nextInt();

      if ( (b + 1 - a) <= 2 * k) {
         for (int i = a; i <= b; i++) {
            System.out.println(i);
         }
      }
      else {
         for (int i = a; i <= a + k - 1; i++) {
            System.out.println(i);
         }
         for (int i = b - k + 1; i <= b; i++) {
            System.out.println(i);
         }
      }
   }
}

Measured memory_bytes: 24788
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;


int main(){
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


ll com(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    ll h,w,a,b; cin >> h >> w >> a >> b;
    comInit();
    ll ans = 0;
    ll t = 0;
    rep(i,h-a){
        if(com(i+b,b) > t){
            ans += ((com(i+b,b)-t) * com(h-i-1+w-b-1,h-i-1)) % MOD;
        }else{
            ans += ((com(i+b,b)+MOD-t)*com(h-i-1+w-b-1,h-i-1))%MOD;
        }
        t = com(i+b,b);
        ans %= MOD;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

using namespace std;

int diff(string &s,string &t)
{	int c=0;
   for(int i=0;i<t.size();i++)
   {
      if(s[i]!=t[i])
         ++c;
   	}
   return c;
}


int main()
{	string s,t;
 	cin>>s>>t;
	cout<<diff(s,t);
 	return 0;
}

Measured memory_bytes: 3920
#include<stdio.h>
#include<string.h>
int main(void)
{
    int a,b,i,j,k;
    char x[200],y[400];
    while(1){
        scanf("%s",x);
        if(x[0]=='-')break;
        a=strlen(x);
        scanf("%d",&b);
        int c[b];
        for(i=0;i<b;i++){
            scanf("%d",&c[i]);
        }
        for(j=0;j<b;j++){
            strcpy(y,x);
            strcat(y,x);
            for(k=0;k<a;k++){
                x[k]=y[k+c[j]];
            }
            x[a]=0;
        }
        printf("%s\n",x);
    }
    return 0;
}

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

int main(){
	string S;
	cin>>S;
	
	int ans=700;
	if(S[0]=='o')
		ans+=100;
	if(S[1]=='o')
		ans+=100;
	if(S[2]=='o')
		ans+=100;
	
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
s = input()
p = input()
ls = len(s)
lp = len(p)
res = "No"
for i in range(ls):
    if s[i] == p[0]:
        c = 1
        for j in range(1, lp):
            if s[(i + j) % ls] == p[j]:
                c += 1
        if c == lp:
            res = "Yes"
            break
print(res)



Measured memory_bytes: 5560