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

const int mxN = 1e5;
string s,t;
const long long inf =1e18l+7;
int dp[mxN+1],N,M,ans=0,vis[mxN],inDegree[mxN];

vector<int> adj[mxN];


void dfs(int u)
{
    
    vis[u]=1;
    for(int v : adj[u]){
       dp[v]=max(dp[v],dp[u]+1);
       inDegree[v]--;
       if(inDegree[v]==0){ 
           dfs(v);
       }   
    }
}
int main(){
    cin >> N >> M;

    for(int i=0,a,b ; i<M ;++i){
       cin >> a >> b,--a,--b;
       adj[a].push_back(b);
       inDegree[b]++;
    }

    for(int i=0 ;i<N ;++i)
    {
        if(!vis[i] && inDegree[i]==0){
            dfs(i);
        }
    }
    for(int i=0 ; i<N ;++i)ans=max(ans,dp[i]);

    cout << ans;     
           
}

Measured memory_bytes: 14836
#include <iostream>
#include <string>
#include <limits.h>
#include <numeric>
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,c) for (int i=0;i<c;i++)
using namespace std;
 
 
int main(){
    int N,A,B;
    cin >> N >> A >> B;
    char s[N];
    rep(i,N) cin >> s[i];
    int q = 0;
    int b =1;
    rep(i,N){
        if(s[i] == 'a'){
            if(q < A+B){
                q++;
                cout <<"Yes" <<endl;
            }
            else{
                cout << "No"<<endl;
            }
        }
        else if(s[i]=='b'){
            if(q < A+B && b <= B){
                b++;
                q++;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 768
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum_a=[0]*(n+1)
for i in range(n):
  sum_a[i+1]=(sum_a[i]+a[i])
sum_b=[0]*(m+1)
for i in range(m):
  sum_b[i+1]=(sum_b[i]+b[i])
ans=0
nokori=k
for i in range(n+1):
  if k>=sum_a[i]:
    cnt=i
    nokori=k-sum_a[i]
    cnt+=(bisect.bisect(sum_b,nokori)-1)
    ans=max(ans,cnt)
  else:
    pass
print(ans)

Measured memory_bytes: 47380
import java.awt.Point;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int[][] map;
    static int VISITED = -1;
    public static void main(String[] args) throws java.io.IOException {
        Scanner sc = new Scanner(System.in);
        while(true){
            int w = sc.nextInt();
            int h = sc.nextInt();
            if((w|h)==0)break;
            map = new int[h][w];
            int xs = sc.nextInt()-1;
            int ys = sc.nextInt()-1;
            int xg = sc.nextInt()-1;
            int yg = sc.nextInt()-1;
            int n = sc.nextInt();
            for(int i=0;i<n;i++){
                int c = sc.nextInt();
                int d = sc.nextInt();
                int x = sc.nextInt()-1;
                int y = sc.nextInt()-1;
                setBlock(c,d,x,y);
            }
            boolean flag = false;
            Point sp = new Point(xs,ys);
            Queue<Point> fifo = new LinkedList<Point>();
            fifo.add(sp);
            int color = map[ys][xs];
            if(color==VISITED||color!=map[yg][xg]){
            	System.out.println("NG");
            	continue;
            }
            while(fifo.peek()!=null){
                Point p = fifo.poll();

                if(p.x==xg&&p.y==yg){
                    flag=true;
                    break;
                }
                int x = p.x;
                int y = p.y;

                int[] dx={1,0,-1,0};
                int[] dy={0,1,0,-1};
                for(int i=0;i<4;i++){
                    int nx = x+dx[i];
                    int ny = y+dy[i];
                    if(nx>=0&&nx<w&&ny>=0&&ny<h&&map[ny][nx]==color){
                        fifo.add(new Point(nx,ny));
                        map[ny][nx]=VISITED;
                    }
                }
            }
            System.out.println(""+(flag? "OK" : "NG"));
        }

    }
    public static void setBlock(int c,int d, int x, int y){
        if(d==0){
            for(int i=0;i<2;i++){
                for(int j=0;j<4;j++){
                    map[y+i][x+j] = c;
                }
            }
        }
        else if(d==1){
            for(int i=0;i<4;i++){
                for(int j=0;j<2;j++){
                    map[y+i][x+j] = c;
                }
            }
        }
    }
}

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

const ll MOD = 1e9 + 7;

int main(){
  ll N, M;
  cin >> N >> M;
  ll x[N], y[M];
  for(int i = 0; i < N; i++) cin >> x[i];
  for(int i = 0; i < M; i++) cin >> y[i];

  ll X = 0, Y = 0;
  for(ll i = N - 1; i >= 0; i--){
    X += (-N + 2 * i + 1) * x[i];
    X %= MOD;
  }
  for(ll i = M - 1; i >= 0; i--){
    Y += (-M + 2 * i + 1) * y[i];
    Y %= MOD;
  }

  cout << (X * Y) % MOD << endl;
  return 0;
}

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

int main() {
    int n;
    std::cin >> n;
    
    std::vector<int> A(n);
    for (int i = 0; i < n; i++) {
        std::cin >> A[i];
    }

    int m;
    std::cin >> m;

    std::vector<int> B(m);
    for (int i = 0; i < m; i++) {
        std::cin >> B[i];
    }

    for (int i = 0; i < std::min(n, m); i++) {
        if (A[i] < B[i]) {
            std::cout << 1 << std::endl;
            return 0;
        } else if (A[i] > B[i]) {
            std::cout << 0 << std::endl;
            return 0;
        }
    }
    std::cout << (int)(n < m) << std::endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define maxN 1000001
#define mod 1000000007
#define maxLL 1000000000000000000
#define PI 3.14159265358979323846264338327950L
typedef long long ll;

bool compared(int a,int b){
	return a < b;
}

int cmp(const void *a,const void *b){
	return(*(int*)b - *(int*)a);
}

int GCD(int a,int b){
	return b?GCD(b,a%b):a;
}

int a[101] = {0};

int main(){
	int x,n;
	cin>>x>>n;
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		a[b] = 1;
	}
	int mn = mod;
	int l = x-1;
	int r = x+1;
	if(a[x] == 1){
		while(1){
			if(a[l] == 0){
				cout<<l<<endl;
				break;
			}
			else{
				l--;
			}
			if(a[r] == 0){
				cout<<r<<endl;
				break;
			}
			else{
				r++;
			}
		}
	}
	else{
		cout<<x<<endl;
	}
	return 0;
}


Measured memory_bytes: 3640
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = input()

M = int(input())
T = [0] * M
for i in range(M):
    T[i] = input()

m = 0
for s1 in S:
    x = 0
    for s2 in S:
        if s1 == s2:
            x += 1
    for t in T:
        if t == s1:
            x -= 1

    if x > m:
        m = x
print(m)


Measured memory_bytes: 3060
//==================================================================================================
// Name        : a.cpp
// Author      : lotus.eater086
// Copyright   : If you're reading this then this warning is for you. Every word you read of this 
//               useless fine print is another second of your life. Don't you've other things to do?
//               Is your life so empty that you honestly can't think of a better way to spend these
//               moments ? Or are you so impressed with authority that you give respect and 
//               credence to all who claim it ? Do you read everything you're supposed to read ? Do
//               you think everything you're supposed to think ? Buy what you're told you should 
//               want ? Get out of your apartment . Meet a member of the opposite sex. Stop the 
//               excessive shopping and self-improvement . Quit your boring job.
//               Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
//               statistic. You've been warned !

// Description : 
// Date        : 2019-10-02
// Time        : 11:28:00
// Directory   : C:\Users\Lenovo\cpPractise\deliberatePractise\code_folder\.vscode
// FilePath    : C:\Users\Lenovo\cpPractise\deliberatePractise\code_folder\.vscode\a.cpp
//==================================================================================================
    

#include <bits/stdc++.h>
#define LL long long
#define endl "\n"

using namespace std ;
    
//
template < typename T >

inline T read( T &x )
{

    x = 0 ;

    int f = 0 ;

    char ch = getchar() ;

    while( ch < '0' || ch > '9' )  {

        f |= ( ch == '-' ) , ch = getchar() ;

    }

    while( ch >= '0' && ch <= '9' )  {

        x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;

    }

    return x = f ? -x:x ;

}
//

void print_vector( vector<int> v )
{

    for( int i = 0 ; i < v.size() ; i++ ) {

       if( i == 0 )  cout << v[i] ; 
        else 
        cout << " " << v[i] ;  

    }

}

void insertion_sort( vector<int> v )
{

    print_vector( v ) ;   cout << endl ;

    for( int i = 1 ; i < v.size()  ; i++ )  {

        int key = v[i] , j = i-1 ;

        while( j >= 0 && v[j] > key )  v[j+1] = v[j] , j-- ;

        v[j+1] = key ;  

        print_vector( v ) ;   cout << endl ;

    }

}

void solve( void )
{

    int n ;

    cin >> n ;

    vector<int> v( n ) ;

    for( int i = 0 ; i < n ; i++ )  cin >> v[i] ;

    insertion_sort( v ) ;  




}

int main( void )

{

    //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  */  

    if( 0 )  {

        int t = 100 ;

        for( int i = 1 ; i <= t ; i++ )  solve() ;

    }

    else  {

        solve() ;

    }

  /*  #ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " sec\n" ;
    #endif  */

    return 0 ;

}



Measured memory_bytes: 3148
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  string a,b;
  cin >> a>>b;
  
  rep(i,b.size()){
    cout << a[i] << b[i];
  }
  
  if(a.size()>b.size()) cout << a[a.size()-1];
  
  cout << endl;
  
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  long long count = 0;
  int flags = 0;
  int left;
  int right = 0;
  for(left = 0; left < n; left++){
    while(right < n && (flags & a[right]) == 0){
      flags |= a[right];
      right++;
    }
    
    count += (long long)(right - left);
    
    if(left == right) right++;
    else flags -= a[left];
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
int main(){
	ll n, w;
	cin >> n >> w;
	ll dp[w+1] = {};
	fop(i,0,n){
		ll x, y;
		cin >> x >> y;
		for(ll j = w;j >= x;j --){
			dp[j] = max(dp[j],dp[j-x] + y);
		}
	}
	cout << dp[w];
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

map<int, pair<vector<int>,int>>getans(string st) {
	map<int, pair<vector<int>,int>>ans;
	ans[stoi(st)] = make_pair(vector<int>(1,stoi(st)),1);
	if (st.size()) {
		for (int i = 1; i < st.size(); ++i) {
			map<int, pair<vector<int>, int>>mp(getans(st.substr(i, st.size() - i)));
			for (auto& j : mp) {
				string from = st.substr(0, i);
				vector<int>now(1, stoi(from) );
				if (!ans.count(stoi(from) + j.first)) {		
					now.insert(now.end(), j.second.first.begin(), j.second.first.end());
					ans[stoi(from) + j.first] = make_pair(now, j.second.second);
				}
				else {
					ans[stoi(from) + j.first].second+=j.second.second;
				}
			}
		}
	}
	
	return ans;
}

int main() {
	while (1) {
		int sum; string num; cin >> sum >> num;
		if (sum == 0)break;
		map<int, pair<vector<int>, int>>mp(getans(num));
		auto it(mp.upper_bound(sum));

		if (it == mp.begin()) {
			cout << "error" << endl;
		}
		else if (prev(it)->second.second != 1) {
			cout << "rejected" << endl;
		}
		else {
			cout << prev(it)->first;
			for (int i = 0; i < prev(it)->second.first.size(); ++i) {
				cout <<" "<< prev(it)->second.first[i];
			}
			cout << endl;
		}

	}
	return 0;
}

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

using namespace std;

#define llong long long 
llong int n,s;
llong int ans;
llong int memo[101][10][1000];

llong int solve(int now, int d, int sum){
	if(d == 0){
		llong int ret = 0;
		for(int i = 0; i <= 100; i++){
			ret += solve(i, 1, i);
		}

		return ret;
	}

	if(memo[now][d][sum] != -1) return memo[now][d][sum];

	if(d == n){
		if(sum == s) return memo[now][d][sum] = 1;
		else return memo[now][d][sum] = 0;
	}
	if(d < n && sum >= s) return memo[now][d][sum] = 0;

	llong int ret = 0;
	for(int i = now + 1; i <= 100; i++){
		ret += solve(i, d + 1, sum + i);
	}

	return memo[now][d][sum] = ret;
}	

int main(){

	while(cin >> n >> s, n){
		fill_n(**memo, 101 * 10 *1000, -1);
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 10960
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,k;
ll dp[101][200001],s[101][200001];
vector<ll> nums;
map<ll,bool> f;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(ll i=1;i*i<=n;i++)
    {
        nums.push_back(i);
        f[i]=1;
    }
    for(ll j=nums.size()-1;j>=0;j--)
    {
        if(f.count(n/nums[j])==0)
        {
            nums.push_back(n/nums[j]);
            f[n/nums[j]]=1;
        }
    }
    /*for(auto j:nums)
        cout<<j<<" ";
    cout<<'\n';*/
    ll m=nums.size();
    for(int i=0;i<m;i++)
    {
        dp[1][i]=1;
        if(i==0)
        {
            s[1][i]=dp[1][i];
            continue;
        }
        s[1][i]=(s[1][i-1]+(dp[1][i]*(nums[i]-nums[i-1])%mod))%mod;
    }
    for(int j=2;j<=k;j++)
    {
        for(int i=0;i<m;i++)
        {
            dp[j][i]=s[j-1][m-i-1];
            if(i==0)
            {
                s[j][i]=dp[j][i];
                continue;
            }
            s[j][i]=(s[j][i-1]+(dp[j][i]*(nums[i]-nums[i-1])%mod))%mod;
        }
    }
    cout<<s[k][m-1]%mod;
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 2 * 1e5;

int n, m;
int parent[N], gsz[N];

void init_set(int v) {
	parent[v] = v;
	gsz[v] = 1;
}

int find_set(int v) {
	if (parent[v] == v) return v;
	else return parent[v] = find_set(parent[v]);
}

void merge_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (gsz[a] < gsz[b]) swap(a, b);
		parent[b] = a;
		gsz[a] += gsz[b];
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	
	rep(i, 0, n) {
		init_set(i);
	}
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		merge_sets(a, b);
	}
	
	int ans = -1;
	rep(i, 0, N) {
		ans = max(ans, gsz[i]);
	}
	
	cout << ans;
}


Measured memory_bytes: 5212
S = list(input())
ans = 0
for i in range(1 << len(S) - 1):
    output = S[0]
    for j in range(len(S) - 1):
        if ((i >> j) & 1) == 1:
            output += "+"
        output += S[j + 1]
    ans += eval(output)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    int m,p[100][100]={},t;
    for(int i=0;i<n;i++){
      cin>>m;
      for(int j=0;j<m;j++)cin>>t,p[i][t]=1;
    }
    int k,l[100],an,c=0;
    cin>>k;
    for(int i=0;i<k;i++)cin>>l[i];
    for(int i=0;i<n;i++){
      bool f=1;
      for(int j=0;j<k;j++){
	if(!p[i][l[j]])f=0;
      }
      if(f)an=i,c++;
    }
    if(c!=1)an=-2;
    cout<<an+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	s := newSegment(n)
	for i := 0; i < n; i++ {
		s.assign(0, i, math.MaxInt32)
		update(s, i)
	}
	for i := 0; i < q; i++ {
		c := getNextInt(scanner)
		x := getNextInt(scanner)
		y := getNextInt(scanner)
		switch c {
		case 0:
			s.assign(0, x, y)
			update(s, x)
		case 1:
			fmt.Fprintln(writer, query(s, x, y+1, math.MaxInt32))
		}
	}
}

type segment [][]int

func newSegment(n int) *segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]int, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]int, 1))
	return &seg
}

func (s *segment) assign(h, i int, v int) {
	(*s)[h][i] = v
}
func (s *segment) height() int {
	return len(*s)
}
func (s *segment) width(h int) int {
	return len((*s)[h])
}
func (s *segment) at(h, i int) int {
	return (*s)[h][i]
}
func (s *segment) f(x, y int) int {
	if x < y {
		return x
	}
	return y
}

type segtree interface {
	assign(h, i int, v int)
	height() int
	width(h int) int
	at(h, i int) int
	f(x, y int) int
}

func update(s segtree, i int) {
	for h := 1; h < s.height(); h++ {
		i >>= 1
		if i<<1+1 < s.width(h-1) {
			s.assign(h, i, s.f(s.at(h-1, i<<1), s.at(h-1, i<<1+1)))
		} else {
			s.assign(h, i, s.at(h-1, i<<1))
		}
	}
}
func query(s segtree, l, r int, v int) int {
	for h := 0; h < s.height() && l < r; h++ {
		if l&1 == 1 {
			v = s.f(v, s.at(h, l))
			l++
		}
		l >>= 1
		if r&1 == 1 {
			v = s.f(v, s.at(h, r-1))
		}
		r >>= 1
	}
	return v
}



Measured memory_bytes: 5860
#include<stdio.h>
#include<iostream>
using namespace std;
int main() {
/*
	int a, b;
	cin >> a;
	cin >> b;
	if (a <= 5) {
		cout << 0;
	}
	else if (a <= 12) {
		cout << b / 2;
	}else{
		cout << b;
	}

	return 0;
	*/
	//B
	long long int r, d, x;
	cin >> r;
	cin >> d;
	cin >> x;

	int i;
	for (i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x;
		cout <<'\n';
	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int a[3][3],n,b[10];
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    cin>>n;
    bool tmp[3][3]={};
    for(int i=0;i<n;i++){
        cin>>b[i];
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                if(a[j][k]==b[i])
                    tmp[j][k]=1;
    }
    bool ok=0;
    for(int i=0;i<n;i++)
        if(tmp[i][0]&&tmp[i][1]&&tmp[i][2])
            ok=1;
    for(int i=0;i<n;i++)
        if(tmp[0][i]&&tmp[1][i]&&tmp[2][i])
            ok=1;
    if(tmp[0][0]&&tmp[1][1]&&tmp[2][2])
        ok=1;
    if(tmp[2][0]&&tmp[1][1]&&tmp[0][2])
        ok=1;
    cout<<(ok?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;

int main(void)
{
    int N;
    cin >> N;
    map<string, int> mp;
    for (int i = 0; i < N; ++i)
    {
        string str;
        cin >> str;
        auto itr = mp.find(str);
        if (itr != mp.end())
            itr->second++;
        else
            mp[str] = 1;
    }
    int MAX = 0;
    for (auto itr : mp)
        MAX = max(MAX, itr.second);
    for (auto itr : mp)
    {
        if (itr.second == MAX)
            cout << itr.first << "\n";
    }
}


Measured memory_bytes: 25216
import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [1,0] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' and b[i-1] != j:
    print(-1)
    sys.exit()
  b[i-1] = j
if a[0] == 0:
  if N != 1:
    a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)

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

using namespace std;
#define rep(i, n) for(int i=0;i<(int)n;++i)

void binary_brute_force(const vector<char>& num)
{
    int n = num.size() - 1, sum;
    for(int i=0; i < (1 << n); ++i)
    {
        sum = (num[0] - '0');
        for(int j=0; j<n; ++j)
        {
            if((i >> j) & 1)
            {
                sum += (num[j+1] - '0');
            }
            else{
                sum -= (num[j+1] - '0');
            }
        }
        if(sum == 7)
        {
            cout << num[0];
            for(int j=0;j<n;++j)
            {
                if((i >> j) & 1) cout << '+';
                else             cout  << '-';
                cout << num[j+1];
            }
            cout << "=7" << endl;
            break;
        }
    }
}

int main()
{
    vector<char> num(4);
    for(char& c : num){
        cin >> c;
    }
    binary_brute_force(num);
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}
		
		Arrays.sort(A);
		int sum = 0;
		
		for(int i = 1; i <= N; i++) {
			if(A[i] != A[i - 1]) {
				int count = 0;
				for(int j = i; j <= N; j++) {
					if(A[i] == A[j]) {
						count++;
					} else {
						break;
					}
				}
				if(count % 2 != 0) {
					sum++;
				}
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 50712
#include <iostream>
#include <algorithm>
#include <cstring>

#define INF 999999

using namespace std;

typedef long long int ll;

int values[100009];
int n, k;
ll dp[100009];

int main() {
  memset(dp, INF, sizeof(dp));

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> values[i];

  dp[0] = 0;

  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= i && j <= k; j++)
      dp[i] = min(dp[i], dp[i-j] + abs( values[i]-values[i-j] ) );
  }

  for (int i = 1; i < n; i++)
    for (int j = 0; j <= i && j <= k; j++)
      dp[i] = min(dp[i], dp[i-j]+abs(values[i]-values[i-j]));

  cout << dp[n-1] << endl;
}


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

const int maxn = (int) 1e5 + 5;

int n, m;
int BIT[maxn];

void update(int x, int val) {
    while (x < maxn) {
        BIT[x] += val;
        x += x & (-x);
    }
}

int get(int x) {
    int ret = 0;
    while (x > 0) {
        ret += BIT[x];
        x -= x & (-x);
    }
    return ret;
}

int main() {
    ///freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    int cur, pre;
    cin >> pre;
    for (int i = 1; i < m; i ++) {
        cin >> cur;
        int x = min(cur, pre);
        int y = max(cur, pre);
        pre = cur;
        update(x, 1);
        update(y, -1);
    }
    long long res = 0;
    for (int i = 1; i < n; i ++) {
        long long a, b, c;
        cin >> a >> b >> c;
        int cnt = get(i);
        res += min(a * cnt, c + b * cnt);
    }
    cout << res << endl;
}

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

int main() {
  int c[3][3];
  bool ans=true;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c[i][j];
    }
  }
  for(int i=1;i<3;i++){
    if(c[i][0]-c[0][0]==c[i][1]-c[0][1] && c[i][1]-c[0][1]==c[i][2]-c[0][2]){
      continue;
    }
    else ans=false;
  }
  if(ans)cout << "Yes";
  else cout << "No";
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

void solve()
{
	int n, k;
	cin >> n >> k;

	int cnt = 0;

	for(int i = 0; i < n; ++i)
		cnt += (fetch<int>() >= k);

	cout << cnt << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  int N,T,i,k=1001;
  int c[100],t[100];
  
  scanf("%d %d",&N,&T);
  
  for(i=0;i<N;i++)
  {
    scanf("%d %d",&c[i],&t[i]);
  }
  for(i=0;i<N;i++)
  {
    if(t[i]<=T)
    {
      if(c[i]<=k)
      {
        k=c[i];
      }
    }
  }
  if(k>=1001)
  {
    printf("TLE");
  }
  else if(k<=1000)
  {
    printf("%d",k);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>

using namespace std;

int main() {
	string a, b, ans = "No";
	int c;
	cin >> a >> b;
	a.append(b);
	c = stoi(a);
	for (int i = 0; i*i <= c; i++) {
		if (i*i == c)
			ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
bool _1(string s)
{
    for (int i = 0; i < s.size()/2; ++i)
    {
        if(s[i]!=s[s.size()-i-1])return 0;
    }
    return  1;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;cin >> s;
    ll n=s.size();n--;n/=2;
    string u=s.substr(0,n);
    string t=s.substr(n+1);
    if(_1(u) and _1(t) and _1(s))cout << "Yes";
    else cout << "No";
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int number;
    cin >> number;
    printf("ABC%03d\n", number);
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int x, a;
  cin >> x >> a;
  cout << (x < a ? 0 : 10) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n;
int x[55], y[55];
map<PII, int> mp;

int main()
{
	scanf("%d", &n);
	rep(i, n) scanf("%d%d", &x[i], &y[i]);
	rep(i, n) rep(j, i) {
		mp[MP(x[i] - x[j], y[i] - y[j])] ++;
		mp[MP(x[j] - x[i], y[j] - y[i])] ++;
	}
	
	int ans = n;
	for(map<PII, int>::iterator it = mp.begin(); it != mp.end(); it ++)
	ans = min(ans, n - it->second);
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int k, x, y, s;
vector<int> ans_x;
vector<int> ans_y;

int main()
{
  cin >> k >> x >> y;
  
  int x_mark = 1, y_mark = 1;
  if (x < 0) {
    x_mark = -1;
    x = -x;
  }
  if (y < 0) {
    y_mark = -1;
    y = -y;
  }

  int dist = x + y;
  
  if (k % 2 == 0 and dist % 2) {
    cout << -1 << endl;
    return 0;
  }
    
  if (dist == k) {
    cout << 1 << endl;
    cout << x * x_mark << " " << y * y_mark << endl;
    return 0;
  }   
    
  s = (dist - 1) / k + 1;
  if (s == 1) {
    s = 2;
  }
  
  int px = 0, py = 0;
  int tmp = s;
  while (tmp > 2) {
    int dist_x = x - px;
    if (k <= dist_x) {
      px += k;
    } else {
      px = x;
      py += k - dist_x;
    }
    ans_x.push_back(px);
    ans_y.push_back(py);
    tmp--;
  }
  
  int dist_x = x - px;
  int dist_y = y - py;
  dist = dist_x + dist_y;
  
  int loss;
  
  if (dist % 2) {
    loss = min(k, (k*3 - dist) / 2);
    px -= loss;
    py += k - loss;
    ans_x.push_back(px);
    ans_y.push_back(py);
    dist_x = x - px;
    dist_y = y - py;
    dist = dist_x + dist_y;
    s++;
  }
  
  loss = (k*2 - dist) / 2;
  if (dist_x < dist_y) {
    px -= loss;
    py += k - loss;
  } else {
    px += k - loss;
    py -= loss;
  }
  
  ans_x.push_back(px);
  ans_y.push_back(py);
  
  ans_x.push_back(x);
  ans_y.push_back(y);
  
  cout << s << endl;
  for (int i = 0; i < s; i++) {
    cout << ans_x[i] * x_mark << " " << ans_y[i] * y_mark << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4076
import sys
from collections import deque, Counter, defaultdict
from itertools import accumulate  # 累積和
from bisect import bisect_left, bisect
from heapq import heappop, heappush  # 優先度付きキュー
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

scores = defaultdict(int)
for _ in range(int(input())):
    scores[input()] += 1

for _ in range(int(input())):
    scores[input()] -= 1

print(max(max(scores.values()), 0))


Measured memory_bytes: 64364
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long d = sc.nextLong();
        if(d==0){
            double ans = ((double)m-1)/((double)n);
            System.out.println(ans);
            System.exit(0);
        }
        if(n%2==1){
            double ans;
            if(d>(n-1)/2){
                ans = ((double)m-1.0)/((double)n);
            }
            else{
                ans = 2.0*((double)(n-d))*((double)m-1.0)/((double)(n*n));
            }
            System.out.println(ans);
        }
        else{
            double ans;
            if(d>n/2){
                ans = ((double)m-1.0)/((double)n);
            }
            else{
                ans = 2.0*((double)(n-d))*((double)m-1.0)/((double)(n*n));
            }
            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 21844
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, Z, W;
int A[2005];

int dp[2005][2];
int solve(int n, int t){
    if(dp[n][t] != -1) return dp[n][t];
    if(t == 0){
        int ret = abs(A[n-1] - A[N]);
        for(int i=n; i<N; i++){
            ret = max(ret, solve(i+1, t^1));
        }
        return dp[n][t] = ret;
    }
    else{
        int ret = abs(A[n-1] - A[N]);
        for(int i=n; i<N; i++){
            ret = min(ret, solve(i+1, t^1));
        }
        return dp[n][t] = ret;
    }
}

signed main(){
    cin >> N >> Z >> W;
    A[0] = W;
    rep(i, N) cin >> A[i+1];

    memset(dp, -1, sizeof(dp));
    cout << solve(1, 0) << endl;
}

Measured memory_bytes: 3748
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	x := getNextInt(scanner)
	n := getNextInt(scanner)
	pp := make([]int, n)
	m := map[int]int{}
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
		m[pp[i]] = 1
	}
	for i := 0; i < 200; i++ {
		if m[x-i] == 0 {
			fmt.Fprintln(writer, x-i)
			return
		}
		if m[x+i] == 0 {
			fmt.Fprintln(writer, x+i)
			return
		}
	}
}


Measured memory_bytes: 1864
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	q := sc.ReadInt()
	abcds := make([]ABCD, q)
	for i := 0; i < q; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		c := sc.ReadInt()
		d := sc.ReadInt()
		abcds[i] = ABCD{a, b, c, d}
	}

	combinations := generateCombinations(1, m, n, 0)

	maxScore := 0
	updateMaxScore := func(combi SeqA) {
		score := computeScore(abcds, combi)
		if score > maxScore {
			maxScore = score
		}
	}
	combinations.Each(updateMaxScore)

	fmt.Println(maxScore)
}

func generateCombinations(min, max, n, nCur int) *SeqAList {
	combinations := NewSeqAList()

	if nCur == n {
		combinations.Add(make(SeqA, n))
		return combinations
	}

	for i := min; i <= max; i++ {
		combinationsForI := generateCombinations(i, max, n, nCur+1)

		f := func(combi SeqA) {
			combi[nCur] = i
		}
		combinationsForI.Each(f)

		combinations.Concat(combinationsForI)
	}
	return combinations
}

func computeScore(abcds []ABCD, seqA SeqA) int {
	totalD := 0
	for _, abcd := range abcds {
		if seqA[abcd.B-1]-seqA[abcd.A-1] == abcd.C {
			totalD += abcd.D
		}
	}
	return totalD
}

type SeqA []int

type ABCD struct {
	A int
	B int
	C int
	D int
}

type SeqAList struct {
	first *seqAListNode
	last  *seqAListNode
}

type seqAListNode struct {
	child *seqAListNode
	value SeqA
}

func NewSeqAList() *SeqAList {
	root := seqAListNode{nil, nil}
	return &SeqAList{&root, &root}
}

func (list *SeqAList) Add(item SeqA) {
	node := seqAListNode{nil, item}
	list.last.child = &node
	list.last = &node
}

func (list *SeqAList) Concat(other *SeqAList) {
	if other.first.child == nil {
		return
	}
	list.last.child = other.first.child
	list.last = other.last
}

func (list *SeqAList) Each(f func(item SeqA)) {
	cur := list.first
	for cur.child != nil {
		cur = cur.child
		f(cur.value)
	}
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

int main () {
  string s;
  cin >> s;
  bool good = true;

  for(int i = 1 ; i < s.size(); i++){
    if (s[i-1] == s[i]) good = false;
  }

  if (good) cout << "Good" << endl;
  else cout << "Bad" << endl;
  return 0;
}

Measured memory_bytes: 256
L = 1000
@memo = {}

def doit(s, n = 1)
  return (s <= L) ? 1 : 0 if n == 4
  key = "#{s},#{n}"
  return @memo[key] if @memo[key]
  co = 0
  a = (s <= L) ? s : L
  (0..a).each do |i|
    co += doit(s - i, n + 1)
  end
  @memo[key] = co
end

$<.readlines.map(&:to_i).each do |s|
  puts doit(s)
end


Measured memory_bytes: 7204
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,m;
string s,t;
int main(){FAST;
cin>>s>>t;
n = s.length();
m = t.length();
vl f[26];
for(ll i=0;i<n;i++){
	f[s[i]-'a'].pb(i);
}
ll pre = -1;
ll conc=1;
for(ll i=0;i<m;i++){
	ll ff = t[i]-'a';
	if(f[ff].empty()){
		cout<<-1;
		return 0;
	}
	auto it = upper_bound(all(f[ff]),pre);
	if(it == f[ff].end()){
		conc++;
		pre = ff[f].front();
	}
	else{
		pre = *it;
	}
}
cout<<(conc-1)*n+pre+1;
return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    long x;
    cin >> x;

    long d = 100;

    ll year = 0;
    while(1) {
        year ++;
        d = d * (1 + 0.01);
        if(d >= x) {
            cout << year << endl; 
            return 0;
        }
    }
    
    return 0;
}
/** atcoder **/


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

main(){
    while(1){
        int n;cin>>n;
        if(!n)exit(0);
        vector<set<int>> v;
        rep(i,n){
            int m;cin>>m;
            v.push_back(set<int>());
            rep(_,m){
                int x;cin>>x;
                v.back().insert(x);
            }
        }
        int k;cin>>k;
        set<int> s;
        rep(i,k){
            int x;cin>>x;
            s.insert(x);
        }
        bool flag=false;int pre;
        rep(i,n){
            bool f=true;
            for(auto e:s){
                f&=(v[i].count(e)>0);
            }
            if(f){
                if(flag){
                    cout<<-1<<endl;
                    goto end;
                }
                else{
                    flag = true;
                    pre = i+1;
                }
            }
        }
        if(flag){
            cout<<pre<<endl;
        }
        else cout<<-1<<endl;
        end:;
    }
}


Measured memory_bytes: 3516
n,a,b = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
x.sort!
ans = 0
(0..(n-2)).each do |i|
  if((t = ((x[i+1] - x[i])*a)) > b)
    ans += b
    next
  else
    ans += t
    next
  end
end
puts ans

Measured memory_bytes: 10232
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}




int main() {
  ll n, z,w;
  cin >>n >>z >>w;

  vector<ll> a(n);

  cin >> a;

  ll lastval = a[n-1];


  //nはたった2000

  vector<ll> b(n);
  for (int i = 0; i < n; ++i){
    b[i] = abs(a[i]-lastval);
  }

  ll ans = 0;
  ll xscore = abs(lastval - w);
  ll yscore = abs(lastval - z);

  if (n==1){
    ans = abs(lastval - w);
  }else{
    ans = max(abs(lastval - w) ,abs(lastval - a[n-2]) );
  }




  cout << ans << endl;




}




















Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	if N == 1 && M == 1 {
		fmt.Printf("1\n")
		return
	}
	if N == 1 {
		fmt.Printf("%d\n", M - 2)
		return
	}
	if M == 1 {
		fmt.Printf("%d\n", N - 2)
		return
	}
	fmt.Printf("%d\n", N * M - 2 * (N + M) + 4)
}


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

int solve(int *arr,int n,int *dp)
{
if(n <0) return INT_MAX;
if(n==1) return 0;
if(n==2) return abs(arr[1]-arr[0]);

if(dp[n]==-1)
{
int first=abs(arr[n-1]-arr[n-2])+solve(arr,n-1,dp);
int second=abs(arr[n-1]-arr[n-3])+solve(arr,n-2,dp);

dp[n]= min(first,second);
}
return dp[n];

}

int main()
{
    int n; cin>>n;
    int arr[n];
    int dp[n+1];
    for(int i=0;i<=n;i++) dp[i]=-1;
    for(int i=0;i<n;i++) cin>>arr[i];

    int ans=solve(arr,n,dp);
    cout<<ans<<endl;


    return 0;
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

bool func(ll n) {
	for (ll i = 1; i * i <= n; i++) {
		if (i * i == n) {
			return true;
		}
	}
	return false;
}

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> n;

	ll sum;
	ll b, c, d;
	V ans(1000000,0);
	ll high = sqrt(n);
	rep1(x, high) {
		rep1(y, high) {
			rep1(z, high) {
				sum = x * x + y * y + z * z + x * y + y * z + z * x;
				ans[sum]++;
			}
		}
	}

	rep(i, n) {
		cout << ans[i + 1] << "\n";
	}
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


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

int n, l;
vector<string>s;
void solve(){
    cin >> n >> l;
    for(int i=0;i<n;++i) {
        string t;
        cin >> t;
        s.push_back(t);
    }
    sort(s.begin(), s.end());
    for(string i:s)
        cout << i ;
    cout << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	s[k-1] = tolower(s[k-1]);
	cout<<s;
	return 0;
}

Measured memory_bytes: 3616