akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using P = pair<i64, i64>;

i64 u = 20000;
i64 v = 10000;

void solve(long long H, long long W, std::vector<std::vector<long long>> A, std::vector<std::vector<long long>> B){
    i64 h = H, w = W;
    auto a = A;
    auto b  = B;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(u, false)));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            i64 d = abs(a[i][j] - b[i][j]);
            if(i == 0){
                if(j == 0){
                    dp[i][j][v + d] = true;
                    dp[i][j][v - d] = true;
                }else{
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i][j - 1][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i][j - 1][k + d]) dp[i][j][k] = true;
                    }
                }
            }else{
                if(j == 0){
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i - 1][j][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i - 1][j][k + d]) dp[i][j][k] = true;
                    }
                }else{
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i - 1][j][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i - 1][j][k + d]) dp[i][j][k] = true;
                        if(k - d >= 0 && dp[i][j - 1][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i][j - 1][k + d]) dp[i][j][k] = true;
                    }
                }
            }
        }
    }
    i64 ans = 10000;
    for(i64 i = 0; i < u; ++i){
        if(dp[h - 1][w - 1][i]) ans = min(ans, abs(i - v));
    }
    cout << ans << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&B[i][j]);
        }
    }
    solve(H, W, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 16640
/*input
5 14 80
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}

fn main() {
    let v: Vec<u32> = read_line()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().expect(""))
        .collect();
    let mut count: u32 = 0;
    for i in v[0]..v[1] + 1 {
        if v[2] % i == 0 {
            count = count + 1;
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 5024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int a,b,c;
	int count;
	scanf("%d%d%d", &a, &b, &c);
	for(int i = a ; i <= b ; i++){
		if(c % i == 0){
			count++;
		}
	}
	printf("%d\n", count);
	return 0 ;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
int main() {
	LL x; cin >>x;
	LL ans = x / 11 * 2;
	if (ans / 2 * 11 < x) {
		if (ans / 2 * 11 + 6 < x) ans += 2;
		else ans ++;
	}
	cout <<ans<<endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    K = int(input())
    N = 50
    result = list(range(N))
    for x in range(N):
        result[x] += K // N
    K %= N

    for x in range(K):
        result[x] += N + 1
        for i in range(N):
            result[i] -= 1
    print (len(result))
    print (" ".join(map(str, result)))


Measured memory_bytes: 3060
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

wf arr range = do
    forM_ range $ \k -> do
        forM_ range $ \i -> do
            forM_ range $ \j -> do
                before <- readArray arr (i,j)
                after1 <- readArray arr (i,k)
                after2 <- readArray arr (k,j)
                writeArray arr (i,j) $ min before $ after1 + after2

cost arr (-1) = return 0
cost arr n = readArray arr (n,1)

main = do
    arr <- newArray ((0,0),(9,9)) 1234 :: IO (IOUArray (Int, Int) Int)
    [h, w] <- getInts
    forM_ [0..9] $ \i -> do
        cs <- getInts
        forM_ (zip cs [0..9]) $ \(c, j) -> writeArray arr (i,j) c
    wf arr [0..9]
    concat <$> replicateM h getInts >>= sequence . map (cost arr) >>= print . sum
    return ()



Measured memory_bytes: 8828
#include <bits/stdc++.h>
using namespace std;
int main () {
  // ios::sync_with_stdio(false);
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for(int i = 0; i < n; ++i) scanf("%d", &v[i]);
  
  if (n <= 2) {
    printf("1\n");
    return 0;
  }
  int ct = 0;
  int dir = 0;
  for(int i = 1; i < n; ++i) {
    if (v[i] > v[i - 1]) {
      if (dir < 0) {
        ct++;
        dir = 0;
      } else dir = 1;
    } else if (v[i] < v[i - 1]){
      if (dir > 0) {
        ct++;
        dir = 0;
      } else dir = -1;
    }
  }
 
  ct++;
  printf("%d\n", ct);
}

Measured memory_bytes: 640
import fractions, math

a, b = map(int, input().split())
gcd = fractions.gcd(a, b)

n = 2
cnt = 1
sq = math.sqrt(gcd)
while n <= sq:
    if gcd % n == 0:
        cnt += 1
        while gcd % n == 0:
            gcd = gcd // n
    n += 1
if gcd != 1:
    cnt += 1
print(cnt)

Measured memory_bytes: 5432
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template <class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template <class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template<class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define IN(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);

#define vin(name,n) int n; cin>>n; vector<T> name(n); for(auto &i : name)cin>>i;
#define vIn(name,n) vector<int> name(n); for(auto &i : name)cin>>i;
#define Vin(T,name,n) T n; cin>>n; vector<T> name(n); for(auto &i : name)cin>>i;
#define VIn(T,name,n) vector<T> name(n); for(auto &i : name)cin>>i;

#define vIn2(name,name2,n) vector<int> name(n),name2(n); rep(i,n)cin>>name[i]>>name2[i];
#define VIn2(T,name,name2,n) vector<T> name(n),name2(n); rep(i,n)cin>>name[i]>>name2[i];
#define VIN2(T,name,T2,name2,n) vector<T> name(n); vector<T2> name2(n); rep(i,n)cin>>name[i]>>name2[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
template<> void out(double a) { printf("%.20f\n", a); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void Yay(bool f) { puts(f ? "Yay!" : ":("); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(n);
	out(n % 2 == 0 ? n : n * 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


bool comp(const pair<int, int> p1, const pair<int, int> p2){
    if(p1.first == p2.first){
        return p1.second > p2.second;
    }
    return p1.first < p2.first;
}

ll dp[3010][3010];

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

    int n, t, a, b;
    vector<pair<int, int>> ab;
    cin >> n >> t;
    rep(i, n){
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }

    sort(all(ab));

    ll res = 0;
    rep(i, n){
        dp[i][t-1] = 0;
    }
    rep(i, n){
        repr(j, t, 0){
            if(j - ab[i].first > 0){
                chmax(dp[i+1][j], dp[i][j - ab[i].first] + ab[i].second);
            }
            chmax(dp[i+1][j], dp[i][j]);
            chmax(res, dp[i][j] + ab[i].second);
        }
    }

    cout << res << endl;

    // for(auto const& e : ab){
    //     cout << e.first sp e.second << endl;
    // }

    return 0;
}


Measured memory_bytes: 70912
import sys
S = input()
T = input()
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')
    sys.exit()

for i in range(s - t, -1, -1):
    OK = True
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
    if OK:
        for j in range(t):
            SS = S[:i] + T + S[i + j + 1:]
            SS = SS.replace('?', 'a')
        print(SS)
        sys.exit()

print('UNRESTORABLE')

Measured memory_bytes: 3064
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

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

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int h = -1, w, m, y, x, xm = 0, ym = 0, ans = 0;
		cin >> h >> w >> m;
		if (h <= 0) return 0;
		vector<int> yc(h), xc(w), by(m), bx(m);
		for (int i = 0; i < m; ++i) {
			cin >> y >> x;
			--y, --x;
			by[i] = y;
			bx[i] = x;
			yc[y] += 1;
			xc[x] += 1;
			ym = max(ym, yc[y]);
			xm = max(xm, xc[x]);
		}
		{
			set<II> f;
			set<int> vg;
			for (int i = 0; i < m; ++i) {
				if (xm == xc[bx[i]]) {
					vg.emplace(bx[i]);
					f.emplace(II(by[i], bx[i]));
				}
			}
			int sz = (int)vg.size();
			map<int, set<int>> mm;
			for (int i = 0; i < m; ++i) {
				if (ym == yc[by[i]]) {
					mm[by[i]].emplace(bx[i]);
				}
			}
			for (auto kv : mm) {
				int cross = 0;
				for (int x : kv.second) {
					if (f.find(II(kv.first, x)) != f.end()) {
						++cross;
					}
				}
				if (cross >= sz) {
					ans = max(ans, xm + ym - 1);
				} else {
					ans = xm + ym;
				}
			}
		}
		{
			set<II> f;
			set<int> hg;
			for (int i = 0; i < m; ++i) {
				if (ym == yc[by[i]]) {
					hg.emplace(by[i]);
					f.emplace(II(by[i], bx[i]));
				}
			}
			int sz = (int)hg.size();
			map<int, set<int>> mm;
			for (int i = 0; i < m; ++i) {
				if (xm == xc[bx[i]]) {
					mm[bx[i]].emplace(by[i]);
				}
			}
			for (auto kv : mm) {
				int cross = 0;
				for (int y : kv.second) {
					if (f.find(II(y, kv.first)) != f.end()) {
						++cross;
					}
				}
				if (cross >= sz) {
					ans = max(ans, xm + ym - 1);
				} else {
					ans = xm + ym;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;
const int MAXN=105;
int n,x,mx;
map<int,int> mp;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x),mx=max(x,mx),mp[x]++;
	if(mx==1&&n!=2) return !puts("Impossible");
	for(int i=mx;i>=0;i--)
	{
		int cur=max(i,mx-i);
		if(2*cur==mx)
		{
			if(mp[cur]!=1)
				return !puts("Impossible");
		}
		else if(2*cur-1==mx)
		{
			if(mp[cur]!=2)
				return !puts("Impossible");
		}
		else if(mp[cur]<2) return !puts("Impossible");
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int,input().split())

# aとcの距離ACを定義
if (a - c) >= 0:
    AC = (a-c)
else:
    AC = (c-a)

# BがAとCの間に入る場合のみ、AB間、BC間を定義
if a < b < c:
    AB = (b - a)
    BC = (c - b)
if c < b < a:
    AB = (a-b)
    BC = (b-c)

# AとCの距離がd以下ならYes！
if AC <= d:
    print('Yes')
# AB間、BC間ともにd以下ならYes！
elif AB <= d and BC <= d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9088
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void times(int n, void delegate() pred) {
    foreach(i; 0..n) pred();
}
T[] rep(T)(int n, T delegate() pred) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

int INF = 1<<25;
void main() {
    int N, K;
    readf("%d %d\n", &N, &K);

    Vertex[] vertices = N.rep(() => new Vertex());
    Edge[] edges = (N-1).rep({
        int a, b;
        readf("%d %d\n", &a, &b);
        a--; b--;
        vertices[a].edges ~= Edge(vertices[a], vertices[b]);
        vertices[b].edges ~= Edge(vertices[b], vertices[a]);
        return Edge(vertices[a], vertices[b]);
    });

    if (K%2==0) {
        vertices.map!((s) {
            vertices.each!(v => v.depth = INF);
            auto list = DList!(Vertex)(s);
            s.depth = 0;
            while (!list.empty) {
                Vertex v = list.front;
                list.removeFront;
                v.edges.each!((e) {
                    if (e.end.depth <= v.depth+1) return;
                    e.end.depth = v.depth+1;
                    list.insertBack(e.end);
                });
            }
            return vertices.count!(v => v.depth>K/2);
        }).reduce!min.writeln;
    } else {
        edges.map!((s) {
            vertices.each!(v => v.depth = INF);
            auto list = DList!(Vertex)([s.start, s.end]);
            s.start.depth = 0;
            s.end.depth = 0;
            while (!list.empty) {
                Vertex v = list.front;
                list.removeFront;
                v.edges.each!((e) {
                    if (e.end.depth <= v.depth+1) return;
                    e.end.depth = v.depth + 1;
                    list.insertBack(e.end);
                });
            }
            return vertices.count!(v => v.depth>(K-1)/2);
        }).reduce!min.writeln;
    }
}

class Vertex{
    Edge[] edges;
    int depth;
}

struct Edge {
    Vertex start, end;
}


Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <vector>
int main() {
  std::vector<std::string> v;
  std::string s;
  while(std::getline(std::cin, s, ' ')) {
    v.push_back(s);
  }
  int ans = 1;
  for(int i = 1; i < v.size(); ++i) {
    ans = ans * (v[i - 1][v[i - 1].size() - 1] == v[i][0]);
  }
  std::cout << (ans?"YES":"NO");
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


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

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

//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 PB push_back
#define MP make_pair
#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())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {
	int sum = 0;
	string t; cin >> t;
	for (char  c : t)c = tolower(c);

	while (1) {
		string s; cin >> s;

		if (s == "END_OF_TEXT")break;

		for (char &c : s)c = tolower(c);

		if (s==t) sum++;
	}

	cout << sum << endl;

	return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    bool first[n] = {};
    bool second[n] = {};
    while(m--){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(a == 0) first[b] = true;
        if(b == n-1) second[a] = true;
    }
    
    for(int i=0; i<n; i++){
       if(first[i] && second[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();
    println!("{}", if a <= c && c <= b { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	long long a,b,x,y,n,count=0;
	while(cin>>a>>b){
		if(a==0&&b==0)break;
		if(a>=b){
			x=a;y=b;
		}else{
			x=b;y=a;
		}
		while(1){
			if(y==0)break;
			x=x%y;
			swap(x,y);
		}
		n=a*b/x;
		cout<<x<<" "<<n<<endl;

	}
	return 0;
}

Measured memory_bytes: 3096
// This file is a "Hello, world!" in C# language by Mono for wandbox.
using System;
namespace Wandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine();
            char N = char.Parse(imp);
            switch(N)
                {
                case'A':
                    Console.Write('T');
                    break;
                case'T':
                    Console.Write('A');
                    break;
                case'C':
                    Console.Write('G');
                    break;
                case'G':
                    Console.Write('C');
                    break;
                    }
        }
    }
}
       

// Mono references:
//   http://www.mono-project.com/

// C# language references:
//   https://msdn.microsoft.com/library/618ayhy6.aspx


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

int main(void){
	sonic();
	ll n, k;
	cin >> n >> k;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	vector<ll> f(n);
	rep(i, n) cin >> f[i];
	sort(all(f));
	reverse(all(f));
	Vec b(n);
	rep(i, n) b[i] = a[i]*f[i];

	ll l = -1, r = 1e12;
	while(r-l > 1){
		ll m = (l+r)/2, sum = 0;
		rep(i, n) if(b[i] > m) sum += a[i]-m/f[i];
		if(sum <= k) r = m;
		else l = m;
	}

	co(r);

	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
string s;

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

    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes\n";
    } else{
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
struct stru{
	bool b[26];
};
string str;
stru s[2000001], empty;
void build(int id, int l, int r){
	if (l == r){
		for (int i = 0; i < 26; i++) s[id].b[i] = false;
		s[id].b[str[l] - 'a'] = true;
		return;
	}
	int mid = l + (r - l) / 2;
	build(id * 2, l, mid);
	build(id * 2 + 1, mid + 1, r);
	for (int i = 0; i < 26; i++) s[id].b[i] = s[id * 2].b[i] || s[id * 2 + 1].b[i];
}
void update(int id, int l, int r, int pos, char x){
	if (l == r){
		s[id].b[str[l] - 'a'] = false;
		s[id].b[x - 'a'] = true;
		str[l] = x;
		return;
	}
	int mid = l + (r - l) / 2;
	if (pos <= mid){
		update(id * 2, l, mid, pos, x);
	}else{
		update(id * 2 + 1, mid + 1, r, pos, x);
	}
	for (int i = 0; i < 26; i++) s[id].b[i] = s[id * 2].b[i] || s[id * 2 + 1].b[i];
}
stru query(int id, int l, int r, int L, int R){
	if (R < l || r < L){
		return empty;
	}else if (L <= l && r <= R){
		return s[id];
	}
	int mid = l + (r - l) / 2;
	stru ll = query(id * 2, l, mid, L, R), rr = query(id * 2 + 1, mid + 1, r, L, R), res;
	for (int i = 0; i < 26; i++) res.b[i] = ll.b[i] || rr.b[i];
	return res;
}
int main(){
	for (int i = 0; i < 26; i++) empty.b[i] = false;
	int n, q, x, y;
	char cc;
	cin >> n >> str >> q;
	build(1, 0, n - 1);
	for (int i = 0; i < q; i++){
		scanf("%d", &x);
		if (x == 1){
			scanf("%d %c", &y, &cc);
			update(1, 0, n - 1, y - 1, cc);
		}else{
			scanf("%d %d", &x, &y);
			stru ye = query(1, 0, n - 1, x - 1, y - 1);
			int count = 0;
			for (int i = 0; i < 26; i++) if (ye.b[i]) count++;
			printf("%d\n", count);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  int p1000 = n / 1000, p100 = n % 1000 / 100, 
      p10 = n % 1100 / 10, p1 = n % 1110 / 1;

  if (n == 1000) {
    cout << "Yes" << endl;
  } 
  else if (n == 1100) {
    cout << "No" << endl;
  }
  else if ((p1000 == p100 && p100 == p10) || (p100 == p10 && p10 == p1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

const int maxn = 510;

int n,m;
int a[maxn][maxn];
int X1[maxn*maxn],Y1[maxn*maxn],X2[maxn*maxn],Y2[maxn*maxn],num;

void read(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j] %= 2;
}

void work(){
    for(int i=1;i<=m;i++){
	for(int j=n;j>=2;j--){
	    if(a[j][i] == 1){
		a[j-1][i] ^= 1;
		num++;
		Y1[num] = j; X1[num]=i;
		Y2[num] = j-1; X2[num] = i;
	    }
	}
	if(a[1][i] == 1&&i<m){
	    a[1][i+1] ^= 1;
	    num++;
	    Y1[num] = 1; X1[num] = i;
	    Y2[num] = 1; X2[num] = i+1;
	}
    }
    printf("%d\n",num);
    for(int i=1;i<=num;i++){
	printf("%d %d %d %d\n",Y1[i],X1[i],Y2[i],X2[i]);
    }    
}

int main(){
    read();
    work();
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
using namespace std;
const int nmax=112345;

int n,k,h[nmax],cnt[nmax];

int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;++i)
        scanf("%d",&h[i]);
    cnt[1]=abs(h[1]-h[0]);
    for(int i=1;i<k && i<n;++i){
         cnt[i]=cnt[0]+abs(h[i]-h[0]);
            for(int j=1;j<i;++j)
                cnt[i]=min(cnt[j]+abs(h[i]-h[j]),cnt[i]);
    }
    for(int i=k;i<n;++i){
         cnt[i]=cnt[i-1]+abs(h[i]-h[i-1]);
            for(int j=2;j<=k;++j)
                cnt[i]=min(cnt[i-j]+abs(h[i]-h[i-j]),cnt[i]);
    }
    printf("%d",cnt[n-1]);

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size


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

    ll k,j;
    cin>>k;
    ll i,n,a;
    n=1<<k;
    vector<ll> v;
    multiset<ll> s;
    for(i=0;i<n;i++){
        cin>>a;
        s.insert(-1*a);
    }
    v.pb(*s.begin());
    s.erase(s.begin());
    for(i=0;i<k;i++){
        vector<ll> temp;
        for(j=0;j<v.sz();j++){
            auto it=s.upper_bound(v[j]);
            if(it==s.end()){
                cout<<"No"<<endl;
                return 0;
            }
            temp.pb(*it);
            s.erase(it);
        }
        for(j=0;j<temp.sz();j++)
            v.pb(temp[j]);
        sort(v.begin(),v.end());
    }
    cout<<"Yes"<<endl;
    return 0;  
}

Measured memory_bytes: 15560
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<string, string> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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


ull gcd(ull a, ull b) {
    while (a % b != 0) {
        ull tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

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


int n;

int main() {
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == a[i + 1]) {
            i++;
        }
        else {
            ans++;
        }

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

Measured memory_bytes: 1024
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;

string c[100];

int main(){
	int h,w;
	
		cin >> h >> w;
	
	for(int i=0;i<h;i++){
			cin >> c[i];
	}
	
	for(int i=0;i<h;i++){
		for(int k=0;k<2;k++){
				cout << c[i] << endl;
		}	
	}
	
	return 0;
};

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int n; cin >> n;
	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		cnt += b - a + 1;
	}
	cout << cnt << endl;
}

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

long long inv_merge(vector<int>& A, int i, int j, vector<int>& T) // [i, j)
{
    if (j - i <= 1) return 0;
    long long cnt = 0;
    int m = (i+j)/2;
    cnt += inv_merge(A, i, m, T);
    cnt += inv_merge(A, m, j, T);
    copy(&A[i], &A[j], &T[i]);
    int a = i, b = m, p = i;
    while (a < m && b < j) {
        if (T[a] <= T[b]) {
            A[p++] = T[a++];
        } else {
            A[p++] = T[b++];
            cnt += m - a;
        }
    }
    if (a < m) copy(&T[a], &T[m], &A[p]);
    if (b < j) copy(&T[b], &T[j], &A[p]);
    return cnt;
}

long long inv(const vector<int>& A) // #{(Ai,Aj)|i<j&&Ai>Aj}
{
    vector<int> B(A), T(A);
    return inv_merge(B, 0, B.size(), T);
}

bool ge(const vector<int>& A, int n) // median >= n
{
    vector<int> B(A.size());
    B[0] = A[0] >= n ? 1 : -1;
    for (int i = 1; i < A.size(); i++) {
        B[i] = (A[i] >= n ? 1 : -1) + B[i-1];
    }
    long long total = A.size()*(A.size()-1)/2;
    return inv(B) <= total / 2;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) cin >> A[i];
    int l = 1, r = 1000000000;
    while (l != r) {
        int m = (l + r + 1) / 2;
        if (ge(A, m)) {
            l = m;
        } else {
            r = m - 1;
        }
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1864
#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 INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  cin >> n;


  
  vector<int> A;
  REP(i,n){
      cin >> a;
      A.push_back(a);
  }
  ll mn = 99999999999999;
  REP(i,2){
    ll sum = 0;
    ll op = 0;
    REP(j,n){
        sum += A[j];
        if((i+j)%2==0 && sum >= 0){
            op += (sum+1);
            sum = -1;
        }else if((i+j)%2==1 && sum <= 0){
            op += (-sum+1);
            sum = 1;
        }
        //cout << sum <<  " " << op <<endl;
    }
    mn = min(mn,op);
  }
  cout << mn << endl;

}

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

bool broke[100010];
int fq[100010];
int modulo=1000000007;

int func(int a){
	if(broke[a]!=false){
		return 0;
	}
	if(a==0){
		return 1;
	}
	if(a==1){
		return 1;
	}
	if(a<0){
		return 0;
	}
	if(fq[a]!=-1)
		return fq[a];
	else{	
		fq[a]=(func(a-1)+func(a-2))%modulo;
		return fq[a];
	}
}

int main(){
	int n,m,x;
	cin >> n >> m;

	memset(fq,-1,sizeof fq);

	for(int i=m-1;i>=0;i--){
		cin >> x;
		broke[x]=true;
	}

	int tt = func(n);

	cout << tt << endl;
}


Measured memory_bytes: 3840
N = int(input())
S = input()

total = 0
 
total_list = []

# 事前に計算しておく
count_w_from_left = [0]
pre_count = 0
for i in range(1, N):
  if S[i-1:i] == 'W':
    pre_count += 1
  count_w_from_left.append(pre_count)

count_e_from_right = []
for i in range(N):
  count_e_from_right.append(0)
pre_count = 0
for i in range(N - 2, -1, -1):
  if S[i+1:i+2] == 'E':
    pre_count += 1
  count_e_from_right[i] = pre_count

# 算出処理
for i in range(N):
    to_E = count_w_from_left[i]
    to_W = count_e_from_right[i]
    total_list.append(to_E + to_W)
 
print(min(total_list))

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

typedef long long ll;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<string> vstr;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int main(){
  int n;
  cin >> n;
  
  vint a(n+1), b(n);
  cin >> a;
  cin >> b;
  
  ll ans=0;
  
  ll tmp;
  for(int i=0; i<n; i++){
    tmp = std::min(a[i], b[i]);
    ans += tmp;
    a[i] -= tmp;
    b[i] -= tmp;
    if(b[i]>0){
      tmp = std::min(a[i+1], b[i]);
      ans += tmp;
      a[i+1] -= tmp;
      b[i] -= tmp;
    }
  }
  
  cout << ans << endl;  
}

Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int kai(int n){
    if(n==1)return 1;
    return n*kai(n-1);
}

int getnum(vector<int> p){
    int n = p.size();
    if(n == 1)return 1;

    vector<int> r = p;
    sort(r.begin(),r.end());
    int target = p[0];
    p.erase(p.begin());
    return kai(n-1)*distance(r.begin(),find(r.begin(),r.end(),target))+getnum(p);
}

int main(){
    int n;
    cin >> n;
    vector<int> p,q,v;
    p.resize(n);
    q.resize(n);
    for(int i=0;i<n;i++)cin >> p[i];
    for(int i=0;i<n;i++)cin >> q[i];
  int num = getnum(p)-getnum(q);
    cout << max(num,-num) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

long X[200010];
long A[200010];

int main(void) {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		A[i] = X[i];
	}
	sort(X, X + N);
	int midl = X[N / 2 - 1];
	int midr = X[N / 2];
	for (int i = 0; i < N; i++) {
		if (A[i] <= midl) {
			cout << midr << endl;
		}
		else if (midr <= A[i]) {
			cout << midl << endl;
		}
	}
	//system("pause");
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N, H;
string s;
ll a[100010], b[100010];

int main(void) {
    cin >> N >> H;
    ll maxa=0, m_idx=0;
    for(int i=0; i<N; ++i){
        ll n, m; cin >> n >> m;
        a[i] = n; b[i]=m;
        if(maxa<n||(maxa==n&&b[m_idx]>b[i])){
            maxa = n;
            m_idx=i;
        }
    }
    ll cnt=0;
    sort(b, b+N);
    for(int i=N-1; i>=0; --i){
        if(a[m_idx]<b[i]&&i!=m_idx){
            H-=b[i];
            cnt++;
        }
        if(H<=0) break;
    }

    while(H>0){
        if(H<=b[m_idx]){
            cnt++;
            break;
        }
        H-=a[m_idx];
        cnt++;
    }
    cout << cnt << endl;
    
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
   int  a=0;
  REP(i,4){
    char b;
   cin >>b;
    if(b=='+')a++;
    else a--;
  }
  cout <<a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<P>E[100000];
bool used[100000];
int a[100000];

void dfs(int v){
	used[v]=true;
	for(auto p:E[v]){
		if(used[p.second]){
			if(a[v]+p.first!=a[p.second]){
				puts("No");exit(0);
			}
		}
		else{
			a[p.second]=a[v]+p.first;
			dfs(p.second);
		}
	}
}
signed main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int l,r,d;scanf("%d%d%d",&l,&r,&d);l--;r--;
		E[l].push_back(P(d,r));
		E[r].push_back(P(-d,l));
	}
	rep(i,n){
		if(!used[i]){
			dfs(i);
		}
	}
	puts("Yes");
}

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

using namespace std;

int main(void) {
	int n, k; cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < k; i++) {
		int d; cin >> d;
		for (int j = 0; j < d; j++) {
			int tmp; cin >> tmp;
			A[tmp - 1]++;
		}
	}

	int cnt = 0;
	for (int i = 0; i < A.size(); i++) {
		if (A[i] == 0) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
#define MAX 100000

int a[MAX],n;

int paetition(int p,int r){
    int x,i,j,t;
    x=a[r];
    i=p-1;
    
    for(j=p;j<r;j++){
        if(a[j]<=x){
            i++;
            t=a[i];
            a[i]=a[j];
            a[j]=t;
        }
    }
    t=a[i+1];
    a[i+1]=a[r];
    a[r]=t;

    return i+1;
}

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

    q=paetition(0,n-1);

    for(i=0;i<n;i++){
        if(i)printf(" ");
        if(i==q)printf("[");
        printf("%d",a[i]);
        if(i==q)printf("]");

    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 2120
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int now = 0;
    boolean check = false;
    String ans = "Yes";
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      if(n <= now-2 || (n < now && !check)){
        ans = "No";
        break;
      }else if(n > now){
        now = n;
        check = true;
      }else if(n < now && check){
        now--;
        check = false;
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 46908
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int[] count = new int[4+1];
        for (int i = 0; i < 6; i++) {
            count[sc.nextInt()]++;
        }
        
        int count2 = 0;
        for (int i = 1; i <= 4; i++) {
            if (count[i] == 2) count2++;
        }
        println(count2 == 2 ? "YES" : "NO");
    }

    static int    ni() { return sc.nextInt(); }
    static long   nl() { return sc.nextLong(); }
    static String n()  { return sc.next(); }
    
    static char[] nChars() { return n().toCharArray(); }
    static int[] nInts(int n) { 
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = ni();
        return a;
    }
    static void println(Object o)  { so.println(o);}
    static void println(long l)    { so.println(l);}
    static void println(char c)    { so.println(c);}
    static void println(double d)  { so.println(d);}
    static void println(boolean b) { so.println(b);}
    
    static void print(Object o)  { so.print(o);}
    static void print(long l)    { so.print(l);}
    static void print(char c)    { so.print(c);}
    static void print(double d)  { so.print(d);}
    static void print(boolean b) { so.print(b);}
}


Measured memory_bytes: 21844
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

n,p=map(int,input().split())
a=factorization(p)
ans=1
for x,y in a:
    y//=n
    ans*=x**y
print(ans)

Measured memory_bytes: 63440
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
  		int nums[] = new int[s]; 
      	int count = 0;
      	
      	for(int i = 0;i < s; i++){
        	nums[i] = sc.nextInt();
        }
      
      	for(int i = 1;i < s-1; i++){
        	if((nums[i-1] < nums[i] && nums[i] < nums[i+1]) ||
               (nums[i-1] > nums[i] && nums[i] > nums[i+1])){
              count++;
            }
        }
 		
      	System.out.println(count);
        
	}
}


Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

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

  if(a == b)
    cout << a + b << endl;
  else if(a > b)
    cout << a * 2 - 1 << endl;
  else
    cout << b * 2 - 1 << endl;

}





Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

struct edge {
    ll from;
    ll to;
    ll cost;
};

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

    int N;
    cin >> N;
    vector<vector<ll>> d(N, vector<ll>(N, INF)), G(N, vector<ll>(N));
    vector<vector<bool>> use(N, vector<bool>(N, true));
    rep(i, N) {
        rep(j, N) {
            cin >> G[i][j];
            d[i][j] = G[i][j];
        }
    }

    for (int k = 0; k < N; k++) {         // 経由する頂点
        for (int i = 0; i < N; i++) {     // 始点
            for (int j = 0; j < N; j++) { // 終点
                if (d[i][j] > d[i][k] + d[k][j]) {
                    cout << -1 << endl;
                    return 0;
                } else if (d[i][j] == d[i][k] + d[k][j] && i != k && k != j)
                    use[i][j] = false;

                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    ll ans = 0;

    rep(i, N) {
        rep(j, N) {
            if (use[i][j])
                ans += d[i][j];
        }
    }

    cout << ans / 2 << endl;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

//         18
//     17      15
// 16      14      11
//     13      10
// 12       9       6
//      8       5
//  7       4       2
//      3       1
//          0
inline int f(const string& s,int b,const int* a)
{
	int x=0;
	rep(i,7) x|=(b>>a[i]&1)<<i;
	return s[x]-'0';
}

int main()
{
	int a[][7]={
		{0, 1, 3, 4, 5, 8, 9},
		{1, 2, 4, 5, 6, 9,10},
		{3, 4, 7, 8, 9,12,13},
		{4, 5, 8, 9,10,13,14},
		{5, 6, 9,10,11,14,15},
		{8, 9,12,13,14,16,17},
		{9,10,13,14,15,17,18},
		{0, 1, 2, 3, 4, 5, 6},
	};
	for(string s;cin>>s && s!="#";){
		bool res=true;
		rep(i,1<<19){
			int x=0;
			rep(j,7) x|=f(s,i,a[j])<<j;
			int y=f(s,x,a[7]);
			res&=y==(x>>3&1);
		}
		cout<<(res?"yes":"no")<<endl;
	}
}

Measured memory_bytes: 1180
#include<stdio.h>
#define N 44

int A[N],cnt[N];

int fibo(int n){
  int i;
  if(n==0||n==1) return 1;
 
  
  if(A[n] != -10) return A[n]; 
    
  
  return A[n] = fibo(n-2)+fibo(n-1);
  
  }

int main(){
  int i,j,n,num=0;

  scanf("%d",&n);

  for(i=0;i<=N;i++){A[i] = -10;}
  
   num = fibo(n);

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

  return 0;
}



Measured memory_bytes: 2112