akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define chmin(a, b) a = min((a), (b));
using namespace std;
const int N = 2e2;
const int V = 2e5;
const int INF = 1<<30;

struct good {
    int w;
    int v;
};

int n, w;
good g[N];
long dp[N][V];

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++)
        cin >> g[i].w >> g[i].v;

    fill(dp[0], dp[N], INF);

    dp[0][0] = 0;
    dp[0][g[0].v] = g[0].w;
    for(int i = 0; i < n; i++) {
        for(int v = 0; v < V; v++) {
            chmin(dp[i+1][v], dp[i][v]);
            chmin(dp[i+1][v+g[i+1].v], dp[i][v]+g[i+1].w);
        }
    }
    long ans = 0;
    for(int v = 0; v < V; v++) {
        if(dp[n-1][v] <= w)
            ans = v;
    }

    cout << ans << endl;
}

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

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


int main(){
    string S,T;
    int flag1 = 0;
    int flag2 = 0;

    cin >> S >> T;

    flag1 = equal(T.begin(),T.end()-1,S.begin());
    
    if(S.length() == T.length()-1){
        flag2 = 1;
    }


    if(flag1==1&&flag2==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3620
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 2e5 + 5;

int n;
int go[N];

void solve() {
  cin >> n;
  ll k; cin >> k;
  for(int i = 1; i <= n; i++) {
    int x; cin >> x;
    go[i] = x;
  }
  int p = 1;
  int who = -1;
  set <int> s;
  while(true) {
    p = go[p];
    if(s.count(p)) {
      who = p;
      break;
    }
    s.insert(p);
  }
  int old = who;
  vector <int> cyc;
  cyc.push_back(who);
  while(true) {
    who = go[who];
    if(who == old) break;
    cyc.push_back(who);
  }
  int cur = 1;
  while(true) {
    cur = go[cur];
    k--;
    if(cur == old) {
      break;
    }
    if(k == 0) {
      print(cur);
      return;
    }
  }
  int m = cyc.size();
  cout << cyc[k % m] << '\n';
}

int main() {
  int t; t = 1;
  while(t--) solve();
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll n, m;
    cin >> n >> m;
    ll ok = 0;
    ll ng = m / 2 + 1;
    while(ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll C = m - 2 * mid;
        ll S = n + C / 2 - mid;
        if(S >= 0) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

using R = long double;
constexpr R eps = 1e-14;
int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  R a, b, c;
  cin >> a >> b >> c;
  cout << (sgn(sqrt(a) + sqrt(b), sqrt(c)) < 0 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n,k;
    string s;
    cin>>n>>s>>k;
    REP(i,s.size()){
        if(s[i]!=s[k-1]){
            cout<<'*';
        }else{
            cout<<s[i];
        }
    }
    cout<<endl;
    return 0;
}


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

using namespace std;

const int INF = 0x3f3f3f3f;

using LL = long long;

int main() {

	ios_base :: sync_with_stdio(0); cin.tie(NULL);
	
	int h, n;
	cin >> h >> n;

	vector<LL> dp(h + 1, INF);

	dp[0] = 0LL;

	while(n--) {
		int a, b;
		cin >> a >> b;

		for(int i = 0; i <= h; ++i) {
			int j = min(i + a, h);
			dp[j] = min(b + dp[i], dp[j]);
		}	
	}

	cout << dp[h] << '\n';
	


	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

int main()
{
  while (true)
  {
    long long n = 0, min = 0, max = 0, result = 0, win = -1;
    cin >> n >> min >> max;

    if (n == 0 && min == 0 && max == 0)
      exit(0);

    vector<long long> v(n, 0);

    for (int i = 0; i < n; i++)
    {
      cin >> v[i];
    }

    for (int i = min - 1; i < max; i++)
    {
      if (v[i] - v[i + 1] >= result)
      {
        result = v[i] - v[i + 1];
        // cout << result << endl;
        win = i;
      }
    }
    cout << win + 1 << endl;
  }

}



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

const int N = 405;

int n;
int a[N];
long long pre[N];
long long f[N][N];

long long calc(int l,int r) {
	if (l == r) {
		return 0;
	}
	long long &res = f[l][r];
	if (~res) {
		return res;
	}
	res = 1e18;
	for (int mid = l; mid <= r - 1; ++mid) {
		res = min(res, pre[r] - pre[l - 1] + calc(l, mid) + calc(mid + 1, r));
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		pre[i] = pre[i - 1] + a[i];
	}
	memset(f, -1, sizeof f);
	printf("%lld\n", calc(1, n));
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#pragma warning(disable:4996)
using namespace std;


int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int dx = c - a;
	int dy =d - b;
	printf("%d %d %d %d", c - dy, d + dx, a - dy, b + dx);

	

	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    long long a,b,n,i,j;
	scanf("%lld%lld%lld",&n,&a,&b);
	i=n/(a+b);
	j=n%(a+b);
	if(j>=a)
	printf("%lld",a*i+a);
	else
	printf("%lld",a*i+j);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

int main() {
	int n;
	std::string s;
	std::cin >> n;
	std::cin >> s;

	std::string tmp;

	std::string a, b;
	int max = 0;
	for (int i = 0; i < n; i++) {
		tmp = "";
		a = s.substr(0, i + 1);
		b = s.substr(i + 1, n - 1);
		for (int j = 0; j < (int) a.size(); j++) {
			for (int k = 0; k < (int) b.size(); k++) {
				if (a.at(j) == b.at(k)
						&& tmp.find(b.at(k)) == std::string::npos) {
					tmp += a.at(j);
				}
			}
		}
		if (max < (int) tmp.size()) {
			max = (int) tmp.size();
		}
	}

	std::cout << max << std::endl;
	return 0;
}

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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

static const int INF = 0x3f3f3f3f;

vector<int> g[202020];
int grundy[202020];
bool used[202020];

int dfs(int v, int prev) {
        used[v] = true;
        set<int> s;
        for (auto u : g[v]) if (u != prev) {
                if (used[u]) s.insert(grundy[u]);
                else s.insert(dfs(u, v));
        }
        if (s.count(-1)) return grundy[v] = -1;
        int g = 0;
        while (s.count(g)) g ++;
        return grundy[v] = g;
}

int main() {
        int n;
        cin >> n;
        for (int i = 0; i < n; i ++) {
                int p;
                cin >> p;
                p --;
                g[p].push_back(i);
        }
        memset(grundy, -1, sizeof(grundy));
        for (int i = 0; i < n; i ++) if (!used[i]) dfs(i, -1);
        int start;
        for (int i = 0; i < n; i ++) {
                if (grundy[i] == -1) {
                        start = i;
                        break;
                }
        }
        set<int> s;
        for (auto t : g[start]) {
                if (grundy[t] == -1) continue;
                s.insert(grundy[t]);
        }
        int mi1 = 0, mi2 = 0;
        while (s.count(mi1)) mi1 ++;
        s.insert(mi1);
        while (s.count(mi2)) mi2 ++;
        grundy[start] = mi1;
        int check[202020] = { 0 };
        for (int i = 0; i < n; i ++) if (grundy[i] == -1) check[i] = -1;
        for (int i = 0; i < n; i ++) if (grundy[i] == -1) used[i] = false;
        for (int i = 0; i < n; i ++) if (!used[i]) dfs(i, -1);
        set<int> s1;
        for (auto t : g[start])  s1.insert(grundy[t]);
        int gr = 0;
        while (s1.count(gr)) gr ++;
        if (gr == grundy[start]) {
                cout << "POSSIBLE" << endl;
                return 0;
        }
        for (int i = 0; i < n; i ++) if (check[i] == -1) grundy[i] = -1;
        grundy[start] = mi2;
        for (int i = 0; i < n; i ++) if (grundy[i] == -1) used[i] = false;
        for (int i = 0; i < n; i ++) if (!used[i]) dfs(i, -1);
        set<int> s2;
        for (auto t : g[start]) s2.insert(grundy[t]);
        gr = 0;
        while (s2.count(gr)) gr ++;
        if (gr == grundy[start]) {
                cout << "POSSIBLE" << endl;
                return 0;
        }
        cout << "IMPOSSIBLE" << endl;
        return 0;
}



Measured memory_bytes: 30848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
 
#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n';
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
    #define eprintf(...) 42
#endif

clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = (ll)1e9 + 7, INF = (ll)1e18;;
ll add(ll x, ll y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
ll mul(ll x, ll y) {
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(x, bin_pow(x, p - 1));
    return bin_pow(mul(x, x), p / 2);
}

const int N = 100100;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    startTime = clock();
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n, streak = 0;
    cin >> n;
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        if (x == y)
            ++streak;
        else
            streak = 0;
        if (streak == 3) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    
    return 0;
}


Measured memory_bytes: 3648
import java.io.*;
public class Main {
  public static void main(String args[]) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String s = null;
    try {
      s = reader.readLine();
    } catch(IOException e) {
    }
    System.out.println(s.substring(0, 4) + " " + s.substring(4));
  }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define ITR(i,x) for(auto i=(x).begin();i!=(x).end();++i)
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int mod = 1000000007;

bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a);//a進数におけるNの各桁の和、計算量はloga(N)
ll mpow(ll x, ll n);
ll inv_mod(ll a){return mpow(a,mod-2);}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

int main(){
    int N,M,R;
    cin>>N>>M>>R;
    vector<int> r(R);
    REP(i, R){ 
        cin >> r[i];
        r[i]--;
    }
    vector<vector<ll>> dist(N,vector<ll>(N));
    REP(i,N) REP(j,N) dist[i][j]=1<<28;
    REP(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        dist[a][b]=c;dist[b][a]=c;
    }
    
    REP(k,N) REP(i,N) REP(j,N){
        if(dist[i][j]>dist[i][k]+dist[k][j]){
            dist[i][j]=dist[i][k]+dist[k][j];
        }
    }
    sort(All(r));
    ll ans=LLONG_MAX;
    do{
        ll tmp=0;
        REP(i,R-1) tmp+=dist[r[i]][r[i+1]];
        ans=min(ans,tmp);
    }while(next_permutation(All(r)));
    cout<<ans<<endl;
    
}

int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
/*
class Factorial{//階乗とその逆元を求めて計算に利用するクラス
private:
    vector<ll> fac;
public:
    
    Factorial(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};
*/

/*
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
*/

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,m,a,b; cin>>n>>m;
	vector<ll> arr(n+1),ok(n+1,1);
	for(auto i=1;i<=n;++i)cin>>arr[i];
	for(auto i=1;i<=m;++i){
		cin>>a>>b;
		if(arr[a]<=arr[b])ok[a]=0;
		if(arr[a]>=arr[b])ok[b]=0;
	}
	ll cnt=0;
	for(auto i=1;i<=n;++i){
		cnt+=ok[i];
	}
	cout<<cnt<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 4780
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val K = rd.readInt()
    val A = rd.readLongArray()

    val lo = LongArray(K+1){0L}
    val hi = LongArray(K+1){0L}

    lo[K] = 2L; hi[K] = 2L

    var ok = true
    for (i in K-1 downTo 0) {
        lo[i] = ((lo[i+1]+A[i]-1)/A[i]) * A[i]
        hi[i] = (hi[i+1]/A[i]) * A[i] + (A[i] - 1)
        if (hi[i]/A[i] - (lo[i]-1)/A[i] <= 0) {
            ok = false
            break
        }
    }

    if (!ok) {
        println(-1)
    } else {
        println("${lo[0]} ${hi[0]}")
    }
}


//val rd = debug.Reader("agc", "020", "b", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 61596
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>

using vi = std::vector<int>;


bool f(const vi &A, int N)
{
	std::unordered_set<int> bucket;

	for (int i = 0; i < N; i++)
	{
		auto it = bucket.find(A[i]);
		if (it != bucket.end())
		{
			return false;
		}
		else
		{
			bucket.insert(A[i]);
		}
	}
	return true;
}

const char* YESNO(bool b)
{
	if (b)
	{
		return "YES";
	}
	else
	{
		return "NO";
	}
}

int main()
{
	int N;
	std::cin >> N;

	vi A(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> A[i];
	}

	std::cout << YESNO(f(A,N));
}

Measured memory_bytes: 9288
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005
#define lim 10000
using namespace std;
 
typedef long long ll;

int n,d,koru,ans;

int main()
{
	cin >> n >> d;
	koru = d + d + 1;
	ans = n/koru;
	if (n % koru != 0)
		ans++;
	cout << ans;
	
    return 0;
}


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

int main() {

    int n;
    cin >> n;
    int costs[n];
    int h[n];
    for (int i=0; i<n; i++) {
        cin >> h[i];
    }
    costs[0] = 0;
    costs[1] = abs(h[1]-h[0]);
    for (int i=2; i<n; i++) {
        costs[i] = min(costs[i-2]+abs(h[i]-h[i-2]), costs[i-1]+abs(h[i]-h[i-1]));
    }
    cout << costs[n-1];

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll cnt = 0;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w;cin>>h>>w;
  for(int i=0;i<h;i++){
    string s;cin>>s;
    for(auto c:s)cnt += (c == '#');
  }
  if(cnt == h+w-1)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int L[1000000], R[1000000];
int count = 0;
 
void merge(int A[], int left, int mid, int right) {
    int i, j, k, n1, n2;
    n1 = mid - left;
    n2 = right - mid;
     
    for (i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
 
    L[n1] = 2000000000;
    R[n2] = 2000000000;
    i = 0; 
    j = 0;
 
    for (k = left; k < right; k++) {
        count++;
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i = i + 1;
        }
        else {
            A[k] = R[j];
            j = j + 1;
        }
    }
}
 
void mergeSort(int A[], int left, int right) {
    int mid;
     
    if ((left + 1) < right) {
        mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
 
int main(void)
{
    int n, i;
    int A[500000];
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
 
    mergeSort(A, 0, n);
 
    for (i = 0; i < n; i++) {
        printf("%d", A[i]);
 
        if (i != (n - 1)) {
            putchar(' ');
        }
        else {
            putchar('\n');
        }
    }
 
    printf("%d\n", count);
 
    return 0;   
}


Measured memory_bytes: 5660
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int d[100];
int get()
{
	int mini = 100, maxi = -1;
	int las = -1000;
	int ans = 1000;
	for (int i = 0; i < 24; i++)
	{
		if (d[i] >= 2)return 0;
		if (d[i])ans = min(ans, i - las), las = i, mini = min(mini, i), maxi = max(maxi, i);
	}
	return min(ans, mini + 24 - maxi);
}
int x[25];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		x[z]++;
	}
	int maxi = 0;
	for (int p = 0; p < (1 << 12); p++)
	{
		fill(d, d + 25, 0);
		d[0] = x[12];
		for (int i = 0; i < 12; i++)
		{
			if (x[i] >= 3)
			{
				printf("0\n");
				return 0;
			}
			if (x[i] == 2)d[12 - i] = d[12 + i] = 1;
			else if (x[i] == 1)
			{
				if (p&(1 << i))d[12 - i] = 1;
				else d[12 + i] = 1;
			}
		}
		d[12]++;
		maxi = max(maxi, get());
	}
	printf("%d\n", maxi);
}

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

using namespace std;

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		if (s[2] == s[3] && s[4] == s[5]) {
			cout << "Yes"
					 << "\n";
		} else {
			cout << "No"
					 << "\n";
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const ll mod = 1000000007;

ll modpow(ll b, ll e) {
  if(e == 0) return 1LL;
  if(e % 2 == 1) return modpow(b, e - 1) * b % mod;
  ll m = modpow(b, e >> 1);
  return m * m % mod;
}

int main() {
  string s;
  cin >> s;

  int n = s.size();
  vector<int> la(n), lq(n), rc(n), rq(n);

  for(int i = 1; i < n; i++) {
    la[i] = la[i - 1], lq[i] = lq[i - 1];
    if(s[i - 1] == 'A') ++la[i];
    if(s[i - 1] == '?') ++lq[i];
  }
  for(int i = n - 2; i >= 0; i--) {
    rc[i] = rc[i + 1], rq[i] = rq[i + 1];
    if(s[i + 1] == 'C') ++rc[i];
    if(s[i + 1] == '?') ++rq[i];
  }

  ll ans = 0LL;
  rep(i, n) {
    if(s[i] == 'A' || s[i] == 'C') continue;

    ll ac = (modpow(3, lq[i]) * modpow(3, rq[i])) % mod;
    ac = (ac * la[i]) % mod;
    ac = (ac * rc[i]) % mod;
    ans = (ans + ac) % mod;

    if(rq[i] > 0) {
      ll aq =
        (modpow(3, lq[i]) * modpow(3, rq[i] - 1)) % mod;
      aq = (aq * la[i]) % mod;
      aq = (aq * rq[i]) % mod;
      ans = (ans + aq) % mod;
    }

    if(lq[i] > 0) {
      ll qc =
        (modpow(3, lq[i] - 1) * modpow(3, rq[i])) % mod;
      qc = (qc * lq[i]) % mod;
      qc = (qc * rc[i]) % mod;
      ans = (ans + qc) % mod;
    }

    if(lq[i] > 0 && rq[i] > 0) {
      ll qq =
        (modpow(3, lq[i] - 1) * modpow(3, rq[i] - 1)) % mod;
      qq = (qq * lq[i]) % mod;
      qq = (qq * rq[i]) % mod;
      ans = (ans + qq) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long
int n,z;
int t[111111];
int  nex[50][111111];
int q;

int che(int x){

	int l=x,r=n,mid=(r+l)/2;
	
	while(r-l>1){
		int ab=t[mid]-t[x];
		if(ab>z)r=mid;
		else l=mid;
		mid=(r+l)/2;
	}

	return l;
}

int main(){
	cin>>n;
	rep(i,n)cin>>t[i];
	cin>>z;

	rep(i,n){
		nex[0][i]=che(i);
	}

	rep(i,25){
		rep(j,n){
			if(nex[i][j]==n)nex[i+1][j]=n;
			else nex[i+1][j]=nex[i][nex[i][j]];
		}
	}


	//rep(i,3){
	//	rep(j,n)cout<<nex[i][j]<<" ";
	//	cout<<endl;
	//}


	cin>>q;
	rep(i,q){
		int a,b;
		cin>>a>>b;
		if(a>b)swap(a,b);
		a--;b--;
		int l=0,r=n,mid=(r+l)/2;
		int tmp=a;
		
		while(r-l>1){
			tmp=a;

			rep(j,24){
				if((1<<j)&mid)tmp=nex[j][tmp];
			}

			if(tmp>=b)r=mid;
			else l=mid;
			mid=(r+l)/2;
		}
		cout<<r<<endl;
	}
	return 0;
}


Measured memory_bytes: 13312
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
a = []
b = []
c = []
d = []
for _ in range(q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

num = list(range(1, m + 1))
max_score = 0
for A in list(combinations_with_replacement(num, n)):
    score = 0
    for i in range(q):
        if A[b[i] - 1] - A[a[i] - 1] == c[i]:
            score += d[i]
    max_score = max(max_score, score)
print(max_score)


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vi p(n), q(n);
  for(int i=0;i<n;++i) {
    cin >> p[i];
  }
  for(int i=0;i<n;++i) {
    cin >> q[i];
  }

  vi tmp(n);
  int fact = 1;
  for(int i=0;i<n;++i) {
    tmp[i] = i+1;
    fact *= i+1;
  }
  
  int a = -1, b = -1;
  for(int i=0;i<fact;++i) {
    //printv(tmp);
    bool pok = true, qok = true;
    for(int j=0;j<n;++j) {
      if(tmp[j] != p[j]) pok = false;
      if(tmp[j] != q[j]) qok = false;
    }
    if(pok) a = i;
    if(qok) b = i;
    //cout << a << ":" << b << endl;
    next_permutation(tmp.begin(), tmp.end());
  }
  
  cout << abs(a - b) << endl;
  

}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

type ElementKey int
type Node struct {
	key    ElementKey
	parent *Node
	rank   int
}

func newNode(key ElementKey) *Node {
	node := Node{}
	node.key = key
	node.parent = &node
	node.rank = 0

	return &node
}

func union(x, y *Node) {
	xSet := findSet(x)
	ySet := findSet(y)
	link(xSet, ySet)
}

func link(x, y *Node) {
	if x.rank > y.rank {
		y.parent = x
	} else {
		x.parent = y

		if x.rank == y.rank {
			y.rank++
		}
	}
}

func findSet(x *Node) *Node {
	if x != x.parent {
		x.parent = findSet(x.parent)
	}
	return x.parent
}

func newDisjointSets(nSets int) *DisjointSets {
	sets := DisjointSets{}
	sets.keyToNode = map[ElementKey]*Node{}
	for i := 0; i < nSets; i++ {
		key := ElementKey(i)
		sets.keyToNode[key] = newNode(key)
	}
	return &sets
}

type DisjointSets struct {
	keyToNode map[ElementKey]*Node
}

func (sets *DisjointSets) union(x, y ElementKey) {
	xNode := sets.keyToNode[x]
	yNode := sets.keyToNode[y]
	union(xNode, yNode)
}

func (sets DisjointSets) findSet(x ElementKey) *Node {
	xNode := sets.keyToNode[x]
	return findSet(xNode)
}

type Edge struct {
	i, j   int
	weight int
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	nEdges := nextInt()
	sets := newDisjointSets(nNodes)
	edges := []Edge{}
	for i := 0; i < nEdges; i++ {
		e := Edge{
			i:      nextInt(),
			j:      nextInt(),
			weight: nextInt(),
		}
		edges = append(edges, e)
	}
	sort.Slice(edges, func(i, j int) bool { return edges[i].weight < edges[j].weight })
	totalWeight := 0
	for _, edge := range edges {
		i := ElementKey(edge.i)
		j := ElementKey(edge.j)
		if sets.findSet(i) != sets.findSet(j) {
			totalWeight += edge.weight
			sets.union(i, j)
		}
	}
	fmt.Println(totalWeight)
}



Measured memory_bytes: 11332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
// 1*A+x(無限）*500=N       x*500=N-A
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
   else {
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
int n, m;

int main() {
    cin >> n >> m;
    vector<int> gate(100100, 0);
    for(int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        gate.at(l)++;
        gate.at(r+1)--;
    }

    for(int i = 0; i < n; ++i) {
        gate.at(i+1) += gate.at(i);
    }

    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(gate.at(i) == m) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
 int a,b,c,t;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    if(b>c){
        t=b;
        b=c;
        c=t;
    }
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

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

int s(int &a, int &b){
    int t = a;
    a = b;
    b = t;
}

void Main()
{
    int x, y, z;
    cin >> x >> y >> z;
    s(x,y);
    s(x,z);
    cout << x << " " << y << " "  << z << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep2(i, n) for(int i = 0 ; i < n ; i++)
#define rep(i, moji_len) for(int i = 0 ; i < moji_len ; i++)
#define n 33

int main()
{
  char moji[33];
  while(true){
    cin >> moji;
    if(moji[0] == '#') break;
    int moji_len = 0, cnt = 0;
    
    rep(i, n){
      if(moji[i] == '\0'){
	moji_len = i;
	break;
      }
    }
    int hand = -1;
    rep(i, moji_len){
      if(moji[i] == 'y' || moji[i] == 'u' || moji[i] == 'o' || moji[i] == 'p' || moji[i] == 'i' || moji[i] == 'h' || moji[i] == 'j' || moji[i] == 'k' || moji[i] == 'l' || moji[i] == 'n' || moji[i] == 'm'){
	if(hand == -1){
	  hand = 0;
	}
	if(hand == 1){
	  hand = 0;
	  cnt++;
	}
      }else if(moji[i] == 'q' || moji[i] == 'w' || moji[i] == 'e' || moji[i] == 'r' || moji[i] == 't' || moji[i] == 'a' || moji[i] == 's' || moji[i] == 'd' || moji[i] == 'f' || moji[i] == 'g' || moji[i] == 'z' || moji[i] == 'x' || moji[i] == 'c' || moji[i] == 'v' || moji[i] == 'b'){
	if(hand == -1){
	  hand = 1;
	}
	if(hand == 0){
	    hand = 1;
	    cnt++;
	}
      }
    }
    cout << cnt << '\n'; 
  }
}

Measured memory_bytes: 1140
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main() {
	string x, y, z;
	cin >> x >> y >> z;
	cout << x[0] << y[1] << z[2];
	
	return 0;

}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#include <queue>
#define N 100005
using namespace std;
typedef long long ll;
struct st{ll a, b, c;} d[N];
ll n, x, y, z, ans, sc, g[N], s[N];
priority_queue<ll, vector<ll>, greater<ll> > q1, q2;
bool cmp(st p, st q) {return p.a-p.b > q.a-q.b;}

int main() {
	ll i;
	scanf("%lld%lld%lld", &x, &y, &z);
	n = x+y+z;
	for(i=1; i<=n; i++) scanf("%lld%lld%lld", &d[i].a, &d[i].b, &d[i].c), sc += d[i].c;
	sort(d+1, d+n+1, cmp);
	for(i=1; i<=x+z; i++) {
		q1.push(d[i].a - d[i].c);
		g[i] = g[i-1] + d[i].a - d[i].c;
		if(i>x) g[i] -= q1.top(), q1.pop();
	}
	for(i=n; i>x; i--) {
		q2.push(d[i].b - d[i].c);
		s[i] = s[i+1] + d[i].b - d[i].c;
		if(i<=n-y) s[i] -= q2.top(), q2.pop();
	}
	ans = g[x] + s[x+1];
	for(i=x+1; i<=n-y; i++) ans = max(ans, g[i] + s[i+1]);
	printf("%lld", ans + sc);
	return 0;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    init_combination();
    ll ans = 0;
    for(ll k = 0; k <= min(K, N - 1); k++) {
        ll tmp = combination(N, k);
        ll num = N - k;
        tmp *= combination(N - num + num - 1, num - 1);
        tmp %= mod;
        ans += tmp;
    }
    ans %= mod;
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

int D;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));
vector<int> last(26,0);
vector<int> t(365);


ll calc_score(vector<int> t){
	ll score = 0;
	vector<int> last(26,0);
	for (int d=0; d<D; d++){
		score += s[d][t[d]];
		last[t[d]] = d+1;
		for (int i=0; i<26; i++) score -= c[i]*(d+1-last[i]);
	}
	return score;
}
	

int main(){
	cin >> D;
	for (int i=0; i<26; i++) cin >> c[i];

	for (int i=0; i<D; i++){
		for(int j=0; j<26; j++){
			cin >> s[i][j];
		}
	}
	

	long long sat = 0;
	for (int i=0; i<D; i++){
		int T;
		cin >> T;
		T--;
		t[i] = T;
	}

	ll cur_score = calc_score(t);
	
	int m;
	cin >> m;

	for (int i=0; i<m; i++){
		int d,q;
		cin >> d >> q;
		d--,q--;
		//int old = t[d];
		t[d] = q;

		ll new_score = calc_score(t);
		cout << new_score << endl;

		//cur_score = new_score;
	}

	return 0;
}

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

int main(void) {
	int n;
	int i,j;
	int times[1000];
	int last[1000];
	int now[1000];
	int month,day,hour,minute;
	char io[4];
	int id;
	int now_time;
	int max;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		memset(times,0,sizeof(times));
		memset(last,0,sizeof(last));
		memset(now,0,sizeof(now));
		for(i=0;i<n;i++) {
			scanf("%d/%d %d:%d %s %d",
				&month,&day,&hour,&minute,io,&id);
			now_time=hour*60+minute;
			if(io[0]=='I') {
				now[id]=1;
			} else {
				if(id==0) {
					for(j=1;j<1000;j++) {
						if(now[j]) {
							times[j]+=now_time-
								(last[0]>last[j]?last[0]:last[j]);
						}
					}
				} else {
					if(now[0]) {
						times[id]+=now_time-
							(last[0]>last[id]?last[0]:last[id]);
					}
				}
				now[id]=0;
			}
			last[id]=now_time;
		}
		max=0;
		for(i=1;i<1000;i++) {
			if(times[i]>max)max=times[i];
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b;
   cout << a *b << endl;
}


Measured memory_bytes: 3668
import sys
readline = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
ans = [""] * m
li = []
for i in range(m):
    p, y = map(int, readline().split())
    li.append((p, y, i))
li.sort()
cnt = 1
ans[li[0][2]] = "{:06}{:06}".format(li[0][0], cnt)
for i in range(1, m):
    cnt = cnt + 1 if li[i - 1][0] == li[i][0] else 1
    ans[li[i][2]] = "{:06}{:06}".format(li[i][0], cnt)
print(*ans, sep="\n")


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

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

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

	int N;
	cin >> N;

	int A[N];
	rep(i, N)
		cin >> A[i];

	double t = 0;
	rep(i,N) {
		t += (double) 1/A[i];
	}

	cout << fixed << setprecision(9);
	cout << (double) 1/t << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  string s; cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(input())
print(array[N-1])

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

int main() {
  
  int x;
  cin >> x;
  
  int a =x / 500;
  int b = (x - a * 500) / 5;
  int ans = a * 1000 + b * 5;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
const long long MOD = 1000000007;
const int MAX = 200001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

int BIT_SIZE = 64;
long long power(long long m, long long n){
    long long ans = 1;
    long long tmp = m;
    for(int i = 0; i < BIT_SIZE; i++){
        //cout << ans << endl;
        if(((n >> i) & 1) == 1){
            ans = ans * tmp % MOD;
        }
        tmp = (tmp * tmp) % MOD;
    }
    return ans;
}

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

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


long long a[100001];
int appeared_in[100001];
int main(){
    comb_init();
    int n;
    cin >> n;
    for(int i = 0; i < n + 1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n + 1; i++){
        appeared_in[i] = -1;
    }

    
    int first_appearence;
    int second_appearence;
    for(int i = 0; i < n + 1; i++){
        if(appeared_in[a[i] - 1] < 0){
            appeared_in[a[i] - 1] = i;
        } else {
            first_appearence = appeared_in[a[i] - 1];
            second_appearence = i;
        }
    }
    //cout << first_appearence << " " << second_appearence << endl;
    for(int k = 1; k <= n + 1; k++){
        long long all = comb(n + 1, k);
        long long double_count = 0;
        if(k - 1 <= first_appearence + n - second_appearence){
            double_count = comb(first_appearence + n - second_appearence, k - 1);
        }
        //cout << all << " " << double_count << endl;
        cout << ((all - double_count) % MOD + MOD) % MOD << endl;
    }
    return 0;
}


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

int main() {
  int N,K;
  cin>>N>>K;
  int d;
 d=0;
  for (int i = 0; i < N; i++) {
 int x;
  cin>>x;
    if(x<=K-x){d+=2*x;}
    else{d+=2*(K-x);}
    
  
}
cout << d << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int nb = b;
  int digit_b;
  while(nb!=0){
    nb = nb/10;
    digit_b++;
  }
  while(digit_b!=0){
    a*=10;
    digit_b--;
  }
  int n,m;
  n=a+b;
  m=sqrt(n);
  if(n==m*m) printf("Yes");
  else printf("No");
  return 0;
}
  
  

Measured memory_bytes: 128
import math
x=int(input())
if x<4:
    print(x)
elif x<=5:
    print(5)
else:
    ans=0
    while ans==0:
        if x%2==0:
            x+=1
        if x%10==5:
            x+=2
        i_max=math.ceil(x**0.5)+1
        for i in range(2,i_max):
            if x%i==0:
                break
            elif i==i_max-1:
                ans=x
                break
        x+=2
    print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

 class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		ArrayList<Integer> aa = new ArrayList<>();
		int cnt = 0;
		for (int i = a; i <= b; i++) {
			if (cnt <k) {
				aa.add(i);
				cnt++;
			} else
				break;
		}
		cnt = 0;
		for (int i = b; i >= a; --i) {
			if (cnt <k) {
				aa.add(i);
				cnt++;
			} else
				break;
		}
		Collections.sort(aa);
		int pre=aa.get(0);
		System.out.println(pre);
		for(int i=1;i<aa.size();i++) {
			if(pre !=aa.get(i))
				System.out.println(aa.get(i));
			pre=aa.get(i);
			}
	}

}


Measured memory_bytes: 23124
sx, sy, tx, ty = map(int, input().split())

dy = ty - sy
dx = tx - sx

print('U' * dy + 'R' * dx +
      'D' * dy + 'L' * dx +
      'LU' + 'U' * dy + 'R' * dx + 'RD' +
      'RD' + 'D' * dy + 'L' * dx + 'LU')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

int n, p;
int a, c[2];

ll dp[55][55];

int main() {
	rep(i, 0, 50) {
		dp[i][0] = dp[i][i] = 1;
		rep(j, 1, i - 1)
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
	}
	
	scanf ("%d%d", &n, &p);
	rep(i, 1, n) {
		scanf ("%d", &a);
		c[a % 2]++;
	}
	
	ll s = 0;
	for (int i = 0; i <= c[1]; i += 2)
		s += dp[c[1]][i];
	s *= (1LL << c[0]);
	
	if (p) 
		s = (1LL << n) - s;
	printf ("%lld\n", s);
	
	
	return 0;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define int long  long 

using namespace std ; 
	 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ; 
	cin >> n ; 
	vector<int> a(n) ; 
	for(int i = 0 ; i < n ; ++i)
		cin >> a[i] ; 

	int cnt = 0; 
	sort(a.begin() , a.end()) ; 
	for(int i = 0 ; i < n -2 ; ++i)
	{
		for(int j = i +1; j < n-1 ; ++j)
		{
			if(a[i] != a[j])
			{
				for(int k = j +1 ; k < n ; ++k)
				{
					if(a[k] != a[i] && a[k] != a[j] )
					{
						if(a[i] + a[j] > a[k] )
							cnt++ ; 
					}
				}
			}
		}
	}
	cout << cnt ;

}       





Measured memory_bytes: 3664
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef pair< int , int > pi;
typedef set< int > se;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define Fn 1.618033987
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    int k;
    ll ans=0;
    cin>>n>>m>>k;
    char A[n][m];
    REP(i,0,n-1)
    {
        REP(j,0,m-1)
        {
            cin>>A[i][j];
        }
    }
    for(int maskn=0;maskn<(1<<n);maskn++)
    {
        for(int maskm=0;maskm<(1<<m);maskm++)
        {
            int c=0;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(((maskn&(1<<i))>0)&&((maskm&(1<<j))>0))
                    {
                        if(A[i][j]=='#')
                        {
                            ++c;
                        }
                    }
                }
            }
            if(c==k)
            {
                ++ans;
            }
        }
    }
    cout<<ans<<"\n";
    return 0; 
}

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#define lli long long int
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<queue>
#define pb push_back
#define N (int)(1e5)
using namespace std;
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    lli ans=0;
    vector<lli>arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr.begin(),arr.end(),greater<int>());
    for(int i=k;i<n;i++)
    {
        ans = ans+arr[i];
    }
    cout<<ans<<endl;
    
    
    

}



Measured memory_bytes: 4748