akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

//reference to isikado
public class Main{
	Scanner sc = new Scanner(System.in);
	double r = 6378.1;
	double PI = Math.PI;
	
	class P3D{
		double [] p;
		public P3D(double[] p) {
			this.p = new double[3];
			for(int i =0; i < 3; i++){
				this.p[i] = p[i];
			}
			this.p = p;
		}
	}
	
	private double distance3D(P3D p1, P3D p2) {
		double res = 0;
		for(int i = 0; i < 3; i++){
			res += (p1.p[i] - p2.p[i]) * (p1.p[i] - p2.p[i]);
		}
		return Math.sqrt(res);
	}
	
	private void doit() {
		while(true){
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			double c = sc.nextDouble();
			double d = sc.nextDouble();
			if(a == -1 && b == -1 && c == -1 && d == -1) break;
			double [][] rad = new double[2][2];
			rad[0][0] = a / 180 * PI;
			rad[0][1] = b / 180 * PI;
			rad[1][0] = c / 180 * PI;
			rad[1][1] = d / 180 * PI;
			P3D [] p = new P3D[2];
			for(int i = 0; i < 2; i++){
				double x = r * Math.cos(rad[i][0]) * Math.cos(rad[i][1]);
				double y = r * Math.cos(rad[i][0]) * Math.sin(rad[i][1]);
				double z = r * Math.sin(rad[i][0]);
				p[i] = new P3D(new double[]{x,y,z});
			}
			double dis = distance3D(p[0], p[1]);
			double deg = calcRadA(dis, r, r);
			double ans = deg * r;
			System.out.printf("%.0f\n", ans);
		}
	}

	private double calcRadA(double a, double b, double c) {
		double costheta = (b * b + c * c - a * a) / (2 * b * c); 
		double res = Math.acos(costheta);
		return res;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 20664
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  vector< pair<int,string> >a(m);
  vector<int>b(n+1,0);
  vector<int>ver(n+1);
  for(int i=0;i<m;i++)
  {
    cin>>a[i].first>>a[i].second;
  }
  int ac=0,v=0;
  for(int i=0;i<m;i++)
  {
	if(!b[a[i].first])
    {
      if(a[i].second=="AC")
      {
        b[a[i].first]=1;
        ac++;
      }
      else ver[a[i].first]++;
    }
  }
  for(int i=0;i<ver.size();i++)v+=(b[i])*ver[i];
  cout<<ac<<' '<<v<<endl;
  return 0;
}

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

int main(){
    int n,total=0;

    cin>>n;

    while(n){
        total += n%10;
        n = n/10;
    }

    if(total==1)
        cout<<10<<endl;
    else
        cout<<total<<endl;

    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  char c[2];
  
  scanf("%s", c);
  
  if(c[0] == 'a' || c[0] == 'i' || c[0] == 'u' || c[0] == 'e' || c[0] == 'o'){
    printf("vowel\n");
  } else {
    printf("consonant\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<int> vt;
int n,q;
vector<pair<int,int>> info((1<<18) + 3);
vector<pair<int,int>> res;
#define fi first
#define se second
const int MAX = 100001;
int dp[515][MAX];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	
	for(int i=0;i<n;i++){
		int v,w;
		cin>>v>>w;
		info[i] = make_pair(v,w);
	}
	//preprocess
	const int MAX = 100001;
	int lim = min(512,n);
	
	for(int j=0;j<MAX;j++){
		dp[0][j] = (j>=info[0].se ? info[0].fi : 0);
	}
	for(int i=1;i<lim;i++){
		int p = (i-1)/2;
		for(int j=0;j<MAX;j++){
			if(j<info[i].se){
				dp[i][j] = dp[p][j];
			}else{
				dp[i][j] = max(dp[p][j] , dp[p][j - info[i].se] + info[i].fi);
			}
		}
	}
	
	cin>>q;
	while(q--){
		int V,L;
		cin>>V>>L;
		V--;
		vector<int> rem;
		while(V>=lim){
			rem.push_back(V);
			V = (V-1)/2;
		}
		int ans = 0;
		int sz = rem.size();
		for(int i=0;i<(1<<sz);i++){
			int sv = 0;
			int sw = 0;
			for(int j=0;j<sz;j++){
				if(i>>j&1){
					sv += info[rem[j]].fi;
					sw += info[rem[j]].se;
				}
			}
			if(sw <= L){
				ans = max(ans , dp[V][L-sw] + sv);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}




Measured memory_bytes: 205400
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
typedef long double cdb;
const int maxn = 500005;

int n,L,head,tail;
LL sum,amt[maxn];
cdb tem[maxn],ans;

int main()
{
	#ifdef Amberframe
		freopen("arc072f.in","r",stdin);
		freopen("arc072f.out","w",stdout);
	#endif
	scanf("%d %d",&n,&L);
	for (int t,v,i=1;i<=n;i++) {
		scanf("%d %d",&t,&v);
		while (sum+v>L) {
			if (sum+v-amt[head]<=L) {
				ans-=(sum+v-L)*tem[head];
				amt[head]-=sum+v-L;sum=L-v;
			}
			else {
				ans-=amt[head]*tem[head];
				sum-=amt[head];++head;
			}
		}
		
		sum+=v;ans+=(LL)t*v;
		double curs=(LL)t*v;LL curv=v;
		while (head<=tail&&tem[tail]>curs/curv) {
			curv+=amt[tail];curs+=tem[tail]*amt[tail];--tail;
		}
		amt[++tail]=curv;tem[tail]=curs/curv;
		printf("%.8lf\n",(double)ans/L);
	}
	return 0;
}

Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

operators = {"+": lambda x, y: x + y,
             "-": lambda x, y: x - y,
             "*": lambda x, y: x * y,
             "/": lambda x, y: float(x) / y}


def calculation(A):
    stack = []

    for i in xrange(len(A)):
        if isinstance(A[i], str):
            op_right = stack.pop()
            op_left = stack.pop()
            stack.append(operators[A[i]](op_left, op_right))
        elif isinstance(A[i], int):
            stack.append(int(A[i]))
    return stack[-1]

if __name__ == '__main__':
    A = raw_input().split()
    # A = [1, 2, '+', 3, 4, '-', '*']
    for i in xrange(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print calculation(A)

Measured memory_bytes: 6436
#include <iostream>
#include <vector>
#include <string>

using namespace std;
using i64 = long long int;
using P = pair<i64, i64>;

struct RollingHash{
    i64 m1 = 1000000007, m2 = 1000000009;
    i64 b1 = 1009, b2 = 1007;
    vector<i64> h1, h2, p1, p2;
    RollingHash(string s){
        i64 n = s.length();
        h1.resize(n + 1); h2.resize(n + 1); p1.resize(n + 1); p2.resize(n + 1);
        h1[0] = s[0] % m1;
        h2[0] = s[0] % m2;
        p1[0] = p2[0] = 1;
        for(int i = 0; i < n; ++i){
            h1[i + 1] = (h1[i] * b1 % m1 + s[i]) % m1;
            h2[i + 1] = (h2[i] * b2 % m2 + s[i]) % m2;
            p1[i + 1] = p1[i] * b1 % m1;
            p2[i + 1] = p2[i] * b2 % m2;
        }
    };
    P get(i64 l, i64 r){
        i64 hash1 = (h1[r] + m1 - h1[l] * p1[r - l] % m1) % m1;
        i64 hash2 = (h2[r] + m2 - h2[l] * p2[r - l] % m2) % m2;
        return P(hash1, hash2);
    };
};

int main(){
    string t, p;
    cin >> t >> p;
    if(t.length() < p.length()) return 0;
    RollingHash ht(t), hp(p);
    for(int i = 0; i + p.length() <= t.length(); ++i){
        if(ht.get(i, i + p.length()) == hp.get(0, p.length())) cout << i << endl;
    }
}


Measured memory_bytes: 36124
#include<bits/stdc++.h>
 
using namespace std;
using L = vector<long long>;
using A = vector<vector<long long>>;
using D = deque<long long>;
using M = map<int,long long>;
using Q = priority_queue<long long>;

#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())

//__gcd(a,b)はコンパイラがGCC時のみ


M dijkstra(int n, int point, map<int, A> d){
    M cost;
    for(int i=1  ;i<n+1  ;i++) {
        cost[i]=1e18;
    }
    priority_queue<L,A,greater<L>> q;

    long long nownode,nextnode,nowcost,passcost,newcost;
    
    cost[point]=0;
    q.push( {cost[point],point} );

    while (!q.empty()){
        nowcost=q.top()[0];
        nownode=q.top()[1];
        q.pop();
        if (cost[nownode]<nowcost){  //今costに登録されてる値が現在のその座標のコストより小さいとき
            continue;
        }
        for(auto item_of_d:d[nownode]){
            passcost=item_of_d[1];
            nextnode=item_of_d[0];
            newcost=nowcost+passcost;
            if (cost[nextnode]>newcost){
                cost[nextnode]=newcost;
                q.push({newcost,nextnode});
            }
        }
    }
    return cost;
}


int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  //scanfとかと混ぜるな！
    
    int n,m,a,b,c;
    
    
    cin>>n; //>>m;
    m=n-1;
    map<int,A> d;
    for(int i=0  ;i<m  ;i++){
        cin>>a>>b>>c;
        d[a].push_back({b,c});
        d[b].push_back({a,c});
    }
    
    
    
    int x,y,num,num2;
    cin>>x>>y;
    map<int,long long> costmap=dijkstra(n,y,d);
    for(int i=0  ;i<x  ;i++){
        cin>>num>>num2;
        cout<<costmap[num]+costmap[num2]<<endl;
    }
}


Measured memory_bytes: 51760
#include <iostream>
#define SIZE 1000000
using namespace std;
int l[SIZE+1]={0};
int m[SIZE+1]={0};

int main(){
    int i,n,a=1,b=1,c=1;
    for(i=1;i<SIZE+1;i++){
        l[i]=i;
        m[i]=i;
    }
    while(b<SIZE){
        for(i=0;i+b<SIZE+1;i++){
            l[i+b]=min(l[i+b],l[i]+1);
            if(b%2){m[i+b]=min(m[i+b],m[i]+1);}
        }
        a+=(c+1);
        b+=a;
        c++;
    }
    while(1){
        cin>>n;
        if(!n){break;}
        cout<<l[n]<<" "<<m[n]<<endl;
    }
    return 0;
}



Measured memory_bytes: 10856
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const double PI = 3.14159265359;
typedef pair<int,int> P;

signed main() {
    string S;
    cin >> S;
    vector<int> vec(S.size());
    for(int i = 0;i < S.size();i++) {
        vec.at(i) = S.at(i) - '0';
    }
    int ret2 = 0;
    for(int bit = 0;bit < (1<<S.size() - 1);++bit) {
        vector<int> cnt(S.size() - 1);
        for(int i = 0;i < S.size() - 1;++i) {
            if(bit & (1<<i)) {
                cnt.at(i) = 1;
            }
            else {
                cnt.at(i) = 0;
            }
        }
        int a = vec.at(0);
        int ret = 0;
        for(int i = 0;i < S.size() - 1;i++) {
            if(cnt.at(i) == 1) {
                ret += a;
                a = vec.at(i + 1);
            }
            else {
                a = a * 10 + vec.at(i + 1);
            }
        }
        ret += a;
        ret2 += ret;
    }
    cout << ret2 << endl;
}

Measured memory_bytes: 256
#include <iostream> 
using namespace std; 
int main(){ 
  string s; 
  cin >> s; 
  int ans; 
  if(s == "SUN")ans = 7; 
  else if(s == "MON")ans = 6; 
  else if(s == "TUE")ans = 5; 
  else if(s == "WED")ans = 4; 
  else if(s == "THU")ans = 3; 
  else if(s == "FRI")ans = 2; 
  else if(s == "SAT")ans = 1; 
  cout << ans << endl; 
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String S = sc.next();
        String[] sp = S.split("");
        int[] l = new int[Q];
        int[] r = new int[Q];
        
        int[] sum = new int[sp.length];
        sum[0] = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            if(sp[i-1].equals("A") && sp[i].equals("C")) {
                count++;
                sum[i-1] = count;
            }
            sum[i] = count;
        }
        
        int last = 0;
        int first = 0;
        int ans = 0;
        for(int i = 0; i < Q; i++) {
            first = Integer.parseInt(sc.next());
            last = Integer.parseInt(sc.next());

            first--;
            last--;
            
            
            if(sum[last] == 0) {
                System.out.println(0);
            }else if(first == 0) { //パターン1, 2
                if(sum[last] == sum[last-1]) {
                    if(sum[first] == 0) {
                        System.out.println(sum[last]);
                    }else {
                        System.out.println(sum[last] - sum[first] + 1);
                    }
                    
                }else {
                    if(sum[first] == 0) {
                        System.out.println(sum[last] - 1);
                    }else {
                        System.out.println(sum[last] - sum[first]);
                    }
                }
            }else if(last - first == 1) {
                if(sum[first] == sum[first-1]) {
                    System.out.println(0);
                }else {
                    System.out.println(1);
                }
            }else {
                //➀
                if(sum[first] != sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first] + 1);
                //➁
                }else if (sum[first] != sum[first-1] && sum[last] != sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //➂
                }else if (sum[first] == sum[first-1] && sum[last] == sum[last-1]) {
                    System.out.println(sum[last] - sum[first]);
                //④
                }else {
                    System.out.println(sum[last] - sum[first] - 1);
                }
            }
            
        }
        
    }
}

Measured memory_bytes: 64700
A, B, K = map(int, input().split())
if A+K-1 >= B-K+1:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)   
    for i in range(B-K+1,B+1):
        print(i)     


Measured memory_bytes: 3060
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int n, arr[10002];


void process_l2r(){
    for(int i=2;i<=n;i++)
        cout<<i-1<<" "<<i<<endl;
}


void process_r2l(){
    for(int i=n-1;i>=1;i--)
        cout<<i+1<<" "<<i<<endl;
}


void add(int pos){
    for(int i=1;i<=n;i++)
        if(i != pos)
            cout<<pos<<" "<<i<<endl;
}



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

    cin>>n;
    int maxi = -1e6, mini = 1e6;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        maxi = max(maxi, arr[i]);
        mini = min(mini, arr[i]);
    }

    if(mini >= 0){
        cout<<n-1<<endl;
        process_l2r();
        return 0;
    }

    if(maxi <= 0){
        cout<<n-1<<endl;
        process_r2l();
        return 0;
    }

    int pos = -1;
    for(int i=0;i<n;i++)
        if(maxi > -mini && arr[i] == maxi)
            pos = i;
        else if(maxi <= -mini && arr[i] == mini)
            pos = i;

    cout<<2*(n-1)<<endl;
    add(pos+1);
    if(maxi > -mini)    process_l2r();
    else    process_r2l();
    return 0;
}







Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
typedef pair<int,int> P;
 
int main() {
    int i,j,p,q,temp;
    long long int t=0;
    int flag=0;
    int n=-1;
    string s;
    long long int x,y;
    cin>>x>>y;
    long long int ans;
    if(x%y==0){cout<<-1;}
    else{cout<<x;}
 
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = null;
		Map<String, List<Integer>> index = new TreeMap<String, List<Integer>>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String[] s = stdIn.nextLine().split(" ");
				if( !index.containsKey(s[0]) ){
					List<Integer> list = new ArrayList<Integer>();
					list.add(Integer.parseInt(s[1]));
					index.put(s[0], list);
				} else {
					index.get(s[0]).add(Integer.parseInt(s[1]));
					index.put(s[0], index.get(s[0]));
				}
			}
			
			for(String str : index.keySet()){
				System.out.println(str);
				Collections.sort(index.get(str));
				for(int i = 0; i < index.get(str).size()-1; i++){
					System.out.print(index.get(str).get(i) + " ");
				}
				System.out.println(index.get(str).get(index.get(str).size()-1));
				
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s; cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N, A[20], X[20][20], Y[20][20];
ll mk[20];
ll i, j, k,ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        mk[i] = -1;
        scanf("%lld", &A[i]);
        fornum(j,0,A[i]){
            scanf("%lld%lld", &X[i][j], &Y[i][j]);
            X[i][j]--;
        }
    }
    fornum(i,0,1<<N){
        ll a = __builtin_popcount(i);
        fornum(j,0,N){
            if(i&(1<<j)){
                fornum(k,0,A[j]){
                    ll aa = (i & (1 << X[j][k]));
                    if((aa>0)!=Y[j][k]){
                        break;
                    }
                }
                if(k!=A[j])
                    break;
            }
        }
        //printf("%lld %lld %lld\n", i, j, k);
        if(j==N){
            ans = max(a, ans);
        }
    }
    printf("%lld", ans);
    return 0;
}

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

int main(){
    long long h,ans=1;
    cin >> h;
    int i=0;
    while(true){
        if(h/2!=0){
            i++;
            h=h/2;
        }
        else break;
    }
    i++;
    for(int j=0;j<i;j++){
        ans*=2;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int d, g;
	cin >> d >> g;

	vector<int> p(d), c(d);
	rep(i,d){
		cin >> p[i] >> c[i];
	}

	int ans = 1e9;
	rep(s, 1 << d){
		rep(i,d){
			int point = g;
			int prob = 0;
			if(s >> i bitand 1){
				rep(j,d){
					if(s >> j bitand 1){
						if(i == j) continue;
						prob += p[j];
						point -= (j + 1) * 100 * p[j] + c[j];
					}
				}

				rep(j,p[i]){
					if(point <= 0) break;
					point -= (i + 1) * 100;
					prob++;

					if(j + 1 == p[i]) point -= c[i];
				}

				if(point <= 0){
					//cout << prob << ' ' << s << endl;
					ans = min(ans, prob);
				}
			}
		}
	}
	cout << ans << endl;
}


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

int main()
{
    ll x[5];
    cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

    for(int i = 0; i < 5; i++)
    {
        if(x[i] == 0)
        {
            cout << i+1 << endl;
        }
    }

    return 0;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int ans=3;
	if(a==b){
		if(a==c)ans-=2;
		else ans-=1;
		}
	else if(a==c){
		if(b==c)ans-=2;
		else ans-=1;
		}	
	else if(b==c){
		if(a==b)ans-=2;
		else ans-=1;
		}	
		cout<<ans<<endl;
		return 0;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll n;
    cin >> n;
    if (n<3){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    ll ans = 0;
    ll sho = n / 3;
    ll res = n % 3;
    while (sho>0){
        ans += COM(res+sho-1, res);
        sho--;
        res += 3;
        ans %= MOD;
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 15572
def dfs(land,y,x):
    land[y][x] = '0'
    if y > 0:
        if land[y-1][x] == '1':
            dfs(land,y-1,x)
    if y != 11:
        if (land[y+1][x] == '1'):
            dfs(land,y+1,x)
    if (x > 0):
        if  (land[y][x-1] == '1'):
            dfs(land,y,x-1)
    if (x != 11) :
        if  (land[y][x+1] == '1'):
            dfs(land,y,x+1)

island = []

while True:
    try:
        ss = input()
        if ss :
            island.append(list(ss))
    except:
        break
        
num = int(len(island) / 12)

for i in range(num):
    count = 0
    for j in range(12):
        for k in range(12):
            if (island[i*12+j][k] == '1'): 
                dfs(island[i*12:(i+1)*12],j,k)
                count += 1

    print(count)


Measured memory_bytes: 5584
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<lint> zyo;
lint mo=1000000007;
int main(){
	int n,m;
	cin>>n>>m;
	if(n<m) swap(n,m);
	if(n>m+1){
		cout<<0<<endl;return 0;
	}
	zyo.pb(1);
	rep(i,100100) zyo.pb((zyo[i]*(i+1))%mo);
	if(n==m) cout<<(2*zyo[n]*zyo[m])%mo<<endl;
	else cout<<(zyo[n]*zyo[m])%mo<<endl;
}


Measured memory_bytes: 1908
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
#define Test int t;cin>>t;while(t--)
#define endl "\n"
#define PI acos(-1)
#define sz(x) (x).size()
#define aa(s) (s).begin(),(s).end()
using namespace std;
const int dx[]={-1,-1,-1,0,0,0,1,1,1};
const int dy[]={-1,0,1,-1,0,1,-1,0,1};
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll lcm(ll a,ll b){
    return a*b/__gcd(a,b);
}
bool g[101];
int main()
{
    fast();
    string s;
    cin>>s;
    for(int i=0;i<sz(s);i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s;
    return 0;
}


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> v;
    vector<double> v_ruiseki;
    REP(i, N) {
        int tmp; cin >> tmp;
        v.push_back(tmp);
        if (i==0) v_ruiseki.push_back((tmp+1)*tmp/2/(double)tmp);
        else v_ruiseki.push_back((tmp+1)*tmp/2/(double)tmp+v_ruiseki.back());
    }
    double max_sum_seq_K = 0.0;
    for(int i = K-1; i < N; i++) {
        if (i == K - 1) max_sum_seq_K = max(max_sum_seq_K, v_ruiseki[i]);
        else max_sum_seq_K = max(max_sum_seq_K, v_ruiseki[i] - v_ruiseki[i-K]);
    }
    cout << fixed << setprecision(7) << max_sum_seq_K << endl;
    return 0;
}


Measured memory_bytes: 3052
sx, sy, tx, ty = map(int, input().split())

dist_x = tx - sx
dist_y = ty - sy

res = "R" * dist_x + "U" * dist_y + "L" * dist_x + "D" * dist_y + "D" + "R" * (dist_x + 1) + "U" * (dist_y + 1) + "L" + "U" + "L" * (dist_x + 1) + "D" * (dist_y + 1) + "R"
print(res)

Measured memory_bytes: 61808
#include <iostream>
#include <climits>
#include <vector>
#include <unordered_set>

using namespace std;


int main() {
    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        vector<vector<int>> costs;
        for(int i = 0; i < n; i++) {
            vector<int> cost;
            for(int j = 0; j <= n; j++) {
                int c; cin >> c;
                cost.emplace_back(c);
            }
            costs.emplace_back(cost);
        }
        vector<int> ans(1 << n, INT_MAX);
        ans[0] = 0;
        for(int i = 0; i < (1 << n); i++) {
            for(int next = 0; next < n; next++) {
                if((i & (1 << next)) != 0) continue;
                int cost = costs[next][0];
                for(int item = 0; item < n; item++) {
                    if((i & (1 << item)) != 0 && costs[next][item+1] < cost) {
                        cost = costs[next][item+1];
                    }
                }
                if(ans[i] + cost < ans[i | (1 << next)]) {
                    ans[i | (1 << next)] = ans[i] + cost;
                }
            }
        }
        cout << ans[(1 << n) - 1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3416
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  int a, p;
  while (cin >> a >> p) {
    cout << (a * 3 + p) / 2 << endl;
  }
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, m;
    cin >> n >> m;
    vector<Int> a(m);
    for (Int i = 0; i < (Int)m; i++) {
        cin >> a[i];
    }
    Int sum = accumulate(all(a), (Int)0);
    print(sum > n ? -1 : n - sum);
    return 0;
}

Measured memory_bytes: 3704
import sys
input = sys.stdin.readline



def main():
    N = int(input())
    h = [int(x) for x in input().split()]



    ans = 0
    while len(h) != 0:
        for i in range(len(h) - 1, 0, -1):
            if h[i] == h[i - 1]:
                h.pop(i)

        if len(h) == 1:
            ans += h[0]
            break

        ma = max(h)
        mai = h.index(ma)
        if mai == len(h) - 1:
            ans += ma - h[mai - 1]
        elif mai == 0:
            ans += ma - h[mai + 1]
        else:
            ans += min(ma - h[mai + 1], ma - h[mai - 1])
        h.pop(mai)

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int N, x;
    cin >> N >> x;
    vector<int> a;
    int num;
    for (int i = 0; i < N; i++) {
        cin >> num;
        a.push_back(num);
    }

    sort(a.begin(), a.end());

    int ans = 0;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        if (x >= a[i]){
            x -= a[i];
            ans++;
        } else {
            flag = true;
            break;
        }
    }
    if (!flag && x > 0) {
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[101],i,sum=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n-1;i++)
    {
        sum+=a[i];
    }
    if(a[n-1]<sum)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for a1 in range(0,a+1):
    for b1 in range(0,b+1):
        for c1 in range(0,c+1):
            yen = a1*500 + b1*100 + c1*50
            if yen == x:
                ans += 1
print(ans)

Measured memory_bytes: 39664
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;

  long long int power = 1;
  for (int i = 1; i <= n; i++) {
    power = (power * i) % (1000000000 + 7);
  }

  cout << power << endl;
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	cout<<min(N*A,B)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
L = list(map(int,input().split()))
mod = 10**9 +7

cnt = 0
for i in range(n-1):
    tmp = 0
    for j in range(i+1,n):
        if L[i] > L[j]:
            cnt +=1
cnt2 = 0
li = []
for i in range(n):
    tmp = 0
    for j in range(n):
        if L[i] > L[j]:
            cnt2 +=1

ans = cnt*k%mod
ans += cnt2*k*(k-1)//2%mod
print((ans)%mod)


Measured memory_bytes: 70320
N = int(input())

l = []

for i in range(N) :
    a, b = map(str, input().split())
    b = int(b)
    l.append([a, b, i+1])

l = sorted(l, key=lambda x:(x[0],-x[1]))

for i in range(len(l)) :
    print(l[i][2])


Measured memory_bytes: 3060
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a-b;
    cout<<sum%c<<endl;
}


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

vector<int64_t> sheets(50);
vector<int64_t> patties(50);

int64_t f(int64_t n, int64_t x)
{
  return n > 0 ? x <= sheets[n - 1] + 1 ? f(n - 1, x - 1) :
    patties[n - 1] + 1 + f(n - 1, x - 2 - sheets[n - 1]) :
			   x <= 0 ? 0 : 1;
}

int main()
{
  int64_t n, x;
  cin >> n >> x;
  sheets[0] = 1;
  patties[0] = 1;
  for (auto i = 1; i < n; i++) {
    sheets[i] = sheets[i - 1] * 2 + 3;
    patties[i] = patties[i - 1] * 2 + 1;
  }
  cout << f(n, x) << endl;
}


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

string s;

int main() {
  cout << "? 1000000000" << endl;
  char c;
  cin >> c;
  int L = 0;
  if (c == 'Y') {
    for (int i = 0; i <= 9; i++) {
      cout << "? 2";
      for (int j = 0; j < i; j++) cout << '0';
      cout << endl;
      cin >> c;
      if (c == 'Y') { L = i; break; }
    }
    cout << "! 1";
    for (int i = 0; i < L; i++) cout << '0';
    cout << endl;
  } else {
    L = 8;
    for (int i = 1; i < 9; i++) {
      cout << "? 1";
      for (int j = 0; j < i; j++) cout << '0';
      cout << endl;
      cin >> c;
      if (c == 'N') { L = i - 1; break; }
    }

    int lb = 1, ub = 10;
    for (int i = 0; i < L; i++) lb *= 10, ub *= 10;
    ub--;
    while (lb < ub) {
      int mid = (lb + ub) / 2;
      cout << "? " << mid << '0' << endl;
      cin >> c;
      if (c == 'Y') ub = mid;
      else lb = mid + 1;
    }
    cout << "! " << ub << endl;
  }
  return 0;
}


Measured memory_bytes: 596
// CODE by Kazhybay Askar

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

using namespace std;
using namespace __gnu_pbds;

/*
find_by_order(k);
order_of_key(k);
ordered_set(int) s;
*/

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
rng();
shuffle(permutation.begin(), permutation.end(), rng);
*/

/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC    optimize("Ofast")
#pragma GCC    target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define F      first
#define S      second
#define pb     push_back
#define pf     push_front
#define ppb    pop_back
#define ppf    pop_front
#define Speed  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz     size()
#define all(x) x.begin(),x.end()
#define cont   continue
#define r0     return 0
#define nl     '\n'
#define ordered_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef long double   ld;
typedef pair<ll,ll>   pll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;

const int MAXN  = 5e5  + 7;
const int MOD   = 1e9  + 7;
const int INF   = 1e9  + 7;
const ll  MINF  = 1e18 + 7;
const int EPS   = 1e-6;
const int dx[]  = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[]  = {1, -1, 0, 0, -1, 1, -1, 1};
const double pi = acos(-1.0);

ll n,a[MAXN];

void solve(){
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            ans+=i;
        }
    }
    cout<<ans;
}



int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    Speed;
    ll T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    r0;
}


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

bool flg = false;

int main() {
  int C[3][3],C1[3][3],C2[3][3],C3[3][3],C4[3][3],C5[2][3];
  for (int i = 0; i<2; i++) for (int j = 0; j<3; j++) C5[i][j] = 0;
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) cin >> C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C1[i][j] = C[i][(j+1)%3]-C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C2[i][j] = C[(i+1)%3][j]-C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C3[i][j] = C1[(i+1)%3][j]-C1[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C4[i][j] = C2[i][(j+1)%3]-C2[i][j];
  for (int i = 0; i<3; i++) C5[0][i] = C1[i][0]+C1[i][1]+C1[i][2];
  for (int i = 0; i<3; i++) C5[1][i] = C2[0][i]+C2[1][i]+C2[2][i];

  
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) if(C3[i][j] != 0 && flg ==false) {
    cout << "No\n";
    flg = true;
  }
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) if(C4[i][j] != 0 && flg ==false) {
    cout << "No\n";
    flg = true;
  }
  for (int i = 0; i<2; i++) for (int j = 0; j<3; j++) if(C5[i][j] != 0 && flg ==false) {
    cout << "No\n";
    flg = true;
  }

  if(flg == false) cout << "Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/*
string solve(vector<string> &C, int W, int H, int i, int j, string ret){
  string s[2];
  ret += C[i][j];
  for(int k = 1; k < 3; ++k){
    if(i+k/2 < H && j+k%2 < W && C[i+k/2][j+k%2] <= '9' && C[i+k/2][j+k%2] >= '0'){
      s[k-1] = solve(C,W,H,i+k/2,j+k%2,"");
    }
  }
  if(s[0].size() == s[1].size()){
    ret += max(s[0],s[1]);
  }else{
    if(s[0].size() > s[1].size()) ret += s[0];
    else ret += s[1];
  }
  return ret;
}
*/
int main(){
  int W, H;
  while(cin >> W >> H, W){
    vector<string> C(H);
    for(int i = 0; i < H; ++i)
      cin >> C[i];
    /*
    string ans;
    for(int i = 0; i < H; ++i){
      if((int)ans.size() > H - i + W) break;
      for(int j = 0; j < W; ++j){
	if(C[i][j] > '9' || C[i][j] <= '0' ||
	   (i > 0 && C[i-1][j] > '0' && C[i-1][j] <= '9') ||
	   (j > 0 && C[i][j-1] > '0' && C[i][j-1] <= '9'))
	  continue;
	if((int)ans.size() > H - i + W - j) break;
	else{
	  string t = solve(C,W,H,i,j,"");
	  if(ans.size() == t.size()) ans = max(ans, t);
	  else if(ans.size() < t.size()) ans = t;
	}
      }
    }
    if(ans == "") cout << 0 << endl;
    else cout << ans << endl;
    */
    string dp[H][W];
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	if(C[i][j] < '0' || C[i][j] > '9') continue;
	string s = string(1,C[i][j]), t = string(1,C[i][j]);
	if(i > 0 && dp[i-1][j] != "0") s = dp[i-1][j] + C[i][j];
	if(j > 0 && dp[i][j-1] != "0") t = dp[i][j-1] + C[i][j];
	if(s.size() == t.size()) dp[i][j] = max(s,t);
	else{
	  if(s.size() > t.size()) dp[i][j] = s;
	  else dp[i][j] = t;
	}
      }
    }
    string ans = "";
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	if(ans.size() == dp[i][j].size()) ans = max(ans,dp[i][j]);
	else{
	  if(ans.size() < dp[i][j].size()) ans = dp[i][j];
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int SumLeft=0,SumRight=0;
  SumLeft = A+B;
  SumRight = C+D;
  if(SumLeft > SumRight){
    cout << "Left"<< endl;
  }else if(SumLeft == SumRight){
    cout << "Balanced" << endl;
  } else{
    cout << "Right" << endl;
  }
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e18+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii >

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve() {
    string s, t;
    cin >> s >> t;
    if(si(t)-1 == si(s)){
        t.pop_back();
        if(s == t){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
        return;
    }
    cout << "No" << endl;

}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;
    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make(int, N);

    vector<int> As(N);
    REP(i, N) {
        make(int, A);
        A--;

        As.at(i) = A;;
    }

    // i番目を既に押したか?
    vector<bool> Trained(N, false);

    int now = 0;
    Trained.at(0) = true;
    FORE(cnt, 1, INF){
        now = As.at(now);

        if (now == 1) {
            cout << cnt << endl;
            return 0;
        }

        if (Trained.at(now)) {
            cout << -1 << endl;
            return 0;
        } else {
            Trained.at(now) = true;
        }
    }

}


Measured memory_bytes: 3756
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> [Int16] -> Int32
solve n hs = fst $ fst dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp = foldl'
    (\((!dp1, !dp2), (!x, !y)) (!i, !v) -> if i == 0
      then ((0, dp1), (v, x))
      else if i == 1
        then ((dp1 + abs (fromIntegral $ v - x), dp1), (v, x))
        else
          ( ( min (dp1 + abs (fromIntegral $ v - x))
                  (dp2 + abs (fromIntegral $ v - y))
            , dp1
            )
          , (v, x)
          )
    )
    ((-1, -1), (-1, -1))
    (zip [0 ..] hs)

main = do
  let sillyTail b | B.null b  = b
                  | otherwise = B.tail b
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt b
        | B.null b = Nothing
        | otherwise = fmap (first fromIntegral . second sillyTail) $ B.readInt b

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- unfoldr readInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 1916
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

//u に隣接するvを番号順に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if( M[u][v] ) return v; 
    }
    return NIL;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(S.size() != 0){
        int u = S.top();
        int v = next(u);
        if(v != NIL){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs_init(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    //未訪問のuを始点として深さ優先探索
    for(int u = 0; u < n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i = 0;i < n; i++){
        cout << i + 1 << " " << d[i]  << " " << f[i] << endl;
    }
}

int main(){
    cin >> n;
    int u, k, v;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        for(int j = 0; j < k; j++){
            scanf("%d", &v);
            M[u-1][v-1] = 1;
        }
    }

    dfs_init();

    return 0;
}


Measured memory_bytes: 3252
def lcs(x, y):
    m, n = len(x), len(y)
    dp = [0] * (n+1)
    
    for xi in x:
        temp = dp[:]
        for j in range(n):
            if xi == y[j]:
                dp[j+1] = temp[j] + 1
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]
    
    return dp[-1]

N = int(input())
for _ in range(N):
    x = input()
    y = input()
    print(lcs(x, y))

Measured memory_bytes: 7736
// #pragma comment(linker, "/STACK:1024000000")
#include <bits/stdc++.h>

using namespace std;

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

#define fori(i,a,b) for (ll i=(a); i<=(b); ++i)
#define ford(i,a,b) for (ll i=(a); i>=(b); --i)
#define foreach(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define filla(a, x) memset(a, x, sizeof(a))
#define fillv(v, x) memset(&v[0], x, v.size() * sizeof(v[0]))
#define err(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl;
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define has(a, x) (a.find(x) != a.end())
#define all(x) x.begin(), x.end()
#define sz(a) int(a.size())
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define endl '\n'


inline ll read() {	ll x;   cin >> x;   return x;   }


const int MAX_N = 1e4;

int a[MAX_N];


int main() {
#ifdef DEBUG
	freopen("agc001_a.in", "r", stdin);
	freopen("agc001_a.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);	cin.tie(0);
	cout.precision(9);
	cout.setf(ios::fixed, ios::floatfield);

	int n = read() * 2;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a+n);
	int ans = 0;
	for (int i = n-1; i >= 0; i -= 2) {
		int t = a[i];
		if (i>0) t = min(t, a[i-1]);
		ans += t;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256