akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 200308
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar('\n');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
int N,a=1,b=1;
signed main()
{
	read(N);
	for(reg int i=sqrt(N);i;--i)
	{
		if(N%i==0){
			a=i;break;
		}
	}
	Write(a+(N/a)-2);
	return 0;
}


Measured memory_bytes: 256
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*I
m+=d,
a=~w+a*w+b
q=[a]
d[a]=1
for s in q:
 for x in 0,1,2,3:
  for z in range(k):
   y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[~x];t=i*w+j;p=d[s]+1
   if'.'!=m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)


Measured memory_bytes: 132656
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
			sum += p[i];
		}
		Arrays.sort(p);
		sum -= p[n - 1] / 2;
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define int ll
#define Endl endl

signed main(){
    int H,W,h,w;
    cin >> H >>W >> h >> w;
    cout <<(H-h)*(W-w) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {
	int a, b, m;
	cin >> a >> b >> m;
	int x[100005], y[100005];
	int mi = INF, mi2 = INF;
	rep(i, a) {
		cin >> x[i];
		mi = min(mi, x[i]);
	}
	rep(i, b) {
		cin >> y[i];
		mi2 = min(mi2, y[i]);
	}
	int ans = mi + mi2;
	rep(i, m) {
		int j, k, l;
		cin >> j >> k >> l;
		j--, k--;
		ans = min(ans, x[j] + y[k] - l);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
let [|H;W;A;B|] = stdin.ReadLine().Split() |> Array.map int
let rec f h w (s:string) =
    if h=H then ()
    elif w=W then
        stdout.WriteLine s
        f (h+1) 0 ""
    elif (h<H-B && w<W-A) || (h>H-B-1 && w>W-A-1) then f h (w+1) (s+"1")
    elif (h<H-B && w>W-A-1) || (h>H-B-1 && w<W-A) then f h (w+1) (s+"0")
f 0 0 ""

Measured memory_bytes: 16380
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        ll t = a;
        a = b;
        b = t;
    }
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << (a * b) / gcd(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>


using namespace std;
static const int MAX = 100;

int main()
{
	int n, a[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
	cout << a[n - 1] << endl;
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;

		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int i = 0; i < n; i++) {
			cout << a[i];
			if (i != n - 1) cout << " ";
			else cout << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3088
a = input()
n = len(a)

ans = 0

for i in range(2 ** (n-1)):

    formula = ''
    formula += a[0]

    for j in range(n-1):

        if (i >> j) & 1:
            formula += '+'

        formula += a[j+1]
    
    ans += sum(map(int, formula.split('+')))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector<int> v(5);
	int ans;
	for(int i = 0; i < 5; i++) {
		cin >> v[i];
		if(v[i] == 0) {
			ans = i;
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF INT_MAX
int n;
vi seg;
vi lazy;

void propagate(int k) {
  if (lazy[k] == 0) {
    return;
  }
  if (k < n) {
    lazy[k*2] += lazy[k];
    lazy[k*2+1] += lazy[k];
  } else {
    seg[k] += lazy[k];
  }
  lazy[k] = 0;
}

// seg[k] : [l, r)
void range_add(int a, int b, int k, int l, int r, int x) {
  if (r <= a || b <= l) {
    return;
  }
  if (a <= l && r <= b) {
    lazy[k] += x;
    return;
  } else {
    propagate(k);
    range_add(a, b, k*2, l, (l+r)/2, x);
    range_add(a, b, k*2+1, (l+r)/2, r, x);
  }
}

int range_get(int x, int k, int l, int r) {
  propagate(k);
  if (x < l || r <= x) {
    return 0;
  }
  if (l == x && r == x+1) {
    return seg[k];
  } else {
    return range_get(x, k*2, l, (l+r)/2) + range_get(x, k*2+1, (l+r)/2, r);
  }
}

int get_query(int x) {
  return range_get(x, 1, 0, n);
}

int main() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  n = (1 << (int)(ceil(log2(n_))));
  seg.assign(2*n, 0);
  lazy.assign(2*n, 0);
  int op, s, t, x;
  rep (i, q) {
    scanf("%d", &op);
    if (op == 0) {
      scanf("%d %d %d", &s, &t, &x);
      s -= 1;
      range_add(s, t, 1, 0, n, x);
    } else {
      scanf("%d", &x);
      x -= 1;
      printf("%d\n", get_query(x));
    }
  }

  return 0;
}

Measured memory_bytes: 5136
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	cout << a / b << " " << a % b << " "<<fixed << setprecision(5) << (double)a / b << "\n";
	return 0;
}


Measured memory_bytes: 3300
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N, M, X;
int A[MAX_N];

bool check(int n)
{
  for (int i = 0; i < M; i++) {
    if (A[i] == n) return true;
  }
  return false;
}

int main(void)
{
  cin >> N >> M >> X;
  REP(i, M) cin >> A[i];

  int ans = INT_MAX;
  int cost = 0;
  for (int i = X; i >= 0; i--)
    if (check(i)) cost++;
  ans = min(ans, cost);
  cost = 0;
  for (int i = X; i < N; i++)
    if (check(i)) cost++;
  ans = min(ans, cost);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

#人は0からN-1,言語は1からMまで
N, M = rl()
KL = [rl() for _ in range(N)]
speak_lan = [[] for _ in range(M+1)] #0は使わない
for i, x in enumerate(KL):
    k, *lan = x
    for l in lan:
        speak_lan[l].append(i)

communicate = set()
used_language = set()
def dfs(person):
    global communicate
    global used_language
    lan = KL[person][1:]
    for l in lan:
        if l in used_language:
            continue
        used_language.add(l)
        for p in speak_lan[l]:
            if p not in communicate:
                communicate.add(p)
                dfs(p)

dfs(0)
if len(communicate) == N:
    print('YES')
else:
    print('NO')



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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N;cin >> N;
	vector<ll> h(N);
	REP(i, N) cin >> h[i];

	ll pre{0};
	ll res{0};
	REP(i, N)
	{
		res += max(0ll, h[i] - pre);
		pre = h[i];
	}

	std::cout << res << std::endl;
}


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

int main()
{
	int n;
	int* v, * c;
	int total = 0;

	cin >> n;
	v = new int[n];
	c = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		if (v[i] - c[i] > 0) {
			total += v[i] - c[i];
		}
	}
	cout << total << '\n';
	return 0;
}


Measured memory_bytes: 256
S=input()

isok=True
for i,s in enumerate(S):
    if (i+1) % 2 == 0:
        if s=='R':
            isok=False
            break
    else:
        if s=='L':
            isok=False
            break

if isok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 39892
#include <cstdio>
#include <cstring>
#include <algorithm>
#define y1 yy

using namespace std;

namespace SETS {

int fa[405];

void init() {
  for(int i=1;i<=401;i++) fa[i]=i;
}

int find_father(int x) {
  return (fa[x]==x)?x:fa[x]=find_father(fa[x]);
}

bool check(int x,int y) {
  x=find_father(x);y=find_father(y);
  return x==y;
}

void merge(int x,int y) {
  x=find_father(x);y=find_father(y);
  if (x==y) return;
  fa[x]=y;
}

}

inline int id(int x,int y,bool on) {
  int p=(!y)?x:y+200;
  if (on) {
  	if (p<=200) p+=200; else p-=200;
  }
  return p;
}

int d[405];
bool vis[405];

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  SETS::init();
  for(int i=1;i<=n;i++) {
  	int x1,x2,y1,y2;
  	scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
  	int p=id(x1,y1,0),q=id(x2,y2,1);
  	vis[p]=vis[q]=1;
  	d[p]++;d[q]--;
  	SETS::merge(p,q);
  }
  int s1=0;
  for(int i=1;i<=200;i++)
    if (d[i]>0) {
    	s1+=d[i];
    	SETS::merge(i,401);
	}
	else if (d[i]<0) {
		puts("NO");
		return 0;
	}
  int s2=0;
  for(int i=201;i<=400;i++)
    if (d[i]<0) {
    	s2-=d[i];
    	SETS::merge(i,401);
	}
	else if (d[i]>0) {
		puts("NO");
		return 0;
	}
  for(int i=1;i<=400;i++)
    if (vis[i]&&!SETS::check(i,401)) {
    	puts("NO");
    	return 0;
	}
  puts("YES");
  return 0;
}

Measured memory_bytes: 256
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
div={}
def div2(x): #素因数分解配列
    global div
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            if check not in div:
                div[check]=1
            else:
                div[check]+=1
            x/=check
        check+=1
    if x != 1:
      div[x]=1
    return div

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,p = map(int,input().split())
    div2(p)
    ans=1
    for i in div:
        if div[i]>=n:
            ans*=i**(div[i]//n)
    print(int(ans))
main()

Measured memory_bytes: 38896
#include <stdio.h>

void insertsort(int a[] , int n);

int main(void)
{
	int n;
	scanf("%d",&n);
	int i,a[n];
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	
	insertsort(a,n);
	
	return 0;
}

void insertsort(int a[] , int n)
{
	int i , j , k , tmp;
	
	for(  k = 0; k < n; k++)
	{
		if(k != n-1)printf("%d ",a[k]);
		else printf("%d\n",a[k]);
	}

	for( i = 1; i < n; i++)
	{
		j = i;
		while( j > 0 && a[j] < a[j-1] )
		{
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			j--;
		}
		for(  k = 0; k < n; k++)
		{
			if(k != n-1)printf("%d ",a[k]);
			else printf("%d\n",a[k]);
		}
	}
}


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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



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

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    int ar[3][3];
    for(int i=0;i<3 ;i++)
    {
        for(int j=0;j < 3; j++)
        {
            cin >> ar[i][j];
        }
    }
    int n;
    cin >> n;
    for(int k=0; k< n ;k++)
    {
        int x; 
        cin >> x ;
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(ar[i][j]==x) ar[i][j]=-1;
            }
        }
    }
    for(int i=0;i<3;i++)
    {
        if(ar[i][0]==-1 && ar[i][1]==-1 && ar[i][2]==-1) return cout << "Yes\n",0;
        if(ar[0][i]==-1 && ar[1][i]==-1 && ar[2][i]==-1) return cout << "Yes\n",0;
    }
    if(ar[0][0]==-1 && ar[1][1]==-1 && ar[2][2]==-1) return cout << "Yes\n",0;
    if(ar[0][2]==-1 && ar[1][1]==-1 && ar[2][0]==-1) return cout << "Yes\n",0;
    cout << "No\n";
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		long s = 0;
		for (int i = n - 1; i >= 0; --i) {
			if ((a[i] + s) % b[i] == 0)
				continue;
			s += b[i] - (a[i] + s) % b[i];
		}
		System.out.println(s);
	}
}


Measured memory_bytes: 72840
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<double, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem0562 : Shopping in JOI Kingdom **/

// Node 0...2999 : Given
//      3000...  : Add
const int MAX_V = 1e5+100;
const int BASE = 100;

struct edge{
	int to; double cost;
	edge(int t, int c):to(t), cost(c){}
};
vector<edge> G[MAX_V];
int d[MAX_V];
bool used[MAX_V];

int main()
{
	int N, M, K; cin>>N>>M>>K;
	rep(i, M) {
		int a, b; double c;
		cin>>a>>b>>c;
		a--, b--;
		
		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, c));
	}
	
	priority_queue<P, vector<P>, greater<P> > Q;
	fill(d, d+N, INF);
	
	rep(i, K) {
		int s; cin>>s; s--;
		d[s] = 0;
		Q.push(P(0, s));
	}
	
	while (Q.size()) {
		P p = Q.top(); Q.pop();
		int v = p.second;
		
		if (d[v] < p.first) continue;
		for (int i=0; i<G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
	
	double ans = 0;
	for (int i=0; i<N; i++) {
		for (int v=0; v<G[i].size(); v++) {
			edge e = G[i][v];
			ans = max(ans, (d[i]+d[e.to]+e.cost)/2.0);
		}
	}
	
	cout << round(ans) << endl;
}

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

using namespace std;

// add(pos, n): data[pos] += n;
// sum(l, r)  : sum [l, r)
template <typename T>
class FenwickTree
{
    const int n;
    vector<T> data;

  public:
    FenwickTree(int _n) : n(_n), data(_n, 0) {}

    void add(int pos, const T &value)
    {
        for (int i = pos; i < n; i |= i + 1)
            data[i] += value;
    }

    T sum(int pos) const
    {
        T res = 0;
        for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1)
            res += data[i];
        return res;
    }

    T sum(int l, int r) const
    {
        return sum(r) + (-sum(l));
    }
};

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

    int N;
    cin >> N;
    FenwickTree<int> ft(N + 1);
    int cnt = 0;
    bool zero = false;
    vector<int> x(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
        bool f;
        if (zero)
        {
            f = false;
        }
        else if (N < x[i])
        {
            cnt++;
            f = true;
        }
        else if (!ft.sum(x[i], x[i] + 1))
        {
            f = true;
            ft.add(x[i], 1);
        }
        else
        {
            if (ft.sum(1, x[i] + 1) == x[i] && (cnt || ft.sum(x[i] + 1, N + 1)))
            {
                f = false;
            }
            else
            {
                f = true;
                while (ft.sum(x[i], x[i] + 1))
                {
                    ft.add(x[i], -1);
                    x[i]--;
                }
                ft.add(x[i], 1);
                if (x[i] == 0)
                    zero = true;
            }
        }
        cout << (f ? "Yes" : "No") << endl;
    }
    return 0;
}



Measured memory_bytes: 6780
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int n = inp[0], a = inp[1], b = inp[2], c = inp[3], d = inp[4];
        var s = Console.ReadLine();
        bool judge = true;
        var sunuke = new int[n + 2];
        var funuke = new int[n + 2];
        sunuke[a] = 1;
        if (s[(a - 1) + 1] == '.') sunuke[a + 1] = 1;
        if (a > 1 && s[(a - 1) - 1] == '.') sunuke[a - 1] = 1;
        funuke[b] = 1;
        if (s[(b - 1) + 1] == '.') funuke[b + 1] = 1;
        if (b > 1 && s[(b - 1) - 1] == '.')
        {
            funuke[b - 1] = 1;
            if (funuke[b - 1] == 1 && funuke[b + 1] == 1) funuke[b - 1] = 2;
        }
        for (int i = a + 2; i < c + 1; i++)
        {
            if (s[i - 1] == '.')
            {
                if (sunuke[i - 1] > 0) sunuke[i]++;
                if (sunuke[i - 2] > 0) sunuke[i]++;
            }
        }
        for (int i = b + 2; i <= d + 1; i++)
        {
            if (i <= n && s[i - 1] == '.')
            {
                if (funuke[i - 1] > 0) funuke[i]++;
                if (funuke[i - 2] > 0) funuke[i]++;
            }
        }
        if (sunuke[c] == 0) judge = false;
        if (funuke[d] == 0) judge = false;
        if (c > d && !funuke.Contains(2)) judge = false;
        Console.WriteLine(judge ? "Yes" : "No");
    }
}

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

int main() {
  int n,sy;
  sy = 0;
  string color;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> color;
    if(color == "Y"){
      sy = 1;
    }
  }
  if(sy == 0){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a;
  int L[100], R[100], A[100], B[100];
  REP(i,n){
      cin >> a;
      A[i] = a;
  }
  REP(i,n){
      cin >> a;
      B[i] = a;
  }
  int sml = 0;
  int smr = 0;
  REP(i,n){
      sml += A[i];
      L[i] = sml;
      smr += B[n-i-1];
      R[n-i-1] = smr ;
  } 
  int ans = 0;
  REP(i,n){
      ans = max(ans,L[i]+R[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define int long long
#define vll vector<long long>
#define pii pair<long long ,long long >
#define vvi vector< vector<long long > >
#define vpii vector<pair<int,int>>
#define pll  pair<long long ,long long >
#define pb  push_back
#define ff  first
#define sec second
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend())
#define m_p make_pair
#define all(x) (x.begin(),x.end())
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD = 1e9 + 7 ;
int size = 10000000;


void solve() {

	int a, b, c; cin >> a >> b >> c;

	int k;  cin >> k;
	int x = 0;

	while (b <= a) {
		b *= 2; k--; //debug(b);
		if (k < 0) { x = 1 ; break ; }
	}


	while (c <= b) {
		c *= 2; k--; //debug(c, k);
		if (k < 0) { x = 1; break; }
	}



	if (x) cout << "No" << endl;
	else cout << "Yes" << endl;

}


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

	int T = 1; //cin>>T;
	while (T--) {
		solve();
	}

	return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
#include<vector>
#include<set>
#define ll long long
#define db double
#define si short int
#define mem(a) memset(a,0,sizeof(a))
#define maxn 85
#define maxm
#define inf 0x7fffffff
#define mod
#define eps
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
ll read(){
	ll a=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){a=a*10+c-'0';c=getchar();}
	return a*f;
}
ll n,m,v[maxn][maxn];
bool f[maxn][maxn][maxn*maxn*2];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	m=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			v[i][j]=read();
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			v[i][j]=abs(v[i][j]-read());
		}
	}
	f[1][1][v[1][1]+6400]=1;
	f[1][1][6400-v[1][1]]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<=12800;k++){
				if(k+v[i][j]<=12800)f[i][j][k+v[i][j]]|=f[i-1][j][k]|f[i][j-1][k];
				if(k-v[i][j]>=0)	f[i][j][k-v[i][j]]|=f[i-1][j][k]|f[i][j-1][k];
//				if(k+v[i][j]<=12800)f[i][j][k+v[i][j]]|=f[i][j-1][k];
//				if(k-v[i][j]>=0)	f[i][j][k-v[i][j]]|=f[i-1][j][k];
//				if(k+v[i][j]<=12800)f[i][j][k+v[i][j]]|=f[i-1][j][k];
//				if(k-v[i][j]>=0)	f[i][j][k-v[i][j]]|=f[i][j-1][k];
			}
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++){
//			cout<<v[i][j]<<" ";
//		}
//		cout<<endl;
//	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++){
//			for(int k=0;k<=12800;k++){
//				if(f[i][j][k]){
//					cout<<i<<" "<<j<<" "<<k<<endl;
//				}
//			}
//		}
//	} 
	ll ans=inf;
	for(int i=0;i<=12800;i++){
		if(f[n][m][i]){
			ans=Min(ans,abs(i-6400));
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 97408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int main(){
	int a;
	string s;
	cin>>a>>s;
	if(a>=3200){
		cout<<s<<endl;
	}else{
		cout<<"red"<<endl;
	}
	return 0;
}

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

#define ll long long
bool p(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
int main() {
#ifndef ONLINE_JUDGE
  //cout << "\x1B[34m";
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; n; i++) {
    if (p(i) && i % 5 == 1) n--, cout << i << " ";
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		char A;
		while(scanf("%s",&A)!=EOF){
			if(A=='a'||A=='e'||A=='i'||A=='o'||A=='u'){
				printf("vowel\n");
			}
			else{
				printf("consonant\n");
			}
		}
		return 0;
	}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    if(n <= k){
        cout << 0;
    }else{
        ll ans = 0;
        for(int i = 0; i < n-k; i++){
            ans += a[i];
        }
        cout << ans;
    }
    
}

Measured memory_bytes: 1792
import std.stdio, std.conv, std.string, std.math;

void main(){
	auto ip = readln.split.to!(int[]);
	if(ip[0] == ip[1]){
		"Draw".writeln;
	} else if(ip[0] == 1){
		"Alice".writeln;
	} else if(ip[1] == 1){
		"Bob".writeln;
	} else if (ip[0] > ip[1]){
		"Alice".writeln;
	} else {
		"Bob".writeln;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int n,m;
  cin>>n>>m;
  int ans[n],l,r;
  for(int i=0;i<n;i++) ans[i]=0;
  for(int i=0;i<m;i++){
    cin>>l>>r;
    ans[l-1]++;
    ans[r]--;
  }
  int t=0;
  if(ans[0]==m) t++;
  for(int i=1;i<n;i++){
    ans[i]+=ans[i-1];
    if(ans[i]==m) t++;
  }
  cout<<t;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  string n;
  cin >> n;
  
  for(char c : n){
	if(c == '9'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}



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

int calc(int num, string &s){
    s = "";
    for(;num;num/=27){
        int tmp = num % 27;
        if(tmp==0)return 1;
        s = "a" + s;
        s[0] += (tmp-1);
    }
    return 0;
}

int main(){
    int n;
    cin>>n;
    set<string>st;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<s.size();j++){
            for(int k=0;k<4 && j+k<s.size();k++){
                st.insert(s.substr(j, k+1));
            }
        }
    }
    for(int i=1;;i++){
        string s;
        if(calc(i, s))continue;
        if(st.find(s)==st.end()){
            cout<<s<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 42384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt64(scanner)
	p := getNextInt64(scanner)
	m := map[int64]int{}
	for p > 1 {
		d := nextd(p)
		m[d] = m[d] + 1
		p /= d
	}
	var i, ans int64
	ans = 1
	for d, c := range m {
		for i = int64(0); i < int64(c)/n; i++ {
			ans *= d
		}
	}

	fmt.Fprintln(writer, ans)
}

func nextd(p int64) int64 {
	var i int64
	for i = 2; i*i <= p; i++ {
		if p%i == 0 {
			return i
		}
	}

	return p
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()
#define PI acos(-1)

// code starts
int main()
{
  int n;
  cin >> n;
  string x;
  cin >> x;
  int i;
  int count1 = 0;
  rep(i,n)
  {
    if(x[i] == '1') count1++;
  }
  if(count1 >= 2)
  {
    int kp = count1+1;
    int kn = count1-1;
    vector<int> ps(n);
    vector<int> ns(n);
    int nowp = 0;
    int nown = 0;
    int vp = 1;
    int vn = 1;
    for(i=n-1;i>=0;i--)
    {
      //cout << i << endl;
      vp %= kp;
      vn %= kn;
      ps[i] = vp;
      ns[i] = vn;
      vp *= 2;
      vn *= 2;
      if(x[i] == '1')
      {
        nowp = (nowp+ps[i])%kp;
        nown = (nown+ns[i])%kn;
      }
    }
    rep(i,n)
    {
      int now;
      int count = 1;
      if(x[i] == '0')
      {
        now = (nowp+ps[i])%kp;
        while(now != 0)
        {
          //cout << now << endl;
          int next = 0;
          int left = now;
          while(left > 0)
          {
            if(left%2 == 1)
            {
              next++;
            }
            left /= 2;
          }
          //cout << next << endl;
          now = now%next;
          count++;
        }
      }
      else
      {
        now = (nown-ns[i]+kn)%kn;
        //if(i==n-2)cout << ns[i] << '@' << endl;
        while(now != 0)
        {
          int next = 0;
          int left = now;
          while(left > 0)
          {
            if(left%2 == 1)
            {
              next++;
            }
            left /= 2;
          }
          now = now%next;
          count++;
        }
      }
      cout << count << "\n";
    }
  }
  else
  {
    int kp = count1+1;
    vector<int> ps(n);
    int nowp = 0;
    int vp = 1;
    for(i=n-1;i>=0;i--)
    {
      vp %= kp;
      ps[i] = vp;
      vp *= 2;
      if(x[i] == '1')
      {
        nowp = (nowp+ps[i])%kp;
      }
    }
    rep(i,n)
    {
      int now;
      int count = 1;
      if(x[i] == '0')
      {
        now = (nowp+ps[i])%kp;
        while(now != 0)
        {
          int next = 0;
          int left = now;
          while(left > 0)
          {
            if(left%2 == 1)
            {
              next++;
            }
            left /= 2;
          }
          now = now%next;
          count++;
        }
      }
      else
      {
        count = 0;
      }
      cout << count << "\n";
    }
    
  }
  
}


Measured memory_bytes: 5244
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
  if a[i]%2==0:
    if a[i] % 3 != 0 and a[i] % 5 != 0:
      x+=1
if x==0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
s1=input()
s2=input()
l1=len(s1)
l2=len(s2)
dp=[[0 for i in range(l2+1)] for j in range(l1+1)]
for i in range(1,l1+1):
    for j in range(1,l2+1):
        if s1[i-1]==s2[j-1]:
            dp[i][j]=1+dp[i-1][j-1]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i=l1;j=l2
ans=""
while(i>0 and j>0):
    if s1[i-1]==s2[j-1]:
        ans=s1[i-1]+ans
        i-=1
        j-=1
    else:
        if dp[i-1][j]>dp[i][j-1]:
            i-=1
        else:
            j-=1
print(ans)


Measured memory_bytes: 119772
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int x = sc.nextInt();
	int cout = 0;
	for(int i = 0; i <= a; i++) {
		for(int j = 0; j <= b; j++) {
			for(int k = 0; k <= c; k++) {
				if(500 * i + 100 * j + 50 * k == x) {
					cout++;
				}
			}
		}
	}
	System.out.println(cout);
}
}


Measured memory_bytes: 21972
import sys
input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())

A = list(map(int, input().split()))


visited = set()
visited.add(1)
lst = [1, ]

now = 1
flg = 0
for i in range(K):
    now = A[now-1]
    if now in visited:
        last = K - i
        loop_point = now
        flg = 1
        break
    visited.add(now)
    lst.append(now)
if not flg:
    print(lst[-1])
    exit()    

for i in range(len(lst)):
    if lst[i] == loop_point:
        inter = i
        loop = lst[i:]

last = (last-1) % len(loop)
print(loop[last])

Measured memory_bytes: 115048
fun main(){
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray()

    var max = s.filter { it == 'R' }.size.toLong() * s.filter { it == 'G' }.size.toLong() * s.filter { it == 'B' }.size.toLong()

    for (i in 1 until s.size){
        for(j in 0 until i){
            val k = 2 * i - j
            if(k >= s.size) continue
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) max--
        }
    }

    println(max)
}

Measured memory_bytes: 36460
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;

struct st{
  int a, b;
  st(int _a, int _b) : a(_a), b(_b) {}
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<bool> used = vector<bool>(n, false);
  vector<vector<int> > edges = vector<vector<int> >(n, vector<int>());
  for(int i = 0; i < m; ++i){
    int from, to;
    cin >> from >> to;
    --from; --to;
    edges[from].push_back(to);
    edges[to].push_back(from);
  }
  for(int i = 0; i < edges.size(); ++i){
    sort(edges[i].begin(), edges[i].end());
  }
  deque<st> q;
  int var = edges[0][0];
  q.push_back(st(0, var));
  used[0] = used[var] = true;
  edges[0].erase(remove(edges[0].begin(), edges[0].end(), var), edges[0].end());
  edges[var].erase(remove(edges[var].begin(), edges[var].end(), 0), edges[var].end());
  while(true){
    var = q.front().a;
    int to = -1;
    for(int i = 0; i < edges[var].size(); ++i){
      if (!used[edges[var][i]]){
        to = edges[var][i];
        break;
      }
    }
    if (to == -1)
      break;
    q.push_front(st(to, var));
    used[to] = true;
    edges[to].erase(remove(edges[to].begin(), edges[to].end(), var), edges[to].end());
    edges[var].erase(remove(edges[var].begin(), edges[var].end(), to), edges[var].end());
  }
  while(true){
    var = q.back().b;
    int to = -1;
    for(int i = 0; i < edges[var].size(); ++i){
      if (!used[edges[var][i]]){
        to = edges[var][i];
        break;
      }
    }
    if (to == -1)
      break;
    q.push_back(st(var, to));
    used[to] = true;
    edges[to].erase(remove(edges[to].begin(), edges[to].end(), var), edges[to].end());
    edges[var].erase(remove(edges[var].begin(), edges[var].end(), to), edges[var].end());
  }
  cout << q.size()+1 << endl << q.front().a+1;
  while(!q.empty()){
    cout << " " << q.front().b+1;
    q.pop_front();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

int N = 0;
int W = 0;


int main(){
    //ナップサック問題　荷物の価値を最大化
    cin >> N;
    cin >> W;

    vector<vector<ll> > T;
    //重量：価値
    T = vector<vector<ll> >(N + 1, vector<ll>(2, 0));
    //初期化
    T[0][0] = 0;
    T[0][1] = 0;

    for(int i = 1; i <= N; i++){
        for(int j = 0;  j < 2; j++){
            cin >> T[i][j];
        }
    }
    
    //dp
    vector<vector<ll> > dp;
    dp = vector<vector<ll> >(N + 1, vector<ll>(W + 1, -1));
    dp[0][0] = 0;

    //答え
    ll ans = 0;

    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            if(dp[i - 1][j] > -1){
                //直下を更新
                if(dp[i][j] <= dp[i - 1][j]){
                    dp[i][j] = dp[i - 1][j];
                }
                //荷物を足し合わせたところを更新
                if(dp[i][j + T[i][0]] <= dp[i - 1][j] + T[i][1] && j + T[i][0] <= W){
                    dp[i][j + T[i][0]] = dp[i - 1][j] + T[i][1];
                    //ans確認
                    if(ans < dp[i - 1][j] + T[i][1]) ans = dp[i - 1][j] + T[i][1];
                }
            }          
        }

    }

    cout << ans << endl;

    //確認
    /*
    for(int i = 0; i < N + 1; i++){
        for(int j = 0; j < W + 1; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    

}

Measured memory_bytes: 80256
n = int(input())

if n == 3:
    print(2,5,63)
    exit()
elif n == 4:
    print(2,5,20,63)
    exit()
elif n == 5:
    print(2,5,20,30,63)
    exit()

ans = [8,9,2,3,4,10,6] + [0 for _ in range(n)]
k = 12
i = 7
while i < n:
    ans[i] = k
    ans[i + 1] = k + 2
    ans[i + 2] = k + 3
    ans[i + 3] = k + 4
    i += 4
    k += 6

ans = ans[:n]

temp = sum(ans) % 6

if temp == 2:
    ans[0] = k
elif temp == 3:
    ans[1] = k
elif temp == 5:
    if ans[n - 1] < k - 2:
        ans[1] = k - 2
    else:
        ans[1] = k + 4

print(' '.join(map(str, ans)))


Measured memory_bytes: 5160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int Q = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[][] spells = new char[Q][2];
        for (int i = 0; i < Q; i++) {
            spells[i][0] = sc.next().charAt(0);
            spells[i][1] = sc.next().charAt(0);
        }

        int ng=-1,ok=N;
        while( Math.abs(ng-ok) > 1){
            int mid = (ng+ok)/2;
            if(isOK(mid,spells,s) ==-1){
                ng = mid;
            }else{
                ok = mid;
            }
        }

        int leftOK = ok;

        ng=N;ok=-1;
        while( Math.abs(ng-ok) > 1){
            int mid = (ng+ok)/2;
            if(isOK(mid,spells,s) == 1){
                ng = mid;
            }else{
                ok = mid;
            }
        }

        int rightOK = N-1-ok;


        System.out.println( N - rightOK-leftOK);
    }

static    int isOK(int mid,char[][] spells ,char[] s ){
        for (int i = 0; i < spells.length; i++) {
            if(spells[i][0] == s[mid]){
                if(spells[i][1]=='L'){
                    mid--;
                }else{
                    mid++;
                }
                if(mid == -1) {
                    return -1;
                }
                if(mid == s.length) {
                    return 1;
                }
            }
        }
        return 0;
    }

}


Measured memory_bytes: 77040
import numpy as np
mod = 10 ** 9 + 7


def matpow(A, x):
    if x == 1:
        return A % mod
    elif x % 2 == 0:
        return matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
    else:
        ans = matpow(np.linalg.matrix_power(A, 2) % mod, x // 2)
        ans = ans.dot(A) % mod
        return ans


N, K = map(int, input().split(" "))
A = []
for _ in range(N):
    A.append(list(map(int, input().split(" "))))

A = np.array(A, dtype=object)
print(np.sum(matpow(A, K) % mod) % mod)

Measured memory_bytes: 19300
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    ll s; cin >> s;
    ll a = (s + 1000000000 - 1) / 1000000000;
    ll b = a * 1000000000 - s;
    cout << 0 << " " << 0 << " " << 1000000000 << " " <<  1 << " " << b << " " << a << endl;
    return 0;}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAX_N = 100000;
const int MAX_K = 1000;

ll N, K, x[MAX_N], y[MAX_N], ans;
char c;
ll xys[2][4*MAX_K][4*MAX_K];

ll sum_rect(int p1, int q1, int p2, int q2, int wb) {
  ll res = 0;
  res += xys[wb][p2][q2];
  if (0 < p1) res -= xys[wb][p1-1][q2];
  if (0 < q1) res -= xys[wb][p2][q1-1];
  if (0 < p1 && 0 < q1) res += xys[wb][p1-1][q1-1];
  return res;
}

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

  for (int i=0; i<N; i++) {
    scanf("%lld %lld %c", &x[i], &y[i], &c);
    int wb = (c == 'W') ? 0 : 1;
    xys[wb][x[i]%(2*K)][y[i]%(2*K)]++;
    xys[wb][x[i]%(2*K)+2*K][y[i]%(2*K)]++;
    xys[wb][x[i]%(2*K)][y[i]%(2*K)+2*K]++;
    xys[wb][x[i]%(2*K)+2*K][y[i]%(2*K)+2*K]++;
  }

  for (int wb=0; wb<2; wb++) {
    for (int i=0; i<4*K; i++) {
      for (int j=0; j<4*K; j++) {
        if (i == 0 && j != 0) {
          xys[wb][i][j] += xys[wb][i][j-1];
        } else if (i != 0 && j == 0) {
          xys[wb][i][j] += xys[wb][i-1][j];
        } else if (i != 0 && j != 0) {
          xys[wb][i][j] += xys[wb][i][j-1] + xys[wb][i-1][j] - xys[wb][i-1][j-1];
        }
      }
    }
  }

  ll ans1 = 0, ans2 = 0, sum1, sum2;
  for (int i=0; i<2*K; i++) {
    for (int j=0; j<2*K; j++) {
      int m = i + K, n = j + K;
      int k = i + 2*K-1, l = j + 2*K-1;
      sum1 = sum2 = 0;
      sum1 += sum_rect(i, j, m-1, n-1, 0) + sum_rect(m, n, k,   l, 0);
      sum1 += sum_rect(i, n, m-1,   l, 1) + sum_rect(m, j, k, n-1, 1);
      sum2 += sum_rect(i, j, m-1, n-1, 1) + sum_rect(m, n, k,   l, 1);
      sum2 += sum_rect(i, n, m-1,   l, 0) + sum_rect(m, j, k, n-1, 0);
      ans1 = max(ans1, sum1);
      ans2 = max(ans2, sum2);
    }
  }

  // for (int wb=0; wb<2; wb++) {
  //   for (int i=0; i<4*K; i++) {
  //     for (int j=0; j<4*K; j++) {
  //       cout << xys[wb][j][4*K-1-i] << " ";
  //       if (j == 2*K-1) cout << " ";
  //     }
  //     if (i == 2*K-1) cout << endl;
  //     cout << endl;
  //   }
  //   cout << endl;
  //   cout << endl;
  // }

  ans = (ans1 < ans2) ? ans2 : ans1;
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 251776