akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

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

    int diff = b - a;
    if (diff <= 0)
        cout << "delicious" << endl;
    else if (diff <= x)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rint register int

using namespace std;

int n;
int x,y,z;
char s[21];

int main(){
//	freopen("1.in","r",stdin);
	scanf("%s",s);
	x = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0' ) * 10 + s[3] - '0';
	y = (s[5] - '0') * 10 + s[6] - '0';
	z = (s[8] - '0') * 10 + s[9] - '0';
	if(x > 2019) { puts("TBD");return 0;}
	if(x < 2019) {puts("Heisei");return 0;}
	if(y > 4) {puts("TBD");return 0;}
	if(y < 4){ puts("Heisei");return 0;}
	if(z <= 30){puts("Heisei");return 0;}
	puts("TBD");
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    nl     "\n"
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

int main()
{
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=b-(n-a);
    if(a<=n)
    {
        cout<<0<<" ";
        if(x>=0)cout<<x;else cout<<0;
    }
    else cout<<a-n<<" "<<b;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

int n,m,q, a[N], d[N], c[N], ans[N];
vi g[N];
bool was[N][12];

void calc(int v,int d,int c){
	if(was[v][d]) return;
	was[v][d] = 1;
	if(d == 0){
		ans[v] = c;
		return;
	}
	calc(v, d - 1, c);
	for(int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		calc(to, d - 1, c);
	}
}

int main () {
	scanf("%d%d",&n,&m);
	for(int i = 1,u,v; i <= m; i++){
		scanf("%d%d",&u,&v);
		g[u].pb(v);
		g[v].pb(u);
	}
	scanf("%d",&q);
	for(int i = 1; i <= q; i++){
		scanf("%d%d%d",&a[i],&d[i],&c[i]);
	}
	for(int i = q; i > 0; i--){
		calc(a[i], d[i], c[i]);	
	}

	for(int i = 1; i <= n; i++){
		printf("%d\n", ans[i]);
	}


return 0;
}

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

int main() {
  int x;
  cin >> x;
  for (int a = 0; a < 120; a++) {
    ll a5=1;
    rep(i,5) a5 *= a;
    for(int b = -120; b < a; b++) {
      ll b5=1;
      rep(i,5) b5 *= b;
      if(a5-b5==x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  } 
  return 0;
}

Measured memory_bytes: 3624
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

map<ll, list<ll>> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll d, x, res=0;
        cin >> d;
        ll c[26];
        ll arr[d][26];
        ll la[26];
        for(ll i=0; i<26; i++) {
            cin >> c[i];
            la[i]=-1;
        }
        for(ll i=0; i<d; i++) {
            ll ma=0, r;
            for(ll j=0; j<26; j++) {
                cin >> arr[i][j];
                if(ma<arr[i][j]) {
                    ma=max(ma, arr[i][j]);
                    r=j+1;
                }
            }
            cout << r << endl;
        }
    }
}


Measured memory_bytes: 3248
n,c=gets.split.map(&:to_i)
d=[]
g=[]
c.times{d.push(gets.split.map(&:to_i))}
n.times{g.push(gets.split.map(&:to_i))}
l=[]
a=Array.new(3).map{Array.new(c,0)}
  c.times{|q|
    n.times{|x|
      n.times{|y|
        a[(x+y)%3][q]+=d[g[y][x]-1][q]
      }
    }
  }
[*0...c].permutation(3){|x,y,z|l.push(a[0][x]+a[1][y]+a[2][z])}
p l.min

Measured memory_bytes: 4732
#include<bits/stdc++.h>
#define N 2005
using namespace std;
const int mod=1e9+7;
int n,m,k;
int dp[2][N];
long long ans;
int main(){
    scanf("%d%d%d",&n,&m,&k);n--,k--;
    int now=0;
    dp[now][0]=1;
    for(int tot=0;tot<=n+m;tot+=k){
        memset(dp[now^1],0,sizeof(dp[0]));
        for(int j=max(0,tot-n);j<=min(m,tot);j++){
            if(m%k==j%k) ans+=dp[now][j];
            for(int si=0;si<=k;si++)
                if(j+si<=m && tot-j+k-si<=n)
                    (dp[now^1][j+si]+=dp[now][j])%=mod;
            if(j+0<=m && tot-j+k-0<=n && m%k==j%k)
                ans-=dp[now][j];
        }
        now^=1;
    }
    cout<<(ans-(m%k==0? 1:0) )%mod<<endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val wcs = (0..(n - 1)).toMutableList()
    val ecs = (0..(n - 1)).toMutableList()

    s.forEachIndexed { index, c ->
        wcs[index] = if (index == 0) 0 else wcs[index - 1]
        if (c == 'W') {
            wcs[index]++
        }
    }

    s.reversed().forEachIndexed { index, c ->
        ecs[index] = if (index == 0) 0 else ecs[index - 1]
        if (c == 'E') {
            ecs[index]++
        }
    }

    ecs.reverse()

    val min = (0..(n - 1)).map {
        if (it == 0) return@map ecs[it + 1]
        if (it == (n - 1)) return@map wcs[it - 1]
        wcs[it - 1] + ecs[it + 1]
    }.min()

    println(min)
}

Measured memory_bytes: 81184
import Control.Applicative

f a b c x y = do
  let cn = if (a + b) > c * 2 then min x y else 0
  let an = x - cn
  let bn = y - cn
  let can = if a > c * 2 && x > y then x - y else 0
  let cbn = if b > c * 2 && y > x then y - x else 0
  sum $ zipWith (*) [a, b, c] [max 0 $ an - (can * 2), max 0 $ bn - (cbn * 2), (cn + can + cbn) * 2]

main = do
  [a, b, c, x, y] <- map read <$> words <$> getLine :: IO [Int]
  print $ f a b c x y


Measured memory_bytes: 508
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, m, R;
    cin >> n >> m >> R;

    vector<int> X(R);
    for (int i = 0; i < R; ++i) {
        cin >> X[i];
        --X[i];
    }

    const long long INF = 1LL << 50;
    vector<vector<long long>> dis(n, vector<long long>(n, INF));

    for (int i = 0; i < m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;

        dis[u][v] = min(dis[u][v], (long long) w);
        dis[v][u] = min(dis[v][u], (long long) w);
    }
    for (int i = 0; i < n; ++i) {
        dis[i][i] = 0;
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }

    vector<int> ord(R, 0);
    iota(ord.begin(), ord.end(), 0);

    long long res = INF;
    do {
        long long d = 0;
        for (int i = 1; i < R; ++i) {
            int u = X[ord[i - 1]], v = X[ord[i]];
            d += dis[u][v];
        }
        res = min(res, d);
    } while (next_permutation(ord.begin(), ord.end()));

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3756
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, k, s = LI()
    if s == 10 ** 9:
        for i in range(k):
            print(s, end=" ")
        for i in range(n - k):
            print(s - 1, end=" ")
        print()
        return
    for i in range(k):
        print(s, end=" ")
    for i in range(n - k):
        print(s + 1, end=" ")
    print()
    return


#main
if __name__ == '__main__':
    solve()


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    vector<vector<int>> list(H, vector<int>(W));
    vector<int> color(N);
    for (int i = 0; i < N; i++)
        cin >> color[i];
    int x = 0, y = 0, now = 0;
    for (int i = 0; i < H * W; i++)
    {
        list[x][y] = now + 1;
        color[now]--;
        if (color[now] == 0)
            now++;

        if (y % 2 == 0)
        {
            if (x == H - 1)
                y++;
            else
                x++;
            continue;
        }
        if (y % 2 == 1)
        {
            if (x == 0)
                y++;
            else
                x--;
            continue;
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << list[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

template<class T>
struct line:vector< point<T> >{
	line(){}
	line(const point<T> &a,const point<T> &b){ push_back(a), push_back(b); }
};

template<class T>
struct polygon:vector< point<T> >{
	polygon(){}
	polygon(int n):vector< point<T> >(n){}
};

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

point<double> rot(const point<double> &a,double theta){
	return (point<double>){a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)};
}

enum {CCW=1,CW=-1,ON=0};
int ccw(const point<double> &a,const point<double> &b,const point<double> &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

template<class T>
T area2(const polygon<T> &G){
	int n=G.size();
	T a=0;
	rep(i,n) a+=cross(G[i],G[(i+1)%n]);
	return abs(a);
}

template<class T>
point<double> get_intersect(const line<T> &L1,const line<T> &L2){
	double a1=cross(L1[1]-L1[0],L2[1]-L2[0]);
	double a2=cross(L1[1]-L1[0],L1[1]-L2[0]);
	if(abs(a1)<EPS) return L1[0]; // L1 == L2
	return L2[0]+a2/a1*(L2[1]-L2[0]);
}

template<class T>
polygon<double> convex_cut(const polygon<T> &G,const line<T> &L){
	int n=G.size();
	polygon<double> H;
	rep(i,n){
		int d1=ccw(L[0],L[1],G[i]);
		int d2=ccw(L[0],L[1],G[(i+1)%n]);
		if(d1!=CW) H.push_back(G[i]);
		if(d1==CCW && d2==CW || d1==CW && d2==CCW){
			H.push_back(get_intersect(L,line<T>(G[i],G[(i+1)%n])));
		}
	}
	return H;
}

int main(){
	const point<double> O={0,0},P={1,0};

	for(int n;scanf("%d",&n),n;){
		polygon<double> G(n);
		rep(i,n) scanf("%lf%lf",&G[i].x,&G[i].y);

		double A2=area2(G);
		line<double> L0(O,P);

		double lo=0,hi=PI;
		if(area2(convex_cut(G,L0))>A2/2) lo=-PI, hi=0;
		rep(_,100){
			double mi=(lo+hi)/2;
			line<double> L(O,rot(P,mi));
			if(area2(convex_cut(G,L))<A2/2) lo=mi; else hi=mi;
		}

		point<double> ans=rot(P,(lo+hi)/2);
		printf("%.15f %.15f\n",2*ans.x,2*ans.y);
	}

	return 0;
}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T& a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

int N;
int A[200010];
map<int, int> mp;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N) {
    cin >> A[i];
    mp[A[i]]++;
  }
  sort(A, A+N);
  reverse(A, A+N);
  int ans = 0;
  REP(i, N) if (mp[A[i]] >= 1) {
    int num = 1;
    while (num <= A[i]) num <<= 1;
    int x = num-A[i];
    if (mp[x] > 0) {
      if (x == A[i]) {
        if (mp[x] >= 2) {
          mp[x] -= 2;
          ans++;
        }
      } else {
        mp[A[i]]--;
        mp[x]--;
        ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 26880
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector<ull> a(N, 0);
	for (int i = 0; i < N; ++i){
		cin >> a[i];
	}

	ull cnt = 0;
	for (int ii = 0; ii < N; ++ii){
		ull value = a[ii];
		while(value % 2 == 0){
			cnt++;
			value /= 2;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,pt[4][13],mul[10];
bool hand[4][14];

int ck()
{
	int rank[13]={0};
	rep(i,4)rep(j,13)if(hand[i][j])rank[j]++;
	
	bool royal=0,straight=0,flush=0,four=0,three=0; int two=0;
	rep(i,10)
	{
		rep(j,5)if(!rank[(i+j)%13])goto FAIL;
		if(i==9)royal=1;
		straight=1; FAIL:;
	}
	bool e[4]={0}; int s=0;
	rep(i,4)rep(j,13)if(hand[i][j])e[i]=1;
	rep(i,4)s+=e[i];
	flush=s==1;
	
	rep(i,13)
	{
		if(rank[i]==4)four=1;
		if(rank[i]==3)three=1;
		if(rank[i]==2)two++;
	}
	if(straight&&flush)return royal?8:7;
	if(four)return 6;
	if(two&&three)return 5;
	if(flush)return 4;
	if(straight)return 3;
	if(three)return 2;
	if(two==2)return 1;
	if(two)return 0;
	return 9;
}

int main()
{
	char st[256]; st['S']=0; st['C']=1; st['H']=2; st['D']=3;
	char ra[256]; for(int i=2;i<=9;i++)ra['0'+i]=i-1;
	ra['A']=0; ra['T']=9; ra['J']=10; ra['Q']=11; ra['K']=12;
	
	bool f=1;
	while(~scanf("%d",&n))
	{
		if(!f)puts(""); else f=0;
		rep(i,4)rep(j,13)scanf("%d",pt[i]+j);
		rep(i,9)scanf("%d",mul+i);
		
		rep(i,n)
		{
			rep(j,4)rep(k,13)hand[j][k]=0;
			
			int bs=0;
			rep(j,5)
			{
				char h[3]; scanf("%s",h);
				int r=ra[h[0]],s=st[h[1]];
				hand[s][r]=1; bs+=pt[s][r];
			}
			printf("%d\n",mul[ck()]*bs);
		}
	}
	return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
int main(void){
    int a, b, c, tmp;
    scanf("%d %d %d", &a, &b, &c);
    
    if(a>b) {tmp=a; a=b; b=tmp;}
    if(a>c) {tmp=a; a=c; c=tmp;}
    if(b>c) {tmp=b; b=c; c=tmp;}


    printf("%d %d %d\n", a, b, c);
    
}



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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  int Alice =0;
  int Bob =0;
  
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<n; i++){
    if(i%2==0){
      Alice+=a[i];
    }
    else{
      Bob+=a[i];
    }
  }
  cout << Alice-Bob << endl;
  
  
}

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

using LL = long long;
using VL = vector<LL>;
using VVL = vector<vector<LL>>;
using STR = string;

#define REP(i, n) for (LL i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (LL i = LL(n) - 1; i >= 0; --i)

template <class T> void chmin(T& a, T b) { if (b < a) { a = b; } }
template <class T> void chmax(T& a, T b) { if (b > a) { a = b; } }

#define SZ(var) (LL)(var.size())
#define pb push_back

#define IN_LL(var) LL var; cin >> var;
#define IN_LL2(var0, var1) LL var0, var1; cin >> var0 >> var1;
#define IN_LL3(var0, var1, var2) LL var0, var1, var2; cin >> var0 >> var1 >> var2;
#define IN_LL4(var0, var1, var2, var3) LL var0, var1, var2, var3; cin >> var0 >> var1 >> var2 >> var3;

#define IN_VL(var, n) VL var(n); REP(i, n) { cin >> var[i]; };
#define IN_STR(var) STR var; cin >> var;

#define OUT(var) cout << (var) << '\n';

void myMain();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(16);
	myMain();
	return 0;
}

void myMain() {
	IN_LL2(N, M);
	VVL R(N);
	REP(i, M) {
		IN_LL2(a, b);
		R[a - 1].pb(b - 1);
		R[b - 1].pb(a - 1);
	}

	VL froms(N, -1);

	queue<LL> queue;
	queue.push(0);
	froms[0] = 0;

	while (queue.empty() == false) {
		LL p = queue.front();
		queue.pop();

		for (LL n : R[p]) {
			if (froms[n] != -1) {
				continue;
			}

			froms[n] = p;
			queue.push(n);
		}
	}

	OUT("Yes");
	for (LL i = 1; i < N; ++i) {
		OUT(froms[i] + 1);
	}
}

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

//#include "rubo.h"
//#define mp make_pair
//#define pb push_back
#define in int
#define ll long long
#define vc vector
#define SQ(j) (j)*(j)
//#define x first
//#define y second

//#define ld long double
#define dbl  long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

#define db(x) cout << #x << " = " << x << endl
#define dbCont(x) cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout << endl;

typedef long double ld;

using namespace std;


const int N = 100*1000+5;
int n,k;
vector<int> a;

int dp[N];

int main() {
    cin >> n >> k;
    loop(i,n){
        int e;
        cin >> e;
        a.push_back(e);
    }

    loop(i,N) dp[i] = 2e9;
    dp[0] = 0;

    for(int i = 1; i < n; i++){
        for(int kk = 1; kk <= k; kk++) {
            if(i-kk >= 0) {
                dp[i] = min(dp[i], dp[i - kk] + abs(a[i] - a[i - kk]));
            }
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1144
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<n;i++)
#define out(s) cout << s << endl

int gcd(int a,int b){
    if(a<b){
        int tmp=a;
        a=b;
        b=tmp;
    }
    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int find(vector<int> &a,int x){
    int n=a.size();
    int index=-1;
    int mi=10000000;
    for(int i=0;i<n;i++){
        if(gcd(a[i],x)<mi){
            mi=gcd(a[i],x);
            index=i;
        }
    }
    for(int i=0;i<n;i++){
        if(i==index)continue;
        else{
            x=gcd(x,a[i]);
        }
    }
    return x;
}


int main(){
    int n;cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m=0;
    sort(a.begin(),a.end());
    
    
    cout << max(find(a,a[0]),find(a,a[1])) << endl;
    return 0;
    
}



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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const int MAX_N = 110000;

int memo[MAX_N]; // memo[i]がiについての答え

int rec(int n)
{
    if (n == 0)
        return 0;
    if (memo[n] != -1)
        return memo[n];

    int res = n;
    for (int pow6 = 1; pow6 <= n; pow6 *= 6)
        res = min(res, rec(n - pow6) + 1);
    for (int pow9 = 1; pow9 <= n; pow9 *= 9)
        res = min(res, rec(n - pow9) + 1);

    return memo[n] = res;
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < MAX_N; i++)
        memo[i] = -1;
    cout << rec(N) << endl;

    return 0;
}

Measured memory_bytes: 7152
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int n, ans = 0, d[55];
    cin >> n;
    rep(i, n) {
        cin >> d[i];
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(i != j) {
                ans += d[i] * d[j];
            }
        }
    }
    cout << ans / 2 << endl;
    return 0;
}


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

int dis(int x0,int y0,int x1,int y1) {
  return abs(x0-x1) + abs(y0-y1);
}
bool iseven(int a, int b) {
  return (a-b) % 2 == 0;
}

int main() {
  int n;cin>>n;
  int t0=0,x0=0,y0=0;
  int ti,xi,yi,d;
  rep(i,n) {
    cin>>ti>>xi>>yi;
    d = dis(x0,y0,xi,yi);
    if (d> (ti-t0) or !iseven(d,ti-t0)) {
      cout << "No";
      return 0;
    }
    t0=ti;x0=xi;y0=yi;
  }
  cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;


//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}

const ll mod = 1e9 + 7;
const ll N = 1e5 + 7;
ll n, h;



int main()
{
    MohamedMotaz;
    cin >> n;
    vector<ll> v(n);
    ll dp[n];
    memset(dp, 0, sizeof(dp));
    f(i,0,n) cin >>v[i];
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    f(i,2,n){
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    //f(i,0,n) cout << dp[i] << " ";
    //cout << endl;
    cout << dp[n- 1];
}



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

long long div_ceil(long long a, long long b) {
  if ((a >= 0 and b >= 0) or (a < 0 and b < 0)) {
    return a / b + (a % b != 0);
  } else {
    return a / b;
  }
}

long long div_floor(long long a, long long b) {
  if ((a >= 0 and b >= 0) or (a < 0 and b < 0)) {
    return a / b;
  } else {
    return a / b - (a % b != 0);
  }
}

int main() {
  long long n, k; cin>>n>>k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin>>a[i];
  sort(a.begin(), a.end());

  long long ok = 1e18, ng = -1e18-1;
  while (ng + 1 < ok) {
    long long mid = (ok + ng) / 2;
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < 0) {
        long long v = div_ceil(mid, a[i]);
        cnt += a.begin() + i - lower_bound(a.begin(), a.begin() + i, v);
      } else if (a[i] == 0) {
        if (mid >= 0) cnt += i;
      } else {
        long long v = div_floor(mid, a[i]);
        cnt += upper_bound(a.begin(), a.begin() + i, v) - a.begin();
      }
    }
    if (cnt >= k) ok = mid;
    else ng = mid;
  }

  cout << ok << endl;

  return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
 
class Simple {
    int N, Z, W;
    int[] a;
    void Solve() {
        //input
        N = io.Int;
        Z = io.Int;
        W = io.Int;
        a = new int[N];
        for (int i = 0; i < N; ++i)
            a[i] = io.Int;
        //cal
        var ans1 = Math.Abs(a.Last() - W);
        if(N==1){
            Console.WriteLine(ans1);
            return;
        }            
        var ans2 = Math.Abs(a[N-2]-a.Last());
        var ans = new int[]{ans1,ans2}.Max();
        Console.WriteLine(ans);    
    }
 
 
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}
 
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

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

int main(){

string str1,str2;
cin >> str1 >> str2 ;
int count=0;
rep(i,3){
  if(str1.at(i)==str2.at(i))count++;
}

cout << count << endl;
return 0;

}




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

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

using namespace std;

const int INF=1<<29;

template<class T>
class network{
	struct edge{
		int to,rev;
		T capa,flow;
		edge(int to,int rev,const T& capa,const T& flow):to(to),rev(rev),capa(capa),flow(flow){}
	};

	int s,t;
	vector<vector<edge>> G;

public:
	network(int n,int s,int t):s(s),t(t){
		G.resize(n);
	}

	void add_directed_edge(int u,int v,const T& capa){
		G[u].emplace_back(v,G[v].size()  ,capa,0);
		G[v].emplace_back(u,G[u].size()-1,   0,0);
	}

	T maximum_flow(){
		int n=G.size();
		vector<int> pre(n);
		vector<bool> vis(n);

		auto augment=[&](){
			rep(u,n) vis[u]=(u==s);

			queue<pair<int,T>> Q; Q.emplace(s,0);
			for(const edge& e:G[s]){
				Q.front().second=max(Q.front().second,e.capa-e.flow);
			}

			T res=0;
			while(!Q.empty()){
				int u;
				T water; tie(u,water)=Q.front(); Q.pop();

				if(u==t){ res=water; break; }

				for(const edge& e:G[u]) if(!vis[e.to] && e.capa-e.flow>0) {
					vis[e.to]=true;
					pre[e.to]=e.rev;
					Q.emplace(e.to,min(water,e.capa-e.flow));
				}
			}

			if(res>0){
				for(int u=t;u!=s;){
					edge& e1=G[u][pre[u]];
					edge& e2=G[e1.to][e1.rev];
					e1.flow-=res;
					e2.flow+=res;
					u=e1.to;
				}
			}

			return res;
		};

		T res=0;
		for(T water=1;water>0;res+=water) water=augment();
		return res;
	}
};

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char B[100][101];
	rep(i,h) scanf("%s",B[i]);

	int sx,sy,tx,ty;
	rep(i,h) rep(j,w) {
		if(B[i][j]=='S') tie(sy,sx)=tie(i,j);
		if(B[i][j]=='T') tie(ty,tx)=tie(i,j);
	}

	network<int> G(2*h*w,sy*w+sx+h*w,ty*w+tx);
	rep(i,h) rep(j,w) if(B[i][j]!='.') {
		G.add_directed_edge(i*w+j,i*w+j+h*w,1);
		rep(k,h) if(k!=i && B[k][j]!='.') G.add_directed_edge(i*w+j+h*w,k*w+j,INF);
		rep(k,w) if(k!=j && B[i][k]!='.') G.add_directed_edge(i*w+j+h*w,i*w+k,INF);
	}

	int ans=G.maximum_flow();
	printf("%d\n",ans<INF?ans:-1);

	return 0;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
int ng[1000001];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	set<int> st;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (st.find(A[i]) == st.end()) {
			st.insert(A[i]);
			for (int j = 2 * A[i]; j <= 1000000; j += A[i]) {
				ng[j] = 1;
			}
		} else {
			ng[A[i]] = 1;
		}
	}
	for (int i = 0; i < N; i++) {
		if (!ng[A[i]]) {
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 21836
#include<bits/stdc++.h>
using namespace std;
long long n,a[1001],top=0;
int main()
{
	scanf("%lld",&n);
	if(n==0){printf("0");return 0;}
	while(n!=0)
	{
		a[++top]=n%(-2);
		n=(n-a[top])/(-2);
		if(a[top]<0)a[top]=1,n++;
		//printf("%d %d\n",a[top],n);
	}
	while(top)printf("%d",a[top--]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ctime>
using namespace std;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define TESTS wez(testow)while(testow--) //for multilple cases problems
#define whileZ int T; getI(T); while(T--) // the same as above
#define getS(x) scanf("%s", x) //get a char* string
#define clr(a,x) memset(a,x,sizeof(a)) //set elements of array to some value
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end()) 
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end()) 
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);//to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n",n); }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define MAXN 10000
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<long long> vll;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
// directions
const int fx[4][2] = {{0,1}, {-1,0}, {0,-1}, {1,0}};
const int fxx[9][2] = {{0,0},{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
const int N = 500;
const ll mod = 1000000007;



int main() 
{IOS
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = a*c;
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    cout<<ans;


}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n,x,m;
  cin >> n >> x >> m;
  vector<int32> visited(m,-1);
  int64 ans = x;
  int64 pre = x;
  visited[x] = 1;
  int64 lpf = -1;
  REP(i,n-1){
    int64 nxt = pre * pre % m;
    if(visited[nxt] != -1){
      lpf = nxt;
      n -= visited[pre];
      break;
    }
    ans += nxt;
    visited[nxt] = visited[pre] + 1;
    pre = nxt;
  }
  // ANS(lpf);
  if(lpf == -1){
    ANS(ans);
    return 0;
  }

  // REP(i,m)cout << visited[i] << " ";
  // cout << endl;

  // ANS(n);

  int64 lpsum = lpf;
  int64 lpl = 1;
  int64 cur = lpf * lpf % m;
  while(cur != lpf){
    lpsum += cur;
    cur = cur * cur % m;
    ++lpl;
  }

  // ANS(lpsum);
  // ANS(lpl);
  
  ans += lpsum * (n / lpl);
  n %= lpl;
  REP(i,n){
    ans += lpf;
    lpf = lpf * lpf % m;
  }
  ANS(ans);
  return 0;
}

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

#define MOD 1000000007
#define INF 1000000000000

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    string s, t;
    cin >> s >> t;
    int S = s.length(), T = t.length();
    vector<vector<int>> dp(S+1, vector<int>(T+1, 0));
    for (int i = 0; i < S; ++i) {
        for (int j = 0; j < T; ++j) {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            if (s[i] == t[j]) {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }
    // print(dp);
    // cout << dp[S][T] << endl;

    int i = S, j = T, k = dp[S][T] - 1;
    // print(i, j);
    vector<char> ans(dp[S][T]);
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i-1][j]) {
            i -= 1;
        } else if (dp[i][j] == dp[i][j-1]) {
            j -= 1;
        } else {
            ans[k] = s[i-1];
            i -= 1; j -= 1; k -= 1;
        }
        // print(i, j, ans);
    }

    for (int i = 0; i < dp[S][T]; ++i) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S[K-1] = 'a' + int(S[K-1] - 'A');
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = -1;
        if(a < 10 && b < 10) ans = a * b;
        System.out.println(ans);
    }
}


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

int main() {
  int N;
  int64_t ans = 0;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) cin >> vec.at(i);
  rep(i, N - 1) {
    if(vec.at(i) > vec.at(i + 1)) {
      ans += vec.at(i) - vec.at(i + 1);
      vec.at(i + 1) = vec.at(i);
    }
  }
  cout << ans << endl;
}

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

const long long MOD = 1e9 + 7;
const int MAX_N = 21;

int n, a[MAX_N];
long long dp[1 << MAX_N];

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char c; cin >> c;
            a[i] |= (c & 1) << j;
        }
    }

    dp[0] = 1;
    for (int mask = 1; mask < (1 << n); mask++) {
        int i = __builtin_popcount(mask) - 1;
        int mask2 = mask & a[i];
        while (mask2) {
            int j = __builtin_ffs(mask2) - 1;
            dp[mask] += dp[mask ^ 1 << j];
            mask2 &= mask2 - 1;
        }
        dp[mask] %= MOD;
    }

    cout << dp[(1 << n) - 1] << "\n";

    return 0;
}


Measured memory_bytes: 16640
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
const li inf = 1 << 60;

void _main(int tc) {
  li n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n) { cin >> w[i] >> v[i]; }
  // ********* Recursive ************
  // vector<vector<li>> mem(n, vector<li>(W + 1, -1));
  // function<li(int, int)> knapsack = [&](int i, int k) -> li {
  //   if (i == n) return 0;
  //   if (mem[i][k] != -1) return mem[i][k];
  //   if (k - w[i] >= 0) mem[i][k] = v[i] + knapsack(i + 1, k - w[i]);
  //   mem[i][k] = max(mem[i][k], knapsack(i + 1, k));
  //   return mem[i][k];
  // };
  // cout << knapsack(0, W) << endl;
  // ********* End Recursive ************

  vector<vector<li>> mem(n + 1, vector<li>(W + 1, 0));
  rrep(i, n) {
    rrep(k, W + 1) {
      if (k - w[i] >= 0) mem[i][k] = v[i] + mem[i + 1][k - w[i]];
      mem[i][k] = max(mem[i][k], mem[i + 1][k]);
    }
  }
  cout << mem[0][W] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////

int main() {
string op1,op2,op3;
	int N,A,B,C,D;
	cin >> N;
	A = N / 1000;
	B = (N / 100) %10;
	C = (N / 10) %10;
	D = N %10;

	op1 = '+';
	op2 = '+';
	op3 = '+';
	if(A+B+C+D == 7){}
	else if(A+B+C-D == 7){op3 = '-';}
	else if(A+B-C+D == 7){op2 = '-';}
	else if(A+B-C-D == 7){op3 = '-'; op2 = '-';}
	else if(A-B+C+D == 7){op1 = '-';}
	else if(A-B+C-D == 7){op1 = '-'; op3 = '-';}
	else if(A-B-C+D == 7){op1 = '-'; op2 = '-';}
	else if(A-B-C-D == 7){op1 = op2 = '-';}

	cout << A << op1 << B << op2 << C << op3 << D << '=' << 7 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if (op=='?'){
			break;
		}
		switch(op){
			case '+':
				printf("%d\n",a+b);
				break;
			case '-':
				printf("%d\n",a-b);
				break;
			case '*':
				printf("%d\n",a*b);
				break;
			case '/':
				printf("%d\n",a/b);
				break;
		}
	}
return 0;
}

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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

int start[502], interval[502], duration[502];

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n;

    cin >> n;

    for(int i = 0; i < n - 1; ++i){
        cin >> duration[i] >> start[i] >> interval[i];
    }

    interval[n - 1] = 1;

    for(int i = 0; i < n; ++i){
        int time = 0;
        for(int station = i; station < n; ++station){
            time += (interval[station] - time % interval[station]) % interval[station];
            time = max(time, start[station]) + duration[station];
        }
        cout << time << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
const ll MOD (1e9+7);
const ll INF (2e9);
const int MAX_N (200001);

int main(void) {
    int n;
    cin>>n;
    ll sumt,suma;
    cin>>sumt>>suma;
    int t,a;
    for(int i=1;i<n;i++){
        cin>>t>>a;
        ll m=max(sumt/t+(sumt%t==0?0:1),suma/a+(suma%a==0?0:1));//　sumt/tの切り上げ
        sumt=m*t;
        suma=m*a;
    }
    
    cout<<sumt+suma<<endl;
    return 0;
}

Measured memory_bytes: 256