akhauriyash/Code-Regression huggingface dataset:
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Vikash Kumar @ Codechef/codeforces 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define ll                    long long int
#define ll_MAX                LLONG_MAX
#define ll_MIN                LLONG_MIN
#define pi                    3.14159265358979323846
#define count_1(n)            __builtin_popcountll(n)
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define mid(s,e)              (s+(e-s)/2)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

const ll MXX=3005;
ll dp[MXX][MXX];

inline void solve(){
    /*_Start_*/
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
      cin>>a[i];
    for(ll l=0;l<n;l++){
      for(ll r=l;r>=0;r--){
        if(l==r)
          dp[l][r]=a[l];
        else
          dp[l][r]=max( a[l]-dp[l-1][r],a[r]-dp[l][r+1] );
      }
    }
    cout<<dp[n-1][0]<<endl;
    /*_End_*/
   
}

int main()
{
	cout<<fixed<<setprecision(12);
	//freopen("input.txt", "r", stdin);
	fastio;ll  t=1,tc=1;
	//cin>>t;
	while(t--){solve();}return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct SegmentTree{
  int N;
  vector <ll> Table[20];
  void Make(){
    for (int i = 0; i < 20; i++){
      Table[i].resize((1<<i));
    }
    return;
  }

  ll Search(int num){
    int now = 19; ll ans = 0;
    while (num > 0){
      if (num % 2 == 0){
        now--; num = num / 2 - 1;
        ans = max(ans, Table[now][num]);
      }else{
        num--;
        ans = max(ans, Table[now][num]);
      }
    }
    return ans;
  }

  void Add(int num, ll val){
    for (int i = 19; i >= 0; i--){
      Table[i][num] = max(Table[i][num], val);
      num /= 2;
    }
  }
};

int N, H[int(2e5+5)];
ll A[int(2e5+5)];

int main(){
  int N; cin >> N;
  for (int i = 0; i < N; i++) cin >> H[i];
  for (int j = 0; j < N; j++) cin >> A[j];

  SegmentTree T; T.N = N;
  T.Make();

  for (int i = 0; i < N; i++){
    ll now = A[i] + T.Search(H[i]);
    T.Add(H[i], now);
  }
  cout << T.Table[0][0] << endl;

  return 0;
}


Measured memory_bytes: 13724
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
using namespace std;

// int i,j,k;
const ll MOD = 1000000000 + 7;

int main(){
    int s,w;
    string ans="safe";
    cin>>s>>w;
    if(w>=s){
        ans="unsafe";
    }

    
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll d[2][3];
void Main() {
  ll t[2],a[2],b[2];
  rep(i,2) R t[i];
  rep(i,2) R a[i];
  rep(i,2) R b[i];
  
  rep(i,2) {
    if(i%2==0) {
      d[0][i+1]=d[0][i]+a[0]*t[0];
      d[1][i+1]=d[1][i]+b[0]*t[0];
    } else {
      d[0][i+1]=d[0][i]+a[1]*t[1];
      d[1][i+1]=d[1][i]+b[1]*t[1];
    }
  }
  if(d[0][2]==d[1][2]) {
    pr("infinity");
    return;
  }
  ll f=0;
  if(d[0][1]>d[1][1]&&d[0][2]<=d[1][2]) f=1;
  else if(d[0][1]<d[1][1]&&d[0][2]>=d[1][2]) {
    f=1;
    swap(d[0],d[1]);
  }
  ll c=abs(d[0][2]-d[1][2]);
  if(f) pr((d[0][1]-d[1][1])/c*2+((d[0][1]-d[1][1])%c!=0));
  else pr(0);
}

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    M = [[0 for j in range(W)] for i in range(H)]

    for h in range(H):
        for w in range(W):
            if S[h][w] is "#":
                M[h][w] = -1

    for h in range(H):
        for w in range(W):

            if M[h][w] !=  -1:
                continue

            for hi in [-1,0,1]:

                if not (0 <= h+hi < H):
                    continue

                for wi in [-1,0,1]:

                    if not (0 <= w+wi < W):
                        continue
                        
                    val = M[h+hi][w+wi]
                    if val == -1:
                        continue
                    else:
                        M[h+hi][w+wi] += 1

    for h in range(H):
        print( "".join( [ "#" if w == -1 else str(w) for w in M[h] ] ) )
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
#define mod 1000000007
ll mypower(ll a, ll b, ll p)
{
    ll ans = 1;
    a = a%p;
    while(b)
    {
        if(b%2)
            ans = ans*a % p;
        b=b/2;
        a = a*a % p;
    }
    return ans;
}
int main() {
    int n,m;
    cin >> n >> m;
    int arr[n+1];
    int i;
    for(i=1;i<=n;i++)
        cin >> arr[i];
    vector<int> adj[n+1];
    for(i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int cnt = 0;
    for(i=1;i<=n;i++)
    {
        int j;
        for(j=0;j<adj[i].size();j++)
        {
            if(arr[i] <= arr[adj[i][j]])
                break;
        }
        if(j == adj[i].size())
        {
           // cout << i << '\n';
            cnt++;
        }
    }
    cout << cnt;
}

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

int main()
{
    ll N, Q;
    string S;

    cin >> N >> Q;
    cin >> S;

    vector<ll> L(Q);
    vector<ll> R(Q);

    rep(i, Q) cin >> L.at(i) >> R.at(i);

    vector<int> dp(N);
    dp.at(0) = 0;
    rep(i, N - 1)
    {
        if (S.at(i) == 'A' && S.at(i + 1) == 'C')
        {
            dp.at(i + 1) = dp.at(i) + 1;
        }
        else
        {
            dp.at(i + 1) = dp.at(i);
        }
    }

    rep(i, Q)
    {
        cout << dp.at(R.at(i) - 1) - dp.at(L.at(i) - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 5356
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    static int dfs(int node, ArrayList<Integer> l[], boolean visited[]){
        int ret = 1;
        visited[node] = true;
        for(int adj : l[node]){
            if(visited[adj])
                continue;

            ret += dfs(adj, l, visited);
        }

        return ret;
    }

    public static void process(int test_number)throws IOException
    {
        int n = ni(), m = ni(), res = 0;
        boolean visited[] = new boolean[n + 1];
        ArrayList<Integer> l[] = new ArrayList[n + 1];
        for(int i =1; i <= n; i++)
            l[i] = new ArrayList<>();

        for(int i = 1; i <= m; i++){
            int u = ni(), v = ni();
            l[u].add(v);
            l[v].add(u);
        }    

        for(int i = 1; i <= n; i++){
            if(visited[i])
                continue;

            int sz = dfs(i, l, visited);
            res = Math.max(res, sz);
        }

        pn(res);
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
        //t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<int> prime;
bool is_prime[1000010];
int min_factor[1000010];
int sieve(int n) {
  fill(is_prime + 2, is_prime + 1000010, true);
  min_factor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0) min_factor[j] = i;
      }
    }
  }
  return prime.size();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(10010);
  int n;
  while (cin >> n, n) {
    int p = -1, q = -1;
    for (int i = 0; i + 1 < int(prime.size()); i++) {
      if (prime[i + 1] > n) break;
      if (prime[i + 1] - prime[i] != 2) continue;
      p = max(p, prime[i]);
      q = max(q, prime[i + 1]);
    }
    cout << p << " " << q << endl;
  }

  return 0;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define debug(...) cout<<__FUNCTION__<<":"<<__LINE__<<": ";debugger(#__VA_ARGS__, __VA_ARGS__);
template<typename arg>
void debugger(const char* varname, arg&& var) { cout<<varname<<" = "<<var<<endl; }
template<typename arg, typename... args>
void debugger(const char* varnames, arg&& var, args&&... vars) {
    const char* comma = strchr(varnames + 1, ',');
    cout.write(varnames, comma - varnames)<<" = "<<var<<" | ";
    int sz = 1; if(isspace(comma[sz])) sz++;
    debugger(comma + sz, vars...);
}
#define forr(i, s, n) for(ll i=(ll)(s); i<(ll)(n); ++i)
#define forn(i, n) forr(i, 0, n)
#define eb(n) emplace_back(n)
#define endl '\n'
#define fst first
#define snd second
using ll = long long;
using ii = pair<ll,ll>;
using vi = vector<ll>;
extern const int INF = INT_MAX - 5;
extern const ll LINF = LLONG_MAX - 5;
extern const int MOD = 1e9 + 7;
extern const int N = 2e5 + 200;
int x;
int main() {
    scanf("%d", &x);
    ll p1 = x / 500;
    x %= 500;
    ll p2 = x / 5;
    ll ans = p1 * 1000 + p2 * 5;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
class Tree:
    __slots__ = ['id', 'p', 'depth', 'type', 'len_c', 'c']
    def __init__(self):
        self.id = 0
        self.p = -1
        self.depth = -1
        self.type = "leaf"
        self.len_c = 0
        self.c = []
    def __str__(self):
        return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}"
n = int(input())
li = [Tree() for _ in range(n)]
for _ in range(n):
    id, k, *c = map(int, readline().split())
    if k == 0:
        c = []
    else:
        li[id].type = "internal node"
    li[id].id = id
    li[id].c = c
    for j in c:
        li[j].p = id
root = 0
while True:
    a = li[root].p
    if a == -1:
        li[root].type = "root"
        li[root].depth = 0
        break
    root = a
dp = [(root, 0)]
while dp:
    id, d = dp.pop()
    for i in li[id].c:
        li[i].depth = d + 1
        dp.append((i, d + 1))
for i in range(n):
    print(li[i])



Measured memory_bytes: 35608
#include <bits/stdc++.h>
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;


ll N;

/*
   cur : 現在の値
   use : 3,5,7のどれを使ったのかを示すフラグ
         1ビット目 : 7を使ったときに立てる
		 2ビット目 : 5を使ったときに立てる
		 3ビット目 : 3を使ったときに立てる
		 　　→　0b0111なら3,5,7を各1個以上使っていると判断できる
		   　　　フラグとして使用するだけなので0bxxxを10進数に変換した数値には何の意味もない
   counter : 七五三数の個数
*/
void func(ll cur, int use, ll &counter) {
	//ベースケース
	if (cur > N) {
		return;
	}

	//七五三数(3,5,7を1つ以上使って作った数)のときはカウント
	//(35(0b110),55(0b010),73(0b101)などは使っていない文字があるのでカウントしない)
	if (use == 0b0111) {
		counter++;
	}

	//7を使う
	func(cur * 10 + 7, use | 0b001, counter); //7を使ったので1ビット目を立てる

	//5を使う
	func(cur * 10 + 5, use | 0b010, counter); //5を使ったので2ビット目を立てる

	//3を使う
	func(cur * 10 + 3, use | 0b100, counter); //3を使ったので3ビット目を立てる
	
}

int main() {

	cin >> N;

	ll res = 0;
	func(0, 0, res);
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 256
let rec fold_n n f a = if n <= 0 then a else fold_n (n-1) f (f a)
let f (a, b) = (b + a/2, a/2)
let _ = Scanf.scanf "%d %d %d" @@ fun a b n ->
  let x, y = fold_n n f (a, b) in
  let x, y = if n mod 2 = 0 then x, y else y, x in
  Printf.printf "%d %d\n" x y

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

bool comp(pair<double,string> &lhs, pair<double,string> &rhs)
{
	if(lhs.first!=rhs.first)
		return lhs.first>rhs.first;
	else
		return lhs.second<rhs.second;
}

int main()
{
	while(1)
	{
		int n;
		cin>>n;
		if(n==0)
			break;
		
		string l[50];
		double p[50];
		double abc[50];
		double de[50];
		double fs[50];
		int m[50];

		vector<pair<double,string> > ans;

		for(int i=0;i<n;i++)
		{
			double a,b,c,d,e,f,s;
			cin>>l[i]>>p[i]>>a>>b>>c>>d>>e>>f>>s>>m[i];
			abc[i]=a+b+c;
			de[i]=d+e;
			fs[i]=f*s;
			double turn=0.0f;
			double kei=0.0f;
			turn=abc[i]+de[i]*(double)m[i];
			kei=fs[i]*(double)m[i]-p[i];
			ans.push_back(make_pair(kei/turn,l[i]));
		}

		sort(ans.begin(),ans.end(),comp);
		for(int i=0;i<n;i++)
			cout<<ans[i].second<<endl;
		cout<<"#"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class floyd_warshall
{
public:
	const value_type INF = 1e9;

public:
	vector<vector<value_type>> dist;

public:
	floyd_warshall(int vertex_count)
		: dist()
	{
		dist.assign(vertex_count, vector<value_type>(vertex_count, INF));
	}

public:
	void create_edge(int from, int to, value_type cost)
	{
		dist[from][to] = cost;
	}

	void process()
	{
		for (int k = 0; k < (int)dist.size(); k++)
		{
			for (int i = 0; i < (int)dist.size(); i++)
			{
				for (int j = 0; j < (int)dist.size(); j++)
				{
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
};

//floyd_warshall<int> fw(N);
//fw.create_edge(u, v, c);
//fw.process();
//int ret = fw.dist[a][b];

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

	int H, W;
	cin >> H >> W;

	floyd_warshall<int> fw(10);

	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			int c;
			cin >> c;

			fw.create_edge(i, j, c);
		}
	}

	fw.process();

	int result = 0;

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			int a;
			cin >> a;

			if (a != -1)
			{
				result += fw.dist[a][1];
			}
		}
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int main(){

    ios :: sync_with_stdio(false);
    int N;
    cin >> N;
    int lo = -1;
    ll ans = -1;

    bool ok = 1;
    FOR(i,N){
        int x;
        cin >> x;
        if(x <= lo){
            ans += x;
        }
        else if(x == lo+1){
            ans += 1;
        }
        else ok = 0;

        lo = x;
    }

    if(!ok) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int m1 = sc.nextInt();
        int d1 = sc.nextInt();
        int m2 = sc.nextInt();
        int d2 = sc.nextInt();
        if(m1 == m2){
        	System.out.println("0");
        }else{
        	System.out.println("1");
        }
    }
}

Measured memory_bytes: 35828
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
int t[20][20];
const int inf = 1000;
void solve(int sum, int i, int j, int h, int w, char t2[20][20]) {
	if (i + 1 < h&&t2[i + 1][j] == '.'&&t[i+1][j]>sum+1) {
		t[i + 1][j] = sum + 1;
		solve(sum + 1, i + 1, j, h, w, t2);
	}
	if (i - 1 >= 0 && t2[i - 1][j] == '.'&&t[i-1][j]>sum+1) {
		t[i - 1][j] = sum + 1;
		solve(sum + 1, i - 1, j, h, w, t2);
	}
	if (j + 1 < w&&t2[i][j + 1] == '.'&&t[i][j+1]>sum+1) {
		t[i][j + 1] = sum + 1;
		solve(sum + 1, i, j + 1, h, w, t2);
	}
	if (j - 1 >= 0 && t2[i][j - 1] == '.'&&t[i][j-1]>sum+1) {
		t[i][j - 1] = sum + 1;
		solve(sum + 1, i, j - 1, h, w, t2);
	}
}
int main() {
	int h, w;
	char t2[20][20];
	int t3[20][20][10];
	while (cin >> h >> w&&h != 0 && w != 0) {
		string u;
		int p[2];
		int g[2];
		for (int i = 0; i < h; i++) {
			cin >> u;
			for (int j = 0; j < w; j++) {
				t2[i][j] = u[j];
				if (u[j] == 'A') {
					p[0] = i;
					p[1] = j;
				}
				if (u[j] == 'B') {
					g[0] = i;
					g[1] = j;
				}
				t[i][j] = inf;
				for (int z = 0; z < 10; z++) t3[i][j][z] = 0;
			}
		}
		string a;
		cin >> a;
		int b[10][2];
		for (int i = 0; i < a.length(); i++) {
			switch (a[i])
			{
			case '5':
				b[i][0] = 0;
				b[i][1] = 0;
				break;
			case '8':
				b[i][0] = -1;
				b[i][1] = 0;
				break;
			case '6':
				b[i][0] = 0;
				b[i][1] = 1;
				break;
			case '4':
				b[i][0] = 0;
				b[i][1] = -1;
				break;
			case '2':
				b[i][0] = 1;
				b[i][1] = 0;
			default:
				break;
			}
		}
		t[p[0]][p[1]] = 0;
		t2[g[0]][g[1]] = '.';
		int sum2 = 0;
		bool l = false;
		solve(0, p[0], p[1], h, w, t2);
		int k = 0, x = g[0], y = g[1], sum = 0;
		while (true) {
			x += b[k][0];
			y += b[k][1];
			k++;
			sum++;
			if (k >= a.length()) k = 0;
			x = max(0, min(x, h - 1));
			y = max(0, min(y, w - 1));
			if (t[x][y] <= sum) {
				cout << sum << " " << x << " " << y << endl;
				break;
			}
			if (t3[x][y][k] == 1&&!l) {
				sum2 = 0;
				l = true;
			}
			if (t3[x][y][k] == 2) {
				if (sum2 == 0) {
					cout << "impossible" << endl;
					break;
				}
			}
			if (l&&t[x][y]!=inf) {
				sum2++;
			}
			t3[x][y][k]++;
		}
	}
}

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

#define NIL NULL

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};

typedef struct node * Node;


Node root;

Node treeMim(Node x){

    while(x->left != NULL){
        x = x->left;
    }
    return x;
}


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


Node TreeSuccessor(Node x){
    Node y, p;
    if(x->right != NULL){
        return treeMim(x->right);
    }
    y = x->parent;
    while(y != NULL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void TreeDelete(Node z){
    Node x,y;

    if(z->left == NULL || z->right == NULL){
        y = z;
    }else{
        y = TreeSuccessor(z);
    }
    if(y->left != NULL){
        x = y->left;
    }else{
        x = y->right;
    }
    if(x != NULL){
        x->parent = y->parent;
    }
    if(y->parent == NULL){
        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 == NULL){
        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(" ");
        printf("%d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u){
    printf(" ");
    printf("%d", u->key);
    if(u->left != NIL){ 
        preorder(u->left);
    }
    if(u->right != NIL){
        preorder(u->right);
    }
}


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

    for (i=0; i<n; i++){
        scanf("%s", &com[0]);
        x = 0;
        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: 20456
#include <bits/stdc++.h>
using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (now == 1) {
      cout << i << '\n';
      return 0;
    }
    now = a[now];
  }
  cout << -1 << '\n';
  return 0;
}

Measured memory_bytes: 640
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        10000000070000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll x,mn=hell,n,ans=0;
	cin>>n;
	for(int i=0;i<5;i++){
		cin>>x;
		mn=min(mn,x);
	}
	ans=(n+mn-1)/mn+4;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,ans;
string a,b,c;
int main(){
    cin>>n>>a>>b>>c;
    ans=2*n;
    for(int i=0;i<n;i++){
        char x=a[i];
        char y=b[i];
        char z=c[i];
        if(x==y&&y==z)ans-=2;
        else if(x==y||x==z||y==z)ans--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	int h, w;
	cin >> h >> w;

	int y, x;
	cin >> y >> x;

	cout << (h - y) * (w - x) << endl;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    double a;
    double sum = 0;
    rep(i, 0, n){
        cin >> a;
        sum += (double)(1 / a);
    }
    cout << 1 / sum << endl;
}

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

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

        System.out.print(s.charAt(0));
        System.out.print(s.length() - 2);
        System.out.print(s.charAt(s.length() - 1));
    }
}


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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<ll>a(3*n);
  for(int i = 0;i < 3*n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(int i = 0;i < n;i++) ans += a[3*n-2*(i+1)];
  cout << ans << endl;
}


Measured memory_bytes: 2688
use std::io;
use std::cmp;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let (n, k) = {
        let a = read::<isize>();
        (a[0], a[1])
    };

    let mut cnt = 0;
    for b in 1..(n + 1) {
        let p = n / b;
        let q = n % b;
        cnt += p * cmp::max(0, b - k) + cmp::max(0, q - k + 1);
        if k == 0 { cnt -= 1; }
    }

    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    cin >> N;
    vll A(N), B(N);
    for(auto &a:A) cin >> a;
    for(auto &a:B) cin >> a;
    vll D(N);
    for (int i = 0; i < N; i++)
    {
        D[i] = A[i] - B[i];
    }
    DESC(D);
    vll pos, neg;
    for(auto &d:D) {
        if(d >= 0) {
            pos.push_back(d);
        }else {
            neg.push_back(d);
        }
    }
    if(accumulate(D.begin(), D.end(), 0LL) < 0) {
        cout << -1 << endl;
        return;
    }
    ll ans = neg.size();
    ll d = -accumulate(neg.begin(), neg.end(), 0LL);
    for(int i = 0; i < pos.size(); i++) {
        if(d <= 0) {
            cout << ans + i << endl;
            return;
        }
        d -= pos[i];
    }
    if(d <= 0) {
            cout << ans + pos.size() << endl;
            return;
    }
}

int main() {
    FIO;
    solve();
    return 0;
}


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

int main(){
    ll n,m2;
    cin >> n >> m2;
    vector <ll> p(n);

    rep(i,n){
        cin >> p[i];
    }

    vector <vector <int>> m(n);

    ll x,y;
    rep(i,m2){
        cin >> x >> y;
        m[x-1].push_back(y-1);
        m[y-1].push_back(x-1);

    }

    vector <ll> no(n,0);
    vector <ll> v1,v2,v3;
    queue <ll> q;
    ll qq;
    ll l;
    ll ans=0;

    rep(i,n){
        if(no[i]!=0){
            continue;
        }
        else{
            v1=v2;
            q.push(i);
            no[i]=-1;
            while(q.size()!=0){
                qq=q.front();
                q.pop();
                v1.push_back(qq);
                l=m[qq].size();
                rep(j,l){
                    if(no[m[qq][j]]==0){
                        no[m[qq][j]]=-1;
                        q.push(m[qq][j]);
                    }
                }
            }
            l=v1.size();
            v3=v1;
            rep(j,l){
                v3.push_back(p[v1[j]]);
                ++v3[j];
            }
            sort(v3.begin(),v3.end());
            l=v3.size();
            rep(j,l){
                if(j==0){
                    continue;
                }
                else{
                    if(v3[j]==v3[j-1]){
                        ++ans;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12428
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0; i <(n); i++)
int main(){
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);
  x=x-z;
  printf("%d\n",x/(y+z));
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <climits>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) cin >> s[i];

	vector<pair<int, int>> v(n, { 0, 0 });
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int tmp = 0;
		for (int j = 0; j < s[i].size(); ++j) {
			if (s[i][j] == '(') tmp++;
			else tmp--;
			v[i].second = min(v[i].second, tmp);
		}
		v[i].first = tmp;
		sum += tmp;
	}

	if (sum != 0) {
		cout << "No" << endl;
		return 0;
	}

	vector<pair<int, int>> v1, v2, v3;
	for (int i = 0; i < n; ++i) {
		if (v[i].second >= 0) v1.push_back(v[i]);
		else if (v[i].first >= 0) v2.push_back(v[i]);
		else v3.push_back(v[i]);
	}

	int now = 0;
	for (auto i : v1) {
		now += i.first;
	}
	
	vector<bool> used(n, false);
	bool update = true;
	while (update) {
		update = false;
		for (int i = 0; i < v2.size(); ++i) {
			if (used[i]) continue;
			if (-v2[i].second <= now) {
				now += v2[i].first;
				used[i] = true;
				update = true;
			}
		}
	}
	// cout << now << " " << v2.size() << endl;

	for (int i = 0; i < v2.size(); ++i) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	vector<vector<int>> x;
	for (auto i : v3) x.push_back({ i.first - i.second, i.first, i.second });
	sort(x.begin(), x.end());
	reverse(x.begin(), x.end());

	for (auto i : x) {
		// cout << now << " " << i[2] << endl;
		if (-i[2] > now) {
			cout << "No" << endl;
			return 0;
		}
		now += i[1];
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3232
s=int(input())
flag=False
d=[s]
count=1
while flag!=True:
  if s%2:
    s=3*s+1
    if s in d:
      flag=True
    d.append(s)
    count+=1
  else:
    s/=2
    if s in d:
      flag=True
    d.append(s)
    count+=1
print(count)

  

Measured memory_bytes: 2940
import itertools

n, m = [int(x) for x in input().split()]
edges = set(tuple(int(x) for x in input().split()) for _ in range(m))
print(sum(1 if all(p in edges or tuple(reversed(p)) in edges for p in [(1, path[0])] + list(zip(path, path[1:]))) else 0 for path in itertools.permutations(range(2, n + 1))))


Measured memory_bytes: 3060
A, B, K = map(int, input().split())

N = B - A + 1
limit = int(N / 2)
if K > limit:
  for i in range(A, B + 1):
    print(i)
else:
  for i in range(K):
    print(A + i)
  for i in range(K):
    print(B - K + 1 + i)



Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll x[100001];
ll cnt;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	cinf(x,n);
	rep(i,n-1){
		cnt+=(((x[i+1]-x[i])*a>b)?b:(x[i+1]-x[i])*a);
	}
	cout << cnt << endl;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long sum = 0, baf;
  for(int i = 1; i <= N; i++){
    sum += i;
    if(sum >= N){
      baf = i;
      break;
    }
  }
  sum = 0;
  for(int i = baf; i >= 1; i--){
    if(sum + i <= N){
      cout << i << endl;
      sum += i;
      if(sum == N)break;
    }
  }
  return 0;
}

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


using namespace std;

int main(){

    int N; cin>>N;

    string s = to_string(N);
    auto p = find (s.begin(), s.end(), '7');
    if (p == s.end()) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 3680
#include "bits/stdc++.h"
using namespace std;

vector< int > v[26];

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        v[s[i] - 'a'].emplace_back(i + 1);
    }

    for(int i = 0; i < 26; ++i) {
        if(v[i].size() < 2) continue;

        for(int j = 1; j < (int) v[i].size(); ++j) {
            int a = v[i][j];
            int b = v[i][j - 1];
            if(a - b <= 2) return !printf("%d %d\n", b, a);
        }
    }

    puts("-1 -1");
}

Measured memory_bytes: 1148
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;
vb a;

string func(int x,int y){
	vb b(n);
	b[0]=(x==0)?0:1;b[1]=(y==0)?0:1;
	for(int i=1;i<n-1;i++){
		if(b[i]^a[i]) b[i+1]=!b[i-1];
		else b[i+1]=b[i-1];
	}
	if(b[0]^a[0]&&b[1]==b[n-1]) return "!";
	if(!(b[0]^a[0])&&b[1]!=b[n-1]) return "!";
	if(b[n-1]^a[n-1]&&b[n-2]==b[0]) return "!";
	if(!(b[n-1]^a[n-1])&&b[n-2]!=b[0]) return "!";
	string res;
	for(int i=0;i<n;i++) res+=(b[i])?"S":"W";
	return res;
}

int main(){
	cin>>n;
	a=vb(n,0);
	for(int i=0;i<n;i++){
		char c;
		cin>>c;
		if(c=='o') a[i]=1;
	}
	for(int i=0;i<2;i++) for(int j=0;j<2;j++){
		string s=func(i,j);
		if(s[0]!='!'){
			cout<<s<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 640
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9+7;
const int maxn=1e5+5;

int n,m,cnt,cyc;
int deg[maxn],b[maxn],e[maxn];
bool vis[maxn];
vector<int> g[maxn];

void dfs(int u,int f){
	if(~e[cnt]) return;
	//printf("u=%d e=%d\n",u,e[cnt]);
	FOR(i,0,g[u].size()){
		int v=g[u][i];
		if(v==f) continue;
		if(~e[cnt]) return;
		if(deg[v]>=4){
			e[cnt]=v;
			vis[v]=true;
			return;
		}
		if(vis[v]) continue;
		vis[v]=true;
		dfs(v,u);
	}
	return;
}

int main(){
	scanf("%d%d",&n,&m);
	FOR(i,0,m){
		int u,v;
		scanf("%d%d",&u,&v);
		--u;--v;
		g[u].PB(v);
		g[v].PB(u);
		++deg[u];++deg[v];
	}
	FOR(u,0,n) if(deg[u]&1){
		puts("No");
		return 0;
	}
	FOR(u,0,n) if(deg[u]>=6){
		puts("Yes");
		return 0;
	}
	cnt=0;
	FOR(u,0,n) if(deg[u]>=4) ++cnt;
	if(cnt>2){
		puts("Yes");
		return 0;
	}
	cnt=0;
	memset(e,-1,sizeof(e));
	FOR(u,0,n) if(deg[u]>=4) FOR(i,0,g[u].size()){
		int v=g[u][i];
		if(!vis[v]){
			//printf("u=%d v=%d\n",u,v);
			b[cnt]=u;
			vis[u]=vis[v]=true;
			dfs(v,u);
			++cnt;
		}
		//FOR(j,0,n) printf("%d ",vis[j]);
		//puts("");
	}
	//FOR(i,0,cnt) printf("%d %d\n",b[i],e[i]);
	FOR(i,0,cnt) if(b[i]==e[i]){
		++cyc;
	}
	if(cyc+(cnt-cyc)/2>=3) puts("Yes");
	else puts("No");
	return 0;
}
/*
10 12
1 4
4 5
1 2
2 9
6 9
2 10
6 10
2 3
3 8
8 7
6 7
5 6

10 12
1 2
1 3
2 4
3 4
3 5
3 7
5 6
6 7
4 8
4 10
9 10
8 9
*/


Measured memory_bytes: 8832
"use strict";

function main(arg) {
    const S = arg.split("\n")[0].split("");
    if(S.some(n=>n=="a") && S.some(n=>n=="b") && S.some(n=>n=="c")) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

long long s[200005];

int main()
{
	long long n;
	cin>>n;
	long long a[n+1];
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
	}
	
	long long c=0;
	
	for(int i=n;i>=2;i--)
	{
		c+=(a[i]%1000000007)*(s[i-1]%1000000007);
		c=c%1000000007;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 6644
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ch[200],ans,L,ch2[200];
string s[200];
queue<ll>que;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        ll cnt=0;
        for(int j=0;j<n;j++){
            if(s[i][j]=='1')cnt++;
        }
        if(cnt==1)L=i;
    }
    que.push(L);
    //cout<<L<<endl;
    ch[L]=1;
    while(!que.empty()){
        ll q=que.front();
        que.pop();
        for(int i=0;i<n;i++){
            if(s[q][i]=='1'){
                if(ch[i]==0){
                    ch[i]+=ch[q]+1;
                    que.push(i);
                }
                else if(ch[i]==ch[q]){
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }
    }/*
    for(int i=0;i<n;i++){
        ans=max(ans,ch[i]);
    }*/
    for(int j=0;j<n;j++){
        for(int i=0;i<n;i++)ch2[i]=0;
    que.push(j);
    ch2[j]=1;
    while(!que.empty()){
        ll q=que.front();
        que.pop();
        for(int i=0;i<n;i++){
            if(s[q][i]=='1'){
                if(ch2[i]==0){
                    que.push(i);
                    ch2[i]+=ch2[q]+1;
                    ans=max(ans,ch2[i]);
                }
            }
        }
    }
    }
    cout<<ans<<endl;
}


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

// ----本問について----
// 問題：ナップザック問題
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/DPL_1_C
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

const ll N_MAX = 100 + 10;
const ll W_MAX = 10000 + 10;

// グローバル変数（入力）
ll N, W, v[N_MAX], w[N_MAX], dp[N_MAX][W_MAX];

ll solve(ll i, ll j) {                     // メモ化再帰（？）
  if (dp[i][j] != -1) { return dp[i][j]; } // 計算済みならその値を返す

  if (i == 0) {
    dp[i][j] = 0;
    return dp[i][j];
  }

  ll maxCount = floor((long double)j / w[i]);
  for (ll k = 0; k <= maxCount; k++) {
    dp[i][j] = max(solve(i - 1, j - w[i] * k) + v[i] * k, dp[i][j]);
  }

  return dp[i][j];
}

int main() {
  // cout << fixed << setprecision(10);
  rep(i, N_MAX) {
    rep(j, W_MAX) { dp[i][j] = -1; }
  }
  cin >> N >> W;
  vector<pair<ll, ll>> items(N);
  rep(i, N) {
    ll value, weight;
    cin >> value >> weight;
    items[i] = make_pair(weight, value);
  }
  // 同重量で価値が最大のもの以外間引きしていく
  sort(items.begin(), items.end());
  ll index = 0;
  rep(i, N - 1) {
    if (items[i].first != items[i + 1].first || i == N - 2) {
      items.erase(items.begin() + index, items.begin() + i);
      index = i + 1;
    }
  }
  N = items.size();
  rep(i, N) {
    w[i + 1] = items[i].first;
    v[i + 1] = items[i].second;
  }
  /*
  rep(i, N+1) {
    cout << "v[" << i << "] = " << v[i] << ", w[" << i << "] = " << w[i]
         << endl;
  }
  */
  cout << solve(N, W) << endl;
  return 0;
}



Measured memory_bytes: 11772
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 100005, mod = 998244353;
ll res;
int n, a[MX], cn[MX];

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

	res = a[0] == 0 && cn[0] == 1;
	for (int i = 1; i < n; i++)
		if (a[i])
			(res *= cn[a[i]-1]) %= mod;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll n,m;
  	cin >> n >> m;
  	vector<ll> x(m);
  	rep(i,m){
      cin >> x[i];
    }
  
  	sort(all(x));
  	vector<ll> diffs;
    for (ll i = 1; i < x.size(); ++i) diffs.push_back(x[i] - x[i-1]);
    sort(all(diffs), greater<ll>());
        
  	ll ans = x.back() - x[0];
    for (ll i = 0; i < min((ll)diffs.size(), n-1); ++i) ans -= diffs[i];
  	cout << ans << endl;
}

Measured memory_bytes: 2168
/*
    Washief Hossain Mugdho
    21 September 2020
    Educational DP Permutation
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
#define mod 1000000007
using namespace std;

inline int sub(int a, int b)
{
    int c = a - b;
    return c < 0 ? (c + mod) : c;
}

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    int n;
    string s;
    cin >> n >> s;
    int prefix[n][n + 1];

    for (int i = 1; i <= n; i++)
        prefix[0][i] = 1;
    for (int i = 0; i < n; i++)
        prefix[i][0] = 0;

    for (int i = 1; i < n; i++)
    {
        bool x = (s[i - 1] == '<');
        for (int j = 1; j <= i + 1; j++)
        {
            if (x)
                prefix[i][j] = (prefix[i][j - 1] + prefix[i - 1][j - 1]) % mod;
            else
                prefix[i][j] = (prefix[i][j - 1] + sub(prefix[i - 1][n], prefix[i - 1][j - 1])) % mod;
        }
        for (int j = i + 2; j <= n; j++)
            prefix[i][j] = prefix[i][i + 1];
    }
    cout << prefix[n - 1][n] << endl;
}


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

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


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

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<char> > area(n, vector<char>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> area[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool f = true;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(area[(i+j)%n][k] != area[(i+k)%n][j]) f = false;
            }
        }
        if(f) ans++;
    }
    cout << ans * n << endl;
}

Measured memory_bytes: 384