akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.ReadInt;
            var s = ReadLine();

            var x = 0;
            var ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'I') x++;
                else if (s[i] == 'D') x--;
                ans = Max(x, ans);
            }
            WriteLine(ans);
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 11092
import sys

x = int(input())
for a in range(1,1000):
    a_5 = a**5
    if a_5 > x:
        b = 1
        s = x+1
        while s > x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b += 1
            
    elif a_5 < x:
        b = -1
        s = x-1
        while s < x:
            s = a_5 - b**5
            if s == x:
                print(a, b)
                sys.exit()
            b -= 1
    else:
        print(a,0)
        sys.exit()


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    char x;cin>>x;
    cout<<++x<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[][][] B = new int[4][3][10];

        int N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            int b = Integer.parseInt(sc.next());
            int f = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            int v = Integer.parseInt(sc.next());

            B[b - 1][f - 1][r - 1] += v;
        }

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    System.out.printf(" %d", B[i][j][k]);
                }
                System.out.println();
            }
            if (i != 3) System.out.println("####################");
        }
    }
}

Measured memory_bytes: 29980
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[100+5];
 
 int main()
 {
   int N;
   cin>>N;
   int count=0;
   for(int i=0;i<N;i++) cin>>arr[i];
   for(int i=0;i<N;i++)
   {
     for(int j=N-1;j>i;j--)
     {
       if(arr[j]<arr[j-1])
       {
         count++;
         int temp=arr[j];
         arr[j]=arr[j-1];
         arr[j-1]=temp;                   
       }          
     }        
   }
   for(int i=0;i<N-1;i++) cout<<arr[i]<<" ";
   cout<<arr[N-1]<<endl;
   cout<<count<<endl;
   //while(1);
   return 0;
 }
 
 
 

Measured memory_bytes: 3084
'use strict';
(function(stdin) {
  var lines = stdin.toString().split('\n');
  var Command = function(str) {
    this.text = str;
    this.buf = [];
  };
  Command.prototype.exec = function(command,index,option) {
    var self = this;
    var commands = {
      print : function(index) {
        self.buf.push(self.text.slice(index[0],index[1] + 1));
      },
      reverse : function(index) {
        var chars = self.text.split('');
        var reverse = chars.slice(index[0],index[1] + 1).reverse().join('');
        this.replace(index,reverse);
      },
      replace : function(index,option) {
        var chars = self.text.split('');
        chars.splice(index[0],index[1] - index[0] + 1,option);
        self.text = chars.join('');
      }
    };
    commands[command](index,option);
  }
  Command.prototype.toString = function(){
    return this.buf.join('\n');
  };
  var result = (function(source ,commands) {
    var command = new Command(source);
    commands.forEach(function(v) {
      command.exec(v[0],v.slice(1,3).map(Number),v[3]);
    });
    return command.toString();
  }(lines.shift(),lines.slice(0,lines.shift()).map(function(v){return v.split(' ')})
    ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 9496
open Printf
open Scanf

module Pqueue = struct

  type 'a t = {mutable cnt : int; hp : 'a array; cmp : 'a -> 'a -> int}
                
  let create n v f = {cnt = 0; hp = Array.make n v; cmp = f}

  let push k pq =
    let swap i j =
      let t = pq.hp.(i) in
      pq.hp.(i) <- pq.hp.(j);
      pq.hp.(j) <- t in
    let rec iter i =
      let p = i / 2 in
      if p = 0 || pq.cmp pq.hp.(p) pq.hp.(i) >= 0 then ()
      else (swap p i; iter p)
    in
    pq.cnt <- pq.cnt + 1;
    pq.hp.(pq.cnt) <- k;
    iter (pq.cnt)

  let max_heapify pq i =
    let swap i j =
      let t = pq.hp.(i) in
      pq.hp.(i) <- pq.hp.(j);
      pq.hp.(j) <- t in
    let rec iter i =
      let l = 2 * i in
      let r = 2 * i + 1 in
      let mi =
        let ti = if l <= pq.cnt && pq.cmp pq.hp.(l) pq.hp.(i) > 0 then l else i in
        if r <= pq.cnt && pq.cmp pq.hp.(r) pq.hp.(ti) > 0 then r else ti in
      if mi <> i then
        begin
          swap mi i;
          iter mi
        end
    in
    iter i
  
  let pop pq =
    let ret = pq.hp.(1) in
    pq.hp.(1) <- pq.hp.(pq.cnt);
    pq.cnt <- pq.cnt - 1;
    max_heapify pq 1;
    ret

  let top pq = pq.hp.(1)
                    
  let is_empty pq = pq.cnt = 0
                               
end

let prim g n =
  let pq = Pqueue.create (n*n) (0, 0) (fun x y -> compare (fst y) (fst x)) in
  let vt = Array.make n true in
  let rec loop d =
    if Pqueue.is_empty pq then d
    else let w, u = Pqueue.pop pq in
         if vt.(u) then begin
             vt.(u) <- false;
             Array.iteri (fun v w' ->
                          if w' >= 0 then
                            Pqueue.push (w', v) pq
                         ) g.(u);
             loop (d+w)
           end
         else loop d
  in
  Pqueue.push (0,0) pq;
  loop 0

let id x = x
             
let () =
  let n = scanf "%d " id in
  let g = Array.init n (fun _ ->
                        Array.init n (fun _ ->
                                      let x = scanf " %d" id in x)
                       ) in
  printf "%d\n" (prim g n)

Measured memory_bytes: 4600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long s = sc.nextLong();
		long w = sc.nextLong();
		if(s<=w){
			System.out.println("unsafe");
		}else{
			System.out.println("safe");
		}
	}
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint ch(int n, int a){
	mint x = 1, y = 1;
	rep(i, a){
		x *= (n-i);
		y *= (i+1);
	}
	
	return x/y;
}

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	mint ans = 2;
	ans = ans.pow((ll)n);
	ans -= 1;
	ans -= ch(n, a);
	ans -= ch(n, b);
	cout << ans.x << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi a(n),b(n);
    cin>>a>>b;
    int ans=0;
    REP(i,n){
        ans+=max(a[i]-b[i],0);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int sum = 30;
  
  for(int i = 0; i < N; i++){
    int x;
    int count = 0;
    
    cin >> x;
    
    while(x%2 == 0){
      x = x/2;
      count++;
    }
    
    if(count < sum){
      sum = count;
    }
    
  }
  
  cout << sum << endl;
    
}


Measured memory_bytes: 256
//2019.8.19 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG unl x){
//    if(x>10)write(x/10);
//    putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=3e5+10;
const int kcz=998244353;
namespace MAIN{
    int n;
    char str[N];
    int r,b,g,rb,rg,bg;
    int ans=1;
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    inline void MAIN(){
        n=read(),scanf("%s",str+1);
        for(res i=1;i<=n;i++)ans=mul(ans,i);
        for(res i=1;i<=3*n;i++){
            if(str[i]=='R'){
                if(bg)ans=mul(ans,bg--);
                else if(b)ans=mul(ans,b--),rb++;
                else if(g)ans=mul(ans,g--),rg++;
                else r++;
            }
            else if(str[i]=='B'){
                if(rg)ans=mul(ans,rg--);
                else if(r)ans=mul(ans,r--),rb++;
                else if(g)ans=mul(ans,g--),bg++;
                else b++;
            }
            else {
                if(rb)ans=mul(ans,rb--);
                else if(r)ans=mul(ans,r--),rg++;
                else if(b)ans=mul(ans,b--),bg++;
                else g++;
            }
        }
        printf("%d\n",ans);
    }
}
int main(){
//    srand(19260817);
//    freopen("signin.in","r",stdin);
//    freopen("signin.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

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

void bfs(vector<vector<int>>& to, vector<int>& d, int s){
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int i = q.front();
        q.pop();
        for(auto e: to[i]){
            if(d[e] != 1e9) continue;
            d[e] = d[i] + 1;
            q.push(e);
        }
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    vector<pair<int,int>> p;
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
        p.push_back({a,b});
    }
    
    int ans = 0;
    for(auto e: p){
        vector<int> d(n, 1e9);
        auto co = to;
        int f = e.first;
        int l = e.second;
        // cout << f << ", " << l << endl;
        co[f].erase(find(co[f].begin(), co[f].end(), l));
        co[l].erase(find(co[l].begin(), co[l].end(), f));
        bfs(co, d, f);
        if(d[l] == 1e9) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}





int main() {
  int N=input();
  if(N<=111){
    cout<<111<<endl;
  }else if(N<=222){
    cout<<222<<endl;
  }else if(N<=333){
    cout<<333<<endl;
  }else if(N<=444){
    cout<<444<<endl;
  }else if(N<=555){
    cout<<555<<endl;
  }else if(N<=666){
    cout<<666<<endl;
  }else if(N<=777){
    cout<<777<<endl;
  }else if(N<=888){
    cout<<888<<endl;
  }else{
    cout<<999<<endl;
  }





  

  
  
  


  
  


  

  




  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a<b){swap(a,b);}
    if(a%b==0){return b;}
    return gcd(b,a%b);
}
int main(){
    int N,X;
    cin>>N>>X;
    int x;
    cin>>x;
    int g=abs(x-X);
    for(int i=0;i<N-1;i++){
        cin>>x;
        g=gcd(g,abs(x-X));
    }
    cout<<g<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: String = read();
    let m: String = read();

    let a: i64 = read();
    let b: i64 = read();

    let u: String = read();

    if u == n {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;



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

	int l = -INF, r = INF;
	int N, M; cin >> N >> M;
	REP(i, M) {
		int L, R; cin >> L >> R;
		l = max(l, L);
		r = min(r, R);
	}
	if (l > r) {
		print(0);
	}
	else {
		print(r - l + 1);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 100001
struct D{
	int x,step;
}nxt;
int n,m,st,ed;
vector<int>edge[M];
bool mark[M][3];
int spfa(){
	queue<D>Q;
	Q.push((D){st,0});mark[st][0]=1;
	while(!Q.empty()){
		D now=Q.front();Q.pop();
		for(int i=0;i<edge[now.x].size();i++){
			int y=edge[now.x][i];
			nxt.x=y,nxt.step=now.step+1;
			if(mark[y][nxt.step%3])continue;
			mark[y][nxt.step%3]=1;
			if(y==ed&&nxt.step%3==0)return nxt.step/3;
			Q.push(nxt);
		}
	}
	return -1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
	}
	scanf("%d%d",&st,&ed);
	printf("%d",spfa());
	return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


typedef pair<string, int> p;

int main(){
  int n, m;

  scanf("%d", &n);

  string s;
  vector<p> v;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    bool flag = true;
    REP (i, v.size()) {
      if (v[i].first == s) {
        v[i].second++;
        flag = false;
      }
    }
    if (flag) v.push_back(make_pair(s, 1));
  }

  scanf("%d", &m);

  for (int i = 0; i < m; ++i) {
    cin >> s;
    REP (i, v.size()) {
      if (v[i].first == s) {
        v[i].second--;
      }
    }
  }

  int ans = 0;
  for (auto x : v) {
    ans = max(ans, x.second);
  }

  cout << ans << endl;
}


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

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

  int n, m;
  cin >> n >> m;

  vector<vector<int>> dailyJobs(m);  // dailyの仕事候補一覧

  for (int i = 0; i < n; i++) {
    int d, r;  // 日数、報酬
    cin >> d >> r;

    if (d > m) continue;
    dailyJobs.at(m - d).push_back(r);  // 日ごとの仕事候補一覧を決定
  }

  ll count = 0;
  priority_queue<int> q;
  // dailyJobsの後ろから貪欲に調べる
  for (int i = m - 1; i >= 0; i--) {
    // 日ごとに一番最高報酬の仕事をみつける
    for (int r : dailyJobs.at(i)) {
      q.push(r);
    }

    if (!q.empty()) {
      count += q.top();
      q.pop();
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 5632
n,m,q=map(int,input().split())
atlas=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
    l,r=map(int,input().split())
    atlas[l][r] +=1
for i in range(n+1):
    for j in range(1,n+1):
        atlas[i][j] +=atlas[i][j-1]

for i in range(n+1):
    for j in range(1,n+1):
        atlas[i][j] +=atlas[i-1][j]

for p,q in [list(map(int,input().split())) for _ in range(q)]:
    print(atlas[q][q]-atlas[q][p-1]-atlas[p-1][q]+atlas[p-1][p-1])

Measured memory_bytes: 75864
//A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF=(int)2e9;
const double PI=(double)acos(-1.0);
const double EPS=(double)1e-9;
const ll MOD=(ll)1e9+7;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define FOR(i,n) REP(i,0,n-1)
#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FORD(i,n) REV(i,n-1,0)

int main(){
	int n,x;
	scanf("%d %d",&n,&x);
	printf("%d\n",n-min(x,n));
	return 0;
}

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

int main(void){
   int A,B,M;
   cin>>A>>B>>M;
   int Mini_a=200000;
   int Mini_b=200000;
   vector<int> a(A),b(B);
   for(int i=0;i<A;i++){
      cin>>a[i];
      Mini_a=min(Mini_a,a[i]);
   }
   for(int i=0;i<B;i++){
      cin>>b[i];
      Mini_b=min(Mini_b,b[i]);
   }
   vector<int> x(M),y(M),c(M);
   for(int i=0;i<M;i++){
      cin>>x[i]>>y[i]>>c[i];
   }
   int ans=1000007;
   for(int i=0;i<M;i++){
      int sum=a[x[i]-1]+b[y[i]-1]-c[i];
      ans=min(ans,sum);
   }
   cout<<min(ans,Mini_a+Mini_b)<<endl;
   return 0;
}


Measured memory_bytes: 5036
fun main(args: Array<String>) {

    var (n, y) = readLine()!!.split(" ")!!.map { it.toInt() }

    // ｎ の上限は 2000, 計算実行の制限時間は2秒, １秒間処理できるループ回数はだいたい 10^8
    for (i in 0..n) {
        for (j in 0..n) {
            val sum = 10000*i + 5000*j + 1000*(n-i-j)
            if (sum == y && i + j <= n) {
                print("$i $j ${n-i-j}")
                return
            }
        }
    }
    print("-1 -1 -1")
}

Measured memory_bytes: 37928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n; cin >> n;
  map<string, int> m;
  rep(i,n){
    string s; cin >> s;
    if(m.count(s)==0) m[s]++;
  }
  cout << m.size();
  return 0;
}


Measured memory_bytes: 19240
// Your code here!

import std.stdio,std.conv,std.string,std.algorithm,std.array;
void main(){
    auto s=readln().chomp().split().map!(to!int);
    int a=s[0],b=s[1];
    if(a>b)
        writeln(a-1);
    else
        writeln(a);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		// 入力
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] aList = new int[n];
		for (int i = 0; i < n; i++) {
			aList[i] = scanner.nextInt();
		}
		
		// 計算
		Arrays.sort(aList);
		
		int max = aList[n-1];
		int mid = max/2;
		int target = -1;
		for (int i = 0; i < aList.length; i++) {
			if (mid <= aList[i]) {
				int targetA = aList[i-1];
				int targetB = aList[i];
				if (targetA >= max - targetB) {
					target = targetA;
				} else {
					target = targetB;
				}
				break;
			}
			
		}
		
		System.out.printf("%d %d\n", max, target);
		
	}
}

Measured memory_bytes: 52124
n = int(input())
abc =[]
for i in range(n):
    a,b = [int(x) for x in input().split()]
    abc.append([a,b,a+b])
abc = sorted(abc,key=lambda x: x[2],reverse=True)
t=0
a=0
for i in range(n):
    if i%2==0:
        t+=abc[i][0]
    else:
        a+=abc[i][1]
print(t-a)

Measured memory_bytes: 66392
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		if(a.length() > b.length()) ou.println("GREATER");
		else if(a.length() < b.length()) ou.println("LESS");
		else{
			boolean co = true;
			int ke = 0;
			while(co){
				co = false;
				if(ke == a.length()) ou.println("EQUAL");
				else if(a.charAt(ke) > b.charAt(ke)) ou.println("GREATER");
				else if(a.charAt(ke) < b.charAt(ke)) ou.println("LESS");
				else co = true;
				ke++;
			}
		}
		ou.flush();
	}
}

Measured memory_bytes: 35780
import java.util.*;

class Main{

    void solve(){
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	char[] shop = sc.next().toCharArray();

	String[] list = new String[n];
	boolean[] boo = new boolean[n];

	for(int i=0; i<n; i++) list[i] = sc.next();

	int cnt = 0;
	for(int i=0; i<50; i++){//wide
	    for(int k=0; k<n; k++){//furui
		if(boo[k]) continue;
		char[] c = list[k].toCharArray();
		for(int l=0; l<c.length; l++){//start
		    for(int j=0; j<shop.length; j++){//shop
			int idx = i * j + j + l;
			if(idx>=c.length) break;
			if(c[idx]!=shop[j]) break;
			if(j==shop.length-1) boo[k] = true;
		    }
		    if(boo[k]) break;
		}
	    }
	}

	for(int i=0; i<boo.length; i++){
	    if(boo[i]) cnt++;
	}

	System.out.println(cnt);
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 22532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

ll mod=(ll)1e9+7;
ll pow(ll m,ll n){
    ll ret=1;
    ll a=m;
    while(n>0){
        if(n&1)ret=(ret*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ret;
}
void solve(){
    ll m,n;cin>>m>>n;
    cout<<pow(m,n)<<endl;
}

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



Measured memory_bytes: 3216
import bisect
import heapq
import sys


input = sys.stdin.readline
sys.setrecursionlimit(100000)


class V:
    def __init__(self, f):
        self.f = f
        self.v = None

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n)

    def get(self):
        return self.v


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def calc_v(D, f, i):
    p, n, c = V(f), V(f), V(f)
    for d, P in D.items():
        for pp in P:
            if d == ("R" if i == 0 else "U"):
                p.ud(pp[i])
            elif d == ("L" if i == 0 else "D"):
                n.ud(pp[i])
            else:
                c.ud(pp[i])

    p = p.get()
    n = n.get()
    c = c.get()
    return p, n, c, f


def calc_e(p, n, c, f):
    if p is None:
        if c is None or n is None:
            return []
        else:
            return [n - c]

    if n is None:
        if c is None:
            return []
        else:
            return [c - p]

    t = (n - p) / 2
    if c is None:
        return [t]

    return [t, c - p, n - c]


def calc(t, L):
    res = V(L[3])
    if L[0] is not None:
        res.ud(L[0] + t)

    if L[1] is not None:
        res.ud(L[1] - t)

    if L[2] is not None:
        res.ud(L[2])

    return res.get()


def main():
    N = int(input())
    D = {
        "R": [],
        "L": [],
        "U": [],
        "D": [],
    }

    for _ in range(N):
        x, y, d = input().split()
        x = int(x)
        y = int(y)
        D[d].append((x, y))

    VV = []
    VV.append(calc_v(D, max, 0))
    VV.append(calc_v(D, min, 0))
    VV.append(calc_v(D, max, 1))
    VV.append(calc_v(D, min, 1))

    E = {0}
    for e in [calc_e(*v) for v in VV]:
        for t in e:
            E.add(t)

    res = V(min)
    for t in E:
        if t < 0:
            continue
        res.ud((calc(t, VV[0]) - calc(t, VV[1])) * (calc(t, VV[2]) - calc(t, VV[3])))
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 17028
#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 elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for(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 -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }  
  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<string> _s(N);
  auto * const s = &_s[0];
  for (int i = 0; i < N; ++i)
  {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(_s.begin(), _s.end());
  auto __s(_s);
  __s.erase(unique(__s.begin(), __s.end()), __s.end());
  long long sum = 0;
  long long count = 0;
  int j = 0;
  for (int i = 0, _i = __s.size(); i < _i; ++i)
  {
    for (int _j = _s.size(); j < _j; ++j)
    {
      if (_s[j] == __s[i])
        ++count;
      else
      {
        sum += count*(count - 1)/2;
        count = 0;
        break;
      }
    }
  }
  sum += count*(count - 1)/2;
  cout << sum;
  return 0;
}


Measured memory_bytes: 8064
// ABC049C - Daydream
package main

import (
	"fmt"
)

func Reverse(s string) []rune {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}
func canMakeT(sRuneR []rune) bool {
	i := 0
	for i < len(sRuneR) {
		if i+5 > len(sRuneR) {
			return false
		}
		if string(sRuneR[i:i+5]) == "esare" ||
			string(sRuneR[i:i+5]) == "maerd" {
			i += 5
			continue
		}

		if i+6 > len(sRuneR) {
			return false
		}
		if string(sRuneR[i:i+6]) == "resare" {
			i += 6
			continue
		}
		if i+7 > len(sRuneR) {
			return false
		}
		if string(sRuneR[i:i+7]) == "remaerd" {
			i += 7
			continue
		}
		return false
	}
	return true
}
func main() {
	var s string
	//sc := bufio.NewScanner(os.Stdin)
	//sc.Scan()
	//s = sc.Text()
	fmt.Scan(&s)
	sRuneR := Reverse(s)
	if canMakeT(sRuneR) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1664
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=[list(map(int,input().split()))[::-1]for _ in range(m)]+[[0,1000000000000]]
bc.sort(reverse=1)
t=[]
for c,b in bc:
  for _ in range(b):
    t.append(c)
    if len(t)>=n:break
ans=0
for i in range(n):ans+=max(a[i],t[i])
print(ans)

Measured memory_bytes: 27472
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int n, h;
    cin >> n;
    int ans = 0;
    int mx = -1;
    for(int i = 0; i < n; i++){
        cin >> h;
        if(mx <= h){
            ans++;
            mx = h;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int s1=0,s2=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='R'){
			s1++;
		}else{
			s2++;
		}
	}
	int ans=0;
	for(int i=0;i<s1;i++){
		if(s[i]=='W'){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int count1;
  int count2;
  if(c % b != 0) {
    count1 = c/b +1;
  }else {
    count1 = c/b;
  }
  if(a % d != 0) {
    count2 = a/d +1;
  }else {
    count2 = a/d;
  }
  if(count1 > count2) {
    cout << "No" << endl;
  }else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
import std.stdio,std.string,std.conv;

int main()
{
	int sum = 0,count = 0;
	double num = 0;

	string s;
	while((s = readln.chomp).length != 0)
	{
		count++;
		string[] _s = s.split(",");
		sum += _s[0].to!int * _s[1].to!int;
		num += _s[1].to!int;
	}

	sum.writeln;
	writeln(cast(int)((num/count) + 0.5));
	return 0;
}

Measured memory_bytes: 1068
h, w = map(int, input().split())
a_s = [list(map(int, input().split())) for _ in range(h)]
pm = 1
x = 0
ans = []
car = 0
for y in range(h):
    for _ in range(w - 1):
        if (a_s[y][x] + car) % 2 == 0:
            car = 0
        else:
            car = 1
            ans.append([y + 1, x + 1, y + 1, x + 1 + pm])
        x += pm
    if y != h - 1:
        if (a_s[y][x] + car) % 2 == 0:
            car = 0
        else:
            car = 1
            ans.append([y + 1, x + 1, y + 2, x + 1])
    pm *= -1
print(len(ans))
for row in ans:
    print(*row)

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

int main() {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  int ans = min(a,b) + min(c,d);
 
  cout << ans << endl;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr long long MOD = 998244353;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}


void solve() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << en;
	else cout << "No" << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {

            int N = Integer.parseInt(line);

            next:
            for (int i = 0; i < N; i++) {
                int[] num = new int[3];
                StringTokenizer st = new StringTokenizer(br.readLine());
                num[0] = Integer.parseInt(st.nextToken());
                num[1] = Integer.parseInt(st.nextToken());
                num[2] = Integer.parseInt(st.nextToken());
                num[0] *= num[0];
                num[1] *= num[1];
                num[2] *= num[2];

                for (int j = 0; j < 3; j++) {
                    if (num[j % 3] == num[(j + 1) % 3] + num[(j + 2) % 3]) {
                        System.out.println("YES");
                        continue next;
                    }
                }
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 18632
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string ss[3];
	for(int i = 0; i < 3; ++i){
		cin >> ss[i];
	}
	bool ok[3][3][4010] = {};
	for(int a = 0; a < 3; ++a)
	for(int b = 0; b < 3; ++b)
	if(a != b){
		int la = ss[a].size(), lb = ss[b].size();
		for(int i = 0; i < 4010; ++i){
			bool flag = true;
			for(int j = 0; j < lb && i + j < la; ++j){
				char ca = ss[a][i + j], cb = ss[b][j];
				if(ca != '?' && cb != '?' && ca != cb){
					flag = false;
					break;
				}
			}
			ok[a][b][i] = flag;
		}
	}

	int ans = INT_MAX;
	int perm[] = {0, 1, 2};
	do{
		int a = perm[0], b = perm[1], c = perm[2];
		for(int i = 0; i < 2005; ++i){
			if(!ok[a][b][i]){ continue; }
			if((int)ss[b].size() + i > ans){ continue; }
		
			for(int j = i; j < 4010; ++j){
				if(ok[a][b][i] && ok[b][c][j - i] && ok[a][c][j]){
					int len = max({ss[a].size(), ss[b].size() + i, ss[c].size() + j});
					chmin(ans, len);
				}
			}
		}
	}while(next_permutation(perm, perm + 3));
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


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

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

typedef long long lint;

using namespace std;

int main(){
  lint N;
  cin>>N;
  string s="";
  lint sign;
  if(N>0)sign=1;
  else sign=-1;
  if(N==0)s="0";
  N=sign*N;
  for(int i=0;(N>>i)>0;i++){
    s=to_string((N>>i)&1)+s;
    if((N>>i)&1 and((i%2==0 and sign==-1) or (i%2==1 and sign==1))){
      N+=((lint)1<<(i+1));
    }
  }
  cout<<s<<endl;
  return 0;
}


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

int p[10],c[10];

signed main(){

  int D,G; cin >> D >> G;
  for(int i = 0; i < D; i++){
    cin >> p[i] >> c[i];
  }

  int ans = 1145141919;
  for(int i = 0; i < (1 << D); i++){
    int t = 0,cnt = 0;
    for(int j = 0; j < D; j++){
      if(1 & (i >> j)){
        t += p[j]*(j+1)*100 + c[j];
        cnt += p[j];
      }
    }

    for(int j = D-1; j >= 0; j--){
      if(1 & (i >> j)) continue;
      if(G <= t) break;
      int need = min((G-t)/((j+1)*100),p[j]);
      t += need*(j+1)*100;
      cnt += need;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = -1

def dfs(i, s, p, cnt):
    if i == 0:
        cnt += 1
        if cnt == K:
            print(s)
            exit()
        else:
            return cnt
    if s == 0:
        for ii in range(10):
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)
    else:
        for ii in RUN[p]:
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)

    return cnt

dfs(10, 0, 0, cnt)

Measured memory_bytes: 3064
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

char a[101][101];
char b[101][101];

int main(){
  int H, W;
  cin >> H >> W;
  rep(h, H) cin >> a[h];
  rep(h, H){
    bool f = true;
    rep(w, W){
      rep(i, W) if(a[h][i] == '#') f = false;
    }
    if(f) continue;
    rep(w, W){
      bool f = false;
      rep(i, H) if(a[i][w] == '#') f = true;
      if(f) cout << a[h][w];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = []
count = 0
def dfs(s):

    if int(s)>n:
        return 0
    ans.append(s)
    for c in '753':
        dfs(s+c)
dfs('0')
for i in ans:
    if all(i.count(j)>0 for j in '753'):
        count += 1
print(count)


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

typedef long long ll;
ll memo[1000002];
ll n;
map<ll,bool> s;

ll dp(ll x){
    if (x>n)
    {
        memo[x] = 0;
        return 0;
    }

    if (s[x]){
        memo[x] = 0;
        return 0;
    }
    ll to_add = 0;
    if (x==n)
    {
        return 1;
    }
    if (memo[x] != -1)
        return memo[x];
    else
    {
        if(!s[x+1])
        to_add += dp(x+1);
        if (!s[x+2]&&x+2<=n)
            to_add += dp(x+2);
        memo[x] = to_add%1000000007;
        return memo[x];
    }

}

int main()
{
    memset(memo, -1, sizeof(memo));
    // memo[n] = 1;
    ll m, t;
    cin>>n>>m;
    while(m--)
    {
        cin>>t;
        s[t]=1;
    }
    cout<<dp(0)<<'\n';

    return 0;

}

Measured memory_bytes: 23680
n = gets.chomp.split(" ").map(&:to_i)
height = n[0]
width = n[1]

map = Array.new()

n[0].times do
    map.push(gets.chomp.split(""))
end

fullfillFrag = true
height.times do |h|
    width.times do |w|
        if map[h][w] == "#"
            canPaint = 1
            if 0 <= h - 1 and map[h - 1][w] == "#"
                canPaint += 1
            end
            if h + 1 < height and map[h + 1][w] == "#"
                canPaint += 1
            end
            if 0 <= w - 1 and map[h][w - 1] == "#"
                canPaint += 1
            end
            if w + 1 < height and map[h][w + 1] == "#"
                canPaint += 1
            end
            if canPaint < 2
                fullfillFrag = false
                break
            end
        end
    end
    if fullfillFrag == false
        break
    end
end

if fullfillFrag
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 2172