akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b;
    if(a%2==0 || b%2==0)cout<<"Even\n";
    else cout<<"Odd\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1,_2,_3,name,...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i=(a); i<(n); ++i)
#define rep(...) _overload3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<class T> inline void print(const T& x) {cout << x << "\n";}
template<class T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll n, m, a, b, c, f, ans{0}, cnt{0};
    cin >> n >> m;
    map<ll, ll, greater<ll>> d;
    rep(i, n) {cin >> a; ++d[a];}
    rep(i, m) {cin >> b >> c; d[c] += b;}
    each(e, d) {
        f = min(e.se, max(n - cnt, 0LL));
        cnt += f;
        ans += e.fi * f;
    }
    print(ans);
}

Measured memory_bytes: 16120
import fractions
import math
from functools import reduce
import sys
sys.setrecursionlimit(10**8)


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


def lcm(numbers):
    return reduce(lcm2, numbers)


n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
while all(x % 2 == 0 for x in a):
    count += 1
    a = list(map(lambda x: x//2, a))

if any(x % 2 == 0 for x in a):
    print(0)
    exit()

lcm = lcm(a)
print(m // (lcm * (2 ** (count - 1))) - m // (lcm * (2 ** count)))

Measured memory_bytes: 16308
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static List<int>[] friendsList;
    static int[] linkedId;

    static void Main()
    {
        string[] inputs = Console.ReadLine().Split(' ');
        int n = int.Parse(inputs[0]);
        int m = int.Parse(inputs[1]);
        friendsList = new List<int>[n];
        linkedId = new int[n];
        for (int i = 0; i < n; i++) friendsList[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int s = int.Parse(inputs[0]);
            int t = int.Parse(inputs[1]);
            friendsList[s].Add(t);
            friendsList[t].Add(s);
        }
        int q = int.Parse(Console.ReadLine());
        AssignId();
        for (int i = 0; i < q; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int s = int.Parse(inputs[0]);
            int t = int.Parse(inputs[1]);
            Console.WriteLine(linkedId[s] == linkedId[t] ? "yes" : "no");
        }
    }

    static void AssignId()
    {
        int id = 1;
        for (int i = 0; i < linkedId.Length; i++)
        {
            AssignId(i, id++);
        }
    }
    private static void AssignId(int num, int id)
    {
        if(linkedId[num] != 0) return;
        linkedId[num] = id;
        foreach (var item in friendsList[num])
        {
            AssignId(item, id);
        }
    }
}

Measured memory_bytes: 34084
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    int r, d, x;
    cin >> r >> d >> x;
    rep(i,10){
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
function Main(input){
	input = input.split(" ").map(a=>~~a);
  return Math.min(...["012","021","102","120","201","210"].map(function(a){
  	a = a.split("").map(a=>~~a);
    return Math.abs(input[a[0]]-input[a[1]])+Math.abs(input[a[1]]-input[a[2]])
  }))
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1 6 3
`);

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

bool solve(){
    i64 n, k;
    cin >> n >> k;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];
    map<int,int> m_x, m_y;
    for(int i = 0; i < n; ++i){
        if(++m_x[x[i]] >= k)
            return true;
        if(++m_y[y[i]] >= k)
            return true;
    }
    for(int i = 0; i < n; ++i){
        map<pair<int,int>,int> m;
        for(int j = 0; j < n; ++j){
            int xd = x[i] - x[j];
            int yd = y[i] - y[j];
            if(!xd || !yd)
                continue;
            int gc = __gcd(abs(xd), abs(yd));
            pair<int,int> p(xd / gc, yd / gc);
            if(++m[p] >= k - 1)
                return true;
        }
    }
    return false;
}

signed main(){
    cout << solve() << endl;
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	string s;
	cin>>s;
	int n=s.size();
	for(int i=n/2-1;i>0;i--){
		if(s.substr(0,i)==s.substr(i,i)){
			cout<<2*i<<endl;
			return 0;
		}
	}
	return 0;
}

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


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

    int a = 7 % k;
    set<int> s;
    int sum = 1;
    while (s.count(a) == 0) {
        if (a == 0) {
            cout << sum << endl;
            return 0;
        }
        s.insert(a);
        a = (a * 10 + 7) % k;
        sum++;
    }
    cout << -1 << endl;

    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};


class LowLink {
    const int N;
    vector<vector<int>> G;
    set<int> used_v;
    vector<int> ord, low, parent;

    void dfs(int v, int &k)
    {
        used_v.insert(v);
        ord[v] = low[v] = k++;

        for (auto u : G[v]) {
            if (!used_v.count(u)) {
                parent[u] = v;
                dfs(u, k);
                low[v] = min(low[v], low[u]);
            } else if (u != parent[v]) {
                low[v] = min(low[v], ord[u]);
            }
        }
    }

    void calc_lowlink()
    {
        int k = 0;
        dfs(0, k);
    }

public:
    LowLink(int _N) : N(_N), G(_N), ord(_N), low(_N), parent(_N) {}

    vector<int> articulation_point()
    {
        vector<int> res;

        parent[0] = -1;
        calc_lowlink();

        int root_deg = 0;
        for (int i=1; i<N; i++) {
            int p = parent[i];
            if (p == 0) root_deg++;
            else if (ord[p] <= low[i]) {
                res.push_back(p);
            }
        }

        if (root_deg > 1) res.push_back(0);
        sort(res.begin(), res.end());
        res.erase(unique(res.begin(), res.end()), res.end());

        return res;
    }

    vector<PII> bridge()
    {
        vector<PII> res;
        calc_lowlink();
        for (int v=0; v<N; v++) {
            for (auto u : G[v]) {
                if (ord[v] < low[u]) {
                    res.emplace_back(min(v, u), max(v, u));
                }
            }
        }
        return res;
    }

    void add_edge(int u, int v)
    {
        G[u].push_back(v);
        G[v].push_back(u);
    }
};

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

    LowLink LL(N);

    rep(i, M) {
        int U, V;
        cin >> U >> V;
        LL.add_edge(U, V);
    }

    vector<PII> b = LL.bridge();
    sort(ALL(b));
    for (auto a : b) cout << a.first << " " << a.second << endl;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

string cmd;
stack<PII> stk;
VI match;
VI cnt;

int main() {
	cin >> cmd;
	ll cur=0;
	for(int i=0; i<SZ(cmd); i++) {
		char c = cmd[i];
		if(c == '(') {
			stk.push(MP(SZ(cnt), c=='('));
			cnt.PB(0);
			match.PB(-1);
		} else if(c == ')') {
			if(stk.empty() or stk.top().S == 0) {
				stk.push(MP(SZ(cnt), c=='('));
				cnt.PB(0);
				match.PB(-1);
			} else {
				if(stk.top().F == 0)
					cnt.PB(1);
				else
					cnt.PB(cnt[stk.top().F-1]+1);
				cur += cnt.back();
				match.PB(stk.top().F);
				stk.pop();
			}
		} else if(c == '-') {
			if(match.back() == -1)
				stk.pop();
			else {
				cur -= cnt.back();
				stk.push(MP(match.back(), 1));
			}
			cnt.pop_back();
			match.pop_back();
		} else
			assert(c=='\n');
		/*
		switch(c) {
			case '(':
				break;
			case ')':
				break;
			case '-':
				break;
			default:
				return 0;
		}
		*/
		cout << cur << endl;
	}
	return 0;
}



Measured memory_bytes: 6448
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

/*
 * 3 = -2(-1) + 1.
 * -3 = -2(1) -1.
 * アルゴリズムはわからんが基本，商を切り捨てで求めてからそれとの積との差が
 * 割り算になるようだ.よってあまりが-1になったり1になったりする.
 */

int main(){
    int N;
    cin >> N;
    string ans = "";
    do{
        int r;
        r = abs(N % (-2));
        N -= r;
        ans += char(r + '0');
        N /= (-2);
    }while(N);

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,i,now;
signed main() 
{
    scanf("%d",&n);
    while(i<=1000000)
    {
        i++;
        now=(now*10+7)%n;
        if(now==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB")
        cout << "No";
    else 
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
numbers = list(map(int, input().split()))
d = defaultdict(int)

for num in numbers:
    for x in [-1, 0, 1]:
        if num + x >= 0:
            d[num + x] += 1

ans = 0
for k, v in d.items():
    ans = max(ans, v)

print(ans)

Measured memory_bytes: 21028
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<string, string>;
using PP = pair<P, string>;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int N, Q;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<PP> books;
    for(int i = 0; i < N; i++)
    {
        string s, t, u; cin >> s >> t >> u;
        books.push_back(PP(P(s, t), u));
    }
    cin >> Q;
    for(int i = 0; i < Q; i++)
    {
        string s, t, from, to; cin >> s >> t >> from >> to;
        if(i) cout << "\n";
        for(int j = 0; j < N; j++)
        {
            int match = 0;
            PP book = books[j];
            if(s == "*" or book.first.first.find(s) != -1) match++;
            if(t == "*" or book.first.second.find(t) != -1) match++;
            if(from == "*") from = "0000/00/00";
            if(to == "*") to = "2040/01/01";
            if(from <= book.second and book.second <= to) match++;
            if(match == 3) cout << book.first.first << "\n";
        }
    }
    return 0;
}




Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf -1000000000000000000
int n,k;
// vector<int>a;
const int sz = 100005;
vector<int>graph[sz];
vector<int>h, p;
int ans = 0;

/*void dfs(int root, vector<bool>&vis) {
	vis[root] = true;
	bool flag = true;
	for(int c : graph[root]) {
		if(!vis[c]) {
			p[c] = root;
			if(h[c] >= h[root]) {
				flag = false;
			}
			dfs(c, vis);
		}
	}
	if(p[root] != -1) {
		if(flag && h[root] > h[p[root]]) ans++;
	}
	else {
		if(flag) ans++;
	}
}*/
int main() {
	io
	cin>>n>>k;
	h.resize(n+1, -1);
	p.resize(n+1, -1);
	for(int i = 1; i<=n; i++) {
		cin>>h[i];
	}
	for(int i = 0; i<k; i++) {
		int a, b;
		cin>>a>>b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	/*vector<bool>vis(n+1, false);
	for(int i = 1; i<=n; i++) {
		if(!vis[i]) {
			dfs(i, vis);
		}
	}*/
	for(int i = 1; i<=n; i++) {
		if(graph[i].size() == 0) ans++;
		else {
			bool flag = true;
			for(int j = 0; j<graph[i].size(); j++) {
				if(h[i] <= h[graph[i][j]]) flag = false;
			}
			if(flag) ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b - a == c - b) cout << "YES\n";
  else cout << "NO\n";
  return;
}

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


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int j=0,i=0,n=0,a;
  int A[12];
  for(i=0;i<12;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<12;i++){
    for(j=i+1;j<12;j++){
      if(A[i]<A[j]){
        a=A[j];
	A[j]=A[i];
	A[i]=a;

      }
    }
  }
  if(A[0]==A[3]&&A[4]==A[7]&&A[8]==A[11]){
    printf("yes");
  }else{
    printf("no");
  }
  printf("\n");
  return 0;
}
    



Measured memory_bytes: 2756
# ABC065B - Trained?
import sys
input = sys.stdin.readline

n = int(input())
lst = list(map(int, [input().rstrip() for _ in range(n)]))
button = lst[0]
count = 0
for _ in range(n):
    count += 1
    if button == 2:
        break
    button = lst[button - 1]
else:
    count = -1
print(count)

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

 ll i,j,k;
    ll n;
    ll x[10],y[10];
int turn[500000][10];
    int roop=1;
    double ans=0;

double far(int one,int two)
{
  double xx,yy;
  xx=pow((x[one]-x[two]),2.0);
  yy=pow((y[one]-y[two]),2.0);
  return sqrt(xx+yy);
}
int main() {
  
    cin >> n;
    for(i=0; i<n; i++)
    {
      cin>> x[i] >> y[i];
    }
i=0;
while(n-i>0)
{
  roop*=n-i;
  i+=1;
}

// for(i=0; i<roop; i++)
// {
// int one=-1,two;
//   for(j=0; j<n; j++)
//   {
//     if(i%pow(2.0,double(j+1))==0)
//     {
//       if(one==-1)
//       {
//         one=j;
//       }else
//       {
//         two=j;
//       }
//     }
//   }
// }

// for(i=0; i<roop; i<++)
// {
//   for(j=0; j<n-1; j++)
//   {
//     ans+=far(turn[i][j],turn[i][j+1]);
//   }
// }

int t[10];
for(i=0; i<n; i++)
{
  t[i]=i;
}

do{
  for(j=0; j<n-1; j++)
  {
    ans+=far(t[j],t[j+1]);
   for(i=0; i<n; i++)
   {
    //  cout << roop<<" ";
   }
  //  cout<< endl;
  }
}while(next_permutation(t,t+n));

  cout << setprecision(10)<< ans/double(roop) << endl;
}


Measured memory_bytes: 256
import itertools
n=int(input())
lst=[]
permu=list(itertools.permutations(list(range(n))))
for i in range(n):
  x,y=map(int,input().split())
  lst.append([x,y])
dist=0
for i in range(len(permu)):
  for j in range(n-1):
    dist+=(((lst[permu[i][j]][0]-lst[permu[i][j+1]][0])**2)+((lst[permu[i][j]][1]-lst[permu[i][j+1]][1])**2))**0.5
m=1
for i in range(1,n+1):
  m*=i
dist=dist/m
print(dist)  



Measured memory_bytes: 8180
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

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

int const N = 3e5 + 20 , inf = 1e9 + 20 ;
int n , a[N] , b , w ;

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

	cin >> n ;
	for (int i = 0 ; i < n ; i ++) {
		cin >> a[i] ;
		(i & 1 ? w : b) += a[i] ;
	}

	if (!(n & 1))
		return cout << max(b , w) << ' ' << min(b , w) << '\n' , 0 ;

	int low = 0 , high = inf ;

	while (high - low > 1) {
		int mid = (low + high) >> 1 ;

		int mx = 0 ;

		for (int i = 0 ; i < n ; i ++) {
			if (i & 1) mx -= a[i] ;
			else {
				mx += a[i] ;
				if (mx >= mid && i + 1 < n) mx = max(mx , a[i + 1]) ;
			}
		}

		(mx >= mid ? low : high) = mid ;
	}

	cout << w + low << ' ' << b - low << '\n' ;
}

Measured memory_bytes: 1408
def main():
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    ans = float('inf')

    for i in range(n-k+1):
        if x[i] > 0:
            ans = min(ans,x[i+k-1])
        elif x[i+k-1] < 0:
            ans = min(ans,abs(x[i]))
        else:
            ans = min(ans,min(abs(x[i]),abs(x[i+k-1]))*2 + max(abs(x[i]),abs(x[i+k-1])))
        
    print(ans)


main()




Measured memory_bytes: 14228
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] bingo = new int[3][3];
		boolean[][] check = new boolean[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				bingo[i][j] = Integer.parseInt(sc.next());
				check[i][j] = false;
			}
		}
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			int tmp = list.get(i);
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(tmp == bingo[j][k]) {
						check[j][k] = true;
					}
				}
			}
		}
		for(int i = 0; i < 3; i++) {
			if(check[i][0] && check[i][1] && check[i][2]) {
				System.out.println("Yes");
				return;
			}
			if(check[0][i] && check[1][i] && check[2][i]) {
				System.out.println("Yes");
				return;
			}
		}
		if(check[0][2] && check[1][1] && check[2][0]) {
			System.out.println("Yes");
			return;
		}else if(check[0][0] && check[1][1] && check[2][2]) {
			System.out.println("Yes");
			return;
		}else {
			System.out.println("No");
		}

	}

}

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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

template <typename T> inline
void chmin(T &a, T b){
    if (a > b) {
        a = b;
    }
}

template <typename T> inline
bool chmax(T &a, T b){
    if (a < b) {
        a = b;
        return true;
    }

    return false;
}

void dp1(int N, int W, const vector<int> &w, const vector<LL> &v){
    vector<pair<LL, vector<int>>> V(W + 1);
    REP(i, W + 1) V[i].first = -1;


    V[0].first = 0;
    REP(i, N) V[0].second.push_back(i);

    LL res = 0;

    REP(cur_w, W+1) {
        LL cur_v = V[cur_w].first;
        if (cur_v == -1) continue;

        vector<int> remains = V[cur_w].second;

        REP(i, remains.size()) {
            int id = remains[i];

            int next_w = cur_w + w[id];
            if (next_w > W) continue;

            if(chmax(V[next_w].first, cur_v + v[id])) {
                V[next_w].second.resize(V[cur_w].second.size() - 1);
                copy(remains.begin(), remains.begin() + i, V[next_w].second.begin());
                copy(remains.begin() + i + 1, remains.end(), V[next_w].second.begin() + i);
            }
        }

        chmax(res, V[cur_w].first);
    }

    cout << res << endl;
}

LL dp[110][100010] = {0};

void dp2(int N, int W, const vector<int> &w, const vector<LL> &v) {
    REP(i, N) {
        REP(j, W + 1) {
            int next_w = j + w[i];

            if (next_w <= W) {
                chmax(dp[i + 1][next_w], dp[i][j] + v[i]);
            }

            chmax(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;
}



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

    int N, W; cin >> N >> W;

    vector<int> w(N);
    vector<LL> v(N);
    REP(i, N) cin >> w[i] >> v[i];

//    dp1(N, W, w, v);

    dp2(N, W, w, v);

}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<string>> S(H,vector<string>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> S.at(i).at(j);
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S.at(i).at(j)=="snuke"){
        cout << (char)('A'+j) << i+1 << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
//waz
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

int n, a[110];

VI ans;

int main() {
  cin >> n; int m = n;
  for (int i = 1; i <= n; ++i) {
  	cin >> a[i];
  }
  for (int x = n; x; --x) {
  	for (int i = n; i; --i) {
  	  if (a[i] == i) {
    	ans.pb(i);
	    for (int j = i; j <= n; ++j) a[j] = a[j + 1];
	    --n;
	    break;
	  }
    }
  }
  if (SZ(ans) != m) {
  	puts("-1");
  } else {
  	reverse(ALL(ans));
  	for (auto v : ans) {
  	  printf("%d\n", v);
	}
  }
}


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

#define MAX 100001
vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

// プロトタイプ宣言
void Solve(void);
void dfs(int, int);
// ここまで


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

	int from,to;
	for(int i=0;i<e;i++){
		cin>>from>>to;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	Solve();


	return 0;
}


void Solve(void){
	for(int i=0;i<MAX;i++) visited[i]=false;
	timer=1;
	dfs(0,-1);

	set<int> ArtiPoint;
	int np=0;
	for(int i=1;i<N;i++){
		int p=parent[i];
		if(p==0)np++;
		else if(prenum[p] <= lowest[i]) ArtiPoint.insert(p);
	}
	if(np>1) ArtiPoint.insert(0);

	for(set<int>::iterator it=ArtiPoint.begin();it!=ArtiPoint.end();it++){
		cout<<*it<<endl;
	}
}


void dfs(int current, int prev){
	prenum[current]=lowest[current]=timer;
	timer++;

	visited[current]=true;

	for(int next : G[current]){
		if(visited[next]==false){
			parent[next]=current;
			dfs(next,current);

			lowest[current]=min(lowest[current], lowest[next]);
		}else if(next != prev){
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
}



Measured memory_bytes: 6988
n = int(input())

a = map(int,raw_input().split())
b = map(int,raw_input().split())

combs = [0 for i in range(n)]
unique = [0 for i in range(n)]
t = 0
mod = 10**9 + 7
for i in range(n):
	if a[i] > t or a[i] == 1:
		combs[i] = 1
		t = a[i]
		unique[i] = 1

	else :
		combs[i] = t
t = 0
for i in range(n-1,-1,-1):
	if unique[i] == 1 and a[i] > b[i] :
		print 0
		quit()

	if b[i] > t:
		combs[i] = 1
		t = b[i]

	else :
		combs[i] = min(combs[i], t)

ans = 1
for i in combs:
	ans = (ans * i)%mod

print ans

Measured memory_bytes: 14500
#include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < n; ++i)
#define FOR(i, b, n) for (long i = b; i <= n; ++i)

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

void solve(long N, vector<long> h) {
  vector<long> cost(N + 1);
  FOR(i, 2, N)
    cost[i] = min(cost[i - 2] + abs(h[i - 2] - h[i]), cost[i - 1] + abs(h[i - 1] - h[i]));

  cout << cost[N] << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;
  vector<long> h(N);
  FOR(i, 1, N)
    cin >> h[i];
  h[0] = h[1];

  solve(N, move(h));

  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}
int main(){
  ll n;cin>>n;
  vll a(n);
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  vb dp(a[n-1]+1,true);
  vll cnt(a[n-1]+1,0);
  ll ans=0;
  rep(i,0,n){
    for(int j=a[i]*2;j<=a[n-1];j+=a[i]){
      dp[j]=false;
    }
    cnt[a[i]]++;
  }
  rep(i,0,n){
    if(dp[a[i]]&&cnt[a[i]]==1)ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 12768
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

void CountingSort(vs32& A, vs32& B, int k)
{
  vs32 C(k + 1, 0);
  rep (i, A.size())
  {
    ++C[A[i]];
  }

  rep (i, k)
  {
    C[i + 1] += C[i];
  }

  for (int i = A.size() - 1; i >= 0; --i)
  {
    B[C[A[i]]] = A[i];
    --C[A[i]];
  }
}

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

    int n;
    cin >> n;

    vs32 A(n);
    vs32 B(n + 1);
    int k = 0;
    rep (i, n)
    {
      cin >> A[i];
      k = MAX(k, A[i]);
    }

    CountingSort(A, B, k);

    rep (i, n)
    {
      if (i > 0) cout << " ";
      cout << B[i + 1];
    }

    cout << "\n";
    return 0;
}



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

long long n, m, ans;

int main(){
    cin >> n >> m;
    if(n-2 < 0 || m - 2 < 0){
        if(n == 1 && m == 1){
            cout << "1\n";
            return 0;
        }
        else if(n < m){
            cout << m - 2 << endl;
            return 0;
        }
        else{
            cout << n - 2 << endl;
            return 0;
        }
    }

    cout << (n-2)*(m-2) << endl;
}

Measured memory_bytes: 256
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

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

	int mx = 1000000;
	vector<int> D(mx+1, 0);
	rpd(i, 2, mx+1, 1)
		if(!D[i]) rpd(j, i, mx+1, i) D[j] = i;

	int N; cin>>N;
	int g = 0;
	bool not_pairwise = false;
	set<int> past;
	rpd(i, 0, N, 1){
		int a; cin>>a;
		g = gcd(g, a);
		if(not_pairwise) continue;
		set<int> now;
		while(a != 1){
			// 素数 D[a]: 今回は未済 & 過去は済
			if(( not_pairwise = !now.count(D[a]) && past.count(D[a]) )) break;
			now.insert(D[a]);
			past.insert(D[a]);
			a /= D[a];
		}
	}
	int t = not_pairwise + (g > 1);
	cout<< vector<string>{"pairwise","setwise","not"}[t] <<" coprime\n";
}


Measured memory_bytes: 10816
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>
#include"bits/stdc++.h"
 
using namespace std;
 
typedef pair<int, int> P;
typedef long long int ll;
 
 
 
int main() {
	//union_find a(5);
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 1; i < 4; i++) {
		if (S[i] == S[i - 1]) { ans = 1; }
	}
	if (ans == 0) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}
 
}

Measured memory_bytes: 256
#include <iostream>
long long n,k,a,i;int main(){std::cin>>n>>k;if(!k)a=n*n;else for(i=k+1;i<=n;i++)a+=n/i*(i-k)+(n-n/i*i>=k?n-n/i*i-k+1:0);std::cout<<a;}

Measured memory_bytes: 256
R,C,K = map(int, input().split())

maze = [[0 for _ in range(C)] for _ in range(R)]
dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
for i in range(K):
    r,c,v = map(int, input().split())
    r -=1
    c -= 1
    maze[r][c] = v

for i in range(R):
    for j in range(C):
        
        for k in range(2, -1, -1):
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + maze[i][j])

        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])  

ans = 0

for k in range(4):
    ans = max(ans, dp[k][R-1][C-1])       

print(ans)

Measured memory_bytes: 469496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int calc(int x){
	int ret = 0;
	while(x%100 == 0){
		x /= 100;
		++ret;
	}
	return ret;
}

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

	int d,n;
	cin >> d >> n;
	int cnt = 0;
	int tmp = 0;
	while(cnt < n){
		tmp++;
		if(calc(tmp)==d) ++cnt;
	}
	cout << tmp << endl;
	return 0;

}


Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))
D = {}
for t in a:
    if t in D:
        D[t]+=1
    else:
        D[t]=1

ans = 0
for k,v in D.items():
    if k==v:
        continue
    elif k>v:
        ans += v
    else:
        ans += v-k

print(ans)

Measured memory_bytes: 18168
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ASomethingOnIt {
public:
	void solve(istream& in, ostream& out) {
        string s; in >> s;
        int ans = 700;
        rep(i,3) {
            if(s[i] == 'o') ans += 100;
        }
        out << ans << endl;
	}
};

int main() {
	ASomethingOnIt solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,a[200005];
long long s,p,t=1e18;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        s+=a[i];
    }
    for(int i=1;i<n;i++){
        p+=a[i]; s-=a[i];
        t=min(t,abs(p-s));
    }
    cout << t;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

struct sta{
  int x;
  int y;
  int d;
};

int main(){
  while(1){
    int h,w,c;
    cin >> h >> w >> c;
    if(h==0) return 0;
    c--;
    vector<vector<int>> f(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> f[i][j];
        f[i][j]--;
      }
    }
    vector<int> a;
    int ans=0;
    int v[5]={0,1,0,-1,0};
    for(int x1=0;x1<6;x1++){
      for(int x2=0;x2<6;x2++){
        for(int x3=0;x3<6;x3++){
          for(int x4=0;x4<6;x4++){
            if(f[0][0]==x1||x1==x2||x2==x3||x3==x4||x4==c) continue;
            a={f[0][0],x1,x2,x3,x4,c};
            priority_queue<sta,vector<sta>,function<bool(sta,sta)>>
              heap([](const sta &a, const sta &b){return a.d>b.d;});
            vector<vector<int>> dist(h,vector<int>(w,IINF));
            heap.push({0,0,0});
            int tmp=0;
            while(!heap.empty()){
              sta now = heap.top();
              heap.pop();
              if(dist[now.y][now.x]!=IINF) continue;
              dist[now.y][now.x] = now.d;
              tmp++;
              for(int i=0;i<4;i++){
                int nx = now.x + v[i];
                int ny = now.y + v[i+1];
                if(0<=nx&&nx<w&&0<=ny&&ny<h){
                  if(dist[ny][nx]==IINF){
                    for(int k=now.d;k<7;k++){
                      if(f[ny][nx]==a[k]){
                        heap.push({nx,ny,k});
                      }
                    }
                  }
                }
              }
            }
            ans=max(ans,tmp);
          }
        }
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3048
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	int a[1010]={};
	int b[1010]={};
	int c[1010]={};
	int mat[110][110]={};
	
	for(int i=0;i<110;i++)
		for(int j=0;j<110;j++)
			if(i!=j)
				mat[i][j]=1e7;
	
	cin >> N >> M;
	for(int i=0;i<M;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		mat[a[i]][b[i]]=min(mat[a[i]][b[i]],c[i]);
		mat[b[i]][a[i]]=min(mat[b[i]][a[i]],c[i]);
	}
	
	for(int k=0;k<N;k++)
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
	
	int ans=M;
	for(int k=0;k<M;k++)
	{
		bool isneed=false;
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<N;j++)
			{
				if(mat[i][a[k]]+c[k]+mat[b[k]][j]==mat[i][j])
					isneed=true;
			}
		}
		if(isneed)
			ans--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/agc014/tasks/agc014_b
//B - Unplanned Queries
//根までの経由に置き換える
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N,M; cin>>N>>M;
    vector<ll> cnt(N+1);
    REP(i,M){
        ll a,b;
        cin>>a>>b;
        ++cnt.at(a);
        ++cnt.at(b);
    }
    for(const auto& c:cnt){
        if(c%2!=0) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vc=vector<char>;

const ll MOD=1000000007;


ll frac(int n)
{
	ll ret=1;

	for(int i=1;i<=n;i++)
	{
		ret=(ret*i)%MOD;
	}
	return ret;
}


int main(void)
{
	int n;
	char s[200000+2];

	while(scanf("%d\n%200000[BW]\n", &n, s)==2)
	{
		vi a(2*n);
		vc c;
		char p='W';
		bool is_open=true;
		for(int i=0;i<2*n;i++)
		{
			a[i]=(s[i]=='B');
			if(p==s[i])
			{
				is_open=!is_open;
			}
			c.push_back(is_open?'(':')');
			p=s[i];
		}

//		printf("%.*s\n", c.size(), &c[0]);

		ll ans=frac(n);
		int o=0;
		for(int i=0;i<c.size();i++)
		{
			if(c[i]=='(')
			{
				o++;
				continue;
			}
			ans=(ans*o--)%MOD;
		}
		if(o!=0) ans=0;
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1664
from heapq import heappush, heappop

# 入力
N, C = map(int, input().split())
s, t, c = zip(*(map(int, input().split()) for _ in range(N)))

# 優先度付きキューを用いてシミュレーション
Q = []
p = [0 for _ in range(C + 1)]
ans = 0
for x, y, z in sorted(zip(s, t, c)):
    while Q and (Q[0] < x or Q[0] == x == p[z]):
        p[z] = 0
        heappop(Q)
    p[z] = y
    heappush(Q, y)
    ans = max(ans, len(Q))

# 出力
print(ans)


Measured memory_bytes: 62320
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#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;

int main(){
  ll n,m;
  cin >> n >> m;
  ll x[m];
  REP(i,m) cin >> x[i];
  sort(x,x+m);
  vector<ll> ints;
  REP(i,m-1) ints.push_back(x[i+1]-x[i]);
  sort(ints.begin(),ints.end(),greater<ll>());
  ll ans = x[m-1]-x[0];
  REP(i,min(n-1,m-1)){
    ans -= ints[i];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(int argc, char * argv[]) {
    long long n, k;

    cin >> n >> k;

    n = n%k;

    unordered_set<int> prevVals;
    long long minVal = n;

    prevVals.insert(n);

    while(true) {

        n = abs(n - k);
        minVal = min(minVal, n);

        if(n == 0 || prevVals.count(n) != 0)
            break;

        prevVals.insert(n);

    }

    cout << minVal << endl;
    return 0;
}



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

int main()
{
  int n;

  cin >> n;

  long long ans = 0, ans_2 = 0;

  vector<char> c(n);

  rep(i, n)
  {
    cin >> c.at(i);
  }

  int x = 0;
  int y = n - 1;

  while (1)
  {
    if (x > y)
      break;
    else if (c.at(x) == 'W' && c.at(y) == 'R')
    {
      ans++;
      x++;
      y--;
    }
    else if (c.at(x) == 'R')
    {
      x++;
    }
    else if (c.at(x) == 'W')
    {
      y--;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3568
#include <stdio.h>
int sum(int vc[], int no)
{
    int x = 0;
    for (int i = 0; i < no; i++)
    {
        x += vc[i];
    }
    return x;
}
int main()
{
    int r, c;
    scanf("%d %d", &r, &c);
    int n[100][100];
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            scanf(" %d", &n[i][j]);
        }
    }

        int r_n[100];
    int c_n[100];
    int c_sum[100];
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            printf("%d ", n[i][j]);
            r_n[j] = n[i][j];
        }
        printf("%d\n", sum(r_n, c));
    }
    for (int i = 0; i < c; i++)
    {
        for (int j = 0; j < r; j++)
        {
            c_n[j] = n[j][i];
        }
        c_sum[i] = sum(c_n, r);
        printf("%d ", c_sum[i]);
    }
    printf("%d\n", sum(c_sum, c));
}


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



int main(){
    int W, H;
    vector<vector<int>> mapp(1000, vector<int>(1000, 0));
    cin >> H >> W;

    vector<pair<int,int>> move;
    move.push_back(make_pair(1,0));
    move.push_back(make_pair(-1,0));
    move.push_back(make_pair(0,1));
    move.push_back(make_pair(0,-1));
    int cnt = 0;
    for (int i = 0; i < H ; i++){
        for (int j = 0; j < W; j++){
            char a;
            cin >> a;
            if(a == '.'){
                mapp[i][j] = 0;
                cnt++;
            }else{
                mapp[i][j] = 1;
            }
        }
    }

    vector<vector<int>> dist(1000, vector<int>(1000, 0));
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    while (!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        for (auto p: move){
            int nx = x + p.first;
            int ny = y + p.second;
            if(nx == -1 || nx == W || ny == -1 || ny == H || mapp[ny][nx] == 1) continue;
            if(dist[ny][nx] == 0 ){
                dist[ny][nx] = dist[y][x] + 1;
                que.push(make_pair(nx, ny));
            }
        }
    }

    if(dist[H - 1][W - 1] == 0){
        cout << -1 << endl;
    }else{
        int ans = cnt - (dist[H - 1][W - 1] + 1);
        cout << ans << endl;
    }


}


Measured memory_bytes: 8192
import java.util.*;

public class Main {

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

    for (int i = 0; i < s.length(); i++) {
      String first = s.substring(0,i);
      String last = s.substring(i,s.length());
      String full = last + first;

      if (t.equals(full)) {
        System.out.println("Yes");
        return;
      }
    }

    System.out.println("No");
    
  }
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
using namespace std;
using lli = long long int; 

int main(){
	lli a,b;
	cin >> a;
	cin >> b;
	lli A = a;
	lli B = b;
	lli amari;
	lli koubai = 1;
	while(true){
		amari = a % b;
		if(amari == 0){
			koubai = b;
			break;
		}
		a = b;
		b = amari;
	}
	cout << A*B/koubai;
}

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

int main()
{
    int a, b, c;

    // 入力
    cin >> a >> b >> c;

    int count = 3;

    if (a == b && b == c)
    {
        count = 1;
    }
    else
    {
        if (a == b)
            count--;
        if (b == c)
            count--;
        if (a == c)
            count--;
    }
    cout << count << endl;
}

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

int N, K, A[100];
bool DP[100001];

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

    DP[0] = false;  //DP[i]は残りi個のとき先手が勝てるか
    for(int i=1;i<=K;i++){
        for(int j=0;j<N;j++){
            if( A[j] <= i && !DP[i-A[j]] ){
                DP[i] = true;
                break;
            }
            DP[i] = false;
        }
    }

    cout << ( (DP[K])? "First" : "Second" ) << endl;
}

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

bool solve(void){
  string s;
  cin >> s;
  bool flag = false;
  for(int i = 0 ; i < s.size() ; i++){
    if(s[i] == 'C'){
      flag = true;
    }
    if(flag && s[i] == 'F'){
      return true;
    }
  }
  return false;
}

int main(){
  if(solve()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        while(i+1 < n && a[i] == a[i+1]){
            i++;
        }

        if(i+1 < n && a[i] < a[i+1]){
            while(i+1 < n && a[i] <= a[i+1]){
                i++;
            }
        }
        else if (i+1 < n && a[i] > a[i+1]){
            while(i+1 < n && a[i] >= a[i+1]){
                i++;
            }
        }
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
A = [input() for _ in range(H)]

#行の削除
for i in range(len(A)-1, -1, -1):
  if A[i].count(".") == len(A[i]):
        A.pop(i)

rm = []
#列の削除
for w in range(W):
  f = True
  for h in range(len(A)):
    if A[h][w] == "#":
        f = False
  if f:
    rm.append(w)

for r in range(len(rm)-1, -1, -1):
  for h in range(len(A)):
      A[h] = A[h][:rm[r]] + A[h][rm[r]+1:]

#出力
for a in A:
  print(a)

Measured memory_bytes: 66628