akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s;
		char c;
		while(true){
			s = sc.nextLine();
			if(s.length() == 1)
				break;
			Bracket b = new Bracket();
			for(int i = 0; i < s.length(); i++){
				c = s.charAt(i);
				if(c == '(' || c == ')' || c == '[' || c == ']'){
					b.c[b.n] = c;
					b.n++;
				}
			}
			b.balance();
			System.out.println(b.answer == 1 ? "yes" : "no");
		}
	}

}

class Bracket{
	int answer = 1;
	char[] c = new char[100];
	int n = 0;
	void balance(){
		balance(0, n-1);
	}
	void balance(int left, int right){
		if(left <= right){
			int bal = 0;
			for(int i = left; i <= right; i++){
				if(c[i] == '(' || c[i] == '[')
					bal++;
				if(c[i] == ')' || c[i] == ']')
					bal--;
				if(bal < 0){
					answer = 0;
					break;
				}
				if(bal == 0){
					if((c[left] == '(' && c[i] == ')') ||
					(c[left] == '[' && c[i] == ']')){
						balance(left+1, i-1);
						balance(i+1, right);
					}else
						answer = 0;
					break;
				}	
			}
			if(bal > 0)
				answer = 0;
		}
	}
}

Measured memory_bytes: 34952
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        List<Integer> eats = new ArrayList<>();
        int count = 0;

        for(int i=0; i<n; i++){
            eats.add(sc.nextInt());
        }

        eats = eats.stream().sorted((a,b)->a-b).collect(Collectors.toList());

        for(Integer eat:eats){
            if(eat <= x && n != 1){
                x -= eat;
                n -= 1;
                count++;
            }else if(eat == x && n == 1){
                count++;
                break;
            }else{
                break;
            }
        }
        System.out.println(count);

    }

}


Measured memory_bytes: 28368
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=5e3+100;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int xs[twx];
struct LV
{
    int y;
    int Next;
}a[twx];
int Link[twx];
int len;
int asd[twx];
int qwe[2][twx];
void Insert(int x,int y)
{
    a[++len].y=y;
    a[len].Next=Link[x];
    Link[x]=len;
}
void dfs(int x)
{
    f3(Link[x],a[i].Next,i)
    {
        int y=a[i].y;
        dfs(y);
    }
    memset(qwe[0],0x3f,sizeof qwe[0]);
    int tmp=0;
    qwe[tmp][0]=0;
    f3(Link[x],a[i].Next,i)
    {
        int y=a[i].y;
        tmp=1-tmp;
        memset(qwe[tmp],0x3f,sizeof qwe[tmp]);
        f1(0,xs[x],j)
        {
            if(j-xs[y]>=0)
            {
                qwe[tmp][j]=min(qwe[tmp][j],qwe[1-tmp][j-xs[y]]+asd[y]);
            }
            if(j-asd[y]>=0)
            {
                qwe[tmp][j]=min(qwe[tmp][j],qwe[1-tmp][j-asd[y]]+xs[y]);
            }
        }
    }
    f1(0,xs[x],i)
    {
        asd[x]=min(asd[x],qwe[tmp][i]);
    }
}
void init()
{
	n=read();
    f1(2,n,i)
    {
        int p=read();
        Insert(p,i);
    }
    f1(1,n,i)
    {
        xs[i]=read();
    }
    memset(asd,0x3f,sizeof asd);
    dfs(1);
    if(asd[1]!=inf)
    {
        puts("POSSIBLE");
    }
    else
    {
        puts("IMPOSSIBLE");
    }
}
int main()
{
    init();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5)+1;

int n, m, par[MAX], lvl[MAX];
set<int> g[MAX];
queue<int> leaves;
bool mark[MAX];
void dfs(int u) {
	if(g[u].size() == 1) leaves.push(u);
	for(int v: g[u]) if(v != par[u]) {
		par[v] = u;
		lvl[v] = lvl[u]+1;
		dfs(v);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		g[u].insert(v);
		g[v].insert(u);
	}
	if(n == 1) cout << "First", exit(0);
	else if(n == 2) cout << "Second", exit(0);
	int root = 1;
	while(g[root].size() == 1) root++;
	dfs(root);
	while(!leaves.empty()) {
		int v = leaves.front();
		leaves.pop();
		if(!g[v].count(par[v])) cout << "First", exit(0);
		mark[v] = mark[par[v]] = true;
		for(int x: g[par[v]]) g[x].erase(par[v]);
		if(g[par[par[v]]].size() == 1 && lvl[*g[par[par[v]]].begin()] < lvl[par[par[v]]]) leaves.push(par[par[v]]);
	}
	for(int i = 1; i <= n; i++) if(!mark[i]) cout << "First", exit(0);
	cout << "Second";
}


Measured memory_bytes: 15360
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split(" "))))
    B = A.copy()

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 12068
#include <iostream>
using namespace std;
 
int main() {
    long long N, K, sum = 0;
    cin >> N >> K;
    for(long long i = K; i <= N + 1; i++){
        sum += i * (N - i + 1) + 1;
    }
    sum = sum % (1000000000 + 7);
    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++)
        cin >> l[i];
    
    sort(l.rbegin(), l.rend());
    //reverse(l.begin(), l.end());
    
    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += l[i];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;
const int mod = 1e9+7;


int main() {
  int N; cin >> N;
  long long ans = 1;
  int a[1000] = {0};
  for(int i = 2; i <= N; i++) {
    int ret = i;
    for(int j = 2; ret > 1; j++) {
      while(ret % j == 0) {
        a[j]++;
        ret /= j;
      }
    }
  }

  for(int i = 0; i < 1000; i++) {
    ans = ans*(a[i]+1)%mod;
  }
  cout << ans << endl;

  return 0;
}



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

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, n) for(long long (i) = (a); (i) < (n); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define GET(v) cin >> (v)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

int main()
{
    int x;
    GET(x);
    
    if(x == 5 || x == 3 || x == 7) {
        SHOW("YES");
    }
    else {
        SHOW("NO");
    }
    
    return 0;
}


Measured memory_bytes: 256
def main():
  N=int(input())
  S=input()
  scount=0
  for i in range(N-1):
    for j in range(N):
      S_i=S[i:j+1]
      if(S_i=='ABC'):
        scount=scount+1
  print(scount)
  
if __name__=='__main__':
  main()

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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long
const int mod = 2019;
const int nax = 1e5 + 5;
ll power_5(ll x){
	ll ret = x;
	for(int i = 0; i < 4; ++i){
		ret *= x;
	}
	return ret;
}
ll is_power_5(ll x){
	ll l = -4000, r = 4000;
	ll mid;
	while(l <= r){
		mid = l + r >> 1;
		ll val  = power_5(mid);
		if(val > x){
			r = mid - 1;
		}
		if(val < x){
			l = mid + 1;
		}
		if(val == x){
			return mid;
		}
	}
	return -9999;
}
int main()
{
	fast();
	ll a, b, x;
	cin >> x;
	a = 1;
	for(ll i = 0; i <= 4000; ++i){
		ll t = power_5(i);
		ll rs = t - x;
		ll check = is_power_5(rs);
		if(check!= -9999){
			return cout << i << " " << check <<"\n", 0;
		}
	}
}



Measured memory_bytes: 3652
N=int(input())
dic={}
for i in range(N):
    s = input()
    try:
      dic[s]+=1
    except:
      dic[s]=0
slis = sorted(dic.items(), key=lambda x:x[1],reverse=True)
maxv=slis[0][1]
lis = []
for i in range(len(slis)):
  if slis[i][1]==maxv:
    lis += [slis[i][0]]
  else:
    break
lis=sorted(lis)
for s in lis:
  print(s)

Measured memory_bytes: 47324
#include <stdio.h>
int main(void){
    // Your code here!
    int i,j,k,r,c;   
    int a[101][101]={{0}};   
    scanf("%d %d",&r,&c);   
    for(i=0;i < r;i++){       
        for(j=0;j<c;j++){           
            scanf("%d",&a[i][j]);           
            if(j==0){               
                a[i][c]=a[i][0];           
                
            }else{              
                a[i][c]=a[i][c]+a[i][j];           
                
            }           
            if(i==0){           
                a[r][j]=a[0][j];       
                
            }else{           
                a[r][j]=a[r][j]+a[i][j];       
                
            }       
            
        }   
        
    }      
    for(i=0;i < r;i++){        
        if(i==0){            
            a[r][c]=a[0][c];        
            
        }else{            
            a[r][c]=a[r][c]+a[i][c];        
            
        }    
        
    }   
    for(i=0;i<r+1;i++){        
        for(j=0;j<c+1;j++){            
            printf("%d",a[i][j]);            
            if(j==c)break;            
            printf(" ");        
            
        }        
        printf("\n");   
    }     
    return 0;}




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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; i--)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A(N); REP(i, N) cin >> A.at(i)
#define ANS(ans) cout << (ans) << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN(N);
  CINVEC(A, N);

  SORT(A);
  vector<int> V(1, 0);
  REP1(i, A.size()) {
    if (3 <= A[i] - A[i - 1]) V.emplace_back(i);
  }
  V.emplace_back(A.size());

  int ans = 0;
  REP(i, V.size() - 1) {
    int num = 0;

    if (V[i + 1] - V[i] <= ans) continue;

    if (A[V[i + 1] - 1] - A[V[i]] <= 3) {
      num = V[i + 1] - V[i];
    } else {
      for (int x = A[V[i] + 1]; x < A[V[i+1] -1]; x++) {
	int aaa = 0;
	for (int j = V[i]; j < V[i + 1]; j++) {
	  if (x + 1 < A[j]) break;
	  if (A[j] < x - 1) continue;
	  aaa++;
	}
	num = max(num, aaa);
      }
    }
    ans = max(num, ans);
  }

  ANS(ans);
  
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
int main()
{
    int x,i,c=0;
    scanf("%d",&x);
    int n[x];
    for(i=0;i<x;i++)
        scanf("%d",&n[i]);
    for(i=0;i<x;i++)
    {
        if(n[i]-1==i) 1;
        else c++;
    }
    if(c<=2) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()

	cnt10 := 0
	cnt01 := 0
	for i := 0; i < len(s); i++ {
		if (i+1)%2 == 1 {
			if s[i] == '1' {
				cnt01++
			} else {
				cnt10++
			}
		} else {
			if s[i] == '1' {
				cnt10++
			} else {
				cnt01++
			}
		}
	}

	fmt.Println(min(cnt10, cnt01))

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 100 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1972
h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]

ans=0

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])

for i in range(h):
  for j in a[i]:
    if j==1 or j==-1:
      continue
    ans+=c[j][1]
print(ans)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define int ll

signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	map<int,pii> mp;
	rep(i,n){
		int h =a[i];
		if(mp.count(h)==0)mp[h] = make_pair(1,i+1);
		else{
			pii t = mp[h];
			mp[h] = make_pair(t.first+1,min<ll>(t.second,i+1));
		}
	}
	mp[0] = pii(0,0);
	
	vector<int> ans(n+1,0);
	
	
	auto it = mp.end();
	it--;
	
	while(1){
		int h = it->first;
		int sum = it->second.first;
		int num = it->second.second;
		
		
		if(h==0)break;

		it--;
		ans[num]+=sum*(h-it->first);
		it->second.first+=sum;
		it->second.second =min<ll>(it->second.second,num);
	}
	for(int i=1;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n);
    vector<int> ans(n);
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    for(int i=n; i>0; --i){
        for(int j=i; j>0;--j){
            if(b[j-1] == j){
                ans[i-1] = b[j-1];
                b.erase(b.begin() + (j-1));
                break;
            }
            if(j-1 == 0){
                cout << -1 << endl;
                return 0;
            }
        }

    }
    for(int i=0; i<n; ++i){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    using i32 = int32_t; using u32 = uint32_t;
    using i64 = int64_t; using u64 = uint64_t;
    using f32 = float; using f64 = double;

    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n; cin >> n;
    vec<int> l(n);
    for (auto &e : l) cin >> e;
    sort(l.rbegin(), l.rend());

    int ans = 0;
    for (int i = 0; i < n - 2; ++i) {
        int right = l.size() - 1;
        for (int j = i + 1; j < n - 1 && j < right; ++j) {
            while (j < right && !(l[i] < l[j] + l[right])) --right;
            ans += right - j;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3620
import math
a, b, angle_C = map(float, input().split())
S = 1/2 * a * b * math.sin(math.radians(angle_C))
L = (((a**2 + b**2)-2*a*b*math.cos(math.radians(angle_C)))**(0.5))+a+b
h = (2 * S) / a
print(f"{S:.8f}")
print(f"{L:.8f}")
print(f"{h:.8f}")



Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 200005;

int n, k, i, add[N], tab[N], sum;

bool notAllN() {
	for (int i=0;i<n;i++) if (tab[i] != n) return true;
	return false;
}

int main() {
scanf("%d %d", &n, &k);
//n = 200000;
//k = 200000;
for (i=0;i<n;i++) scanf("%d", &tab[i]);
while (k-- && notAllN()) {
	for (i=0;i<=n;i++) add[i] = 0;
	for (i=0;i<n;i++) {
		add[max(0, i - tab[i])]++;
		add[min(n, i + tab[i] + 1)]--;
	}
	//for (i=0;i<n;i++) printf("%d ", add[i]);
	//printf("\n");
	sum = 0;
	for (i=0;i<n;i++) {
		sum += add[i];
		tab[i] = sum;
	}
}
for (i=0;i<n;i++) printf("%d ", tab[i]);
printf("\n");
return 0;
}

Measured memory_bytes: 5364
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <chrono>
#include <ctime>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <iomanip>
#include <assert.h>
#include <stdio.h>
#include <cstring>
#include <random>

using namespace std;
#define int long long
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define try tr
#define pii pair<int, int>
#define ti tuple <int, int, int>
#define vi vector <int>
#define vpi vector <pii>
#define umap unordered_map
#define uset unordered_set
#define left left11
#define right right11
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define fs first
#define sc second

ld TL = 0.25;
bool is_tl = 0;
int CALLS = 0;

inline bool IS() {
    if (++CALLS == 1000) {
        CALLS = 0;
        is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
    }
    return is_tl;
}

template<typename T1, typename T2>
inline void amin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void amax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
    os << p.first << ' ' << p.second << endl;
    return os;
}

template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
    for (auto &u : v) os << u << ' ';
    os << endl;
    return os;
}

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 1e18 + 7, SM = 1e2 + 7;
const ld eps = 1e-9;
int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4];
int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
void solve() {
    int n, cnt = 0;
    cin >> n;
     vi a(n), b(n);
     for (int i= 0; i < n; i++) {
         cin >> a[i];
         cnt += a[i];
     }
     if(cnt % ((n * (n + 1)) / 2)) {
         cout << "NO\n";
         return;
     }
     cnt /= ((n * (n + 1)) / 2);
     for (int i = 0; i < n; i++) {
         int d = a[(i + 1) % n] - a[i];
         int x = cnt - d;
         if(x < 0 || x % n) {
             cout << "NO\n";
             return;
         }
         x /= n;
         b[(i + 1) % n] = x;
     }

     cout << "YES\n";
}

signed main() {
    fast
    solve();
}


Measured memory_bytes: 4800
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int a, b, c, ha, hb, hc;
    cin >> a >> b >> c;
    int ans = -1;
    for (int i = 0; i < 100; ++i){
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            ans = i;
            break;
        }
        else {
            ha = a / 2;
            hb = b / 2;
            hc = c / 2;
            a = hb + hc;
            b = hc + ha;
            c = ha + hb;
        }
        if(a == b && b == c){
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin >> n;
    if (n[0] == '7' || n[1] == '7' || n[2] == '7')
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';

    return 0;
}

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

using namespace std;

int n;
bool answer = false;
int main()
{
    cin >> n;

    int r;
    while (n > 10)
    {
        r = n%10;
        n /= 10;
        
        
        if ( r == 7)
        {
            cout << "Yes\n";
            answer = true;
            break;

        }
    }

    
    if (n == 7)
    {
        if (!answer)
            cout << "Yes\n";
    }
        
    else
    {
        if (!answer)
            cout << "No\n";
    }
    
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  string s(b, '0'+a);
  string t(a, '0'+b);
  if(a < b) cout << s << endl;
  else cout << t << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int R, G, B;
    cin >> R >> G >> B;
    int ret = G * 2 + B;
    cout << (ret % 4 == 0 ? "YES" : "NO") << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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 iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int nx[1010], ny[1010], mx[210], my[210];
set<pair<int, int>> s;

void solve(int m) {
    int n;
    REP(i, m) { cin >> mx[i] >> my[i]; }
    cin >> n;
    REP(i, n) {
        cin >> nx[i] >> ny[i];
        s.insert(make_pair(nx[i], ny[i]));
    }
    REP(i, m) {
        REP(j, n) {
            bool flag1 = true;
            bool flag2 = true;
            int dx = nx[j] - mx[i];
            int dy = ny[j] - my[i];

            REP(k, m) {
                auto nnx = dx + mx[k];
                auto nny = dy + my[k];

                if (!s.count(make_pair(nnx, nny))) {
                    flag1 = false;
                }
            }

            if (flag1) {
                cout << dx << " " << dy << endl;
                return;
            }

            dx = -dx;
            dy = -dy;

            REP(k, m) {
                auto nnx = dx + mx[k];
                auto nny = dy + my[k];

                if (!s.count(make_pair(nnx, nny))) {
                    flag2 = false;
                }
            }

            if (flag2) {
                cout << dx << " " << dy << endl;
                return;
            }
        }
    }
}

int main() {
    int m;
    while (cin >> m && m) {
        solve(m);
    }
    return 0;
}


Measured memory_bytes: 3252
N=int(input())
def kakuwa(N):
  summ=0
  i=0
  while N>10**i:
    i+=1
  for k in range(i+1)[::-1]:
    summ+=N//(10**k)
    N-=(10**k)*(N//(10**k))
  return(summ)

if N%kakuwa(N)==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define int double
using namespace std;

signed main() {
	signed a, b;
	while (cin >> a >> b, a | b) {
		map<int, vector<int>>l;
		vector<vector<int>>s;
		vector<int>c(a);
		vector<int>d(b);
		int x, y;
		x = y = 0;
		for (int e = 0; e < a; e++) {
			cin >> c[e];
			x += c[e];
		}
		for (int f = 0; f < b; f++) {
			cin >> d[f];
			y += d[f];
		}
		x = (x - y) / 2;
		for (int g = 0; g < a; g++) {
			for (int h = 0; h < b; h++) {
				if (c[g] - d[h] == x) { vector<int>i(2); i[0] = c[g]; i[1] = d[h]; s.push_back(i); }
			}
		}
		if (s.size() == 0)cout << -1 << endl;
		else {
			for (auto j : s) {
				l[j[0] + j[1]];
				l[j[0] + j[1]] = j;
			}
			auto q = l.begin();
			cout << q->second[0] << " " << q->second[1] << endl;
		}
	}
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a;
  cin >> a;

  string bs;
  cin >> bs;

  string bt = "";
  for (int i = 0; i < bs.size(); i++) {
    if (bs[i] != '.') {
      bt += bs[i];
    }
  }

  ll b = stoll(bt);

  cout << a * b / 100 << ln;

  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top = 0,S[1000];

void push(int x){
    S[++top] = x;
}

int pop(void){
    top--;
    return S[top+1];
}

int main(void){
    int a,b;
    top = 0;
    char s[100];
    while(scanf("%s",s)!= EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        } else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a-b);
        } else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        } else {
            push(atoi(s));
        }
    }
    printf("%d\n",pop());
    
    return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
const int MAX=1000001;

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

    string ans="Yes";
    for(int i=0;i<s.size();i++){
        if(s[a]!='-') ans="No";
        if(i!=a)if('0'>s[i]||'9'<s[i]){
            ans="No";
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int k = sc.nextInt();

        char[] c = s.toCharArray();

        for (int i=0;i<n;i++) {
            if (c[i] != c[k-1]) {
                c[i] = '*';
            }
        }

        System.out.println(String.valueOf(c));
    }
}


Measured memory_bytes: 23252
scara = input()
s= sorted(scara)
tcar = input()
t= sorted(tcar, reverse=True)

for i, j in zip(s, t):
  if i < j:
    print("Yes")
    break
  elif i > j:
    print("No")
    break
else:
        if len(s) < len(t):

            print("Yes")
        else:

            print("No")


Measured memory_bytes: 3064
#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 all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

string s, t;
int n, m, x;


int main(){
  cin >> n >> m >> x;
  int c[12], a[12][12];
  int k[12];
  int ans = INF;
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    fill(k, k+12, 0);
    bool flag = true;
    int co = 0;
    rep(i, n){
      if(s.test(i)){
        rep(j, m){
          k[j] += a[i][j];
        }
        co += c[i];
      }
    }
    rep(j, m){
      if(k[j] < x) flag = false;
    }
    if(flag) ans = min(co, ans);
  }
  if(ans == INF) ans = -1;
  cout << ans <<endl;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    S=input()
    W=["Sunny","Cloudy","Rainy"]
    if S==W[0]:print(W[1])
    elif S==W[1]:print(W[2])
    else: print(W[0])
    #%%submit!
resolve()

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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int64_t ll;
typedef double dd;

void Solve(ll) {
  ll n;
  cin >> n;
  vector<ll> arr(n), sum(n + 1);
  RARA(a, arr) cin >> a;
  partial_sum(ALL(arr), sum.begin() + 1);
  ll res = ll(1e60);
  VEVE(s2, 2, n - 1) {
    const ll pre = sum[s2];
    auto pref_st = lower_bound(sum.begin() + 1, sum.begin() + s2, pre / 2) - sum.begin();

    const ll suf = sum.back() - pre;
    auto suff_st = lower_bound(sum.begin() + s2 + 1, sum.end(), pre + suf / 2) - sum.begin();
    VEVE(p, pref_st - 2, pref_st + 2) if (0 < p and p < s2) {
        VEVE(s, suff_st - 2, suff_st + 2) if (s2 < s and s < n) {
//            DEBUG(p, s2, s);
            array<ll, 4> vals = {sum[p], sum[s2] - sum[p], sum[s] - sum[s2], sum.back() - sum[s]};
            sort(ALL(vals));
//            DEBUG(vals);
            res = min(res, vals.back() - vals.front());
          }
      }
  }
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int MA_X = 1e-6;
const int MAxn = 2e5 + 5;

int main(){
    int n, a[MAxn];
    while(~scanf("%d", &n)){
        int y2 = 0, y4 = 0;
        memset(a, 0, sizeof(a));
        for(int i = 1; i <= n; i++){
            int x;
            cin >> x;
            if(x % 4 == 0) y4++;
            else if(x % 2 == 0) y2++;
        }
        //for(int i = 1; i <= n; i++) printf("%d " , a[i]);
        //printf("\n");
        if(y4 >= n/2) printf("Yes\n");
        else if(y2 == n-2*y4) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1024
import copy
from collections import deque
H,W = map(int,input().split())
A = []
for i in range(H):
    A.append(list(input()))
now = [0,0]
goal = [H-1,W-1]
x1 = [0,1]
y1 = [1,0]
alr = copy.deepcopy(A)
alr[0][0] = 1
que = deque()
que.append(now)
while que:
    q = que.popleft()
    for i in range(2):
        if 0 <= q[0]+x1[i] <= H-1 and 0 <= q[1]+y1[i] <= W-1 and alr[q[0]+x1[i]][q[1]+y1[i]] == '#':
            alr[q[0]+x1[i]][q[1]+y1[i]] = alr[q[0]][q[1]] +1
            que.append([q[0]+x1[i],q[1]+y1[i]])
if alr[-1][-1] != '#':
    num = alr[-1][-1]
    count = {}
    flag = True
    for i in range(1,num+1):
        count[i] = 0
    for i in range(H):
        for j in range(1,num+1):
            count[j] += alr[i].count(j)
        if '#' in alr[i]:
            flag = False
    
    for i,v in count.items():
        if v != 1:
            flag = False
    if flag:
        print('Possible')
    else:
        print('Impossible')
else:
    print('Impossible')

Measured memory_bytes: 3444
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
ans = [0] * N
B = Counter(A)
for i in range(N):
    ans[i] = B[A[i]]-1

total=sum(ans)
C=[]
for i in range(N):
    c = (total-2*ans[i])//2
    C.append(c)

for num in C:
    print(num)

Measured memory_bytes: 34404
#include <stdio.h>

int main(void){
  int a,b;
  scanf("%d %d", &a,&b);
  a-=2*b;

  (a>=0) ? fprintf(stdout, "%d\n", a) : fprintf(stdout, "%d\n", 0);
  /*
  if(a>=0)
    fprintf(stdout, "%d\n", a);
  else
    fprintf(stdout, "%d\n", 0);
  */
  return 0;
}


Measured memory_bytes: 128
n = int(input())
ans = set()
if n%2 == 1:
  for i in range(1,n):
    ans.add((i,n))
  n -= 1
if n%2 == 0:
  chk = [[] for i in range(n//2)]
  for i in range(1,n//2+1):
    chk[i-1].append(i)
    chk[i-1].append(n+1-i)
  for i in range(n//2-1):
    for j in range(2):
      a = chk[i][j]
      for k in range(i+1,n//2):
        b = chk[k][0]
        c = chk[k][1]
        if a < b:
          ans.add((a,b))
        else:
          ans.add((b,a))          
        if a < c:
          ans.add((a,c))
        else:
          ans.add((c,a))
          
#print(ans)
print(len(ans))
for i in ans:
  print(*i)

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    rep(i, 0, s.size()-8) {
        cout << s[i];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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 powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct node
{
	ll jiage;
	ll shuliang;
}a[maxn];
ll n,k;
bool cmp(node aa,node bb)
{
	return aa.jiage<bb.jiage;
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>k;
	repd(i,1,n)
	{
		cin>>a[i].jiage>>a[i].shuliang;
	}
	sort(a+1,a+1+n,cmp);
	ll ans=0ll;
	repd(i,1,n)
	{
		ll num=min(k,a[i].shuliang);
		ans+=num*a[i].jiage;
		k-=num;
		if(!k)
			{break;}
	}
	cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

Measured memory_bytes: 1792
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long S;
        S = sc.nextLong();
        solve(S);
    }

    static void solve(long S){
        long e = 1000000000;
        long hoge = S / e;
        long fuga = S % e;

        if(fuga != 0) {
            hoge++;
            fuga = e - fuga;
        }

        System.out.println(0);
        System.out.println(0);
        System.out.println(e);
        System.out.println(fuga);
        System.out.println(1);
        System.out.println(hoge);
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    vector<long long> S(N+1);
    S.at(0) = 0;

    for (int i = 1; i <= N; i++){
        long long A;
        cin >> A;
        S.at(i) = S.at(i-1) + A;
    }
    sort(S.begin(), S.end());
    
    long long answer = 0;
    long long count = 0;
    for (int i = 1; i <= N; i++){
        if (S[i-1] == S[i]){
            count++;
            answer += count;
        }
        else {
            count = 0;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define lson root<<1
#define rson root<<1|1
using namespace std;
 
int n;
int a[200010];
int sum[200010];
 
struct node
{
    int l,r,sum;
}tr[1600080];
 
int push_up(int root)
{
    tr[root].sum=tr[lson].sum+tr[rson].sum;
}
 
int build(int root,int l,int r)
{
    if(l==r)
    {
        tr[root].sum=0;
        tr[root].l=l;
        tr[root].r=r;
        return 0;
    }
    tr[root].l=l;
    tr[root].r=r;
    int mid=(l+r)>>1;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(root);
}
 
int update(int root,int pos)
{
    if(pos==tr[root].l&&pos==tr[root].r)
    {
        tr[root].sum++;
        return 0;
    }
    int mid=(tr[root].l+tr[root].r)>>1;
    if(pos<=mid)
    {
        update(lson,pos);
    }
    else
    {
        update(rson,pos);
    }
    push_up(root);
}
 
int query(int root,int l,int r)
{
    if(l>r) return 0;
    if(l<=tr[root].l&&tr[root].r<=r) return tr[root].sum;
    int mid=(tr[root].l+tr[root].r)>>1;
    if(r<=mid)
    {
        return query(lson,l,r);
    }
    else
    {
        if(l>mid)
        {
            return query(rson,l,r);
        }
        else
        {
            return query(lson,l,mid)+query(rson,mid+1,r);
        }
    }
}
 
int check(int x)
{
    long long ans=0;
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++)
    {
        sum[i]=sum[i-1]+((a[i]<=x)?1:-1);
    }
    for(int i=0;i<=n;i++)
    {
        sum[i]+=n+1;
    }
    build(1,1,200010);
    for(int i=0;i<=n;i++)
    {
        ans+=query(1,1,sum[i]-1);
        update(1,sum[i]);
    }
    return ans>=1ll*n*(n+1)/4+1;
}
 
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int l=1,r=1e9,mid;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid))
        {
            r=mid;
        }
        else
        {
            l=mid+1;
        }
        if(r-l<=1) 
        {
            mid=check(l)?l:r;
            break;
        }
    }
    printf("%d\n",mid);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t; cin >> s >> t;
  sort(all(s));
  sort(all(t), greater<char>());
  cout << (s < t ? "Yes" : "No") << endk;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

#define FOR(i, n, m) for (int i = (n); i < (m); ++i)
#define FORR(i, n, m) for (int i = (m)-1; i >= (n); --i)

ll N, S;

ll f(ll n, ll x) {
  ll res = 0;
  while (x) res += x%n, x/=n;
  return res;
}

int main() {

  cin >> N >> S;
  if (N == S) {
    cout << N+1 << endl;
    return 0;
  }
  if (N < S) {
    cout << -1 << endl;
    return 0;
  }

  ll K = (ll)sqrt(N);

  FOR (k, 2, K+2) if (f(k, N) == S) {
      cout << k << endl;
      return 0;
  }

  FORR (p, 1, K+10) {
    ll q = S - p;
    ll b = (N-q)/p;
    if (b == 1) continue;
    if (f(b, N) == S) {
      cout << b << endl;
      return 0;
    }
  }
  if (S == 1) {
    cout << N << endl;
    return 0;
  }

  cout << -1 << endl;
  return 0;

}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 310000
#define MAX_V 400010
#define vec vector<int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};
ll int inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(int a,int b){
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
vector<int> divisor(int n){
    vector<int> res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}
vec d;
ll m;
map<ll,ll> mp;
ll calc(int k){
    ll sum=modpow(m,(k+1)/2);
    rep(i,d.size()){
        if(k%d[i]==0&&k!=d[i])sum-=mp[d[i]];
        sum=(sum+MOD)%MOD;
    }
    mp[k]=sum;
    return (k%2?sum*k%MOD:sum*k/2%MOD);
}
main(){
    ll n;
    cin>>n>>m;
    calc_inv();
    d=divisor(n);
    sort(d.begin(),d.end());
    ll ans=0;
    rep(i,d.size()){
        ans=(ans+calc(d[i]))%MOD;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
    string s;
    cin>>s;
    ll ans=0,cmp=0;
    for(int i=0;i<s.length();i++){
        cmp+=s[i]-'0';
    }
    
    ans+=(s.length()-1)*9;
    ans+=s[0]-'1';
    cout<<max(ans,cmp)<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	if (m<=2*n){
		printf("%lld\n",m/2);
	}else{
		printf("%lld\n",n+(m-2ll*n)/4);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
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;}
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="Sunny")cout<<"Cloudy";
  if(s=="Cloudy")cout<<"Rainy";
  if(s=="Rainy")cout<<"Sunny";
}


Measured memory_bytes: 256
r, c = gets.split.map(&:to_i)
sum = [0] * c
r.times do
  s = 0
  tmp = gets.split.map(&:to_i)
  c.times do |j|
    s += tmp[j]
    sum[j] += tmp[j]
    printf("%d ", tmp[j])
  end
  puts s
end
s = 0
for x in sum
  s += x
  printf("%d ", x)
end
puts s



Measured memory_bytes: 6888