akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
//const ll INF64 = 9223372036854775807ll;
const ll INF64 = 9223372036854775ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    if(n==1)std::cout << s << std::endl;
    else{
        bool b=0;
        rrep(i,1,n){
            if(s[i]!='9')b=1;
        }
        if(b){
            std::cout << (n-1)*9+(s[0]-'0'-1)<< std::endl;
        }
        else{
            std::cout << (n-1)*9+(s[0]-'0'-0) << std::endl;
        }
    }
}

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

char c, p;
int l, lp;
long long r;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  for(; cin.get(c) && c > ' '; r += ++l) {
    if(c != p) { 
      if(c == '<')
        r -= l < lp ? l : lp;
      p = c, lp = l, l = 0;
    }
  }
  if(p == '>')
    r -= l < lp ? l : lp;
  cout << r << '\n';
  return 0;
}


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


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool is_prime(long long n){
    for(int i=2; i*i<=n; i++){
        if(n%i==0) return false;
    }
    return true;
}

int min_div(long long n){
    for(int i=2;i*i<=n; i++){
        if(n%i==0) return i;
    }
    return n;
}

int fact[200000];

int main(){
    COMinit();

    long long N, M;
    cin >> N >> M;
    if(M==1) {cout << 1 <<endl; return 0;}
    if(is_prime(M)) {cout << N << endl; return 0;}
    long long m=M;

    int cnt=0;
    int t_before, t_now;
    t_before=1;
    while(m>1){
        t_now = min_div(m);
        if(t_now==t_before) fact[cnt]++;
        else{
            cnt++;
            fact[cnt]++;
        }
        t_before = t_now;
        m = m/t_now;
    }
//    for(int i=2; i*i<=M;i++){
//        while(m%i==0) {
//            fact[i]++;
//            m = m/i;
//        }
//    }

    long long ans = 1;

    for(int i=0; i<200000; i++){
//        if(i<15) cout << fact[i] << endl;
        ans *= COM(N+fact[i]-1, fact[i]);
        ans %= MOD;
    }

    cout << ans << endl;

}

Measured memory_bytes: 12288
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
const ll mod=1000000007;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int a,b,c; cin>>a>>b>>c;
  int k=3;
  if(a==c||a==b) k--;
  if(b==c) k--;
  cout<<k<<endl; 

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int64_t l_num(int x){
  int64_t l[x],i;
  if(x==0){
  return 2;
  }
  if(x==1){
  return 1;
  }
for(int i=2;i<=x;i++){
l[i] =0;
}
for(int i=2;i<=x;i++){
l[0]=2;
l[1]=1;
l[i]+=l[i-1]+l[i-2];
}
return l[x];
 
}
 
int main(){
int N;
cin >> N;
cout << l_num(N) <<endl;
}  

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1e5 + 5;
vector <int> adj[MAXN];
vector <int> vis(MAXN,0);
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
void dfs(int s)
{
  vis[s] = 1;
  for(int u:adj[s])
  {
    if(!vis[u])
    {
      dfs(u);
    }
  }
  return ;
}
int32_t main()
{
 //c_p_c();
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++)
  {
    int x,y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cc = 0;
  for(int i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      dfs(i);
      cc++;
    }
  }
  if(cc == 1)
  {
    fill(vis.begin(),vis.end(),0);
    cout<<"Yes"<<endl;
    vector<int> dist(n+1,inf);
    queue <int> q;
    q.push(1);
    dist[1] = 0;
    vis[1] = 1;
    while(!q.empty())
    {
      
      int f = q.front();
      q.pop();
      vis[f] = 1;
      for(int u:adj[f])
      {
        if(!vis[u])
        {
          vis[u] = 1;
          q.push(u);
          dist[u] = f;
        }
      }
    }
    for(int i=2;i<=n;i++)
    {
      cout<<dist[i]<<endl;
    }
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 15352
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;

int n;
int nxt[N];
ll k;

int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
        scanf("%d", &nxt[i]);
    
    map<int, int> m; // 记录是否到达过
    int pos = 1; // 跳跃的点
    m[pos] = 1;  // 初始化 1 号点
    int cnt = 0; // 跳跃的次数
    int ans = -1;
    while(1){
        pos = nxt[pos]; // 跳跃到下一个点
        cnt ++; // 次数 ++
        // 次数用光了，退出
        if(cnt == k) { ans = pos; break; } 
        // m[pos] = 1,说明 pos 在之前已经到达过了，此时进入了循环
        if(m[pos] == 1) break;
        m[pos] = 1; // 标记
    }

    if(ans != -1) { cout << ans << endl; return 0; }
    k -= cnt; // 减去已经跳跃的次数

    int t = pos;
    vector<int> node; // 记录循环节上的点
    node.push_back(pos); 
    cnt = 0;
    while(1){
        t = nxt[t];
        cnt ++;
        node.push_back(t);
        if(t == pos) break; // 循环终止
    }

    // 取模输出即可
    cout << node[k % cnt] << endl;

    return 0;
}

Measured memory_bytes: 11972
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

ll mpow(ll n, ll t) {
  rep(i,t) n*=n;
  if (t==0) n=1;
  return n;
}

int main() {
  int N;
  cin >> N;
  ll S=0;
  vector<ll> A(N);
  rep(i,N) {
    cin >> A[i];
    S^=A[i];
  }
  rep(i,N) cout << (S^A[i]) << ' ';
  cout << endl;
}

Measured memory_bytes: 4836
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

def main():
	P,Q,R = map(int, input().split(" "))
	#N = int(input())
	#S = input()
	#S = list(S)

	ans = []
	ans.append(Q)
	ans.append(P)
	ans.append(R)
	ans.sort()

	ans1 = ans[0] + ans[1]

	print(ans1)


	

if __name__ == "__main__":
	main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 #define MAX 1000000000005
 #define ll long long int
 int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   ll t;
        long long int m,sum=0,k=0,i,d=0,j,sum1=0,sum2=0,sum3=0,l,kk,sum4=0,sum5=0,sum6=0,c=0,x,y,q;
         ll n;
           cin>>n;
          ll a[n];
           for(i=0;i<n;i++)
             {cin>>a[i];
              sum+=a[i];
             }
              map<ll,ll>mp;
              for(i=0;i<n;i++)
                 mp[a[i]]++;
          cin>>q;
           while(q--){
            cin>>x>>y;
             ll z=mp[x];
             sum-=mp[x]*x;
               mp.erase(x);
                sum+=y*z;
                 mp[y]+=z;
                 cout<<sum<<endl;

           }
    }








Measured memory_bytes: 8320
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll a=0,b=0,c=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='a')a++;
        if(s[i]=='b')b++;
        if(s[i]=='c')c++;
    }
    int diff1 = abs(a - b);
    int diff2 = abs(b - c);
    int diff3 = abs(a - c);
    if(diff1 > 1 || diff2 > 1 || diff3 > 1) 
        puts("NO");
    else 
        puts("YES");
    return 0;
}

Measured memory_bytes: 3656
s = str(input())
n = len(s)
ans = 1
count = 1
tmp = s[0]
while count < n:
    if s[count] == tmp:
        if count == n-1:
            ans -=1
        tmp = s[count:count+2]
        count +=2

    else:
        tmp = s[count]
        count +=1
    ans +=1

print(ans)

Measured memory_bytes: 3500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.awt.Point;
import java.util.Deque;
import java.util.ArrayDeque;
   
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
while(!(str=br.readLine()).equals("0 0")){
String[] value=str.split(" ");
int h=Integer.parseInt(value[0]);
int w=Integer.parseInt(value[1]);
char[][] map=new char[h][w];
for(int i=0;i<h;i++){
map[i]=br.readLine().toCharArray();
}
Deque <Point> que=new ArrayDeque<Point>();
int ans=0;
for(int m=0;m<h;m++){
for(int n=0;n<w;n++){
if(map[m][n]!='.'){
ans++;
Point p = new Point(n,m);
que.addLast(p);
while(que.peekFirst()!=null){
p=que.pollFirst();
int x=p.x;
int y=p.y;
char crop = map[y][x];
map[y][x]='.';
int [] dx ={0,1,0,-1};
int [] dy ={1,0,-1,0};                   
for(int i=0;i<4;i++){
int nx =x+dx[i];
int ny =y+dy[i];
if(nx>=0&&nx<w&&ny>=0&&ny<h&&map[ny][nx]!='.'&&map[ny][nx]==crop){
Point np = new Point(nx,ny);
que.addLast(np);                       
}
}
}
}
}
}System.out.println(ans);
}
}
}

Measured memory_bytes: 25060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int a;
    string s;
    cin >> a >> s;

    if(a >= 3200) {
        cout << s;
    }
    else {
        cout << "red";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = ""
for i in range(1, n + 1):
    if(i % 3 == 0):
        ans += " " + str(i)
        continue
    x = i
    while(x):
        if(x % 10 == 3):
            ans += " " + str(i)
            break
        x //= 10
print(ans)

Measured memory_bytes: 7680
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a,v = inpm()
    b,w = inpm()
    t = inp()
    if w >= v:
        print('NO')
        return
    if abs(a-b)/(v-w) <= t:
        print('YES')
        return
    print('NO')

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10876
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define PB push_back
#define MP make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << std::setprecision(15) << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
const ld PI = 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);AIN(ld,P,N);
  ld dp[N+1][N+1];
  REP(i,N+1){
    dp[i][0] = 0.0L;
  }
  dp[0][0] = 1;
  for(ll i = 0; i <= N; i++){
    for(ll j = 1; j <= N; j++){
      dp[i][j] = (1.0L-P[j-1])*dp[i][j-1];
      if(i != 0){
        dp[i][j] += P[j-1]*dp[i-1][j-1];
      }
    }
  }
  ld sum = 0.0L;
  for(ll i = N/2 + 1; i <= N; i++){
    sum += dp[i][N];
  }
  OUTD(sum);
}

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

long long N, M, K;
vector<long long> SA, SB;

bool check(long long x) {
  if (x > N + M) { return false; }
  long long time = 1LL << 60;
  for (int i = 0; i <= min(x, N); i++) {
    long long tmp = 0;
    tmp += SA.at(i);
    int b = x - i;
    if (b > M) continue;
    if (b >= 0) tmp += SB.at(b);
    time = min(time, tmp);
  }
  return time <= K;
}

int main() {
  cin >> N >> M >> K;
  vector<long long> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < M; i++) cin >> B.at(i);
  SA.resize(N+1);
  SB.resize(M+1);
  for (int i = 0; i < N; i++) SA.at(i+1) = SA.at(i) + A.at(i);
  for (int i = 0; i < M; i++) SB.at(i+1) = SB.at(i) + B.at(i);

  long long left = 0;
  long long right = N + M + 1;
  while (right - left > 1) {
    long long mid = (left + right) / 2;
    if (check(mid)) left = mid;
    else right = mid;
  }
  cout << left << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int64_t ans=1;
  int n=A.size()-K;
  ans+=n/(K-1);
  if(n%(K-1)!=0){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;

int main() {
    FIO;
    ll x; cin >> x;
    FOR(i,-1000,1000) FOR(j,-1000,1000)
        if(1ll*i*i*i*i*i - 1ll*j*j*j*j*j == x)
            return cout << i << ' ' << j << '\n', 0;
    return 0;
}


Measured memory_bytes: 3652
import sys
MOD = 10 ** 9+7
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
for h in range(1, 3500):
    for n in range(1, 3500):
        if (4 * h * n - N * n - N * h) > 0 and (N * h * n) % (4 * h * n - N * n - N * h) == 0:
            print(h, n, (N * h * n)//(4 * h * n - N * n - N * h))
            exit()


Measured memory_bytes: 40556
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N;
string A[40], D[40][40];
int B[40], C[40], mask[40];

int dfs(int v, int seen) {
    if (v == N || seen == (1LL << N) - 1) return 0;
    if (seen >> v & 1) return dfs(v + 1, seen);
    int newSeen = seen | mask[v], newV = v + 1;
    while (newV < N && (newSeen >> newV & 1)) ++newV;
    int res = B[v] + dfs(newV, newSeen);
    if (newSeen == (seen | 1LL << v)) return res;
    newV = v + 1;
    while (newV < N && (seen >> newV & 1)) ++newV;
    res = max(res, dfs(newV, seen | 1LL << v));
    return res;
}

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

    while (cin >> N, N) {
        map<string, int> id;
        REP (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            REP (j, C[i]) cin >> D[i][j];
            id[A[i]] = i;
        }
        REP (i, N) {
            mask[i] = 1LL << i;
            REP (j, C[i]) {
                mask[i] |= 1LL << id[D[i][j]];
            }
        }
        cout << B[0] + dfs(1, mask[0]) << endl;
    }
}


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int dp[2][514][505];
const int L=512;

void add(int &a,int b){
    a=(a+b)%MOD;
}

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

  int N,X;
  cin>>N>>X;

  int t=0;
  rep(i,X+1) dp[t][i][i]=1;
  vector<vector<int>> sum(L,vector<int> (X+1,0));
  for(int i=1;i<N;i++){
      rep(x,L) rep(j,X+1) sum[x][j]=0;
      for(int x=0;x<L;x++){
          for(int j=0;j<=X;j++){
              if(j>0) add(sum[x][j],sum[x][j-1]);
              add(sum[x][j],dp[t][x][j]);
          }
      }

      for(int x=0;x<L;x++){
          for(int j=0;j<=X;j++){
              int pre=x^j;
              add(dp[1-t][x][j],sum[pre][j]);
          }
      }

      for(int x=0;x<L;x++) for(int j=0;j<=X;j++) dp[t][x][j]=0;
      t=1-t;
  }

  int ans=0;
  for(int j=0;j<=X;j++) add(ans,dp[t][X][j]);
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 6056
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,n;cin >> h >> n;
  int sum=0;
  for(int i=0;i<n;i++){
    int a;cin >> a;
    sum+=a;
  }
  if(sum>=h){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b,n,x,i;
    
    for(;;){
        i=0;
        scanf("%d%d",&n,&x);
        if(n+x ==0)break;
        
        for(a=1;a<=n;a++)
            for(b=a+1;b<=n;b++)
                if(b<x-a-b&&x-a-b<=n)i++;
    
    printf("%d\n",i);
    
    }
    return 0;
    
}



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

int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if((c-a)*(b-c)>0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		Arrays.sort(arr);
		int mid=0,s=0,c=0;
		while(mid<=arr.length-1 && c!=k)
		{
			s=s+arr[mid];
			c++;
			mid++;
		}
		System.out.println(s);

	}

}


Measured memory_bytes: 38948
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a),greater<int>());
    auto itr = adjacent_find(ALL(a));
    int dist = distance(a.begin(),itr);
    if(a[dist] == a[dist+3])cout << a[dist]*a[dist] << endl;
    else {
        auto itr2 = adjacent_find(itr+2,a.end());
        int dist2 = distance(a.begin(),itr2);
        cout << a[dist]*a[dist2] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cctype>
#include <set>

using namespace std;

typedef unsigned int ui;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long int ulli;

template<class TypeName>void print(TypeName value) {
	cout << value << " ";
}
template<class TypeName>void println(TypeName value) {
	cout << value << endl;
}


bool isPrime(ui value) {
	if (value < 2) return false;
	if (value == 2) return true;
	for (ui i = 2; i <= sqrt(value); i++) {
		if (value % i == 0) {
			return false;
		}
	}
	return true;
}

ulli reverse(ulli value) {
	ulli temp = 0;
	while (value) {
		temp = temp * 10 + (value % 10);
		value /= 10;
	}
	return temp;
}

int main() {
	

	//97 - 122
	//48 - 57
	//65 - 90
	cout << fixed;
	cout << setprecision(0);

	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cout << fixed;
	cout << setprecision(0);


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

	cin >> input;

	for (ulli i = input; ; i++) {
		if (isPrime(i)) {
			println(i);
			break;
		}
	}


	return 0;
}


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

int calculateIntegerDivisible(int);

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

    int count = 0;
    int ans = 0;
    while(count < N){
        ans++;
        if(calculateIntegerDivisible(ans) == D) count++;
    }
    
    cout << ans << endl;
    return 0;
}

int calculateIntegerDivisible(int x){
    int DivisibleTimesby100 = 0;
    while(x % 100 == 0){
        x /= 100;
        DivisibleTimesby100++;
    }
    return DivisibleTimesby100;
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
#include <cmath>  
#include <string>  
#include <map>  
#include <stack>  
#include <vector>  
#include <set>  
#include <queue>  
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <map>
#include <cctype>
#include <vector>
#include <cstdlib>
using namespace std;
long long mod = (long long)(1e9 + 7);

int main()
{
	long long  n;
	scanf("%lld", &n);

		long long sum = 1;
		for (int i = 2; i <= n; i++)
		{
			sum *= i;
			sum = sum%mod;
		}
		cout << sum%mod << '\n';

	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

ll X;

bool judge(long long x){
    ll sum = x*(x+1)/2;
    if(sum>=X)return true;
    return false;
}

long long BinarySearchLowest(long long low, long long high){
    while(high-low>1){
        long long mid=(low+high)/2;
        if(judge(mid))high = mid;
        else low = mid;
    }
    return high;
}


int main(){
    
    cin>>X;
    
    cout<<BinarySearchLowest(0,1e9+7)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using P=pair<int,int>;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d[3];cin>>n;
    rep(i,3)cin>>d[i];
    vector<P> q;
    rep(i,n){
        string ss;cin>>ss;
        int a,b;
        if(ss=="AB")a=0,b=1;
        else if(ss=="BC")a=1,b=2;
        else a=0,b=2;
        q.push_back({a,b});
    }
    q.push_back({0,1});
    string ans;
    auto add=[&](int a,int b){
        d[a]++;d[b]--;
        ans+='A'+a;
    };
    rep(i,n){
        int a=q[i].first;
        int b=q[i].second;
        if(!d[a]&&!d[b]){
            cout<<"No"<<endl;
            return 0;
        }
        else if(!d[a])add(a,b);
        else if(!d[b])add(b,a);
        else {
            int na=q[i+1].first;
            int nb=q[i+1].second;
            if(a==na||a==nb)add(a,b);
            else add(b,a);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,ans.size())cout<<ans[i]<<endl;
    return 0;
}


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

class Program
{
  static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var A = Console.ReadLine().Split().Select(x => int.Parse(x));
    
    int count = 0;
    
    while(A.All( x => x%2 == 0 ))
    {
      A = A.Select( i => i/2 );
      count++;
    }

    Console.WriteLine(count);
  }
}


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

now = 0
x, y = 0, 0
flag = True

for _ in range(n):
    t, x_target, y_target = map(int, input().split())

    distance = abs(x_target - x) + abs(y_target - y)
    duration = t - now

    if distance > duration:
        flag = False
        break
    
    elif distance % 2 != duration % 2:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;
vector<ll>lunlun;

void go(ll cur, int take){
     if(take > 11)return;
     if(cur)lunlun.push_back(cur);
     for(int i = 0; i<=9; ++i){
        if(cur){
           if(abs(i - (cur % 10)) <= 1)go(cur * 10ll + i, take+1);
        }
        else {
             if(i)go(i, take+1);
        }
     }
}

int main(){
    go(0, 0);
    int k;
    scanf("%d", &k);
    sort(all(lunlun));
    lunlun.resize(unique(all(lunlun))-lunlun.begin());
    printf("%lld\n", lunlun[k-1]);
}

Measured memory_bytes: 10476
from itertools import permutations
X = [int(input()) for i in range(5)]


ans = float('inf')
for perm in permutations(X):
    tmp_ans = 0
    for p in perm:
        tmp_ans += p
        if p % 10 != 0:
            tmp_ans += (10 - p % 10)

    if perm[-1] % 10 != 0:
        tmp_ans -= (10 - perm[-1] % 10)
    ans = min(ans, tmp_ans)

print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int a,b,c,i;
    int ans = 0;
    cin >> a >> b >> c;
    for(i = a;i <= b;i++){
        if (c%i == 0){
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3108
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            int m = int.Parse(In[1]);
            string ans = "No";
            if (n == m)
            {
                ans = "Yes";
            }
            Console.WriteLine(ans);
        }

    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] counter = new int[100];
        int maxCnt = 0;
        
        for (int i = 0; i < counter.length; i++) {
            counter[i] = 0;
        }
        
        while (scanner.hasNext()) {
            int n = scanner.nextInt() - 1;
            counter[n]++;
            if (counter[n] > maxCnt) {
                maxCnt = counter[n];
            } 
        }
        
        for (int i = 0; i < counter.length; i++) {
            if (counter[i] == maxCnt) {
                System.out.println(i+1);
            }
        }
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, m;
	cin >> n >> m;
	vvi g(n);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		if( a==0 || a==n-1 || b==0 || b==n-1 ){
			g[a].push_back(b);
			g[b].push_back(a);
		}
	}
	for(auto v:g[0]){
		for(auto u:g[v]){
			if(u==n-1){
				puts("POSSIBLE");
				return;
			}
		}
	}	
	puts("IMPOSSIBLE");  
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <map>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	map<string, bool> T; // キーになる文字列とそれが入ってるか否かのbool値を入れる
	int n;
	char str[10], com[13];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> com >> str; // コマンド(insertかfind)と文字列を入力
		if (com[0] == 'i') T[string(str)] = true;
		else {
			if (T[string(str)]) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 47328
#include<iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int count = 0;
	for (int i = 1;i < 10;i++) {
		if (N % i == 0 && N / i <= 9) {
			cout << "Yes" << endl;
			count++;
			break;
		}
	}
	if (count == 0) {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int k = 0;
    int num = n;
    while(num > 0){
        num /= 10;
        k++;
    }
    if (k == 1) {
        cout << n - 0 << endl;
    }else if (k == 2) {
        cout << 9 << endl;
    }else if (k == 3) {
        cout << n - 99 + 9 << endl;
    }else if (k == 4) {
        cout << 900 + 9 << endl;
    }else if (k == 5) {
        cout << n - 9999 + 900 + 9 << endl;
    }else{
        cout << 90000 + 900 + 9 << endl;
    }
    
    
    
    
    
    
}

Measured memory_bytes: 256
using System;

namespace Contest148
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] strs = Console.ReadLine().Split(' ');

			int[] nums = new int[strs.Length];
			for(int i = 0; i < strs.Length; i++)
			{
				nums[i] = int.Parse(strs[i]);
			}

			int sum = 0;
			string message = "";

			foreach(int num in nums)
			{
				sum += num;
			}

			if(sum >= 22)
			{
				message = "bust";
			}
			else
			{
				message = "win";
			}

			Console.WriteLine(message);
		}
	}
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
	int x;
	cin>>x;
	if(x<=1999 && x>=1800){
		cout<<1<<endl;
	}
	else if(x<=1799 && x>=1600){
		cout<<2<<endl;
	} 
	else if(x<=1599 && x>=1400){
		cout<<3<<endl;
	}
	else if(x<=1399 && x>=1200){
		cout<<4<<endl;
	}
	else if(x<=1199 && x>=1000){
		cout<<5<<endl;
	}
	else if(x<=999 && x>=800){
		cout<<6<<endl;
	}
	else if(x<=799 && x>=600){
		cout<<7<<endl;
	}
	else if(x<=599 && x>=400){
		cout<<8<<endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>

int main(void){
    int h,a,n;
    
    scanf("%d%d",&h, &a);

    if(h%a == 0){
        n=h/a;
        printf("%d",n);
    }

    else if(h%a!=0){
        n=h/a;
        printf("%d",n+1);
    }

    return 0;

}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	
	vector<double> p(k);
	auto get_p = [&](ll i) { return i < k ? p[i] : 1.0; };

	FORD(i,1,k) p[i] = get_p(2*i)/2;
	
	double res = 0;
	FOR(i,1,n+1) res += get_p(i);
	res /= n;
	
	cout << fixed << setprecision(20) << res << endl;



}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string s,t;
int n,m;
vector<int> S[26];

void solve(){
    cin >> s >> t;
    n=s.length();
    m=t.length();
    int ord_a ='a';
    rep(i,n){
        S[s[i]-ord_a].push_back(i);
    }
    ll ans,re=0;
    int k=t[0]-ord_a;
    if (S[k].empty()) {
        cout << "-1" << endl;
        return;
    }
    ans=S[k][0];
    //cout << ans << endl;
    Rep(i,1,m){
        int k=t[i]-ord_a;
        //cout << (char)(k+ord_a) << endl;
        if (S[k].empty()) {
            cout << "-1" << endl;
            return;
        }
        if (S[k].back()<=ans%n){
            re+=1;
            ans=re*n+S[k][0];
        }
        else{
            ans=re*n+(*upper_bound(S[k].begin(),S[k].end(),ans%n));
        }
        //cout << ans << endl;
    }

    cout << ans+1 << endl;
}

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

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

using namespace std;

template <typename T>
class Mylist
{
public:
	vector<T> data;
	int R;
	int C;
	int ndim;

	//コンストラクタ
	Mylist() {}


	Mylist(int size, T init) :data(size, init), R(1), C(size) {}

	Mylist(int R_, int C_, T init) :data(R_*C_, init), R(R_), C(C_) {}

	T &at(int index)
	{
		if (index >= 0) {
			return *(data.begin() + index);
		}
		else {
			return *(data.end() + index);
		}
	}

	T &at(int ri, int ci)
	{
		return *(data.begin() + ci + ri * C);
		// todo 逆アクセス
	}

	Mylist slice(int rs, int cs, int re, int ce)
	{
		if (rs < 0) rs = R + rs;
		if (re < 0) re = R + re;
		if (cs < 0) cs = C + cs;
		if (ce < 0) ce = C + ce;

		Mylist dist(re - rs + 1, ce - cs + 1, 0);
		for (int ri = 0; ri < dist.R; ri++) {
			for (int ci = 0; ci < dist.C; ci++) {
				dist.at(ri, ci) = this->at(rs + ri, cs + ci);
			}
		}
		return dist;
	}

	bool is_alone(int ri, int ci) 
	{
		if (ri == 0 || ri == R - 1) return false;
		if (ci == 0 || ri == C - 1) return false;
		if (this->at(ri, ci) == '.') return false;

		//if (this->at(ri - 1, ci -1 ) == '#') return false;
		if (this->at(ri - 1, ci) == '#') return false;
		//if (this->at(ri - 1, ci + 1) == '#') return false;
		if (this->at(ri, ci - 1) == '#') return false;
		if (this->at(ri, ci + 1) == '#') return false;
		//if (this->at(ri + 1, ci - 1) == '#') return false;
		if (this->at(ri + 1, ci) == '#') return false;
		//if (this->at(ri + 1, ci + 1) == '#') return false;

		return true;

	}

};



class Puzzle
{
public:
	int R, C;
	Mylist<char> table,goal;

	void input()
	{
		cin >> R >>C;
		table = Mylist<char>(R+2, C+2, '.');
		goal = table;

		char c;
		for (int ri = 0; ri < R; ri++) {
			for (int ci = 0; ci < C; ci++) {
				cin >> c;
				goal.at(ri+1,ci+1) = c;
			}
		}
	}

	void play()
	{
		for (int ri = 0; ri < R; ri++) {
			for (int ci = 0; ci < C; ci++) {
				if (goal.is_alone(ri, ci) == true) {
					cout << "No";
					return;
				}
			}
		}

		cout << "Yes";
	}

};


int main()
{

	Puzzle puz;

	puz.input();
	puz.play();

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll n;
	cin >> n;
	Array a(3*n, 0);
	REP(i, 3*n) cin >> a[i];

	Array sum_l(n + 1, 0);

	priority_queue<ll, Array, greater<ll>> que;
	REP(i, n) {
		que.push(a[i]);
		sum_l[0] += a[i];
	}
	REP(i, n) {
		que.push(a[i + n]);
		ll min=que.top();
		sum_l[i+1] =sum_l[i]+ (a[i + n] - min);
		que.pop();
	}

	priority_queue<ll> que2;
	Array sum_r(n + 1, 0);
	REP(i, n) {
		que2.push(a[i + 2 * n]);
		sum_r[n] += a[i + 2 * n];
	}
	for (int i = 2 * n - 1; i >= n; i--) {
		que2.push(a[i]);
		ll max = que2.top();
		que2.pop();
		sum_r[i - n] = sum_r[i - n + 1] + (a[i] - max);
	}
	
	ll ans = -INF;
	REP(i, n + 1) {
		if (ans < sum_l[i] - sum_r[i]) ans = sum_l[i] - sum_r[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6516
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  	int n;
  	while (cin >> n && n){
	   int g[n][n], ret = 0;
	   int b[n], c[n];
	   for (int i = 0; i < n; i++){
		 for (int j = 0; j < n; j++){
			  cin >> g[i][j]; 
			}  
		 }
	   for (int i = 0; i < n; i++){
		  b[i] = INF;
		  c[i] = 0;
		  for (int j = 0; j < n; j++){
			   b[i] = min(b[i], g[i][j]);
			   c[i] = max(c[i], g[j][i]);  
			}   
		}
	   for (int i = 0; i < n; i++){
		 for (int j = 0; j < n; j++){
			   if (b[i] == c[j]) ret = b[i]; 
			}  
		 }
	   cout << ret << endl;
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int a[100005];

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

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

    if(a[N-1] < K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int g = a[0];
    for(int i=1;i<N;i++){
        g = __gcd(g, a[i]);
    }
    if(g == 1 || K % g == 0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int b = sc.nextInt();

		int bLen = String.valueOf(b).length();

		int c = a*(int)Math.pow(10, bLen) + b;

		boolean ans = false;

		for(int i=1;;i++) {

			if(i*i>c) break;

			if(i*i==c) {

				ans = true;

				break;
			}
		}

		if(ans) System.out.println("Yes");

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

}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(void){
  int A, B, X;
  cin >> A >> B >> X;

  if(A > X) //指定数Xより，既に猫が多い
    cout << "NO" << endl;
  else
    if(A+B >= X) //現在の猫の数Aに不明数Bを足すと指定数X以上
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
      
  return 0;
}


Measured memory_bytes: 256