akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


int chartoint(char c){
  if(c == 'T') return '9' - '0' + 1;
  if(c == 'J') return '9' - '0' + 2;
  if(c == 'Q') return '9' - '0' + 3;
  if(c == 'K') return '9' - '0' + 4;
  if(c == 'A') return '9' - '0' + 5;
  return c - '0';
}

ll compare(string a, string b, char joker, char table){
  if(a[1]!=b[1]){
    if(a[1] == joker) return 0;
    if(b[1] == joker) return 1;
    if(a[1] == table) return 0;
  }
  else{
    int ai = chartoint(a[0]);
    int bi = chartoint(b[0]);
//    cout<<"  compare " <<ai<<" "<<bi<<endl;
    if(ai>bi) return 0;
  }
  return 1;
}

ll ns=0;
ll pri=0;
void game(string n, string e, string s, string w, char joker){
  ll win = 0;
  string tmp = n;
  vector<string> v = {n,e,s,w};
  char table = v[pri][1];
//  cout<<" table is "<<table<<endl;
//  cout<<" "<<pri<<endl;
  FOR(i,1,4){
    if(compare(tmp,v[i],joker,table)){
      win = i;
      tmp = v[i];
//      cout<<"  "<<win<<endl;
    }
  }
  if(win%2 == 0){
    ns++;
  }
  pri = win;
//  cout<<" "<<win<<endl;
}

void res(ll ns){
  if(ns<7)cout<<"EW "<<7-ns<<endl;
  else cout<<"NS "<<ns-6<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char joker;
    cin>>joker;
    while(joker != '#'){
      vector<string> n,e,s,w;
      FOR(i,0,4){
        FOR(j,0,13){
          string in;
          cin>>in;
          if(i == 0)n.push_back(in);
          if(i == 1)e.push_back(in);
          if(i == 2)s.push_back(in);
          if(i == 3)w.push_back(in);
        }
      }
      ns = 0;
      pri = 0;
      FOR(i,0,13){
        game(n[i],e[i],s[i],w[i],joker);
      }

      res(ns);
      cin>>joker;
    }


}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	int a1,a2,a3;
	cin>>a1>>a2>>a3;
	if(a1+a2+a3>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;

	return 0;

}



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

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

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

int main(){
    int N,X;
    cin >> N >> X; 
    vector<int>m(N);
    int syu = 0;
    for(int i = 0; i < N; i++) {
        cin >> m[i];
        syu += m[i];
    }
    sort(m.begin(),m.end());
    cout << N+(X-syu)/m[0] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

int n,input,max=0,min=0,i;
long sum=0;

scanf("%d",&n);

if(n==0){
 printf("undefined\n");
}else{
for(i=0;i<n;i++){
 scanf("%d",&input);
 if(i==0){
  min = input;
  max = input;
  sum = input;
 }else{
  if(max < input) max=input;
  if(input < min) min=input;
  sum += input;
 }
}

printf("%d %d %ld\n",min,max,sum);
}
return 0;

}

Measured memory_bytes: 600
fn main() {
    let mut case = 0;

    loop {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let message = buf.trim();

        let num: i32 = message.parse().unwrap();
        if num == 0 { break };
        case += 1;
        println!("Case {}: {}", case,num);
    }
}


Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N,T;
    cin >> N >> T;
    
    int c[100] ={};
    int t[100] ={};
    int ans = 10000;
    
    
    for(int i=0;i<N;i++){
        cin >> c[i] >> t[i];
        if(t[i]<=T){
            ans=min(ans,c[i]);
        }
    }
    if(ans==10000){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
        
    }
}


Measured memory_bytes: 256
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    aBA =[0]*iN
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iB = aB[i]
        while aA[iIndex] >= iB:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            aBA[i] = iIndex + 1
        else:
            break
    aAcBA=[0]*iN
    aAcBA[0]=aBA[0]
    for i in range(1,iN):
        aAcBA[i]=aAcBA[i-1]+aBA[i]
    iAns = 0
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iC = aC[i]
        while aB[iIndex] >= iC:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            iAns += aAcBA[iIndex]
        else:
            break
    print(iAns)
解()


Measured memory_bytes: 24112
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  if(prev_permutation(a.begin(),a.end())){
    rep(i,n){
      if(i)cout<<' ';
      cout<<a[i];
    }
    cout<<endl;
  }
  next_permutation(a.begin(),a.end());
  rep(i,n){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
  if(next_permutation(a.begin(),a.end())){
    rep(i,n){
      if(i)cout<<' ';
      cout<<a[i];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){

 string s;cin>>s;
 string t;cin>>t;
 for(int i=0;i<100000;i++){
     if(s==t) {
         cout<<"Yes"<<endl;
         return 0;
     }

     char save = s[0];
     for(int i=0;i<s.size();i++){
         if(i==s.size()-1) s[i] = save;
         else s[i] = s[i+1];
     }

 }

 cout<<"No"<<endl;
 return 0;
    
    
 


    return 0;
}

 



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define N 1000000
#define ar array
#define inf 1e18
#define mod 1000000007
#define ld long double
#define pb push_back
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	ll n,i,j,a,b;
	cin>>n;
	vector<pair<ll,ll>>g(n+1);
	for(i=0;i<n-1;i++){
		cin>>a>>b;
		g[i+1]={a,b};
	}
	ll ans=0;
	for(i=1;i<=n;i++)
		ans+=i*(n-i+1);
	for(i=1;i<n;i++){
		ll mi=min(g[i].fi,g[i].se);
		ll mx=max(g[i].fi,g[i].se);
		ll c=(mi-1+1)*(n-mx+1);
		ans-=c;
	}
	cout<<ans;
}


Measured memory_bytes: 6304
import java.io.PrintWriter
import kotlin.math.abs

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }
    val b = IntArray(n + 2)
    for (i in 0 until n) {
        b[i + 1] = a[i]
    }
    var s = 0
    for (i in 0..n) {
        s += abs(b[i] - b[i + 1])
    }
    val pw = PrintWriter(System.out)
    for (i in 1..n) {
        pw.println(s - abs(b[i - 1] - b[i]) - abs(b[i] - b[i + 1]) + abs(b[i - 1] - b[i + 1]))
    }
    pw.flush()
}


Measured memory_bytes: 55880
module simple;import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, core.stdc.string;

immutable long MOD = 998244353;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    if (A[0] != 0 || A.map!(a => a == 0).sum >= 2) {
        writeln(0);
        return;
    }

    auto D = new long[](N+10);
    foreach (a; A) D[a] += 1;

    foreach (i; 1..N) {
        if (D[i-1] > 0 && D[i+1] > 0 && D[i] == 0) {
            writeln(0);
            return;
        }
    }

    long ans = 1;
    foreach (i; 1..N) {
        if (D[i] == 0) break;
        ans = ans * powmod(D[i-1], D[i], MOD) % MOD;
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 4444
x,k,d=map(int,input().split())
if abs(x)>=k*d:print(abs(abs(x)-k*d))
else:
    k-=abs(x)//d
    x=x%d if x>0 else -(-x%d) 
    if k%2:
        print(abs(x-d) if x>0 else d+x)
    else:
        print(abs(x))


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

const int N = (int) 2e5 + 5;

int n, k;
long long a[N];
map <long long, long long> remain;

int main() {
	scanf("%d %d", &n, &k);
	remain[0]++;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; a[i] += a[i - 1];
		if (i - k >= 0) remain[(a[i - k] - (i - k)) % k]--;
		ans += remain[(a[i] - i) % k]++;
	}
	printf("%lld", ans);
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	const int x = (n + 1) / 2;
	cout << (x >= k ? "YES" : "NO") << endl;
	return 0;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    long long ans = 0;
    for(long long i=k;i<=n+1;i++){
        ans += (n-i+1)*i +1;
        ans %= 1000000007;
    }

    cout << ans << endl;
    return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        if(ab[1] == 1)
        {
            Console.WriteLine(0);
            return;
        }

        var count = 1;
        while (ab[1] > ab[0] + (ab[0] - 1) * (count - 1))
        {
            ++count;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13396
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <climits>
using namespace std;
using ll = long long;

constexpr int dlim = 11;
ll d, g;
int p[dlim], c[dlim];

int dfs(vector<int> v, int rest){
  if(v.size() == 0) return -INT_MAX;

  int res = INT_MAX;
  for(int i=0; i<v.size(); i++){
    vector<int> vv = v;
    vv.erase(vv.begin() + i);
    int rr = rest-v[i]*p[v[i]]-c[v[i]];
    if(rr > 0) res = min(res, dfs(vv, rr) + p[v[i]]);
    else res = min(res, min((int)ceil(rest*1.0/v[i]), p[v[i]]));  
  }

  return res;
}

int main(){
  cin >> d >> g;
  g = g / 100;

  for(int i=1; i<=d; i++) {
    cin >> p[i] >> c[i];
    c[i] = c[i] / 100;
  }

  vector<int> v;
  for(int i=1; i<=d; i++){
    v.push_back(i);
  }

  cout << dfs(v, g) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())

    if x < 1200:
        print("ABC")
    else:
        print("ARC")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61940
#include<iostream>

#include<string>
#include <algorithm> 
using namespace std;

int main()
{
    int x,a,b;
    cin >> x >> a >> b;

    if (a-b>=0) cout << "delicious" << endl;
    else if (x>=b-a) cout << "safe" << endl;
    else cout << "dangerous" << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	string str = "";
	cin >> str;
	ll ans = 1000000000;
	vector<ll>E(n + 1), W(n + 1);
	rep(i, n + 1) { E[i] = W[i] = 0; }
	W[n - 1] = E[0] = 0;
	rep(i, n) {
		if (i == 0) { E[i+1] = (str[i] == 'W'); W[n - i -1] = (str[n - i - 1] == 'W'); }
		else {
			E[i+1] = (str[i] == 'E') + E[i]; W[n - i - 1] = W[n - i] + (str[n - i - 1] == 'E');
		}
	}
	W[n - 1] = E[0] = 0;
	for(int i=1;i<=n;i++){
		E[i] = E[i - 1] + (str[i-1] == 'W');
	}
	for (int i = n - 2; i >= 0; i--) {
		W[i] = W[i + 1] + (str[i+1] == 'E');
	}
	for (int i = 0; i < n+1 ; i++) {
		//cout << E[i] << " " << W[i] << endl;

		ans = min(E[i]+ W[i], ans);
	}
	//ans = min(min(W[0],ans),E[n-1]);
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int ans = 0;
	int n, x;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> x;
		if (x & 1 and i & 1) ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> S;
    UNIQUE(S);
    cout << S.size() << endl;
}

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

#define Debug(x) x
typedef int regular_int;
// #define int ll
typedef long long ll;

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
        cnt += (s[i] == 'o');
	}
	if (cnt + 15 - s.size() >= 8){
        cout << "YES" << endl;
	} else {
	    cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n,max=0,sec=0;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]>max){
      sec=max;
      max=a[i];
    }
    else if(a[i]>sec)
      sec=a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]==max)
      printf("%d\n",sec);
    else
      printf("%d\n",max);
  }
  return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define MAX 100005
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))
#define sz size
const int MOD = 1e9+7;

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n;
ld dp[3003][3003], arr[3003];

ld solve(int n, int h){
	if (h>n || h<0) return (ld) 0;
	if (h==0) return (ld) 1;
	if (dp[n][h] != (ld) -1) return dp[n][h];
	if (n==1 && h ==1) return dp[n][h] = arr[n];
	return dp[n][h] = arr[n]*solve(n-1,h-1) + solve(n-1,h)*(1-arr[n]);
}

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


	cin>>n;
	For(i,1,n+1) cin>>arr[i];

	For(i,0,3003){
		For(j,0,3003) dp[i][j] = (ld) -1;
	}
	ld res = 0;
	// For(i,n/2+1,n+1) res += solve(n,i);
	res = solve(n,n/2+1);
	cout<<fixed<<setprecision(12);
	cout<<res<<endl;
	// For(i,1,n+1){
	// 	For(j,1,i+1) {
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }	

	return 0;
}


Measured memory_bytes: 141440
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321
#define MAXV 3000500


#define MOD 1234567

int N,M,T,K;

int fix[100500];
vector<Pi> E[100500];
int deg[100500];
int main(){
	geti(N,M);
	repp(i,M){
		int a,b,c; geti(a,b,c);
		E[a].push_back({b,c});
		deg[b]++;
	}

	queue<int> q;
	repp(i,N){
		fix[i] = -1;
		if( deg[i] == 0 ) q.push(i), fix[i] = 0;
		
	}

	while( !q.empty() ){
		int cur = q.front();
		q.pop();
		for(auto e : E[cur]){
			if( fix[e.Fi] == -1 ) {
				fix[e.Fi] = fix[cur] + e.Se;
				q.push(e.Fi);
			}
			else{
				if( fix[e.Fi] != fix[cur] + e.Se ){
					printf("No\n");
					return 0;
				}
			}
		}
	}

	repp(i,N){
		for(auto e : E[i]){
			if( fix[e.Fi] != fix[i] + e.Se ){
				printf("No\n");
				return 0;
			}
		}
	}


	printf("Yes\n");

}



Measured memory_bytes: 6784
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;


    auto cost = [&](int x) {
        return x + x * 8 / 100;
    };

    int lo = 0, hi = n;

    while (lo < hi) {
        auto mi = (lo + hi) / 2;

        if (cost(mi) >= n) {
            hi = mi;
        } else {
            lo = mi + 1;
        }
    }

    if (cost(lo) == n) {
        cout << lo << '\n';
    } else {
        cout << ":(\n";
    }

    return 0;
}

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

bool livesAlone(vector<int> &as) {
  int living = 0;
  for (const int &a : as) {
    if (a > 0) { living++; }
  }
  return (living == 1);
}

void attack(vector<int> &as) {
  int power = 1e9 + 1;
  int index = 1e6;
  for (int i = 0; i < as.size(); i++) {
    if (as[i] < 1) { continue; }
    if (power > as[i]) {
      power = as[i];
      index = i;
    }
  }

  for (int i = 0; i < as.size(); i++) {
    if (i == index) { continue; }
    as[i] %= power;
  }
}

int main(void) {
  int n;
  cin >> n;
  vector<int> as(n);
  for (int &a : as) {
    cin >> a;
  }

  while (!livesAlone(as)) {
    attack(as);
  }
  
  int power = 0;
  for (const int &a : as) {
    power = max(power, a);
  }

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

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

using namespace std;

int main()
{
	int n, x, m, sum = 0, mn = 1000000;
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		sum += m;
		mn = min(mn, m);
	}
	int ans = n + (x - sum) / mn;
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
values = [input().split() for i in range(n)]

# Initialize Array
a = [["#" if i > 0 and i % 4 == 3 else 0 for j in range(10)] for i in range(15)]

# Search
for value in values:
    b, f, r, v = map(int, value)
    a[4 * b + f - 5][r - 1] += v

# Output
for i in range(15):
    row_output = ""
    for j in range(10):
        if i > 0 and i % 4 == 3:
            row_output += "##"
        else:
            row_output += " " + str(a[i][j])
    print(row_output)



Measured memory_bytes: 5604
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<>();//x, y
		Set<Integer> isRed = new HashSet<>();//xが入る
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			map.put(a, sc.nextInt());
			isRed.add(a);
		}
		for(int i = 0; i < n; i++) {
			map.put(sc.nextInt(), sc.nextInt());
		}
		TreeSet<Integer> redyset = new TreeSet<>();
		int ans = 0;
		for(Integer x : map.keySet()) {
			if(isRed.contains(x)) {
				redyset.add(map.get(x));
			} else {
				int y = map.get(x);
				if(redyset.lower(y)!=null) {
					redyset.remove(redyset.lower(y));
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MAX_V 100001
#define INF 10000000000
ll d[MAX_V];
ll b_draw[MAX_V];
struct edge{ll to,cost;};
vector<edge> G[MAX_V];
typedef pair<ll,ll> P;
bool used[MAX_V]={};
vector<ll> prever(MAX_V,-1);
void dij(ll s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+MAX_V,INF);
  d[s]=0;
  que.push(make_pair(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d[v]<p.first) continue;
    for(ll 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;  
        prever[e.to]=v;
        que.push(make_pair(d[e.to],e.to));
      }
    }
  }
}
ll fill_f(ll v){
  if(used[v])return 0;
  if(b_draw[v]==2) return 0;
  b_draw[v]=1;
  ll time = 1;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    time += fill_f(G[v][i].to);
  }
  return time;
}
vector<ll> getpath(ll t){
  vector<ll> path;
  for(;t!=-1;t=prever[t]){
    path.push_back(t);
  }
  reverse(path.begin(),path.end());
  return path;
}
signed main(){
  ll n,f,s,num;
  fill(b_draw,b_draw+MAX_V,-1);
  vector<ll> path;
  cin >> n;
  ll a[n],b[n];
  for(int i=0;i<n-1;i++){
    cin >> a[i]>>b[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(edge{b[i],1});
    G[b[i]].push_back(edge{a[i],1});
  }
  dij(0);
  path = getpath(n-1);
  f=0;
  s=path.size()-1;
  while(true){
    if(b_draw[path[f]]==-1){
      b_draw[path[f++]]=1;
    }else{
      break;
    }
    if(b_draw[path[s]]==-1){
      b_draw[path[s--]]=2;
    }else{
      break;
    }
  }
  num = fill_f(0);
  /*
  for(int i=0;i<7;i++){
    cout << b_draw[i]<<endl;
  }
  cout << num<<endl;
  */
  if(num*2>n){
    cout <<"Fennec\n";
  }else{
    cout <<"Snuke\n";
  }
}


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

int main()
{
	int n;
	int a[2][110];
	int max_num = 0;

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

	for (int i = 0; i < n; ++i)
	{
		int num = 0;
		for (int j = 0; j <= i; ++j)
		{
			num += a[0][j];
		}
		for (int j = i; j < n; ++j)
		{
			num += a[1][j];
		}
		if (num > max_num)
		{
			max_num = num;
		}
	}

	cout << max_num << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7

N = int(input())
G = [[] for _ in range(N)]
for _ in  range(N - 1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

dp = [[-1] * 2 for _ in range(N)]
def dfs(v,color,p = -1):
    if dp[v][color] != -1:
        return dp[v][color]
    if color == 0:
        ans = 1
        for e in G[v]:
            if e == p:
                continue
            ans *= dfs(e,0,v) + dfs(e,1,v)
            ans %= MOD
        dp[v][color] = ans
        return ans
    else:
        ans = 1
        for e in G[v]:
            if e == p:
                continue
            ans *= dfs(e,0,v)
            ans %= MOD
        dp[v][color] = ans
        return ans

ans = (dfs(0,0) + dfs(0,1))%MOD
print(ans)

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

int main(){
  typedef pair<unsigned long int ,int> AB;
  priority_queue<AB,vector<AB>,greater<AB>> pque;
  int N,M,i,b;
  unsigned long int a,sum=0;
  cin >> N >> M;
  for(i=0;i<N;i++){
    cin>>a>>b;
    pque.push(make_pair(a,b));
  }
 
  while(M>0){
    a=pque.top().first;b=pque.top().second;
    if(M-b>=0) sum+=a*b;
    else  sum+=a*M;
    pque.pop();
    M=M-b; 
  }
  
  cout << sum<<endl;
  
  return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>
int main(){
    int W,H,x,y,r;
    scanf ("%d%d%d%d%d", &W, &H, &x, &y, &r);
    (x >= W || y >= H || r > W || r > H || x < 0 || y < 0 || x+r>W || y+r>H)? printf("No\n") : printf("Yes\n");
}

Measured memory_bytes: 2668
s = gets.chomp.chars

(0..s.size - 1).each do |i|
  if i % 2 == 0
    if s[i] == "L"
      puts "No"
      exit
    end
  else
    if s[i] == "R"
      puts "No"
      exit
    end
  end
end

puts "Yes"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin, cout の高速化
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)

const ll INF = 1e15;

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    REP(i, s.length())
    {
        bool tmp = true;
        REP(j,t.length()){
            if(s[(i+j)%s.length()] != t[j]) tmp=false;
        }
        if(tmp){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};
//END CUT HERE
//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string t,p;
  cin>>t>>p;
  using ll = long long;
  const ll MOD = 1e9+7;
  const ll B = 1777771;
  using RH = RollingHash<ll, MOD, B>;
  RH rt(t),rp(p);
  for(int i=0;i<(int)t.size()-(int)p.size()+1;i++){
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/06/16
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B&lang=jp
*/



Measured memory_bytes: 19752
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ans = 0
# (i, j, k) -> Fix j

for i in b:
    lower = bisect.bisect_left(a, i)
    higher = n - (bisect.bisect_right(c, i))
    ans += lower * higher

print(ans)


Measured memory_bytes: 23360
// Problem : A - Coffee
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	string s;cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>
using namespace std;

class YukiIO {
	char* buff;
	string format;
public:
	YukiIO(int s_, int pre_) { buff = new char[s_]; format = "%." + to_string(pre_) + "lf"; }
	~YukiIO() { delete buff; }
	//--------------input---------------
	inline void scan(int &i_) { scanf("%d", &i_); }
	inline void scan(long long &l_) { scanf("%lld", &l_); }
	inline void scan(double &d_) { scanf("%lf", &d_); }
	inline void scan(float &f) { scanf("%f", &f); }
	inline void scan(char &c_) { scanf("%*c%c", &c_); }
	inline void scan(char* s_) { scanf("%s", s_); }
	inline void scan(string &s_) { scanf("%s", buff); s_ = string(buff); }
	template <typename HEAD, typename ...TAIL>inline void scan(HEAD& head, TAIL& ...tails) {
		scan(head);
		scan(tails...);
	}
	template <typename T> inline void scan(vector<T>& v) {
		for (int i = 0; i < v.size(); ++i) scan(v[i]);
	}
	template <typename ...ARGS> inline void scan(const string &format, ARGS& ... args) {
		scan(buff);
		sscanf(buff, format.data(), &args...);
	}
	//--------------outut---------------
	inline void print(bool b_) { printf("%s", b_ ? "true" : "false"); }
	inline void print(int i_) { printf("%d", i_); }
	inline void print(long long l_) { printf("%lld", l_); }
	inline void print(double d_) { printf(format.data(), d_); }
	inline void print(float f) { printf("%f", f); }
	inline void print(char c_) { printf("%c", c_); }
	inline void print(char* s_) { printf("%s", s_); }
	inline void print(string &s_) { printf("%s", s_.data()); }
	inline void print(const char* s_) { printf("%s", s_); }
	template <typename T> inline void print(vector<T>& v) {
		print(v[0]);
		for (int i = 1; i < v.size(); ++i) {
			putchar(' '); print(v[i]);
		}
	}
	inline void println() { puts(""); }
	template <typename T> inline void println(vector<T>& v) { for (int i = 0; i < v.size(); ++i) println(v[i]); }
	template <typename HEAD, typename ...TAIL>inline void print(HEAD head, TAIL ...tails) {
		print(head);
		print(tails...);
	}
	template <typename ...ARGS>inline void println(ARGS ...args) {
		print(args...);
		puts("");
	}
};

YukiIO io{ 893, 12 };

int main(void) {
	int N;
	io.scan(N);
	vector<int> V(N);
	io.scan(V);

	vector<pair<int, int>> CE(100001, { 0, 0 }), CO(100001, { 0, 0 });
	for (int i = 0; i < N; ++i) {
		int v = V[i];
		if (i & 1) {
			CO[v].first++;
			CO[v].second = v;
		}
		else {
			CE[v].first++;
			CE[v].second = v;
		}
	}
	sort(CO.rbegin(), CO.rend());
	sort(CE.rbegin(), CE.rend());



	int mxO = CO[0].second;
	int mxE = CE[0].second;

	auto check = [&]() -> int 
	{
		int ans1 = 0, ans2 = 0;
		for (int i = 0; i < N; ++i) {
			if (i & 1) {
				if (V[i] != mxO)++ans1;
			}
			else {
				if (V[i] != mxE)++ans2;
			}
		}
		return ans1 + ans2;
	};


	if (mxO != mxE) {
		io.println(check());
	}
	else {
		mxE = CE[0].second, mxO = CO[1].second;
		int res1 = check();
		mxE = CE[1].second, mxO = CO[0].second;
		int res2 = check();
		io.println(min(res1, res2));
	}

	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, p[10], ans=0, dai=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> p[i];
		ans+=p[i];
		dai=max(dai, p[i]);
	}
	cout << ans-dai/2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define pip pair<int,pair<int,int> >
typedef unsigned long long ull;
const int inf=103974182;
using namespace std;
int n;
pair<int,pii> a[200005];
vector <pair<int,pii> >vec;
set <pair<int,pair<int,int> > > squ;
int f[200005];
priority_queue <pip,vector <pip>,greater<pip> >que;

int find(int x)
{
	return (x==f[x]?x:f[x]=find(f[x]));
}

int add(int x,int y)
{
	x=find(x);
	y=find(y);
	if(rand()&1) f[x]=y;else f[y]=x;
}

bool compare1(pair<int,pii> a,pair<int,pii> b)
{
	return a.second.first<b.second.first;
}

bool compare2(pair<int,pii> a,pair<int,pii> b)
{
	return a.second.second<b.second.second;
}

void init()
{
	for(int i=0;i<200005;i++)
	{
		f[i]=i;
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].second.first,&a[i].second.second);
		a[i].first=i;
	}
	sort(a,a+n,compare1);
	for(int i=0;i<n-1;i++)
	{
		vec.push_back(mp(min(abs(a[i+1].second.first-a[i].second.first),abs(a[i+1].second.second-a[i].second.second)),mp(a[i].first,a[i+1].first)));
	}
	sort(a,a+n,compare2);
	for(int i=0;i<n-1;i++)
	{
		vec.push_back(mp(min(abs(a[i+1].second.first-a[i].second.first),abs(a[i+1].second.second-a[i].second.second)),mp(a[i].first,a[i+1].first)));
	}
	sort(vec.begin(),vec.end());
//	for(int i=0;i<vec.size();i++)
//	{
////		que.push(vec[i]);
//		squ.insert(vec[i]);
//	}
//	for(set <pair<int,pii> > ::iterator it=squ.begin();it!=squ.end();it++)
//	{
//		cout<<it->first<<' '<<it->second.first<<' '<<it->second.second<<endl;
//	}
//	cout<<que.size()<<endl;
	init();
	int k=0;
	ll ans=0;
	int len=vec.size();
	for(int i=0;i<len;i++)
	{
//		cout<<que.size()<<endl;
//		system("pause");
		if(k==n-1) break;
		pip t=vec[i];
		if(find(t.second.first)==find(t.second.second)) continue;
		k++;
//		cout<<k<<endl;
		ans+=t.first;
		add(t.second.first,t.second.second);
	}
	cout<<ans<<Endl;
	return 0;
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 1000000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void cMin(T* a, T* b)  {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  div(T a, T b)     {return ((a+b-1)/b);}
template<typename T> inline bool eoVerify(T a)     {return (!(a&1)? true : false );}

int main(){
    ll n, ans=0, tmp=0;
    cin >> n;
    vector<ll> a(n);
    rep(0,n) cin >> a[i];

    rep(0,n){
        ans = (ans+a[i]*tmp)%MOD;
        tmp = (tmp+a[i])%MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int a[3][3], n;
bool vis[3][3] = {0};
void init(){
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
            a[i][j] = read();
    n = read();
    while (n--){
        int b = read();
        for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
        if (a[i][j] == b)
            vis[i][j] = true;
    }
}
void solve(){
    for (int i = 0; i < 3; ++i)
        if (vis[i][0] && vis[i][1] && vis[i][2]){
            printf("Yes\n");
            return ;
        }
    for (int i = 0; i < 3; ++i)
        if (vis[0][i] && vis[1][i] && vis[2][i]){
            printf("Yes\n");
            return ;
        }
    if (vis[0][0] && vis[1][1] && vis[2][2]){
            printf("Yes\n");
            return ;
        }
    if (vis[2][0] && vis[1][1] && vis[0][2]){
            printf("Yes\n");
            return ;
        }
    printf("No\n");

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int N;
	cin >> N;
	vector<char> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		if (S[i] == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;

	return 0;
}

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

LL gcd(LL a, LL b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  LL N, M;
  string s, t;
  cin >> N >> M >> s >> t;

  LL gcd_nm = gcd(N, M);
  LL n = N / gcd_nm, m = M / gcd_nm;
  LL ans = gcd_nm * n * m;
  for (LL i = 0; i < gcd_nm; i ++) {
    if (s.at(i * n) != t.at(i * m)) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=924844033;
int dp[2][2020][2];
int fac[2020];
int t[2020],tn;
int main()
{
	int n,kk,now=0,to=1,h;
	scanf("%d%d",&n,&kk);
	tn=0;
	for(int i=1;i<=kk*2;i++)
		for(int j=i;j<=n;j+=kk*2)
			t[++tn]=j;
	memset(dp,0,sizeof(dp));
	dp[now][0][1]=1;
	t[n+1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)
			for(int k=0;k<2;k++)
				if(dp[now][j][k])
				{
					if(t[i]+2*kk<=n)
					{
						(dp[to][j][0]+=dp[now][j][k])%=mod;
						(dp[to][j+1][1]+=dp[now][j][k])%=mod;
						if(k==0)
							(dp[to][j+1][0]+=dp[now][j][k])%=mod;
					}
					else
					{
						if(t[i+1]<=kk)
							h=1;
						else
							h=0;
						(dp[to][j][h]+=dp[now][j][k])%=mod;
						if(t[i]+kk<=n)
							(dp[to][j+1][h]+=dp[now][j][k])%=mod;
						if(k==0)
							(dp[to][j+1][h]+=dp[now][j][k])%=mod;
					}
					dp[now][j][k]=0;
				}
		swap(now,to);
	}
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=(long long)fac[i-1]*i%mod;
	int ans=0;
	for(int i=0;i<=n;i++)
		if(i&1)
			ans=(mod-(long long)fac[n-i]*dp[now][i][1]%mod+ans)%mod;
		else
			ans=((long long)fac[n-i]*dp[now][i][1]+ans)%mod;
	printf("%d\n",ans);
	return 0;
}

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

void merge(int,int,int);
void mergeSort(int,int);

long int A[1000000];
int count=0;

int main(){
  int a,i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  mergeSort(0,a);
  for(j=0;j<a-1;j++){
    printf("%d ",A[j]);
  }
  printf("%d\n",A[a-1]);
  printf("%d\n",count);
  return 0;
}
 void merge(int left,int mid,int right){
   long int n1,n2,L[1000000],R[1000000],i,j,k;
   n1 = mid-left;
   n2 = right-mid;
   for(i=0;i<n1;i++){
     L[i]=A[left+i];
   }
   for(i=0;i<n2;i++){
     R[i]=A[mid+i];
   }
   L[n1] = 10000000000;//INFINITY;
     R[n2] = 10000000000;//INFINITY;
   i = 0;
   j = 0;
   for(k = left;k<right;k++){
     if(L[i]<=R[j]){
       A[k] = L[i];
       i=i+1;
     }
     else {
       A[k] = R[j];
       j = j+1;
     }
     count++;
   }
 }
void mergeSort(int left,int right){
  int mid;
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(left,mid);
    mergeSort(mid,right);
    merge(left,mid,right);
  }
}
	



Measured memory_bytes: 10392
#include <stdio.h>

int main(void) {
    int n, d, x;
    scanf("%d", &n);
    scanf("%d%d", &d, &x);
    int a[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= d; j += a[i-1]) {
            x++;
        }
    }
    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
struct node
{
	long long x,y;
	int a,b;
}point[55];
int incx(const void *a, const void *b)
{
    struct node m = *(struct node *)a;
    struct node n = *(struct node *)b;
    if(m.x<n.x) return -1;
    else return 1;
}
int incy(const void *a, const void *b)
{
    struct node m = *(struct node *)a;
    struct node n = *(struct node *)b;
    if(m.y<n.y) return -1;
    else return 1;
}
int main()
{
	int n,k,mp[55][55],xmax,ymax,temp;
	bool np[55][55];
	long long x[55],y[55],S,min=-1,xx[55],yy[55],Smax=-1;
	for(int i=0;i<55;i++)
	{
		for(int j=0;j<55;j++)
		{
			mp[i][j]=0;
			np[i][j]=false;
		}
	}
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld%lld",&point[i].x,&point[i].y);
	qsort(point,n,sizeof(struct node),incx);
	temp=0;
	for(int i=0;i<n;i++)
	{
		point[i].a=temp;
		xx[temp]=point[i].x;
		temp++;
	}
	qsort(point,n,sizeof(struct node),incy);
	temp=0;
	for(int i=0;i<n;i++)
	{
		point[i].b=temp;
		np[point[i].a][point[i].b]=true;
		yy[temp]=point[i].y;
		temp++;
	}
	if(np[0][0]==false)mp[0][0]=0;
	else mp[0][0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==0)mp[i][j]=mp[i][j-1]+np[i][j];
			else if(j==0)mp[i][j]=mp[i-1][j]+np[i][j];
			else mp[i][j]=mp[i-1][j]+mp[i][j-1]-mp[i-1][j-1]+np[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int p=i+1;p<n;p++)
			{
				for(int q=j+1;q<n;q++)
				{
					int sum;
					if(i==0)sum=mp[p][q]-mp[p][j-1];
					else if(j==0)sum=mp[p][q]-mp[i-1][q];
					else sum=mp[p][q]-mp[i-1][q]-mp[p][j-1]+mp[i-1][j-1];
					if(sum>=k)
					{
						if((xx[p]-xx[i])*(yy[q]-yy[j])<=Smax||Smax<0)Smax=(xx[p]-xx[i])*(yy[q]-yy[j]);
					}
				}
			}
		}
	}
	printf("%lld\n",Smax);
}

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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7

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

    int a = n/(2*d+1);
    int b = n%(2*d+1);
    if(b!=0) a++;
    cout << a<<endl;
    

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using  namespace  std;
int main(){
int a=0,b=0,c=0;
cin>>a>>b>>c;
if(a!=b && a!=c) cout<<a<<endl;
 
else  if(b!=a && b!=c) cout<<b<<endl;
 
else if (c!=a && c!=b) cout<<c<<endl;
 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	lint MOD = 1000000007;
	lint n, m;
	cin >> n >> m;
	lint N = max(n, m);
	lint M = min(n, m);
	lint ans = 1;
	if (N == M + 1) {
		for (int i = 1; i <= M; i++) {
			ans = ans * i % MOD;
		}
		for (int i = 1; i <= N; i++) {
			ans = ans * i % MOD;
		}
		cout << ans << endl;
	}
	else if (N == M) {
		for (int i = 1; i <= M; i++) {
			ans = ans * i % MOD;
		}
		for (int i = 1; i <= N; i++) {
			ans = ans * i % MOD;
		}
		ans = ans * 2 % MOD;
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}




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


int main(){
    int N;
    int a[110] = {0};

    cin >> N;

    for(int i = 0; i < N; i++) cin >> a[i];


    sort(a,a+N);

    int stage = 1;

    for(int i = 0; i < N; i++){
        if(a[i] < a[i+1]) stage++;

    }

    cout << stage <<"\n";

}
   

Measured memory_bytes: 256