akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<climits>
#include<cstdlib>
using namespace std;
int d[1111][1111];
char input[1111][1111];
bool visited[1111][1111];
int H,W,N,S_x,S_y,answer=0;
const int dirx[]={0,-1,0,1};
const int diry[]={1,0,-1,0};
int now='1';
int D[11];
queue<int> q;
void BFS();
void clean();
int main(){
	int i,j;
	char ch; 
	cin>>H>>W>>N;
	for(i=0;i<H*W;i++){
		cin>>ch;
		input[i%W][i/W]=ch;
		d[i%W][i/W]=0;
		if(ch=='S'){
			S_x=i%W;S_y=i/W;
		}
	}
	while(now<=N+48){
		BFS();
		now++;
	}
	for(i=1;i<=N;i++){
		answer+=D[i];}
	cout<<answer<<endl;
}
void BFS(){
	int x,y,k,mx,my;
	q.push(S_x);
	q.push(S_y);
	visited[S_x][S_y]=true;
	while(!q.empty()){
		x=q.front();q.pop();
		y=q.front();q.pop();
		for(k=0;k<4;k++){
			mx=x+dirx[k];
			my=y+diry[k];
			if(mx<W&&mx>=0&&my<H&&my>=0){ 
			if(input[mx][my]!='X'&&!visited[mx][my]){
				q.push(mx);
				q.push(my);
				d[mx][my]=d[x][y]+1;
				if(input[mx][my]==(char)now){S_x=mx;S_y=my;D[now-48]=d[mx][my];}
				visited[mx][my]=true;
			}}
		}
	}
	clean();
}
void clean(){
	int i,j;
	for(i=0;i<W;i++)
		for(j=0;j<H;j++){
			visited[i][j]=false;
			d[i][j]=0;}
}

Measured memory_bytes: 7848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	long long int T1, T2;
	long long int A1, A2;
	long long int B1, B2;
	cin >> T1 >> T2;
	cin >> A1 >> A2;
	cin >> B1 >> B2;

	// 
	long long int T1diff = (A1 - B1) * T1;
	long long int T2diff = (A2 - B2) * T2;

	// T1diffを正にする
	if(T1diff < 0) {
		T1diff *= -1;
		T2diff *= -1;
	}

	if(T1diff + T2diff == 0) {
		cout << "infinity";
		return 0;

	} else if(T1diff + T2diff > 0) {
		// 追いつけない
		cout << 0;
		return 0;

	}

	long long int times1 = T1diff / (-1 * (T2diff + T1diff));
	long long int times2 = (-T2diff) / (-1 * (T2diff + T1diff));
	if( (-T2diff) % (-1 * (T2diff + T1diff)) == 0 ) {
		times2 = (times2 == 0) ? times2 : times2-1;
	}

	cout << (times1 + times2);
	return 0;
}



Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

minutes_mod = min(l)

# for i in l:
#     if i < minutes_mod:
#         new_l = [j % i for j in l]
#     else:
#         new_l = [j % minutes_mod for j in l]
#     new_l_set = list(set(new_l))
#     if 0 in new_l_set:
#         new_l_set.remove(0)
#     if len(new_l_set) != 0:
#         minutes_mod_list.append(min(new_l_set))
#         minutes_mod = min(new_l_set)

new_l = list(set([i % minutes_mod for i in l]))
new_l.append(minutes_mod)
if 0 in new_l:
    new_l.remove(0)

another_list = list(set(new_l))
minutes = min(another_list)

while 1 :
    first_minutes = minutes
    another_list = list(set([i % minutes for i in another_list]))
    another_list.append(minutes)
    if 0 in another_list:
        another_list.remove(0)

    minutes = min(another_list)

    if first_minutes == minutes:
        break
print(minutes)


Measured memory_bytes: 14252
#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 mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, x; cin >> n >> x;
	vl a(n);
	FOR(i,0,n) cin >> a[i];

	ll res = oo;
	vl dp(n,oo);
	FOR(k,0,n) {
		ll cur = 0;
		FOR(i,0,n) {
			dp[i] = min(dp[i],a[(i+n-k) % n]);
			cur += dp[i];
		}
		res = min(res,cur + k*x);
	}
	cout << res << endl;
}


Measured memory_bytes: 384
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
#define N 200005
using namespace std;
int n,l,t;
long long Rank;
int x[N],w[N],e[N];
int main()
{
	scanf("%d%d%d",&n,&l,&t);
	Rank=0;
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&x[i],&w[i]);
		e[i]=x[i]+((w[i]==1)?1:-1)*t;
		e[i]%=l;
		e[i]=(e[i]+l)%l;
		if (w[i]==1)
			Rank+=(x[i]+t)/l; else
			Rank-=(l-x[i]-1+t)/l;
	}
	Rank=(Rank%n+n)%n;
	sort(e,e+n);
	for (int i=Rank;i<n;i++)
		printf("%d\n",e[i]);
	for (int i=0;i<Rank;i++)
		printf("%d\n",e[i]);
	return 0;
}

Measured memory_bytes: 4932
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
  vl x(N);
  iota(ALL(x), 1LL);
  ll a = -1,b = -1;
  ll cnt = 0;
  do{
    cnt++;
    bool chk = true;
    dump(P,Q,x);
    rep(i,N) chk &= (P[i]==x[i]);
    if(chk) a = cnt;
    
    chk = true;
    rep(i,N) chk &= (Q[i]==x[i]);
    if(chk) b = cnt;

  }while(next_permutation(ALL(x)));
  dump(a,b);
  cout << abs(b-a) << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
  std::vector<long long> Q(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&Q[i]);
  }
  solve(N, std::move(P), std::move(Q));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define push_back pb
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int H,W;
char A[1010][1010];
int D[1010][1010] = {};
int ans = 0;

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

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            cin >> A[i][j];
        }
    }
    
    
    for(int i = 0; i < 1002; i++){
        D[0][i] = D[i][0] = D[H+1][i] = D[i][W+1] = 3000;
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(A[i][j] == '#'){  
                D[i][j] = 0;
            }
            else{
                D[i][j] = min(D[i-1][j],D[i][j-1]) +1;
            }
        }
    }
    for(int i = H; i > 0; i--){
        for(int j = W; j > 0;j--){
            D[i][j] = min(D[i][j], min(D[i+1][j], D[i][j+1]) + 1);
        }
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            ans = max(ans,D[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int>str;
    int n,cnt=0;
    cin>>n;
    while(n--)
    {
        string a;
        cin>>a;

        if(str[a]==0)
        {
            cnt++;
            str[a]++;
        }



    }
    cout<<cnt;
}


Measured memory_bytes: 19112
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Drink> d = new ArrayList<Drink>();
        for(int i = 0;i < n;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            Drink t = new Drink(a,b);
            d.add(t);
        }
        Collections.sort(d,(a, b)->Integer.compare(a.money,b.money));
        int count = 0;
        BigInteger ans = BigInteger.ZERO;
        while(m > 0){
            Drink drink = d.get(count);
            count++;
            ans = ans.add(drink.sum);
            m -=drink.number;
            BigInteger tmp = BigInteger.valueOf(m).multiply(BigInteger.valueOf(drink.money));
            if(m < 0)ans = ans.add(tmp);
        }
        System.out.println(ans);
    }
}
class Drink{
    public int money;
    public int number;
    public BigInteger sum;
    Drink(int a,int b){
        this.money = a;
        this.number = b;
        this.sum = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
    }
}

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

const int MAX = 1e5+5;

const int MOD = 1e9 + 7;

vector<int>vec[20];
int  n ,d;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int l , r;
    
    cin>>l>>r;
    
    vector<ll>rem;
    for(int i = l ,cnt = 1  ; cnt <=5000 && i<=r ; i++ , cnt++  ) {
        
        rem.push_back(i%2019);
    }
    
    ll ans = 1e9;
    for(int i =0 ; i < rem.size() ; i++ ) {
        for(int j = i +1 ; j < rem.size() ; j++ ) {
            ans = min(ans , (rem[i]*rem[j])%2019 );
        }
    }
    
    
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

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

    int n;
    cin >> n;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        long long a;
        cin >> a;
        if((i == 0 && a != 0) || (i != 0 && a == 0)){
            cout << 0 << endl;
            return 0;
        }
        A[a]++;
    }

    long long ans = 1;
    for(int i = 2; i < n; i++){
        for(int j = 0; j < A[i]; j++){
            ans = ans * A[i - 1] % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

stack<char> st;
string s;
int l;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    l=s.size();
    for(int i=0;i<l;++i)
    {
        if(st.empty()||!(st.top()=='S'&&s[i]=='T')) st.push(s[i]);
        else st.pop();
    }
    cout<<st.size();
    return 0;
}

Measured memory_bytes: 720
N = int(input())

cnt = 0
if N < 10: # 10^1
  cnt = N
elif N < 100: # 10^2
  cnt = 9
elif N < 1000: # 10^3
  cnt = 9 + N - 100 + 1 
elif N < 10000: # 10^4
  cnt = 9 + 900
elif N < 100000: #10^5
  cnt = 9 + 900 + N - 10000 + 1
else :
  cnt = 9 + 900 + 90000

print(cnt)

Measured memory_bytes: 3060
import sys

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


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    cnt = [0] * 3
    ans = 1

    for x in a:
        p = cnt.count(x)
        if p == 0:
            return print(0)
        ans *= p
        ans %= MOD
        cnt[cnt.index(x)] += 1

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> graph(n);
  for (int i = 0; i < m; ++i) {
    int src, dest;
    cin >> src >> dest;
    src--;
    dest--;
    graph[src].push_back(dest);
  }

  int s, t;
  cin >> s >> t;
  s--;
  t--;

  int ans = -1;
  vector<vector<bool>> visited(n, vector<bool>(3, false));
  queue<pair<int, int>> q;
  q.push({s, 0});
  while (!q.empty()) {
    int node_idx = q.front().first, dist = q.front().second;
    q.pop();

    if (visited[node_idx][dist % 3]) {
      continue;
    }

    visited[node_idx][dist % 3] = true;

    if (dist % 3 == 0 && node_idx == t) {
      ans = dist / 3;
      break;
    }

    for (auto &neighbor : graph[node_idx]) {
      q.push({neighbor, dist + 1});
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 12800
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

cnt = [[-1]*W for _ in range(H)]

que = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            que.append((h, w))
            cnt[h][w] = 0

ans = 0
while que:
    h, w = que.popleft()
    ans = cnt[h][w]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        next_h = h + dy
        next_w = w + dx
        if next_h < 0 or H <= next_h or next_w < 0 or W <= next_w:
            continue
        if cnt[next_h][next_w] == -1:
            cnt[next_h][next_w] = ans+1
            que.append((next_h, next_w))

print(int(ans))

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

const int mod = 1e9+7;

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

    int n, x;
    cin >> n >> x;

    if (x == 1 || 2*n-1 <= x) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        int s = (2*n-1)/2;
        if (n > x) s = 2*n-1-(n-x);
        else s = x - n;
        for (int i = s; i < 2*n-1; ++i) {
            cout << i+1 << endl;
        }
        rep(i, s) { cout << i+1 << endl; }
    }

    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxx=1e6+7;
char ss[maxx];
map<int,int> mp;
int main()
{
    std::ios::sync_with_stdio(false);
    cin >>ss;
    int len=strlen(ss);
    int a,b;
    for(int i=1;i<len;i++)
    {
        if(ss[i]=='L'&&ss[i-1]=='R')
        {
            a=0,b=0;
            for(int j=i-1;j>=0;j--)
            {
                if(ss[j]=='R') a++;
                else break;
            }
            for(int j=i;j<len;j++)
            {
                if(ss[j]=='L') b++;
                else break;
            }
            if((a+b)%2==0) mp[i]=mp[i-1]=(a+b)/2;
            else if(a>b&&(a-b)%2==1)
            {
                if(b%2==0) mp[i]=(a+b)/2,mp[i-1]=mp[i]+1;
                else mp[i-1]=(a+b)/2,mp[i]=mp[i-1]+1;
            }
            else
            {
                if(a%2==0) mp[i-1]=(a+b)/2,mp[i]=mp[i-1]+1;
                else mp[i]=(a+b)/2,mp[i-1]=mp[i]+1;
            }
        }
    }
    for(int i=0;i<len;i++)
    {
        if(mp[i]) cout <<mp[i]<<" ";
        else cout <<0<<" ";
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int n;
    while (true) {
        cin >> n;
        if (!n) { break; }

        vector<int> v(n);

        for (int i = 0; i < n; i++) { cin >> v[i]; }
        sort(v.begin(), v.end());

        int sum = 0;
        for (int i = 1; i < n-1; i++) {
            sum += v[i];
        }

        cout << sum / (n-2) << endl;
    }
    return 0;
}


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

int main(){
  int N,C,K; cin >> N >> C >> K;
  int bussum=0;
  int buslimit=0;
  int busin=0;
  int itime[100000];
  for(int i=0; i<N; i++){
    cin >> itime[i];
  }
  sort(itime,itime+N);
  for(int i=0; i<N; i++){
    if(buslimit<itime[i]||busin==C){
      busin=0;
      bussum++;
      buslimit=itime[i]+K;
    }
    busin++;
  }
  cout << bussum << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  if(s == "ABC"){
    cout << "ARC\n";
  }else{
    cout << "ABC\n";
  }
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
#include<map>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

struct  threeset
{
	int num;
	int x;
	int y;
};


int main() {

	int h, w, d;
	cin >> h >> w >> d;

	threeset a;
	vector<threeset> v;

	for(a.x=0;a.x<h;a.x++)
		for (a.y= 0; a.y < w; a.y++)
		{
			cin >> a.num;
			v.push_back(a);
		}
	sort(v.begin(), v.end(), [](const threeset& a, const threeset& b) {return a.num < b.num; });

	int dp[90001];
	for (int i = 0; i <= d; i++)
		dp[i] = 0;
	for (int i = d + 1; i <= h * w; i++)
	{
		dp[i] = dp[i - d] + abs(v[i - 1].x - v[i - 1 - d].x)+abs(v[i - 1].y - v[i - 1 - d].y);
	}

	int q,aa,aaa;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> aa >> aaa;
		cout << dp[aaa] - dp[aa] << endl;
	}



	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> list(3*N);
  long long ans=0 ;
  for (int i=0; i<3*N; i++){
    cin >> list.at(i);
  }
  sort(list.begin(),list.end(),greater<int>());
  for (int j=0; j<N; j++){
    ans += list.at(2*j+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut count = vec![0; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        count[a] += 1;
        count[b] += 1;
    }

    for &c in &count {
        if c % 2 == 1 {
            println!("NO");
            return;
        }
    }
    println!("YES");
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>

 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 1e5+5;
ll n = 0, a[MAXN], BIT[MAXN];

ll largest(ll a, ll b){
	return (a<b)?b:a;
}
int smallest(ll a, ll b){
	if(a < b)return a;
	return b;
}

int main() {
	int n = 0;
	cin >> n;
	float sum;
	vector<float> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	sum = 1/a[0];
	for(int i = 1; i < n; ++i){
		sum+=(1/a[i]);
	}
	cout << setprecision(10) << 1/sum << endl;


    return 0;
}	

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

int main() {
  string w;
  cin >> w;
  int W=w.size();
  vector<char> y(W);
  for(int i=0;i<W;i++){y[i]=w[i];}
  sort(y.begin(),y.end());
  string ans="Yes";
  if(W%2==1){cout << "No" << endl;}
  else{
    for(int i=0;i<W;i+=2){
      if(y[i]!=y[i+1]){ans="No";}
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

score = [[] for _ in range(n)]
for i in range(1, n + 1):
    x = [i]
    s = 0
    while True:
        x.append(p[x[-1] - 1])
        s += c[x[-1] - 1]
        score[i - 1].append(s)
        if x[-1] == i:
            break

ans = -1e20
for i in range(n):
    l = len(score[i])
    for j in range(min(k, l)):
        tmp = score[i][j]
        if 0 < score[i][-1]:
            tmp += ((k - j - 1) // l) * score[i][-1]
        ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 284056
//****** @author mdazmat9 **********
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
const ll size=1e6;
ll dp[size];
void solve() {
    ll x;cin>>x;

    memset(dp,1, sizeof(dp));
    dp[0]=0;dp[1]=0;
    for(ll i=2;i*i<size;i++){
        if(dp[i]){
            for(ll j=i+i;j<size;j+=i)dp[j]=0;
        }
    }
    for(ll i=x;i<size;i++){
        if(dp[i]){
            cout<<i<<endl;
            return;
        }
    }



}
int main()
{
    IOS;
    ll test=1;
   // cin>>test;
    while(test--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 8064
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n;
int a[100];

int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int ans=0;
	rep(i,n-1) ans+=a[i];
	ans+=a[n-1]/2;
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

sm1=[0]*N
if S[0]=='#':
    sm1[0]=1
for i in range(1, N):
    sm1[i]=sm1[i-1]
    if S[i]=='#':
        sm1[i]+=1
sm2=[0]*N
if S[-1]=='.':
    sm2[-1]=1
for i in range(N-2, -1, -1):
    sm2[i]=sm2[i+1]
    if S[i]=='.':
        sm2[i]+=1

ans=INF
for i in range(1, N):
    ans=min(ans, sm1[i-1]+sm2[i])
print(min(ans, S.count('#'), S.count('.')))


Measured memory_bytes: 12840
from bisect import bisect_right, bisect_left

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, K = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(N + 100)
A = list(map(int, input().split()))
A.sort()

ans = 0
for i, a in enumerate(A):
    mi = min(i, bisect_right(A, a) - 1)
    mx = N - max(i + 1, bisect_left(A, a))

    ans = (ans + (comb.ncr(mi, K - 1) - comb.ncr(mx, K - 1)) * a) % MOD

print(ans)

Measured memory_bytes: 26716
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>A(3);
  for(int i=0;i<3;i++)cin>>A[i];
  count(A.begin(),A.end(),5)==2&&count(A.begin(),A.end(),7)==1?puts("YES"):puts("NO");
}

Measured memory_bytes: 3536
(function main(){
  let lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  let [n, k] = lines.shift().split(' ').map(Number);
  let w = lines.map(Number);

  const canAllStack = (p) => {
    let cnt = 0, sum = 0;
    for (let i = 0; i < k; i++) {
      for (sum = 0; sum + w[cnt] <= p;) {
        sum += w[cnt++]
        if (cnt === n) return n;
      }
    }
    return cnt;
  };

  let mid, left = 0, right = 1e9;
  while (right - left > 1) {
    mid = (right + left) / 2;
    if (canAllStack(mid) >= n) right = mid;
    else left = mid;
  }
  console.log(Math.floor(right));
})();


Measured memory_bytes: 29216
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  if(n==3||n==5||n==7)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;


int main()
{

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    
    int N;
    cin>>N;
    
    vector<long long> R(N);
    for(int i=0;i<N;i++){
        cin>>R[i];
    }
    
    
    long long maxv=-1000000000;
    long long minv=R[0];
    
    for(int i=1;i<N;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    
    
    cout<<maxv<<endl;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    ll first = n;
    vector<ll> d(k);
    rep(i, k) cin >> d[i];
    for (size_t i = n; i < (ll)pow(10, (to_string(n)).size() + 2); i++)
    {
        ll tmp = i;
        bool isok = true;
        while (tmp) {
            if (count(all(d), tmp % 10)) {
                isok = false;
                break;
            }
            tmp /= 10;
        }
        if (isok) {
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN2(n,m);
  OUT((n-1)*(m-1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  vector<int> a(3);
  rep(i,3) cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[0]+a[1]<<endl;
return 0;
}

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



int main(){
  ll n;
  cin >> n;
  string ans;

  while(n > 0){
    n --;
    ans += ('a' + n % 26);
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}



Measured memory_bytes: 3608
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        ArrayList<ArrayList<Integer>> g = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            g.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;
            g.get(a).add(b);
            g.get(b).add(a);
        }
        boolean[] used = new boolean[n];
        int[] ans = new int[n];
        used[0] = true;
        ArrayList<Integer> q = new ArrayList<>();
        q.add(0);
        int index = 0;
        while (index < q.size()) {
            int v = q.get(index);
            index++;
            for (int i = 0; i < g.get(v).size(); i++) {
                if (!used[g.get(v).get(i)]) {
                    ans[g.get(v).get(i)] = v + 1;
                    q.add(g.get(v).get(i));
                    used[g.get(v).get(i)] = true;
                }
            }
        }
        for (int i = 1; i < n; i++) {
            if (ans[i] == 0) {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
        for (int i = 1; i < n; i++) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 67952
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void add_edge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

i32 calc (i32 v, graph *g, i32 *dp) {
  if (dp[v] >= 0) return dp[v];
  dp[v] = 0;
  for (i32 p = g->start[v]; p != -1; p = g->edge[p].next) {
    i32 u = g->edge[p].vertex;
    i32 x = calc (u, g, dp) + 1;
    dp[v] = MAX (dp[v], x);
  }
  return dp[v];
}

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  graph *g = new_graph (n + 1);
  while (m--) {
    i32 x, y;
    scanf ("%" SCNi32 "%" SCNi32, &x, &y);
    add_edge (g, x, y);
  }
  for (i32 i = 1; i <= n; ++i) {
    add_edge (g, 0, i);
  }
  i32 *dp = ALLOC (n + 1, i32);
  for (i32 i = 0; i <=n; ++i) {
    dp[i] = -1;
  }
  i32 ans = calc (0, g, dp) - 1;
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 4096
# coding=utf-8

A = []
n, m = map(int, raw_input().split())
for _ in xrange(n):
    A.append(map(int, raw_input().split()))
# print A

b = []
for _ in xrange(m):
    b.append(input())
# print b

Ab = [sum([A[i][j] * b[j] for j in xrange(m)]) for i in xrange(n)]
# print Ab
for x in Ab:
    print x

Measured memory_bytes: 4564
from collections import deque
N, M = map(int, input().split())
E1 = [[] for _ in range(N)]
E2 = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E1[a-1].append((b-1, -c))
    E2[b-1].append((a-1, -c))

def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c, w in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

def bellman_ford(n, E, s=0):
    D = [1<<100] * n
    D[s] = 0
    f = 1
    while f:
        f = 0
        for i in range(n):
            if not B[i]: continue
            for j, c in E[i]:
                if not B[j]: continue
                if D[i] < 1<<100 and D[j] > D[i] + c:
                    D[j] = D[i] + c
                    f = 1
    return D

def bellman_ford_check(n, E, s=0):
    D = [0] * n
    for k in range(n):
        for i in range(n):
            if not B[i]: continue
            for j, c in E[i]:
                if not B[j]: continue
                if D[j] > D[i] + c:
                    D[j] = D[i] + c
                    if k == n-1: return 1
    return 0

B1 = BFS(N, E1, 0)
B2 = BFS(N, E2, N-1)
B = [0 if B1[i] < 0 or B2[i] < 0 else 1 for i in range(N)]

if bellman_ford_check(N, E1):
    print("inf")
else:
    D = bellman_ford(N, E1)
    print(-D[-1])


Measured memory_bytes: 50136
#include<iostream>
#include<cstdlib>
#include<string>

using namespace std;

class Dice{
	public:
		int label[6];
		void Command(char hougaku);
};

void Dice::Command(char hougaku){
	int temp[6];
	for(int i = 0; i < 6; i++){
		temp[i] = label[i];
	}
	if(hougaku == 'E'){
		label[0] = temp[3];
		label[2] = temp[0];
		label[3] = temp[5];
		label[5] = temp[2];
	}
	else if(hougaku == 'W'){
		label[0] = temp[2];
		label[2] = temp[5];
		label[3] = temp[0];
		label[5] = temp[3];
	}
	else if(hougaku == 'N'){
		label[0] = temp[1];
		label[1] = temp[5];
		label[4] = temp[0];
		label[5] = temp[4];
	}
	else if(hougaku == 'S'){
		label[0] = temp[4];
		label[1] = temp[0];
		label[4] = temp[5];
		label[5] = temp[1];
	}
}

int main(){
	Dice dice;
	for(int i = 0; i < 6; i++){
		cin >> dice.label[i];
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int a, b;
		cin >> a >> b;
		if(dice.label[0] == a && dice.label[1] == b){
			cout << dice.label[2] << endl;
			continue;
		}
		
		while(1){
			double x = (double)rand() / RAND_MAX;
			if(x < 0.25){
				dice.Command('E');
			}
			else if(x < 0.50){
				dice.Command('W');
			}
			else if(x < 0.75){
				dice.Command('N');
			}
			else{
				dice.Command('S');
			}
			if(dice.label[0] == a && dice.label[1] == b){
				cout << dice.label[2] << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1164
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    char c;cin>>c;
    if(c>='A' and c<='Z')
        cout<<'A'<<endl;
    else
        cout<<'a'<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    cin.tie(NULL);cout.tie(NULL);
//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}
/*
10 4
1 2
1 3
1 4
2 5
2 6
5 7
3 8
8 10
4 9

5 1
1 2
2 3
3 4
4 5
*/


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0]+a[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    vector<pair<ll, ll>> cnt(n, {0, 0}), a;
    rep(i, n)cin >> s[i];
    ll cnt1 = 0, cnt2 = 0;
    rep(i, n){
        rep(j, s[i].size()){
            if(s[i][j] == '(')cnt[i].first++;
            else{
                if(cnt[i].first)cnt[i].first--;
                else cnt[i].second++;
            }
        }
    }
    ll now = 0;
    rep(i, n){
        if(!cnt[i].second)now += cnt[i].first;
    }
    rep(i, n){
        if(cnt[i].first && cnt[i].second){
            a.push_back({cnt[i].second, cnt[i].first-cnt[i].second});
        }
    }
    sort(all(a));
    ll j = 0, ma = 0;
    priority_queue<pair<ll, ll>> que;
    rep(i, a.size()){
        while(j < a.size() && a[j].first <= now){
            que.push({a[j].second, j}); j++;
        }
        if(que.empty()){cout << "No" << endl; return 0;}
        if(a[que.top().second].first > now){cout << "No" << endl; return 0;}
        now += que.top().first; que.pop();
    }
    rep(i, n){
        if(!cnt[i].first)now -= cnt[i].second;
    }
    cout << (now == 0 ? "Yes" : "No") << endl;
}


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

bool  cmp(char  a, char  b)
{
	return  a>b;
}

int  main()
{
    string  s,t;
    
    cin>>s>>t;
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),cmp);
    
    if(s<t)
       cout<<"Yes"<<endl;
    else
       cout<<"No"<<endl;
	   
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{

	long long int z,s,d,a,f,g,h,i,j,k;
	scanf("%lld",&a);
	while(a!=0){
		h=1;
		s=0;
		i=-1;
		z=0;
		d=a;
		while(1){
			i++;
			s=d%8;
			d=d/8;
		//	printf("%lld\n",s);
			if(s==4)
				s+=1;
			else if(s>4)
				s+=2;
			s*=h;
			z+=s;
			h*=10;
			if(d<8)
				break;
		}
		if(d==4)
			d+=1;
		else if(d>4)
			d+=2;
		d*=h;
		z+=d;
		printf("%lld\n",z);
		scanf("%lld",&a);
	}
	return 0;
}

Measured memory_bytes: 2568
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
 
struct Node{
    int key;
    Node *prev,*next;
};
 
Node *nil;
void init(){
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
 
void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
 
Node* listSearch(int key){
    Node *cur=nil->next;
    while(cur!=nil && cur->key!=key){
        cur=cur->next;
    }
    return cur;
}
 
void deleteNode(Node *t){
    if(t==nil)return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
 
void deleteFirst(){
    deleteNode(nil->next);
}
 
void deleteLast(){
    deleteNode(nil->prev);
}
 
void deleteKey(int key){
    deleteNode(listSearch(key));
}
 
int n;
int main(void){
    init();
    char com[21];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int key;
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }
        else if(com[0]=='d'){
            if(strlen(com)>6){
                if(com[6]=='F')deleteFirst();
                if(com[6]=='L')deleteLast();
            }else{
                scanf("%d",&key);
                deleteKey(key);
            }
        }
    }
    Node *now=nil->next;
    while(now!=nil){
        printf("%d%c",now->key,now->next==nil?'\n':' ');
        now=now->next;
    }
    return 0;
}



Measured memory_bytes: 33864
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int32_t main() {
	int a,b,ans=0,i;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{
		string s=to_string(i);
		if(s[0]==s[4] && s[1]==s[3])
			ans++;
	}
	cout<<ans;
}
						

Measured memory_bytes: 256
#include<stdio.h>
int main (){
 int a,b;
 scanf("%d %d\n",&a,&b);
 char str[20];
 scanf("%s",str);
 int k=a,flag=1;
 while(a--){
 	if(str[a]<'0'||str[a]>'9'){
	 flag=0;}
 }
 while(b--){
 	if(str[k+1+b]<'0'||str[k+1+b]>'9'){
	 flag=0;}
 }if(str[k]!='-')flag=0;
 if(flag==1)printf("Yes\n");
 else printf("No\n");
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int abs(int n) {
    return (n >= 0) ? n : -n;
}

int calc_min_dis(int left, int right, int X, int Y) {
    int dis1 = right - left;
    int dis2 = abs(X - left) + abs(Y - right) + 1;
    return (dis1 < dis2) ? dis1 : dis2;
}

int main() {
    int N, X, Y, i, j;
    cin >> N >> X >> Y;
    
    int distance_count[N];
    rep(i, N) distance_count[i] = 0;

    for (i = 0; i < N - 1; i++) {
        for (j = i + 1; j < N; j++) {
            int d = calc_min_dis(i + 1, j + 1, X, Y);
            distance_count[d]++;
        }
    }

    for (i = 1; i < N; i++) {
        cout << distance_count[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			int input = int.Parse(Console.ReadLine());
			int count = 0;
			while (input != 0)
			{
				count++;
				Console.WriteLine($"Case {count}: {input}");

				input = int.Parse(Console.ReadLine());
			}
		}
	}
}



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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	double M, N;
	cin >> N >> M;
	double total_votes = 0;
	double A[1005];
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		total_votes += A[i];
	}
	double min_votes = total_votes / (4 * M);
	int num_items = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] >= min_votes) num_items++;
		if (num_items == M) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
count = [0] * len(H)
i = 0
k = 0
while i < len(H)-1:
    while H[i]>=H[i+1]:
        i += 1 
        k += 1
        if i >=len(H)-1:
            break
    count[i] = k
    i += 1
    k = 0
print(max(count))

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;


int main() {
    ll x;
    cin>>x;
    ll now=100;
    int count=0;
    while(now<x){
        now*=1.01;
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[] a = new int[n];
		double dif = Integer.MAX_VALUE, ave = 0;
		int idx = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			ave += a[i];
		}
		ave = ave / n;
		for (int i = 0; i < n; i++) {
			if (dif > Math.abs(ave - a[i])) {
				dif = Math.abs(ave - a[i]);
				idx = i;
			}
		}
		System.out.println(idx);
	}
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	for(int i = 0; i < n; ++i){
		cin >> a[i+1];
	}
	int ans = 0;
	vector<bool> visited(n + 1, false);
	visited[1] = true;
	int next = a[1];
	while(true){
		if(visited[next]){
			ans = -1;
			break;
		}
		ans++;
		if( next == 2 ){
			break;
		}
		visited[next] = true;
		next = a[next];
	}
	cout << ans << endl;
}


Measured memory_bytes: 768