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

using namespace std;

#define int          long long
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v)       v.begin() , v.end()
#define err(x)       cerr << #x << " is : " << x << endl
//#define endl         "\n"
#define pii pair <int , int>
#define f first
#define s second




const int MOD   =   1e9 + 7;
const int N     =   1e6 + 20;
const int big   =   1e14;

class comp
{
public:
    bool operator()(pii b , pii a)
    {
        if(min(a.f , a.s) == min(b.f , b.s))
            return (max(a.f , a.s)  > max(b.s , b.f));
        return min(a.f , a.s) > min(b.s , b.f);
    }
};



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

    if(n == 1)
    {
        cout << 0 << endl;
        return;
    }

    if(n == 2)
    {
        cout << max(a[0] , a[1]) << endl;
        return;
    }


    sort(a , a + n , greater <int> ());

    // for(int i = 0 ; i < n ; i++)
    //     cout << a[i] << " ";
    // cout << endl;
    priority_queue <pii , vector <pii> , comp> pq;
    int ans = a[0];

    pq.push({a[0] , a[1]});
    pq.push({a[0] , a[1]});


    for(int i = 2 ; i < n ; i++)
    {
        pii x = pq.top();
        ans += min(x.f , x.s);

        // cout << x.f << " " << x.s << endl;
        pq.pop();
        pii y = {x.f , a[i]};
        pii z = {x.s , a[i]};

        pq.push(y);
        pq.push(z);
    }

    cout << ans << endl;
    return;
}


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

    int t = 1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 9044
from collections import deque

def solve(n, AB):
    g = [[] for _ in range(n + 1)]
    for i, (a, b) in enumerate(AB):
        g[a].append(b)

    q = deque(maxlen=n)
    q.append((1, -1))
    k = 0
    color = {}
    while q:
        node, col = q.popleft()
        count = 0
        for i in range(len(g[node])):
            if i == col:
                count += 1
            color[(node, g[node][i])] = count
            q.append((g[node][i], count))
            count += 1
        if k < count - 1:
            k = count - 1
    return [k + 1] + [color[(a, b)] + 1 for a, b in AB]

_n = int(input())
_AB = [tuple(map(int, input().split())) for _ in range(_n - 1)]
print(*solve(_n, _AB), sep='\n')


Measured memory_bytes: 41636
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000
#define NMAX 200005

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef long long ll;
typedef pair<int ,int > P;

struct edge{
  int to,cost;
};

int A[NMAX],B,C,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void even(){
	for (int i = 0; i < N/2; ++i)
	{
		cout << A[N-i*2-1];
		if(i == N-1){
			cout << "\n";
		}else{
			cout << " ";
		}
	}
	for (int i = 0; i < N/2; ++i)
	{
		cout << A[i*2];
		if(i == N/2-1){
			cout << "\n";
		}else{
			cout << " ";
		}
	}
}

void odd(){
	for (int i = 0; i < N/2+1; ++i)
	{
		cout << A[N-i*2-1];
		if(i == N-1){
			cout << "\n";
		}else{
			cout << " ";
		}
	}
	for (int i = 0; i < N/2; ++i)
	{
		cout << A[i*2+1];
		if(i == N/2-1){
			cout << "\n";
		}else{
			cout << " ";
		}
	}	
}

void solve(){
	if(N%2){
		odd();
	}else{
		even();
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	// answer();

	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    string s,t;
    cin>>s>>t;
    ll ans=0;
    rep(i,s.length()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3924
import java.util.Scanner;

public class Main
{
    static final int INF = Integer.MAX_VALUE / 2;

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

        int[][] map = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                map[i][j] = INF;
            }
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            map[a][b] = c;
            map[b][a] = c;
        }

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

        int[][] stepMap = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                stepMap[i][j] = INF;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (map[i][j] <= l) {
                    stepMap[i][j] = 1;
                }
            }
        }

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

        int q = sc.nextInt();
        for (int iq = 0; iq < q; iq++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;
            int step = stepMap[start][end];
            if (step == INF) {
                System.out.println(-1);
            }
            else {
                System.out.println(step - 1);
            }
        }
    }
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}
int n,m;
vb seen(50);
vvb g(50,vb (50));

void dfs(int v){
  seen[v] =true;
  for(int i=0;i<n;i++){
    if(g[v][i]==false) continue;
    if(seen[i] ==true) continue;
    dfs(i);
  }
  
}

int main(){
  cin>>n>>m;
  vi a(m);
  vi b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    g[a[i]][b[i]] =g[b[i]][a[i]]=true;
  }
  int ans=0;
  for(int i=0; i<m;i++){
    g[a[i]][b[i]] =g[b[i]][a[i]]=false;
    rep(j,n) seen[j]=false;
    dfs(0);
    bool bridge =false;
    rep(j,n){if(seen[j]==false)bridge=true;}
    if(bridge) ans++;
    g[a[i]][b[i]] =g[b[i]][a[i]]=true;
  
  }
  cout <<ans<<endl;

}


Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)

cnt=0
(0...n).each{|i|
  [0,1].each{|k|
    p = [a[i+k], b[i]].min
    a[i+k]-=p
    b[i]-=p
    cnt+=p
  }
}

print cnt

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

#define COUT(x) cout << x << endl
#define CIN(x) cin >> x
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define EXIST(s, e) (s.find(e) != s.end())
#define SORT(c) sort(c.begin(), c.end())
#define ERASEUNIQE(v) v.erase(unique(v.begin(), v.end()), v.end())

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

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

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

// container util
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()

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

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

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

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main(int argc, char const *argv[])
{
    int n, ans;
    CIN(n);

    for(int i = 111;; i = i + 111)
    {
        if (i >= n) {
            ans = i;
            break;
        }
    }

    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		BigDecimal doubled = new BigDecimal(d).multiply(new BigDecimal(d));
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			sc.hasNextLine();
			int x = sc.nextInt();
			int y = sc.nextInt();
			BigDecimal doublex = new BigDecimal(x).multiply(new BigDecimal(x));
			BigDecimal doubley = new BigDecimal(y).multiply(new BigDecimal(y));
			if (doubled.compareTo(doublex.add(doubley)) >= 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 59584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i,s.size()){
    cout << (char)(65+(s[i]+n-65)%26);
  }
}


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

int main(){
    //方針：大きい順に並び替えて、小さい方のN個は無視して大きい方の2N個で偶数番目を出力
    int N; cin >> N;
    vector<long long> A(N*3);
    for (int i = 0; i < N*3; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long>());
    long long res = 0;
    for (int i = 1; i < N*2; i += 2) res += A[i];
    cout << res << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int n, l;
	string s[100];
	cin >> n >> l;
	REP(i, n){
		cin >> s[i];
	}
	sort(s, s+n);
	REP(i, n){
		cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    ll ans = 0;
    ll fl = 0;
    if (z[0] > 0)fl = -1;
    for (int i = 1; i < n; i++) {
        if (z[i - 1] + 1 < z[i])fl = -1;
    }
    if (fl == -1)cout << -1 << endl;
    else {
        ans += z[n - 1];
        for (int i = n-2; i > 0; i--) {
            if (z[i + 1] <= z[i])ans += z[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
int main(){
  string x;
  cin>>x;
  
  int ans=0;
  for(int i=0;i<4; i++){
    if(x[i]=='-'){
      ans--;
    }
    else{ans++;}
  }
  cout<<ans<<endl;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m; 
    vector<int> s(m); vector<char> c(m);
    rep(i, m) {cin >> s[i] >> c[i]; s[i]--;}

    int mn, mx;
    if(n==1)mn=0, mx=9;
    if(n==2)mn=10, mx=99;
    if(n==3)mn=100, mx=999;

    int res = -1;
    for(int i=mn; i<=mx; i++){
	bool fg = true;
        string num = to_string(i);
	rep(j, m){
	    if(c[j]!= num[s[j]]){fg = false; break;}
	}
        if(fg){res = i; break;}
    }
    cout << res << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <set>

using namespace std;




int main(void) {
	long long n;
	long long i, j, k;
	long long res = 100;
	long long a, b;
	long long year = 0;
	double rate = 0.01;
	cin >> n;

	while (1) {
		if (res >= n) {
			break;
		}

		res = res + floor(res * rate);
		
		year++;
	}

	cout << year << endl;

	return 0;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
# B
#
# input
n, m = map(int,input().split())
o = [0] * (m+1)
for i in range(n):
  l = list(map(int,input().split()))
  #print(l)
  x = l[0]
  #print(x)
  for j in range(x):
    o[l[j+1]] += 1
    #print(o)
# output
print(o.count(n))

Measured memory_bytes: 3060
n,m,c = map(int,input().split())
b=list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
# print(a)
# print(a[0][0])
cnt=0
for i in range(n):
    add=0
    for j in range(m):
        add +=a[i][j]*b[j]
    if add+c > 0:
        cnt+=1
print(cnt)

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

int main ()
{
  	const long long INF = 1LL << 60;

	long long dp[100010];

  	for (int i = 0; i < 100010; i++)
	{
		dp[i] = 1LL;
	}

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


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n, m;
    cin >> n >> m;
    char a[n][m];
    ll ans[n+2][m+2]; mem(ans, 0);
    rep(i, n) rep(j, m) cin >> a[i][j];
    rep(i, n){
        rep(j, m)
        {
            if(a[i][j] == '#')
            {
                ans[i+1][j+1] = -1;
                rep(k, 8)
                {
                    ll x = i+1+dx[k], y = j+1+dy[k];
                    if(a[x-1][y-1] != '#')ans[x][y]++;
                }
            }
        }
    }
    rep(i, n)
    {
        rep(j, m)
        {
            if(ans[i+1][j+1] == -1) cout << "#";
            else cout << ans[i+1][j+1];
        }cout << endl;
    }
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

ll gcd(ll a,ll b){//最大公約数を求める
    if(a<b){
        swap(a,b);
    }

    if(a%b == 0){
        return b;
    }else{
    return gcd(b,a%b);
    }
}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<ll> v(n),g(n,0),c(n,0);
    for(int i=0;i < n;i++)
    {
        cin >> v.at(i);
    }

    g.at(1)=v.at(0);
    for(int i=2;i < n;i++)
    {
        g.at(i)=gcd(g.at(i-1),v.at(i-1));
    }
    c.at(n-2)=v.at(n-1);
    
    for(int i=n-3;0<=i;i--)
    {
        c.at(i)=gcd(c.at(i+1),v.at(i+1));
    }
    for(int i=1;i < n-1;i++)
    {
        ans=max(ans,gcd(g.at(i),c.at(i)));
    }
    ans=max(ans,g.at(n-1));
    ans=max(ans,c.at(0));
    cout << ans << endl;
}


Measured memory_bytes: 2560
H, W, M = gets.split.map(&:to_i)
B = M.times.map{ gets.split.map(&:to_i) }
R = Array.new(H + 1, 0)
C = Array.new(W + 1, 0)

B.each do |h,w|
  R[h] += 1
  C[w] += 1
end

Rmax = R.max
Cmax = C.max

Rcount = R.count(Rmax)
Ccount = C.count(Cmax)

if Rcount * Ccount > B.count{|h,w| R[h] == Rmax && C[w]  == Cmax }
  puts Rmax + Cmax
else
  puts Rmax + Cmax - 1
end



Measured memory_bytes: 39324
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[MAX][MAX];
void dijkstra(){
  int minv,u,v;
  int d[MAX],color[MAX];
  int i,j;
  for(i =0;i < n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    u = -1;
    for(i =0;i < n;i++){
      if(minv > d[i] && color[i] != BLACK){
        u =i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(v = 0;v < n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i =0;i < n;i++){
    printf("%d ",i);
    if(d[i] == INFTY) printf("%d\n",-1);
    else printf("%d\n",d[i]);
  }
}
int main(){
  int i,j,e,k,c,u,v;
  scanf("%d",&n);
  for(i =0;i<n;i++){
    for(j =0;j<n;j++){
      M[i][j] = INFTY;
    }
  }
  for(i =0;i < n;i++){
    scanf("%d%d",&u,&k);
    for(j =0;j < k;j++){
      scanf("%d%d",&v,&c);
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
const int mod =1e9+7;
const int maxn=3e6+5;
ll fac[maxn];
string s;

ll qpow(ll a,ll b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}

void init()
{
	fac[0]=1;
	rept(i,1,3000000) fac[i]=fac[i-1]*i%mod;
}
ll c(ll n,ll k)
{
	return fac[n]*qpow(fac[k],mod-2)%mod*qpow(fac[n-k],mod-2)%mod;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	int k;
	cin>>k>>s;
	ll ans=0;
	int n=s.size();
	rept(i,0,k)
	{
		ll val=1;
		val=val*qpow(26,i)%mod*c(n-1+k-i,n-1)%mod*qpow(25,k-i)%mod;
//		dd(i);dd(val);dd(n-1+k-i);dd(n-1);de(k-i);
		ans=(ans+val)%mod;
	}
	cout<<ans<<"\n";
	return 0;
}

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

#define  BeatMeScanf    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  tc(x)          int x; cin >> x; while(x--)
#define  ll             long long
#define  vi             vector<int>
#define  pii            pair<int,int>
#define  mii            map<int,int>
#define  inf            1<<28
#define  mem(x,y)       memset(x, y, sizeof(x))
#define  ps(x,y)        fixed<<setprecision(y)<<x
#define  show(val)      cout<< #val << " -> " << val << endl
#define  Case           cout<< "Case "<< ++cs << ": "
#define  all(v)         (v).begin(), (v).end()
#define  rall(v)        (v).rbegin(), (v).rend()
#define  mod            1000000007
#define MAX             1000


int main()
{
    BeatMeScanf;

    ll n;
    cin >> n;
    ll sum = 0;

    for (int i = 1; i <= n; ++i)
    {
       if(i % 3 == 0 || i % 5 ==0) continue;
       else sum += i;
    }

    cout<< sum <<'\n';

    return 0;
}



Measured memory_bytes: 3648
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt(), K = sc.nextInt();
		boolean flag = false;
		for(int i = 0; i <= N; i++){
			if(flag) break;
			for(int j = 0; j <= M; j++){
				if(i*(M-j) + j*(N-i) == K){
					flag = true;
					System.out.println("Yes");
					break;
				}	
			}
		}
		if(!flag) System.out.println("No");
    }
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long int i,n;
    n=s.length();
    for(i=0;i<n;i++)
    {
        if(s[i]=='?')
        {
            if(s[i-1]=='P'&&((i-1)>=0))
                s[i]='D';
            else if(((s[i+1]=='D')||(s[i+1]=='?'))&&(i+1<n))
                s[i]='P';
            else
            s[i]='D';
        }
    }
    cout<<s;




return 0;
}

Measured memory_bytes: 3744
#include <stdio.h>
#define N 200000
int main(){

  int i,j,n,a[N],min,max;
  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&a[i]);
  max=a[1]-a[0];
  min=a[0];
  for(i=1;i<n;i++){
    if(max<a[i]-min) max=a[i]-min;
    if(a[i]<min) min=a[i];
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1376
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}

//x未満の要素数を返す二分探索関数
int b_s(vector<int>&vecxx, int xx) {
	if (xx <= vecxx[0]) { //x以下の要素数を返させる時は"<"に変える
		return 0;
	}
	if (vecxx.back() < xx) { //x以下の要素数を返させる時は"<="に変える
		return vecxx.size();
	}
	int aa1 = 0, aa2 = vecxx.size() - 1, aa3;
	while (aa1 + 1 < aa2) {
		aa3 = (aa1 + aa2) / 2;
		if (vecxx[aa3] >= xx) { //x以下の要素数を返させる時は">"に変える
			aa2 = aa3;
		}
		else {
			aa1 = aa3;
		}
	}
	return aa2;
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す

int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	ans += min(a, k);
	k -= a;
	k -= b;
	ans -= max(0ll, min(k, c));
	cout << ans << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
typedef long long ll;
bool Right_is_Bigger(vector<int>&a,vector<int>&b){
    if(a[0]<b[0]){return true;}
    if(a[0]>b[0]){return false;}
    for(int i=9;i>0;i--){
        if(a[i]<b[i]){return true;}
        if(a[i]>b[i]){return false;}
    }
    return false;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int>w{0,2,5,5,4,5,6,3,7,6};
    map<int,int>m;
    int N,M;
    cin>>N>>M;
    int A;
    vector<int>n_list;
    for(int i=0;i<M;i++){
        cin>>A;
        if(m[w[A]]<A){m[w[A]]=A;}
    }
    for(int i=2;i<=7;i++){
        if (m[i]!=0){n_list.push_back(m[i]);}
    }
    vector<int> zero{0,0,0,0,0,0,0,0,0,0};
    vector<vector<int>>dp(N+1,zero);
    vector<int>a;
    for(int i=0;i<N+1;i++){
        for(int j=0;j<n_list.size();j++){
            if(i-w[n_list[j]]>=0){
                if(dp[i-w[n_list[j]]]==zero&&i!=w[n_list[j]]){continue;}
                a=dp[i-w[n_list[j]]];
                a[n_list[j]]++;
                a[0]++;
                if(Right_is_Bigger(dp[i],a)){dp[i]=a;}
            }
        }
    }
    for(int i=9;i>0;i--){
        for(int j=0;j<dp[N][i];j++){
            cout<<i;
        }
    }
    cout<<endl;
}

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

struct tWord{
	string w;
	int cnt;
};

bool operator<( const tWord& l, const tWord &r ){
	return l.cnt > r.cnt;
}

int main(){
	vector<tWord> words;
	string in, max="";
	while( cin >> in ){
		int i;
		for( i=0; i<words.size(); i++ ){
			if( words[i].w == in ){
				words[i].cnt++;
			}
		}
		if( i == words.size() ){
			tWord w;
			w.w = in; w.cnt = 1;
			words.push_back(w);
			if( max.length() < in.length() ){
				max = in;
			}
		}
	}
	sort( words.begin(), words.end() );
	cout << words[0].w << " " << max << endl;
	return 0;
}

Measured memory_bytes: 0
import Control.Applicative
import Control.Monad.State

data SegTree a = Leaf a | Seg (SegTree a) a (SegTree a)  deriving (Show)

main = do
    [n,q] <- map read.words<$>getLine
    let seg = fromList $ replicate n (2^31 - 1)
    evalStateT (rmq n q) seg

rmq :: Int -> Int -> StateT (SegTree Int) IO ()
rmq s 0 = return ()
rmq s n = do
    q <- getQuery
    q s
    rmq s (n-1)

getQuery :: StateT (SegTree Int) IO (Int -> StateT (SegTree Int) IO ())
getQuery = do
    [c,x,y] <- lift $ map read.words<$>getLine
    case c of
      0 -> return $ (\s -> update s x y)
      1 -> return $ (\s -> find s x y)
      3 -> return $ (\s -> (get >>= \t -> lift $ print t))

update :: Int -> Int -> Int -> StateT (SegTree Int) IO ()
update s x y = modify (\seg -> updateSeg seg s x y)

find :: Int -> Int -> Int -> StateT (SegTree Int) IO ()
find s x y = do
    seg <- get
    lift $ print $ findSeg seg (0,s-1) (x,y)

val :: SegTree a -> a
val (Leaf a) = a
val (Seg _ a _) = a

fromList :: Ord a => [a] -> SegTree a
fromList xs = fl n xs
    where n = length xs
fl :: Ord a => Int -> [a] -> SegTree a
fl _ [x] = Leaf x
fl n xs  = Seg left v right
    where
        n' = n `quot` 2
        (xsL, xsR) = splitAt n' xs
        left = fl n' xsL
        right = fl (n-n') xsR
        v = min (val left) (val right)

updateSeg :: (Ord a) => SegTree a -> Int -> Int -> a -> SegTree a
updateSeg (Leaf v) _ _ x = Leaf x
updateSeg (Seg l v r) n i x
  | i < n' = Seg left (min (val left) (val r)) r
  | otherwise = Seg l (min (val l) (val right)) right
    where
        n' = n `div` 2
        left = updateSeg l n' i x
        right = updateSeg r (n-n') (i - n') x

findSeg :: Ord a => SegTree a -> (Int, Int) -> (Int, Int) -> a
findSeg (Leaf x) _ _ =  x
findSeg seg@(Seg l v r) (i,j) (s,t) 
  | s == i && t == j = val seg
  | n' < s =  findSeg r (n'+1, j) (s,t)
  | t <= n' = findSeg l (i, n') (s,t)
  | s <= n' && t > n' = min (findSeg l (i,n') (s,n')) (findSeg r (n'+1,j) (n'+1,t))
  where n' = (i+j-1) `quot` 2



Measured memory_bytes: 57464
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",if a%3<1||b%3<1||(a+b)%3<1{"Possible"}else{"Impossible"})
}

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

void zero(long long &a){
    if(a < 0)a = 0;
}

int main(){
    int N;
    cin >> N;
    vector<long long> H(N);
    if(N == 1){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 0; i < N; i++)cin >> H[i];
    reverse(H.begin(), H.end());
    
    bool ans = true;
    
    for(int i = 1; i < N; i++){
        if(H[i - 1] >= H[i])continue;
        H[i]--;
        if(H[i - 1] < H[i]){
            ans = false;
            break;
        }
    }
    
    cout << ((ans) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
class Program
{
      public static int CountChar(string s, char c) {
    return s.Length - s.Replace(c.ToString(), "").Length;
  }
	static void Main(string[] args)
	{
        /*
		// 整数の入力
		int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int b = int.Parse(input[0]);
		int c = int.Parse(input[1]);
		// 文字列の入力
		string s = Console.ReadLine();
		//出力
		Console.WriteLine((a+b+c) + " " + s);
        */

        System.Console.WriteLine(CountChar(Console.ReadLine(), '1'));
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

ll power(ll x,ll n) {
  ll result=1;
  while(n>0){
    if(n&1)result = ((result) * (x));
    
    x=((x)*(x));
    
    n >>= 1;
  }
  return result;
}
ll gcd(ll a,ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}

int main() {
  #ifdef AVI  
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  ll n;
  string s;
  cin >> n >> s;
  for(ll i=0 ; i<s.length() ; i++){
    ll x = s[i] - 'A';
    x += n;
    x %= 26;
    s[i] = 'A' + x;
  }
  cout << s;
}

Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
 ans=l[i][1]+l[i][0]
 for j in range(i+1,n-1):
  if ans<l[j][1]:
   ans=l[j][1]+l[j][0]
  else:
   if ans%l[j][2]!=0:
    ans+=l[j][2]-(ans%l[j][2])
   ans+=l[j][0]
 print(ans)

print(0)

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

int main(){
    int A, B, C, X, cnt = 0;
    cin >> A >> B >> C >> X;
    
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                if (i*500 + j*100 + k*50 == X) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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(){
    int h[3], m[2];
    rep(i, 2){
        cin >> h[i] >> m[i];
    }
    int k;
    cin >> k;
    int ans = 0;
    
    if(h[0] == h[1]){
        ans += m[1]-m[0];
        ans += (h[1]-h[0])*60;
    }
    else if(h[0] < h[1]){
        ans += (60-m[0])+m[1];
        ans += (h[1]-h[0]-1)*60;
    }
    else {
        ans += (60-m[0])+m[1];
        ans += (24+h[0]+h[1]-1)*60;
    }
    cout << ans-k << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
int main() {
    fast();
    // /ll t;
    // cin>>t;
    // while(t--)			
    // {
    
    // }
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cntr=0,cntw=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
        cntw++;
        else
        cntr++;
    }
    ll ans=min(cntr,cntw);
    ll i=0,j=n-1,cnt=0;
    while(i<j&&i<n&&j>0)
    {
        while(s[i]=='R')
        i++;
        while(s[j]=='W')
        j--;
        if(i<j)
        {
            swap(s[i],s[j]);
            cnt++;
        }
    }
    ans=min(ans,cnt);
    cout<<ans;
}

Measured memory_bytes: 3772
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <bits/stdc++.h>

using namespace std;

long long n, s, u;
long long a[200200];

int main () {
    cin >> n;
    u = pow(10, 9);
    for ( int i = 1; i <= n; i++) {
        cin >> a[i];
        if ( a[i] < u ) {
            s++;
        }
        u = min(a[i], u);
        //cout << "i = " << i << " u = " << u << " s = " << s << endl;
    }
    cout << s;
}


Measured memory_bytes: 1792
#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;

char a[100000][8];

int main()
{
    char ch1,ch2;
    scanf("%c %c",&ch1,&ch2);
    if(ch1<ch2)
       printf("<\n");
    else if(ch1>ch2)
        printf(">\n");
    else printf("=");
}


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

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

  vector<int> V(N);

  vector<int> C(N);

  for (int i = 0; i < N; i++)
  {
    cin >> V.at(i);
  }

  for (int  i = 0; i < N; i++)
  {
    cin >> C.at(i);
  }
  

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (V.at(i) > C.at(i)) ans += V.at(i) - C.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int a[n], vis[(n+1)/2];
	memset(vis, 0, sizeof(vis));
	for (int i=0; i<n; i++) {
		cin >> a[i];
		if (n%2 == a[i]%2) {
			cout << 0; return 0;
		}
		if (++vis[a[i]/2] > 2) {
			cout << 0; return 0;
		}
	}
	if ((n&1) && vis[0] != 1) {
		cout << 0; return 0;
	}
	int ans = 1;
	for (int i=0; i<n/2; i++) {
		ans = (ans*1ll*2) % MOD;
	}
	cout << ans;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	static long INF = (Long.MAX_VALUE/2);
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        String s = sc.nextLine();
        String t = sc.nextLine();
        int dp[][] = new int[t.length()+1][s.length()+1];
        for(int i = 0; i <= s.length(); i++)
        {
        	dp[0][i] = 0;
        }
        for(int i = 0; i <= t.length(); i++)
        {
        	dp[i][0] = 0;
        }
        
        for(int i = 1; i <= t.length(); i++)
        {
        	for(int j = 1; j <= s.length(); j++)
        	{	
        		if(s.charAt(j-1) == t.charAt(i-1))
        		{
        			dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j-1]+1);
        		}
        		else
        		{
        			dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
        		}
        		//out.print(dp[i][j]+" ");
        	}
        	//out.println();
        }
        
        
        StringBuffer sb = new StringBuffer();
        int i = t.length();
        int j = s.length();
        while(i >= 1 && j >= 1)
        {
        	if(s.charAt(j-1) == t.charAt(i-1))
        	{	
        		sb.append(t.charAt(i-1));
        		i--;
        		j--;
        	}
        	else if(dp[i-1][j] > dp[i][j-1])
        	{
        		i--;
        	}
        	else
        	{
        		j--;
        	}
        }
        
        sb.reverse();
        out.println(sb.toString());
        out.close();
	}

}


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

int main(){
    int n;
    cin >> n;
    vector<long long> lucas(n + 1);
    lucas.at(0) = 2;
    lucas.at(1) = 1;
    for(int i = 2;i < n + 1;i++){
        lucas.at(i) = lucas.at(i - 1) + lucas.at(i - 2);
    }
    cout << lucas.at(n) << endl;
}

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


int main(){
  int n,i,j;
  
  
  int up = 0;
  cin >> n;
  for(i=0;i<n;i++){
    int sum[110]={};
    string a,b;
    up = 0;
    cin >> a >> b;
    int sa=a.size(),sb=b.size();
    int flag=0;
    if(max(sa,sb)>80) flag =1;
    else 
    for(j=0;j<max(sa,sb);j++){
      if(sa>j&&sb>j){
	sum[j] = (a[sa-j-1]-'0') + (b[sb-j-1]-'0') + up;
      }else if(sa>j){
	sum[j] = (a[sa-j-1]-'0') + up;
      }else if(sb>j){
	sum[j] = (b[sb-j-1]-'0') + up;
      }
      up=0;
      if(sum[j]>9){
	up=1;
	sum[j]-=10;
      }
    }
    sum[max(sa,sb)]=up;
    int k=max(sa,sb);
    while(sum[k]==0&&k>0) k--;
    if(k>=80||flag==1) cout << "overflow";
    else
    for(j=k;j>=0;j--)
      cout << sum[j];
    cout << endl;
  }
}

Measured memory_bytes: 1212
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int diff = 0;
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		if (x != i + 1) ++diff;
	}
	cout << (diff <= 2 ? "YES" : "NO") << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.length() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) + "..." << endl;
    }

    return 0;
}

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

int main() {
    int a,b,c,x;
    std::cin >> a >> b >> c >> x;
    int num = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500*i + 100*j + 50*k == x) num++;
            }
        }
    }
    std::cout << num << std::endl;
}

Measured memory_bytes: 256
# 解説
def accumulate(a):
    su = 0
    yield su

    for x in a:
        su += x
        yield su


def solve_agc034c():
    from collections import namedtuple
    import sys
    input = sys.stdin.readline

    Test = namedtuple('Test', 'Aoki_score lower_bound upper_bound')
    Test.D_partial = lambda self, score: \
        self.lower_bound * score if score <= self.Aoki_score \
            else self.upper_bound * score - (self.upper_bound - self.lower_bound) * self.Aoki_score

    def is_ok(init_rest):
        """init_rest: 勉強に使える時間"""
        take, rest = divmod(init_rest, X)
        if take > N - 1:
            r = take - (N - 1)
            take = N - 1
            rest += r * X

        for i, partial_solve_test in enumerate(tests, start=1):
            when_full = partial_solve_test.D_partial(X)
            if i <= take:
                su = acc[take + 1] - when_full
            else:
                su = acc[take]

            when_partial = partial_solve_test.D_partial(min(X, rest))
            d = INIT_D + su + when_partial
            if d >= 0:
                return True

        return False

    def binary_search(*, ok, ng, is_ok):
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    N, X = map(int, input().split())
    tests = []
    for _ in range(N):
        row = map(int, input().split())
        tests.append(Test(*row))
    tests.sort(key=lambda test: test.D_partial(X), reverse=True)
    # 勝つ科目と負ける科目を決める
    # 勝つ科目は重要度をupper_boundにする
    # 負ける科目は重要度をlower_boundにする

    INIT_D = -sum(test.lower_bound * test.Aoki_score for test in tests)

    *acc, = accumulate(test.D_partial(X) for test in tests)

    res = binary_search(ok=10 ** 10, ng=-1, is_ok=is_ok)
    # D>=0となる勉強時間

    print(res)
    return


if __name__ == '__main__':
    solve_agc034c()


Measured memory_bytes: 81820
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

const int N = 100000;
const int INF = 1<<29;

int n, k;
int input[N];
int data[N];

int solve(){
  if(n == 1) return 0;
  for(int i=0;i<n-1;i++){
    data[i] = input[i+1] - input[i];
  }
  sort(data, data+n-1, greater<int>());
  int res = input[n-1] - input[0];
  for(int i=0;i<k-1;i++){
    res -= data[i];
  }
  if(res < 0) res = 0;
  return res;
}

main(){
  int tc;
  cin >> tc;
  while(tc--){
    cin >> n >> k;
    for(int i=0;i<n;i++){
      cin >> input[i];
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// コメントを修正して, 再提出.
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define a first
#define b second
#define all(x) x.begin(), x.end()

int main(){
    
    // 1. 入力情報.
    int N, K;
    map<char, int> m;
    scanf("%d %d", &N, &K);
    rep(i, N){
        char c[22];
        scanf("%s", c);
        m[c[0]]++;
    }
    
    // 2. データを保存.
    vector<pair<int, char>> v;
    for(auto &i : m) v.push_back({i.b, i.a});
    
    // 3. 最大で何回のKUPCを開催できるか？
    // ex.
    // 6 2
    // DAWN
    // DAYLIGHT
    // DAZZLE
    // BAKERY
    // BARRIER
    // ABSENCE
    // -> 3回 が 正しいので, ロジック修正.
    int ans = 0;
    while(1){
        int k = K;
        sort(all(v));
        reverse(all(v));
        for(auto &p : v){
            if(p.a > 0){
                p.a--;
                k--;
            }
            if(!k) break;
        }
        if(k) break;
        else  ans++;
    }
    
    // 4. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  int a[N], b[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  for(int i = 0; i < N; i++) cin >> b[i];

  sort(a, a + N);
  sort(b, b + N);

  int ans = 0;
  //kビットが1になるようなai+bjの個数を求め、ansに足す。
  for(int k = 0; k < 30; k++){
    int aa[N];
    int bb[N];
    for(int i = 0; i < N; i++){
      aa[i] = a[i] % (1 << (k + 1));
      bb[i] = b[i] % (1 << (k + 1));
    }

    sort(aa, aa + N);
    sort(bb, bb + N);

    int T = (1 << k);
    ll cnt = 0;
    //aを固定して2^k <= x < 2^k+1, 2^k+2 <= x < 2^k+3の個数
    for(int i = 0; i < N; i++){
      auto ind1 = lower_bound(bb, bb + N, T - aa[i]);
      auto ind2 = lower_bound(bb, bb + N, 2 * T - aa[i]);
      auto ind3 = lower_bound(bb, bb + N, 3 * T - aa[i]);
      auto ind4 = lower_bound(bb, bb + N, 4 * T - aa[i]);
      cnt += (ind2 - ind1) + (ind4 - ind3);
    }

    if(cnt % 2 == 1){
      ans += (1 << k);
    }
  }

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


Measured memory_bytes: 3328