akhauriyash/Code-Regression huggingface dataset:
ma = lambda : map(int,input().split())
ni = lambda :int(input())

n = ni()
pt,pa = ma()
for i in range(n-1):
    t,a = ma()
    l = max((pt+t-1)//t,(pa+a-1)//a)
    pt = t*l
    pa = a*l
print(pt+pa)


Measured memory_bytes: 3060
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    ll a, b;
    cin>>a>>b;

    int ans=b;
    if(a<13)
        ans/=2;
    if(a<6)
        ans=0;

    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,a,b;
  cin>>n>>a>>b;
  if(b<=a){
    cout<<"delicious"<<endl;
  }else if(n>=abs(a-b)){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
  return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int Q(int&);
int E(int&);
int T(int&);
int F(int&);

string S;
int N;

int err = 0;
string gs;
int Q(int& p){
  int l = E(p);
  if(err || p >= N || gs[p] != '='){
	err = 1;
	return 0;
  }
  ++p;
  int r = E(p);
  if(err || p != N){
	err = 1;
	return 0;
  }
  return l == r;
}

int E(int& p){
  int x = T(p);
  while(p < N){
    if(gs[p] == '+'){
      ++p;
      x += T(p);
    }
    else if(gs[p] == '-'){
      ++p;
      x -= T(p);
    }
    else
      break;
  }
  return x;
}
 
int T(int& p){
  int x = F(p);
  while(p < N){
    if(gs[p] == '*'){
      ++p;
      x *= F(p);
    }
    else
      break;
  }
  return x;
}

int F(int& p){
  if(err || p >= N){
	err = 1;
	return 0;
  }
  int x = 0;
  if(gs[p] == '-'){
	++p;
	x = -F(p);
  }
  else if(gs[p] == '('){
	++p;
	x = E(p);
	if(gs[p] != ')'){
	  err = 1;
	  return 0;
	}
	++p;
  }
  else if(gs[p] == '0'){
	x = 0;
	++p;
  }
  else if(gs[p] == '1'){
	x = 1;
	++p;
	while(p<N){
	  if(gs[p] == '0')
		x *= 2;
	  else if(gs[p] == '1')
		x = x*2 + 1;
	  else
		break;
	  ++p;
	}
  }
  else{
	err = 1;
	return 0;
  }

  return x;
}

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

  cin >> S;
  N = SZ(S);

  set<char> s;

  REP(i,N)
	if(('a' <= S[i] && S[i] <= 'z') || ('A' <= S[i] && S[i] <= 'Z'))
	  s.insert(S[i]);
  if(SZ(s) > 8){
	cout << 0 << endl;
	return 0;
  }

  char cs[9] = "+-*=()01";
  sort(cs, cs+8);

  set<string> ans;
  do{
	string tmp = S;
	int j = 0;
	REP(i,N){
	  char c = tmp[i];
	  if(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')){
		REP(k,N)
		  if(tmp[k] == c)
			tmp[k] = cs[j];
		++j;
	  }
	}
	int p = 0;
	err = 0;
	gs = tmp;
	int flag = Q(p);
	if(flag && !err)
	  ans.insert(gs);
  }while(next_permutation(cs, cs+8));

  cout << SZ(ans) << endl;
  //for(auto&&s:ans)cout<<s<<endl;

  return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=m;j++){
            ll ans = (n-i)*j+(m-j)*i;
            if(ans==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int[] tempArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int x = tempArray[0];
            int y = tempArray[1];

            int t = (y - 2 * x) / 2;
            int c = x - t;

            if (t >= 0 && c >= 0 && t + c == x && 4 * t + 2 * c == y)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.Out.Flush();
        }
    }
}

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

using namespace std;

int main()
{
  int N;
  vector<int> a;
  cin >> N;
  a.reserve(N);

  for (int i = 0; i < N; i++) {
    int c;
    cin >> c;
    a.push_back(c);
  }
  if (N == 1) {
    cout << a[0] << endl;
    return 0;
  }

  int i = N - 1;
  while (i >= 0) {
    cout << a[i] << " ";
    i -= 2;
  }
  i++;
  while (i < 0) {
    i += 2;
  }
  while (i < N - 2) {
    cout << a[i] << " ";
    i += 2;
  }
  cout << a[N-2] << endl;

  return 0;
}



Measured memory_bytes: 3072
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rn-sshawish
 */
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        
        if (n == 2) {
            System.out.println("Borys");
            return;
        }
        
        int diff = Math.abs(a - b) -1;
        if (diff % 2 != 0) {
            System.out.println("Alice");
        }else{
            System.out.println("Borys");
        }
        
    }
}


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

using namespace std;

const int N = 500010;

char s[N];
int l[N], r[N];

typedef long long LL;

int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i)
    l[i] = (s[i] == '<') ? l[i - 1] + 1 : 0;
  for (int i = n; i >= 1; --i)
    r[i] = (s[i] == '>') ? r[i + 1] + 1 : 0;
  LL ans = 0;
  for (int i = 0; i <= n; ++i)
    ans += max(l[i], r[i + 1]);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4608
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	ps := make([]int, n)
	for i := range ps {
		sc.Scan()
		ps[i], _ = strconv.Atoi(sc.Text())
	}

	ans := 0
	for i := 1 ; i < n-1; i++ {
		if ps[i-1] < ps[i] {
			if ps[i+1] > ps[i] {
				ans++
				continue
			}
		}
		if ps[i-1] > ps[i] {
			if ps[i+1] < ps[i] {
				ans++
			}
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 1844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

int main(){
    ll n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    ll ans=0;
    for(int i=0;i<k;i++){
        if(t[i]=='r')ans+=p;
        else if(t[i]=='s')ans+=r;
        else ans+=s;
        char prev=t[i];
        for(int j=i+k;j<n;j+=k){
            if(t[j]==prev)prev='a';
            else{
                prev=t[j];
                if(t[j]=='r')ans+=p;
                else if(t[j]=='s')ans+=r;
                else ans+=s;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
def int_input():
    return int(input())
  
yens = int_input()

if yens >= 500:
  yens_500 = yens // 500
  yens_5 = (yens % 500) // 5
  happiness_pts = (yens_500 * 1000) + (yens_5 * 5)
  print(happiness_pts)
else:
  print((yens//5) * 5)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    long K = sc.nextLong();
    if (K % 2 == 0) {
      System.out.println(A - B);
    } else {
      System.out.println(B - A);
    }
  }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define fir fisrt
#define sec second

map <int, int> dis;
map <int, int> vis;
map <int, bool> qwe;

int n;
int a[100050];

int main(){
	scanf(" %d", &n);
	int pos;
	if(n % 2 == 0) pos = n / 2;
	else pos = n / 2 + 1;
	for(int i = 1; i <= n; i ++){
		scanf(" %d", &a[i]);
		if(i % 2 != 0) dis[a[i]] ++;
		else vis[a[i]] ++;
	}
	int er1 = 1e9 + 7, er2 = 1e9 + 7, er3 = 1e9 + 7, er4 = 1e9 + 7;
	int Min1 = 1e9 + 7;
	int Min3 = 1e9 + 7;
	int cnt = 0;
	for(int i = 1; i <= n; i += 2){
		if(pos - dis[a[i]] <= Min1 && qwe[a[i]] != 1){
			if(Min1 <= Min3){
				Min3 = Min1;
				er3 = er1;
			}
			Min1 = pos - dis[a[i]];
			er1 = a[i];
		}
		else if(qwe[a[i]] != 1 && pos - dis[a[i]] <= Min3){
			Min3 = pos - dis[a[i]];
			er3 = a[i];
		}
		qwe[a[i]] = 1;
	}
	cnt = 0;
	int Min2 = 1e9 + 7;
	int Min4 = 1e9 + 7;
	qwe.clear();
	for(int i = 2; i <= n; i += 2){
		if((n - pos) - vis[a[i]] <= Min2 && qwe[a[i]] != 1){
			if(Min2 <= Min4){
				Min4 = Min2;
				er4 = er2;
			}
			Min2 = (n - pos) - vis[a[i]];
			er2 = a[i];
		}
		else if(qwe[a[i]] != 1 && (n - pos) - vis[a[i]] <= Min4){
			Min4 = (n - pos) - vis[a[i]];
			er4 = a[i];
		}
		qwe[a[i]] = 1;
	}
	if(n == 1) printf("0\n");
	else if(n == 2){
		if(a[1] == a[2]) printf("1\n");
		else printf("0\n");
	}
	else if(er1 != er2) printf("%d\n", Min1 + Min2);
	else{
		int Min = 1e9 + 7;
		if(Min3 != 1e9 + 7 && er3 != er2){
			Min = min(Min, Min3 + Min2);
		}
		if(Min3 != 1e9 + 7 && Min4 != 1e9 + 7 && er3 != er4){
			Min = min(Min, Min3 + Min4);
		}
		if(Min4 != 1e9 + 7 && er1 != er4){
			Min = min(Min, Min1 + Min4);
		}
		if(Min == 1e9 + 7) printf("%d\n", min(pos, n - pos));
		else printf("%d\n", Min);
	}
}

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

int main() {
  string ABCD;
  cin >> ABCD;
  int A=ABCD.at(0)-'0', B=ABCD.at(1)-'0', C=ABCD.at(2)-'0', D=ABCD.at(3)-'0';
  if (A+B+C+D==7) cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A-B+C+D==7) cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A+B-C+D==7) cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A+B+C-D==7) cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A+B-C-D==7) cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  else if (A-B+C-D==7) cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A-B-C+D==7) cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A-B-C-D==7) cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
}

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


#define ALREADY 1
#define YET 0

int *passed;
int *distance_ps;

using namespace std;


void bfs(vector< vector<int> > a, int i, int dis){
  // i?????????vector<int>??????????????¢?????????
  dis++;
  vector<int> ai = a[i];
  int n = ai.size();
  // cout << "i: " << i << ",n: " << n << endl;
  for(int j=0;j<n;j++){
    int nexti=ai[j]-1;
    
    if(passed[nexti]==YET || distance_ps[nexti]>dis){
      passed[nexti]=ALREADY;
      distance_ps[nexti]=dis;
      bfs(a, nexti, dis);
    }
  }
}

int main(){
  int n;
  cin >> n;
  vector< vector<int> > a;
  for(int i=0;i<n;i++){
    int u;
    int k;
    cin >> u >> k;
    vector<int> tmpa;
    for(int j=0;j<k;j++){
      int tmp;
      cin >> tmp;
      tmpa.push_back(tmp);
    }
    a.push_back(tmpa);
  }
  
  int a2[n][n];
  passed = new int[n];
  distance_ps = new int[n];
  
  for(int i=0;i<n;i++){
    passed[i] = 0;
    distance_ps[i] = 1000;
  }

  distance_ps[0]=0;
  bfs(a, 0, 0);

  for(int i=0;i<n;i++){
    if(passed[i]==YET){
      distance_ps[i] = -1;
    }
  }
  distance_ps[0]=0;
  
  for(int i=0;i<n;i++){
    cout << i+1 << " " << distance_ps[i] << endl;
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      a2[i][j]=0;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)a[i].size();j++){
      a2[i][a[i][j]-1] = 1;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      // if(j!=0)cout << " ";
      // cout << a2[i][j];
    }
    // cout << endl;
  }
      
  
}

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

int main() {
  //入力を受け取る
  //a(i)を大きい順にソート
  //aliceの下から奇数番目を合計したものを計算
  //bobは下から偶数番目を合計したものを計算
  //alice-bob
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);}
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  //cout<<a.at(1);
  int alice,bob=0;
  //cout<<alice;
  for(int i=0;i<N;i++){
    if(i%2>0){bob+=a.at(i);}
    else if(i%2==0){alice+=a.at(i);}
  }
  cout<<alice-bob<<endl;
  return 0;}
  

Measured memory_bytes: 256
#include <cctype>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

typedef set<pair<int,int> > S;

map<int, S> table;
pair<int,int> ps[100000+50];

int solve(int n) {
  sort(ps, ps + n);
  REP(i, n) {
    auto it = table.find(ps[i].second);
    if(it == table.end()) {
      S s;
      s.insert(make_pair(ps[i].first, i));
      table[ps[i].second] = s;
    } else {
      it->second.insert(make_pair(ps[i].first, i));
    }
  }
  int rest = n-2;
  for(int i = n-1; i >= 0; --i) {
    pair<int,int> p = ps[i];
    if(p.first <= p.second) {
      auto it = table.find(p.second);
      it->second.erase(make_pair(p.first, i));
      if(it->second.empty()) {
        table.erase(it);
      }
      continue;
    }
    if(rest <= 0) return false;
    auto it = table.lower_bound(p.first); // 交換対象のset
    if(it == table.end()) return false;
    auto it2 = it->second.begin(); // 交換対象
    ps[it2->second].second = p.second;
    ps[i].second = it->first;
    auto it3 = table.find(p.second); // 元のset
    it3->second.erase(make_pair(p.first, i));
    it3->second.insert(*it2);
    it->second.erase(it2);
    --rest;
  }
  return true;
}

int as[100000+50];
int bs[100000+50];
int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &as[i]);
  }
  REP(i, n) {
    scanf("%d", &bs[i]);
    ps[i] = make_pair(as[i], bs[i]);
  }
  bool res = solve(n);
  puts(res ? "Yes" : "No");
  
  return 0;
}


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


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

    vector<int> v(N+1, 0);
    while(M--) {
        int A;
        cin >> A;
        v[A]++;
    }
    int l = accumulate(v.begin(), v.begin()+X, 0);
    int r = accumulate(v.begin()+X, v.end(), 0);
    cout << min(l, r) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	int A, B;
	cin >> A >> B;
	vector<int>vec(3);
	vec.at(0) = A + B;
	vec.at(1) = A - B;
	vec.at(2) = A * B;
	sort(vec.begin(), vec.end());
	cout << vec.at(2) << endl;
}



	


Measured memory_bytes: 256
class Array
  include Comparable
  def cumsum(s = 0); map{|k| s += k } end
  def diff; s = self[0]; self[1...(self.size)].map{|k|d=k-s; s=k; d} end
end
include Math
mod = 10 ** 9 + 7
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a  end
def yn(f); puts f ? "Yes" : "No" end
def yes; puts "Yes"; exit end
def no; puts "No"; exit end
#(n, k), (s, k), a, f = $<.map{|l| l.to_s.split.map(&:to_i) }
#n = gets.to_s.to_i
a, b = gets.to_s.split.map{|e|e.to_i}
#m = Array.new(n){ gets.to_s.split.map{|e|e.to_i} }
#s = gets.to_s.chomp
ans = a * b

puts ans

Measured memory_bytes: 14324
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,lcm;
int a[200005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	lcm=a[1];
	for (int i=2;i<=n;i++)  lcm=(lcm/__gcd(lcm,a[i]))*a[i];
	cout<<lcm<<endl;
	
	return 0;
}

Measured memory_bytes: 256
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

bool desc(const P &a, const P &b){
	return a.sc > b.sc;
}

int main(void){
	ll n, k;
	cin >> n >> k;
	double ans = 0;
	repn(i, n){
		ll score = i;
		double p = 1.0;
		while(score < k){
			score <<= 1;
			p /= 2;
		}
		ans += p;
	}
	setp(10);
	co(ans/n);

	return 0;
}


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

using namespace std;

int main()
{
    string fi;
    int n;
    string ring;
    int ans = 0;

    cin >> fi >> n;

    for (int i = 0; i < n; i++) {
        cin >> ring;
        ring += ring;
        if (ring.find(fi) != -1) {
            ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3144
using System;
using System.Linq;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var sArray = s.ToArray();
            var tArray = t.ToArray();

            Array.Sort(sArray);
            Array.Sort(tArray);
            Array.Reverse(tArray);

            var replacedS = string.Join("", sArray);
            var replacedT = string.Join("", tArray);

            var result = replacedS.CompareTo(replacedT) == -1 ? "Yes" : "No";

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 26692
import sys
t='X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t and'+'!=e[1])or('+X='not in e and'+X'in e)or(e[-1]==t and'=X'in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split('+')))==int(r):print(i);break
 else:print('NA')


Measured memory_bytes: 5620
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let x: u64 = sc.read();
    let mut books = vec![];
    for _ in 0..n {
        let c: u64 = sc.read();
        let a: Vec<u64> = sc.vec(m);
        books.push((c, a));
    }

    let mut ans = 1 << 60;
    for mask in 0..(1 << n) {
        let mut cost = 0;
        let mut ability = vec![0; m];
        for i in 0..n {
            if mask & (1 << i) != 0 {
                cost += books[i].0;
                for j in 0..m {
                    ability[j] += books[i].1[j];
                }
            }
        }

        if ability.into_iter().all(|a| a >= x) {
            ans = min(ans, cost);
        }
    }

    if ans == 1 << 60 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[200100];
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	cin>>k>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int res=k;
	for(int i=1;i<n;i++){
		res=min(res,k-(a[i+1]-a[i]));
	}
	res=min(res,a[n]-a[1]);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
import java.math.RoundingMode;
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        double b = sc.nextDouble();
        BigDecimal bd1 = BigDecimal.valueOf(a);
        BigDecimal bd2 = BigDecimal.valueOf(b);
        BigDecimal bd3 = bd1.multiply(bd2);
        BigDecimal sol = bd3.setScale(0, RoundingMode.DOWN);

        System.out.println(sol);
    }
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int n;
    cin >> n;
    set<int> a;
    while (n--) {
        int c;
        cin >> c;
        a.insert(c);
    }
    cout << a.size() << "\n";
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0,w=0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = -1, mini = 9999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremonogusu[100010], koware[100001];
long long  int iremonokisu[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<char>kinds{}, kaku{}, kakutwo{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a,long long int b)
{
	return a * b / gcd(a, b);
}

int main() {
	cin >> a;
	cout << 3 * a*a << endl;
}




Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    cout << 2 * r * M_PI << endl;
    return 0;
}



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

template<typename T>
struct Sieve{
    vector<bool> is_prime;
    vector<T> prime;
    T prime_count;
    Sieve(T n):is_prime(n+1,true),prime_count(0){
        is_prime[0] = false;
        is_prime[1] = false;
        for (T i=2;i<=n;i++){
            if (is_prime[i]){
                prime.push_back(i);
                prime_count++;
                for (T j=2*i; j<=n ;j+=i) is_prime[j]=false;
            }
        }
    };
};

void solve(long long Q, std::vector<long long> l, std::vector<long long> r){
    ll maximum_n = 100007;
    Sieve<ll> a(maximum_n);
    vector<ll> like2017(maximum_n+1,0);
    for (int i=0;i<maximum_n;i++){
        if (i%2==1){
            if (a.is_prime[i] && a.is_prime[(i+1)/2]) like2017[i] =1;
        }
    }
    vector<ll> like2017_count(maximum_n);//[0,idx)のlike2017のカウント
    ll count = 0;
    for (ll i=0;i<maximum_n;i++){
        like2017_count[i] =count;
        count+=like2017[i];
    }
    for (int i=0;i<Q;i++){
        ll ret = like2017_count[r[i]+1] - like2017_count[l[i]];
        printf("%lld\n",ret);
    }
    


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(Q, std::move(l), std::move(r));
    return 0;
}


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

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(void){
    ll N;
    cin >> N;
    vector<pair<ll, ll>> ab(N);
    for (int i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(), ab.end(), compare_by_b);
    
    ll count_time = 0;
    bool flag = true;
    for (int i = 0; i < N; i++) {
        count_time += ab[i].first;
        if (count_time > ab[i].second)
            flag = false;
    }
    
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<int> **route = (vector<int>**) malloc( sizeof(vector<int>*) * (n + 1) );
    for ( int i =0; i < n + 1; i++ ) route[i] = new vector<int>();
    for(int i = 0; i < m; i++ )
    {
        int a, b;
        cin >> a >> b;
        route[a]->push_back(b);
        route[b]->push_back(a);
    }

    queue<int> searchlist;

    int *parent = (int*) malloc(sizeof(int) * (n + 1) );
    memset(parent, 0, sizeof(int) * (n + 1) );
    parent[1] = 1;

    {
        searchlist.push(1);

        while( !searchlist.empty() )
        {
            int next = searchlist.front();
            searchlist.pop();
            for(auto itr = route[next]->begin(); itr != route[next]->end(); ++itr) {
                if( parent[*itr] == 0 )
                {
                    parent[*itr] = next;
                    searchlist.push(*itr);
                }
            }
        }
    }

    cout << "Yes" << endl;
    for( int i = 2; i < n + 1; i++ )
    {
        cout << parent[i] << endl;
    }

    for ( int i =0; i < n + 1; i++ ) delete route[i];
    free(route);
    free(parent);
}


Measured memory_bytes: 11788
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define si scanf
#define so printf
#define N 200100
#define M 
#define INF  
#define nxt t[j]
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
int n; 
int h[N],x[N*2],t[N*2],tot=1;
int du[N],A;
void add(int u,int v)
{
	++tot;
	x[tot]=h[u];
	h[u]=tot;
	t[tot]=v;
	++du[u];
}
int ln[N],l2[N];
int f[N];
bool ok(int mid,int u)
{
	for(int i=1;i<=ln[0];++i)
		if(i==mid)
			l2[i]=n+100;
		else
			l2[i]=ln[i];
	sort(l2+1,l2+ln[0]+1);
	for(int i=1;i<ln[0];++i)
		if(l2[i]+l2[ln[0]-i]+1>u)
			return 0;
	return 1;
}
int dp(int u)
{
	sort(ln+1,ln+ln[0]+1);
	for(int i=1;i<=ln[0]-1;++i)
		if(ln[i]+ln[ln[0]-i]+1>u)//无法配对 
			return n*12;
	ln[ln[0]+1]=n*12;
	int l=1,r=ln[0]+1,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(ok(mid,u))
			r=mid;
		else
			l=mid+1;
	}
	if(l>ln[0])
		return n*12;
	return ln[l]+1;
}
bool dfs(int now,int u,int fa)
{
	for(int j=h[now];j;j=x[j])
		if(nxt!=fa)
			if(dfs(nxt,u,now)==0)
				return 0;
	ln[0]=0;
	for(int j=h[now];j;j=x[j])
		if(nxt!=fa)
			ln[++ln[0]]=f[nxt];
	if(du[now]&1)
		ln[++ln[0]]=0;
	f[now]=dp(u);
	if(f[now]>u)
		return 0; 
	return 1;
}
int main()
{
	rd(n);
	int u,v;
	for(int i=1;i<n;++i)
	{
		rd(u),rd(v);
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=n;++i)
		if(du[i]&1)
			++A;
	int rt=0;
	for(int i=1;i<=n&&!rt;++i)
		if(du[i]==1)
			rt=i;
	A>>=1;
	int l=1,r=n*10,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		//memset(f,0x3f,sizeof(f));
		if(dfs(rt,mid,0))
			r=mid;
		else
			l=mid+1;
	}
	so("%d %d\n",A,l-1);
	return 0;
} 

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    vi a(n);
    rep(i, n) a[i] = i + 1;

    int pcount = 0, qcount = 0;
    bool pbool = false, qbool = false;
    do
    {
        // for (size_t i = 0; i < n; i++)
        // {
        //     cout << a[i] << " ";
        // }
        // cout << endl;
        // cout << "p : " << pcount << " q : " << qcount << endl;
        if (p == a)
        {
            pbool = true;
        }
        if (q == a)
        {
            qbool = true;
        }
        if (pbool && qbool)
        {
            break;
        }

        if (!pbool)
            pcount++;
        if (!qbool)
            qcount++;
    } while (next_permutation(a.begin(), a.end()));

    cout << abs(pcount - qcount) << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
if S[0]==S[1]==S[2]==S[3]:
	print("No")
else:
	if S[0] == S [1]:
		if S[2] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[2]:
		if S[1] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[3]:
		if S[1] == S[2]:
			print("Yes")
		else:
			print("No")
	else:
		print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a.at(i);
    sort(a.begin(),a.end(),greater<int>());
    queue<int> q;
    int count=-1;
    int v=-1;
    rep(i,n){
        if(v!=a.at(i)){
            count=1;
            v=a.at(i);
        }
        else{
            count++;
        }
        if(!(count%2)){
            count-=2;
            q.push(v);
        }
        if(q.size()==2){
            break;
        }
    }
    if(q.size()==2){
        ll x,y;
        x=q.front(); q.pop();
        y=q.front(); q.pop();
        cout<<x*y<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<double>A(N);
  for(int i=0;i<N;i++)cin>>A.at(i);
  sort(A.begin(),A.end());
  double S=A.at(0);
  for(int i=1;i<N;i++){
    S=(S+A.at(i))/2;
  }
  cout<<S<<endl;
}
  
  

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, x;
    for(i=1; i<=10000; i++)
    {
        cin >> x;
        if(x==0)
            break;
        else
            cout << "Case " << i << ": " << x << endl;
        
        
        
    }
}


Measured memory_bytes: 3076
N,M = $stdin.gets.chomp.split(" ").map(&:to_i)

cnt = 0
rightest = -1
(0...M).map{ $stdin.gets.chomp.split(" ").map(&:to_i) }.sort_by{ |m| m[1] }.each{ |m|
  a,b = m
  if rightest <= a
    cnt += 1
    rightest = b
  end
  #p [a,b, rightest, cnt]
}
puts cnt

Measured memory_bytes: 12664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int h,w;
	char s[100][101];

	cin >> h >> w;
	for(int i=0;i<h;i++){
		cin >> s[i];
	}
	bool x[100];
	bool y[100];
	for(int i=0;i<100;i++){
		x[i] = false;
		y[i] = false;
	}

	for(int i=0;i<h;i++){
		bool tmp = true;
		for(int j=0;j<w;j++){
			if(s[i][j]=='#'){
				tmp = false;
			}
		}
		if(tmp) x[i] = true;
	}
	for(int i=0;i<w;i++){
		bool tmp = true;
		for(int j=0;j<h;j++){
			if(s[j][i]=='#'){
				tmp = false;
			}
		}
		if(tmp) y[i] = true;
	}

	for(int i=0;i<h;i++){
		if(x[i]) continue;
		for(int j=0;j<w;j++){
			if(!y[j]){
				cout << s[i][j];
			}
		}
		cout << endl;
	}
	

	return 0;
}

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

if B - A + 1 > 2 * K:
    for i in range(A, A + K):
        print(i)
    for i in range(B - K + 1, B + 1):
        print(i)
else:
    for i in range(A, B + 1):
        print(i)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i,j;
    cout << N*(N-1)/2-N/2 <<endl;
    for(i=N;i>0;i--){
      for(j=i-1;j>0;j--){
          if((j!=N+(N+1)%2-i))cout << i << " "<<j<<endl;
      }
    }
    return 0;
}


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

int main(void){
  int a6,
      a5,
  a4, a1, a3,
      a2;
  string str;
  int n, temp;
  while(cin >> n, n != 0){
    a1 = 1;
    a2 = 2;
    a3 = 3;
    a4 = 4;
    a5 = 5;
    a6 = 6;
    int ans = 1;
    for(int i = 0; i < n; i++){
      cin >> str;
      if(str == "North"){
	temp = a1;
	a1 = a2;
	a2 = a6;
	a6 = a5;
	a5 = temp;
      }
      if(str == "East"){
	temp = a1;
	a1 = a4;
	a4 = a6;
	a6 = a3;
	a3 = temp;
      }
      if(str == "West"){
	temp = a1;
	a1 = a3;
	a3 = a6;
	a6 = a4;
	a4 = temp;
      }
      if(str == "South"){
	temp = a1;
	a1 = a5;
	a5 = a6;
	a6 = a2;
	a2 = temp;
      }
      if(str == "Right"){
	temp = a2;
	a2 = a3;
	a3 = a5;
	a5 = a4;
	a4 = temp;
      }
      if(str == "Left"){
	temp = a2;
	a2 = a4;
	a4 = a5;
	a5 = a3;
	a3 = temp;
      }
      ans += a1;
    }
    cout << ans << endl;
  }
  return 0;
}

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

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template <class Z> Z getint() {
  char c = getchar();
  bool neg = c == '-';
  Z res = neg ? 0 : c - '0';
  while (isdigit(c = getchar())) res = res * 10 + (c - '0');
  return neg ? -res : res;
}
template <class Z> void putint(Z a, char c = '\n') {
  if (a < 0) putchar('-'), a = -a;
  int d[40], i = 0;
  do d[i++] = a % 10; while (a /= 10);
  while (i--) putchar('0' + d[i]);
  putchar(c);
}

template <class T> struct FenwickTree {
  const int n;
  vector<T> t;
  FenwickTree(int _n) : n(_n), t(n + 1) {}
  void add(int i, T a) { for (++i; i <= n; i += i & -i) t[i] += a; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
  int kth(T k) const {
    int i = 0;
    for (int w = 1 << __lg(n); w; w >>= 1)
      if (i + w <= n and t[i + w] <= k) k -= t[i += w];
    return i;
  }
};
template <class T> struct AddSumTree {
  const int n;
  vector< FenwickTree<T> > ft;
  AddSumTree(int _n) : n(_n), ft(2, n + 1) {}
  void add(int l, int r, T a) {
    ft[0].add(l, a), ft[0].add(r, -a);
    ft[1].add(l, l * a), ft[1].add(r, -(r * a));
  }
  T sum(int i) const { return i * ft[0].sum(i) - ft[1].sum(i); }
  T sum(int l, int r) const { return sum(r) - sum(l); }
};

int main() {
  AddSumTree<long long> ast(getint<int>());
  for (int _ = getint<int>(); _--; ) {
    if (getint<int>() == 0) {
      int l = getint<int>() - 1, r = getint<int>();
      long long a = getint<long long>();
      ast.add(l, r, a);
    } else {
      int l = getint<int>() - 1, r = getint<int>();
      putint(ast.sum(l, r));
    }
  }
}



Measured memory_bytes: 5196
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');
    args.map(Number).forEach(function(x){
        console.log(solve(x));
    })
}

function solve(x){
    var count = 0;
    if(x > 9 * 4) {
        return count;
    }

    for(var a = 0; a <= 9; a += 1)
        for(var b = 0; b <= 9; b += 1)
            for(var c = 0; c <= 9; c += 1)
                for(var d = 0; d <= 9; d += 1)
                    if(a + b + c + d === x)
                        count += 1;

    return count;
}

Measured memory_bytes: 16120
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int d,n;
  cin>>d>>n;
  if(d<9&&n<9)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    CNT, ans = 0, 0
    for i in range(N):
        CNT = sum(A[0:i+1]) + sum(B[i:N+1])
        ans = max(ans, CNT)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int par[100010];
int ranks[100010];
int size_UF;

void init(int n){
    size_UF=n;
    for(int i=0; i<n; i++){
        par[i]=i;
        ranks[i]=0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x == y) return;
    size_UF--;

    if(ranks[x] < ranks[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
    }
    
    if(ranks[x] == ranks[y]){
        ranks[x]++;
    }
}

int main(){
    int n, m; cin>>n>>m;
    init(n);
    vector<vector<int>> lang(m);
    for(int i=0; i<n; i++){
        int k; cin>>k;
        for(int j=0; j<k; j++){
            int l; cin>>l;
            l--;
            lang[l].eb(i);
        }
    }

    for(int i=0; i<m; i++){
        for(int j=0; j+1<lang[i].size(); j++){
            unite(lang[i][j], lang[i][j+1]);
        }
    }

    if(size_UF==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int64_t INF = 1'000'000'000'000'000'000;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<int64_t> S(A), T(B), X(Q);
    for(int i=0;i<A;i++)    cin >> S[i];
    for(int i=0;i<B;i++)    cin >> T[i];
    for(int i=0;i<Q;i++)    cin >> X[i];
    S.insert(S.begin(), -INF);
    S.push_back(INF);

    T.insert(T.begin(), -INF);
    T.push_back(INF);

    vector<int64_t>::iterator Sb, Tb;
    for(int i=0;i<Q;i++){
        Sb = upper_bound(S.begin(), S.end(), X[i]);
        Tb = upper_bound(T.begin(), T.end(), X[i]);

        int64_t ans=INF;
        int64_t d1, d2, res;
        for(auto itr1=Sb-1;itr1<=Sb;itr1++){
            for(auto itr2=Tb-1;itr2<=Tb;itr2++){
                d1 = abs(*itr1 - X[i]) + abs(*itr2 - *itr1);
                d2 = abs(*itr2 - X[i]) + abs(*itr1 - *itr2);
                //cout << "d1 = " << d1 << endl;
                //cout << "d2 = " << d2 << endl;
                res = min(d1, d2);
                ans = min(ans, res);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3680
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
class Solution {
    public void solve(TextReader input, TextWriter output) {
        int n = int.Parse(input.ReadLine());
        string s1 = input.ReadLine(), s2 = "";
        foreach (var c in s1)
        {
            if (c == '(')
            {
                s2 += ")";
            }
            else
            {
                s2 += "(";
            }
        }

        string ss = s2 + s1 + s2;
        bool[] used = new bool[3 * n];
        int pos = ss.IndexOf(s1);

        for (int i = pos; i < pos + n; i++)
        {
            if (used[i])
            {
                continue;
            }
            if (ss[i] == ')')
            {
                for (int j = pos; j < i; j++)
                {
                    if (ss[j] == '(' && !used[j])
                    {
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
                }
            }
            else
            {
                for (int j = i; j < pos + n; j++)
                {
                    if (ss[j] == ')' && !used[j])
                    {
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
                }
            }
        }

        for (int i = pos; i < pos + n; i++)
        {
            if (used[i])
            {
                continue;
            }
            if (ss[i] == ')')
            {
                for (int j = 0; j < pos; j++)
                {
                    if (ss[j] == '(' && !used[j])
                    {
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
                }
            }
            else
            {
                for (int j = pos + n; j < 3 * n; j++)
                {
                    if (ss[j] == ')' && !used[j])
                    {
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
                }
            }
        }

        string ans = "";
        for (int i = 0; i < 3 * n; i++)
        {
            if (used[i])
            {
                ans += ss[i];
            }
        }
        output.WriteLine(ans);
    }
}

class CaideConstants {
    public const string InputFile = null;
    public const string OutputFile = null;
}
public class Program {
    public static void Main(string[] args) {
        Solution solution = new Solution();
        using (System.IO.TextReader input =
                CaideConstants.InputFile == null ? System.Console.In :
                        new System.IO.StreamReader(CaideConstants.InputFile))
        using (System.IO.TextWriter output =
                CaideConstants.OutputFile == null ? System.Console.Out:
                        new System.IO.StreamWriter(CaideConstants.OutputFile))

            solution.solve(input, output);
    }
}



Measured memory_bytes: 13404
///                                   ahmocs
#include <bits/stdc++.h>
typedef long long ll;
#define ahmocs  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll N=1e3+5, OO=1e18;
using namespace std;
char g[N][N];
int mem[N][N];
int n,m;
int solve(int h, int w)
{
    if(h>=n || w>=m || h<0 || w<0 || g[h][w] == '#') return 0;
    if (h==n-1 && w==m-1) return 1;
    if (mem[h][w]!=-1) return mem[h][w];
    int cnt=0;
    cnt = (solve(h, w + 1) + solve(h + 1, w)) % 1000000007;
    mem[h][w] = cnt;
    return cnt;
}
int main()
{
    ahmocs
    cin>>n>>m;
     for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            mem[i][j]=-1;
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            cin>>g[i][j];
    cout<<solve(0,0);
    return 0;
}
//islam mohsen edit

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007
//main
signed main(){
  int N,M,O,P,count=0,count2=mod,count3=0,stack=0;
  str S,T;
  cin>>N>>M;
  if(M==1)cout<<0<<endl;
  else cout<<N-M<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rc(s) return cout<<s,0
long long x,y;
int main(){
  cin >> x >> y;
  if(__gcd(x,y)==y) rc(-1);
  for(int i=1;i<=10000000;i++){
     if((x*i)%y!=0)  rc(x*i); 
  }
   rc(-1);
}

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

int main()
{
  int k, n;
  cin >> k >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  int max = (k + a[0]) - a[n-1];
  int dis;
  int sum = max;
  for(int i = 0; i < n-1; i++)
  {
    dis = a[i+1] - a[i];
    sum += dis;
    if(dis > max) max = dis;
  }
  sum -= max;
  cout << sum;
  return 0;
}

Measured memory_bytes: 1024