akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main() {
  int x,i,j,min,flag;
  char c[36][3],t[3],d[36][3];

  scanf("%d",&x);
  for(i = 0; i < x; i++) {
    scanf("%s",c[i]);
    strcpy(d[i],c[i]);
  }
  
  for(i = 0; i < x; i++) {
    for(j = x - 1; j >= i + 1; j--) {
      if((c[j][1] - '0') < (c[j - 1][1] - '0')) {
	strcpy(t,c[j]);
	strcpy(c[j],c[j - 1]);
	strcpy(c[j - 1],t);
      }
    }
  }

  for(i = 0; i < x - 1; i++) {
    printf("%s ",c[i]);
  }
  printf("%s\n",c[i]);
  printf("Stable\n");

  for(i = 0; i < x; i++) {
    min = i;
    for(j = i; j < x; j++) {
      if((d[j][1] - '0') < (d[min][1] - '0')) {
	min = j;
      }
    }
    strcpy(t,d[i]);
    strcpy(d[i],d[min]);
    strcpy(d[min],t);
  }

  for(i = 0; i < x - 1; i++) {
    printf("%s ",d[i]);
  }
  printf("%s\n",d[i]);
  flag = 1;

   for(i = 0; i < x; i++) {
     if(strcmp(c[i],d[i]) != 0) {
       flag = 0;
     }
   }

   if(flag) {
     printf("Stable\n");
   }else{
     printf("Not stable\n");
   }

   return 0;
}
   
  
  



Measured memory_bytes: 2108
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

	N := nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i] = nextInt(), nextInt()
	}

	p := make([]int, N+1)
	for i := N - 1; i >= 0; i-- {
		A[i] += p[i+1]

		amari := A[i] % B[i]
		plus := 0
		if amari != 0 {
			plus = B[i] - amari
		}
		p[i] = p[i+1] + plus
	}
	fmt.Println(p[0])
}


Measured memory_bytes: 5760
#include <cstdio>

int main()
{
  int a;
  int b;
  int c;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);

  if (a == b && a != c) { printf("Yes"); return 0; }
  if (a == c && a != b) { printf("Yes"); return 0; }
  if (b == c && b != a) { printf("Yes"); return 0; }
  printf("No");
  return 0;
}

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

int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  
  int ans=0;
  for(int i=0; i<=(N/R); i++){
    for(int j=0; j<=((N-i*R)/G); j++){
      if((N - i*R - j*G)%B == 0)ans++;
    }
  }
  cout << ans << endl;
}

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


int main(){
	int n,t;
	cin>>n;
	vector<int> v(n,0);
	for(int i=0;i<n;i++)
		cin >> v[i];
	vector<int> dp(n,0); 
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(abs(v[i]-v[i-2])+dp[i-2],abs(v[i]-v[i-1])+dp[i-1]);
	}
	
	cout << dp[n-1] << endl;

	return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
vector<vector<int>>dp, ans;
int cnt = 0;
int get(int a, int b, int c, int d) {
	return dp[c - 1][d - 1] - dp[a - 1][d - 1] - dp[c - 1][b - 1] + dp[a - 1][b - 1];;
}
void dfs(int a, int b, int c, int d) {
	int k = get(a, b, c, d);
	if (k == 1) {
		cnt++;
		rep(i, a, c) {
			rep(j, b, d) {
				ans[i][j] = cnt;
			}
		}
		return;
	}
	bool f = false;
	rep(i, a + 1, c) {
		if (f)break;
		int x = get(a, b, i, d);
		int y = get(i, b, c, d);
		if (x > 0 and y > 0) {
			dfs(a, b, i, d);
			dfs(i, b, c, d);
			f = true;
			break;
		}
	}
	rep(i, b + 1, d) {
		if (f)break;
		int x = get(a, b, c, i);
		int y = get(a, i, c, d);
		if (x > 0 and y > 0) {
			dfs(a, b, c, i);
			dfs(a, i, c, d);
			f = true;
			break;
		}
	}
}

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

	int H, W; cin >> H >> W;
	int K; cin >> K;
	vector<string>v(H); rep(i, 0, H) { cin >> v[i]; }

	dp = vector<vector<int>>(H + 1, vector<int>(W + 1));
	ans = dp;
	rep(i, 1, H + 1) {
		rep(j, 1, W + 1) {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (v[i - 1][j - 1] == '#');
		}
	}
	dfs(1, 1, H + 1, W + 1);
	rep(i, 1, H + 1) {
		rep(j, 1, W + 1) {
			cout << ans[i][j] << (j == W ? '\n' : ' ');
		}
	}

	return 0;
}


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

using namespace std; 

int main() { 

  string n; 

  cin >> n;
  char lastChar = n.at( n.length() - 1 ); 
  if (lastChar == 's' ) cout << n + "es" << endl;
  else cout << n + "s" << endl;

} 

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
const double pi=acos(-1.0);
int v[N];
struct Dat {
    int x,y;
    inline bool operator < (const Dat &A) const {return x<A.x;}
} g[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int a,b,A,B,t=0,tp=0,n;
    cin>>a>>b>>A>>B;
    if(a>A) swap(a,A),swap(b,B);
    if(b>B) b=-b,B=-B,t=1;
    cin>>n;
    for(int i=1;i<=n;i++) {
	int x=gi(),y=gi();
	if(x<a||x>A) continue;
	if(t) y=-y;
	if(y<b||y>B) continue;
	g[++tp]=(Dat){x,y};
    }
    double ans=(A-a+B-b)*100.0;
    sort(g+1,g+1+tp);
    int k=0;v[0]=-1e9;
    for(int i=1;i<=tp;i++) {
	if(g[i].y>v[k]) v[++k]=g[i].y;
	else v[lower_bound(v+1,v+1+k,g[i].y)-v]=g[i].y;
    }
    if(k==A-a+1||k==B-b+1) ans+=5*pi;
    ans+=k*(5*pi-20);
    printf("%.20f",ans);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll X;
	cin >> X;
	for (;; X++) {
		bool flag = true;
		for (ll p = 2; p * p <= X; p++) {
			if (X % p == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			cout << X << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

string toLowerString(string s)
{
	int i, length = s.length();
	string lower ="";
	for (i = 0; i < length; i++)
	{
		lower += (char) tolower(*s.substr(i, 1).c_str());
	}
	return lower;
}

int main()
{
	int counter = 0;
	string str, current;
	cin >> str;
	while (true)
	{
		cin >> current;
		if (current == "END_OF_TEXT") break;
		if (toLowerString(str) == toLowerString(current)) counter++;
	}
	cout << counter << endl;
	return 0;
}

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

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

    vector<int> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    vector<pair<int, int> > k(n);
    for (int i = 0; i < n; i++)
    {
        k[i] = make_pair(s[i],i+1);
    }
    /*
    for (int i = 0; i < n; i++)
    {
        cout << k[i].first << " " << k[i].second << endl;
    }
    */

    sort(k.begin(), k.end());

    for (int i = 0; i < n; i++)
    {
        //cout << k[i].first << " " << k[i].second << endl;
        cout << k[i].second << " ";
    }

    return 0;
}


Measured memory_bytes: 2048
import java.util.*;
public class Main{

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

	if(A < 6){
		System.out.println(0);
		
	}
	else if (A < 13){
		System.out.println(B/2);
	}
	else{
		System.out.println(B);
	}
}	
}

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

n, k = map(int, input().split())
H = []
for _ in range(n):
    h = int(input())
    H.append(h)
H.sort()
d = []

for i in range(n-k+1):
    hmin = H[i]
    hmax = H[i+k-1]
    d.append(hmax - hmin)

print(min(d))


Measured memory_bytes: 11288
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  long long N, P, Q;
  scanf("%lld %lld %lld", &N, &P, &Q);
  vector<long long> C(N);
  for(int i = 0; i < N; ++i) scanf("%lld", &C[i]);
  long long s = 0;
  for(int i = 0; i < N; ++i){
    s += C[i];
    C[i] = (Q - i)*P - C[i];
  }
  sort(C.begin(), C.end(), greater<>());
  long long ans = s;
  for(int i = 0; i < N; ++i){
    s += C[i] + 2*i*P;
    ans = max(ans, s);
  }
  printf("%lld\n", ans);
  return 0;
}



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

int main()
{
  int H,W;

  while(1)
  {
  cin >> H >> W;
  if(H == 0 && W == 0) break;
  for(int i = 1; i <= H; i++)
  {
    for(int j = 1; j <= W; j++)
    {
      printf("#");
    }
    printf("\n");
  }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

void solve(int N, vector<ll> K, vector<ll> L, vector<ll> R){
    vector<llll> S(N);
    for (int i = 0; i < N; i++) {
        S[i].first = L[i] - R[i];
        S[i].second = K[i];
    }
    sort(ALL(S), greater<llll> ());

    ll P, Q;
    P = 0;
    Q = 0;
    for (int i = 0; i < N; i++) {
        if(S[i].first > zero){
            P++;
        }
        else if(S[i].first < zero){
            Q++;
        }
    }

    set<ll> A, B;
    for (int i = 0; i < P+1; i++) {
        A.insert(N-i);
    }
    for (int i = 0; i < Q+1; i++) {
        B.insert(N-i);
    }
    vector<bool> ans(N, false);

    int tmp, tt;
    for (int i = 0; i < P; i++) {
        tmp = max(N-S[i].second, N-P);
        tt = *A.lower_bound(tmp);
        if(tt != N){
            A.erase(tt);
            ans[i] = true;
        }
        else{
            ans[i] = false;
        }

    }

    for (int i = N-1; i >= N-Q; i--) {
        tmp = max(S[i].second, N-Q);
        tt = *B.lower_bound(tmp);
        if(tt != N){
            B.erase(tt);
            ans[i] = true;
        }
        else{
            ans[i] = false;
        }
    }

    ll answer = 0;
    for (int i = 0; i < N; i++) {
        answer += R[i];
        if(ans[i]){
            if(S[i].first > 0){
                answer += S[i].first;
            }
        }
        else{
            if(S[i].first < 0){
                answer += S[i].first;
            }
        }
    }


    printf("%lld\n", answer);

    


}

int main(){
    int T;
    int N;
    cin >> T;
    vector<ll> K, L, R;
    for (int i = 0; i < T; i++) {
        cin >> N;
        K.resize(N);
        L.resize(N);
        R.resize(N);
        for (int j = 0; j < N; j++) {
            cin >> K[j] >> L[j] >> R[j];
        }
        solve(N, K, L, R);


    }

}

Measured memory_bytes: 25188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define All(x) (x).begin(),(x).end()
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=998244353;
const int inf=0x7fffffff;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// fast read
template<class T> void read(T &x) {
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}

int n,s,a[maxn];
ll dp[maxn];
int main(){
	//freopen("test.in","r",stdin);
	read(n),read(s);
	rep(i,1,n) read(a[i]);
	ll inv2=qpow(2,mod-2,mod);
	dp[0]=qpow(2,n,mod);
	rep(i,1,n){
		for(int j=s;j>=a[i];j--){
			dp[j]=(dp[j]+dp[j-a[i]]*inv2)%mod;
		}
	}
	printf("%lld\n",dp[s]%mod);
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> count(N+1);
  int A, num=0;
  for(int i=0; i<N; ++i) {
    cin >> A;
    if(count[A]==0) num++;
    count[A]++;
  }
  if(num<=K) { cout<<0<<endl; return 0; }
  sort(count.begin(), count.end());

  int i, sum=0;
  for(i=0; count[i]==0; i++) ;
  for(int j=0; j<num-K; j++) sum+=count[i++];
  cout<<sum<<endl;

}


Measured memory_bytes: 1024
# ABC133B

import numpy as np

n, d = map(int, input().split())
x = [0] * n
for i in range(n):
    x[i] = list(map(int, input().split()))
x = np.array(x)
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = np.sqrt(sum((x[i, :] - x[j, :]) ** 2))
        # print(i, j, "** d =", d)
        if d == int(d):
            count += 1
print(count)


Measured memory_bytes: 12392
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
int main(){
 
	long long int n, k, mi, ma, se, cnt=0;
	vector<long long int> a, f;
 
	cin>> n >> k;
	a.resize(n);
	f.resize(n);
 
	for(int i=0;i<n;i++) cin>> a[i];
	for(int i=0;i<n;i++) cin>> f[i];
 
	sort(a.begin(),a.end());
	sort(f.begin(),f.end(),greater<long long int>());
 
	mi=-1;
	ma=1000000000000;
 
	while(1){
		se=(mi+ma)/2;
		cnt=0;
 
		for(int i=0;i<n;i++){
			if(se<a[i]*f[i]){
				cnt+=(a[i]*f[i]-se+f[i]-1)/f[i];
			}
            	//cout<< a[i] << f[i] << cnt <<endl;
		}
 
		if(k<cnt) mi=se;
		else ma=se;
        
        if(ma-mi<2) break;
	}
		
 	cout<< ma <<endl;
 
 
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
# define int long long
# define mo 1000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

signed main()
{
   gok
    int n;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<n;i++)
    {
        cout<<s1[i]<<s2[i];
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let s = it.next().unwrap();
    let op: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();
    let mut ans = String::new();
    for c in s.chars() {
        let mut k = c.to_digit(36).unwrap() as usize - 10 + n;
        k %= 26;
        ans.push(op[k]);
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

int main(){
    int N;
    cin >> N;
    vector<int> S(N);
    for (int i=0; i<N; i++) cin >> S.at(i);
    sort(S.begin(), S.end());
    for (int i=1; i<N; i++){
        if (S.at(i) - S.at(i-1) == 0){
            cout << "NO" << endl;
            return 0; //差分がなったらNO出力しreturnでmainを抜けて終わらせる
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 4024
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int vis[maxn],lft[maxn];

int main() {
    int n,m;vis[1]=1;
    read(n);read(m);
    REP(i,1,n) lft[i]=1;
    REP(i,1,m) {
        int x,y;
        read(x);read(y);
        if(vis[x]) vis[y]=1;
        lft[x]--;lft[y]++;
        if(!lft[x]) vis[x]=0;
    }
    int cnt=0;
    REP(i,1,n) if(vis[i]) cnt++;
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
    char h[105][105];
    char q[105]={"0"};
    char w[10005];
int main()
{
	int i;
	int k;
	int p;
	int a;
	int b;
	       scanf("%d%d",&a,&b);
	   	  for(i=0;i<a;i++){
	   	  	   scanf("%s",h[i]);}
	      for(i=0;i<a-1;i++){
	      for(k=0;k<a-1-i;k++){
	      	  p=strcmp(h[k],h[k+1]);
				 if(p>0){
				 	strcpy(q,h[k]);
				 	strcpy(h[k],h[k+1]);
				 	strcpy(h[k+1],q);
				 }
	      	
		  }
	}
		  
		  
		  strcpy(w,h[0]);
		  for(i=1;i<a;i++)
		  	 strcat(w,h[i]);
			   printf("%s",w);
	return 0;	  
		  
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int ans = 0,N,i = 0,highest = 0;
  scanf("%d",&N);
  int H[N];
  for(i = 0;i < N;i++) {
    scanf("%d",&H[i]);
    if(H[i] >= highest) {
      highest = H[i];
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;

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

Measured memory_bytes: 256
#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 <numeric>

using namespace std;


int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    
    std::sort(L.begin(), L.end(), std::greater<int>() );
    
    
    int max = L[0];
    
    L.erase(L.begin() + 0);
    
    int sum = std::accumulate(L.begin(), L.end(), 0);
    
    if(max<sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main(){
    //input
    long long N;
    cin >> N;
    long long A[N],B[N];
    long long i;
    long long C[N+1], D[N+1];
    fill(C,C+N+1,0);
    fill(D,D+N+1,0);
    for(i=0; i<N; i++){
        cin >> A[i];
        C[A[i]]++;
    }
    for(i=0; i<N; i++){
        cin >> B[i];
        D[B[i]]++;
    }

    //calc
    for(i=1; i<=N; i++){
        C[i]+=C[i-1];
        D[i]+=D[i-1];
    }
    for(i=1; i<=N; i++){
        if(C[i]-C[i-1]+D[i]-D[i-1]>N){
            cout << "No" << endl;
            system("pause");
            return 0;
        }
    }
    cout << "Yes" << endl;
    long long x=0;
    for(i=1; i<=N; i++){
        x=max(x,C[i]-D[i-1]);
    }
    for(i=0; i<N-1; i++){
        cout << B[(i+(N-x))%N] << " ";
    }
    cout << B[(N-1+(N-x))%N] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 9920
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
 
int main(){
  int H, W;
  cin >> H >> W;
  string S[H];
  int SH[H];
  int SW[W];
  FOR(i, 0, H) cin >> S[i];
  int zero;
  int lSH = 0;
  int lSW = 0;
  int Hposi = 0;
  int Wposi = 0;
  
  FOR(i, 0, H){
    zero = 0;
    FOR(j, 0, W){
      if(S[i][j]=='#') zero++;
    }
    if(zero==0) SH[i] = 0;
    else SH[i] = 1;
  }
  
  FOR(j, 0, W){
    zero = 0;
    FOR(i, 0, H){
      if(S[i][j]=='#') zero++;
    }
    if(zero==0) SW[j] = 0;
    else SW[j] = 1;
  }
  
  FOR(i, 0, H){
    if(SH[i]==0){
      FOR(k, i, H-1) {
        FOR(l, 0, W) S[k-Hposi][l] = S[k+1-Hposi][l];
      }
      Hposi++;
    }
  }
  
  FOR(i, 0, W){
    if(SW[i]==0){
      FOR(k, i, W-1) {
        FOR(l, 0, H) S[l][k-Wposi] = S[l][k+1-Wposi];
      }
      Wposi++;
    }
  }    
      
    
  /*FOR(i, 0, H){
    zero = 0;
    FOR(j, 0, W){
      if(S[i][j]=='#') zero++;
    }
    if(zero==0){
      FOR(k, i, H-1) {
        FOR(l, 0, W) S[k][l] = S[k+1][l];
      }
    }
    //cout << S[i] << endl;
  }
  
  FOR(j, 0, W){
    zero = 0;
    FOR(i, 0, H){
      if(S[i][j]=='#') zero++;
    }
    if(zero==0){
      FOR(k, j, W-1) {
        FOR(l, 0, H) S[l][k] = S[l][k+1];
      }
    }
    //cout << S[i] << endl;
  }*/
  
  FOR(i, 0, H) lSH += SH[i];
  FOR(i, 0, W) lSW += SW[i];
 
  FOR(i, 0, lSH) {
    FOR(j, 0, lSW) cout << S[i][j];
    cout  << endl;
  }
  
  //cout << lSH << lSW << endl;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,K,R,S,P;
  string T;
  cin>>N>>K>>R>>S>>P>>T;
  /*
  r=>0;
  s=>1;
  p=>2;
  */
  vector<vector<char>>a(K);
  for(int i=0;i<N;i++)a[i%K].push_back(T[i]);
  ll ans=0;
  for(int i=0;i<K;i++){
    ll c=1;
    if(a[i].size()==1){
      if(a[i][0]=='r')ans+=P;
      if(a[i][0]=='s')ans+=R;
      if(a[i][0]=='p')ans+=S;
    }
    for(int j=1;j<a[i].size();j++){
      if(a[i][j]==a[i][j-1])c++;
      else{
        if(a[i][j-1]=='r')ans+=P*((c+1)/2);
        if(a[i][j-1]=='s')ans+=R*((c+1)/2);
        if(a[i][j-1]=='p')ans+=S*((c+1)/2);
        c=1;
      }
      if(j==a[i].size()-1){
        if(a[i][j]=='r')ans+=P*((c+1)/2);
        if(a[i][j]=='s')ans+=R*((c+1)/2);
        if(a[i][j]=='p')ans+=S*((c+1)/2);
        c=1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)

int main(){
    string s,t; cin >> s >> t;
    int n = s.size();
    rep(i,0,n){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF=1e15;
LL memo[100005];
LL datas[100005];
int N;
LL solve(int ix)
{
	if(ix==N) return 0;
	if(ix > N) return INF;
	if(memo[ix]!=-1) return memo[ix];
	return memo[ix]=min(abs(datas[ix]-datas[ix+1])+solve(ix+1), abs(datas[ix]-datas[ix+2])+solve(ix+2));
}

int main()
{
	scanf("%d", &N);
	for(int a=1;a<=N;a++)
	{
		scanf("%lld", &datas[a]);
	}
	memset(memo, -1, sizeof(memo));
	printf("%lld\n", solve(1));
	return 0;
}

Measured memory_bytes: 3328
/*                          The four Truths of Life
                                  
                                    CKMKB
                                    PKMKB
                                  
                                    CKMKC
                                    PKMKC
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
    return (x%m + m)%m;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

//	cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> n;
	//	ll arr[n]; for (i = 0; i < n; i++) {cin >> arr[i];}

        x=n*(1+(n)+(n*n));
        cout<<x;

		ln
	}
	return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 200010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-9
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, cnt, ans;
ll a[SIZE];
int main() {
	io(); cin >> n >> m;
	cout << 100 * (10 - n >= 0 ? 10 - n : 0) + m;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int s = 0;
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans= a[0];
    rep(i, n - 1){
        ans = min(ans, __gcd(a[i + 1], ans));
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200005

int A,B,C;

int main(){

	scanf("%d %d %d",&A,&B,&C);

	if(A > B && A > C){

		printf("A\n");
	}else if(B > A && B > C){

		printf("B\n");
	}else{

		printf("C\n");
	}

	return 0;
}



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

template <typename T>
class fenwick {
public:
  vector<T> fenw;
  int n;
  fenwick(int _n) : n(_n) {
    fenw.resize(n);
  }
  void modify(int x, T v) {
    while (x < n) {
    	fenw[x] = max(fenw[x], v);
      // fenw[x] += v;
      x |= (x + 1);
    }
  }
  T get(int x) {
    T v{};
    while (x >= 0) {
    	v = max(v, fenw[x]);
      // v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};
int main() {
#ifdef LOCAL_DEFINE
	// freopen("data.in", "rt", stdin);
	// freopen("data.out", "w", stdout);
	auto _start = chrono::high_resolution_clock::now();
#endif

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<int> h(n), a(n);
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	fenwick<long long> dp(n);
	for(int i = 0; i < n; i++) {
		long long cur = dp.get(h[i] - 1) + a[i];
		dp.modify(h[i] - 1, cur);
	}
	cout << dp.get(n - 1) << '\n';

#ifdef LOCAL_DEFINE
	auto _end = chrono::high_resolution_clock::now();
	cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
#endif
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

bool comp_output(pair<ll, pair<ll, pl>> a, pair<ll, pair<ll, pl>> b){
    return a.S.S.F < b.S.S.F;
}

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

    // solution comes here
    ll ans1, ans2;
    cin >> ans1 >> ans2;
    cout << ans1*ans2/2 << nl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
#input = sys.stdin.readline

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
P = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    P[p-1] += x
ans = [-1] * N
#print(G)
#print(P)

def dfs(v, p):
    ans[v] = P[v] + p
    for vi in G[v]:
        if ans[vi] != -1:
            continue
        dfs(vi, ans[v])
dfs(0, 0)

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


Measured memory_bytes: 237748
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

b += [0]

ans = 0

for i in range(n+1):
    if a[i] > b[i-1]:
        ans += b[i-1]
        a[i] -= b[i-1]
        b[i-1] = 0
    else:
        ans += a[i]
        b[i-1] -= a[i]
        a[i] = 0
    
    if a[i] > b[i]:
        ans += b[i]
        a[i] -= b[i]
        b[i] = 0
    else:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        
print(ans)

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

vector<int>E[200000];
int ans=0;

int dfs(int v,int p){
	bool b=false;
	int cnt=0;
	for(int u:E[v]){
		if(u==p)continue;
		int res=dfs(u,v);
		if(res==0)b=true;
		else cnt++;
	}
	if(cnt>1)ans+=cnt-1;
	return (b||cnt>1?0:1);
}

int main(){
	int n;cin>>n;
	if(n==2){
		puts("1");return 0;
	}
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	vector<int>v;
	rep(i,n){
		if(E[i].size()==1)v.push_back(i);
	}
	random_device rnd;
	set<int>se;
	rep(i,min((int)v.size(),100)){
		int x;
		do{
			x=rnd()%v.size();
		}while(se.count(x));
		se.insert(x);
	}
	int Min=INT_MAX;
	for(int i:se){
		ans=0;
		dfs(v[i],-1);
		Min=min(Min,ans+1);
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i,n,k) for(int i=0;i<n;i=i+k)
#define forpn(p,n,k) for(int i=p;i<n;i+=k)
#define for0(n) for(int i=0;i<n;i++)
#define for1(n) for(int i=1;i<=n;i++)
const long double PI=3.141592653589793;
using namespace std;
int no_of_bits(long long n)
{
    int count=0;
    while(n>0)
    {
        n=n>>1;
        count++;
    }
    return count;
}
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}





int main()
{   ios::sync_with_stdio(0);
    int n;
    cin>>n;
  
    cin.tie(0);
    cout.tie(0);
   	int rem=n%10;
  if(rem==2||rem==4||rem==5||rem==7||rem==9) cout<<"hon";
 else if(rem==3) cout<<"bon";
 else cout<<"pon";
    return 0;
}

    



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


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

    ll i,j,k,l,m,n,w,z,p,q,tmp,sum=0;
    string str;
    cin>>n>>m;
    vector<ll> cnt(n+1);
    vector<ll> x(m+1);
    vector<ll> y(m+1);
    rep(i,m){
        cin>>x[i]>>y[i];
    }
    rep(i,m){
        UnionFind t(n+1);
        rep(j,m){
            if(i==j) continue;
            t.unite(x[j],y[j]);
        }
        ll r;
        r=t.root(1);
        for(j=2;j<=n;j++){
            if(t.root(j)!=r){
                sum++;
                break;
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}





Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] n = br.readLine().split(" ");
        
        Dice dice = new Dice(n[0], n[1], n[2], n[3], n[4], n[5]);
        
        String command = br.readLine();
        
        for(int i = 0; i < command.length(); i++) {
            switch(command.charAt(i)) {
                case 'N':
                    dice.goNorth();
                    break;
                case 'S':
                    dice.goSouth();
                    break;
                case 'E':
                    dice.goEast();
                    break;
                case 'W':
                    dice.goWest();
                    break;
            }
        }

        System.out.println(dice.nowTopNum());
    }
}

class Dice {
    private String top;
    private String front;
    private String right;
    private String left;
    private String back;
    private String bottom;
    
    public Dice(String top, String front, String right, String left, String back, String bottom) {
        this.top = top;
        this.front = front;
        this.right = right;
        this.left = left;
        this.back = back;
        this.bottom = bottom;
    }
    
    public String nowTopNum() {
        return this.top;
    }
    
    public void goSouth() {
        String tmp = this.front;
        this.front = this.top;
        this.top = this.back;
        this.back = this.bottom;
        this.bottom = tmp;
    }

    public void goNorth() {
        String tmp = this.front;
        this.front = this.bottom;
        this.bottom = this.back;
        this.back = this.top;
        this.top = tmp;
    }

    public void goEast() {
        String tmp = this.top;
        this.top = this.left;
        this.left = this.bottom;
        this.bottom = this.right;
        this.right = tmp;
    }

    public void goWest() {
        String tmp = this.top;
        this.top = this.right;
        this.right = this.bottom;
        this.bottom = this.left;
        this.left = tmp;
    }
}



Measured memory_bytes: 24316
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
double l;
int main(){
    cin>>l;
    printf("%.6lf",pow(l/3,3));
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

ans=0
exist_odd=False
while True:
  for i in range(N):
    if A[i]%2!=0:
      exist_odd=True
  if exist_odd:
      break
  ans+=1
  for i in range(N):
    A[i]=int(A[i]/2)

print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        ReaderA.init(System.in);
        int n = ReaderA.nextInt();
        int a = ReaderA.nextInt();
        int can = n - (n/500)*500;
        System.out.println(can <= a ? "Yes" : "No");
    }
}

/**
 * Reader class based on the article at "https://www.cpe.ku.ac.th/~jim/java-io.html"
 */
class ReaderA {
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

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

//    static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}



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

int main(){
    string s,fs,bs;
    cin >> s;
    int ln=s.size();
    fs=s.substr(0,(ln-1)/2);
    bs=s.substr((ln+3)/2-1);
    int fln=fs.size();
    int bln=bs.size();

    bool kaibun = true;
    bool f_kaibun = true;
    bool b_kaibun = true;
    bool s_kaibun = true;

    for (int i=0;i<ln/2;i++){
        if(s[i]!=s[ln-1-i]){
            kaibun=false;
            break;
        }
    }
    for (int i=0;i<fln/2;i++){
        if(s[i]!=s[fln-1-i]){
            f_kaibun = false;
            break;
        }
    }

    for (int i=0;i<bln/2;i++){
        if(s[i]!=s[bln-1-i]){
            b_kaibun = false;
            break;
        }
    }

    if (kaibun && f_kaibun && b_kaibun){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 
}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

int dp[3005][3005];
string s1, s2;

int kil(int idx1, int idx2)
{
  if(idx1 == s1.length() || idx2 == s2.length())
    return 0;

  if(dp[idx1][idx2] != -1)
    return dp[idx1][idx2];

  if(s1[idx1] == s2[idx2])
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2+1) + 1);
  else
  {
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1, idx2+1));
    dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1+1, idx2));
  }
  return dp[idx1][idx2];
}


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

  string res="";

  memset(dp, -1, sizeof dp);
  cin>>s1>>s2;

  // recursive
  // kil(0, 0);

  // iterative
  memset(dp, 0, sizeof dp);

  for(int idx1 = s1.length()-1; idx1>=0; idx1--)
    for(int idx2 = s2.length()-1; idx2>=0; idx2--)
    {
      if(s1[idx1] == s2[idx2])
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2+1] + 1);
      else
      {
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1][idx2+1]);
        dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1+1][idx2]);
      }
    }



  int idx1=0, idx2=0;

  while(idx1 != s1.length() && idx2 != s2.length())
  {
    if(s1[idx1] == s2[idx2])
    {
      res += s1[idx1];
      idx1 += 1;
      idx2 += 1;
    }
    else
    {
      if(dp[idx1][idx2] == dp[idx1+1][idx2] && dp[idx1][idx2] != -1)
        idx1 += 1;
      else
        idx2 += 1;
    }
  }

  cout<<res<<endl;
  return 0;
}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<998244353>;

const int MAXS = 6000;
num dp[MAXS];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, S; cin >> N >> S;
	num ans = 0;
	for (int i = 0; i < N; i++) {
		dp[0]++;
		int a; cin >> a;
		for (int v = S-a; v >= 0; v--) {
			dp[v+a] += dp[v];
		}
		ans += dp[S];
	}
	cout << ans << '\n';

	return 0;
}


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

int main() {
    ll K; cin >> K;
    ll L = (K % 7 == 0) ? K / 7 * 9 : 9 * K;
    ll cnt = 1;
    ll M = 10 % L;
    while (cnt < L) {
        if (M == 1) {
            cout << cnt << endl;
            return 0;
        }
        M = (M * 10) % L;
        cnt++;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n,m,v[maxn],fa[maxn];
long long cnt[maxn][2],res,ans=1e18;
vector<int> g[maxn];
int p1, p2, len;
void dfs(int x,  int d = 0) {
	++ cnt[x][d & 1];
	for (int u=0;u< g[x].size();++u) {
		if (g[x][u] ==fa[x]) continue;
		if (x == p1 && g[x][u] == p2) continue;
		if (x == p2 && g[x][u] == p1) continue;
		fa[g[x][u]]=x;
		dfs(g[x][u], d + 1);
		cnt[x][0] += cnt[g[x][u]][0];
		cnt[x][1] += cnt[g[x][u]][1];
		res += abs(cnt[g[x][u]][0] - cnt[g[x][u]][1]);
	}
}
void dfs2(int x, int p = 0) {
	v[x] = v[p] + 1;
	for (int u=0;u< g[x].size();++u) {
		if (g[x][u] == p) continue;
		if (v[g[x][u]]) {
			p1 = x;
			p2 = g[x][u];
			len = v[x] - v[g[x][u]] + 1;
		}
		else dfs2(g[x][u], x);
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if (m == n - 1) {
		dfs(1);
		long long ans = res;
		if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
		printf("%lld\n", ans);
	}
	else {
		dfs2(1);
		dfs(1);
		if (len & 1) {
			if (abs(cnt[1][0] - cnt[1][1]) & 1) return 0 * puts("-1");
			long long del = (cnt[1][0] - cnt[1][1]) / 2;
			memset(cnt, 0, sizeof(cnt));
			cnt[p1][0] -= del;
			cnt[p2][0] -= del;
			res=0;
			dfs(1);
			long long ans = res+ abs(del);
			printf("%lld\n", ans);
		}
		else {
			fa[1]=0;
			memset(cnt,0,sizeof(cnt));
			dfs(1,0);
			if(cnt[1][0]!=cnt[1][1]){
				puts("-1");
				return 0;
			}
			int l=-1e6,r=1e6;
			while (l + 10 <= r) {
				long long midl = (l + r) / 2;
				long long midr = (midl + r) / 2;
				memset(cnt, 0, sizeof(cnt));
				cnt[p1][0] += midl;
				cnt[p2][1] += midl;
				res=0;
				dfs(1,0);
				long long res1 = res+abs(midl);
				memset(cnt, 0, sizeof(cnt));
				cnt[p1][0] += midr;
				cnt[p2][1] += midr;
				res=0;
				dfs(1,0);
				long long res2 = res+abs(midr);
				ans = min(ans, res1);
				ans = min(ans, res2);
				if (res1 < res2) {
					r = midr - 1;
				}
				else {
					l = midl + 1;
				}
			}
			for (int i = l; i <= r; ++ i){
				memset(cnt,0,sizeof(cnt));
				cnt[p1][0]+=i;
				cnt[p2][1]+=i;
				res=0;
				dfs(1,0);
				ans = min(ans, res+abs(i));
			}
			printf("%lld\n", ans);
		}
	}
}


Measured memory_bytes: 15872
import sys
from collections import defaultdict
sys.setrecursionlimit(10000)
input = sys.stdin.readline

N, Y = [int(x) for x in input().strip().split()]
f = False
for man in range(N + 1):
    for gosen in range(N - man + 1):
        sen = N - man - gosen
        t = (sen + 5 * gosen + 10 * man) * 1000
        if t == Y:
            print(man, gosen, sen)
            f = True
            break
        elif t > Y:
            break
    if f:
        break
else:
    print(-1, -1, -1)

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

// ---------------------------template starts here-------------------------- 

#define int long long int
#define pb push_back
#define MAX INT_MAX
#define F first
#define S second 
#define mp make_pair
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

// --------------------------template ends here------------------------------

void solve() {
    int ar[] = {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};
    int k;
    cin >> k;
    k--;
    cout << ar[k];    
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 256
from heapq import*
n=int(input())
A=[[]for _ in[0]*n]
for _ in[0]*n:
 e=list(map(int,input().split()))
 for i in range(e[1]):k=2*-~i;A[e[0]]+=[(e[k],e[k+1])]
H=[[0,0]]
d=[0]+[1e6]*n
c=[1]*n
while H:
 f=heappop(H)
 u=f[1]
 c[u]=0
 if d[u]>=f[0]:
  for s in A[u]:
   v=s[0]
   if c[v]and d[v]>d[u]+s[1]:
    d[v]=d[u]+s[1]
    heappush(H,[d[v],v])
for i in range(n):print(i,d[i])


Measured memory_bytes: 69104