akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool calc(long a, long b, long c) {
    if (c - a - b <= 0) return false;
    return 4 * a * b < (c - a - b) ^^ 2;
}

void main() {
    long a, b, c; scan(a, b, c);
    writeln(calc(a, b, c) ? "Yes" : "No");
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 256
// Problem : E - 1 or 2
// Contest : AtCoder - AtCoder Beginner Contest 126
// URL : https://atcoder.jp/contests/abc126/tasks/abc126_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

vector<bool> visited(1000001,false);
vi a[1000001];
void dfs(int n)
{
	visited[n]=true;
	trav(i,a[n])
	{
		if(!visited[i])
		dfs(i);
	}
	
}
int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,m;
	int ans=0;
	cin>>n>>m;
//	fill(all(a),false);
	loop(i,m)
	{
		int b,c,t;
		cin>>b>>c>>t;
		a[b].pb(c);
		a[c].pb(b);
	}
	l00p(i,1,n+1)
	{
		if(!visited[i])
		{
			dfs(i);
			ans++;
		}
	}
	cout<<ans<<nl;
//	a.clear();
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 32972
import sys
input = sys.stdin.readline

INF = 10**12
N,M = map(int,input().split())
K = []
for i in range(M) :
    a,b = map(int,input().split())
    s = 0 #setをbitで管理.
    cx = list(map(int,input().split()))
    for c in cx :
        s = s | (1 << (c-1)) #setの和集合
    K.append([s, a])

#dp[bit]: 集合=bit のときのコストの最小値
dp = [INF]*(1 << N)
dp[0] = 0

for bit in range(1 << N) :
    for i in range(M) :
        s,a = K[i]
        t = bit | s
        cost = dp[bit] + a
        dp[t] = min(dp[t], cost)
ans = -1 if dp[-1] == INF else dp[-1]

print(ans)


Measured memory_bytes: 42348
from operator import itemgetter

n = int(input())
a = []
for i in range(n):
    a.append((i, int(input())))

a = sorted(a, key=itemgetter(1))
for i in range(n):
    if i == a[-1][0]:
        maxx = a[-2][1]
    else:
        maxx = a[-1][1]
    print(maxx)

Measured memory_bytes: 34748
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM


readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt

  vs <- VBM.new (n+1)
  VBM.set vs (Seq.empty)

  replicateM (n-1) $ do
    [a, b] <- getIntList
    sa <- VBM.read vs a
    VBM.write vs a (sa Seq.|> b)
    sb <- VBM.read vs b
    VBM.write vs b (sb Seq.|> a)

  vs' <- VB.freeze vs

  cs <- getIntList
  let cs' = sortBy (flip compare) cs

  ws <- VM.new (n+1)
  VM.set ws (0::Int)

  let bfs s cs | Seq.null s = return ()
               | otherwise = do
                   let x = Seq.index s 0
                       xs = Seq.drop 1 s
                   w <- VM.read ws x
                   if w == 0
                     then do VM.write ws x (head cs)
                             let cs' = tail cs
                                 xs' = xs Seq.>< (vs' VB.! x)
                             bfs xs' cs'
                     else bfs xs cs

  bfs (Seq.fromList [1]) cs'

  print $ sum $ tail cs'

  forM_ [1..n] $ \i -> do
    when (i > 1) $ putStr " "
    w <- VM.read ws i
    (putStr . show) w

  putStrLn ""

Measured memory_bytes: 6524
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    REP(i, N) cin >> A[i];

    for (int i = K; i < N; ++i) {
        if (A[i] > A[i - K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#define N 15
using namespace std;

int main()
{
  char str[N + 1];
  cin >> str;
  int count = 0;
  int i;
  for(i = 0; i < N; i++) {
    if(str[i] == 'o')
      count++;
    if(str[i + 1] == '\0')
      break;
  }
  string result = (count + (N - i - 1) >= 8)? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main()
{
	int n, a[100001] = {}, ans = 0;
	cin >> n;
	for (int i = 0; i< n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int x ,count=1;
	for (int i = 0; i < n; i++) {
		x = a[i];
		if (x == a[i+1]) { count++;}
		else {
			if (count < a[i]) ans += count;
			else if (count > a[i]) ans += count - a[i - 1];
			count = 1;
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

#include <stdlib.h>
int par(int *,int,int);
int main(){
  int ans,i,n,a[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  ans=par(a,0,n-1);
  for(i=0;i<n;i++){
    if(ans == i)
      printf("[");
    printf("%d",a[i]);
    if(ans == i)
      printf("]");
    
    if(i!=n-1) printf(" ");
    else printf("\n");
  }
  
  return 0;
}
int par(int *a,int s,int l){
  int j,ins,i,key,miniwall;
  key=a[l];
  miniwall=s;
  for(i=s;i<l;i++){
    if(a[i]<=key){
      ins = a[i];
      a[i] = a[miniwall];
      a[miniwall] = ins;
      miniwall++;
    }
    /*    for(j=0;j<l+1;j++){
      if(j==miniwall) printf("|");
      if(j==i) printf("|");
      printf("%d",a[j]);
    
      if(j!=l) printf(" ");
      else printf("\n");
*/

  }
  ins = a[l];
  a[l] = a[miniwall];
  a[miniwall] = ins;
  //  if(miniwall > 2)
  //  par(a,s,miniwall);
  // if(l-miniwall+1 > 2)
  //  par(a,miniwall+1,l);
  return miniwall;
}



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

int main() {
  int a;
  
  cin >> a;
  int result = 0;
  for (int i=0;i<a;i++){
    for (int j=0;j<a;j++){
      for (int k=0;k<a;k++){
        result+=gcd(gcd(i+1,j+1),k+1);
      }
    }
  }
  cout <<  result << "\n";
}
int gcd(int p, int q){
	if(p % q == 0)return q;
	return gcd(q, p % q);
}

Measured memory_bytes: 3640
import java.util.Scanner;

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

		while(true){
			int n=sc.nextInt();
			int r=sc.nextInt();
			if(n==0) break;

			int[] card=new int[n];
			for(int i=0;i<n;i++) card[i]=n-i;
			for(int i=0;i<r;i++){
				int p=sc.nextInt()-1;
				int c=sc.nextInt();
				int[] next=new int[n];
				for(int j= p ;j<p+c;j++) 
				    next[j-p]=card[j];
				for(int j= 0 ;j< p ;j++) 
				    next[c+j]=card[j];
				for(int j=p+c;j< n ;j++) 
				    next[ j ]=card[j];
				card=next;
			}
			System.out.println(card[0]);
		}

		return;
	}
}


Measured memory_bytes: 37932
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using ull = unsigned long long;
int main(){
	ull N{}, M{};
	std::cin >> N >> M;
	
	auto sqM =static_cast<ull>( std::sqrt(M) );
//	std::cout <<sqM<< "\n";
	std::vector<ull> Ds;
	for (ull i{ 1 }; i <= sqM; i++) {
	//	std::cout << M / i << " <= " << M << " " << i << "\n";
		if (M%i != 0) continue;
		
		if (M / i == i && i <= M/N )
			Ds.emplace_back(i);
		else {
			if (i <= M / N)
				Ds.emplace_back(i);
			if (M / i <= M / N)
				Ds.emplace_back(M / i);
		}
		
	}

	std::cout << *std::max_element(std::begin(Ds), std::end(Ds)) << "\n";

	/*
	for (const auto&e : Ds) {
		std::cout << e << "\n";
	}*/
		
	
	return 0;
}

Measured memory_bytes: 256
first = False
while 1:
    n = int(input())
    if n == 0:
        break

    if first:
        print()
    else:
        first = True

    data = []
    for _ in range(n):
        country, win, lose, draw = map(str, input().split())
        point = int(win) * 3 + int(draw)
        data.append([country, point])

    data.sort(key=lambda item: -item[1])

    for country, point in data:
        print(country + "," + str(point))



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

int main() {
  int A, B;
  cin >> A >> B;
  if((A > 8) || (B > 8)) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}
  

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

int main() {
  int N;
  scanf("%d", &N);

  int imos[100000+10]={};
  for (int i=0; i<N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    ++b;
    ++imos[a];
    --imos[b];
  }

  ++imos[1];
  --imos[100002];

  for (int i=1; i<=100001; ++i)
    imos[i+1] += imos[i];

  for (int i=N+2; i--;)
    if (i <= imos[i])
      return !printf("%d\n", i-1);

  return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

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

    int i = 0;
    while(i < S.size()) {
        cout << S.at(i);
        i += N;
    }
    cout << endl;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
vi a,b;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M;
    if(N*M%2)cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
    return 0;
}

Measured memory_bytes: 384
n = gets.to_i
p = gets.split(' ').map(&:to_i)
q = gets.split(' ').map(&:to_i)
arr = []
(1..n).each do |i|
  arr << i
end
per = arr.permutation.to_a
p1 = per.index(p) + 1
q1 = per.index(q) + 1

puts p1-q1 if p1 > q1
puts q1-p1 if q1 > p1
puts p1-q1 if p1 == q1

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int L; cin >> L;
  vector<int> A(L);
  rep(i, 0, L) cin >> A[i];
  vector<vector<int>> dp(L + 1,vector<int>(5, 1e9));
  dp[0][0] = 0;
  rep(i, 0, L) {
    int pre = dp[i][0];
    rep(j, 0, 5) {
      chmin(pre, dp[i][j]);
      if(j == 0 || j == 4) {
        chmin(dp[i+1][j], pre + A[i]);
      } else if(j == 1 || j == 3) {
        int dif = A[i] == 0 ? 2 : A[i] % 2;
        chmin(dp[i+1][j], pre + dif);
      } else {
        chmin(dp[i+1][j], pre + (A[i] + 1) % 2);
      }
    }
  }
  int ans = 1e9;
  rep(i, 0, 5) chmin(ans, dp[L][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    FILE*DSA=freopen("water.in","r",stdin);
    FILE*SDU=freopen("water.out","w",stdout);
#endif
}

const int MAXN=1e5+7;

static int n,l,q;

static int x[MAXN];

inline void init()
{
	read(n);
	Rep(i,1,n)read(x[i]);
	read(l);read(q);
}

static int nxt[19][MAXN],pr[19][MAXN];

inline void solve()
{
	x[n+1]=INT_MAX;
	Rep(i,1,n)
	{
		nxt[0][i]=upper_bound(x+1,x+n+2,x[i]+l)-x-1;
		pr[0][i]=lower_bound(x+1,x+n+2,x[i]-l)-x;
	}
	Rep(i,0,17)nxt[i][n+1]=n+1;
	Rep(i,0,17)pr[i][0]=0;
	Rep(j,1,17)Rep(i,1,n)nxt[j][i]=nxt[j-1][nxt[j-1][i]],
	pr[j][i]=pr[j-1][pr[j-1][i]];
	static int st,ed,ans;
	Rep(i,1,q)
	{
		read(st),read(ed);
		ans=0;
		if(st<ed)
		{
			Repe(i,17,0)if(nxt[i][st]<ed)
				ans|=1<<i,st=nxt[i][st];
			write(ans+1);
		}
		else
		{
			Repe(i,17,0)if(pr[i][st]>ed)
				ans|=1<<i,st=pr[i][st];
			write(ans+1);
		}
	}
	flush();
}

int main()
{
    init();
    solve();
    return 0;
}


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

int main() {
  ll n;
  cin >> n;

  ll min = 1e12;
  ll a;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0 && abs(i - n / i) < min) {
      min = abs(i - n / i);
      a = i;
    }
  }

  cout << (a - 1) + (n/a - 1) << endl;
}


Measured memory_bytes: 256
long n, k;

long fun(long n, long x){
	if(n==0)return(x<=0?0:1);
	long p=(1LL<<n)-1;
	if(x<=2*p)return fun(n-1,x-1);
	return p+1+fun(n-1,x-1-2*p);
}

main(){
	scanf("%ld%ld",&n,&k);
	printf("%ld\n",fun(n,k));
}

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

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0)
        {
            cout << " " << i;
            continue;
        }
        int x=i;
        do
        {
            if(x%10==3)
            {
                cout << " " << i;
                break;
            }
            x/=10;
        }
        while(x);
    }
    cout << endl;
}


Measured memory_bytes: 3096
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    int N; cin>>N;
    vector<vector<int>> happy(N+3, vector<int>(3, 0));
    vector<vector<int>> abc(N+3, vector<int>(3, 0));

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin>>abc[i][j];
        }
    }
    happy[0][0]=abc[0][0]; happy[0][1]=abc[0][1]; happy[0][2]=abc[0][2];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(j==k) continue;
                happy[i+1][k] = max(happy[i+1][k], happy[i][j]+abc[i+1][k]);
            }
        }
    }
    cout<<max({happy[N-1][0],happy[N-1][1],happy[N-1][2]})<<endl;

    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char const *argv[]) {

    std::string S;
    std::cin >> S;

    std::vector<bool> showed_alphabet(26);

    bool overlapping_find_word = false;
    for(const auto& word : S)
    {
        int alphabet_index = word - 'a';
        if(showed_alphabet[alphabet_index] == true)
        {
            overlapping_find_word = true;
            break;
        }

        showed_alphabet[alphabet_index] = true;
    }

    std::cout << (overlapping_find_word ? "no" : "yes" ) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int card[200];
	int n;
	int work_space[200];
	int work;
	int work_cnt;
	
		scanf("%d", &n);
		
		for (int i = 0; i < 2 * n; i++){
			card[i] = i + 1;
		}
		
		scanf("%d", &work_cnt);
		for (int i = 0; i < work_cnt; i++){
			scanf("%d", &work);
			
			if (work == 0){
				int j;
				
				j = 0;
				for (int i = 0; i < n; i++){
					work_space[j++] = card[i];
					work_space[j++] = card[n + i];
				}
				memcpy(card, work_space, sizeof(card));
			}
			else {
				int i;
				int j;
				
				for (i = 0; i < work; i++){
					work_space[i] = card[i];
				}
				j = 0;
				for (; i < 2 * n; i++){
					card[j++] = card[i];
				}
				memcpy(&card[j], work_space, sizeof(int) * work);
			}
		}
		for (int i = 0; i < 2 * n; i++){
			printf("%d\n", card[i]);
		}
	
	return (0);
}

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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L.at(i);
  sort(L.begin(), L.end());
  int ans=0;
  for(int i=0; i<N-2; i++){
    for(int j=i+1; j<N-1; j++){
      for(int k=j+1; k<N; k++){
        if(L.at(i)+L.at(j)>L.at(k)) ans++;
        else break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// includes, macros {{{
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

#define rep(i, s, e)    for (int i = (s); i < (int)(e); i++)
//#define PB(e) push_back(e)
//#define MP(a, b) make_pair(a, b)

// for debug
#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}
 
typedef long long ll;
typedef unsigned long long ull; // }}}

int main(){
    int n, k;
    bool kirai[10];
    rep(i, 0, 10){
        kirai[i] = false;
    }

    cin >> n >> k;

    rep(i, 0, k){
        int d;
        cin >> d;
        kirai[d] = true;
    }

    for(int i=n;;i++){
        for(int j=1;;j*=10){
            if(j>i){
                cout << i << endl;
                return 0;
            }
            if(kirai[(i/j)%10]){
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
  #include<fstream>
  #include<vector>
  #include<initializer_list>
  #include<string>
  using namespace std;
    int main(){
   string c;
   cin >> c;

   if (c=="a" || c=="i" || c=="u" || c=="e" || c=="o")
   {cout << "vowel" << endl;}

   else {cout << "consonant" << endl;}







  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
//cout<<123<<endl;
  int N;
  int ans =0;
  cin>>N;
  int A[N];// 0 indexed
  int B[N];
  vector <int> D(0);
  vector <int> D1(0);
  vector<int> D2(0);
  ll asum = 0,bsum = 0;
  for(int i=0;i<N;i++) {cin>>A[i];asum+=A[i];}
  for(int i=0;i<N;i++) {cin>>B[i];bsum+=B[i];}
  if(asum<bsum) {cout<<-1<<endl;return 0;}
  for(int i=0;i<N;i++) D.push_back(A[i]-B[i]); //ズレを収納
  sort(D.begin(),D.end());//昇順ソート
  for(int i=0;i<D.size();i++){
    if(D[i]==0) {
    // ans++;
      D.erase(D.begin()+i);
      continue;
    }
    if(D[i]<0) D1.push_back(D[i]);
    else D2.push_back(D[i]);
  }
  
  ll D1sum=0;
  for(int i=0;i<D1.size();i++) D1sum += D1[i];
  ll sumleft= - D1sum;
  int memori;
  while(sumleft > 0){
    memori=D2[D2.size()-1];//現状の最大
    D2.erase(D2.begin()+D2.size()-1);// memoriに入れたら消す
    ans++;
    sumleft = sumleft - memori;
  }
  ans += D1.size();
  cout<<ans<<endl;
  
  
  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> data(n);
  rep(i,n) {
    cin >> get<0>(data.at(i)) >> get<1>(data.at(i));
    get<2>(data.at(i)) = i + 1;
  }
  rep(i,n) get<1>(data.at(i)) = 100 - get<1>(data.at(i));
  sort(data.begin(), data.end());
  rep(i,n) cout << get<2>(data.at(i)) << endl;
}

Measured memory_bytes: 256
import math
a,b,x = map(int,input().split())

if x >= a*a*b/2:
  y = ((2*x)/(a*a)) - b
  ans = math.degrees(math.atan((b-y)/a))
  
else:
  y = (2*x/a)/b
  ans = math.degrees(math.atan(b/y))

print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int inf = (int)1.05e9;

struct Edge
{
	int to, cap, cost, rev;
	Edge(int to, int cap, int cost, int rev) :
		to(to), cap(cap), cost(cost), rev(rev) {}
};

struct Graph
{
	vector<vector<Edge> > g;

	void init(int n)
	{
		g.resize(n);
	}

	void add_edge(int from, int to, int cap, int cost)
	{
		g[from].push_back(Edge(to, cap, cost, g[to].size()));
		g[to].push_back(Edge(from, 0, -cost, g[from].size()-1));
	}

	int push_mincost_flow(int s, int t, int f)
	{
		int ans = 0;
		vector<int> h(g.size(), 0);

		while(f > 0) {

			vector<int> dist(g.size(), inf);
			vector<pair<int, int> > his(g.size());
			priority_queue<pair<int, int> > q;

			q.push(make_pair(0, s));
			dist[s] = 0;

			while(!q.empty()) {
				int d = -q.top().first;
				int v = q.top().second;
				q.pop();
				if(dist[v] < d)
					continue;
				for(int i = 0; i < g[v].size(); ++i) {
					Edge &e = g[v][i];
					if(e.cap <= 0)
						continue;
					int p = d + e.cost + h[v] - h[e.to];
					if(dist[e.to] <= p)
						continue;
					dist[e.to] = p;
					his[e.to] = make_pair(v, i);
					q.push(make_pair(-p, e.to));
				}
			}

			for(int i = 0; i < g.size(); ++i)
				h[i] += dist[i];

			if(h[t] >= inf)
				return inf;

			int cap = f;

			for(int v = t; v != s; v = his[v].first)
				cap = min(cap, g[his[v].first][his[v].second].cap);
			for(int v = t; v != s; v = his[v].first) {
				Edge &e = g[his[v].first][his[v].second];
				e.cap -= cap;
				g[e.to][e.rev].cap += cap;
			}

			f -= cap;
			ans += cap * h[t];
		}

		return ans;
	}
};

int main()
{
	int n;
	vector<int> a, b;
	vector<int> hs;

	scanf("%d", &n);
	a.resize(n); b.resize(n);
	for(int i = 0; i < n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		if(a[i] < b[i]) swap(a[i], b[i]);
		hs.push_back(a[i]);
		hs.push_back(b[i]);
	}
	sort(hs.begin(), hs.end());
	hs.erase(unique(hs.begin(), hs.end()), hs.end());

	Graph g;

	g.init(2 + n + hs.size() + 1);

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

		int v = 2 + i;
		int av = lower_bound(hs.begin(), hs.end(), a[i]) - hs.begin() + (2 + n);
		int bv = lower_bound(hs.begin(), hs.end(), b[i]) - hs.begin() + (2 + n);
		int cv = 2 + n + hs.size();

		g.add_edge(0, v, 1, 0);
		g.add_edge(v, av, 1, a[i] - b[i]);
		g.add_edge(v, bv, 1, 0);
		g.add_edge(v, cv, 1, a[i]);
	}

	for(int i = 0; i < hs.size(); ++i)
		g.add_edge(2 + n + i, 1, 1, 0);
	g.add_edge(2 + n + hs.size(), 1, n, 0);

	int c = g.push_mincost_flow(0, 1, n);
	int total = 0;
	for(int i = 0; i < n; ++i)
		total += a[i];

	int ans = total - c;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1456
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long n = in.nextLong();
		System.out.println(solve(n));
		in.close();
	}
 
	private static long solve(long n) {
		long r = (long) (Math.pow(n, 0.5) + 1);
		for (; r > 1; r--)
			if (n % r == 0)
				return n / r + r - 2;
		return n - 1;
	}
}

Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int n, m;
    cin >> n >> m;
    int sum=0, a;
    rep(i, m){
        cin >> a;
        sum += a;
    }

    if(sum > n) cout << -1 << endl;
    else cout << n-sum << endl;
    return 0;
}

Measured memory_bytes: 3612
//
// Created by 倉澤　一詩 on 2020/04/03.
//
#include <iostream>
#include <string>


int main(){

    std::string s;
    std::getline(std::cin, s);

    while (0 < s.length()) {

        if (s.substr(s.length()-5) == "dream"){
            for (int j = 0; j < 5; ++j) {
                s.pop_back();
            }

        } else if (s.substr(s.length()-5) == "erase"){
            for (int j = 0; j < 5; ++j) {
                s.pop_back();
            }

        } else if (s.substr(s.length()-6) == "eraser"){
            for (int j = 0; j < 6; ++j) {
                s.pop_back();
            }

        } else if (s.substr(s.length()-7) == "dreamer"){
            for (int j = 0; j < 7; ++j) {
                s.pop_back();
            }

        } else {

            std::cout << "NO";
            return 0;
        }

    }

    std::cout << "YES";

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n==111){
		printf("999\n");
	}
	else if(n==911){
		printf("199\n");
	}
	else if(n==191){
		printf("919\n");
	}
	else if(n==119){
		printf("991\n");
	}
	else if(n==991){
		printf("119\n");
	}
	else if(n==199){
		printf("911\n");
	}
	else if(n==919){
		printf("191\n");
	}
	else if(n==999){
		printf("111\n");
	}
	return 0;
}	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<t*((n+x-1)/x)<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int a,b,c,sunuke,i,sika,ka;
    cin >> a >> b;
    sika = a*b;
    vector<int> vec(b);
    vector<int> sunu(sika);
    sunuke =0;
    for(int ii=0;ii <b;ii++){
        cin >>c;
        c = c + sunuke;
    for(i = sunuke;i < c;i++){
        cin >> sunu.at(i);
    }
    sunuke = i;
    }

    sort(sunu.begin(),sunu.end());
    for(int ii =0;ii < sika-1;ii++){
        if(sunu.at(ii)!=0&&sunu.at(ii)!=sunu.at(ii+1)){
            ka = ka +1;
        }
    }
    ka = ka+1;
    cout << a-ka<<endl;

}

Measured memory_bytes: 3640
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    string s;
    cin >> s;
    if(s=="AAA" || s=="BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(void){
  string str;
  cin >> str;
  int ans = 0;
  for(int i = 0; i < str.size(); ++i){
    if(str[i] == '+'){
      ++ans;
    } else {
      --ans;
    }
  }

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

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

using pii = pair<int, int>;
#define X first
#define Y second

const int N = 100005;

vector<pii> e[N];

int n, m, a[N], v[N];

int f(int x, int y){
	v[x] = 1;
	a[x] = y;
	for(pii i : e[x]){
		if(v[i.X]) continue;
		f(i.X, y + i.Y);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for(int x, y, z; m--; ){
		cin >> x >> y >> z;
		e[x].emplace_back(y, z);
		e[y].emplace_back(x, -z);
	}
	for(int i = 1; i <= n; i++){
		if(v[i]) continue;
		f(i, 0);
	}
	for(int i = 1; i <= n; i++){
		for(pii j : e[i]){
			if(a[i] + j.Y != a[j.X]){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
}

Measured memory_bytes: 11520
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXT = 200000;
const int MAXM = 531450;

char T[MAXT + 5]; int N, M, K, lenT;
int pw3(int x) {
	int r = 1;
	for(int i=1;i<=x;i++) r *= 3;
	return r;
}

int b[3][MAXM + 5], t[MAXT + 5], t1[MAXT + 5], id[3];

int a[MAXM + 5], ans[MAXM + 5], res[MAXM + 5];
int main() {
	scanf("%d%s", &N, T), M = 3, K = 1, lenT = strlen(T);
	for(int i=1;i<=N;i++,M*=3,K*=3) {
		for(int j=0;j<3;j++)
			for(int k=0;k<K;k++)
				b[j][k] = j;
		
		id[0] = 0, id[1] = 1, id[2] = 2;
		for(int j=0;j<lenT;j++) {
			if( T[j] == 'S' )
				swap(id[1], id[2]);
			else {
				int x = t[j], a0 = b[id[0]][x], a1 = b[id[1]][x], a2 = b[id[2]][x];
				t1[j] = b[id[2]][x]*K + x;
				b[id[0]][x] = a2, b[id[1]][x] = a0, b[id[2]][x] = a1;
			}
		}
		for(int j=0;j<lenT;j++) t[j] = t1[j];
		
		for(int j=0;j<3;j++)
			for(int k=0;k<K;k++)
				res[b[id[j]][k]*K + k] = j*K + ans[k];
		for(int j=0;j<M;j++) ans[j] = res[j];
	}
	
	for(int i=0;i<M/3;i++) printf("%d ", ans[i]);
}

Measured memory_bytes: 11884
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define SC(x) scanf("%d",&x);
#define pr(x)  cout << x << endl;
#define mem(arr,v) memset(arr,v,sizeof arr);
#define bug(x) cout << "#x = " << x <<endl;
const int inf = 0x3f3f3f3f;
const int maxn = 1010;
typedef long long ll;
using namespace std;
char Mz[maxn][maxn],c;
bool vis[maxn][maxn];
int dir[4][2] = {1,0,-1,0,0,1,0,-1};
int M,N,C;
int px[10],py[10];
struct node {
	int x,y,step;
};

int bfs(int des,int sx,int sy) {
	mem(vis,0);
	vis[sx][sy] = 1;
	node nod = {sx,sy,0};
	queue<node> q;
	q.push(nod);

	while(!q.empty()) {
		nod =  q.front();
		q.pop();
		
		int x = nod.x, y = nod.y;
		int step =  nod.step;
		
		if(Mz[x][y] == des + '0')
			return step;
		for(int i =0 ; i < 4 ; i++) {
			int dx = x + dir[i][0];
			int dy = y + dir[i][1];
			if(Mz[dx][dy] == 'X' || Mz[dx][dy] == -1 || vis[dx][dy])	continue;
			nod = {dx,dy,step + 1};
			q.push(nod);
			vis[dx][dy] = 1;
		}
	}
}

int main() {
//	freopen("in.txt","r",stdin);
	cin >> N >> M >> C;
	mem(Mz,-1)
	mem(px,0)  mem(py,0)

	for(int i = 1 ; i <= N ; i++)
		for(int j = 1; j <= M ; j++) {
			cin >> c;
			Mz[i][j] = c;
			if(c == '.' || c == 'X')	continue;
			if(c == 'S') px[0] = i, py[0] = j;
			else
				px[c - '0'] = i , py[c - '0'] = j;
		}
	int res = 0;
	for(int i = 0 ; i < C ; i++) {
		if(px[i] && py[i]) {
//				dfs(i + 1,px[i],py[i],0);
			res += bfs(i + 1,px[i],py[i]);
		}
	}
	printf("%d\n",res);
}

Measured memory_bytes: 5284
def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
 
N=int(input())
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))

Measured memory_bytes: 14052
from collections import deque

N = int(input())
s = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    s[a - 1].add(b - 1)
    s[b - 1].add(a - 1)
c = list(map(int, input().split()))
c.sort(reverse=True)
ans = [0] * N
ans[0] = c[0]
cp = 1
i = 0
pre = -1
dq = deque()
while True:
    for x in s[i]:
        if x != pre:
            ans[x] = c[cp]
            cp += 1
            dq.appendleft((x, i))
    if dq:
        i, pre = dq.pop()
    else:
        break

print(sum(c[1:]))
print(' '.join(map(str, ans)))

Measured memory_bytes: 7860
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve()
{
	ll x;
	cin>>x;
	ll t1=x/500;
	x=x%500;
	ll t2=x/5;
	cout<<t1*1000+t2*5;
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x,y) __gcd(x,y)
#define PI 3.14159265
#define endl "\n"
#define count_ones __builtin_popcountl
#define piii pair<int,pair<int,int>>
const int N=1e5+20,MOD=(int)(1e9)+7;
const int oo = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
ll modPower(ll x, ll y,ll p){
    ll res=1;
    x%=p;
    while(y>0){
        if(y&1) res=(res*x)%p;
        y=y>>1; 
        x=(x*x)%p;
    }
    return res;
}
inline void boost(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
ll GCD(ll a, ll b){
	if(a==0)return b;
	return GCD(b%a,a);
}
/* -------------------------------------- */

/* -------------------------------------- */

int main() {
	boost();
	ll n,q;cin>>n>>q;
//	vector<int> adj[n];
	multimap<ll,ll> mp;
	for(ll i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		mp.insert({a,b});
	}
	vector<ll> ans(n+1,0);
	for(ll i=0;i<q;i++){
		ll a,b;cin>>a>>b;
		ans[a]+=b;
	}
	for(auto a : mp){
		ans[a.second]+=ans[a.first];
	}
	for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}

Measured memory_bytes: 16512
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*N
for i in range(1,N):
    tmp = 10**10
    for j in range(1,min(i+1,K+1)):
        tmp = min(tmp,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = tmp
print(dp[-1])

Measured memory_bytes: 52448
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int X;

  cin >> X;

  long long ans = 0;

  int c500 = X/500;
  int temp = X%500;

  ans += c500*1000;

  int c5 = temp/5;

  ans += c5*5;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int M = sc.nextInt();
    init(n);
    int[] p = new int[n];
    
    for(int i = 0; i < n; i++) {
      int d = sc.nextInt() - 1;
      p[d] = i;
    }
    for(int i = 0; i < M; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      unite(a, b);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
      if(same(i, p[i])) ans++;
    } 
    System.out.println(ans);
  }
  static void init(int m) {
      for(int i = 0; i < m; i++) {
        par[i] = i;
        rank[i] = 1;
      }
    }
  static int find(int x) {
      if(par[x] == x) {
        return x;
      } else {
        return par[x] = find(par[x]);
      }
    }
  static void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if(x != y) {
        if(rank[x] < rank[y]) {
          par[x] = y;
          rank[y] += rank[x];
        } else {
          if(rank[x] == rank[y]) {
            if(x > y) {
              par[x] = y;
              rank[y] += rank[x];
            } else {
              par[y] = x;
              rank[x] += rank[y];
            }
          } else {
            par[y] = x;
            rank[x] += rank[y];
          }
        }
      }
    }
  static boolean same(int x, int y) {
      return find(x) == find(y);
  }
}

Measured memory_bytes: 91040
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
int a[26];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    memset(a,0,sizeof(a));  
    string s;
    cin>>s;
    int ans=0;
    int flag=0;
    REP(i,s.length())
    {
        if(s[i]!=s[s.length()-i-1])
        ans++;
    }
    cout<<ans/2;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  int L,R,d;
  int ans=0;
  cin>>L>>R>>d;
  for(int i=L;i<=R;i++){
    if(i%d==0)ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
	int n,a,b,c,d,sum,count;
	
	
	while(scanf("%d",&n) != EOF){
	count = 0;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					sum = 0;
					
					sum = a+b+c+d;
					
					if(sum == n){
						count += 1;
					}else{
						;
					}
				}
				
			}
		}
	}
	printf("%d\n",count);
	}
	
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    ll i = 0;
    for (i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A')
            break;
    }
    ll k = 0;
    for (k = s.size() - 1; k >= 0; k--)
    {
        if (s[k] == 'Z')
            break;
    }

    cout << (k - i + 1) << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    //標準入力からデータを読み込む準備
    Scanner sc = new Scanner(System.in);
    //2つの文字の塊をそれぞれ整数値と想定して読み込む
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a * b;
    int length = 2 * (a + b);
    System.out.println(area + " " + length);
  }
}



Measured memory_bytes: 26244