akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>                          //include all library
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1


int n;
int f[100][10], p[100][11];

void solve()
{
	long long int maxi = -9999999999;
	FOR(num, 1, 1024)
	{
		int a[10];
		int x = num;
		REP(i,10)
		{
			a[i] = num%2;
			num /= 2;
		}
		num = x;

		long long sum = 0;
		REP(i,n) 
		{
			int count = 0;
			REP(j,10) if(f[i][j]*a[j]==1) count++;
			sum += p[i][count];
		}

		maxi = max(maxi, sum);
	}
	cout << maxi << endl;
}

int main()
{
	cin >> n;
	REP(i,n) REP(j,10) cin >> f[i][j];
	REP(i,n) REP(j,11) cin >> p[i][j];

	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef map<int, int> M;
typedef pair<int, int> P;

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

    itn n, m;
    cin >> n >> m;
    vector<P> vp(m);
    for (int i = 0; i < m; ++i) cin >> vp[i].second >> vp[i].first;
    sort(vp.begin(), vp.end());
    int res = 0;
    int last = 0;
    for (int i =0; i < m; ++i)
    {
        if (vp[i].second >= last)
        {
            last = vp[i].first;
            ++res;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
sx,sy,tx,ty = map(int,input().split())

dx = tx-sx
dy = ty-sy
ans = ''
ans += 'R'*dx + 'U'*dy + 'L'*dx + 'D'*dy
dx+=1
dy+=1
ans +='D'+'R'*dx+'U'*dy+'L'
ans +='U'+'L'*dx+'D'*dy+'R'
print(ans)


Measured memory_bytes: 3316
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let r: u16 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = if r < 1200 {
        "ABC"
    } else if r < 2800 {
        "ARC"
    } else {
        "AGC"
    };
    println!("{}", ans);
}


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

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

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

const ll mod=1e9+7;

ll n_sum(ll x){
    ll cnt=1;
    for(int i=1; i<=x; ++i){
        cnt*=i;
        cnt%=mod;
    }
    return cnt;
}

int main(){
    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>1){cout<<0<<endl; return 0;}
    if(abs(n-m)==1){
        cout<<n_sum(n)*n_sum(m)%mod<<endl;
    }
    else{
        cout<<n_sum(n)*n_sum(m)%mod*2%mod<<endl;
    }
}

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

using namespace std;

int main(){
    int n,m;
    const int mod=1000000007;
    cin>>n>>m;
    vector<bool> a(n,false);
    vector<long long int> dp(n+1);

    for(int i=0;i<m;i++){
        int tmp;
        cin>>tmp;
        a[tmp]=true;
    }
    dp[0]=1;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<=min(i+2,n);j++){
            if(!a[j]){
                dp[j] += dp[i];
                dp[j]%=mod;
            }
        }
    }
    cout<<dp[n];
}


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

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = input[0];
            var X = input[1];

            var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var sum = 0;
            for (int i = 0; i < N; i++)
            {
                if ((sum += L[i]) > X)
                {
                    Console.WriteLine(i + 1);
                    return;
                }
            }
            Console.WriteLine(N + 1);
        }
    }
}

Measured memory_bytes: 13396
n = int(input())
s = list(input())
ans = 1001001
wn = 0
en = sum([1 for i in s[1:] if i == 'E'])
for i in range(n):
    ans = min(ans, wn + en)
    if s[i] == 'W':
        wn += 1
    if i != n - 1:
        if s[i + 1] == 'E':
            en -= 1
print(ans)

Measured memory_bytes: 11084
n,k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("").map{|c| c == "L" ? -1 : 1}

score = 0
s.each_cons(2) do |c1, c2|
  if c1 == c2 then
    score += 1
  end
end

puts [score + 2 * k, n - 1].min


Measured memory_bytes: 10236
import sys
a, b, c, d = (int(i) for i in input().split())
if b-c<=0 or d-a<=0 or b-a<=0 or d-c<=0:
    print(0)
    sys.exit()
else:
    an = min(b-a,d-c,b-c,d-a)
    print(an)


Measured memory_bytes: 2940
n = gets.to_i
ss = gets.chars

min = Float::INFINITY

dp = {l_w: 0, r_w: ss.count{|s| s == "W"}, l_e: 0}
dp[:r_e] = n - dp[:r_w]

n.times do |i|
  if ss[i] == "W"
    dp[:r_w] -= 1
  else
    dp[:r_e] -= 1
  end

  if i > 0
    if ss[i-1] == "W"
      dp[:l_w] += 1
    else
      dp[:l_e] += 1
    end
  end

  count = dp[:l_w] + dp[:r_e]
  min = [min, count].min
end

puts min

Measured memory_bytes: 27148
#include<stdio.h>
 
int main(){
    int a;
    while(~scanf("%d",&a)){
        int ans=0;
        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
                for(int k=0;k<10;k++)
                    for(int l=0;l<10;l++)
                        if(i+j+k+l==a)ans++;
        printf("%d\n",ans);
    }
}

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

int main(){
    int n,t,cost,time,mincost=10000;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>cost>>time;
        if(time<=t){
            mincost=min(mincost,cost);
        }
    }
    if(mincost==10000){
        cout<<"TLE"<<endl;
    }else{
        cout<<mincost<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int K;
  cin >> S >> K;
  vector<vector<int>> dp(S.size()+1, vector<int>(S.size()+1));
  for(auto i = 0; i < S.size(); ++i) dp[i][i+1] = 1;
  for(auto k = 0; k <= K; ++k) {
    auto dup = dp;
    for(auto w = 2; w <= S.size(); ++w) for(auto l = 0; l+w <= S.size(); ++l) {
      auto r = l + w;
      dp[l][r] = max({dp[l][r], dp[l+1][r], dp[l][r-1]});
      if(k)            dp[l][r] = max(dp[l][r], 2 + dup[l+1][r-1]);
      if(S[l]==S[r-1]) dp[l][r] = max(dp[l][r], 2 + dp[l+1][r-1]);
    }
  }
  cout << dp[0][S.size()] << endl;
}


Measured memory_bytes: 1096
class Union_find():
    def __init__(self, N):
        self.Group = [i for i in range(N)]
        
    def find(self,x):# find(a)=find(b)のとき同じグループ
        while self.Group[x] != x:
            x = self.Group[x]
        return x

    def Union(self,x,y):  # xとyが同じグループになるよう更新
        if self.find(x) != self.find(y):
            self.Group[self.find(y)] = self.Group[self.find(x)] = min(self.find(y),self.find(x))
    
    
N,q = map(int,input().split())
A = Union_find(N)

for _ in range(q):
    com,x,y = map(int,input().split())

    if com == 0:
        A.Union(x,y)

    else:
        if A.find(x) == A.find(y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 5980
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N; cin >> N; vector<ll> A(N); FOR(i, N) cin >> A[i];
	// RUISEKI
	vector<ll> Rui(N); Rui[0] = A[0];	

	ll ans = 0;
	if (Rui[0] <= 0) {
		ans += -Rui[0] + 1;
		Rui[0] = 1;
	}
	FOR(i, N - 1) {
		Rui[i + 1] += Rui[i] + A[i + 1];

		if (i + 1 >= 1 and Rui[i+1] * Rui[i] >= 0) {
			if (Rui[i + 1] * Rui[i] == 0 and Rui[i] > 0) {
				ans += 1; Rui[i + 1] = -1;
			}
			else if (Rui[i + 1] * Rui[i] == 0 and Rui[i] < 0) {
				ans += 1; Rui[i + 1] = 1;
			}
			else { // 両方とも同じ符号になった場合
				if (Rui[i + 1] > 0) {
					ans += Rui[i + 1] + 1;
					Rui[i + 1] = -1;
				}
				else {
					ans += - Rui[i + 1] + 1;
					Rui[i + 1] = 1;

				}
			}
		}
	}

	///////////////////////////////////////////////
/////////              ///////////////
///////////////////////////////////////////////

	Rui.clear(); Rui.resize(N); Rui[0] = A[0];
	ll tmp = 0;
	if (Rui[0] >= 0) {
		tmp += Rui[0] + 1;
		Rui[0] = -1;
	}
	FOR(i, N - 1) {
		Rui[i + 1] += Rui[i] + A[i + 1];
		
		if (i + 1 >= 1 and Rui[i + 1] * Rui[i] >= 0) {
			if (Rui[i + 1] * Rui[i] == 0 and Rui[i] > 0) {
				tmp += 1; Rui[i + 1] = -1;
			}
			else if (Rui[i + 1] * Rui[i] == 0 and Rui[i] < 0) {
				tmp += 1; Rui[i + 1] = 1;
			}
			else { // 両方とも同じ符号になった場合
				if (Rui[i + 1] > 0) {
					tmp += Rui[i + 1] + 1;
					Rui[i + 1] = -1;
				}
				else {
					tmp += -Rui[i + 1] + 1;
					Rui[i + 1] = 1;

				}
			}
		}
	}
	
	chmin(ans, tmp);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int N, M; double P;
int U[109], V[109], K[1 << 14]; vector<int> X[109];
double dp[1 << 14], power[1 << 14];

void init() {
	for (int i = 0; i < (1 << N); i++) {
		int cnts = 0;
		for (int j = 0; j < M; j++) {
			if ((i / (1 << U[j])) % 2 == 1 && (i / (1 << V[j])) % 2 == 1) cnts++;
		}
		K[i] = cnts;
	}
	for (int i = 0; i < 109; i++) power[i] = pow(P, 1.0 * i);
}

int main() {
	cin >> N >> M >> P; P = 0.01 * P;
	for (int i = 0; i < M; i++) {
		cin >> U[i] >> V[i]; U[i]--; V[i]--;
		X[U[i]].push_back(V[i]);
		X[V[i]].push_back(U[i]);
	}

	init();

	for (int i = 1; i < (1 << N); i++) {
		for (int j = 1; j < i; j++) {
			if ((i & j) != 0) continue;

			double prob1 = (1.0 - dp[i]);
			int s2 = K[i + j] - K[i] - K[j];
			double prob2 = power[s2];
			
			dp[i + j] += prob1 * prob2;
		}
	}
	printf("%.12lf\n", 1.0 - dp[(1 << N) - 1]);
	return 0;
}


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll n;cin>>n;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    int b[n];
    b[0]=0;
    for(ll i=1;i<n;i++){
        if(b[i-1]==0){
            if(h[i]>=h[i-1]){
                b[i]=0;
            }else if(h[i]==h[i-1]-1){
                b[i]=1;
            }else{
                b[i]=2;
            }
        }else if(b[i-1]==1){
            if(h[i]>=h[i-1]+1){
                b[i]=0;
            }else if(h[i]==h[i-1]){
                b[i]=1;
            }else{
                b[i]=2;
            }
        }else{
            b[i]=2;
        }
    }
    if(b[n-1]==2){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}



Measured memory_bytes: 1408
main :: IO()
main = getContents >>= putOut.formatOut.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
   
formatIn :: String -> [[Double]]
formatIn = map (map read.words).tail.lines

formatOut :: [Double] -> String
formatOut = unlines.map (show.(/1000000).realToFrac.floor.(*1000000))
 
solve :: [[Double]] -> [Double]
solve (xs:ys:_) = map (minkowski xs ys) [1,2,3,(1/0)]

minkowski :: [Double] -> [Double] -> Double -> Double
minkowski x y p | isInfinite p = maximum $zipWith ((abs.).(-)) x y 
                | otherwise    = (**(1/p)).sum $zipWith ((((**p).abs).).(-)) x y 

Measured memory_bytes: 4488
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(void) {
	int N,M;
	cin >> N >> M;
	vector< vector<int> > edge(N+1);
	int s,t;
	for (int i = 0; i < M; ++i) {
		cin >> s >> t;
		edge[s].push_back(t);
	}

	int step = 0;
	bool goal = false;
	queue<int> now;
	queue<int> deep;
	now.push(1);
	int np,nd = 0;
	while (nd < 2 && !goal && !now.empty()) {
		np = now.front();
		now.pop();
		for (int i = 0; i < edge[np].size(); ++i) {
			if (edge[np][i] == N) {
				goal = true;
			}
			now.push(edge[np][i]);
			deep.push(nd+1);
		}
		nd = deep.front();
		deep.pop();
	}

	if (goal) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}


Measured memory_bytes: 9336
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
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[] = new String[N];
		Map<Character, Long> map = new HashMap<>();
		map.put('M', 0L);
		map.put('A', 0L);
		map.put('R', 0L);
		map.put('C', 0L);
		map.put('H', 0L);
		for (int i = 0; i < N; i++) {
			char c = sc.next().charAt(0);
			if (map.containsKey(c)) {
				map.put(c, map.get(c)+1);
			}
		}
		int cnt = 0;
		int idx = 0;
		ArrayList<Long> w = new ArrayList<>();
		for (Entry<Character, Long> e : map.entrySet()) {
			if (e.getValue()!=0) {
				w.add(e.getValue());
				cnt++;
				idx++;
			}
		}
		if (cnt<=2) {
			System.out.println(0);
			return;
		}
		long ans = 0;
		if (cnt == 3) {
			ans = 1;
			for (int i = 0; i < w.size(); i++) {
				ans *= w.get(i);
			}
			System.out.println(ans);
			return;
		}

		if (cnt == 4) {
			long tmp = 1;
			for (int i = 0; i < w.size(); i++) {
				tmp *= w.get(i);
			}
			for (int i = 0; i < w.size(); i++) {
				ans += tmp/w.get(i);
			}
			System.out.println(ans);
		}

		int P []={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
		int Q []={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
		int R []={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};

		if (cnt == 5) {
			ans = 0;
			for (int i = 0; i < 10; i++) {
				ans += w.get(P[i])*w.get(Q[i])*w.get(R[i]);
			}

			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 46828
x=int(input())

if 1800<=x:
    print(1)
elif 1600<=x:
    print(2)
elif 1400<=x:
    print(3)
elif 1200<=x:
    print(4)
elif 1000<=x:
    print(5)
elif 800<=x:
    print(6)
elif 600<=x:
    print(7)
else:
    print(8)


Measured memory_bytes: 9168
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

a,b,x = map(int,input().split())
if a == 0:
    ans = b//x + 1
else:
    ans = b//x - (a-1)//x
print(ans)

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int maxn = max({A, B, C});
  int ans  = A + B + C - maxn;
  for (int i = 0; i < K; i++)
    maxn *= 2;
  cout << ans + maxn << '\n';
  return 0;
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> sum(10*100000+1, 0);
vector<bool> broken(10*100000+1, false);

long long N, M;
vector<ll> A;

void fibo_memo(ll n) {
  if (n == 1 && !broken[n]) sum[n] = 1;
  else if (n == 2 && !broken[n]) sum[n] = sum[n-1]+1;
  else {
    if (!broken[n]) sum[n] = (sum[n-1] + sum[n-2]) % mod;
  }
}

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

  cin >> N >> M;
  A.resize(M);
  rep(i, M) {cin >> A[i]; broken[A[i]] = true;}
  for(ll i = 1; i <= N; i++) {
    fibo_memo(i);
  }
  cout << sum[N] << endl;
  return 0;
}

Measured memory_bytes: 9088
#include<stdio.h>

int main()
{
 int N;
 int K;
 long x[100005];
 long dist;
 long mindist=200000005;
 long distp;
 long distm;
 int i;

 scanf("%d %d",&N,&K);
 for(i=0;i<N;i++) scanf("%ld",&x[i]);
 mindist=2*(x[N-1]-x[0]);

 for(i=K-1;i<N;i++)
 {
  distp=abs(x[i])+abs(x[i]-x[i-K+1]);
  distm=abs(x[i]-x[i-K+1]) + abs(x[i-K+1]);
  if(distp<distm)
  {
   dist=distp;
  }else{
   dist=distm;
  }
  if(mindist>dist) mindist=dist;
 }
 printf("%ld\n",mindist);
 return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(1e9+7)
using namespace std;
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}
signed main(){
	fastIO

    int N, n;
    cin >> N >> n;
    for (int i = 0, a; i < n; i++){
        cin >> a;
        N -= a;
    }
    if (N < 0) cout << -1 << endl;
    else cout << N;


    return 0;

}


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

int main(){
    int N,K;
    cin >> N >> K;
    long long h[N];
    for(int i=0;  i<N; i++){
        cin >> h[i];
    }
    sort(h,h+N);
    long long ans = 10000000000;
    for(int i=0; i<N-K+1; i++){
        if(ans > h[i+K-1] - h[i]) ans = h[i+K-1] - h[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {

	int w, h;

	while(cin >> w >> h) {
		if(!w&&!h) {
			break;
		}
		char s[100][100];
		for(int i=0; i<w; i++) {
			for(int j=0; j<h; j++) {
				cin >> s[i][j];
			}
		}
		int c=0, x=0, y=0;
		while(c<w*h) {
			(s[x][y]=='>') && y++;
			(s[x][y]=='<') && y--;
			(s[x][y]=='^') && x--;
			(s[x][y]=='v') && x++;
			if(s[x][y]=='.') {
				break;
			}
			c++;
		}
		if(c!=w*h) {
			cout << y << " " << x << endl;
		}
		else {
			cout << "LOOP" << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-k){
    if(a[i]<a[i+k])cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

    string str;
    str = "abcdefghijklmnopqrstuvwxyz";
    
    char c;
    cin >> c ;

    for(int i = 0;i < str.size();i++){
        if(c == str.at(i)){
            cout << str.at(i+1) << endl;
        }
    }


return 0;
}

Measured memory_bytes: 256
s = input().rstrip().split(' ')
width = int(s[0])
height = int(s[1])
x = int(s[2])
y = int(s[3])
r = int(s[4])
if x - r >= 0 and x + r <= width and y - r >= 0 and y + r <= height:
 print("Yes")
else:
 print("No")


Measured memory_bytes: 5596
K,S = map(int,input().split())
if S == 0:
  print(1)
  exit()
z = 0
o = 0
t = 0
start = min(S,K)
for i in reversed(range(start+1)):
  if i < (S-1)//3 + 1:
    break
  else:
    num = min(S-i,i)-(S-i+1)//2 + 1
    z += num
    if num == 1:
      if (S-i) % 2 == 0 or min(S-i,i) == i:
        z -= 1
        o += 1
    else:
      if (S-i) % 2 == 0:
        z -= 1
        o += 1
      if min(S-i,i) == i:
        z -= 1
        o += 1
        
      
if S % 3 == 0:
  t += 1
  o -= 1
print(z*6 + o*3 + t)

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  string s;cin>>s;
  ll a;cin>>a;

  string ans="";
  for(ll i=0;i<s.size();i+=a){
    ans+=s[i];
  }
  out(ans);

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    string s; cin >> s;
    int N = s.size();
    vector<int> v(30);
    string ans = s;
    rep(i, N) v[s[i]-'a']++;
    
    bool flag = false;
    if(N != 26) {
        rep(i, 26) {
            if(v[i] == 0) {
                ans += (char)'a'+i;
                break;
            }
        }
    } else {
        rep(i, 25) {
            // 後ろから見ていって、降順でなくなったとき
            if(ans[25-i] > ans[24-i]) {
                char c = ans[24-i];
                ans[24-i] = 'z';
                REP(j, 25-i, 26) {
                    if(c < ans[j]) ans[24-i] = ans[j];
                }
                ans.erase(ans.end()-(i+1), ans.end());
                flag = true;
                break;
            }
        }
        if(!flag) {
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long res = n/(a+b);
		long mod = n%(a+b);
		if(mod>=a)
			mod = a;
		
		System.out.println(res*a+mod);
}

}


Measured memory_bytes: 23764
n,x,y=map(int,input().split())
s= input()
c=0
d=x+y
e = 0
f= False
for i in range(n):
    if s[i]=="a":
        if c<d:
            f=True
    elif s[i]=="b":
        if c<d and e<y:
            f=True
            e+=1
    if f:
        print("Yes")
        c+=1
    else:
        print("No")
    f=False

Measured memory_bytes: 9240
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        boolean[] prime = new boolean[N+1];
        Arrays.fill(prime, true);
        prime[0] = true;
        prime[1] = true;
        for (int i = 2; i * i <= N; i++) {
            if (!prime[i]) {
                continue;
            }
            for (int j = 2; i * j <= N; j++) {
                prime[i*j] = false;
            }
        }
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= N; i++) {
            if (prime[i]) {
                primes.add(i);
            }
        }
        int[] dp = new int[N+1];
        Arrays.fill(dp, -1);
        dp[1] = 1;
        int len = primes.size();
        for (int i = 2; i <= N; i++) {
            if (prime[i]) {
                dp[i] = 2;
                continue;
            }
            for (int j = 0; j < len; j++) {
                if (i % primes.get(j) != 0) {
                    continue;
                }
                int x = primes.get(j);
                int current = i;
                int count = 0;
                int t = 1;
                while (current % x == 0) {
                    count += 1;
                    current /= x;
                    t *= x;
                }
                if (count == 1) {
                    dp[i] = dp[x] * dp[i/x];
                } else {
                    dp[i] = (dp[t/x] + 1)*dp[i/t];
                }
                break;
            }
        }

        long ans = 0;
        for (int i = 1; i <= N; i++) {
            ans += (long) i * (long) dp[i];
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 119416
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<u64>()[0];
    let (mut left, mut right) = (1, 10_000_000);

    while left < right{
        let mid = (left+right)/2;
        if mid*(mid+1)/2 < n{
            left = mid + 1;
        }else{
            right = mid;
        }
    }
    let max = left;
    let mut rest = n - max;
    for i in (1..max).rev(){
        if rest >= i{
            println!("{}", i);
            rest -= i;
        }
        if rest == 0{
            break;
        }
    }
    println!("{}", left);
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A < 9){
    if (B < 9){
      cout << "Yay!" << endl;
    }
    else {
      cout << ":(" << endl;
    }
  }
  else {
    cout << ":(" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
//#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
Graph G,T;
//int n;
 
/*void dfs(int v,int p){

   
    for (int i = 0; i < G[v].size(); i++)
    {
      if(G[i].first==p) continue;
      dfs(np.first ,v);

    }

}*/
int x[100010],y[100010];
int cnt[100010];
signed main(){
  int n;
  cin>>n;
  G.assign(n,vector<int>());
  T.assign(n,vector<int>());
  vector<pair<int,int>>vp;
  for (int i = 0; i < n-1; i++)
  {
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
    vp.emplace_back(a,b);
    //G[a].back().second=G[b].back().second=max((int)G[a].size(),(int)G[b].size());
   // T[a].push_back({b, G[a].back().second});
  }
  int K=0;
  for (int i = 0; i < n-1; i++)
  {
    if(K<(int)G[i].size()) K=(int)G[i].size();
  }
  //cout<<K<<endl;
  map<pair<int,int>,int>I;
  vector<bool>used(n,false);
  vector<int>cs(n,0);
  queue<int>q;
  q.emplace(0);
  used[0]=true;
  while(!q.empty()){
    int v=q.front();q.pop();
    int cur=1;
    for(int u: G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur;
      cur++;
      used[u]=true;
      q.emplace(u);
      }
  }
  cout<<K<<endl;
  for(auto p :vp) cout<<I[p]<<endl; 
    return 0;
}

Measured memory_bytes: 22132
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	std::string s, t;
	std::cin >> s >> t;
	if(s.size()>t.size()){
		puts("GREATER");
		return 0;
	} else if(s.size()<t.size()){
		puts("LESS");
		return 0;
	} else {
		REP(i, 0, s.size()){
			if(s[i]>t[i]){
				puts("GREATER");
				return 0;
			} else if(s[i]<t[i]){
				puts("LESS");
				return 0;
			}
		}
		puts("EQUAL");
	}
	return 0;
}




Measured memory_bytes: 3636
import math

a,b,x=map(int,input().split())

if x==a**2*b:
    print(0.0)
elif x>a**2*b/2:
    print(90.0-math.degrees(math.atan(a**3/(2*a**2*b-2*x))))
else:
    print(90.0-math.degrees(math.atan(2*x/(a*b**2))))


Measured memory_bytes: 3060
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (inputString)
{
  const stringArray = inputString.split(' ');
  const a = Number(stringArray[0]);
  const b = Number(stringArray[1]);
  let result = '';
  
  if (a < b) {
    result ='<';
  } else if(a > b){
    result ='>';
  } else {
    result ='==';
  }
  
  const output = 'a ' + result + ' b'
  console.log(output);
});


Measured memory_bytes: 15244
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define ld long double
#define FAST ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define ins insert
#define ph push
#define mmst(x,v) memset(x,v,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define LLINF ((long long)1e18)
#define MAXN 300006
#define FOR(i,s,e) for(ll i=s;i<e;i++)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
ll n, A[MAXN];
ll bstar(ll x) {
	ll ans = 0;
	for(ll i=1;i<=n;i++) {
		ans += llabs(A[i] - (x+i));
	}
	return ans;
}
int main()
{
	FAST
	cin>>n;
	for(ll i=1;i<=n;i++)cin>>A[i];
	// for(ll i=-10;i<=10;i++) {
		// cerr<<bstar(i)<<' ';
	// }
	// cerr<<'\n';
	ll st=-1e9-MAXN, en = 1e9 + 2, lmid = 0, umid = 0;
	while(en-st > 2) {
		lmid = st+(en-st)/3;
		umid = en-(en-st)/3;
		if(bstar(lmid)>bstar(umid))st=lmid;
		else en=umid;
	}
	cout<<bstar((st+en)>>1ll)<<'\n';
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    string res = "";

    int i = 0;
    while(abs(n) > 0){
        if(abs(n) % 2){
            res = '1' + res;
            n -= (i % 2 ? -1:+1);
        }
        else {
            res = '0' + res;
        }
        n /= 2;
        i++;
    }
    if(res == "") res = "0";

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n;
string stn;

string tostr(ll x)
{
    string res="";
    string tmp = "0";

    while(x)
    {
        tmp[0] = x%10;
        x/=10;
        res+=x;
    }

    return res;
}

ll query(ll x)
{
    cout << "? " << x << "\n";
    cout.flush();

    char c='N';
    cin >> c;

    return (c=='Y');
}

ll EX(ll v,ll e)
{
    ll p = 1;

    rep(i,0,e)
        p*=v;
        return p;
}

int main()
{
    ios_base::sync_with_stdio(false);

    if(query(1000000000000))
    {
        ll low = 1;
        ll high = 11;
        ll digits = 12;

        while(low <= high)
        {
            ll mid = (low+high)/2;

            bool q = query(EX(10,mid)-1);

            if(q)
            {
                high=mid-1;
                digits=min(digits,mid);
            }
            else
            {
                low=mid+1;
            }
        }

        cout << "! "<<EX(10,digits-1) << "\n";
        cout.flush();
        return 0;
    }

    ll low = 1;
    ll high = 9;
    ll digits = 1;

    while(low <= high)
    {
        ll mid = (low+high)/2;

        bool q = query(EX(10,mid));

        if(q)
        {
            low = mid+1;
            digits = max(digits,mid+1);
        }
        else
        {
            high=mid-1;
        }
    }

    ll answer = 0;

    rep(i,0,digits-1)
    {
        low = 0;
        high = 9;
        ll d = 0;

        while(low <= high)
        {
            ll mid = (low+high)/2;

            bool q = query(answer*10+mid);

            if(q)
            {
                low=mid+1;
                d=max(d,mid);
            }
            else
            {
                high=mid-1;
            }
        }

        answer = answer*10+d;
    }

    low = 0;
    high = 9;
    ll d = 9;

    while(low <= high)
    {
        ll mid = (low+high)/2;

        bool q = query(answer*100+10*mid+0);

        if(q)
        {
            high=mid-1;
            d=min(d,mid);
        }
        else
        {
            low=mid+1;
        }
    }

    answer = answer*10+d;

    cout << "! " <<answer << "\n";
    cout.flush();

    return 0;
}



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

i = 2
N_ = N
ans = 0

divisor = {}
for i in range(2,N):
    if N_ % i == 0:
        divisor[i] = 0
        while(N_ % i == 0):
            divisor[i] += 1
            N_  //= i
#;            print(N_,i)
    if i *i > N_:
        if N_ != 1:
            if N_ in divisor.keys():
                divisor[N_] += 1
            else:
                divisor[N_] = 1
        break

ans += 0
def solve(dic,keys,n,i):
    if i == len(keys):
#        print(n)
        if n-1 != 0 and N == (N % (n-1))*n:
            global ans
            ans += n-1

    else:
        for j in range(dic[keys[i]]+1):
            solve(dic,keys,n*keys[i]**j,i+1)

#print(divisor)
ans = 0 
solve(divisor,list(divisor.keys()),1,0)
print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

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

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	string O, E;
	cin >> O >> E;

	string ans;
	while (E.size() > 0) {
		ans += O[0];
		O = O.substr(1, O.size() - 1);
		ans += E[0];
		E = E.substr(1, E.size() - 1);
	}
	if (O.size() > 0) ans += O[0];

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  int ans = 0;
  FOR(i, 1, n + 1) {
    FOR(j, 1, n + 1) {
      FOR(k, 1, n + 1) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> a(n,0);
    for(int i = 0; i < n; ++i){
        if(s[i]=='I') a[i]++;
        else a[i]--;
        if(i != 0) a[i] += a[i-1];
    }
    int xnum = 0;
    for(int num:a){
        xnum = max(xnum,num);
    }
    cout << xnum << endl;   
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int parent[500003];
int ranks[500003];
void init()
{
    for(int i=0;i<500002;i++)
    {
        parent[i]=i;
         ranks[i]=0;
    }
}
int find_p(int x)
{

    if(x!=parent[x])
    {
        return parent[x]=find_p(parent[x]);
    }
    else
        return x;
}
void union_p(int x,int y){
int px=find_p(x);
int py=find_p(y);
if(px==py)
    return;

if(ranks[px]<=ranks[py])
{
    parent[px]=py;
    ranks[py]++;

}
else{
        parent[py]=px;
    ranks[px]++;

}

}
int main()
{
    int a,b,c,d,e,i;

    cin >> a >> b;
    init();
    while(b--)
    {
        cin >> c >> d;
        union_p(c,d);
    }
    map<int,int>mp;
    for(i=1;i<=a;i++)
    {
        mp[find_p(i)]++;
    }
    int l=0;
    for(i=1;i<=a;i++)
    {
        l=max(mp[i],l);
    }
    cout <<  l << endl;

}


Measured memory_bytes: 16912
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, cnt = 0;

void dfs(int k, ll last){
    if(k > 9 || last > n) return;
    ll tmp = last;
    int a = 0, b = 0, c = 0;
    while(tmp > 0){
        int s = tmp%10;
        tmp/=10;
        if(s == 3) a = 1;
        if(s == 5) b = 1;
        if(s == 7) c = 1;
        if(a && b && c) break;
    }
    if(last <= n && a && b && c) cnt++;
    dfs(k+1, last*10+3);
    dfs(k+1, last*10+5);
    dfs(k+1, last*10+7);
}

int main()
{
    scanf("%lld", &n);
    dfs(0, 0);
    printf("%lld\n", cnt);
    return 0;
}

Measured memory_bytes: 760
printedlater = []
while True:
    n = int(input())
    if (n == 0): # the end of input
        break
    c = [x for x in input().split()]
    voteNum = {}
    for cand in list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
        voteNum[cand] = 0
    while True:
        if (len(c) == 0):
            voteMax = max(voteNum.values())
            winners = [x for x in voteNum.keys() if voteNum[x] == voteMax]
            if (len(winners) == 1):
                printedlater.append(winners[0] + " " + str(n))
            else:
                printedlater.append("TIE")
            break
        voteNum[c.pop(0)] += 1
        vote2ndMax, voteMax = sorted(voteNum.values())[-2:]
        if voteMax - vote2ndMax > len(c):
            printedlater.append([x for x in voteNum.keys() if voteNum[x] == voteMax][0] + " " + str(n - len(c)))
            break
for line in printedlater:
    print(line)


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

using namespace std;

#define MAX 6001
#define INF 1e9

struct State{
  int dist,v,cap;
  State(int dist,int v,int cap) 
    : dist(dist),v(v),cap(cap) {}

  bool operator > (const State &s)const{
    return dist > s.dist;
  }
};

struct Edge{
  int to,dist;
  Edge(int to,int dist) : to(to),dist(dist) {}
};

int N,M,cap,src,dst,idx;
set<int> LPG;
vector<Edge> G[MAX];

void init(){
  idx = 1;
  LPG.clear();
  for(int i = 0 ; i < MAX ; i++){
    G[i].clear();
  }
}

int dijkstra(){
  vector<vector<int> > dist(idx);
  cap *= 10;
 
  for(int i = 0 ; i < idx ; i++){
    dist[i].resize(cap+1);
    for(int j = 0 ; j <= cap ; j++){
      dist[i][j] = INF;
    }
  }

  dist[src][cap] = 0;

  priority_queue<State,vector<State>,greater<State> > Q;
  Q.push(State(0,src,cap));

  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int v = s.v,c = s.cap;
    
    if(dist[v][c] < s.dist) continue;
    
    if(v == dst){
      return dist[v][c];
    }

    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      int nc = (LPG.find(v) != LPG.end()) ? cap : c;
      if(e.dist <= nc){
        nc -= e.dist;
        if(dist[v][c] + e.dist < dist[e.to][nc]){
          dist[e.to][nc] = dist[v][c] + e.dist;
          Q.push(State(dist[e.to][nc],e.to,nc));
        }                           
      }
    }
  }
  return -1;
}

int main(){
  int d;
  string a,b;
  
  while(cin >> N >> M >> cap, N){
    init();
    map<string,int> mp; 
    cin >> a; mp[a] = src = idx++; 
    cin >> a; mp[a] = dst = idx++; 
    for(int i = 0 ; i < N ; i++){
      cin >> a >> b >> d;
      if(mp.find(a) == mp.end()){
        mp[a] = idx++;
      }
      if(mp.find(b) == mp.end()){
        mp[b] = idx++;
      }
      G[mp[a]].push_back(Edge(mp[b],d));
      G[mp[b]].push_back(Edge(mp[a],d));
    }
    for(int i = 0 ; i < M ; i++){
      cin >> a;
      LPG.insert(mp[a]);
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 51768
#include<bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
 
int main() {
	int n,k,a[100]={0};
	cin>>n>>k;
	while(k--)
	{
		int d;
		cin>>d;
		for(int i=0;i<d;i++)
		{
			int p;
			cin>>p;
			a[p-1]++;
		}
	}
	int ans =0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

const int MAXN = 555;

char f(int n) {
    if (n == 0) {
        return 'R';
    } else if (n == 1) {
        return 'G';
    } else if (n == 2) {
        return 'B';
    } else {
        return 'Y';
    }
}

int main() {
    //ifstream cin("input.txt");
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int n, m, d;
    cin >> n >> m >> d;
    for (int i = 0; i < n; ++i) {
        string s;
        for (int j = 0; j < m; ++j) {
            int x = 0;
            x += ((i + j) / d) & 1;
            x += 2 * (((n - i + j) / d) & 1);
            s += f(x);
        }
        cout << s << "\n";
    }

}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

int n,k;
int v[100];
int ans;

int s[100];
int t;

int main()
{
    int max_ans = -1000000000;
    cin>>n>>k;
    for (int i=1; i<=n; ++i)
        cin>>v[i];
    for (int i=0; i<=n; ++i)
    {
        for (int j=n+1; j>i; --j)
        {
            t=0;
            for (int o=1; o<=i; ++o)
                s[t++]=v[o];
            for (int o=n; o>=j; --o)
                s[t++]=v[o];
            int nowk = i+(n-j+1);
            if (nowk>k) continue;
            sort(s,s+t);
            int nowans=0;
            for (int o=0; o<t; ++o)
            {
                if (s[o]>0) nowans+=s[o];
                if (s[o]<0)
                {
                    if (nowk<k) 
                    {
                        nowk++;
                    }
                    else
                    {
                        nowans+=s[o];
                    }
                }
            }
            if (nowans>max_ans)
                max_ans=nowans;
        }
    }
    cout<<max_ans<<endl;
    return 0;
}



Measured memory_bytes: 256