akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var _N = int.Parse(Console.ReadLine());
        var _P = int.Parse(Console.ReadLine().Replace(" ",""));
        var _Q = int.Parse(Console.ReadLine().Replace(" ", ""));

        var baseStr = string.Empty;
        for(var i = 1; i <= _N; i++)
        {
            baseStr += i.ToString();
        }
        var total = new List<string>();
        CreateList(baseStr, total);
        var sorted = new SortedList<int, string>();
        foreach(var str in total)
        {
            sorted.Add(int.Parse(str), str);
        }
        var a = sorted.IndexOfKey(_P);
        var b = sorted.IndexOfKey(_Q);
        Console.WriteLine(Math.Abs(a - b));
    }

    static void CreateList(string baseStr, List<string> total, string create = "")
    {
        if(baseStr.Length == 1)
        {
            total.Add(create + baseStr);
        }
        else
        {
            for (var i = 0; i < baseStr.Length; i++)
            {
                var newCreate = create + baseStr[i];
                var newBaseStr = baseStr.Remove(i, 1);
                CreateList(newBaseStr, total, newCreate);
            }
        }
    }
}


Measured memory_bytes: 23384
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI i;
      string s,t;cin>>s>>t;
      LI ans=0;
      fo(i,0,s.length()){
        if(s[i]!=t[i]) ans++;
      }
      cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3816
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    Integer[] l=new Integer[n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    Arrays.sort(l);
    long ans=0;
    for(int i=0;i<n-2;i++){
      for(int j=i+1;j<n-1;j++){
        int ok=j;
        int ng=n;
        while(ng-ok>1){
          int gaze=ok+(ng-ok)/2;
          if(l[gaze]<l[i]+l[j]){
            ok=gaze;
          }else{
            ng=gaze;
          }
        }
        ans=ans+(ok-j);
      }
    }
    System.out.println(ans);
  }
}

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

int main(){
  int N; cin >> N;
  vector<int> a(N);
  int max =0;
  int med;
  int jud = 1000000000;
  
  rep(i,N){
    cin >> a[i];
    if(a[i] > max){
      max = a[i];
    }
  }
  
  rep(i,N){
    if(abs(a[i] *2 - max) < jud){
      if(a[i] != max){
        med = a[i];
        jud = abs(a[i] *2 - max);
      }
    }
  }
  
  cout << max << " " << med << endl;
}

  


Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int M = sc.nextInt();

        int[] arrH = new int[N];
        for(int i = 0; i < N; i++) {
            arrH[i] = sc.nextInt();
        }

        int tmpA = 0;
        int tmpB = 0;
        boolean[] arrB = new boolean[N];
        for(int j = 0; j < M; j++) {
            tmpA = sc.nextInt() - 1;
            tmpB = sc.nextInt() - 1;
            if(arrH[tmpA] > arrH[tmpB]) {
                arrB[tmpB] = true;
            } else if(arrH[tmpA] < arrH[tmpB]) {
                arrB[tmpA] = true;
            } else {
                arrB[tmpA] = true;
                arrB[tmpB] = true;
            }
        }
        int cnt = 0;
        for(int k = 0; k < N; k++) {
            if(arrB[k] == false) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 49572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    int ans=0;
    int beforemin = 1e9;
    for(int i=0; i<n; i++){
        ll p; 
        cin >> p;
        if(p <= beforemin){
            ans ++;
            beforemin = p;
        }
        else continue;
    }
    cout << ans << endl;
}

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

using namespace std;

int N,M,K;
map<int,int> mp;

void make(int n,int sum){
  if(N == n){
    if(sum-K <= 0){
      mp[1]++;
    }else{
      mp[sum-K]++;
    }
    return;
  }
  for(int i = 0 ; i < M ; i++){
    make(n+1,sum+i+1);
  }
}

int main(){
  while(cin >> N >> M >> K, N){
    mp.clear();
    make(0,0);
    double ans = 0;
    map<int,int>::iterator it;
    for(it = mp.begin() ; it != mp.end() ; ++it){
      ans += ((double)it->second/pow((double)M,N))*it->first;
    }
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1692
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;



int main() {
    uint64_t n, m;
    cin >> n >> m;
    std::vector<std::pair<uint64_t, uint64_t> > a(n);
    for (size_t i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    std::sort(a.begin(), a.end());
    uint64_t res = 0;
    size_t i = 0;
    while (m > 0) {
        uint64_t cur = std::min(a[i].second, m);
        m -= cur;
        res += cur * a[i].first;
        ++i;
    }
    cout << res << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int N;
  cin >> N;
  int H[N];
  rep(i,N)
    cin >> H[i];
  int res = 0;
  int a = 0;
  rep(i,N-1){
    if (H[i]>=H[i+1])
      a++;
    else{
      res = max(a,res);
      a = 0;
    }
  }
  cout << max(a,res) << endl;
}

Measured memory_bytes: 3988
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int k=nextInt();
		long sum=0;
		for(int i=1;i<=k;i++)
			for(int j=1;j<=k;j++)
				for(int l=1;l<=k;l++)
					sum+=gcd(gcd(i,j),l);
		out.println(sum);
	}
	int gcd(int a,int b){
	    if(a==0)
	        return b;
	    return gcd(b%a,a);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 32876
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,k,a;
int s[7],s1[7];
int num[12];
bool che(int n)
{
	while(n>=1)
	{
		int x=n%10;
		if(num[x]==1)
			return 0;
		n/=10;
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&a);
		num[a]=1;
	}
	while(1)
	{
		if(che(n))
		{
			printf("%d",n);
			return 0;
		}
		n++;
	}
	return 0;
}


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

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

void print_float(double x, int precision=15) {
    cout.setf(ios::fixed);
    cout.precision(precision);
    cout << x << '\n';
}

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

    int N, M, P;
    while (cin >> N >> M >> P) {
        double p = P/100.0;
        vector<vector<int>> adj(N, vector<int>(N));
        REP(i, M) {
            int u, v; cin >> u >> v; --u; --v;
            ++adj[u][v]; ++adj[v][u];
        }

        vector<int> outedge(1<<N);
        REP(S, 1<<N) {
            int k = 0;
            REP(u, N) if (S & (1<<u))
                REP(v, N) if (~S & (1<<v))
                    k += adj[u][v];
            outedge[S] = k;
        }

        int U = (1<<N)-1;
        vector<double> dp(1<<N);
        REP(S, 1<<N) {
            double q = 0;
            for (int T = (S-1)&S; T; T = (T-1)&S) {
                if ((T&-T) != (S&-S)) continue;
                int k = (outedge[T] + outedge[S^T] - outedge[U^S]) / 2;
                q += dp[T] * pow(p, k);
            }
            dp[S] = 1 - q;
        }
        print_float(dp[U]);
    }
}

Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int p, q;
		int ans[];
		int temp;
		int a[];
		int index;
		boolean flag;

		while (sc.hasNext()) {
			p = sc.nextInt();
			q = sc.nextInt();
			ans = new int[100];
			a = new int[q];
			flag = true;

			ans[0] = p / q;
			temp = p % q;
			a[temp] = 1;
			index = 1;
			while (true) {
				if (temp == 0) {
					break;
				}
				temp *= 10;
				ans[index++] = temp / q;
				temp %= q;
				if (0 < a[temp]) {
					flag = false;
					break;
				}
				a[temp] = index;
			}
			for (int i = 1; i < index; i++) {
				System.out.print(ans[i]);
			}
			System.out.println();
			if (!flag) {
				for (int i = 1; i < index; i++) {
					if (i == a[temp]) {
						for (int j = i; j < index; j++) {
							System.out.print("^");
						}
						break;
					} else {
						System.out.print(" ");
					}
				}
				System.out.println();
			}
		}
	}
}

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

int main()
{
        char a; cin >> a;
        if (isupper(a)) {
                cout << "A" << endl;
        }
        else {
                cout << "a" << endl;
        }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 2019;

struct mcmf{
struct edg{ int pos, cap, rev, cost; };
vector<edg> gph[MAXN];
void clear(){
	for(int i=0; i<MAXN; i++) gph[i].clear();
}
void add_edge(int s, int e, int x, int c){
	gph[s].push_back({e, x, (int)gph[e].size(), -c});
	gph[e].push_back({s, 0, (int)gph[s].size()-1, c});
}
lint dist[MAXN];
int pa[MAXN], pe[MAXN];
bool inque[MAXN];
bool spfa(int src, int sink){
	memset(dist, 0x3f, sizeof(dist));
	memset(inque, 0, sizeof(inque));
	queue<int> que;
	dist[src] = 0;
	inque[src] = 1;
	que.push(src);
	bool ok = 0;
	while(!que.empty()){
		int x = que.front();
		que.pop();
		if(x == sink) ok = 1;
		inque[x] = 0;
		for(int i=0; i<gph[x].size(); i++){
			edg e = gph[x][i];
			if(e.cap > 0 && dist[e.pos] > dist[x] + e.cost){
				dist[e.pos] = dist[x] + e.cost;
				pa[e.pos] = x;
				pe[e.pos] = i;
				if(!inque[e.pos]){
					inque[e.pos] = 1;
					que.push(e.pos);
				}
			}
		}
	}
	return ok;
}
lint match(int src, int sink){
	lint ret = 0;
	while(spfa(src, sink)){
		int cap = 1e9;
		for(int pos = sink; pos != src; pos = pa[pos]){
			cap = min(cap, gph[pa[pos]][pe[pos]].cap);
		}
		ret += dist[sink] * cap;
		for(int pos = sink; pos != src; pos = pa[pos]){
			int rev = gph[pa[pos]][pe[pos]].rev;
			gph[pa[pos]][pe[pos]].cap -= cap;
			gph[pos][rev].cap += cap;
		}
	}
	return ret;
}
}mcmf;

int n;

struct foo{
	int x, y, z, t;
}a[MAXN];

int main(){
	cin >> n;
	for(int i=1; i<=n+n; i++) cin >> a[i].x >> a[i].y >> a[i].z, a[i].t = (i >= n);
	for(int i=1; i<=n; i++){
		mcmf.add_edge(i, 2*n+1, a[i].z, a[i].x + a[i].y);
		mcmf.add_edge(i, 2*n+2, a[i].z, a[i].x - a[i].y);
		mcmf.add_edge(i, 2*n+3, a[i].z, -a[i].x + a[i].y);
		mcmf.add_edge(i, 2*n+4, a[i].z, -a[i].x - a[i].y);
		mcmf.add_edge(2*n+5, i+n, a[i+n].z, -a[i+n].x - a[i+n].y);
		mcmf.add_edge(2*n+6, i+n, a[i+n].z, -a[i+n].x + a[i+n].y);
		mcmf.add_edge(2*n+7, i+n, a[i+n].z, a[i+n].x - a[i+n].y);
		mcmf.add_edge(2*n+8, i+n, a[i+n].z, a[i+n].x + a[i+n].y);
		mcmf.add_edge(0, i, a[i].z, 0);
		mcmf.add_edge(i + n, 2*n+9, a[i+n].z, 0);
	}
	for(int i=1; i<=4; i++) mcmf.add_edge(2*n+i, 2*n+i+4, 10000, 0);
	cout << -mcmf.match(0, 2*n+9) << endl;
}


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

char a[1000001];
char w[] = "JOI";
int k=0, l[3];

int main() {
  
  cin>>a;
  
  for(char* c=a;*c!='\0';) {
    for(int i=0;i<3;++i) {
      l[i]=0;
      while(*c!='\0'&&*c==w[i]) {
        ++l[i];
        ++c;
      }
    }
    if(l[0]>=l[1]&&l[2]>=l[1])k=(k<l[1]?l[1]:k);
  }
  
  cout<<k<<endl;
  
  return 0;
}

Measured memory_bytes: 2120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = IO.GetInt();
            var p = IO.GetIntList();
            var n = 0;
            var ans = "YES";
            for (int i = 0; i < N; i++)
            {
                if (p[i] != i + 1) n++;
                if (n > 2) {ans = "NO"; break; }
            }

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct BIT{
    // [1,n]
    int n; vector<ll> bit;
    // 初期化
    BIT(){}
    BIT(int _n){
        n = _n;
        bit = vector<ll>(n+1,0);
    }
    // sum of [1,i]
    ll sum(int i){
        ll s = 0;
        while(i>0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // add x in i-th element
    void add(int i, ll x){
        while(i<=n){
            bit[i] += x;
            i += i & -i;
        }
    }
    // [l,r]
    ll sum(int l, int r){
        return sum(r)-sum(l-1);
    }
};

const int M = 2020;
const int N = 3333;

BIT row[N],col[N];

int main(){
    int h,w,k;
    cin >>h >>w >>k;

    vector<string> s(h);
    rep(i,h) cin >>s[i];

    vector<vector<pair<int,int>>> v(h+w-1);
    rep(i,h)rep(j,w) v[i+j].pb({i, j});

    rep(i,N){
        row[i] = BIT(N);
        col[i] = BIT(N);
    }

    auto calc = [&](int y, int x, ll val){
        y -= M;
        x -= M;
        if(s[y][x] == '#') return 0;
        return (int)!val;
    };

    ll sum = 0;
    int pi = M, pj = M;
    vector<vector<int>> dp(N,vector<int>(N));
    rep(i,h+w-1){
        sort(all(v[i]));
        int V = v[i].size();

        int si = v[i][0].fi+M, sj = v[i][0].se+M;
        if(i>0){
            int ti = pi-k, tj = pj;
            while(ti<=pi){
                sum -= dp[ti][tj];
                ++ti;
                --tj;
            }
            sum += dp[pi][pj];

            if(pi == si) sum += col[sj].sum(si-k,si-1);
            else sum += row[si].sum(sj-k,sj-1);
        }

        dp[si][sj] = calc(si, sj, sum);
        ll tsum = sum;
        for(int j=1; j<V; ++j){
            int ti = v[i][j].fi+M, tj = v[i][j].se+M;
            tsum -= col[tj+1].sum(ti-k-1, ti-1-1);
            tsum += row[ti].sum(tj-k, tj-1);
            dp[ti][tj] = calc(ti, tj, tsum);
        }

        rep(j,V){
            int ti = v[i][j].fi+M, tj = v[i][j].se+M;
            row[ti].add(tj, dp[ti][tj]);
            col[tj].add(ti, dp[ti][tj]);
        }

        pi = si;
        pj = sj;
    }

    cout << (dp[M+h-1][M+w-1]?"Cacao":"Chieno") << endl;
    return 0;
}



Measured memory_bytes: 231996
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	string s;
	cin >> s;

	vector <int> r;
	vector <int> w;
	for (int ii = 0; ii < N; ++ii){
		if (s[ii] == 'R'){
			r.push_back(ii);
		} else {
			w.push_back(ii);			
		}
	}

	if ((r.size()==0) || (w.size()==0)){
		cout << 0 << "\n";
		return 0;
	}

	int ans = 0;
	int widx = 0;
	int ridx = r.size()-1;
	while(true){
		int left = w[widx];
		int right = r[ridx];
		if (left >= right){
			break;
		}
		ans++;

		widx++;
		ridx--;
		if ( (widx >= w.size()) || (ridx < 0) ){
			break;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4696
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



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

size_t n;
vector<int> a;

bool f(size_t i, int m){
  if(m == 0){
    return true;
  }
  if(i == n-1){
    return m == a[i];
  }
  return f(i+1, m) || f(i+1, m-a[i]);
}


int main(int argc, char *argv[]){
  cin >> n;
  a.resize(n);
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
  }

  size_t q;
  cin >> q;
  for (size_t i = 0; i < q; i++) {
    int m;
    cin >> m;
    if(f(0, m)){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
    
  }

  

  
  
  return 0;
}

Measured memory_bytes: 1200
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
z=-1
p=-1
mod=10**9+7
ans=1
for i in range(n):
    if a[i]==0:
        z=i
    elif a[i]>0:
        p=i
        break
a_abs=sorted(a,key=abs,reverse=True)
if (p==-1 and k%2==1) or n==k:
    for i in range(k):
        ans*=a[n-1-i]
        ans%=mod
    print(ans%mod)
    exit()
else:
    lp=-1
    lm=-1
    f=0
    for i in range(k):
        if a_abs[i]>=0:
            lp=i
        else:
            lm=i
            f+=1
    if f%2==0:
        for i in range(k):
          ans*=a_abs[i]
          ans%=mod
        print(ans)
    else:
        fp=-1
        fm=-1
        check_p=False
        check_m=False
        for i in range(k,n):
            if not check_p and a_abs[i]>=0:
                fp=i
                check_p=True
            elif not check_m and a_abs[i]<0:
                fm=i
                check_m=True
            if check_m and check_p:
                break
        if lp!=-1:
            if fp==-1:
              for i in range(k):
                if i==lp:
                  continue
                ans*=a_abs[i]
                ans%=mod
              ans*=a_abs[fm]
              ans%=mod
            elif fm==-1:
              for i in range(k):
                if i==lm:
                  continue
                ans*=a_abs[i]
                ans%=mod
              ans*=a_abs[fp]
              ans%=mod

            else:
                if a_abs[fm]*a_abs[lm]>=a_abs[fp]*a_abs[lp]:
                  for i in range(k):
                    if i==lp:
                      continue
                    ans*=a_abs[i]
                    ans%=mod
                  ans*=a_abs[fm]
                  ans%=mod
                else:
                  for i in range(k):
                    if i==lm:
                      continue
               	    ans*=a_abs[i]
                    ans%=mod
                  ans*=a_abs[fp]
                  ans%=mod
        else:
          for i in range(k):
            if i==lm:
              continue
            ans*=a_abs[i]
            ans%=mod
          ans*=a_abs[fp]
          ans%=mod
        print(ans%mod)

Measured memory_bytes: 116784
"""
f(n) , f(n+1)の値を求める
f(3456)を求める時

f(0) = 0, f(1) = 1 とする

f(3) = min
(
    f(0) + 3
    f(1) + 7
)
f(4) = min
(
    f(0) + 4
    f(1) + 6
)

f(34) = min
(
    f(3) + 4
    f(4) + 6
)
f(35) = min
(
    f(3) + 5
    f(4) + 5
)

f(345) = min
(
    f(34) + 5
    f(35) + 5
)
f(346) = min
(
    f(34) + 4
    f(35) + 6
)
f(3456) = min
(
    f(345) + 6
    f(346) + 4
)
"""
N = input()
n = [int(i) for i in N]

f0 = 0
f1 = 1

dp = f0, f1

# 桁DP
for i in n:
    # 支払い枚数を考える
    fn_0 = min(dp[0] + i, dp[1] + 10 - i)
    fn_1 = min(dp[0] + (i+1), dp[1] + 10 - (i+1))
    dp = fn_0, fn_1

print(dp[0])


Measured memory_bytes: 116516
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	int H[N]; vector<int> g[N];
	rep(i,0,N) cin>>H[i];
	int a,b;
	rep(i,0,M){
		cin>>a>>b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = 0;
	rep(i,0,N){
		bool flag = true;
		for(int j:g[i])if(H[i] <= H[j]) flag = false;
		if(flag) ans++;
	}cout<<ans<<endl;
}

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int N, M, X;
    cin >> N>>M>>X;

    vector<int> C(N+1,0);
    vector<vector<int>> A(N+1,vector<int>(M+1,0));
    rep(i,N){
        rep(j,M+1){
            if(j==0){
                cin>>C.at(i+1);
            }else{
                cin>>A.at(i+1).at(j);
            }
        }
    }

    const int bitM = M;
    int mincost = INT_MAX;
    int seikou_flag=0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);
    // ビット列を出力
    //cout << s << endl;
    //cout<<s[0]<<endl;
    vector<int> understand(M+1,0);
    int cost = 0;

    for(int i =1;i<N+1;i++){
        if(s[i-1]==0){
            continue;
        }
        cost += C.at(i);
        for(int j=1;j<M+1;j++){
            understand.at(j) += A.at(i).at(j);
        }
    }
    int flag=1;
    for(int i =1;i<M+1;i++){
        if(understand.at(i)<X){
            flag=0;
        }
    }
    if(flag==1 && mincost>cost){
        seikou_flag=1;
        mincost=cost;
    }
  }
  if(seikou_flag==1){
      cout<<mincost<<endl;
  }else{
      cout<<-1<<endl;
  }


}

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

struct Card { // struct???????????????????????¢????????????????????£???public????????§??\??????????´???§??????
    char suit;// class??§??£?¨?????????´??????public:?????????
    int value;// value?????????????????§??????????????°char??§?????¨????????£?¨????????????????
};

void bubble(struct Card A[], int N){ // N????????????????????????????????????
    for ( int i = 0; i < N; i++ ){   // i????????????????????????????????????
        for ( int j = N - 1; j >= i+1; j-- ){ // ????°???????i+1?????§??????????????????
            if ( A[j].value < A[j-1].value ){ // ?????£???????????????????????§???????????°??\?????????
                Card t = A[j]; // ???????????????????????±???t?????????
                A[j] = A[j-1]; // ?????£????????????????????±???????????????????????´???????????????
                A[j-1] = t; // ?????????????????????????????±????????£?????????
            }
        }
    }
}

void selection(struct Card A[], int N){ // N?????????????????????????????????
    for ( int i = 0; i < N; i++ ){ // ????????????????°??????§?????????????????????
        int minj = i; // ????°?????????????????????????????¨????
        for ( int j = i; j < N; j++ ){ // ?????¨??????????????\????????¢?´¢
            if ( A[j].value < A[minj].value ) minj = j; // ????°???????????????????????????????????????°????¨????
        }
        Card t = A[i]; A[i] = A[minj]; A[minj] = t; // ?????¨???????????????????°??????????????????¨??\????????????
    }
}

void print(struct Card A[], int N){ // N???????????????????????±?????????
    for ( int i = 0; i < N; i++ ){
        if (i > 0) cout << " "; // ?????????1?????\??????????????????????????????
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

// ????????????????????¨?????\????????????????????????????????????????????????
// (2???????????????????????????????????????????????????????????????)
// (C1, C2????????????????????????????????????????????????)
bool isStableSort(struct Card C1[], struct Card C2[], int N){
    for ( int i = 0; i < N; i++ ){
        if ( C1[i].suit != C2[i].suit ) return false;
    }
    return true;
}

int main(void){
    Card C1[100], C2[100];
    int N;
    char ch;
    
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        cin >> C1[i].suit >> C1[i].value; // C1?????????????????§
        C2[i] = C1[i];                    // C2????????????
    }
    
    bubble(C1, N);
    selection(C2, N);
    
    print(C1, N);
    cout << "Stable" << endl; // ????????????????????????????????????
    print(C2, N);
    if ( isStableSort(C1, C2, N) ) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}

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

int main(){
    int d, t, s; cin >> d >> t >> s;
    if(d <= t*s)
        cout << "Yes" << endl;
    else
        cout << "No" <<endl;

    return 0;
}

Measured memory_bytes: 3616
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    ll a;
    string b;
    cin >> a >> b;
    ll ans = 0;
    ans += a * (b[0] - '0') * 100;
    ans += a * (b[2] - '0') * 10;
    ans += a * (b[3] - '0');
    cout << ans / 100 << endl;
    return 0;
}

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

const int N = 3e2 + 6, MOD = 998244353;
int n, m;
int Arr[N][N];

void swap_row (int l, int r) {
	for (int i = 0; i < m; i++)
		swap(Arr[l][i], Arr[r][i]);
}

void xor_row (int l, int r) {
	for (int i = 0; i < m; i++)
		Arr[r][i] ^= Arr[l][i];
}

int _sub (int a, int b) {
	int c = a - b;
	if (c < 0)
		c += MOD;
	return c;
}

int _mul (int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

int _pow (int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1)
			res = _mul(res, a);
		a = _mul(a, a);
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> Arr[i][j];

	int pointer = 0;
	for (int i = 0; i < m; i++) {
		int ind = -1;
		for (int j = pointer; j < n; j++)
			if (Arr[j][i])
				ind = j;

		if (ind == -1)
			continue;

		swap_row(pointer, ind);
		for (int j = pointer + 1; j < n; j++)
			if (Arr[j][i])
				xor_row(pointer, j);
		pointer++;
	}

	int num = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (Arr[i][j]) {
				num++;
				break;
			}

	if (!num) {
		cout << "0\n";
		return 0;
	}

	int res = _mul(_sub(_pow(2, num), 1), _pow(2, n - num));
	cout << _mul(res, _pow(2, m - 1)) << "\n";
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;

    cin >> n >> k;

    ll h[n];
    ll ans = LLONG_MAX;

    int i, len = n - k + 1;

    rep(i, n) cin >> h[i];

    sort(h, h + n);

    rep(i, len) Min(ans, h[i + k - 1] - h[i]);

    Out(ans);

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N];
int sum[N],f[N];
long long ans;
int main() {
	scanf("%s",s+1);
	int len=strlen(s+1);
	for (int i=len;i>=1;i--)
		 if (s[i]=='A') {
		 	if (i<len) {
		 		if (s[i+1]=='A') sum[i]=sum[i+1],ans+=(long long)sum[i]; 
		 		else if (s[i+1]=='B') sum[i]=sum[i+f[i+1]*2+1]+f[i+1],ans+=(long long)sum[i];
		 	}
		 }
		 else 
		 if (i+1<=len)	
		 if (s[i]=='B'&&s[i+1]=='C')
		 {
		 	f[i]=f[i+2]+1;
		 }
	printf("%lld\n",ans);	 
} 

Measured memory_bytes: 2048
#include <stdio.h>          // printf(), scanf()
#define MAX_N 1000000
#define MAX_G 1000

int count;
int G[MAX_G];
int ix;

void
insertionSort(int a[MAX_N], int n, int g)
{
	int v;
	int i, j;

	for (i = g; i < n; ++i)
	{
		v = a[i];
		for (j = i - g; j >= 0 && v < a[j]; j -= g)
		{
			a[j + g] = a[j];
			count++;
		}

		a[j + g] = v;
	}
}

void
shellsort(int a[MAX_N], int n)
{
	int h;
	int i;

	ix = 0;
	for (h = 1; h <= n;)
	{
		G[ix++] = h;
		h = 3 * h + 1;
	}

	for (i = ix - 1; i >= 0; --i)
		insertionSort(a, n, G[i]);
}

int
main(int argc, char** argv)
{
	int a[MAX_N];
	int n;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	count = 0;
	shellsort(a, n);

	printf("%d\n", ix);
	for (i = ix - 1; i >= 0; --i)
		printf("%d%c", G[i], (i != 0) ? ' ' : '\n');

	printf("%d\n", count);
	for (i = 0; i < n; ++i)
		printf("%d\n", a[i]);

	return 0;
}

Measured memory_bytes: 4508
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	char c;
	cin >>c;
	if(c >='A' && c<='Z')
		cout << "A" << endl;
	else
		cout << "a" << endl;
	return 0;	
}


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

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


  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
    cout << "YES" <<endl;
  } else {
    cout << "NO" <<endl;
  }



  return 0;
}

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

int main(){

  std::vector<string> word;
  std::vector<int> count;
  string now;
  int num=0,most=0;
  bool aaa;

  while(cin >> now){
    aaa = true;
    for(int i=0;i<num;i++)
      if(word[i] == now){
	count[i]++;
	aaa = false;
      }

    if(aaa){
      word.push_back(now);
      count.push_back(1);
      num = word.size();
    }
  }

  now = " ";

  for(int i=0,mmm=0,nnn=0;i<num;i++){
    if(mmm < count[i]){
      mmm = count[i];
      most = i;
    }
    if(now.size() < word[i].size()){
      now = word[i];
    }
  }

  cout << word[most] << ' ' << now << endl;

  return 0;
}

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

using namespace std;
long long b, a;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>b>>a;
 if(b<=((b*2)+a)/4)cout<<((b*2)+a)/4<<endl;
    else cout<<a/2<<endl;
 
 
 
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;


int main() {

	cin.tie(0);

	lint x;
	cin >> x;

	if (x % 11 > 6)cout << x / 11 * 2 + 2;
	else if (x % 11 != 0)cout << x / 11 * 2 + 1;
	else cout << x / 11 * 2;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;


const int max_N = 1005;
const int max_V = max_N*max_N;
vi to[max_V];
int id[max_N][max_N];

int toId(int i,int j){
    if(i > j) swap(i,j);
    return id[i][j];
}

bool visited[max_V];
bool calc[max_V];
int dp[max_V];

int dfs(int v){
    if(visited[v]){
        if(!calc[v]) return -1;
        return dp[v];
    }
    visited[v] = true;
    dp[v] = 1;
    
    for (int u : to[v]) {
        int res = dfs(u);
        if(res == -1) return -1;
        dp[v] = max(dp[v],dfs(u)+1);
    }
    calc[v] = true;
    return dp[v];
    
    
}



int main()
{
    int N;
    cin >> N;
    
    ve<vi> A(N,vi(N-1));
    rep(i,N) rep(j,N-1){ cin >> A[i][j];A[i][j]--;}
    int V = 0;
    rep(i,N) rep(j,N) {
        if(i<j) id[i][j] = V++;
    }
    rep(i,N){
        rep(j,N-1){
            A[i][j] = toId(i,A[i][j]);
        }
        rep(j,N-2){
            to[A[i][j+1]].pb(A[i][j]);
        }
    }
    
    int ans = 0;
    rep(i,V){
        int res = dfs(i);
        if(res == -1){
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans,res);
    }
    
    
    out(ans);
    

    return 0;
}


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

// Macros
#define F  first
#define S  second
#define PB push_back
#define MP make_pair
#define ALL(container)   container.begin(),container.end()
#define RALL(container)  container.rbegin(),container.rend()
#define MAKE_UNIQUE(vec) vec.erase(unique(ALL(vec)),vec.end())

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Helpers
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
// vec.assign() GOOD; vec.resize() BAD
// comparator, <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef VOID_d1097589d5c8e3676b0fd9e08281f3d4
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(__attribute__((unused)) istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


void solve(){
	int x, y;
	cin >> x >> y;

	// c + t = x
	// 2c + 4t = y => c + 2t = y/2
	// t = y/2 - x

	if(y & 1){
		cout << "No\n";
		return;
	}

	int t = y/2 - x;
	int c = x - t;
	if(t < 0 or c < 0){
		cout << "No\n";
		return;
	}

	cout << "Yes\n";
}

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

	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3652
#include <iostream>
#include <climits>
using namespace std;
const int NM_MAX = 50;
int main (void) {
    int N;
    int M;
    int a[NM_MAX], b[NM_MAX];
    int c[NM_MAX], d[NM_MAX];

    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < M; i++) cin >> c[i] >> d[i];

    for (int i = 0; i < N; i++) {
        int mi = INT_MAX;
        int mij;
        for (int j = 0; j < M; j++) {
            int distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (distance < mi) {
                mi = distance;
                mij = j + 1;
            }
        }
        cout << mij << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int h1, m1, h2, m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int limit = (60*h2+m2)-(60*h1+m1);
  cout<<limit-k;



}


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

int main()
{
    string a,b;
    string s;
    cin >> a >> b;
    int l1 = a.size();
    int l2 = b.size();
    for(int i=0;i<l1;i++)
    {
        if(a[i]=='?' or a[i]==b[0])
        {
            string t = a;
            for(int j=0;j<i;j++)
            {
                if(t[j]=='?')   t[j]='a';
            }
            bool flag =true;
            for(int j=0;j<l2;j++)
            {
                if(a[j+i]==b[j])    continue;
                else if(a[j+i]=='?')    t[j+i]=b[j];
                else flag =false;
            }
            if(flag==true)
            {
                for(int j = i+l2 ; j<l1;j++)    if(t[j]=='?')   t[j]='a';
               // cout << t << '\n';
                s=t;
            }
        }
    }

    if(s.size()==0)
    cout << "UNRESTORABLE\n";
    else    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
  
int const INF = 1<<29;
  
struct tree; typedef tree* tree_ptr;
  
struct tree {
  tree_ptr lch, rch;
  int num;
  tree()
    : lch(NULL), rch(NULL), num(-INF) { }
};
  
void consume(string& S, char expected) {
  if(S[0] == expected) {
    S = S.substr(1);
    return;
  }
  cout << S << ", " << expected << endl;
  assert(0);
}
  
bool consume_if(string& S, char expected) {
  if(S[0] == expected) {
    consume(S, expected);
    return true;
  }
  else {
    return false;
  }
}
  
int read_num(string& S) {
  stringstream ss(S);
  int x; ss >> x;
  ss >> S;
  return x;
}
  
void make_tree(string& S, tree_ptr curr) {
  if(consume_if(S, '(')) {
    tree_ptr lch = new(tree);
    curr->lch = lch;
    make_tree(S, lch);
    consume(S, ')');
     
    consume(S, '[');
    curr->num = read_num(S);
    consume(S, ']');
     
    consume(S, '(');
    tree_ptr rch = new(tree);
    curr->rch = rch;
    make_tree(S, rch);
    consume(S, ')');
    return;
  }
}
  
void dfs(tree* ptr1, tree* ptr2) {
  if(ptr1->num == -INF || ptr2->num == -INF) { return; }
   
  if(ptr1->lch && ptr2->lch) {
    cout << "(";
    dfs(ptr1->lch, ptr2->lch);
    cout << ")";
  }
  cout << "[" << (ptr1->num + ptr2->num) << "]";
  if(ptr1->rch && ptr2->rch) {
    cout << "(";
    dfs(ptr1->rch, ptr2->rch);
    cout << ")";
  }
}
  
int main() {
  
  string a; cin >> a;
  string b; cin >> b;
   
  tree_ptr atree = new(tree);
  tree_ptr btree = new(tree);
   
  make_tree(a, atree);
  make_tree(b, btree);
  
  dfs(atree, btree);
  cout << endl;
   
  return 0;
}

Measured memory_bytes: 3256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    string S;
    cin >> S;

    int ret0 = 0;
    REP(i, S.size())
    {
        if (i % 2 == 0 && S[i] != '0')
        {
            ret0++;
        }
        else if (i % 2 == 1 && S[i] != '1')
        {
            ret0++;
        }
    }

    int ret1 = 0;
    REP(i, S.size())
    {
        if (i % 2 == 0 && S[i] != '1')
        {
            ret1++;
        }
        else if (i % 2 == 1 && S[i] != '0')
        {
            ret1++;
        }
    }

    cout << min(ret0, ret1) << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 512
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    K = int(input())
    ans = 0
    # a,a,a
    ans += sum(range(1,K+1))

    # a,b,b
    tmp = 0
    memo = defaultdict(int)
    for a in range(1,K+1):
        for b in range(a+1,K+1):
            memo[(a,b)] = memo[(b,a)] = gcd(a,b)
            tmp += memo[(a,b)]
    ans += tmp * 6

    # a,b,c
    tmp = 0
    for a in range(1,K+1):
        for b in range(a+1,K+1):
            for c in range(b+1,K+1):
                ab = memo[(a,b)] if memo[(a,b)] else gcd(a,b)
                memo[(a,b)] = memo[(b,a)] = ab
                abc = memo[(ab,c)] if memo[(ab,c)] else gcd(ab,c)
                memo[(ab,c)] = memo[(c,ab)] = abc
                tmp += abc
    ans += tmp * 6

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14392
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std; using ll=long long; const int INF=1e9; using P=pair<int,int>;

int main() {
  int n; cin>>n;
  int a[100001]; fill(a,a+100001,0);
  for(int i=0;i<n;i++) {
    int b; cin>>b; a[b]++;
  }

  int an = 0;
  for(int i=1;i<100000;i++) {
    an = max(an, a[i-1] + a[i] + a[i+1]);
  }
  cout<<an<<endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> count(m, 0);
  int ans = 0;
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int s;
      cin >> s;
      s--;
      a[s] |= (1<<i);
    }
  }
  int p = 0;
  rep(i,m) {
    int x;
    cin >> x;
    p |= (x<<i);
  }
  rep(i,1<<n) {
    int t = 0;
    rep(j,n) if(i>>j&1) t ^= a[j];
    if(t==p) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())

if a==1 and b==0 and c==0:
    print("Close")
    
elif a==0 and b==1 and c==0:
    print("Close")
    
elif a==1 and b==1 and c==0:
    print("Open") 
    
    
elif a==0 and b==0 and c==1:
    print("Open")
    
elif a==0 and b==0 and c==0:
    print("Close")



Measured memory_bytes: 5592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	int N; cin >> N;
	vector<string> S(N);
	vector<int> sum(5);
	rep(i,N){
		cin >> S[i];
		if(S[i][0] == 'M') sum[0]++;
		if(S[i][0] == 'A') sum[1]++;
		if(S[i][0] == 'R') sum[2]++;
		if(S[i][0] == 'C') sum[3]++;
		if(S[i][0] == 'H') sum[4]++;
	}
	ll ans = 0;
	rep(i,3){
		repr(j,i+1,4){
				repr(k,j+1,5){
						ans += (ll)sum[i]*sum[j]*sum[k];
				}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 6144