akhauriyash/Code-Regression huggingface dataset:
// AOJ Volume0 0161

#include <stdio.h>

int main(void)
{
    int n;
    int c, m1, s1, m2, s2, m3, s3, m4, s4;
    int t;
    int prize_1_c, prize_2_c, prize_b_c, prize_l_c;
    int prize_1_t, prize_2_t, prize_b_t, prize_l_t;
    int i;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }

        prize_1_t = prize_2_t = 100 * 100;
        prize_b_t = prize_l_t = -1;
    
        for (i = 0; i < n; i++){
            scanf("%d%d%d%d%d%d%d%d%d", &c, &m1, &s1, &m2, &s2, &m3, &s3, &m4, &s4);
 
            t = (m1 + m2 + m3 + m4) * 100 + 
                (s1 + s2 + s3 + s4) / 60 * 100 +
                (s1 + s2 + s3 + s4) % 60;
            
            if (prize_1_t > t){
                prize_2_t = prize_1_t;
                prize_2_c = prize_1_c;
                prize_1_t = t;
                prize_1_c = c;
            }
            else if (prize_2_t > t){
                prize_2_t = t;
                prize_2_c = c;
            }
            
            if (prize_l_t < t){
                prize_b_t = prize_l_t;
                prize_b_c = prize_l_c;
                prize_l_t = t;
                prize_l_c = c;
            }
            else if (prize_b_t < t){
                prize_b_t = t;
                prize_b_c = c;
            }
            
        }
        printf("%d\n%d\n%d\n", prize_1_c, prize_2_c, prize_b_c);
    }
    return (0);
}

Measured memory_bytes: 600
N,M=map(int,input().split())
A=[]
B=[True]*(N+1)
DP=[0]*(N+1)
DP[0]=1
for i in range(M):
  A.append(int(input()))
for i in range(M):
  B[A[i]]=False
#print(B)

for i in range(1,N+1):
  if B[i]==False:
    DP[i]=0
  else:
    if i==1:
      DP[i]=DP[i-1]
    else:
      DP[i]=(DP[i-1]+DP[i-2])%1000000007
if DP[N]==0:
  print(0)
else:
  print(DP[N])

Measured memory_bytes: 8616
import sys
def input(): return sys.stdin.readline().strip()

def main():
    """
    nのオーダーを見てb < √nまで半分全探索しようという気持ちになるのか・・・？
    そうだとしても√n < bの場合の考察もやや技巧的に思われるが、
    とりあえず√nで切る方策はある種の定石として覚えておくことにする。
    あとは解説pdf参照。
    """
    n = int(input())
    s = int(input())
    if n < s:
        print(-1)
        return
    if n == s:
        print(n + 1)
        return
    for b in range(2, int(n ** 0.5) + 1):
        val = 0
        num = n
        while num >= b:
            val += num % b
            num //= b
        val += num
        if val == s:
            print(b)
            return
    for p in range(int(n ** 0.5), 0, -1):
        if (n - s) % p != 0: continue
        b = (n - s) // p + 1
        val = 0
        num = n
        while num >= b:
            val += num % b
            num //= b
        val += num
        if val == s:
            print(b)
            return
    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73548
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int main(){

	int n;
	scanf("%d", &n);
	int ar[n];
	int sum = 0, s1 = 0;
	for(int i=0; i<n; i++){
		scanf("%d", &ar[i]);
		sum += ar[i];
	}

	int minm = INT_MAX;

	for(int i=0; i<n; i++){
		s1 += ar[i];
		minm = min(minm, abs(s1 * 2 - sum));
	}

	printf("%d\n", minm);

	return 0;
}

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

int n;
int64_t a[100000];

size_t count(bool init_plus) {
    size_t cnt = 0;
    int64_t sum = 0; 
    bool plus = init_plus;
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        if (plus) {
            if (sum == 0) {
                ++cnt;
                sum += 1;
            } else if (sum < 0) {
                cnt += (-sum + 1);
                sum = 1;
            } 

            plus = false;
        } else {
            if (sum == 0) {
                ++cnt;
                sum -= 1;
            } else if (sum > 0) {
                cnt += (sum + 1);
                sum = -1;
            } 

            plus = true;
        }
    }

    return cnt;
}

int main() {
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    std::cout << std::min(count(true), count(false)) << std::endl;

    return 0;
}


Measured memory_bytes: 1024
def maxHeapify(A, i):
    l = 2*i + 1
    r = 2*i + 2
    if l <= H-1 and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r <= H-1 and A[r] > A[largest]:
        largest = r

    if largest != i:
        temp = A[i]
        A[i] = A[largest]
        A[largest] = temp
        maxHeapify(A, largest)


def buildMaxHeap(A):
    for i in range(H//2-1, -1, -1):
        maxHeapify(A, i)


if __name__ == "__main__":
    H = int(input())
    inp = list(map(int, input().split()))
    buildMaxHeap(inp)
    print(" " + " ".join(map(str, inp)))

Measured memory_bytes: 65840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e5;

void solve(int N, std::vector<int> s){
    ll total = accumulate(s.begin(), s.end(), 0);
    ll ans;
    if(total % 10 != 0) ans = total;
    else{
        int val = INF;
        for(int i = 0; i < N; ++i){
            if(s[i] % 10 != 0) val = min(val, s[i]);
        }
        if(val == INF) ans = 0;
        else ans = total - val;
    }
    cout << ans << endl;
    return;
}

int main(){
    int N;
    scanf("%id",&N);
    std::vector<int> s(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%id",&s[i]);
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 3684
A, B = raw_input().split()
A = int(A)
B = int(B)

#A + (A-1)*(X-1) >= B 
# 8 + (A-1)*(X-1) >= 9
#(A-1)*(X-1) >= B-A
X = (B-A)/(A-1) +1
if (B-A)%(A-1) > 0:
    X+=1
print X

Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n; cin >> n;
    long long cnt = 0;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    for(int mid = 1; mid < n-1; mid++){
        for(int high = mid+1; high < n; high++){
            int lowlow = l[high] - l[mid] +1;
            auto itr = lower_bound(l.begin(), l.end(), lowlow);
            int dis = max(distance(itr, l.begin() + mid), 0L);
            cnt += dis;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func merge(m1, m2 map[int]int) map[int]int {
	ans := map[int]int{}
	for k, v := range m1 {
		ans[k] += v
	}
	for k, v := range m2 {
		ans[k] += v
	}
	return ans
}

func factor(num, pnum int, v map[int]int) bool {
	if pnum*pnum > num {
		if num != 1 {
			if v[num] > 0 {
				return false
			}
			v[num]++
		}
		return len(v) == 1
	}

	if num%pnum == 0 {
		num /= pnum
		if v[pnum] > 0 {
			return false
		}
		v[pnum]++
	} else {
		pnum++
	}
	return factor(num, pnum, v)
}

func main() {
	var X int
	fmt.Scan(&X)
	r := 0
	for i := X; r == 0; i++ {
		if factor(i, 2, map[int]int{}) {
			r = i
		}
	}
	fmt.Println(r)
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 2 * 1e5 + 5;
ll mpow(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

int n;
string x;

int comp[N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> x;
	reverse(all(x));
	
	for (int i = 1; i < n; ++i) {
		comp[i] = comp[i % __builtin_popcount(i)] + 1;
	}
	
	int nb = 0;
	for (char i : x) {
		nb += (i == '1');
	}
	
	// sum when nb - 1 and nb + 1
	ll pos[2] = {0, 0};
	for (int i = 0; i < n; ++i) {
		if (nb - 1 > 0 && x[i] == '1')
			pos[0] = (pos[0] + mpow(2, i, nb - 1)) % (nb - 1);
		if (nb + 1 > 0 && x[i] == '1')
			pos[1] = (pos[1] + mpow(2, i, nb + 1)) % (nb + 1);
	}
	
	
	
	for (int i = n - 1; i >= 0; --i) {
		string tx = x;
		if (tx[i] == '1') {
			if (!(nb - 1)) {
				cout << "0\n";
				continue;
			}
			
			ll fin = pos[0] - mpow(2, i, nb - 1);
			fin = (fin + nb - 1) % (nb - 1);
			cout << 1 + comp[fin] << '\n';
		} else {
			ll fin = pos[1] + mpow(2, i, nb + 1);
			fin %= (nb + 1);
			cout << 1 + comp[fin] << '\n';
		}
	}
}


Measured memory_bytes: 4632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<ll>vec(N);
	int cnt = 0;
	bool is = false;
	ll sum = 0;
	ll mn = INF;
	rep(i, 0, N) {
		cin >> vec[i];
		if (vec[i] < 0)++cnt;
		if (vec[i] == 0)is = true;
		sum += abs(vec[i]);
		chmin(mn, abs(vec[i]));
	}
	if (!is && cnt % 2)sum -= 2 * mn;
	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
void swap(int *x, int *y)
{
	int temp=*x;
	*x=*y;
	*y=temp;
}
vector<bool> Visited(100000, false);   //頂点が訪問済みか否かを格納
vector<ll> pos(100000, 0);
vi x(200000), y(200000), cst(200000);
//隣接リストを格納する構造体
struct listc{
	int to;
	int cost;
};
vector<vector<listc>> LC(100000);
//頂点数n, 枝数mのグラフの入力(重み付き)
void Graph_Input_cost(int n, int m)
{
	for(int i=0; i<m; i++){
		int from, to, cost;
		cin>>from>>to>>cost;
		if(from>to){
			swap(&from, &to); cost*=-1;
		}
		from--; to--;
		listc e;
		e.to=to; e.cost=cost;
		LC[from].push_back(e);
		e.to=from; e.cost=-cost;
		LC[to].push_back(e);
		x[i]=from; y[i]=to; cst[i]=cost;
	}
}
void DFS(int v)
{
	Visited[v]=true;

	rep(i, LC[v].size()){
		if(Visited[LC[v][i].to]) continue;
		pos[LC[v][i].to]=pos[v]+LC[v][i].cost;
		DFS(LC[v][i].to);
	}
}
int main(void)
{
	int n, m;

	cin>>n>>m;

	Graph_Input_cost(n, m);

	rep(i, n){
		if(!Visited[i]) DFS(i);
	}

	//rep(i, n) cout<<pos[i]<<endl;

	bool flag=true;
	rep(i, m){
		if(pos[y[i]]-pos[x[i]]!=cst[i]){
			flag=false; break;
		}
	}
	cout<<yn(flag)<<endl;
}

Measured memory_bytes: 14720
#include<stdio.h>
int main() {
	int N, M,i,AM=0;
	int A[10000];
 
	scanf("%d""%d", &N,&M);
	for (i = 0; i < M; i++) {
		scanf("%d",&A[i]);
	}
  for(i=0;i<M;i++){
    AM+=A[i];
    }
  if(AM==N){
    printf("%d",AM-N);
  }
  
  if(AM>N){      
      printf("-1");
  }
  if(AM<N){
    printf("%d",N-AM);
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    rep(i, 9) {
        rep(j, 9) {
            if ((i+1)*(j+1) == N) {
                print("Yes");
                return 0;
            }
        }
    }
    print("No");
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    map<string, int> W;
    vector<string> S(N);
    for (int i=0; i<N; i++) {
        cin >> S.at(i);
        W[S.at(i)]+=1;
    }
    for (auto x : W){
        if (x.second>1) {
            cout << "No";
            return 0;
        }
    }
    string b,e;
    for (int i=1; i<N; i++) {
        e = S.at(i-1).at(S.at(i-1).size()-1);
        b = S.at(i).at(0);
        if (b!=e) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

static ll int inf = 1e9;
const int cont = 10e6+7;
using namespace std;

bool vis[1000005];
vector<int>graph[1000005];
int cnt = 1;

void dfs(int u){
    vis[u] = true;
    for(int i=0; i<graph[u].size(); i++){
        int v = graph[u][i];
        if(!vis[v]){
           dfs(v);
           cnt++;
        }
    }
}

void solve(){
    int n,m;
    cin>>n>>m;
    int a,b;
    for(int i=0;i<m; i++){
        cin>>a>>b;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    memset(vis, 0, sizeof vis);
    int ans = -1;
    for(int i=1; i<=n; i++){
        if(!vis[i]){
        dfs(i);
        ans = max(ans, cnt);
        }
        cnt = 1;
    }
    cout<<ans<<endl;
}
int main() {
  solve();
  return Okay;
}


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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); 
  int n; 
  cin >> n;
  vector<int> val(100009, 0);
  int best = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    val[x]++;
    val[x+1]++;
    val[x+2]++;
    best = max(best, val[x]);
    best = max(best, val[x+1]);
    best = max(best, val[x+2]);
  }
  cout << best << endl;
  return 0;
}



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

int main() {
 string s1,s2;
 cin>>s1>>s2;
 string s=s1+s2;
 string ans ="YES";
  if (s.at(0)!=s.at(5))
    ans ="NO";
  if (s.at(1)!=s.at(4))
    ans ="NO";
  if (s.at(2)!=s.at(3))
    ans ="NO";
  cout <<ans ;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n * 2);
    vector<int> nxt(n * 2, -1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[n + i] = a[i];
    }
    map<int, int> pos;
    for (int i = n * 2 - 1; i >= 0; i--) {
        if (pos.count(a[i])) {
            nxt[i] = pos[a[i]];
        }
        pos[a[i]] = i;
    }
    vector<int> suf(n * 2);
    int per = 1;
    int it = 0;
    do {
        it = nxt[it] + 1;
        if (it > n) {
            per++;
        }
        it %= n;
        suf[per] = it;
    } while(it);
    if (k == per) {
        return 0;
    }
    for (int i = suf[k % per]; i < n; i++) {
        if (nxt[i] >= n) {
            cout << a[i] << ' ';
        } else {
            i = nxt[i];
        }
    }
    return 0;
}

Measured memory_bytes: 15616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();
            string input;
            while ((input = Console.ReadLine()) != null)
            {
                list.Add(GetSet(int.Parse(input)));
            }

            foreach (int a in list)
            {
                Console.WriteLine(a);
            }

        }

        static int GetSet(int n)
        {
            int count = 0;
            for (int i = 0; i < 10; i++)
            {
                if (n < i)
                    break;

                for (int j = 0; j < 10; j++)
                {
                    if (n < i + j)
                        break;

                    for (int k = 0; k < 10; k++)
                    {
                        if(n < i+j+k)
                            break;

                        for (int l = 0; l < 10; l++)
                        {
                            if (i + j + k + l == n)
                            {
                                count++;
                                break;
                            }
                        }
                    }
                }
            }

                return count;
        }

    }
        
}

Measured memory_bytes: 5672
#include <stdio.h>

int main()
{
	int i, price = 700;
	char S[4];
	
	scanf("%s", S);
	for(i=0;i<3;i++)
	{
		if(S[i] == 'o') price += 100;
	}
	
	printf("%d\n", price);
	return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main(void) {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	string s = "";
	s += toupper(s1[0]);
	s += toupper(s2[0]);
	s += toupper(s3[0]);
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define fori(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };



int main()
{
	int r, l;
	cin >> l >> r;
	while (1)
	{
		if (l == r&&r == 0)break;
		vector<int> h;
		for (int i = l; i >=1; i--)h.push_back(i);
		for (int i = 0; i < r; i++)
		{
			vector<int> now;
			int p, c;
			cin >> p >> c;
			for (int k = p - 1; k < p - 1 + c; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < p - 1; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = p - 1 + c; k < h.size(); k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < h.size(); k++)
			{
				h[k] = now[k];
			}
		}
		cout << h[0] << endl;
		cin >> l >> r;
	}

	return 0;
}

Measured memory_bytes: 1220
/*
 * 改行
Console.WriteLine("");
 * 改行なし
Console.Write("");
 */

using System;
using System.Linq;

namespace Library
{
  class LongInput
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }
        public static long[] Read(long row)
        {
            return (new long[row]).Select(j => long.Parse(Console.ReadLine())).ToArray();
        }
        public static long[] ReadMulti()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        public static long[][] ReadMulti(long row)
        {
            return (new long[row][]).Select(j => Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray()).ToArray();
        }
    }
    class ArrayOutput
    {
        public static void Output<T>(T[] content)
        {
            Console.WriteLine(String.Join(" ", content.Select(i => ((object)i).ToString()).ToArray())); 
        }
    }
}
namespace AtCoder
{
    class ABC085_C //適宜名前を変える
    {
        static void Main(string[] args)
        {
            var input = Library.LongInput.ReadMulti();
            var N = input[0];
            var Y = (long)input[1]/1000;
            long[] result = { -1, -1, -1 };
            for(int i = 0; i <= N; i++)
            {
                for(int j = 0; j <= N - i; j++)
                {
                    if(10 * i + 5 * j + (N - i - j) == Y)
                    {
                        result[0] = i;
                        result[1] = j;
                        result[2] = (N - i - j);
                        goto END;
                    }
                }
            }
            END: Library.ArrayOutput.Output<long>(result);
        }
    }
}


Measured memory_bytes: 13524
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    
    val aList = readInputLine().split(" ").map { it.toInt() }
    
    var ans = mutableListOf<Int>()
    
    for (i in n - 1 downTo 0 step 2) {
        ans.add(aList[i])
    }
    for (i in n % 2..n - 1 step 2) {
        ans.add(aList[i])
    }

    println(ans.joinToString(" "))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 101988
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	char c;
	for(int i=0;i<3;i++)
	{
		scanf("%c",&c);
		putchar(c=='9'?'1':'9');
	}
	puts("");
}


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

struct UnionFind{
  int N;
  vector<int> rank,par,sz;
  UnionFind(int n){
    N=n;
    rank.resize(N+1,1);
    par.resize(N+1);
    sz.resize(N+1,1);
    r(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(rank[rx]>rank[ry]){
      sz[rx]+=sz[ry];
      par[ry]=rx;
    }
    else {
      sz[ry]+=sz[rx];
      par[rx]=ry;
      if(rank[rx]==rank[ry])rank[ry]++;
    }
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  
  int get_size(int x){
    return sz[root(x)];
  }
  
};

int main(){
  int n,m,count=0;
  cin >> n >> m;
  vector<int> v(n);
  r(i,n)cin >> v[i];
  UnionFind uf(n);
  r(i,m){
    int a,b;
    cin >> a >> b;
    uf.unite(a-1,b-1);
  }
  r(i,n){
    if(uf.same(v[i]-1,i))count++;
  }
  cout<<count<<endl;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll h, w, a, b;
  cin >> h >> w >> a >> b;

  vector<vector<ll>> ans(h, vector<ll>(w));
  for (ll i = 0; i < b; ++i) {
    for (ll j = 0; j < a; ++j) {
      ans[i][j] = 1;
    }
  }

  for (ll i = b; i < h; ++i) {
    for (ll j = a; j < w; ++j) {
      ans[i][j] = 1;
    }
  }

  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      cout << ans[i][j];
    }
    cout << endl;
  }


  return 0;
}


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

int main() {
  int N,M,X; cin >>N >>M >>X;
  int count_a=0,count_b=0;
  rep(i,0,M) {
    int A; cin >>A;
    if (A<X) count_a++;
    else count_b++;
  }
  cout <<min(count_a,count_b) <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

std::string IntToString(long long a){
  char x[100];
  sprintf(x,"%lld",a);
  std::string s = x;
  return s;
}
long long StringToInt(std::string a){
  char x[100]; long long res;
  strcpy(x,a.c_str());
  sscanf(x,"%lld",&res);
  return res;
}
inline void printIntVal(long long a) {
  std::cout << "The Value is: "<< IntToString(a) << std::endl;
}
inline void printStringVal(std::string a) {
  std::cout << "The Value is: "<< a << std::endl;
}
inline std::string GetString(){
  char x[1000005];
  scanf("%s",x);
  std::string s = x;
  return s;
}
inline std::string uppercase(std::string s){
  int n = (int)s.size();
  for(int i = 0; i < n; i++) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline std::string lowercase(std::string s){
  int n = (int)s.size();;
  for(int i = 0; i < n; i++) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN (std::string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}
inline long long CharToInt(char c) {
    return (c - '0');
}

// ---------------------------------------------------------



int main() {

  std::string p = "";

  for(int i = 0; i < 3; i++) p += toupper(GetString()[0]);

  std::cout << p << std::endl;

  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
# define LL long long
LL A, B, C, K;
int main() {
	scanf("%lld %lld %lld %lld", &A, &B, &C, &K);
	K &= 1;
	while (K --) {
		LL _A = B + C, _B = A + C, _C = A + B;
		A = _A, B = _B, C = _C;
	}
	printf("%lld\n", A - B);
	return 0;
}

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

int main() {
  long long n, a, max_a = -1000000, min_a = 1000000, sum_a = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    max_a = max(a, max_a);
    min_a = min(a, min_a);
    sum_a += a;
  }
  cout << min_a << " " << max_a << " " << sum_a << endl;
}

Measured memory_bytes: 3092
package main

import "fmt"

func main() {
	// Code for B - Grid Compression
	var H, W int
	fmt.Scanf("%d %d", &H, &W)

	a := make([]string, 0)
	var S string
	var flag int
	for i := 0; i < H; i++ {
		fmt.Scanf("%s", &S)
		flag = 0
		for j := 0; j < W; j++ {
			if S[j] == '#' {
				flag = 1
			}
		}
		if flag == 1 {
			a = append(a, S)
		}
	}

	ans := make([]int, 0)
	for i := 0; i < W; i++ {
		flag = 0
		for j := 0; j < len(a); j++ {
			if a[j][i] == '#' {
				flag = 1
			}
		}
		if flag == 1 {
			ans = append(ans, i)
		}
	}
	for i := 0; i < len(a); i++ {
		for _, v := range ans {
			fmt.Printf("%c", a[i][v])
		}
		fmt.Printf("\n")
	}

}


Measured memory_bytes: 1980
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct node {
  int id;
  int weight;
  struct node *next;
};
struct node **list;
int *dist, *prev, *heap, *heap_index, heapsize;
void Insert(int, int, int);
void downheap(int);
void upheap(int);
void PQ_Init(int);
void DijkstraPQ(int, int);
int main(void)
{
  int i, n, r, u, v, c, q;
  scanf("%d %d %d", &n, &r, &q);
  list = (struct node**)malloc(sizeof(struct node*) * n);
  for (i = 0; i < n; i++) {
    list[i] = NULL;
  }
  dist = (int*)malloc(sizeof(int) * n * 2);
  prev = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < r; i++) {
    scanf("%d %d %d", &u, &v, &c);
    Insert(u, v, c);
  }
  DijkstraPQ(q, n * 2);
  //printf("%d\n", dist[2*n-1]);
  for (i = 0; i < n; i++) {
    struct node *p, *q;
    if (dist[i] < INT_MAX) {
      printf("%d\n", dist[i]);
    } else {
      printf("INF\n");
    }
    if (list[i] != NULL) {
      for (q = list[i], p = q->next; p != NULL; q = p, p = p->next) {
        q->next = p->next;
        free(p);
      }
      free(list[i]);
    }
  }
  free(list);
  free(dist);
  free(prev);
  free(heap);
  free(heap_index);
}
void Insert(int a, int b, int weight)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->weight = weight;
  p->next = list[a];
  list[a] = p;
}
void downheap(int k)
{
  int j, v = heap[k];
  while (k < heapsize / 2) {
    j = 2 * k + 1;
    if (j < heapsize - 1 && dist[heap[j]] > dist[heap[j + 1]]) j++;
    if (dist[v] <= dist[heap[j]]) break;
    heap[k] = heap[j];
    heap_index[heap[j]] = k;
    k = j;
  }
  heap[k] = v;
  heap_index[v] = k;
}
void upheap(int j)
{
  int k, v = heap[j];
  while (j > 0) {
    k = (j + 1) / 2 - 1;
    if (dist[v] >= dist[heap[k]]) break;
    heap[j] = heap[k];
    heap_index[heap[k]] = j;
    j = k;
  }
  heap[j] = v;
  heap_index[v] = j;
}
void PQ_Init(int size)
{
  int i;
  heapsize = size;
  heap = (int*)malloc(sizeof(int) * size);
  heap_index = (int*)malloc(sizeof(int) * size);
  for (i = 0; i < size; i++) {
    heap[i] = i;
    heap_index[i] = i;
  }
  for (i = size / 2 - 1; i >= 0; i--) {
    downheap(i);
  }
}
void DijkstraPQ(int p, int size)
{
  int i;
  for (i = 0; i < size; i++) dist[i] = INT_MAX;
  for (i = 0; i < size / 2; i++) prev[i] = -1;
  dist[p] = 0;
  PQ_Init(size);
  while (heapsize > 0) {
    struct node *n;
    int u = heap[0];
    heap[0] = heap[heapsize - 1];
    heap_index[heap[heapsize - 1]] = 0;
    heapsize--;
    downheap(0);
    for (n = list[u%(size/2)]; n != NULL; n = n->next) {
      long int w = n->weight, newlen2 = dist[u] + w;
      if (newlen2 < dist[n->id]) {
        int temp = newlen2;
        newlen2 = dist[n->id];
        dist[n->id] = temp;
        upheap(heap_index[n->id]);
      }
      if (newlen2 < dist[n->id+size/2]) {
        dist[n->id+size/2] = newlen2;
        upheap(heap_index[n->id+size/2]);
      }
    }
  }
}


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



int main()
{

    int i,j,k,a,b,x,y,e,n,m,v;
    cin>>n>>m;
    int arr[n+1],arr2[n+1];
    memset(arr,0,sizeof(arr));
    memset(arr2,0,sizeof(arr2));
    x=0;
    y=0;
    for(i=1;i<=m;i++)
    {
        cin>>a;
        string s;
        cin>>s;


        if(s=="AC")
        {
            if(arr[a]!=1){
                x++;
                arr[a]=1;
                y+=arr2[a];
            }
        }
        else
        {
            if(arr[a]!=1){
               arr2[a]++;
            }
        }
    }
    cout<<x<<" "<<y<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <cstdio>

int solve(int a, int b, int c, int x);

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

	scanf("%d\n", &a);
	scanf("%d\n", &b);
	scanf("%d\n", &c);
	scanf("%d\n", &x);

	printf("%d\n", solve(a, b, c, x));
	return 0;
}

int solve(int a, int b, int c, int x){
	int result = 0;

	if (x < 0){
		return 0;
	}

	if (!x){
		return 1;
	}

	if (a){
		for (int i = 0; i <= a; i++){
			result += solve(0, b, c, x - 500 * i);
		}
		return result;
	}

	if (b){
		for (int i = 0; i <= b; i++){
			result += solve(0, 0, c, x - 100 * i);
		}
		return result;
	}

	if (c){
		for (int i = 0; i <= c; i++){
			result += solve(0, 0, 0, x - 50 * i);
		}
		return result;
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i, tx - sx) {
        cout << "R";
    }

    rep(i, ty - sy) {
        cout << "U";
    }

    rep(i, tx - sx) {
        cout << "L";
    }

    rep(i, ty - sy) {
        cout << "D";
    }

    cout << "D";

    rep(i, tx - sx +1) {
        cout << "R";
    }

    rep(i, ty - sy + 1) {
        cout << "U";
    }

    cout << "L";
    cout << "U";

    rep(i, tx - sx + 1) {
        cout << "L";
    }

    rep(i, ty - sy + 1) {
        cout << "D";
    }

    cout << "R" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  string a;
  cin>>a;
  rep(i,a.size()){
    if(a[i]=='7'){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((A<=C&&C<=B)||(C<=A&&A<=D))
    cout<<min(B,D)-max(A,C)<<endl;
  else
    cout<<"0"<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    vector<char> s(26);
    rep(i, 4){
        char x;
        cin >> x;
        s[x%26]++;
    }
    int ans = 0;
    rep(i, 26){
        if(s[i] == 2) ans++;
    }
    cout << (ans == 2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> A(N),accum(N+1);
    for(int i = 0;i < N;i++){
        cin >> A[i];
        accum[i+1] = accum[i] + A[i];
    }
    ll sum = 0,num = 0,l = 0,r = 0;
    for(;l < N;l++){
        while(l > r)r++;
        while((num ^ A[r]) == accum[r+1] - accum[l] && r < N){   
            num ^= A[r];
            r++;
            sum += r - l;
        }
        num ^= A[l];
    }
    cout << sum << endl;
}

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

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)
#define FOR(i,a,b) 		for (int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, k;
    cin >> n >> k;
    if (n % k == 0)
    	cout << 0 << endl;
    else if (n > k) {
    	ll q = n / k;
    	ll r = q + 1;
    	ll ans = min(abs(q*k-n), abs(r*k-n));
    	cout << ans << endl;
    } else {
    	ll ans = min(abs(n - k), n);
    	cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

string s, t;


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

	int n = s.size(), m = t.size();

	int a[n + 1][m + 1];

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

	for(int i = 0; i <= m; i++) {
		a[0][i] = 0;
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(s[i - 1] == t[j - 1]) {
				a[i][j] = a[i- 1][j - 1] + 1;
			} else {
				a[i][j] = max(a[i - 1][j], a[i][j - 1]);
			}
		}
	}

	

	char ans[a[n][m]+1];
	ans[a[n][m]] = '\0';


	int index = a[n][m] - 1;
	int i = n , j = m;
	while(i > 0 and j > 0) {
		if(s[i-1] == t[j-1]) {
			ans[index] = s[i - 1];
			i--;j--;index--;
		} else if(a[i - 1][j] > a[i][j - 1]) {
			i--;
		} else {
			j--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 73964
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int n; cin >> n;
	vector<int> p(n);
	rep (i, n) {
		cin >> p[i];
	}
	if (n == 1) {
		cout << 1 << endl;
		return;
	}
	int target = p[0];
	int ans = 1;
	for (int i = 1; i < n; ++i) {
		if (target > p[i]) {
			target = p[i];
			ans++;
		}
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
//typedef pair<int, int> P;
//vector<long long> a(max_n);
//map<int, int> m;
static const int max_n = 10, max_m = 102;
static const ll  INF = 1000000000;
const long long mod = 1e18;
int ci;

string C[max_n];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    for(int i=0; i<h; ++i) cin >> C[i];
    int ans=0;
    for(int i=0; i<(1<<h); ++i){
        for(int j=0; j<(1<<w); ++j){
            int cnt = 0;
            for(int x=0; x<h; ++x){
                if(((i>>x)&1)==1) continue;
                for(int y=0; y<w; ++y){
                    if(((j>>y)&1)==1) continue;
                    if(C[x][y]=='#') cnt++;
                }
            }
            if(cnt==k) ans++;
        }
    }
    cout << ans << endl;
    cin >> ci;
    return 0;
}

Measured memory_bytes: 3556
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
// #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=a;i<=(int)b;i++)
#define All(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=1e9+7;
const int inf=2147483647;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int n;

struct node
{
	int x,y;
};

vector<node> vec1,vec2;
bool cmp2(node x1,node x2){
	return x1.x>x2.x;
}
bool cmp1(node x1,node x2){
	return x1.y<x2.y;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		int a=0,b=0;
		for(int i=0;i<(int)s.size();i++){
			if(s[i]=='(') a++;
			else if(a>0) a--;
			else b++; 
		}
		if(a>=b) vec1.pb(node{a,b});
		else vec2.pb(node{a,b});
	}
	sort(All(vec1),cmp1);
	sort(All(vec2),cmp2);
	bool f=true;
	int giao=0;
	rep(i,0,vec1.size()-1){
		giao-=vec1[i].y;
		if(giao<0) f=false;
		giao+=vec1[i].x;
	}
	rep(i,0,vec2.size()-1){
		giao-=vec2[i].y;
		if(giao<0) f=false;
		giao+=vec2[i].x;
	}
	if(giao!=0) f=false;
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;

	return 0;
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

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

int main() {
	int a[4], b[4];
	while (cin >> a[0]) {
		rep (i, 3) cin >> a[i + 1];
		rep (i, 4) cin >> b[i];

		int hit = 0, blow = 0;
		rep(i, 4) {
			rep(j, 4) {
				if (a[i] == b[j]) {
					if (a[i] == b[i]) {
						hit++;
					} else {
						blow++;
					}
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
}

Measured memory_bytes: 1160
N=io.read()
a={}
for i=1, N do
    if i%3==0 and i%5==0 then
        a[i]="FizzBuzz"
    elseif i%3==0 then
        a[i]="Fizz"
    elseif i%5==0 then
        a[i]="Buzz"
    else
        a[i]=i
    end
end

sum = 0
for i=1, N do
    if type(a[i])=="number" then
        sum = sum + a[i]
    end
end
print(sum)

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m, n, i, count=0, q=0;float t;
    cin>>n>>m;
    int a[n];
    for(i = 0; i<n; i++) cin>>a[i];
    for(i = 0; i<n; i++){q=q+a[i];};t = ((1.0/(4*m))*q);
    for(i = 0; i<n; i++)
    {
        if(a[i]>=t)
        {
            count++;
        }
    }
    if(count>=m)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3564
N, K, Q = map(int, input().split(' '))
res = [0 for _ in range(N)]
for i in range(Q):
    a = int(input()) - 1
    res[a] = res[a] + 1
res = list(map(lambda n: n - Q + K, res))
for i in range(N):
    print('Yes' if res[i] > 0 else 'No')


Measured memory_bytes: 7868
from queue import Queue
k=int(input())
q=Queue()
for i in range(1,10):
    q.put(i)
if k<=9:
    print(k)
    exit()
a=9
while a<k:
    p=q.get()
    flag=0
    if p%10!=0:
        q.put(p*10+p%10-1)
        a+=1
    if a==k:
        print(p*10+p%10-1)
        exit()
    q.put(p*10+p%10)
    a+=1
    if a==k:
        print(p*10+p%10)
        exit()
    if p%10!=9:
        q.put(p*10+p%10+1)
        a+=1
    if a==k:
        print(p*10+p%10+1)
        exit()


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

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    int d[5];
    int temp;
    int sum = 0;

    cin >> a >> b;

    for(int i = a; i <= b; ++i)
    {
        temp = i;
        d[0] = temp % 10; temp /= 10;
        d[1] = temp % 10; temp /= 10;
        d[2] = temp % 10; temp /= 10;
        d[3] = temp % 10; temp /= 10;
        d[4] = temp % 10;
        if(d[0] == d[4] && d[1] == d[3]) ++sum;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    ll n,k;
    cin>>n>>k;
    vll a(n);
    cin >> a;
    FOR(i, k, n) {
        if (a[i] <= a[i-k]) {
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 4836
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
 
 
inline ll ksum(ll n, ll k){
  return k * (2*n - k - 1);
}

pii updtp2(pii p, int nw){
  if(p.first == -1) p.first = nw;
  else if(p.second == -1) p.second = nw;
  else if(p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  }
  else if(p.second >= nw) p.second = nw;
  return p;
}
 
#define isValid(y,x) (y >=0 && y < n && x >= 0 && x < m)


ll dp[444][444];

int main(){
    int n;
    cin >> n;
    vector<ll> a(n), sum(n + 1);
    REP(i,n){
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }

	fill(dp[0],dp[444],1e16);

	REP(i,n) dp[i][i]=0;

	rep(d,2,n+1)
    REP(l,n-d+1){
		ll r=l+d-1;
		rep(c,l,r) 
            dp[l][r] = min(dp[l][r],dp[l][c]+dp[c+1][r]);
		dp[l][r] += sum[r+1]-sum[l];
	}
	cout<<dp[0][n-1]<<endl;

	return 0;
} 

Measured memory_bytes: 1792