akhauriyash/Code-Regression huggingface dataset:
//AtCoder ABC114 C - 755
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll N;
ll check_val(vector<ll>& vtbl){
    ll ans=0;
    bool has[10]={};
	{
		ll val = 0;
		for(auto &&v : vtbl) {
            has[v]=true;
			val *= 10;
			val += v;
		}
        //cout<<val<<endl;
		if(val <= N && has[3]&&has[5]&&has[7]) ++ans;
	}
    return ans;
}
ll search(vector<ll> tbl, ll keta){
    ll ans = 0;//search_num(tbl);
    if (keta<=tbl.size())return ans;
	for(auto &n : {3, 5, 7}) {
		auto tmp = tbl;
        tmp.push_back(n);
        ans += check_val(tmp);
        ans += search(tmp, keta);
	}
    return ans;
}
int main() {
    cin>>N;
    ll keta=0;
    {
        ll n=N;
        while(n>0){
            n/=10;
            ++keta;
        }    
    }
    vector<ll> vtbl;
    ll ans=search(vtbl, keta);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b)
{
    if (a > b)
    {
        return gcd(b, a);
    }
    if (b % a == 0)
    {
        return a;
    }
    else
    {
        return gcd(a, b % a);
    }
}

int main()
{
    int n;
    cin >> n;
    uint64_t ans;
    cin >> ans;
    for (int i = 0; i < n - 1; i++)
    {
        uint64_t a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define N 2010
int n,k,d[N];
vector<int> v[N];
struct point{
	int x,y;
}e[N];
void dfs(int x,int last)
{
	for(int i=0,y;i<v[x].size();i++)
	{
		y=v[x][i];
		if(y==last) continue;
		d[y]=d[x]+1;
		dfs(y,x);
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1,a,b;i<=n-1;i++)
	{
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
		e[i].x=a,e[i].y=b;
	}
	int ans=N;
	if(k&1)
	{
		int tep;
		for(int i=1,x,y;i<n;i++)
		{
			tep=0;
		 	x=e[i].x,y=e[i].y;
		 	d[x]=d[y]=0;
		 	dfs(x,y),dfs(y,x);
		 	for(int j=1;j<=n;j++)
		 		if(d[j]>k/2) tep++;
		 	ans=min(ans,tep);
		}
	}
	else
	{
		int tep;
		for(int i=1;i<=n;i++)
		{
			tep=0;
		 	d[i]=0;
		 	dfs(i,0);
		 	for(int j=1;j<=n;j++)
		 		if(d[j]>k/2) tep++;
		 	ans=min(ans,tep);
		}	
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

#define rep(i,n) for (long long int i = 0; i < (n); i++)

using namespace std;

int main(int argc, char* argv[]){
  long long int A, B, C, D;
  cin >> A >> B >> C >> D;

  while(1){
    C = C - B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 20
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P; 
#define INF 100000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    int t[n];
    REP(i,n){
        t[i]=0;
    }
    int f[10];
    f[0]=f[1]=1;
    for(int i=1;i<9;i++){
        f[i+1]=(i+1)*f[i];
    }
    vector<int> p(n);
    vector<int> q(n);
    REP(i,n){
        cin>>p[i];
    }
    REP(i,n){
        cin>>q[i];
    }
    int a=0;
    int b=0;
    REP(i,n){
        int cnt=0;
        REP(j,n){
            if(t[j]==-1){
                cnt++;
            }else if(p[i]-1==j){
                a+=f[n-1-i]*(j-cnt);
                t[p[i]-1]=-1;
                break;
            }
        }
    }
    REP(i,n){
        t[i]=0;
    }
    REP(i,n){
        int cnt=0;
        REP(j,n){
            if(t[j]==-1){
                cnt++;
            }else if(q[i]-1==j){
                b+=f[n-1-i]*(j-cnt);
                t[q[i]-1]=-1;
                break;
            }
        }
    }
    OUT(abs(a-b));
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

const ll max_V=1000;//大きすぎ注意

struct edge{ll to,cost;};

ll N;//頂点数
ll M;
ll cst[max_V][max_V];
vector<edge> G[max_V];
//bool used[max_V];
//ll d[max_V];//頂点sからの最短距離

//ll pr[max_V];

void dijkstra(ll s,V<ll> &d,V<ll> &pr){
    priority_queue<P,vector<P>,greater<P>> que;
    // fill(d,d+N,INF);
    d[s]=0;
    que.push(P(0,s));//pair...first->最短距離、second->頂点

    while(!que.empty()){
        P p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
                pr[e.to]=v;
            }
        }
    }
}

void dijkstra_restore(ll s,V<ll> &d,V<ll> &pr,V<bool> &used){
    // fill(d,d+N,INF);
    // fill(used,used+N,0);
    // fill(pr,pr+N,-1);
    d[s]=0;

    while(true){
        ll v=-1;
        for(int u=0;u<N;u++){
            if(!used[u]&&(v==-1||d[u]<d[v])) v=u;
        }

        if(v==-1) break;
        used[v]=1;

        for(int u=0;u<N;u++){
            if(d[u]>d[v]+cst[v][u]){
                d[u]=d[v]+cst[v][u];
                pr[u]=v;
            }
        }
    }
}

//頂点tへの最短路
vector<ll> get_path(ll t,V<ll> pr){
    vector<ll> path;
    for(;t!=-1;t=pr[t]) path.push_back(t);//tがsになるまでprev[t]をたどっていく
    reverse(all(path));
    return path;
}

signed main(){
    cin>>N>>M;
    set<ll> st;
    map<P,ll> mp;
    rep(i,M){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        edge A,B;
        A.to=b;A.cost=c;
        B.to=a;B.cost=c;
        G[a].push_back(A);
        G[b].push_back(B);
        //cst[a][b]=cst[b][a]=c;
        mp[P(a,b)]=mp[P(b,a)]=i;
    }
    for(ll i=0;i<N-1;i++){
        for(ll j=i+1;j<N;j++){
            //if(i==j) continue;
            V<ll> dist(N,INF),pr(N,-1);
            V<bool> used(N,0);
            dijkstra(i,dist,pr);
            V<ll> path=get_path(j,pr);
            ll m=path.size();
            for(int k=0;k<m-1;k++){
                ll v=mp[P(path[k],path[k+1])];
                st.insert(v);
            }
        }
    }
    cout<<M-st.size()<<endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >>  W >> H >> x >> y >> r;
    int check = 1;
    if (x - r < 0 || x + r > W || y - r < 0 || y + r > H)
        check = 0;
    if (check)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3092
open Batteries
open BatPrintf

let dbg n = Printf.eprintf "%s\n" @@ dump n; n

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_listn n cnv =
  List.range 1 `To n |> List.map (fun _ -> cnv @@ read_line ())

let bsearch_ge arr a =
  let l = Array.length arr in
  match Array.bsearch Int.ord arr a with
  | `All_lower -> l
  | `All_bigger -> 0
  | `Just_after n -> l - n -1
  | `At n -> l - n
  | `Empty -> 0

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let square x = x * x

let as_ = scan_listn 3
    (fun s -> String.split_on_char ' ' s |> List.Labels.map ~f:Int.of_string)
let n = scan "%d" identity
let bs = scan_listn n Int.of_string
let bingo = [[(0,0);(0,1);(0,2)]; [(1,0); (1,1); (1,2)]; [(2,0);(2,1);(2,2)];
             [(0,0);(1,0);(2,0)]; [(0,1); (1,1); (2,1)]; [(0,2);(1,2);(2,2)];
             [(0,0);(1,1);(2,2)];
             [(2,0);(1,1);(0,2)]]
let () =
  List.mapi
    (fun i a -> List.mapi (fun j b -> if List.exists ((=) b) bs then Some (i,j) else None) a) as_
  |> List.flatten
  |> List.filter Option.is_some
  |> List.map Option.get
  |> (fun l -> List.exists ((=) true) @@ List.map (fun b -> (List.fold_left (fun r c -> List.exists ((=) c) l && r) true b)) bingo)
  |> (fun ans -> printf "%s\n" (if ans then "Yes" else "No"))


Measured memory_bytes: 1024
MOD = 10**9 + 7
n = int(input())
if n == 1:
    print(0)
    exit()
print((pow(10,n,MOD)-pow(8,n,MOD)-pow(9,n,MOD)+pow(8,n,MOD)-pow(9,n,MOD)+pow(8,n,MOD))%MOD)

Measured memory_bytes: 9048
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;


long long int N,M,K,Q,res,sum=0,X,Y,a,memo[200050]={},t[100050]={},x[100050]={},y[100050]={};
string str;
vector<long long int>vec;


int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>X>>Y;
    cout<<max((N-2)*Y-(N-2)*X+1,0LL)<<endl;
    
    
}


Measured memory_bytes: 256
from math import factorial
n=int(input())
d=[[0]*10 for _ in range(10)]
for i in range(1,n+1):
  j=i
  while True:
    if j//10:j//=10
    else:break
  d[j][i%10]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=d[i][j]*d[j][i]
print(ans)

Measured memory_bytes: 64636
import sys
input = sys.stdin.buffer.readline

def main():
    a,b,c = map(int,input().split())
    
    if c-a-b < 0:
        print("No")
    elif 4*a*b < (c-a-b)**2:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i <= b; ++i) {
        if ((a*i) % b == c) {
            cout << "YES" << std::endl;
            return 0;
        }
    }
    cout << "NO" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,a1,a2,a3,a4;
    vector<int >v;
    cin>>a>>a1>>a2>>a3>>a4;
    v.push_back(a);
    v.push_back(a1);
    v.push_back(a2);
    v.push_back(a3);
    v.push_back(a4);
    int c=1;
    for(int i=0; i<v.size(); i++)
    {
        if(v[i]==0)
        {
            cout<<c<<endl;return 0;
        }
        else
            c++;
    }
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;
    vec A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    ll ans = 0;
    while (true) {
        ll tmp = 0;
        Rep (i, N) {
            tmp += A[i] / N;
        }

        if (tmp == 0) break;
        ans += tmp;
        Rep (i, N) {
            ll a = A[i];
            A[i] += tmp - a / N;
            A[i] -= a / N * N;
        }

        // printvec(A);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

int main(){
    /*
    棒の高さH
    縦棒の本数W
    目的地K
    */
    int H,W,K;cin>>H>>W>>K;
    /*
    A(h,x) 上からh列目を通過した直後に左からx本目の縦棒にいる場合の数
    h=0のときは一列目より前
    h(0,1) = 1,h(0,2etc) = 0が初期状態
    A(h,x)からA(h+1,x-1) A(h+1,x) A(h+1,x+1)に遷移する
    */
   vector<vector<int>> dp(H+1,vector<int>(W,0)); dp[0][0] = 1;
   REP(i,H){
       //iは上からの高さ
       REP(j,W){
           //jは左からの本数
           REP(k,1<<(W-1)){
               //それぞれについてつなぐつながないの2通りがあると考える2^(W-1)
               //01で繋がってるかをkが表していると考える
               bool ok = true;
               REP(l,W-2){
                   if( ((k>>l) & 1) and ((k>>(l+1)) & 1)){
                       ok = false;
                   }
               }
                if(ok){
                    if( j>= 1 and ((k>>(j-1))&1)){
                        //左方向に進む
                        dp[i+1][j-1] += dp[i][j];
                        dp[i+1][j-1] %= MOD;
                    }else if(j<= W-2 and ((k >> j) & 1)){
                        //右方向に進む
                        dp[i+1][j+1] += dp[i][j];
                        dp[i+1][j+1] %= MOD;
                    }else{
                        //どこにも行かない
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= MOD;
                    }
                }
            }
        }
    }
   cout<<dp[H][K-1]<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll arr[3][3];
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	ll n;
	cin>>n;
	ll brr[15];
	ll f[3][3]={0};
	for(int i=0;i<n;i++)
	{
		cin>>brr[i];
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(brr[i]==arr[j][k])
				{
					f[j][k]=1;
				}
			}
		}
	}
	if((f[0][0]==1&&f[0][1]==1&&f[0][2]==1)||(f[1][0]==1&&f[1][1]==1&&f[1][2]==1)||(f[2][0]==1&&f[2][1]==1&&f[2][2]==1)||(f[0][0]==1&&f[1][0]==1&&f[2][0]==1)||(f[0][1]==1&&f[1][1]==1&&f[2][1]==1)||(f[0][2]==1&&f[1][2]==1&&f[2][2]==1)||(f[0][0]==1&&f[1][1]==1&&f[2][2]==1)||(f[2][0]==1&&f[1][1]==1&&f[0][2]==1))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int kuadrat(int a,int b){
	int total = 1;
	for(int i=1;i<=b;i++){
		total = total * a;
	}
	return total;
}
	
	int main(){
	
	int n;
	scanf("%d",&n);
	
	printf("%d",kuadrat(n,1) + kuadrat(n,2) + kuadrat(n,3));



		return 0;
	}

Measured memory_bytes: 1644
s = gets.chomp
loop do
  if s == ""
    puts "YES"
    break
  elsif s[0, 7] == "dreamer"
    if s[7] == "a"
      s.slice!(0, 5)
    else
      s.slice!(0, 7)
    end
  elsif s[0, 6] == "eraser"
    s.slice!(0, 6)
  elsif s[0, 5] == "dream"
    s.slice!(0, 5)
  elsif s[0, 5] == "erase"
    s.slice!(0, 5)
  else
    puts "NO"
    break
  end
end

Measured memory_bytes: 64636
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

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

		int n=s.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		
		int[] dp=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(arr[1]-arr[0]);
		for(int i=2;i<n;i++) {
			dp[i]=Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]), dp[i-2]+Math.abs(arr[i]-arr[i-2]));
		}
		
		System.out.println(dp[n-1]);
		
		
	
		
	}
}

Measured memory_bytes: 50564
using System;
using System.Collections.Generic;
namespace alds17c
{
    class node{
        public int id;
        public node parent;
        public node left;
        public node right;

        public node(int setid)
        {
            id = setid;
       }
        public void setleft(node tgt){
            left = tgt;
            tgt.parent = this;
        }
        public void setright(node tgt)
        {
            right = tgt;
            tgt.parent=this;
        }
        public void writepre()
        {
            Console.Write(" ");
            Console.Write(id);
            if (left != null) left.writepre();
            if (right != null) right.writepre();
        }
        public void writein()
        {
            if (left != null) left.writein();
            Console.Write(" ");
            Console.Write(id);
            if (right != null) right.writein();
        }
        public void writepost()
        {
            if (left != null) left.writepost();
            if (right != null) right.writepost();
            Console.Write(" ");
            Console.Write(id);
        }


    }
    class main
    {
        static void Main()
        {
            List<node> all=new List<node>();
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                all.Add(new node(i));
            }
            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int tgt = int.Parse(input[0]);
                int left = int.Parse(input[1]);
                int right = int.Parse(input[2]);
                if (left != -1) all[tgt].setleft(all[left]);
                if (right != -1) all[tgt].setright(all[right]);
            }
            node root = all[0];
            foreach (node tgt in all)
            {
                if (tgt.parent == null)
                {
                    root = tgt;
                    break;
                }
            }
            Console.WriteLine("Preorder");
            root.writepre();
            Console.WriteLine();
            Console.WriteLine("Inorder");
            root.writein();
            Console.WriteLine();
            Console.WriteLine("Postorder");
            root.writepost();
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5684
// Aizu 1144: Curling 2.0
// 2017.9.17 bal4u@uu

#include <stdio.h>
#include <string.h>

int m[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
char map[22][22]; int w, h;
int ans;

void combi(int r0, int c0, int k)
{
	int i, r, c, dr, dc;

	if (k++ == 10) return;
	for (i = 0; i < 4; i++) {
		dr = m[i][0], dc = m[i][1];
		r = r0 + dr, c = c0 + dc;
		if (r < 0 || r >= h || c < 0 || c >= w || map[r][c] == 1) continue;
		r = r0, c = c0;
		while (1) {
			r += dr, c += dc;
			if (r < 0 || r >= h || c < 0 || c >= w) break;
			if (map[r][c] == 3) { if (k < ans) ans = k; break; }
			if (map[r][c] == 1) {
				map[r][c] = 0, combi(r-dr, c-dc, k), map[r][c] = 1;
				break;
			}
		}
	}
}

int main()
{
	int a, r, c, sr, sc;

	while(scanf("%d%d", &w, &h) && w) {
		for (ans = sr = -1, r = 0; r < h; r++) for (c = 0; c < w; c++) {
			scanf("%d", &a), map[r][c] = a;
			if (a == 2) sr = r, sc = c, map[r][c] = 0;
		}
		if (sr >= 0) { ans = 11, combi(sr, sc, 0); if (ans > 10) ans = -1; }
		printf("%d\n", ans);
	}
	return 0;
}

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

int grade(int a,int b,int c){
    if(a+b>=80)return 'A';
    else if(a+b>=65)return 'B';
    else if(a+b>=50)return 'C';
    else if(a+b>=30 && c>=50)return 'C';
    else if(a+b>=30)return 'D';
    else{return 'F';}
}
int main(){
    int m,f,r;
    while(true){
    cin>>m>>f>>r;
    if(m==-1 && f==-1 && r==-1)break;
    if(m==-1 || f==-1)cout<<'F'<<endl;
    else{
        char ans=grade(m,f,r);
        cout<<ans<<endl;
    }
    }
    return 0;
}


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

int main()
{
 int N;
  cin >> N;
  
   int a ; 
  if(N % 1000 == 0)
  {
    a = 0;
  }else{
a= 1000 - N % 1000;
  }
  cout << a;
  return 0;
 
  
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(){
	int n, x;
	scanf("%d", &n);
	if(n % 2 == 0){
		x = n;
		printf("%d\n", x);
	}
	else{
		x = n * 2;
			printf("%d\n", x);
	}	
	return 0;
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,t = readInts()
T = readInts()
ma = max(T)
rest = n - ma
print(max(0,ma - rest - 1))


Measured memory_bytes: 10452
N = int(input())
As = list(map(int, input().split()))
if 0 in As:
    print(0)
else:
    As = sorted(As, reverse=True)
    ans = 1
    break_flag = 0
    for n in range(N):
        ans *= As[n]
        if ans > 1e18:
            print(-1)
            break_flag = 1
            break
    if break_flag == 0:
        print(ans)

Measured memory_bytes: 21660
def aroundbom(i , q , h , w , sl):
    bomcount = 0
    dx = [1 , 1 , 0 , -1 , -1 , -1 , 0 , 1]
    dy = [0 , 1 , 1 , 1 , 0 , -1 , -1 , -1]

    for b in range(len(dx)):
        t = i + dx[b]
        y = q + dy[b]
        if t >= 0 and t < h and y >= 0 and y < w and sl[t][y] == "#":
            bomcount += 1

    return str(bomcount)

def minesweeper(h , w , sl):

    ans = []

    for i in range(h):
        count = []
        for q in range(w):
            if sl[i][q] == ".":
                count.append(aroundbom(i , q , h , w , sl))
            else:
                count.append("#")
        ans.append(count)

    return ans

def main():
    h , w = map(int , input().split())
    sl = [list(str(input())) for i in range(h)]
    ans = minesweeper(h , w , sl)

    for i in ans:
        print("".join(i))

if __name__ == '__main__':
    main()

Measured memory_bytes: 42096
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




bool is_prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}

	return true;
}

int main() {
	
	vll prims_acc(100001, 0);
	fori(i, 1, 100001) {
		if (is_prime(i) && is_prime((i + 1) / 2)) prims_acc[i] = prims_acc[i - 1] + 1;
		else prims_acc[i] = prims_acc[i - 1];
	}

	ll Q; cin >> Q;
	rep(i, Q) {
		ll l, r;
		cin >> l >> r;
		cout << prims_acc[r] - prims_acc[l - 1] << endl;
	}
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
int a[120000];
int main()
{
    cin>>n>>k;
    for (int i=0; i<n; ++i)
        cin>>a[i];
    sort(a,a+n);
    int m=2000000000;
    for (int i=0; i<n; ++i)
    {
        int s=i,e=i+k-1;
        if (e>=n) break;
        int ta=a[e]-a[i];
        if (ta<m) m=ta;
    }
    cout<<m<<endl;

    return 0;
}


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

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = IO.GetInt();

            int[][] memo = new int[9][];
            for(int i = 0; i < 9; i++)
            {
                memo[i] = new int[9];
                for(int j = 0; j < 9; j++)
                {
                    memo[i][j] = 0;
                }
            }

            int ans = 0;
            for(int n = 1; n <= N; n++)
            {
                var f = n.First();
                var l = n.Last();
                if(f == 0 || l == 0) { continue; }
                memo[f-1][l-1]++;
            }
            for(int i = 0; i < 9; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    ans += memo[i][j] *memo[j][i];
                }
            }


            Console.WriteLine(ans);


        }

        static int First(this int i)
        {
            return int.Parse(i.ToString().First().ToString());
        }

        static int Last(this int i)
        {
            return int.Parse(i.ToString().Last().ToString());
        }
    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 15540
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
 string t;
  cin >> t;
  
  rep(i,0,t.size()){
   if(t[i]=='?'){
     t[i]='D';
   }
  }
  
  
 cout << t << endl;

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

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int n, k;
vector<int> h;
int dp[310][310][310];
bool vis[310][310][310];

int solve(int N, int K, int P)
{
    if (vis[N][K][P])
        return dp[N][K][P];
    vis[N][K][P] = true;
    if (N == n + 1)
        return 0;
    int pre = h[P];
    int res = solve(N + 1, K, N) + max(0LL, h[N] - pre);
    if (K > 0)
    {
        res = min(res, solve(N + 1, K - 1, P));
        res = min(res, solve(N + 1, K - 1, N + 1) + max(0LL, h[N + 1] - pre));
    }
    return dp[N][K][P] = res;
}

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

    cin >> n >> k;
    h.resize(n + 1);
    h[0] = 0;
    rep(i, n) cin >> h[i + 1];
    cout << solve(1, k, 0) << endl;
}

Measured memory_bytes: 254464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

int N;
string s;

int main(){
    cin >> N;
    if(N % 10 == 3) cout << "bon";
    else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon";
    else cout << "hon";
	return 0;
}

Measured memory_bytes: 3676
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define con continue;
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
void coutv(vector<ll> v)
{
    for (auto it : v)
        cout << it << " ";
    cout << endl;
}
bool can(ll x, ll y)
{
    return y <= 2 * x;
}
int main()
{
    MOAE;
    ll a, b;
    cin >> a >> b;
    cout << ((a + b) % 3 == 0 or a % 3 == 0 or b % 3 == 0 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
const int MAXN = 2e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

int n, c[MAXN];
ll dp[MAXN];
int nex[MAXN], mp[MAXN];

ll rec(int i) {
  if (i == n) return 1;
  ll &ret = dp[i];
  if (ret != -1) return ret;
  ret = rec(i+1);
  if (nex[i] != 0 && nex[i] != i+1)
    ret = (ret+rec(nex[i]))%mod;
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> c[i];
  memset(dp,-1,sizeof dp);
  for (int i = n; i > 0; i--) {
    nex[i] = mp[c[i]];
    mp[c[i]] = i;
  }
  cout << rec(1);
  return 0;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <set>
#include <unordered_map>
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

int main(){
    ofstream out("output.txt");

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


    int n,m;
    cin>>n>>m;

    if(n<=5){
        cout<<0<<endl;
    }
    else if(n<=12){
        cout<<m/2<<endl;
    }
    else{
        cout<<m<<endl;
    }
    


    return 0;
}







Measured memory_bytes: 256
from collections import defaultdict
def main(w, h):
    field = [list(input()) for i in range(h)]
    d = defaultdict(str)
    for y in range(h - 1, -1, -1):
        for x in range(w - 1, -1, -1):
            if "0" <= field[y][x] <= "9":
                d[(x, y)] = field[y][x]
    for y in range(h - 1, -1, -1):
        for x in range(w - 1, -1, -1):
            if "0" <= field[y][x] <= "9":
                if len(d[(x + 1, y)]) == len(d[(x, y + 1)]):
                    d[(x, y)] = field[y][x] + max(d[(x + 1, y)], d[(x, y + 1)])
                elif len(d[(x + 1, y)]) < len(d[(x, y + 1)]):
                    d[(x, y)] = field[y][x] + d[(x, y + 1)]
                else:
                    d[(x, y)] = field[y][x] + d[(x + 1, y)]
    ans = 0
    for v in d.values():
        if v == "":
            continue
        ans = max(ans, int(v))
    print(ans)

while 1:
    w, h = map(int, input().split())
    if h == w == 0:
        break
    main(w, h)


Measured memory_bytes: 6068
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;

  ll result = 0;

  for (int i = 0; i < n; i++){
    if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
      result += 2;
    }
    else if (a[i] == b[i] && b[i] == c[i]){
      result += 0;
    }
    else{
      result += 1;
    }
  }

  cout << result << endl;
}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


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

int main() {
	int num1, num2;
	cin >> num1 >> num2;

	if(num1 < num2){
		cout << "a < b" << endl;
	} else if(num1 > num2){
		cout << "a > b" << endl;
	} else {
		cout << "a == b" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int k;
    cin >> k;
    int odd ,even;
    if(k%2==0){
        odd = k/2; even = k/2;
    }else{
        odd = k/2; even = k/2+1;
    }
    //cout << odd << "," << even<< endl;
    cout << odd * even << endl;
    return 0;
}

Measured memory_bytes: 384
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) + reverse_count == 2:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 102916
#include<iostream>
#include<complex>

using namespace std;

int main(){

        int a,b,c,d;
        int FLG1,FLG2,FLG3;

        cin >> a >> b >> c >> d;

        FLG1=0;
        FLG2=0;
        FLG3=0;

        if(abs(a - b) <= d){

                FLG1=1;

        }

        if(abs(b - c) <= d){

                FLG2=1;

        }

        if(abs(a - c) <= d){

                FLG3=1;

        }

        if(FLG1==1 && FLG2==1 || FLG3==1){

        cout << "Yes" << endl;

        }else{

                cout << "No" << endl;

        }

        return 0;


}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b, c;
	int hako[10000];
	int ans = 0;

	int i, j;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	int box = c;
	for (i = 0; i < 10; i++) {
		ans = a * box - b;
		box = ans;
		printf("%d\n", ans);
	}
	

	return 0;
}

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

int main(){
  ll n; cin >> n;
  ll sum = 0;
  for(ll i=1;i<=n; ++i){
    if(i % 3 != 0 && i % 5 != 0) sum += i;
  }
  cout << sum << endl;
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int K;
    cin >> K;

    int N = s.length();

    set<string> ans;
    for(int i=0; i<N; i++)
    {
        for(int j=0; i+j<N && j<5; j++)
        {
            ans.emplace(s.substr(i, j+1));
        }
    }
    auto itr = ans.begin();
    for(int i=0; i<K-1; i++) itr++;
    cout << *itr << endl;
    // for(auto itr = ans.begin(); itr != ans.end(); itr++)
    // {
    //     cout << *itr << endl;
    // }

    return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int r,g,b;
    cin>>r>>g>>b;
    int d=10*g+b;
    if(d%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}



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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, x, y, z;

string solve(){
    cin >> n;
    for(int i = 0, cur; i < n; ++i){
        cin >> cur;
        if(cur % 4 == 0) x++;
        else if(cur % 2 == 0) z++;
        else y++;
    }

    bool ok;

    if(z && !x && !y) ok = 1;
    else{
        y += (z > 0);
        ok = (y - x) <= 1;
    }

    return ok ? "Yes" : "No";
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n, ans = 0;
	map < ll, ll > freq;
	vector < ll > g; 
	cin >> n;
	for(ll i = 2; i * i <= n; ++i){
		bool ok = false;
		while(n % i == 0){
			freq[i]++;
			n /= i;
			ok = true;
		}
		if(ok)g.push_back(i);
	}
	if(n > 1)g.push_back(n), freq[n]++;
	for(int i = 0; i < (int)g.size(); ++i){
		int sum = 0, cur;
		for(int cnt = 1; sum <= freq[g[i]]; ++cnt){
			sum += cnt;
			cur = cnt - 1;
		}
		ans += cur;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<vector<int> > a(3,vector<int>(3,0));
  int n;
  rep(i,3){
    rep(j,3){
      cin>>a[i][j];
    }
  }
  bool flag[4][4]={};
  cin>>n;
  vint b(n);
  rep(i,n){
    cin>>b[i];
    rep(j,3){
      rep(k,3){
        if(b[i]==a[j][k]){
          flag[j][k]=true;
        }
      }
    }
  }
  bool fg=false;
  rep(i,3){
    if(flag[i][0] && flag[i][1] && flag[i][2]){
      cout<<"Yes"<<'\n';
      return(0);
    }
    if(flag[0][i] && flag[1][i] && flag[2][i]){
      cout<<"Yes"<<'\n';
      return(0);
    }
  }
  if(flag[0][0] && flag[1][1] && flag[2][2]){
    cout<<"Yes"<<'\n';
    return(0);
  }
  if(flag[0][2] && flag[1][1] && flag[2][0]){
    cout<<"Yes"<<'\n';
    return(0);
  }
  cout<<"No"<<'\n';

  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll gcd(ll x,ll y){
    if(x<y) return gcd(y,x);
    if(y==0) return x;
    return gcd(y,x%y);
}

int main(){
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll maxi=0;
    ll g;
    rep(i,0,n-1){
        maxi=max(maxi,a[i]);
        if(i==0){
            g=a[i];
        }else{
            g=gcd(g,a[i]);
        }
    }
    if(g==1 && k<=maxi){
        cout<<"POSSIBLE"<<endl;
    }else if(g>1 && k%g==0 && k<=maxi){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    
    return 0;
}






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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin >> d[i];
    }

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

    cout << d[N/2] -d[N/2 -1];
}

Measured memory_bytes: 640
n = int(input())
SP = [input().split() for i in range(n)]
for i in range(n):
  SP[i][1] = 100 - int(SP[i][1])
A = sorted(SP)
ans = [0]*n

for i in range(n):
  for j in range(n):
    if A[i] == SP[j]:
      print(j+1)
    else:
      pass

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int N, a, i, x;
    cin >> N;
    x = 0;
    for(i = 1; N >= i; i++){
        if(i%2 == 1){
            x = x + 1;
        }
    }
    cout << (double)x/N << endl;
    
    
    
    return 0;
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 3772
def inpl():
    return list(map(int, input().split()))


S = input()
ans = [0 for i in range(len(S))]
R = 0
L = 0
flag = False
k = 0
N = len(S)

for i in range(N):
    if flag is False:
        if S[i] == 'R':
            R += 1
        elif S[i] == 'L':
            flag = True
            L += 1
            k = i
            ans[i - 1] += R // 2 + R % 2
            ans[i] += R // 2
            R = 0

    elif flag is True:
        if S[i] == 'L':
            L += 1
        elif S[i] == 'R':
            R += 1
            flag = False
            ans[k] += L // 2 + L % 2
            ans[k - 1] += L // 2
            L = 0

ans[k] += L // 2 + L % 2
ans[k - 1] += L // 2

print(" ".join(map(str, ans)))


Measured memory_bytes: 10492
#include <stdio.h>

int main(){
	char n[20];
	scanf("%s",&n);
	int len = strlen(n);
	
	int all9 = 1; // all number *expect the first digil*   is 9
	for(char* i = n+1; *i != NULL; i++){
		if( *i != '9' ){
			all9 = 0;
			break;
		}
	}
	
	int ret = 9 * (len - 1);

	n[1] = NULL;
	ret += atoi( n );
	if( ! all9 ) ret -= 1;

	printf("%d\n", ret);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100;
unsigned long long n, t = 10, pos = 1, m, a, b, c, ans, A[MAXN] = { 1,1 };
string str1, str2;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	if (n % 2)
	{
		cout << 0 << endl;
	}
	else
	{
		while (a = n / t)
		{
			ans += a;
			t *= 10;
		}
		t = 50;
		while (a = n / t)
		{
			ans += a;
			t *= 5;
		}
		t = 100;
		while (a = n / t)
		{
			ans -= a;
			t *= 10;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from _collections import deque
k = int(input())

l = [str(i) for i in range(1,10)]
que = deque(l)


while len(l) < k:
    seq = que.popleft()

    a = int(seq[-1])
    if a != 0:
        aa = seq + str(a-1)
        que.append(aa)
        l.append(aa)
    aa = seq + str(a)
    que.append(aa)
    l.append(aa)
    if a != 9:
        aa = seq + str(a+1)
        que.append(aa)
        l.append(aa)

print(l[k-1])



Measured memory_bytes: 86788
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
M = 1000
for i in range(N):
  K = abs(A-(T-H[i]*0.006))
  if K<M:
      basho = i + 1
      M = K
print(basho)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
    int main(){
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    if(s.at(k - 1) == 'A')
    s.at(k - 1) = 'a';
    else if(s.at(k - 1) == 'B')
    s.at(k - 1) = 'b';
    else 
    s.at(k - 1) = 'c';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func solve(k int) int {
	n := 7
	for i := 1; i <= k; i++ {
		n %= k
		if n == 0 {
			return i
		}
		n = 10*n + 7
	}
	return -1
}

func main() {
	k, _ := strconv.Atoi(input())
	fmt.Println(solve(k))
}


Measured memory_bytes: 1788