akhauriyash/Code-Regression huggingface dataset:
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
int sum(int n){return n * (n + 1)/ 2;}

void main(){
	int x,y,s;
	while(read(x,y,s),x|y|s){
		int ans ;
		auto taxed= iota(s).map!(i => tax(x,i)).array.assumeSorted;
		foreach(i;1..s){			
			foreach(j;i..s){
				if (taxed[i] + taxed[j] == s ){
					ans = max(ans,tax(y,i) + tax(y,j));break;
				}
			}
		}
		ans.writeln;
	}
}
int tax(int per,int yen) {return yen * (100 +per) / 100;}

Measured memory_bytes: 2928
#include<stdio.h>

int main()
{
    int N, i, change;
    scanf("%d",&N);
    if(N%1000==0)
        printf("0");
    else
    {
        i=N/1000;
        i=(i+1)*1000;
        change=i-N;
        printf("%d",change);
    }
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int n;
    cin >> n;
    vi v;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(a);
        sum += a;
    }
    sort(bn(v));
    int w = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] % 10 == 0) {
            w++;
        }
        if (w == v.size()) {
            cout << 0 << "\n";
            return;
        }
        if (sum % 10 == 0) {
            if ((sum - v[i]) % 10 != 0) {
                sum -= v[i];
            }
        } else {
            cout << sum << "\n";
            return;
        }
    }
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,k,a[105];
bool dp[N];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=0;i<=k;i++)
	{
		if(i<a[1])
		{
			dp[i]=false;
			for(int j=1;j<=n;j++)
				if(i+a[j]<=k)
					dp[i+a[j]]=true;
		}
		else
		{
			if(!dp[i])
				for(int j=1;j<=n;j++)
					if(i+a[j]<=k)
						dp[i+a[j]]=true;
		}
	}
	cout<<((dp[k])?"First":"Second");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;
vector<int> h;
ll memo[MAXN];
int n;

ll dp (int i) {
    if (i == 0)
        return 0;
    if (memo[i] != -1)
        return memo[i];
    
    if (i > 1) 
        memo[i] = min(dp(i-1) + abs(h[i]-h[i-1]), dp(i-2) + abs(h[i]-h[i-2]));
    else
        memo[i] = dp(i-1) + abs(h[i]-h[i-1]);
    return memo[i];
}

int main() {
    int x;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> x, h.pb(x);
    memset(memo, -1, sizeof(memo));
    ll ans = dp(n-1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 10872
def break_number(N: int)->int:
    freq = [0] * (N+1)
    freq[0] = -float('inf')
    d = 2
    while d <= N:
        i = d
        while i <= N:
            freq[i] += 1
            i += d
        d <<= 1

    return freq.index(max(freq))


if __name__ == "__main__":
    N = int(input())
    ans = break_number(N)
    print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, q;
string s;
vector<char> t, d;

int f(ll x) {
    if(x == -1) return -1;
    if(x == n) return 1;
    rep(i, q) {
        if(t[i] == s[x]) x += (d[i] == 'R' ? 1 : -1);
        if(x == -1) return -1;
        if(x == n) return 1;
    }
    return 0;
}

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

    cin >> n >> q >> s;
    t.resize(q);
    d.resize(q);
    rep(i, q) cin >> t[i] >> d[i];
    ll l = -1, r = n;
    while(l < r - 1) {
        ll mid = l + r >> 1;
        (f(mid) == -1 ? l : r) = mid;
    }
    ll num = r;
    l = -1;
    r = n;
    while(l + 1 < r) {
        ll mid = l + r >> 1;
        (f(mid) == 1 ? r : l) = mid;
    }
    cout << r - num << endl;

    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(){
    int n, a;
    cin >> n;
    int A[100010] = {0};
    for (int i = 0; i < n; i++) {
        cin >> a;
        A[a]++;
    }
    int ans = 0;
    for (int i = 1; i < 100000; i++) {
        int cnt = A[i-1] + A[i] + A[i+1];
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
function Main (input){
  input = input.split("\n");
  tmp = input[0].split(" ");
  var A = parseInt(tmp[0],10);
  var B = parseInt(tmp[1],10);
  if(A >= 10 || B >= 10){
    console.log(-1);
  }else{
    console.log(A*B);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
# include <stdio.h>
#define N 100
 

int main(){
int A[N];
int n;
 int i,j,count=0,tmp;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
     }
  
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
     if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
     
	count++;
     }
    }
  }
     
    
  

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


  return 0;
}



Measured memory_bytes: 2048
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    int ans = 0;
    for(int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
      ans += (a[i] - 1);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int INF = 1000000000;

int main(){
	int n;
	ci(n);
	int ans=0;
	if(n<=99){
		if(n<=9){
			ans=n;
		}
		else{
			ans=9;
		}
	}
	else if(n>=100 && n<=999){
		ans=9+(n-100+1);		
	}
	else if(n>=1000 && n<=9999){
		ans=9+900;
	}
	else if(n>=10000 && n<=99999){
		ans=9+900+(n-10000+1);
	}
	else{
		ans=9+900+90000;
	}
	co(ans);
}


Measured memory_bytes: 256
import numpy as np

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

if a[0] == 1:
  print(1)
  exit()
  
log = np.full(n, -1)
log[0] = 0
step = 0
now = 0
flag = 0
while step < k:
  now = a[now] - 1
  step += 1
  if log[now] != -1:
    flag = 1
    break
  else:
    log[now] = step

if flag == 0:
  print(now+1)
  exit()

loop = step - log[now]
remain = k - step
if remain > loop:
  remain = remain % loop

for i in range(remain):
  now = a[now] - 1
print(now+1)
    

Measured memory_bytes: 50980
#include<cstdio>
#include<iostream>
using namespace std;
int a[105];
int num[105];
int main()
{
	int N,M,n,m,sum=0;
	cin>>N;
	for(int i =1;i<=N;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	cin>>M;
	for(int i =1;i<=M;i++)
	{
	   cin>>m>>n;
	   num[i] = sum-a[m]+n;	
	}
	for(int i =1;i<=M;i++)
      cout<<num[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
#encoding: utf-8

$n = gets.to_i
$ans = 0

# mが七五三数になっていて、n以下かどうか
def check(m)
  flg3 = false
  flg5 = false
  flg7 = false

  mstr = m.to_s
  (0..mstr.size-1).each do |i|
    if mstr[i] == '3'
      flg3 = true
    elsif mstr[i] == '5'
      flg5 = true
    elsif mstr[i] == '7'
      flg7 = true 
    end
  end

  return (flg3 && flg5 && flg7 && (m <= $n)) 
end

def dfs(m)
  $ans += 1 if check(m) == true 
  if m <= 1000000000
    dfs(10*m + 3) 
    dfs(10*m + 5) 
    dfs(10*m + 7) 
  end
end

dfs(0)
puts $ans



Measured memory_bytes: 1916
#include <iostream>

using namespace std;

unsigned long long f[9] = { 0, 1, 1, 2, 3, 5, 8, 13, 21 };

unsigned long long X_i(int i, int w)
{
	return f[i - 1] * f[w - i + 1];
}

unsigned long long Y_i(int i, int w)
{
	return f[i] * f[w - i + 1];
}

unsigned long long Z_i(int i, int w)
{
	return f[i] * f[w - i];
}

int main()
{
	unsigned  int h, w, k;

	cin >> h >> w >> k;

	unsigned long long A[101][10] = {};

	A[0][1] = 1;

	unsigned long long mod = 1000000007;

	for (int i = 0; i < h; ++i)
	{
		for (int j = 1; j < w + 1; ++j)
		{
			A[i + 1][j - 1] += (X_i(j, w) * A[i][j]);
			A[i + 1][j - 1] %= mod;

			A[i + 1][j] += (Y_i(j, w) * A[i][j]);
			A[i + 1][j] %= mod;

			A[i + 1][j + 1] += (Z_i(j, w) * A[i][j]);
			A[i + 1][j + 1] %= mod;
		}
	}

	cout << A[h][k];

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long sum = 0;
		for(int i=0;i<N-1;i++) sum += Math.Min(B,A*(X[i+1] - X[i]));
		Console.WriteLine(sum);
		
		
	}
	int N;
	long A,B;
	long[] X;
	public Sol(){
		var d = ria();
		N = d[0]; A = d[1]; B = d[2];
		X = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 20832
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[200];
int main(){
    int a;
    scanf("%d",&a);
    for(int i=0;i<(a*(a-1)/2);i++){
        int b,c,d,e;
        scanf("%d%d%d%d",&b,&c,&d,&e);
        b--;c--;
        if(d>e)p[b]+=3;
        else if(e>d)p[c]+=3;
        else {p[b]++;p[c]++;}
    }
    for(int i=0;i<a;i++){
        int num=1;
        for(int j=0;j<a;j++){
            if(p[j]>p[i])num++;
        }
        printf("%d\n",num);
    }
}


Measured memory_bytes: 2760
import java.util.*;

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int num = 0;
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < array.length; j++) {
                num += (i - array[j]) * (i - array[j]);
            }
            if (min > num){
                min = num;
            }
            num = 0;
        }

        System.out.println(min);


    }


}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
struct Node {
    ll cn = 0;
    bool vis = 0;
    vector<ll> cl;
};
ll n, q;
Node u[210000];

void dfs(ll c, ll cnt){
    u[c].cn += cnt;
    u[c].vis = 1;

    ll s = u[c].cl.size();
    rep(i,s){
        ll chil = u[c].cl[i];
        ll clcnt = u[c].cn;
        if(!u[chil].vis)dfs(chil, clcnt);
    }

    return;
}
int main(){
    cin >> n >> q;

    rep(i,n-1){
        ll a, b;
        cin >> a >> b;
        u[a].cl.push_back(b);
        u[b].cl.push_back(a);
    }
    rep(i,q){
        ll p, x;
        cin >> p >> x;
        u[p].cn += x;
    }

    /*REP(i,1,n+1){
        cout << u[i].cn << "    ";
        ll m = u[i].cl.size();
        rep(j,m)cout << u[i].cl[j] << " ";
        cout << endl;
    }*/

    dfs(1, 0);

    REP(i,1,n+1)cout << u[i].cn << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 26240
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 8) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	const int cm = 1 << 21;
	char cn[cm], * ci = cn;
	fread(cn, 1, cm, stdin);

	int N = 0;
	while (*ci >= '0') N = N * 10 + *ci++ - '0';
	ci++;

	ll s[100000];
	rep(i, N) {
		sort(ci, ci + 10);
		ll k = 0;
		rep(j, 10) {
			k *= 26;
			k += *ci++ - 'a';
		}
		ci++;
		s[i] = k;
	}

	pakuri_sort(N, s);

	ll kotae = 0;
	ll mae = -1;
	ll kazu = 0;
	rep(i, N) {
		if (mae != s[i]) {
			kotae += kazu * (kazu - 1) / 2;
			mae = s[i];
			kazu = 1;
		}
		else kazu++;
	}

	kotae += kazu * (kazu - 1) / 2;

	printf("%lld", kotae);

	Would you please return 0;
}

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

int main() {
  int n,af;
  cin >> n >>af;
  int mini=af;
  int maxi=af;
  long long sumi=af;
    
  for(int i = 0; i < n-1; i++){
    int a;
    cin >> a;
    if(mini > a) mini=a;
    if(maxi < a) maxi=a;
    sumi+=a;  
  }
  cout << mini <<" "<< maxi<<" " << sumi<<endl;
  
}


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

signed main(){
  int H,W;
  cin>>H>>W;
  int ans=1000000000;
  if(H%3==0||W%3==0)ans=0;
  else ans=min(H,W);
  std::vector<int> v(3);
  for(int i=1;i<H;i++){
    v[0]=W*i;
    v[1]=(H-i)*(W/2);
    v[2]=(H-i)*((W+1)/2);
    sort(v.begin(),v.end());
    ans=min(ans,v[2]-v[0]);
  }
  for(int i=1;i<W;i++){
    v[0]=H*i;
    v[1]=(W-i)*(H/2);
    v[2]=(W-i)*((H+1)/2);
    sort(v.begin(),v.end());
    ans=min(ans,v[2]-v[0]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import collections as cc
import itertools as it
import bisect as bi
I=lambda:list(map(int,input().split()))
n,m,k=I()
a=I()
b=I()
a=[0]+list(it.accumulate(a))
b=[0]+list(it.accumulate(b))
ans=0
for i in range(n+1):
	if k-a[i]<0:
		break
	x=bi.bisect_right(b,k-a[i])
	ans=max(ans,i+x-1)
print(ans)


Measured memory_bytes: 138648
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

//入力
int a,b,c,n ;

int main() {

	cin >> a >> b >> c;

	cout << min({ a + b,b + c,c + a }) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		boolean first = true;
		for(;;) {
			int n = sc.nextInt();
			if( n == 0) break;
			if(first) {
				first = false;
			}
			else System.out.println();
			P[] ps = new P[n];
			for(int i=0;i<n;i++) 
				ps[i] = new P(sc.next(), sc.nextInt()*3 + sc.nextInt()*0 + sc.nextInt()*1, i);
			sort(ps);
			for(int i=0;i<n;i++) System.out.println(ps[i].s + "," + ps[i].p);
		}
	}
	
	class P implements Comparable<P> {
		String s;
		int p, i;
		P(String s, int p, int i) {
			this.s = s;
			this.p = p;
			this.i = i;
		}
		@Override
		public int compareTo(P o) {
			// TODO Auto-generated method stub
			if(p != o.p) return o.p-p;
			return i - o.i;
		}
		
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 20572
H, W = map(int, input().split())
lst = []
for _ in range(H):
    lst.append(input())

for i in range(H):
    for j in range(W):
        if lst[i][j] == "#":
            if (
                (j > 0 and lst[i][j - 1] != "#")
                and (j < W - 2 and lst[i][j + 1] != "#")
                and (i > 0 and lst[i - 1][j] != "#")
                and (i < H - 2 and lst[i + 1][j] != "#")
            ):
                print("No")
                exit()
print("Yes")


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

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

    int N;
    ll M, Q;
    cin >> N >> M >> Q;

    int L[M+1], R[Q+1];
    int x[N+1][N+1] = {}; //R,Lをx,y軸として区間に応じた2次元平面上の点における各列車の数
    int c[N+1][N+1] = {}; //累積和格納用
    for (int i = 1; i < M+1; i++) {
        cin >> L[i] >> R[i];
        x[L[i]][R[i]]++;
    }

    //累積和計算
    for (int i = 1; i < N+1; i++) {
        for (int j = 1; j < N+1; j++) {
            c[i][j] = c[i][j - 1] + x[i][j];
        }
    }

    for (int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;

        int ans = 0;
        for (int j = p; j <= q; j++) {
            ans += c[j][q] - c[j][p - 1];
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 4096
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			Set<Integer> a = new TreeSet<>();
			for(int i = 0; i < n; i++) {
				a.add(sc.nextInt());
			}
			int m = sc.nextInt();
			for(int i = 0; i < m; i++) {
				a.add(sc.nextInt());
			}

			a.forEach(num -> System.out.println(num));
		}
	}
}


Measured memory_bytes: 192084
n,a,b=gets.chomp.split(" ").map(&:to_i)
arr = gets.chomp.split('')
pas = 0;pas_b = 0
n.times do |k|

  if arr[k] == 'a' && pas < a+b
    puts "Yes"
    pas += 1
  elsif arr[k] == 'b' && pas < a+b && pas_b < b
    puts "Yes"
    pas_b += 1
    pas += 1
  else
    puts "No"
  end
end

Measured memory_bytes: 22592
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    string s1,s2;
    cin >> s1;
    cin >> s2;
    int cnt=0;
    for(int i=0;i<3;i++)    if(s1[i]==s2[i])    cnt++;
    cout << cnt << endl;
}

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

#define ll long long int
#define fir first
#define sec second
#define endl '\n'
ll const mod = 1e9 + 7;

ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}

ll MIN(ll a, ll b) {
    if(a<b) return a;   return b;
}

ll MAX(ll a, ll b) {
    if(a>b) return a;   return b;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll a, b, n;
    cin>>a>>b>>n;
    
    if(n<b)
    {
        cout<<(a*n)/b - a*(n/b);
    }
    else
    {
        n=b-1;
        cout<<(a*n)/b - a*(n/b);
    }
    cout<<endl;
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
char *P[]={"No","Yes"};
char f;

char s[101], t[201], c;
int n, i, j;
int main(){
  while((c=getchar())!=10){s[n++]=c;}
  while((c=getchar())!=10){t[i]=c;t[n+i++]=c;}
  for(i=0; i<n; i++){
    f=1;
    for(j=0; j<n; j++){
      if(s[j]!=t[i+j]){f=0; break;}
    }
    if(f){break;}
  }
  puts(P[f]);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  long long S,C,cnt=0;
  cin>>S>>C;
  if(S==0&&C<4||C<2){
    cout<<"0"<<endl;
    return 0;
  }else if(C/2<=S){
    cnt+=C/2;
  }else{
    cnt+=S;
    C-=2*S;
    cnt+=C/4;
  }
  cout<<cnt<<endl;
  return 0;
}


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

using namespace std;

int main(){
 int n,m;
  cin >> n >> m;
  
  vector<int> a(n),b(n),c(m),d(m),index(n);
  
  for(int i=0;i<n;i++) cin >> a[i] >> b[i];
  for(int i=0;i<m;i++) cin >> c[i] >> d[i];

  for(int i=0;i<n;i++){
    int dis=1000000000;
    for(int j=m-1;j>=0;j--){
      int man=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dis>=man){
       dis=man;
       index[i]=j+1;
      }
    }
  }
   for(int i=0;i<n;i++) cout << index[i] << endl;    
  
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> as(n); cin >> as;
    auto calc = [&](int i, int use){ 
        ll cnt = 0;
        for(auto a : as){
            cnt += a >> i & 1;
        }
        return (1ll << i) * max(cnt, use * (n - cnt));
    };
    ll ans = 0;
    ll acc = 0;
    for(int h = 50; h >= 0; h--){
        if(k >> h & 1){
            ll cand = acc;
            for(int i = 0; i < h; i++){
                cand += calc(i, 1);
            }
            cand += calc(h, 0);
            ans = max(ans, cand);
            acc += calc(h, 1);
        }else{
            acc += calc(h, 0);
        }
        printde(ans, acc, h);
    }
    ans = max(ans, acc);
    cout << ans << '\n';
}


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

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 

int main() {
    ios_base::sync_with_stdio(false);
    ll n,x=1,s;
    cin >> n;
    ll mn=n-1;
    while (x*x <= n) {
        if (n%x == 0) {
            s = (x-1) + (n/x - 1);
            if (s < mn) mn = s;
        }
        x++;
    }
    cout << mn << '\n';
    return 0;

    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

Measured memory_bytes: 384
N, K = map(int, input().split())
x = N % K

s = {x}
if 0 in s:
    ans = 0
else:
    while True:
        x = abs(x - K)
        if x == 0:
            ans = 0
            break
        if x in s:
            ans = min(s)
            break
        s.add(x)

print(ans)

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


int n;
int dp[100009];
int arr[100009];
int solve(int idx) {
	if(idx == n - 1)
		return 0;

	if(dp[idx] != -1)
		return dp[idx];

	int ans = INT_MAX;

	ans = min(ans, abs(arr[idx + 1] - arr[idx]) + solve(idx + 1));
	if(idx + 2 < n)
		ans = min(ans, abs(arr[idx + 2] - arr[idx]) + solve(idx + 2)); 

	return dp[idx] = ans;
		
}


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

	cout<<solve(0)<<endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    set<int> st;
    REP(i,n){
        int x;
        cin >> x;
        st.insert(x);
    }
    cout << st.size() << endl;

    return 0;
}





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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long M = 1e9 + 7;
	int n;
	cin >> n;
	int a[n];
	long long total = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		total += a[i];
	}
	long long ans = 0;
	for (int i = 0; i < n-1; i++) {
		total -= a[i];
		ans += ((a[i] % M) * (total % M)) % M;
	}
	ans = ans % M;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4424
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)

int main() {

	int N; cin >> N;
	
	set<int> a;

	for (int i = 0; i < N; i++) {
		int buf; cin >> buf;
		a.insert(buf);
	}

	if (a.size() % 2 == 1) {
		cout << a.size() << endl;
	}
	else {
		cout << a.size() - 1 << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n+2);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    ll sum = 0;
    for (int i = 0; i <= n; ++i) {
        sum += abs(a[i+1] - a[i]);
    }

    for (int i = 1; i <= n; ++i) {
        ll tmp = sum;
        tmp += abs(a[i-1] - a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]));
        cout << tmp << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
// 2013/11/25 Tazoe

#include <iostream>
using namespace std;

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

	int P[101];
	for(int i=1; i<=N; i++){
		P[i] = 0;
	}

	for(int i=0; i<N*(N-1)/2; i++){
		int A, B, C, D;
		cin >> A >> B >> C >> D;

		if(C>D){
			P[A] += 3;
		}
		else if(C<D){
			P[B] += 3;
		}
		else{
			P[A] += 1;
			P[B] += 1;
		}
	}

	for(int i=1; i<=N; i++){
		int cnt = 0;

		for(int j=1; j<=N; j++){
			if(P[i]<P[j]){
				cnt++;
			}
		}

		cout << cnt+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(date, LastDay, type, score):
  res = score
  res += s[date-1][type]
  for i in range(26):
    if i == type:
      continue
    res -= (date - LastDay[i]) *c[i]
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]
ans = [I() for i in range(D)]

LastDay = [0]*26
score = 0
for d in range(D):
  score = tami(d+1, LastDay, ans[d]-1, score)
  LastDay[ans[d]-1] = d+1
  print(score)

Measured memory_bytes: 77696
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int main(int argc, const char * argv[]) {
        int i, j, k;
        int A = 0;
        int B = 0;
        int K = 0;

        scanf("%d %d", &A, &B);

        if(A > B){ k=A;}
        else{ k=B;}

        for(i=0; i<k; i++){
                if(abs(A-i) == abs(B-i)){
                        cout<< i << endl;
                        return 0;
                }
        }

        cout<< "IMPOSSIBLE" << endl;

        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <utility>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    map<string, int> memo;
    string S;
    for (int i = 0; i < N; i++)
    {
        cin >> S;
        memo[S]++;
    }

    int max = 0;
    int v;
    for (const auto& x : memo)
    {
        v = x.second;
        if (v > max) max = v;
    }
    
    for (auto itr = memo.begin(); itr != memo.end(); itr++)
    {
        if (itr->second == max)
        {
            cout << itr->first << endl;
        }
        
    }

    return 0;
}


Measured memory_bytes: 17664
N = int(input())
A = [[0,0,0]]
for i in range(N):
    A.append(list(map(int,input().split())))
for i in range(1,N+1):
    t,x,y = A[i][0],A[i][1],A[i][2]
    pt,px,py = A[i-1][0],A[i-1][1],A[i-1][2]
    #print(t,x,y,pt,px,py)
    if (abs(x-px)+abs(y-py)) > t-pt or (abs(x-px)+abs(y-py))%2 != (t-pt)%2:
        print("No")
        exit()
print('Yes')

Measured memory_bytes: 27324
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	string s;
	cin >> s;
	cout << s.substr(0, 3) << endl;

	return 0;
}


Measured memory_bytes: 3580
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????§???¢
????§???¢????????? a, b ??¨?????????????§? C ?????????
??????????§???¢?????¢??? S?????¨????????? L, 
a ???????????¨????????¨???????????? h 
????±???????????????°?????????????????????????????????
"""
import math
a, b, C = map(float,input().strip().split())
theta = math.radians(C) # ?????????????????¢??????
h = math.sin(theta) * b
S = a * h / 2
a1 = math.cos(theta) * b
a2 = a - a1
x = math.sqrt((h * h) + (a2 * a2))
L = a + b + x

print(S)
print(L)
print(h)

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

bool isRestorable(string &s, const string t){
    for(int i=s.size()-1; i>=0; i--){
        unsigned int count = 0;
        for(int j=i; j>=0; j--){
            if(s[j] == '?' || s[j] == t[t.size()-1-count]) count++;
            else break;
            if(count==t.size()){
                for(unsigned int k=0; k<t.size(); k++){
                    s[j+k] = t[k];
                }
                return true;
            }
        }
    }
    return false;
}
int main(){
    string s, t; 
    cin >> s >> t;

    bool is_find =isRestorable(s,t);

    if(!is_find){
        cout << "UNRESTORABLE" << endl;
    } else {
        for(unsigned int i=0; i<s.size(); i++){
            if(s[i] == '?') s[i] = 'a';
        }
        cout << s << endl;
    }
}


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

signed main(){
  int A,B,C,co=0;
  cin>>A>>B>>C;
  if(A==B&&B==C&&A==C){
    if(A%2==0&&B%2==0&&C%2==0)co=-1;
    else co=0;
    cout<<co<<endl;
    return 0;
  }
  int Al=0,Bl=0,Cl=0;
  rep(i,1e9+7){
    if(A%2==1||B%2==1||C%2==1)break;
    Al=(B+C)/2;
    Bl=(A+C)/2;
    Cl=(A+B)/2;
    A=Al;
    B=Bl;
    C=Cl;
    co++;
  }
  cout<<co<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int a,b,c,d;
    cin >> a >> b >> c >> d;


    cout << ((abs(b - a) <= d && abs(c - b) <= d || abs(c - a) <= d) ? "Yes" : "No") << endl;

    return 0;
}


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

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

bool flag[10000001];
int main()
{
  int n = 0;
  for (int i = 0; i <= 1000000; i++){
    if (i <= 1) flag[i] = false;
    else flag[i] = true;
  }
  for (int i = 2; i <= 1001; i++){
    if(flag[i] == true){
      for(int j = i * 2; j <= 1000000; j += i){
        flag[j] = false;
      }
    }
  }
  while(cin >> n, n){
    int cnt = 0, sum = 0;
    for(int i = 1; i < 10000001; i++){
      if (cnt >= n) break;
      if(flag[i] == true){
        sum += i;
        cnt++;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 2136
import heapq

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
A = [-a for a in A]
B = sorted(list(map(int, input().split())), reverse=True)
B = [-b for b in B]
C = sorted(list(map(int, input().split())), reverse=True)
C = [-c for c in C]

checked = []

h = []
heapq.heappush(h, (A[0]+B[0]+C[0], 0, 0, 0))
for _ in range(K):
    val, i, j, k = heapq.heappop(h)
    print(- val)
    if i+1 < X and (i+1, j, k) not in checked:
        heapq.heappush(h, (A[i+1] + B[j] + C[k], i+1, j, k))
        checked.append((i+1, j, k))
    if j+1 < Y and (i, j+1, k) not in checked:
        heapq.heappush(h, (A[i] + B[j+1] + C[k], i, j+1, k))
        checked.append((i, j+1, k))
    if k+1 < Z and (i, j, k+1) not in checked:
        heapq.heappush(h, (A[i] + B[j] + C[k+1], i, j, k+1))
        checked.append((i, j, k+1))

Measured memory_bytes: 4596
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e5 + 20;
int post[MAXN][26] = {};

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

    string s, t;
    int ns, nt;
    cin >> s;
    cin >> t;
    ns = s.size();
    nt = t.size();

    for(int i = 0; i < MAXN; i++)
    	for(int j = 0; j < 26; j++) 
    		post[i][j] = -1;

    unordered_map<char, int> mp;
    for(int i = ns - 1; i >= 0; i--) {
    	mp[s[i]] = i + ns;
    }
    for(int i = ns - 1; i >= 0; i--) {
    	for(char c = 'a'; c <= 'z'; c++) {
    		if(mp.count(c))
		    	post[i][c - 'a'] = mp[c] - i;
    	}
	    mp[s[i]] = i;
    }
    if(!mp.count(t[0])) {
    	cout << -1 << endl;
    	return 0;
    }
    long long cur = mp[t[0]], res = mp[t[0]];
    for(int i = 1; i < nt; i++) {
    	//cout << cur << endl;
    	if(post[cur][t[i] - 'a'] == -1) {
    		cout << -1 << endl;
    		return 0;
    	}
    	res += post[cur][t[i] - 'a'];
    	cur = res % ns;
    }
    cout << res + 1 << endl;


    return 0;
}











Measured memory_bytes: 10704
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

  int main(){
      ll N,X,m[1001],cnt=0;
      cin>>N>>X;
      rep(i,N) cin>>m[i];
      rep(i,N) X-=m[i];
      sort(m,m+N);
      cnt=X/m[0];
      p(N+cnt);

  }
 

Measured memory_bytes: 256
using System;

namespace ITP1_5_A {
    class Program {
        static void Main(string[] args) {
            while(true) {
                string[] s = Console.ReadLine().Split(' ');
                int H = int.Parse(s[0]), W = int.Parse(s[1]);
                if(H == 0 && W == 0) break;
                for(int i = 0; i < H; i++) {
                    for(int u = 0; u < W; u++) {
                        Console.Write("#");
                        if(u == W - 1) Console.Write("\n");
                    }
                }
                Console.Write("\n");
            }
        }
    }
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,k,l,m,n,a[100005];
    pair<int,int>p[100005];
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++)
    scanf("%d%d",&p[i].first,&p[i].second);
    sort(p,p+m);
    k=p[0].first;
    l=p[0].second;
    int count=1;
    for(i=1;i<m;i++)
    {
        if(p[i].first>=l)
        {
            count++;
            k=p[i].first;
            l=p[i].second;
        }
        else
        {
            k=p[i].first;
            l=min(l,p[i].second);
        }
    }
    printf("%d",count);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n,k;

ll f(ll x){
  if(x==0) return 0;
  ll cnt=1,res=0;
  for(ll i=10;i<1000000000000000;i*=10,cnt++){
    if(x<i){
      res+=cnt*(x-(i/10)+1);
      break;
    }else{
      res+=cnt*(i-(i/10));
    }
  }
  return res;
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>n>>k;
    if(n==0)break;
    ll lb=0,ub=100000000000000000;
    while(ub-lb>1){
      ll mid=(ub+lb)/2;
      if(f(mid)<n)lb=mid;
      else ub=mid;
    }
    string s;
    for(ll i=1;s.length()<200;i++){
      s+=to_string(lb+i);
    }
    cout<<s.substr(n-f(lb)-1,k)<<endl;
  }
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n),b(n);
  long long sum=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  long long s=0;
  for(int i=1;i<n;i+=2){
    s+=2*a[i];
  }
  b[0]=sum-s;
  for(int i=1;i<n;i++){
    b[i]=a[i-1]*2-b[i-1];
  }
  for(int i=0;i<n-1;i++){
    cout << b[i] << ' ';
  }
  cout << b[n-1] << endl;
}

Measured memory_bytes: 2944
//ABC-87-B
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
struct WeightedUnionFind{
    vector<int> par,siz;
    vector<T> ws;

    WeightedUnionFind(int n) : par(n), siz(n, 1), ws(n, T(0)){
        iota(par.begin(), par.end(), 0);
    }

    int root(int x){
        if(par[x] == x) return x;
        int t = root(par[x]);
        ws[x] += ws[par[x]];
        return par[x] = t;
    }

    T weight(int x){
        root(x);
        return ws[x];
    }

    void unite(int x, int y, T w){
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x] < siz[y]){
            swap(x, y);
            w = -w;
        }
        siz[x] += siz[y];
        par[y] = x;
        ws[y] = w;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }

    T diff(int x, int y){
        return weight(y) - weight(x);
    }
};

signed main(){
    int n,m;
    cin >> n >> m;
    int l[m],r[m],d[m];
    REP(i,m){
        cin >> l[i] >> r[i] >> d[i];
        l[i]--;
        r[i]--;
    }
    WeightedUnionFind<ll> wuf(n);
    for(int i = 0; i < m; i++){
        if(wuf.same(l[i], r[i]) && wuf.diff(l[i], r[i]) != d[i]){
            cout << "No" << endl;
            return 0;
        }
        wuf.unite(l[i], r[i], d[i]);
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4096