akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll n;
    cin>>n;
    ll d=0;
    ll t=n;
    while(n>9){
        d+=n%10;
        n/=10;
    }
    d+=n;
    if(t%d==0)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}


func main(){
	var N,res int
	fmt.Scan(&N)
	res=0
	if (N%2!=0){
		res=0
	}else{
		for i:=10;i<=N;i*=5 {
			res+=N/i
		}
	}
	fmt.Println(res)

}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

int main(){
  ll N,M; cin >> N >> M;
  vector<pair<ll,ll>> to[1001];
  for(ll i = 0; i < M; i++){
    ll a,b,w; cin >> a >> b >> w; a--; b--; w *= - 1;
    to[a].push_back({b,w});}
  
  vector<ll> dist(N,INF);
  dist[0] = 0;
  bool closed = false;
  for(ll i = 0; i < 2*N; i++){
    for(ll v = 0; v < N; v++){
      if(dist[v] >= INF){ continue;}
      
        //to[v]に格納されている辺に着目する　辺が主語
          for(auto next : to[v]){
           
          if(dist[next.first] > dist[v] + next.second){
            dist[next.first] = dist[v] + next.second;
          if(next.first == N - 1 && i >= N){//N回目以降にノードN-1が更新されていないかを確認
            closed = true;}
          }}}}
  
  if(closed){ cout << "inf" << endl;}
  else{
    cout << -dist[N-1] << endl; } return 0;}
            
    


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <stack>
 
using namespace std;
 
int main(){
 
  long int n,m;
  cin>>n>>m;
 
   long int a[m];
 
  for(int i=0;i<m;i++)
    cin>>a[i];
 
   long sum=0;
    for(int i=0;i<m;i++){
        sum += a[i];
   }

 
    if(sum <= n)
   cout<<n-sum<<endl;
   else if(sum > n)
    cout<<"-1"<<endl;
 
 return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}
long double ModLog(long double base, long double x) {
    return (logl(x) / logl(base));
}

const int N = 2e6 + 5, MX = 1e9;
char a[N];
int main(){
    scanf("%s %s %s", a, a + 3, a + 6);
    printf("%c%c%c", a[0], a[4], a[8]);
    return 0;
}


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

int main() {

    string a,b,c;

    cin >> a >> b >> c;

    string::iterator ai,bi,ci;

    ai = a.begin();
    bi = b.begin();
    ci = c.begin();

    char now = *ai;

    ai++;

    while(1){

        if(now == 'a'){
            if(ai == a.end()){
                cout << 'A' << endl;
                break;
            }
            now = *ai;
            ai++;
        }
        else if(now == 'b'){
            if(bi == b.end()){
                cout << 'B' << endl;
                break;
            }
            now = *bi;
            bi++;
        }
        else if(now == 'c'){
            if(ci == c.end()){
                cout << 'C' << endl;
                break;
            }
            now = *ci;
            ci++;
        }

    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            double sum = 0;
            for (int i = 0; i < N; i++) {
                double x = scanner.nextDouble();
                String currency = scanner.next();
                switch (currency) {
                    case "JPY":
                        sum += x;
                        break;
                    case "BTC":
                        sum += x * 380000;
                        break;
                }
            }
            System.out.println(sum);
        }
    }
}


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

int main() {
  string S; cin >> S;
  int sum=0;
  for(int i=0; i<S.size(); i++) {
    if(S.at(i)=='x') sum += 1;
  }
  if(sum>=8) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, K; cin >> N >> M >> K;
  FOR(x,0,N+1) {
    FOR(y,0,M+1) {
      if((M-y)*x+(N-x)*y==K) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}

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

using namespace std;

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

	stack<char> st;

	while (n) {
		int p = n % 26;
		if (p == 0) st.push( 'z' );
		else st.push( char(p - 1 + 'a') );
		n--;
		n /= 26;
	}

	while (!st.empty()) { cout << st.top(); st.pop(); }
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <bitset>

#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define rep1(i,n) for (int (i) = 1; (i) <= (n); i++)
typedef long long int llint;

using namespace std;

const long long int inf = 1 << 29 ;

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

	cout << max(a - 2*b,0) << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
using namespace std;

int main() {
  char str[128];
  while (fgets(str, sizeof(str), stdin)) {
    if (str[0] == '.') { break; }
    stack<char> S;
    for (int i = 0; str[i]; ++i) {
      char c = str[i];
      switch (c) {
      case '(': S.push(')'); break;
      case '[': S.push(']'); break;
      case ')': case ']':
        if (S.empty() || S.top() != c) { goto bad; }
        S.pop();
      }
    }
    if (!S.empty()) { goto bad; }
    puts("yes");
    continue;
bad:
    puts("no");
  }
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;
constexpr ldbl pi = 3.141592653589793238l;

int main() {
  llong A, B, H, M;
  cin >> A >> B >> H >> M;

  ldbl m = H*60 + M;

  ldbl ax, ay, bx, by;
  ax = A * cos(m/720.0l * 2*pi);
  ay = A * sin(m/720.0l * 2*pi);
  bx = B * cos(M/60.0l * 2*pi);
  by = B * sin(M/60.0l * 2*pi);

  // cout << ax << endl << ay << endl << bx << endl << by << endl;

  cout << fixed << setprecision(30) << hypotf64(ax - bx, ay - by) << endl;

  return 0;
}

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

int main() {
string N;
  cin>>N;
  //cout<<N.at(1);
  if(N.at(0)=='9'){cout<<"Yes"<<endl;}
  else if(N.at(1)=='9'){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define prique priority_queue<P,vector<P>,greater<P>>
#define ggr getchar(); getchar();return 0;
using namespace std;
typedef pair<ll, ll>P;
signed main() {
	ll k;
	cin>>k;
	ll a=k%50;
	ll b=k/50;
	cout<<50<<endl;
	for(ll i=b;i<=b+49-a;i++)cout<<i<<" ";
	for(ll i=51+b-a;i<=50+b;i++)cout<<i<<" ";
	cout<<endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;
	int ans;
	int t = 1;
	for (ans = 0; t < B; ans++)t += A - 1;

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long

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

    map<string, int> cnt;
    int n;
    cin >> n;
    int mx = -1;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
        mx = max(mx, cnt[s]);
    }
    vector<string> v;
    for (auto p : cnt) {
        if (p.second == mx) v.push_back(p.first);
    }
    for (auto s : v) cout << s << '\n';
}


Measured memory_bytes: 25584
//c++ D.cpp -std=c++11
#include <bits/stdc++.h>
using namespace std;

const string MINUSINF = "-";

int N,M;
string dp[10010];
int match[]={0,2,5,5,4,5,6,3,7,6};

int main(){
	int match_cnt;
	cin >> N >> M;
	vector<int> A(M);
	for(int i=0 ; i < M ; ++i )  cin>>A[i];
		
	for(int i=0 ; i < N+1 ; ++i )  dp[i]="-";
	dp[0]="";
	
	
	for(int i=0 ; i < N+1 ; ++i ) {
		if (dp[i]=="-") continue; 
		for (int a : A) {
			match_cnt=match[a];
			
			if ( dp[i+match_cnt].size() <  (dp[i]+char('0'+a)) .size()  )  {
				dp[i+match_cnt]=dp[i]+(char)( '0'+a );
			}
			else{
				if ( dp[i+match_cnt] < dp[i]+(char)( '0'+a ) ){
					dp[i+match_cnt]=dp[i]+(char)( '0'+a );
				}
			}	
		}
	}
	
	
	cout << dp[N] << endl;
}

Measured memory_bytes: 43904
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    lint N;
    cin >> N;
    vector<lint> res;
    for(lint i = 1; i*i <= N; i++) {
        if(N%i == 0) {
            res.push_back(i);
            if(N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    lint ans = 0;
    FOR(i, 1, res.size()) {
        lint Ntmp = N;
        while(true) {
            if(Ntmp%res[i] == 0) {
                Ntmp /= res[i];
            } else {
                break;
            }
            if(Ntmp%res[i] == 1) {
                //cout << res[i] << endl;
                ans++;
            }
        }
    }
    N--;
    vector<lint> res2;
    for(lint i = 1; i*i <= N; i++) {
        if(N%i == 0) {
            res2.push_back(i);
            if(N/i != i) res2.push_back(N/i);
        }
    }
    ans += res2.size()-1;
    cout << ans << endl;
}

Measured memory_bytes: 384
while True:
    n,m= map(int,input().split())
    if n==0:
        break
    count_h,count_w,count= 0,0,0
    h,w= [0],[0]
    for i in range(0,n):
        count_h+= int(input())
        h.append(count_h)
    for i in range(0,m):
        count_w+= int(input())
        w.append(count_w)

    pos=[0]*1500010
    ans=0
    for i in range(0,n):
        for j in range(i+1,n+1):
            pos[h[j]- h[i]]+= 1
    for i in range(0,m):
        for j in range(i+1,m+1):
            ans= ans+ pos[w[j]-w[i]]
    print(ans)



Measured memory_bytes: 40724
#include<stdio.h>
int main(void){
    int n,d[200],sum;
    sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    for(int i=0;i<n;i++){
        for(int s=0;s<n;s++){
            if(i!=s){
            sum=sum+d[i]*d[s];
            }
        }
    }
    printf("%d",sum/2);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
const int MAXN=1001;
int m,n,ans[MAXN][MAXN];
char a[MAXN][MAXN];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#') ans[i][j]=100;
			else{
				if(a[i-1][j-1]=='#') ans[i][j]++;
				if(a[i-1][j]=='#') ans[i][j]++;
				if(a[i-1][j+1]=='#') ans[i][j]++;
				if(a[i][j-1]=='#') ans[i][j]++;
			    if(a[i][j+1]=='#') ans[i][j]++;
				if(a[i+1][j-1]=='#') ans[i][j]++;
				if(a[i+1][j]=='#') ans[i][j]++;
				if(a[i+1][j+1]=='#') ans[i][j]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(ans[i][j]==100) cout<<"#";
			else cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([][]int, 2)
	t := [2]int{0, 0}
	for i := 0; i < 2; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[i][j])
			t[i] += a[i][j]
		}
	}

	c1 := make([]int, n)
	s := 0
	for i := 0; i < n; i++ {
		s += a[0][i]
		c1[i] = s
	}
	c2 := make([]int, n)
	for i := 0; i < n; i++ {
		c2[i] = t[1]
		t[1] -= a[1][i]
	}

	ans := 0
	for i := 0; i < n; i++ {
		x := c1[i] + c2[i]
		if ans < x {
			ans = x
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define avjo ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    avjo;
    int a,b,c,d,p=0;
    cin>>a>>b>>c>>d;
    while(a>0 && c>0)
    {
    if(p==0)
    {
        c-=b;
        p=1;
    }
    else
    {
        a-=d;
        p=0;
    }
    }
    if(a>0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

using namespace std;
///FILE *fi=freopen("1.txt","r",stdin);
int n;
string s,t;
int main()
{
    cin>>n>>s>>t;
    int i=0,j=0;
    for(int k=1;k<=2*n;k++)
    {
        if(k%2)
        {
            cout<<s[i];
            i++;
        }
        else
        {
            cout<<t[j];
            j++;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>

int main()
{
	int N,ans = 0,r=0;
	std::cin >> N;
	char c;
	std::string C;
	for (int i = 0; i < N; i++)
	{
		std::cin >> c;
		C.push_back(c);
		if (c == 'R')r++;
	}
	for (int i = 0; i < r; i++)
		if (C[i] == 'W')
			ans++;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
// 98 40 30 21 80

int main() {
	ll A, B, Q;
	cin >> A >> B >> Q;
	vector<ll> s(A), t(B), x(Q);
	for (int i = 0; i < A; i++)cin >> s[i];
	for (int i = 0; i < B; i++)cin >> t[i];
	for (int i = 0; i < Q; i++)cin >> x[i];
	sort(s.begin(), s.end()); sort(t.begin(), t.end());
	// 神社→寺　寺→神社
	for (int i = 0; i < Q; i++) {
		ll ans = INF_LL / 2;
		{
			auto itr = upper_bound(s.begin(), s.end(), x[i]);
			if (itr == s.end())itr--;
			auto itr2 = upper_bound(t.begin(), t.end(), *itr);
			if (itr2 == t.end())itr2--;
			ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
		}
		{
			auto itr = upper_bound(s.begin(), s.end(), x[i]);
			if (itr == s.end())itr--;
			auto itr2 = upper_bound(t.begin(), t.end(), *itr);
			if (itr2 != t.begin()) {
				itr2--;
				ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
			}
		}
		{
			auto itr = upper_bound(s.begin(), s.end(), x[i]);
			if (itr != s.begin()) {
				itr--;
				auto itr2 = upper_bound(t.begin(), t.end(), *itr);
				if (itr2 == t.end())itr2--;
				ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
			}
		}
		{
			auto itr = upper_bound(s.begin(), s.end(), x[i]);
			if (itr != s.begin()) {
				itr--;
				auto itr2 = upper_bound(t.begin(), t.end(), *itr);
				if (itr2 != t.begin()) {
					itr2--;
					ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
				}
			}
		}

		{
			auto itr = upper_bound(t.begin(), t.end(), x[i]);
			if (itr == t.end())itr--;
			auto itr2 = upper_bound(s.begin(), s.end(), *itr);
			if (itr2 == s.end())itr2--;
			ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
		}
		{
			auto itr = upper_bound(t.begin(), t.end(), x[i]);
			if (itr == t.end())itr--;
			auto itr2 = upper_bound(s.begin(), s.end(), *itr);
			if (itr2 != s.begin()) {
				itr2--;
				ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
			}
		}
		{
			auto itr = upper_bound(t.begin(), t.end(), x[i]);
			if (itr != t.begin()) {
				itr--;
				auto itr2 = upper_bound(s.begin(), s.end(), *itr);
				if (itr2 == s.end())itr2--;
				ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
			}
		}
		{
			auto itr = upper_bound(t.begin(), t.end(), x[i]);
			if (itr != t.begin()) {
				itr--;
				auto itr2 = upper_bound(s.begin(), s.end(), *itr);
				if (itr2 != s.begin()) {
					itr2--;
					ans = min(abs(x[i] - *itr) + abs(*itr - *itr2), ans);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

#define N 200000
int u[31][N+1];
int main(void){
	int n=in(),C=in(),s,t,c,i,j,ans=0;
	rep(i,n){
		s=in();
		t=in();
		c=in();
		s=2*s-1;
		t=2*t;
		u[c][s]++;
		u[c][t]--;
	}
	rep(i,C){
		rep(j,N)
			u[i+1][j+1]+=u[i+1][j];
	}
	rep(i,N+1){
		int m=0;
		rep(j,31)m+=!!u[j][i];
		ans=max(ans,m);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 23680
h,w=map(int,input().split())
data=[]
for i in range(h):
    a=input()
    data.append(a)
ans="Possible"
r=0
for i in range(h):
    for j in range(w):
        if data[i][j]=="#":
            if j<r:
                ans="Impossible"
                break
            else:
                r=j
    if ans=="Impossible":
        break
print(ans)

Measured memory_bytes: 3064
N = int(input())
red, blue = [], []
for _ in range(N):
    red.append(tuple(int(i) for i in input().split()))
for _ in range(N):
    blue.append(tuple(int(i) for i in input().split()))
ans = 0

red.sort(reverse=True,key=lambda x: x[0])
blue.sort(key=lambda x: x[1])

for bl in blue:
    for re in red:
        if re[0] < bl[0] and re[1] < bl[1]:
            ans += 1
            red.remove(re)
            break

print(ans)

Measured memory_bytes: 3064
// Born Sinner
// old but im not that old
// fuck all you hoes get a grip
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

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 (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    static class pair<T1, T2>{
        T1 first;
        T2 second;
        pair(T1 first, T2 second){
            this.first = first;
            this.second = second;
        }
    }
    static int gcd(int a, int b){
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    public static void main (String[] args) throws java.lang.Exception
    {
        FastReader in = new FastReader();
        int n = in.nextInt();
        n--;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            ans += n/i;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 32764
def main():
    class Factorial:
        def __init__(self, n, mod):
            self.f = [1]
            self.mod = mod
            for j in range(1, n + 1):
                self.f.append(self.f[-1] * j % mod)
            self.i = [pow(self.f[-1], mod - 2, mod)]
            for j in range(n, 0, -1):
                self.i.append(self.i[-1] * j % mod)
            self.i.reverse()
        def factorial(self, j):
            return self.f[j]
        def ifactorial(self, j):
            return self.i[j]
        def comb(self, n, k):
            return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0

    N, A, B, K = map(int, input().split())
    MOD = 998244353

    c = Factorial(N + 1, MOD).comb

    ans = 0
    for a in range(N + 1):
        b = (K - (A * a)) // B
        if A * a + B * b == K and 0 <= b <= N:
            ans += (c(N, a) * c(N, b)) % MOD
            ans %= MOD

    print (ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 26796
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define PII pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point
{
public:
	double x, y;
	Point(double X = 0, double Y = 0)
	{
		x = X;
		y = Y;
	}
	Point operator +(const Point &p)const { return Point(x + p.x, y + p.y); };
	Point operator -(const Point &p)const { return Point(x - p.x, y - p.y); };
	Point operator *(const double a)const { return Point(x*a, y*a); };
	Point operator /(const double a)const { return Point(x / a, y / a); };
	double norm()const { return x*x + y*y; };
	double length()const { return sqrt(norm()); };
	double dot(const Point &p)const { return x*p.x + y*p.y; };
	double cross(const Point &p)const { return x*p.y - y*p.x; };
	bool operator ==(const Point &p)const
	{
		return fabs(x - p.x)<EPS &&fabs(y - p.y)<EPS;
	}
};
typedef Point Vector;

class Segment
{
public:
	Point p1, p2;
	Segment(double x1, double y1, double x2, double y2)
	{
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	bool IsOrthogonal(const Segment &s)
	{
		Vector t1 = p2 - p1;
		Vector t2 = s.p2 - s.p1;
		return equals(0.0, t1.dot(t2));
	}
	bool IsParallel(const Segment &s)
	{
		Vector t1 = p2 - p1;
		Vector t2 = s.p2 - s.p1;
		return equals(0.0, t1.cross(t2));
	}
	Point GetProjection(double X, double Y)const
	{
		Vector V = p2 - p1;
		Point P(X, Y);
		Point ret = V*(V.dot(P-p1) / V.norm());
		return ret + p1;
	}
};
typedef Segment Line;

class Circle
{
public:
	Point c;
	double r;
	Circle(Point C = Point(), double R = 0)
	{
		c = C;
		r = R;
	}
};

int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	Segment s(x1, y1, x2, y2);
	int q;
	cin >> q;
	REP(i, q)
	{
		int x, y;
		cin >> x>> y;
		Point ans=s.GetProjection(x, y);
		cout << fixed<< setprecision(10) <<ans.x << " "<< ans.y << endl;
	}
	return 0;
}

Measured memory_bytes: 3272
#include<stdio.h>
int main() {
    int n, ans=0,flag=0;
    scanf("%d", &n);
    while (n > 0) {
        ans += n % 10;
        n = n / 10;
    }
    if (ans == 1)
        ans = 10;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
    int N; cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }

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

    int size = data.size();
    cout << data[size/2] - data[size/2-1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>

using namespace std;

int n, k, t, ans;

int main()
{
	int i;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; ++i) {
		scanf("%d", &t);
		ans += min(t, k - t) << 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import string


def validate(a, b, s):
    if not s[a] == "-":
        return False
    for i in range(len(s)):
        if i != a and s[i] not in string.digits:
            return False
    return True


def main():
    a, b = (int(x) for x in input().split())
    s = input()
    print("Yes" if validate(a, b, s) else "No")


if __name__ == '__main__':
    main()


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


int main()
{
    int N;
    cin >> N;
    vector<int> a(3*N);
    for( int i = 0; i < 3*N; ++i ) cin >> a[i];


    priority_queue<long long, vector<long long>, greater<int>> firstHalf;
    priority_queue<long long> secondHalf;
    vector<long long> sumFirstHalf(N+1), sumSecondHalf(N+1);
    for( int i = 0; i < N; ++i ){
        firstHalf.push( a[i] );
        sumFirstHalf[0] += a[i];
    }
    for( int i = 2*N; i < 3*N; ++i ){
        secondHalf.push( a[i] );
        sumSecondHalf[N] += a[i];
    }

    // first half について分割部 i についての最大和を求める
    for( int i = N; i < 2*N; ++i ){
        int tmp = firstHalf.top();
        if( tmp < a[i]){
            firstHalf.pop();
            firstHalf.push( a[i] );
            sumFirstHalf[i-N+1] = sumFirstHalf[i-N] - tmp + a[i];
        }else sumFirstHalf[i-N+1] = sumFirstHalf[i-N];
    }
    // second half について分割部 i についての最小和を求める
    for( int i = 2*N-1; i >= N; --i ){
        int tmp = secondHalf.top();
        if( tmp > a[i]){
            secondHalf.pop();
            secondHalf.push( a[i] );
            sumSecondHalf[i-N] = sumSecondHalf[i-N+1] - tmp + a[i];
        }else sumSecondHalf[i-N] = sumSecondHalf[i-N+1];
    }

    long long ans = sumFirstHalf[0] - sumSecondHalf[0];
    for( int i = 1; i <= N; ++i ) ans = max( ans, sumFirstHalf[i] - sumSecondHalf[i] );
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5364
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    ll ansa=100*a,ansb=0;
    rep(i,31){
        rep(j,31){
            rep(k,101){
                rep(l,101){
                    ll w=100*a*i+100*b*j+c*k+d*l;
                    if(w==0||w>f)continue;
                    ll s=c*k+d*l;
                    if(e*w<(100+e)*s)continue;
                    if(ansb*w<ansa*s){
                        ansa=w;
                        ansb=s;
                    }
                }
            }
        }
    }
    cout<<ansa<<' '<<ansb<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

char a[100005];
int main()
{
	int q, l, r;
	int MAX = -1;
	q = 1;
	l = r = 0;
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	if(len % 2 == 1) {
		MAX = len;
		char pp = a[(len + 1) / 2];
		for(int i = (len + 1) / 2 + 1; i <= len; i++)
		{
			if(a[i] != pp || a[i] != a[len - i + 1]) {
				MAX = i - 1;
				break;
			}
		}
	}
	else {
		MAX = len;
		char pp = a[len / 2];
		for(int i = len / 2 + 1; i <= len; i++) 
		{
			if(a[i] != pp || a[i] != a[len - i + 1]) {
				MAX = i - 1;
				break;
			}
		}
	}
	printf("%d\n", MAX);
}


Measured memory_bytes: 256
# coding: utf-8
n, m = map(int, input().split())
ll = [0] * m
for i in range(n):
    l = list(map(int, input().split()))
    for j in range(l[0]):
        ll[l[j+1] - 1] += 1
print(ll.count(max(ll)) if max(ll)==n else 0)

Measured memory_bytes: 3060
/*
* Author:sam51305
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define mp make_pair
#define ll long long
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pb push_back
#define ary array

#define Yes cout << "Yes" <<endl;
#define No cout << "No" << endl;
int main() {
    fastio
    string s;
    string t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0;i < s.length();i++)
        if(s[i]!=t[i]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3776
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

	n := nextInt()

	fmt.Println(n+n*n+n*n*n)
}

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


Measured memory_bytes: 1776
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
 
int main(){
  int N,K;
  cin>>N>>K;
  double p[N];
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  
  double ans=0;
  for(int i=0;i<K;i++){
    ans=ans+p[i];
  }
  double d=ans;
  for(int i=0;i<N-K;i++){
    d=d-p[i]+p[K+i];
    ans=max(ans,d);
  }
  ans=(ans+K)/2;
  cout<<fixed<<setprecision(3);
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
// Contest: AtCoder Beginner Contest 165 (https://atcoder.jp/contests/abc165)
// Problem: F: LIS on Tree (https://atcoder.jp/contests/abc165/tasks/abc165_f)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

void dfs(int v, int p, vvi& adj, vi& a, vi& res, vi& lis) {
    auto it = lower_bound(all(lis), a[v]);
    bool en = it == end(lis);
    int idx = it - begin(lis), old;

    if (en)
        lis.push_back(a[v]);
    else
        old = lis[idx], lis[idx] = a[v];

    res[v] = sz(lis);

    for (auto v2 : adj[v])
        if (v2 != p)
            dfs(v2, v, adj, a, res, lis);

    if (en)
        lis.pop_back();
    else
        lis[idx] = old;
}

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

    int n; cin >> n;
    vi a(n);
    trav(ai, a) cin >> ai;
    vvi adj(n);
    rep(i, n-1) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vi res(n, -1), lis;
    dfs(0, -1, adj, a, res, lis);
    trav(ri, res)
        cout << ri << '\n';

    return 0;
}

Measured memory_bytes: 35892
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
#define sp(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

ll dp[405][405];
int n;
ll a[405];
ll sum[405][405];

ll solve(int i, int j){
	if(i==j)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	ll best=(1LL<<60);
	foo(k,i,j){
		best=min(best, sum[i][j]+solve(i,k)+solve(k+1,j));
	}
	return dp[i][j]=best;

}


int main(){
	fastio();
	cin>>n;
	fo(i,n) cin>>a[i];
	fill(dp,-1);
	fo(i,n){
		foo(j,i,n){
			sum[i][j]=a[j]+((j==i)?0:sum[i][j-1]);
		}
	}

	cout<<solve(0,n-1)<<endl;

}

Measured memory_bytes: 6236
while True:
    n = int(input())
    if n == 0:
        break
    max_sum = max_ending_here = int(input())
    for i in range(1, n):
        a = int(input())
        max_ending_here = max(a, max_ending_here + a)
        max_sum = max(max_sum, max_ending_here)
    print(max_sum)

Measured memory_bytes: 7556
//Train Ticket

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    string s;cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<nnn;
    else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<nnn;
    else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<nnn;
    else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<nnn;
    else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<nnn;
    else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<nnn;
    else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<nnn;
    else if(a-b-c-d==7)cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<nnn;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]

rightMin = 1001
leftMin = 1001

for i in range(N):
    if a[i] == 0:
        rightMin = min(rightMin, w[i])
    else:
        leftMin = min(leftMin, w[i])

if rightMin == 1001 or leftMin == 1001:
    print(0)
else:
    print(rightMin + leftMin)
    
    


Measured memory_bytes: 5604
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 3005

//Solution

string s,t,ans;
int dp[N][N];

void getString(int i, int j){
    if(i == 0 || j == 0) return;
    if(s[i-1] == t[j-1]) ans.pb(s[i-1]), getString(i-1,j-1);
    else if(dp[i-1][j] > dp[i][j-1]) getString(i-1,j);
    else getString(i,j-1);
}

void solve(){
    cin>>s>>t;
    int n = sz(s), m = sz(t);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    getString(n,m);
    reverse(all(ans));
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 74080
/*
[abc142] D - Disjoint Set of Common Divisors
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e6;

ll gcd(ll a, ll b) {
    while (b > 0) {
        swap(b, a %= b);
    }
    return a;
}

ll A, B;

ll solve() {
    ll g = gcd(A, B);
    int ans = 1;
    for (int i = 2; i <= MAX_N; i++) {
        if (g % i == 0) {
            ans++;
        }
        while (g % i == 0) {
            g /= i;
        }
    }
    if (g > 1) {
        ans++;
    }

    return ans;
}

int main() {
    cin >> A >> B;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pb push_back
using namespace std;
vector <int> v;
int n;
int main()
{
	cin>>n;
	if(n<1000) cout<<"ABC";
	else cout<<"ABD";
    rt0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int main() {
	int Q;
	cin >> Q;
	while (Q--) {
		ll A, B;
		cin >> A >> B;

		if (A < B) {
			swap(A, B);
		}

		if (A == B) {
			cout << (A - 1) * 2 << endl;
			continue;
		}

		ll lo = 0, hi = 2e9;
		while (hi - lo > 1) {
			ll m = (lo + hi) / 2;
			if (m * m <= A * B) {
				lo = m;
			} else {
				hi = m;
			}
		}

		if (lo * lo == A * B) {
			cout << (B - 1) + lo - 1 + (lo - 1 - B) << endl;	
		} else if (lo * (lo+1) < A * B) {
			cout << (B - 1) + lo + (lo - B) << endl;
		} else {
			cout << (B - 1) + lo + (lo - 1 - B) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
		int A,B,C;
    	cin >> A >> B >> C;
    	if (A+B+C >= 22) {
    		cout << "bust";
    	}
    	else {
    		cout << "win";
    	}
    }

Measured memory_bytes: 256
import collections


def main():
    n = int(input())
    s = collections.defaultdict(int)
    m = -1
    for i in range(n):
        t = input()
        s[t] += 1
        if m < s[t]:
            m = s[t]

    f = sorted(filter(lambda x: s[x] == m, s.keys()))
    for e in f:
        print(e)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32480
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int test[10][10], up[10001];
int main() {
	long long n, a = 1, ans = 0; cin >> n;
	for (int h = 1; h <= n; h++) {
		if (h >= 10) { a = 10; }
		if (h >= 100) { a = 100; }
		if (h >= 1000) { a = 1000; }
		if (h >= 10000) { a = 10000; }
		if (h >= 100000) { a = 100000; }
		if (h / a != 0 && h % 10 != 0) {
			test[h / a][h % 10]++;
		}
	}
	for (int h = 1; h <= 9; h++) {
		for (int i = 1; i <= 9; i++) {
			ans += test[h][i] * test[i][h];
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
using System;

namespace ITP_6_C{
    public class Program{
        public static void Main(string[] args){
            int count = int.Parse(Console.ReadLine());
            int[][] billList = new int[4][];
            billList[0] = new int[30];
            billList[1] = new int[30];
            billList[2] = new int[30];
            billList[3] = new int[30];

            for(int i=0; i<count; i++){
                string[] value = Console.ReadLine().Split(' ');
                int bill = int.Parse(value[0]) - 1;
                int roomInfo = int.Parse(value[1])*10 + int.Parse(value[2]) - 11 ;
                int person = int.Parse(value[3]);
                
                billList[bill][roomInfo] += person;
            }
            for(int i=0; i<4; i++){
                for(int k=0; k<30; k++){
                    if(k!=0 && k%10==0 ){
                        Console.WriteLine();
                    }
                    Console.Write(" " + billList[i][k]);
                }
                Console.WriteLine();
                if(i<3) Console.WriteLine("####################");
            }
        }
    }
}

Measured memory_bytes: 9156
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
L = [0] * (n+2)
L[0] = a[0]
R = [0] * (n+2)
R[-1] = a[-1]
for i in range(n):
    L[i+1] = math.gcd(a[i], L[i])
    R[-(i+2)] = math.gcd(a[-(i+1)], R[-(i+1)])

ans = 0
for i in range(1, n+1):
    if i - 1 == 0:
        ans = max(ans, R[i+1])
    elif i == n:
        ans = max(ans, L[i-1])
    else:
        ans = max(ans, math.gcd(L[i-1], R[i+1]))
print(ans)

Measured memory_bytes: 89740
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main()
{
    int n, q;
    queue<pair<string, int>> que;
    queue<pair<string, int>> finish;
    int sum = 0;

    cin >> n >> q;

    for (int i = 0; i < n; i++) {
        string s;
        int time;
        cin >> s >> time;
        que.push(make_pair(s, time));
    }

    while (!que.empty()) {
        if (que.front().second > q) {
            que.front().second -= q;
            que.push(que.front());
            que.pop();
            sum += q;
        }
        else {
            sum += que.front().second;
            finish.push(make_pair(que.front().first, sum));
            que.pop();
        }
    }

    while (!finish.empty()) {
        cout << finish.front().first << " " << finish.front().second << endl;
        finish.pop();
    }
}



Measured memory_bytes: 6236