akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
  while(true){
    string s1;
    cin>>s1;
    if(s1=="."){
      break;
    }
    string s2;
    cin>>s2;
    if(s1==s2){
      cout<<"IDENTICAL"<<endl;
      continue;
    }
    string t1=s1;
    string t2=s2;

    while(true){
      size_t d1b=t1.find('\"');
      if(d1b==string::npos){
        break;
      }
      t1.replace(d1b,1,"@");

      size_t d1e=t1.find('\"');
      t1.replace(d1e,1,"@");

      size_t d2b=t2.find('\"');
      if(d2b==string::npos){
        break;
      }
      t2.replace(d2b,1,"@");

      size_t d2e=t2.find('\"');
      t2.replace(d2e,1,"@");

      string u1=s1;
      u1.replace(d1b+1,d1e-d1b-1,"");
      string u2=s2;
      u2.replace(d2b+1,d2e-d2b-1,"");

      if(u1==u2){
        t1=u1;
        t2=u2;
        break;
      }
    }
    if(t1==t2){
      cout<<"CLOSE"<<endl;
    }else{
      cout<<"DIFFERENT"<<endl;
    }
  }
  return 0;
}



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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N;
  string S;
  map<char, int> cnt;

  void init() {
    cin >> N >> S;
    rep(i, N) {
      cnt[S[i]]++;
    }
  }

  void solve() {
    ll ans = 1;
    for(const auto& pr : cnt) {
      ans = ans * (pr.second+1) % MOD_1_000_000_007;
    }
    cout << ans-1 << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
long long gcd(long a,long b)
{
    return b?gcd(b,a%b):a;
}
long long lcm(long long a,long long b)
{

	return a/gcd(a,b)*b;
}
int main()
{
	int n,i;
	long long a[101];
	long long m;
	while(~scanf("%d",&n))
	{
		for (i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
		}
		m=a[0];
		for (i=1;i<n;i++)
		{
		    if (a[i]%m==0)
		    {
		    	m=a[i];
			}
			else
			{
				m=lcm(m,a[i]);
			}
		}
		printf("%lld\n",m);
	}
	return 0;
}

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

int main() {
	char d[101];
	int i,j,a,b;
	while(true) {
	for (i=0;i<3;i++) {
		cin >> d; a=b=0;
		if (d[0]=='0') return 0;
		for (j=1;d[j]!='\0';j++) if (d[j]=='A') a++; else b++;
		if (a>b) a++; else b++;
		cout << a << ' ' << b << endl; 
	}
}  
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mxx=2e5+7;

 int a[1200005]={};
  vector<int> pr;
void primes(int n)
{
	 for(int i=2;i<=n;i++)
	 {     
	   if(a[i]==0)
	   {
	     a[i]=i;pr.push_back(i);
	   }
	   for(int j=0;j<(int)pr.size() && pr[j]<=a[i] && i*pr[j]<=n;j++)
	    a[pr[j]*i]=pr[j];
	 }  
}


int main()
{

    fast
   
    primes(1100001);a[1]=1;
     int n;
     cin>>n;
     int gc=1;int aa[n];
     for(int i=0;i<n;i++)
     {
     	 cin>>aa[i];
     	 if(i==0)gc=aa[i];
     	 else gc=__gcd(gc,aa[i]);
     }
     
     bool ok=false;
     if(gc==1)ok=true;

     bool what=true;
     map<int,int> m;
     for(int i=0;i<n;i++)
     { 
     	   int num=aa[i];
     	   if(!what)break;
     	   set<int> cur;
     	   while(num!=a[num])
     	   {
     	   	 cur.insert(a[num]);
     	   	 num=num/a[num];
     	   }
     	   if(num!=1)cur.insert(num);
     	   	 for(auto x:cur)if(m[x]>0 && x>1){what=false;break;}
     	   	 	else m[x]++;
     }
     
     	 if(what)cout<<"pairwise coprime";
     	 else if(ok)cout<<"setwise coprime";
     	 else cout<<"not coprime";
     

}

Measured memory_bytes: 11964
#include<iostream>
using namespace std;
int main(){
  int n,a;
  int count=0;
  int sum=0;
  cin>>n;
  while(count<n && cin>>a){
    while(a%2!=1){
      a/=2;
      sum++;
    }
    count++;
  }
  cout<<sum<<endl;
  return 0;
}


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

//#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 1e6+5;
int spf[N+5];
bool vis[N];
void sieve()
{
	for(int i=1;i<=N;++i)
	spf[i] = i;
	for(int i=2;i*i<=N;++i)
	{
		if(spf[i]!=i)
		continue;
		for(int j=2*i;j<=N;j+=i)
		{
			if(spf[j]==j)
			{
				spf[j] = i;
			}
		}
	}
}
bool flag = false;
void help(int x)
{
	vector<int> res;
	while(x!=1)
	{
		res.pb(spf[x]);
		if(vis[spf[x]])
		{
			flag = true;
		}
		x/=spf[x];
	}
	for(auto it:res)
	vis[it] = true;
}		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		sieve();
		int n;
		cin>>n;
		int arr[n];
		int gcdd = 0;
		for(int i=0;i<n;++i)
		{
			cin>>arr[i];
			help(arr[i]);
			gcdd = __gcd(gcdd,arr[i]);
		}
		if(!flag)
		{
			cout<<"pairwise coprime";
		}
		else if(gcdd==1)
		{
			cout<<"setwise coprime";
		}
		else
		{
			cout<<"not coprime";
		}
    }
    return 0;
}



Measured memory_bytes: 12220
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail+1)%LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head+1) % LEN;
    return x;
}

int min(int a,int b){
    return a < b ? a : b;
}

int main(){
    int time = 0,c;
    int i,q;
    P u;
    scanf("%d %d",&n, &q);
    
    for(int i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head = 1;
    tail = n + 1 ;
    
    while(head != tail){
        u = dequeue();
        c = min(q,u.t);
        u.t = u.t - c;
        time = time + c;
        if(u.t > 0){
            enqueue(u);
        }
        else{
            printf("%s %d\n",u.name,time);
        }
    }
    return 0;
}


Measured memory_bytes: 12724
#include <bits/stdc++.h>      
#define pb push_back 
#define fr first 
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii; 

int main() {

    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    //int t; cin>>t; while(t--) { 
    int n; cin>>n;
    vi dp(3);
    for(int day = 0; day < n; ++day) {
        vi new_dp(3, 0);
        vi c(3);
        for(int i = 0; i < 3; ++i) cin>>c[i];
        
        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                if(i != j) {
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
        //cout<<new_dp[0]<<" "<<new_dp[1]<<" "<<new_dp[2]<<"\n";
        dp = new_dp;
    }
    cout<<max3(dp[0],dp[1],dp[2]);
    
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main{
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int[] a = in.ni(n);
        Arrays.sort(a);
        long sum = 0, sum2 = 0;
        if(n%2==0){
            for (int i = 0; i < n; i++) {
                if(i<n/2-1) a[i] *= -2;
                else if(i==n/2-1) a[i]*= -1;
                else if(i==n/2) a[i] *= 1;
                else a[i] *= 2;
            }
            for (int i = 0; i < n; i++) sum += a[i];
        }else{
            int[] a2 = Arrays.copyOf(a,n);
            for (int i = 0; i < n; i++) {
                if(i<(n+1)/2-2) a[i] *= -2;
                else if(i<(n+1)/2) a[i]*= -1;
                else a[i] *= 2;
            }
            for (int i = 0; i < n; i++) {
                if(i<n/2) a2[i] *= -2;
                else if(i<n/2+2) a2[i] *= 1;
                else a2[i] *= 2;
            }
            for (int i = 0; i < n; i++) sum += a[i];
            for (int i = 0; i < n; i++) sum2 += a2[i];
        }
        out.println(Math.max(sum,sum2));
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 37260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
		
  int N; 
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++)
    cin >> A.at(i);
  
  int max = A.at(0);
  long long ans = 0;
  for(int i = 1; i < N; i++){
    if(A.at(i) < max){
      ans += max - A.at(i);
    }
    else{
      max = A.at(i);
    }
  }
   cout << ans << endl;
}    

Measured memory_bytes: 3984
#include <iostream>

int main(void){
    int x,y;
    std::cin >> x >>y;
    while (true) {
        if (x==0 && y==0) {
            break;
        }
        else if (x<y) {
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
        std::cin >> x >> y;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

    ll n;cin >> n;
    vector<ll> a(n+1);
    rep(i,n+1)cin >> a[i];
    
    struct p{
        ll min;
        ll max;
    };

    if(n == 0){
        if(a[0] == 1)cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }else if(a[0] == 1){
        cout << -1 << endl;
        return 0;
    }

    vector<p> sum;
    reverse(ALL(a));
    sum.push_back({a[0],a[0]});

    for(ll i=1;i<a.size();i++){
        ll min = (sum[i-1].min + 1)/2 + a[i];
        ll max = sum[i-1].max + a[i];
        sum.push_back({min,max});
    }

    reverse(ALL(sum));
    bool flag = false;
    for(ll i=sum[0].min;i<=sum[0].max;i++){
        if(i == 1){
            flag = true;
            break;
        }
        if(i >= 2)break;
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }

    ll vertex = 1;
    ll ans = 1;
    reverse(ALL(a));
    for(ll i=1;i<=n;i++){
        ll tmp = vertex * 2;
        ans += min(tmp,sum[i].max);
        vertex = min(tmp,sum[i].max) - a[i];
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int N = n - 1;
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for(int i = 0; i < n && N; ++i) {
    int b = min(2 - (i == 0), N);
    ans += 1LL * b * a[i];
    N -= b;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3968
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int n,a[N],ans;
map<int,int>p;
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]),p[a[i]]++;
	sort(a+1,a+n+1);
	for(register int i=n;i;i--)
		if(p[a[i]]>0){
			int x=1;
			while(x<=a[i])x<<=1;
			int b=x-a[i];
			if(p.count(b)&&(p[b]>(a[i]==b)))p[b]--,p[a[i]]--,ans++;
		}
	printf("%d\n",ans);
	return 0;
}

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

int H, W, N;
int a, b;
map<pair<int, int>, int> board;
ll ans[10];

signed main()
{
	cin >> H >> W >> N;
	rep(i,N) {
		cin >> a >> b;		//上からa行目、左からb列目
		for (int aa=a-1; aa<=a+1; aa++) {
			for (int bb=b-1; bb<=b+1; bb++) {
				if (2 <= aa && aa <= H - 1 && 2 <= bb && bb <= W - 1) {
					board[make_pair(aa, bb)]++;
				}
			}
		}
	}

	map<pair<int, int>, int>::iterator it = board.begin();
	while (it != board.end()) {
		ans[it->second]++;
		++it;
	}

	ans[0] = ll((H - 2) * (W - 2)) - board.size();
	rep(i,10) cout << ans[i] << endl;
}


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

using namespace std;

int main(void) {
  int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  vector<int> p, q, r;

  for (int i = 0; i < A; i++) {
    int a; cin >> a;
    p.push_back(a);
  }
  for (int i = 0; i < B; i++) {
    int a; cin >> a;
    q.push_back(a);
  }
  for (int i = 0; i < C; i++) {
    int a; cin >> a;
    r.push_back(a);
  }

  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());

  for (int i = 0; i < X; i++) {
    r.push_back(p[i]);
  }
  for (int i = 0; i < Y; i++) {
    r.push_back(q[i]);
  }

  sort(r.begin(), r.end(), greater<int>());
  long long ans = 0;

  for (int i = 0; i < X+Y; i++) {
    ans += r[i];
  }

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

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6

using namespace std;

int main(){
    int n;
    cin >>n;
    int w[n];
    int all=0;
    rep(i,n) {
        cin >> w[i];
        all+=w[i];
    }
    int ans=INF;
    int wa=0;
    rep(i,n-1){
        wa+=w[i];
        int p=abs(all-2*wa);
        ans=min(ans,p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 202020;
const int INF = 1001001001;

int dp[MAX_N][3];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < MAX_N; i++) for (int j = 0; j < 3; j++) dp[i][j] = -INF;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int pre = 0; pre < 3; pre++) {
            if (dp[i][pre] < 0) continue;
            for (int nxt = 1; nxt < 3; nxt++) {
                if (pre == nxt) {
                    if (nxt == 1) {
                        if (s[i - 1] == s[i]) continue;
                    } else {
                        if (s[i - 2] == s[i] && s[i - 1] == s[i + 1]) continue;
                    }
                }
                dp[i + nxt][nxt] = max(dp[i + nxt][nxt], dp[i][pre] + 1);
            }
        }
    }
    cout << max(dp[n][1], dp[n][2]) << endl;
}

Measured memory_bytes: 2948
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

// ll T,N;
// vector<ll> a(N);
// const int M = 2;
// void dfs(vector<int> &A) {
//     // 終端条件 --- 10 重ループまで回したら処理して打ち切り
//     if (A.size() == n) {
//         return;
//     }

//     for (int v = 0; v < M; ++v) {
//         A.push_back(v);
//         dfs(A);
//         A.pop_back(); // これが結構ポイント
//     }
// }

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  string s,t;
  cin>>s>>t;
  // vector<ll> a(n);
  // rep(i, n){
  //   cin >> a[i];
  // }

  ll ans = 0;
  ll l = s.length();
  rep(i,l){
    if(s[i] == t[i]){
      ans++;
    }
  }
  
  cout << l - ans << endl;


  return 0;
}

Measured memory_bytes: 3868
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	ans := 0
	a := getNextInt(scanner)
	b := getNextInt(scanner)

	if b > 1 {
		ans = (b-2)/(a-1) + 1
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string.h>
#include<functional>
//aoj 0558
using namespace std;
int n,bs;
int hs,sl;
int dh[5]={0,0,0,1,-1};
int dll[5]={0,1,-1,0,0};
int cun[1003][1003];
struct pt{
	int hh;
	int ll;
	int step;
};
pt dl1[11];
char vis[1003][1003];
pt dl[1<<16];
void bfs(int h,int l,int gs)
{
	int qy=1<<16;
	qy--;
	memset(dl,0,sizeof(dl));
	memset(vis,0,sizeof(vis));
	int front=1;
	int back=2;
	pt ls;
	ls.hh=h;
	ls.ll=l;
	ls.step=0;
	dl[1]=ls;
	vis[h][l]=1;
	while(front<back)
	{
		pt lss=dl[front&qy];
		front++;
		for(int i=1;i<=4;i++)
		{
			if(lss.hh+dh[i]>0&&lss.hh+dh[i]<=hs&&lss.ll+dll[i]>0&&lss.ll+dll[i]<=sl&&cun[lss.hh+dh[i]][lss.ll+dll[i]]!=111&&vis[lss.hh+dh[i]][lss.ll+dll[i]]!=1)
			{
				pt jr;
				jr.hh=lss.hh+dh[i];
				jr.ll=lss.ll+dll[i];
				jr.step=lss.step+1;
				if(cun[lss.hh+dh[i]][lss.ll+dll[i]]==gs)
				{
					bs+=jr.step;
					return;
				}else{
					dl[back&qy]=jr;
					vis[jr.hh][jr.ll]=1;
					back++;
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d%d",&hs,&sl,&n);
	while(getchar()!='\n');
	for(int i=1;i<=hs;i++)
	{
		for(int j=1;j<=sl;j++)
		{
			char aaa;
			scanf("%c",&aaa);
			if(aaa=='X')
			{
				cun[i][j]=111;
			}
			if(aaa=='S')
			{
				pt ls;
				ls.hh=i;
				ls.ll=j;
				dl1[0]=ls;
				cun[i][j]=22;
			}
			if(aaa>='1'&&aaa<='9')
			{
				pt ls;
				ls.hh=i;
				ls.ll=j;
				dl1[aaa-'0']=ls;
				cun[i][j]=aaa-'0';
			}
		}
		
		while(getchar()!='\n');
	}
	for(int i=0;i<=n-1;i++)
	{
		bfs(dl1[i].hh,dl1[i].ll,i+1);
	}
	printf("%d\n",bs);
	return 0;
}












Measured memory_bytes: 8320
#include<iostream>
using namespace std;
int main()
{
	/*int t;
	cin>>t;
	double x1,y1,x2,y2,x3,y3;
	double a,k;
	while(t--)
	{
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		a=(y2-y1)/((x2-x1)*(x2-x1));
		k=(y3-y2)/(x3-x2);

	}*/
	int n;
	while(cin>>n){
	if(n/100==n%10)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
C=[]
ans=0
cnt=0
for i in range(N):
  a,b=map(int,input().split())
  C.append((a,b))
C=sorted(C)
for i in range(N):
  if cnt+C[i][1]<=M:
    cnt+=C[i][1]
    ans+=C[i][1]*C[i][0]
  else:
    break
print((M-cnt)*C[i][0]+ans)

Measured memory_bytes: 83656
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}

void solve() {  
    int n, k;
    cin >> n >> k;
    int p[n];
    rep(i, 0, n)
        cin >> p[i];
    sort(p, p + n);
    int ans = 0;
    rep(i, 0, k)
        ans += p[i];
    cout << ans;
}       

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

#define N 32
#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )

static void
solve (
  int * d,
  int * e,
  int   l
  )
{
  const int cl = e[ -1 ];
  int *it;

  if ( cl <= l )
  {
    for ( it = d; it != e; ++it )
    {
      if ( it != d ) putchar ( ' ' );
      printf ( "%d", *it );
    }
    puts ( "" );
  }

  e[ -1 ] = MIN( e[ -1 ], l + 1 );
  while ( --e[ -1 ] )
  {
    e[ 0 ] = cl - e[ -1 ];
    solve ( d, e + 1, e[ -1 ] );
  }

  return ;
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int d[ N ];

    scanf ( "%d", d );
    if ( !d[ 0 ] ) break ;

    solve ( d, d + 1, INT_MAX );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,t,ans;

main(){
    cin>>n>>t;
    int a[n];
    rep(i,n)cin>>a[i];
    rep(i,n-1)ans+=min(t,a[i+1]-a[i]);
    ans+=t;
    dans;
}



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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;

  string res = "";

  string cur, next;
  cin >> cur;
  for (int i = 0; i < n; i++) {
    if (i != n - 1) {
      cin >> next;
    }

    if (cur == "AB") {
      if (a == 1 && b == 1 && c == 0) {
        if (next == "AC") {
          a++;
          b--;
          res += "A";
        } else {
          a--;
          b++;
          res += "B";
        }
      } else {
        if (a > b) {
          a--;
          b++;
          res += "B";
        } else {
          b--;
          a++;
          res += "A";
        }
      }
    }

    if (cur == "BC") {
      if (a == 0 && b == 1 && c == 1) {
        if (next == "AB") {
          b++;
          c--;
          res += "B";
        } else {
          b--;
          c++;
          res += "C";
        }
      } else {
        if (b > c) {
          b--;
          c++;
          res += "C";
        } else {
          b++;
          c--;
          res += "B";
        }
      }
    }

    if (cur == "AC") {
      if (a == 1 && b == 0 && c == 1) {
        if (next == "AB") {
          a++;
          c--;
          res += "A";
        } else {
          a--;
          c++;
          res += "C";
        }
      } else {
        if (a > c) {
          a--;
          c++;
          res += "C";
        } else {
          a++;
          c--;
          res += "A";
        }
      }
    }

    cur = next;

    if (a < 0 || b < 0 || c < 0) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  for (auto &c : res) {
    cout << c << "\n";
  }
  return 0;
}

Measured memory_bytes: 3804
n = int(input())
dic = {}

max = 0
for i in range(n):
    string = input()
    dic.setdefault(string, 0)
    dic[string] = dic[string] + 1
    if(dic[string] > max):
        max = dic[string]

dic2 = sorted(dic.items())
for s ,val in dic2:
    if(val == max):
        print(s)


Measured memory_bytes: 44124
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    Si = [0]*(4)
    s = ["AC", "WA", "TLE", "RE"]
    for _ in range(N):
        a = S()
        for j, ss in enumerate(s):
            if a == ss:
                Si[j] += 1
                break

    print("AC x " + str(Si[0]))
    print("WA x " + str(Si[1]))
    print("TLE x " + str(Si[2]))
    print("RE x " + str(Si[3]))


if __name__ == '__main__':
    main()


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

int main(){
    int N, K; cin >> N >> K;
    vector<int> D(K);
    unordered_map<int,int> MP;
    for(int i = 0; i < K; i++) cin >> D[i];
    for(int i = 0; i < K; i++) MP[D[i]]++;
    for(int yen = N; yen < 100000; yen++){
        int tmp = yen;
        bool flag = 1;
        while(tmp > 0){
            int res = tmp % 10;
            if(MP[res] == 1){
                flag = 0;
                break;
            }
            tmp /= 10;
        }
        if(flag){
            cout << yen << endl;
            return 0;
        }
    }
}

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

vector< vector< int > > adjMatrix;

vector< int > findCostsFrom0(int n) {
  int nvisited = 1;
  vector< int > cost (n, INT_MAX);
  cost[0] = 0;
  while (nvisited < n) {
    int toadd = -1;
    int toaddcost = INT_MAX;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
	if ((cost[i] != INT_MAX) &&
	    (cost[j] == INT_MAX) &&
	    (cost[i] + adjMatrix[i][j] < toaddcost)) {
	  toaddcost = cost[i] + adjMatrix[i][j];
	  toadd = j;
	  // cout << toadd << ' ' << toaddcost << endl;
	}
      }
    }
    nvisited++;
    cost[toadd] = toaddcost;
  }
  return cost;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  adjMatrix = vector< vector< int > > (n, vector< int > (n, INT_MAX/2));
  for (int i = 0; i < n; i++) {
    adjMatrix[i][i] = 0;
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int vj;
      cin >> vj;
      cin >> adjMatrix[u][vj];
    }
  }
  vector< int > costs = findCostsFrom0(n);
  for (int i = 0; i < n; i++)
    cout << i << ' ' << costs[i] << endl;
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=1000001;
using namespace std;


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

    vector<ll> prime(NMAX), cnt(NMAX, 0);
    for(int i = 0; i < NMAX; i++){
        prime[i] = i;
    }
    int p = 2;
    while(p*p <= NMAX){
        if(prime[p] != p){
            p++;
            continue;
        }
        for(int i = p; i < NMAX; i += p){
            prime[i] = p;
        }
        p++;
    }

    bool pairwise = true;
    bool setwise = true;

    for(int i = 0; i < n; i++){
        int tmp = a[i];
        while(prime[tmp] != tmp){
            int sis = prime[tmp];
            cnt[sis]++;
            while(tmp != 1 && tmp%sis == 0) tmp /= sis;
        }
        cnt[prime[tmp]]++;
    }

    for(int i = 2; i < NMAX; i++){
        if(cnt[i] == n){
            pairwise = false;
            setwise = false;
            break;
        } else if(cnt[i] > 1){
            pairwise = false;
        }
    }

    if(pairwise){
        cout << "pairwise coprime" << endl;
    } else if(setwise){
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }

    return 0;
}

Measured memory_bytes: 26752
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

x,y,a,b,c = inp
p = inp.sort{|a,b|b<=>a}[0...x].sort
q = inp.sort{|a,b|b<=>a}[0...y].sort
r = inp.sort{|a,b|b<=>a}
ans = sum(p)+ sum(q)

drf = r.shift
p << 1e20
q << 1e20
while true
  break if(drf < p[0] and drf < q[0])
  if(p[0] > q[0])
    ans += drf - q.shift
  else
    ans += drf - p.shift
  end
  break if r.size == 0
  drf = r.shift
end
p ans



Measured memory_bytes: 32904
#include<stdio.h>
int main(void)
{
	int a1,a2,a3,a4,b1,b2,b3,b4,s,s1;
	scanf("%d %d %d %d",&a1,&a2,&a3,&a4);
	scanf("%d %d %d %d",&b1,&b2,&b3,&b4);
	s=a1+a2+a3+a4;
	s1=b1+b2+b3+b4;
	if(s>=s1){
		printf("%d\n",s);
	}
	else if(s<s1){
		printf("%d\n",s1);
	}

	return 0;
}
	

Measured memory_bytes: 1020
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
const int MaxN = 1e5 + 10;
vector<int>E[MaxN];
queue<int>Q;
int n, u, v, b, w, sum_b, sum_w;
int cnt, d[MaxN], t;
bool vis[MaxN], ok;
struct NOOD{
	int pos, d;
}ans[MaxN];
bool cmp(NOOD x, NOOD y){return x.d < y.d;}
void dfs(int x, int len){
	if(ok)return ;
	if(x == n){
		ok = 1;
		cnt = len - 1;
	}
	vis[x] = 1;
	for(int i = 0; i < E[x].size(); i++)
		if(!vis[E[x][i]]){
			d[E[x][i]] = d[x] + 1;
			dfs(E[x][i], len + 1);
		}
	if(!ok)vis[x] = 0;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n - 1; i++){
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++)
		if(vis[i] && i != 1 && i != n){
			ans[++t].pos = i;
			ans[t].d = d[i];
		}
	sort(ans + 1, ans + t + 1, cmp);
	Q.push(1);
	sum_b = (cnt + 1) / 2;
	sum_w = cnt - sum_b;
	while(!Q.empty()){
		int p = Q.front();
		Q.pop();
		for(int i = 0; i < E[p].size(); i++){
			if(!vis[E[p][i]]){
				sum_b++;
				Q.push(E[p][i]);
				vis[E[p][i]] = 1;
			}
		}
	}
	while(!Q.empty())Q.pop();
	Q.push(n);
	while(!Q.empty()){
		int p = Q.front();
		Q.pop();
		for(int i = 0; i < E[p].size(); i++){
			if(!vis[E[p][i]]){
				sum_w++;
				Q.push(E[p][i]);
				vis[E[p][i]] = 1;
			}
		}
	}
	for(int i = 1; i <= (cnt + 1) / 2; i++){
		while(!Q.empty())Q.pop();
		Q.push(ans[i].pos);
		while(!Q.empty()){
			int p = Q.front();
			Q.pop();
			for(int i = 0; i < E[p].size(); i++){
				if(!vis[E[p][i]]){
					sum_b++;
					Q.push(E[p][i]);
					vis[E[p][i]] = 1;
				}
			}
		}

	}
	for(int i = (cnt + 1) / 2 + 1; i <= t; i++){
		while(!Q.empty())Q.pop();
		Q.push(ans[i].pos);
		while(!Q.empty()){
			int p = Q.front();
			Q.pop();
			for(int i = 0; i < E[p].size(); i++){
				if(!vis[E[p][i]]){
					sum_w++;
					Q.push(E[p][i]);
					vis[E[p][i]] = 1;
				}
			}
		}

	}
	if(sum_b > sum_w)printf("Fennec\n");
	else printf("Snuke\n");
}

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


int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  ll cnt = 0;
  ll snack = 0;
  while(true){
    snack += a.at(cnt);
    if( snack > x ){
      cout << cnt << endl;
      return 0;
    }
    if( snack == x ){
      cout << cnt+1 << endl;
      return 0;
    }
    if( cnt == a.size()-1 && snack < x ){
      cout << cnt << endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        
        int N=int.Parse(Console.ReadLine())+1;
        int[] t=new int[N];
        int[] x=new int[N];
        int[] y=new int[N];
        for(int i=1;i<N;i++) {
            int[] input2=Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            t[i]=input2[0];
            x[i]=input2[1];
            y[i]=input2[2];
        }
        t[0]=x[0]=y[0]=0;
        
        
        if(AbsCheck(N,t,x,y)=="Yes" && ParityCheck(N,t,x,y)=="Yes") {
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }
    }
    
    
    public static string AbsCheck(int N, int[] t, int[] x, int[] y) {    
        string flag="Yes";
        for(int i=1;i<N;i++) {
            int dt=t[i]-t[i-1];
            int dist=Math.Abs(x[i]-x[i-1])+Math.Abs(y[i]-y[i-1]);
            if(dt<dist) {
                flag="No";
                break;
            }
        }
        return flag;
    }
    
    public static string ParityCheck(int N, int[] t, int[] x, int[] y) {
        string flag="Yes";
        for(int i=1;i<N;i++) {
            int dt=t[i]-t[i-1];
            int dist=Math.Abs(x[i]-x[i-1])+Math.Abs(y[i]-y[i-1]);
            if(dt%2!=dist%2) {
                flag="No";
                break;
            }
        }
        return flag;
    }
}


Measured memory_bytes: 17324
#include<stdio.h>
int main(void)
{
	int n,x,i,s,z;
	scanf("%d",&n);
	s=100000;
	for(i=1;i<=n;i++){
		s=s*1.05;
	if(!(s%1000==0)){
		s=(s/1000)*1000+1000;
	}
	}
	printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 2e2+ 10, mod = 1e9 + 7;

void solve() {
	string s;
	cin >> s;
	int len = 0, ans = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'R') {
			len++;
		} else {
			len = 0;
		}
		ans = max(ans, len);
	}
	cout << ans;
}

int main() {
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		solve();
	}
}

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

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

	for(string input; cin >> input;) {
		int joi = 0, ioi = 0;
		for(int i = 0; i + 2 < input.size(); ++i) {
			string tmp = input.substr(i, 3);
			if(tmp == "JOI")
				++joi;

			else if(tmp == "IOI")
				++ioi;

		}

		cout << joi << "\n" << ioi << endl;
	}

	return EXIT_SUCCESS;
}

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


#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl


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

	long long int sum = 0, t , d;
	cin >> t;
	vector <int> vec;

	for (int i = 0; i < t; ++i)
	{
		cin >> d;
		vec.push_back(d);
	}
	for (int i = 0; i < t - 1; ++i)
	{
		for (int j = i + 1; j < t; ++j)
		{
			sum += vec[i] * vec[j];
		}
	}
	cout << sum << endl;

	return 0;
}

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

string rsp = "rsp";

int n, k;
int p[3];
string t;
int res;
int dp[3], ndp[3];

int main()
{
    cin >> n >> k;
    for (int i = 0; i < 3; i++)
        cin >> p[i];
    cin >> t;
    for (int i = 0; i < n && i < k; i++) {
        for (int j = 0; j < 3; j++)
            dp[j] = 0;
        for (int z = i; z < n; z += k) {
            int wh = rsp.find(t[z]);
            for (int a = 0; a < 3; a++)
                for (int b = 0; b < 3; b++) if (a != b) {
                    int cand = dp[a];
                    if ((b + 1) % 3 == wh)
                        cand += p[b];
                    ndp[b] = max(ndp[b], cand);
                }
            for (int j = 0; j < 3; j++) {
                dp[j] = ndp[j];
                ndp[j] = 0;
            }
        }
        int mx = 0;
        for (int j = 0; j < 3; j++)
            mx = max(mx, dp[j]);
        res += mx;
    }
    cout << res << endl;
    return 0;
}


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

vector<int>take;
int N, A, B, C;
int dfs(int depth, int a, int b, int c) {
	if (depth == N) {
		if (min({ a, b, c }) > 0)
			return abs(a - A) + abs(b - B) + abs(c - C) - 30;
		else 
			return (int)1e9;
	}
	int ret0 = dfs(depth + 1, a, b, c);
	int ret1 = dfs(depth + 1, a + take[depth], b, c) + 10;
	int ret2 = dfs(depth + 1, a, b + take[depth], c) + 10;
	int ret3 = dfs(depth + 1, a, b, c + take[depth]) + 10;
	return min({ ret0,ret1,ret2,ret3 });
}

int main() {
	cin >> N >> A >> B >> C;
	take.resize(N);
	for (int i = 0; i < N; i++)cin >> take[i];

	cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
M, D = map(int, input().split())

count = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d_str = str(d).zfill(2)
        d10 = int(d_str[0])
        d1 = int(d_str[1])
        if d1 >= 2 and d10 >= 2 and d1 * d10 == m:
            count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

int T;
int A,B,C,D;

int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
    return (x * y / gcd(x, y));
}

signed main() {
    IOS();
    cin>>T;
    rep(i,0,T){
        cin>>A>>B>>C>>D;
        if(A<B||B>D){
            cout<<"No"<<endl;
            continue;
        }
        int x=gcd(B,D);
        if(B-x+A%x<=C)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    ll x, y;
    cin >> x >> y;
    ll cnt = 0;
    while(x<=y)
    {
        cnt++;
        x *= 2;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1

parent = [-1]*N

def boss(n):
    if parent[n] < 0:
        return n
    else:
        b = boss(parent[n])
        parent[n] = b
        return b

P = [1]*N
S = (N*(N-1))//2

ans = [0] * M
ans[M-1] = S

for i in range(M-1):
    j = M-1-i
    bA = boss(A[j])
    bB = boss(B[j])
    if bA != bB:
        if P[bA] < P[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] += P[bB]
    ans[j-1] = S

for i in range(M):
    print(ans[i])

Measured memory_bytes: 17708
S = input()
T = input()

minnum = 1000
i = 0
while i <= len(S)-len(T):
  num = 0
  j = 0
  
  while j < len(T):
    if S[i+j] != T[j]:
      num += 1
    j += 1
  
  if minnum > num:
    minnum = num
  i += 1

print(minnum)

Measured memory_bytes: 9112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

#define LOCAL 0
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1& arg1, Args&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " /";
    __f(comma + 1, args...);
}

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 0) : 1; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 0) : 1; }
//template <class T> bool maxi
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 7;

int main() {
#if LOCAL
 //   freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif 
    ios_base::sync_with_stdio(0); cin.tie(0);
    LL a, b; cin >> a >> b;
    LL gcd = __gcd(a, b);
    LL ans = 1;
    for (LL i = 2; i * i <= gcd; ++i) if (gcd % i == 0) {
        ++ans;
        while (gcd % i == 0) gcd /= i;
    }
    if (gcd > 1) ++ans;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin >>n;
	vector<long long> h(n);
	for(long long i = 0; i < n; i++)
		cin >>h[i];
	vector<long long> dp(n, INT_MAX);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(long long i = 2; i < n; i++)
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	cout <<dp[n-1];
	return 0;
}


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

using namespace std;
using ll = long long;

const int mx = 1e5 + 9;
const ll MOD = 1e9 + 7;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll cnt[mx];

int main() {
    ll n, k; scanf("%lld %lld", &n, &k);

    ll ans = 0;
    for (ll x = k; x > 0; x--) {
        ll d = k / x;
        cnt[x] = modPow(d, n);

        ll y = 2 * x;
        while (y <= k) {
            cnt[x] = modSub(cnt[x], cnt[y]);
            y += x;
        }

        ans = modAdd(ans, modMul(cnt[x], x));
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 4568