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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to, id;
  Edge(int from, int to, int id) : from(from), to(to), id(id) {}
};

const pair<vector<int>, vector<int>> EMPTY_PAIR = make_pair(vector<int>(), vector<int>());

pair<vector<int>, vector<int>> Solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v_values(n);
  map<int, vector<int>> value_to_vs;
  for (int i = 0; i < n; i++) {
    cin >> v_values[i];
    value_to_vs[v_values[i]].push_back(i);
  }

  vector<vector<Edge>> graph(n);
  vector<Edge> edges;
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--;
    v2--;
    graph[v1].push_back(Edge(v1, v2, i));
    graph[v2].push_back(Edge(v2, v1, i));
    edges.push_back(Edge(v1, v2, i));
  }

  vector<int> edge_weights(m);
  for (int i = 0; i < m; i++) {
    edge_weights[i] = max(v_values[edges[i].from], v_values[edges[i].to]);
  }

  vector<int> colors(n, -1);
  for (int v = 0; v < n; v++) {
    bool valid = false;
    for (const auto& edge : graph[v]) {
      if (edge_weights[edge.id] == v_values[v]) {
        valid = true;
      }
    }
    if (!valid) return EMPTY_PAIR;
  }

  for (const auto& value_vs : value_to_vs) {
    int value;
    vector<int> vs;
    tie(value, vs) = value_vs;

    function<void(int)> dfs_fn = [&](int v) {
      for (const auto& edge : graph[v]) {
        if (v_values[edge.to] == value && colors[edge.to] < 0) {
          colors[edge.to] = 1 - colors[v];
          dfs_fn(edge.to);
        }
      }
    };

    for (int v : vs) {
      if (colors[v] < 0) {
        for (const auto& edge: graph[v]) {
          if (edge_weights[edge.id] == value && colors[edge.to] >= 0) {
            colors[v] = 1 - colors[edge.to];
            dfs_fn(v);
            break;
          }
        }
      }
    }
    for (int v : vs) {
      if (colors[v] < 0) {
        colors[v] = 0;
        dfs_fn(v);
      }
    }
  }

  for (int v = 0; v < n; v++) {
    if (colors[v] < 0) {
      cerr << "colors[v] < 0 at v = " << v << endl;
      exit(1);
    }
  }

  for (int v = 0; v < n; v++) {
    bool valid = false;
    for (const auto& edge : graph[v]) {
      if (edge_weights[edge.id] == v_values[v] && colors[edge.to] != colors[v]) {
        valid = true;
      }
    }
    if (!valid) {
      cerr << "Invalid at v = " << v << endl;
      exit(1);
    }
  }

  return make_pair(colors, edge_weights);
}

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

  vector<int> colors, edge_weights;
  tie(colors, edge_weights) = Solve();
  if (colors.empty()) {
    cout << -1 << "\n";
  } else {
    for (int color: colors) {
      cout << "WB"[color];
    }
    cout << "\n";
    for (int edge_weight : edge_weights) {
      cout << edge_weight << "\n";
    }
  }
}

Measured memory_bytes: 25264
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
			inv[i]=ppow(fact[i],MOD-2);
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};

double dp[2000][2000];
double ans[2000];

int main(){
	ll t=ppow(2,MOD-2);
	int B,W;cin>>B>>W;
	Fact fac(B+W);
	ll p=0,q=0;
	for(int i=1;i<=B+W;i++){
		printf("%lld\n",((1+MOD-p+MOD-q)%MOD*t%MOD+q)%MOD);
		if(i>=B){
			(p+=fac.nCr(i-1,B-1)*ppow(t,i))%=MOD;
		}
		if(i>=W){
			(q+=fac.nCr(i-1,W-1)*ppow(t,i))%=MOD;
		}
	}
}

Measured memory_bytes: 8448
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K, N = lr()
A = np.array(lr())
A = np.append(A, A[0] + K)
diff = np.diff(A)
answer = K - diff.max()
print(answer)


Measured memory_bytes: 43452
array=(1..gets.to_i).to_a
frist = gets.chomp.split.map(&:to_i)
second = gets.chomp.split.map(&:to_i)
first_number = -1.5
second_number = -1.2
array.permutation.to_a.each_with_index do |a,index|
  first_number = index + 1 if frist == a
  second_number = index + 1 if second == a
end
puts (first_number - second_number).abs

Measured memory_bytes: 6780
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T maxi(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T mini(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

signed main() {
	makei(a);
	makei(b);
	makei(c);
	Yn(a == b && b == c);
}

Measured memory_bytes: 256
x, y = gets.split.map(&:to_i)
a = [100000, 200000, 300000].reverse
s = a[x - 1]
s = 0 if s.nil?
t = a[y-1]
t = 0 if t.nil?
cnt = s + t
if x == 1 && y == 1
  cnt += 400000
end
p cnt

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

int main() {
    char S;
    int a, i;
    cin >> a;
    bool x = false;


    for(i = 0; i < a; i++){
        cin >> S;
        if(S == 'Y'){
            x = true;
        }
    }
    if(x){
            cout << "Four"<<endl;
        }else{
            cout << "Three" <<endl;
        }

    return 0;

}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    int ans = INF;
    for (int i = 0; i < n - k + 1; i++) {
        int l = v[i];
        int r = v[i + k - 1];
        if (r <= 0)
            ans = min(ans, -l);
        else if (l >= 0)
            ans = min(ans, r);
        else
            ans = min({ans, r - 2 * l, r * 2 - l});
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n,m;
    cin>>n>>m;
    int p=(int)pow(2,m);
    cout<<p*(1900*m+100*(n-m))<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n; cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];

  ll val=n;
  if(n%4==2)
    val=n+1;

  ll k=0;
  for(int i=0;i<n;i++)
    k^=a[i];

  for(int i=0;i<n;i++)
    a[i]=k^a[i];

  for(auto i:a)
    cout<<i<<" ";
  return 0;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define ll long long
#define ldb long double
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)


const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n){
	ll res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}
	
	return res;
}

int main(){
	fast;
	
	int n;
	cin>>n;
	
	int x[n];
	forr(i,0,n)
	cin>>x[i];
	
	sort(x,x+n);
	
	ll int max=INT_MAX;
	forr(i,x[0],x[n-1]+1){
		ll int sum=0;
		
		forr(j,0,n){
			sum+=(x[j]-i)*(x[j]-i);	
		}
		
		if(sum<max)
		max=sum;
	}
	
	cout<<max;	
	return 0;
}


Measured memory_bytes: 256
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort.reverse
b = gets.strip.split.map(&:to_i).sort
c = gets.strip.split.map(&:to_i).sort

#p a
#p b
#p c

result = 0
b.each do |current_b|

  a_count = a.length - (a.bsearch_index {|e| e < current_b} || a.length)

  c_count = c.length - (c.bsearch_index {|e| e > current_b} || c.length)

#p [current_b, a_count, c_count]
  result += a_count * c_count
end

p result



Measured memory_bytes: 26788
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£????????????????????°?????????????????£?¨?
				Scanner sc = new Scanner(System.in);
		while(true){
			//???
			int H = sc.nextInt();
			//?¨?
			int W = sc.nextInt();
			//??\?????????0????????????
			if(H ==0 && W ==0){
				break;
			}
			//???????????¶???
			for(int i =1; i <=H; i++){
				//?¨?????????¶???
				String s = "";
				for(int j =1; j<=W; j++){
				//?¨??§??????????
					//????????¶??°??????
					if( i % 2 ==0){
					//?¨??????¶??°?????????
						if(j %2 ==0){
							s += "#";
							//?¨?????\???°??????
						}else{
							s +=".";
						}
						//???????\???°??????
					}else{
						//?¨??????¶??°??????
						if(j % 2==0){
							s +=".";
						//?¨?????\???°??????
						}else{
							s +="#";
						}
					}
				}
				System.out.println(s);
			}
		System.out.println("");
		}
	}
}

Measured memory_bytes: 55372
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int R, C, N;
int onedge(int x, int y) {
    if(x == 0) return 1;
    if(x == R) return 2;
    if(y == 0) return 3;
    if(y == C) return 4;
    return 0;
}

vector<pii> vs[4];
void ins(vector<int> &v) {
    int d[] = {0, 3, 1, 2};
    rep(i,0,4) {
        int c = d[i];
        rep(j,0,vs[c].size()) {
            v.push_back(vs[c][j].second);
        }
    }
}

signed main() {
    cin >> R >> C >> N;
    rep(i,0,N) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        int a = onedge(x1, y1);
        int b = onedge(x2, y2);
        if(a && b) {
            a--; b--;
            vs[a].push_back(pii((a/2 ? x1 : y1), i));
            vs[b].push_back(pii((b/2 ? x2 : y2), i));
        }
    }
    sort(vs[0].begin(), vs[0].end());
    sort(vs[3].begin(), vs[3].end());
    sort(vs[1].begin(), vs[1].end(), greater<pii>());
    sort(vs[2].begin(), vs[2].end(), greater<pii>());

    vector<int> v;
    ins(v);
    stack<int> S;
    rep(i,0,v.size()) {
        if(S.empty()) S.push(v[i]);
        else {
            if(S.top() == v[i]) S.pop();
            else S.push(v[i]);
        }
    }
    cout << (S.empty() ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 7216
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,cnt[4];
double dp[334][334][334];
double f(int i,int j,int k){
	if(!i&&!j&&!k)return 0.0;
	if(dp[i][j][k]>0.0)return dp[i][j][k];
	int l=i+j+k;
	double ans=1.0*n/l;
	if(i)ans+=1.0*i/l*f(i-1,j,k);
	if(j)ans+=1.0*j/l*f(i+1,j-1,k);
	if(k)ans+=1.0*k/l*f(i,j+1,k-1);
	dp[i][j][k]=ans;
	return ans;
}
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a;
		cnt[a]++;
	}
	printf("%.12lf\n",f(cnt[1],cnt[2],cnt[3]));
	return 0;
}


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

public class Main {

	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt();
	   int sum = 0;
	   int arr[] = new int[n]; 
	   for(int i = 0; i<n; i++) {
		  arr[i] = in.readInt();
		  while(arr[i] % 2 == 0) {
			  arr[i]/=2; 
			  sum++;
		  }
	   }
	   System.out.println(sum); 
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
//const long double PI = 2 * acos(0.0);
//typedef complex <double> base;



int arr1[110];
int arr2[110];




int main(){

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

    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>arr1[i];
    for(int i=1; i<=n; i++) cin>>arr2[i];

   
    for(int i=1; i<=n; i++) arr1[i]+=arr1[i-1];
    for(int i=1; i<=n; i++) arr2[i]+=arr2[i-1];

    int beshi=INT_MIN;

    for(int i=1; i<=n; i++)
        beshi=max(beshi, arr1[i]+arr2[n]-arr2[i-1]);

    cout<<beshi;

}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] c = new int[4];

            for(int i = 0; i<n; i++)
            {
                string s = Console.ReadLine();

                if (s == "AC")
                    c[0]++;
                if (s == "WA")
                    c[1]++;
                if (s == "TLE")
                    c[2]++;
                if (s == "RE")
                    c[3]++;
            }
            Console.WriteLine("AC x " + c[0]);
            Console.WriteLine("WA x " + c[1]);
            Console.WriteLine("TLE x " + c[2]);
            Console.WriteLine("RE x " + c[3]);
        }    
    }
}


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

ll beki[33];

int main(){
  beki[0]=1;
  rep(i,32) beki[i+1]=beki[i]*2;
  int N; cin>>N;
  vector<ll> A(N);
  map<ll,int> mp;
  rep(i,N){
    cin>>A[i];
    mp[A[i]]++;
  }
  sort(A.rbegin(),A.rend());
  int l=0,ans=0;
  for(int i=32;i>=1;i--){
    while(A[l]>=beki[i]) l++;
    for(int j=l;j<N;j++){
      if(mp[A[j]]!=0&&mp[beki[i]-A[j]]!=0){
        if(beki[i]-A[j]==A[j]&&mp[A[j]]==1) continue;
        ans++;
        mp[A[j]]--;
        mp[beki[i]-A[j]]--;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 65152
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
int cnt[2][105];
int h, w;
bool flag[110][110];

int main() {
	string s, t, u;
	cin >> s >> t >> u;
	int l = s.length();
	int m = t.length();
	int n = u.length();
	char target = s[0];
	while (1) {
		if (target == 'a') {
			l--;
			target = s[0];
			s.erase(0,1);
		}
		else if (target == 'b') {
			m--;
			target = t[0];
			t.erase(0,1);
		}
		else {
			n--;
			target = u[0];
			u.erase(0,1);
		}
		
		if (l < 0) {
			puts("A");
			break;
		}
		else if (m < 0) {
			puts("B");
			break;
		}
		else if (n < 0) {
			puts("C");
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if(N <= 9){
    cout << N << endl;
  }
  else if(N <= 99){
    cout << 9 << endl;
  }
  else if(N <= 999){
    cout << N - 90 << endl;
  }
  else if(N <= 9999){
    cout << 909 << endl;
  }
  else if(N <= 99999){
    cout << N - 9090 << endl;
  }
  else if(N == 100000){
    cout << 90909 << endl;
  }

}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <string.h>
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int maxn=200005;
long long ans1,ans2=1e18,n,da,xiao,maxx,maxy,minx=1e9+10,miny=1e9+10,weizhiy,weizhix;
struct pai
{
	long long x,y;
	bool operator < (const pai &a)const
	{
		long long gx1,gx2;
		if(xiao<=x&&x<=da)
			gx1=0;
		else if(xiao<=y&&y<=da)
			gx1=0;
		else if(y<xiao)
			gx1=xiao-y;
		else if(x>da)
			gx1=x-da;
		else 
			gx1=min(xiao-x,y-da);
		if(xiao<=a.x&&a.x<=da)
			gx2=0;
		else if(xiao<=a.y&&a.y<=da)
			gx2=0;
		else if(a.y<xiao)
			gx2=xiao-a.y;
		else if(a.x>da)
			gx2=a.x-da;
		else 
			gx2=min(xiao-a.x,a.y-da);
		return gx1>gx2;
	}
} p[maxn];
inline char nc()
{
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline long long read()
{
	char ch=nc();
	long long sum=0;
	while(!(ch>='0'&&ch<='9'))
	{
		ch=nc();
		if(ch==EOF)  
			return EOF;
	}
	while(ch>='0'&&ch<='9')
	{
		sum=sum*10+ch-48;
		ch=nc();
		if(ch==EOF)  
			return EOF;
	}
	return sum;
}

int main()
{
//	file("1"); 
	n=read();
	if(n==1)
	{
		printf("0");
		return 0;
	}
	for(int i=1; i<=n; i++)
	{
		p[i].x=read(),p[i].y=read();
		if(p[i].x>p[i].y)
			swap(p[i].x,p[i].y);
		maxx=max(maxx,p[i].x);
		if(p[i].y>maxy)
		{
			weizhiy=i;
			maxy=p[i].y;
		}
		if(p[i].x<minx)
		{
			weizhix=i;
			minx=p[i].x;
		}
		miny=min(miny,p[i].y);
	}
	ans1=(maxy-miny)*(maxx-minx);
//	cout<<ans1<<endl;
	da=p[weizhix].y,xiao=p[weizhiy].x;
	sort(p+1,p+n+1);
	if(da<xiao)
		swap(da,xiao);
	if(weizhix!=weizhiy)
	{
		for(int i=1; i<=n; i++)
		{
			int t=i;
			if((xiao<=p[i].x&&p[i].x<=da)||(xiao<=p[i].y&&p[i].y<=da))
				continue;
			else if(p[i].x>da)
				da=p[i].x;
			else if(p[i].y<xiao)
				xiao=p[i].y;
			else if(xiao-p[i].x<p[i].y-da)
				xiao=p[i].x;
			else
				da=p[i].y;
		}
		ans2=(maxy-minx)*(da-xiao);
	}
//	cout<<ans2<<endl;
	printf("%lld",min(ans1,ans2));
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>//atcoder.089.2
using namespace std;
int main(){
	int n,i,m=0;
	cin>>n;
	char s[n+1];
	for(i=1;i<=n;i++)
		cin>>s[i];
	for(i=1;i<=n;i++)
		if(s[i]=='G'){
			m++;
			break;
		}
	for(i=1;i<=n;i++)
		if(s[i]=='P'){
			m++;
			break;
		}
	for(i=1;i<=n;i++)
		if(s[i]=='W'){
			m++;
			break;
		}
	for(i=1;i<=n;i++)
		if(s[i]=='Y'){
			m++;
			break;
		}
		if(m==1)cout<<"One";
		else if(m==2)cout<<"Two";
		else if(m==3)cout<<"Three";
		else if(m==4)cout<<"Four";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>

using namespace std;

int a[101];
int d[101];

int main()
{
    int x,n;
    int t = 0,z = 0;

    cin >> n >> x;

    for ( int i = 1; i <= n; i++ ) scanf("%d", &a[i]);
    d[1] = 0;
    for ( int i = 2; i <= n+1; i++ )
    {
        z += d[i-1]+a[i-1];
        if ( z <= x ) t++;
    }

    cout << t+1;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nx = Input.ar;
        var ar = Input.ar;
        var ct = 1;
        var then = 0;
        for(var i=0;i<nx[0];i++)
        {
            then = then + ar[i];
            if (then <= nx[1]) ct++;
        }
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}


Measured memory_bytes: 13268
def isSame(h, w):
    for i in range(h, h+m):
        for j in range(w, w+m):
            # print(i, j)
            if A[i][j] != B[i-h][j-w]:
                return False
    return True


n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]

for i in range(0, n-m+1):
    for j in range(0, n-m+1):
        if isSame(i, j) is True:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
std::string s;
int f(int a,int b,int c){
	char i=s[a];
	return ((i!='s'&&i==s[b]&&i==s[c])?i:0);
}
int main(){
	int i,j;
	while(getline(std::cin,s)){
		char x=(f(0,4,8)||f(2,4,6))?s[4]:0;
		if(!x){
			for(i=0;i<3;i++){
				x=f(i,i+3,i+6);
				if(x)break;
				j=i*3;
				x=f(j,j+1,j+2);
				if(x)break;
			}
			if(!x)x='d';
		}
		std::cout<<x<<"\n";
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

int main()
{
    int a, b, c;
    string ans = "win";
    cin >> a >> b >> c;
    if (a + b + c >= 22)
    {
        ans = "bust";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long ans = 0;
        if (inp[0] == 1) ans = inp[1];
        else
            for (long i = 1; i <= Math.Pow(inp[1], 1.0 / inp[0]) + 10; i++)
            {
                if (inp[1] % Math.Pow(i, inp[0]) == 0) ans = i;
            }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include<stdio.h>

int main()
{
	long long n;
	char c[25]; int count = 0;
	scanf("%lld", &n);
	while(n != 0)
	{
		c[count++] = --n % 26 + 'a';
		n /= 26;
	}
	for(int i = count - 1; i >= 0; i--) printf("%c", c[i]);
	return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int get_digit(ll n){
    int digit = 0;
    if(n == 0){
        return 1;
    }
    while(n != 0){
        digit++;
        n /= 10;
    }
    return digit;
}
bool is_junretu(ll n){
    int digit = get_digit(n);
    string s;
    s = to_string(n);
    bool flg= true;
    for(int i = 1; i <= digit; i++){
        if(s.find(i) == string::npos){
            flg = false;
            break;
        }
    }
    return flg;
}

int main(){

    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }
    if(n % 2 != 0){
        cout << 0 << endl;
        return 0;
    }
    sort(d.begin(), d.end());
    int mid = d.size() / 2;
    int cnt = 0;
    for(int i = d[mid-1]; i < d[mid]; i++){
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    double ret=0;
    for(int i=1;i<=n;i++){
        int now=i;
        double temp=1.0/n;
        while(now<k){
            now*=2;
            temp/=2;
        }
        ret+=temp;
    }
    printf("%.12lf\n",ret);
    return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

if a[0] + a[1] > x and a[1] < x:
  ans = a[1]
  a[1] = 0
  ans += a[0] - x
  a[0] = x

for i in range(1, N):
  if a[i] + a[i-1] > x:
    cut = a[i] + a[i-1] - x
    if cut > a[i]:
      a[i] = 0
    else:
      a[i] -= cut
    ans += cut

print(ans)

Measured memory_bytes: 14068
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int nmax=0,nmin=1000;
    for (int i=0;i<n;i++){
        int a;
        cin >> a;
        if (a>nmax){
            nmax=a;
        }
        if (a<nmin){
            nmin=a;
        }
    }
    cout << nmax-nmin << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

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

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M >> K;
	for (int i = 0; i < 10000; i++) {
		if ((N*i) % M == K) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else  return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
    return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left == NIL || z->right == NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left != NIL) x=y->right;
  else x=y->right;
  if(x != NIL) x->parent=y->parent;
  if(y->parent == NIL) root=x;
  else if(y == y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y != z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
    z->parent=y;
    if(y == NIL) root = z;
    else if(z->key < y->key) y->left=z;
    else y->right=z;
  
}

void inorder(Node u){
  if(u != NIL){
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  }  
}
  
void preorder(Node u){
  if(u != NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })


#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
using vi = vector<int>;

namespace FFT { // from KACTL

typedef complex<double> C;
typedef vector<double> vd;

void fft(vector<C> &a, vector<C> &rt, vi& rev, int n) {
	rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
	for (int k = 1; k < n; k *= 2)
		for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
			// C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
			auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
			C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
	}
}

vd conv(const vd& a, const vd& b) {
	if (a.empty() || b.empty()) return {};
	vd res(sz(a) + sz(b) - 1);
	int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
	vector<C> in(n), out(n), rt(n, 1); vi rev(n);
	rep(i,0,n) rev[i] = (rev[i/2] | (i&1) << L) / 2;
	for (int k = 2; k < n; k *= 2) {
		C z[] = {1, polar(1.0, M_PI / k)};
		rep(i,k,2*k) rt[i] = rt[i/2] * z[i&1];
	}
	copy(all(a), begin(in));
	rep(i,0,sz(b)) in[i].imag(b[i]);
	fft(in, rt, rev, n);
	trav(x, in) x *= x;
	rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out, rt, rev, n);
	rep(i,0,sz(res)) res[i] = imag(out[i]) / (4*n);
	return res;
}

};

const ll MOD = 200003;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	vl e(MOD,-1);
	ll t = 1;
	FOR(i,0,MOD-1) e[t] = i, t = t*2 % MOD;
	// FOR(t,1,MOD) assert(e[t] != -1);
	
	ll n; cin >> n;
	
	vector<double> p(MOD-1);
	FOR(i,0,n) {
		ll a; cin >> a;
		if (a > 0) p[e[a]] += 1;
//		cout << e[a] << endl;
	}
	
	auto q = FFT::conv(p,p);

//	FOR(i,0,MOD-1) if (p[i]) cout << i << " " << p[i] << endl;
	
	vl cnt(MOD-1);
	FOR(i,0,sz(q)) cnt[i%(MOD-1)] += llround(q[i]);
	
//	cout << endl;
//	FOR(i,0,MOD-1) if (cnt[i]) cout << i << " " << cnt[i] << endl;

	FOR(i,0,MOD-1) cnt[(2*i)%(MOD-1)] -= p[i];
	
	FOR(i,0,MOD-1) {
		assert(cnt[i]%2 == 0);
		cnt[i] /= 2;
	}
//	cout << endl;
//	FOR(i,0,MOD-1) if (cnt[i]) cout << i << " " << cnt[i] << endl;

	t = 1;

	ll res = 0;
	FOR(i,0,MOD-1) {
		res += cnt[i]*t;
		t = t*2 % MOD;
	}
	cout << res << endl;
}



Measured memory_bytes: 36208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c;
  c = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    c += b - a + 1;
  }
  cout << c << endl;
}

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

using namespace std;

int main(void){
    int K,S;
	cin >> K >> S;
   
  	int result = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(i + j > S){
                break;
            } else if (S - i - j > K){
              
            } else {
                result++;
            }
        }
    }
  	cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, a; cin >> x >> a;
    cout << (x < a ? 0 : 10) << 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,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
int ans;
signed main(){
    string s;
    cin>>s;
    int rnum=0;
    int bnum=0;
    rep(i,s.size()){
        if(s[i]=='0'){
            rnum++;
            
        }
        
    }

    cout<<min(rnum*2,((int)s.size()-rnum)*2)<<endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

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

  int a = 0;

  vector<int> P(9);
  //vector<int64_t> Y(M);

  for (int i = 0; i < 9;i++){
    P.at(i) = N / (i+1);
  }

  for (int i = 0; i < 9;i++){
    if(P.at(i)<=9&&N%(i+1)==0&&a==0){
      cout << "Yes" << endl;
      a = 1;
    }
  }

  if(a==0){
    cout << "No" << endl;
  }
}

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

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

int N, M;
vbb grid(30, vb(30, false));

int did = 0;

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

bool valid(int x, int y) {
	return x >= 0 and y >= 0 and x < N and y < M;
}

int dfs1(pi s) {
	queue<pi> q;

	vii dis(30, vi(30, -1));

	dis[s.x][s.y] = 0;
	q.push(s);
	int ret = 0;
	while (q.size()) {
		pi c = q.front();
		q.pop();
		for (int i = 0; i < 4; ++i)
		{
			int kx = c.x + dx[i];
			int ky = c.y + dy[i];

			if (valid(kx, ky) and grid[kx][ky] and dis[kx][ky] == -1) {
				dis[kx][ky] = dis[c.x][c.y] + 1;
				ret = max(ret, dis[kx][ky]);
				q.push({kx, ky});
			}
		}
	}

	return ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> M;

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			char ch;
			cin >> ch;
			grid[i][j] = (ch == '.');
		}
	}

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			if (grid[i][j]) {
				did = max(did, dfs1({i, j}));
			}
		}
	}
	printf("%d\n", did);

}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/


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

string S[100000];
int p[100000];

int main (void) {
  int N, M;
  cin >> N >> M;
  bool isAC[100000] = {false};
  int penal[100000] = {0};
  int total_penal = 0;
  int AC = 0;
  
  for(int i = 0; i < M; i++) {
    cin >> p[i] >> S[i];
    p[i]--;
    if (S[i] == "AC") {
      if (!isAC[p[i]]) { // 初めて正解
        AC++;
        total_penal += penal[p[i]];
        isAC[p[i]] = true;
      }
    } else if (!isAC[p[i]]) { // 正解したことがない
      penal[p[i]]++;
    }
  }
  
  cout << AC << " " << total_penal << endl;
  
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int dist = 0;
  for (int i=0;i<N;i++) {
    int x;
    cin >> x;
    if (x < (K-x)) {
      dist += 2*x;
    }
    else if (K-x >= 0){
      dist += 2*(K-x);
    }
    else {
      dist += 2*(x-K);
    }
  }
  cout << dist << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
using namespace std;
using ll = long long;
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; }



int main() {
  ll x,y;
  scanf("%lld%lld", &x,&y);
  int count = 0;
  while(x<=y){
    x *= 2;
    ++count;
  }

  cout << count << endl;
  
}



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

namespace ConsoleApplication4
{
    class Program
    {
        static int Main()
        {
            var read = Console.ReadLine();
            string[] split = read.Split(' ');
            int[] a = new int[3];
            for (int c = 0; c < 3; c++)
            {
                a[c] = Int32.Parse(split[c]);
            }
            for (int c = 1; c <= a[1]; c++)
            {
                if (a[0] * c % a[1] == a[2])
                {
                    Console.WriteLine("YES");
                    return 0;
                }

            }
            Console.WriteLine("NO");
            return 0;
        }
    }
}


Measured memory_bytes: 11092
import numpy as np
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

for i in range(n):
    print(whole - abs(a[i + 1] - a[i]) -
          abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]))

Measured memory_bytes: 32008
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int a,b;    cin >> a >> b;
    if(2*b <= a){
        cout << a-2*b << endl;
    }else{
        cout << 0 << endl;
    }
}


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

vector<pair<int,ll>> g[100010];
ll dist[100010];

void dfs(int v,int pre,ll d){
    dist[v] = d;
    for(auto to : g[v])if(pre!=to.first){
        dfs(to.first,v,d+to.second);
    }
}

int main(void){
    int N,Q,K;
    cin>>N;
    rep(i,N-1){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    cin>>Q>>K;
    dfs(K,-1,0);

    rep(i,Q){
        int x,y;
        cin>>x>>y;
        cout<<dist[x]+dist[y]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;

int main()
{   IOS;
    ll a;
    cin >> a;
    vector <ll> L;
    for(int i=0;i<a;i++)
    {
        ll e;
        cin >> e;
        L.push_back(e);
    }
    sort(L.begin(),L.end());
    double res=0;
    ll i=2;ll j=0;
    vector<double> L1;
    res=(double)(L[0]+L[1])*1.0/2;
    L1.push_back(res);
        while(i!=a)
    {

        res=(L1[j]+L[i])/2;
        L1.push_back(res);
        j++;
        i++;




    }

    cout << res;


    cout.precision(30);
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect

s = input()
t = input()

if len(set(t) & set(s)) != len(set(t)):
    print(-1)
    exit()

d = dict()

for i, si in enumerate(s):
    if si in d:
        d[si].append(i)
    else:
        d[si] = [i]

ans = 0
res = d[t[0]][0]

for i in range(1, len(t)):
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s)
        res = d[t[i]][0]
    else:
        res = d[t[i]][index]

ans += res + 1

print(ans)

Measured memory_bytes: 7616
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)

INF = float("inf")
que = deque()
que.append(0)
d = [INF] * N
d[0] = 0
rec = [None] * N
while que:
    v = que.popleft()
    for w in G[v]:
        if d[w] != INF:
            continue
        d[w] = d[v] + 1
        que.append(w)
        rec[w] = v

rec1 = [N - 1]
while rec[rec1[-1]] is not None:
    q = rec[rec1[-1]]
    rec1.append(q)
rec1 = rec1[::-1]
mid = d[-1] // 2 + 1
f = rec1[mid]

visited = [False] * N
visited[f] = True
fnum = 0
que = deque()
que.append(0)
while que:
    v = que.popleft()
    visited[v] = True
    fnum += 1
    for w in G[v]:
        if visited[w]:
            continue
        que.append(w)

snum = N - fnum
if fnum > snum:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 27924
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC103_B solver = new ABC103_B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC103_B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String src = in.nextLine();
            String tar = in.nextLine();

            src = src + src;
            if (src.contains(tar)) {
                out.print("Yes");
            } else {
                out.print("No");
            }
        }

    }
}



Measured memory_bytes: 23636