akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std::literals;
using namespace std;

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

int main()
{
  unsigned long long n, m;
  cin >> n >> m;
  for (auto i = m; i; --i) {
    unsigned long long a;
    cin >> a;
    if (n < a) {
      cout << -1 << endl;
      return 0;
    }
    n -= a;
  }
  cout << n << endl;
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N,K;
  cin >> N >> K;

  LL M = 0;
  REP(i,200000){
    if(i*i>N){
      M = i-1;
      break;
    }
  }

  vector<LL> nums(200000,1);
  REP(i,M){
    nums[2 * M - 1 - i] = N / (i + 1) - N / (i + 2);
  }
  nums[M] = N / M - M;

  vector<LL> dp(200000, 0);
  REP(i,2*M){
    dp[i] = nums[i];
  }
  
  REP(i,K-1){
    vector<LL> newdp(200000, 0);
    LL sum = 0;
    REP(j, 2 * M)
    {
      sum += dp[j];
      sum %= mod;
      newdp[2 * M - 1 - j] = (nums[2 * M - 1 - j] * sum)%mod;
    }
    REP(j,2*M){
      dp[j] = newdp[j];
    }
  }

  LL ans = 0;
  REP(i, 2 * M)
  {
    ans += dp[i];
    ans %= mod;
  }

  cout << ans << endl; 
}

// 1 -> 1~9
// 2 -> 1~4
// 3 -> 1~3
// ? -> 1~3
// 4~4 -> 1~2
// 5~9 -> 1

// 1 -> 1~11
// 2 -> 1~5
// 3 -> 1~3
// 4~5 -> 1~2
// 6~11 -> 1

// 1 -> 1~12
// 2 -> 1~6
// 3 -> 1~4
// 4 -> 1~3
// 5~6 -> 1~2
// 7~12 -> 1


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define REP(i, n) for(LL i=0; i<(n); i++)
#define SORT(x) sort((x).begin(),(x).end())
typedef long long LL;

int main() {
	LL n, k, sum = 0, ans;
	cin >> n >> k;
	vector<pair<LL, LL>> a(n);
	REP(i, n)cin >> a[i].first >> a[i].second;

	SORT(a);
	REP(i, n) {
		sum += a[i].second;
		if (sum >= k) {
			ans = a[i].first;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
n, q = map(int, input().split())
s = input()
lr_array = [[int(x) for x in input().split()] for y in range(q)]

c_array = [0 for x in range(n)]
a_array = [0 for x in range(n)]

for index, char in enumerate(s):
    if s[index] == "C" and s[index-1] == "A":
        tmp = a_array[index-1] + 1
    else:
        tmp = a_array[index-1]
    a_array[index] = tmp
for l, r in lr_array:
    print(abs(a_array[l-1]-a_array[r-1]))



Measured memory_bytes: 25252
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
edges = [tuple(li_()) for _ in range(n-1)]
c = list(li())
c.sort()

visited = [False]*n

graph = [[] for _ in range(n)]
for l, r in edges:
    graph[l].append(r)
    graph[r].append(l)

cnt = 0
num = [0]*n

def dfs(node, graph):
    global cnt
    visited[node] = True
    for nei in graph[node]:
        if not visited[nei]:
            dfs(nei, graph)

    num[node] = c[cnt]
    cnt += 1

dfs(0, graph)

ans = 0
for l, r in edges:
    ans += min(num[l], num[r])

print(ans)
print(*num)

Measured memory_bytes: 14828
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();
	int a, sa, b, sb, t; 
	cin >> a >> sa >> b >> sb >> t; 
	int dis = abs(a - b); 
	if(sb >= sa)
		cout << "NO"; 
	else cout <<(((dis + sa - sb - 1) / (sa - sb) ) <= t ? "YES" : "NO"); 
	return 0;
}

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

a = [0]* N

x = [i for i in range(1,101)]
y = [i for i in range(1,101)]
z = [i for i in range(1,101)]
ans = []
for i in x:
    for j in y:
        for k in z:
            t = (i**2+j**2+k**2+i*j+j*k+k*i)
            if t <= N:
                a[t-1] += 1
            
for i in range(N):
    print(a[i])

Measured memory_bytes: 9296
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
	int N, T;
	cin >> N >> T;
	int cost = INF / 2;
	for (int i = 0; i < N; i++) {
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			cost = min(cost, c);
		}
	}
	if (cost == INF / 2) {
		cout << "TLE" << endl;
		return 0;
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n,m;
    cin>>n>>m;
    vi a(n);
    cin>>a;
    ll sum=0;
    map <ll,ll> count;
    for(ll i=0;i<n;i++)
    {
        sum+=a[i];
        sum%=m;
        count[sum]++;
    }
    ll ans=0;
    for(auto &i:count)
    {
        if(i.F!=0)
            ans+=(i.S)*(i.S-1)/2;
        else
            ans+=(i.S)*(i.S+1)/2;
    }
    cout<<ans<<nl;
}


Measured memory_bytes: 7820
/*Author : Kartik Bansal
 *Date : 07/09/19
 *Time : 16:14 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define tc int t ;cin>>t ;while(t--)
#define pb push_back
#define FOR(i,n) for(int i =0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin() , v.end()
#define sort(v) sort(all(v))
#define vi  vector<int>
#define vll  vector<long long >
#define inf INT_MAX
#define minf INT_MIN
const ll m = 1e9 + 7 ;
int32_t main()
{
  ios::sync_with_stdio(0) ;
  cin.tie(0) ; cout.tie(0) ;

ll cnt = 0 ;
int a , b ;
cin>>a>>b ; 
FOR(i,a+1)
{
       FOR(j,a+1)
       {
              int su = b-i-j ;
              if(su>=0 && su<=a)
                     cnt  = (cnt%m + 1 )%m ;
       }
}

cout <<cnt ;


  return 0 ;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print(A*B)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

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

    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int n, k;
    cin >> n >> k;

    vector<int> l;
    REP(i, n){
        int li;
        cin >> li;
        l.push_back(li);
    }

    sort(l.begin(), l.end(), greater<int>());
    int sum = 0;
    REP(i, k){
        sum += l[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }



int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n,a,b;
    cin >> n >> a >> b;

    if (a % 2 == b % 2) {
        cout << (b-a)/2 << endl;
    } else {
        long long ans = min(n-a, b-1);
        long long tmp = a;
        long long l = 1;
        long long r = b-tmp;
        ans = min(ans, tmp + (r-l)/2);
        tmp = n-b + 1;
        l = a + tmp;
        r = n;
        ans = min(ans, tmp + (r-l)/2);
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
a_list = [-1]
a_tmp = list(map(int, input().split()))
a_list.extend(a_tmp)

ball_list = [0]*(n+1)


for i in reversed(range(1, n+1)):
    div = n // i

    sum_ball = 0
    for j in range(2, div+1):
        sum_ball += ball_list[i*j]

    if a_list[i] == 1:
        if sum_ball % 2 == 0:
            ball_list[i] = 1
    else:
        if sum_ball % 2 == 1:
            ball_list[i] = 1

sb = sum(ball_list)
print(sb)
if sb != 0:
    p_a = [str(i) for i in range(1, n+1) if ball_list[i] == 1]
    print(' '.join(p_a))


Measured memory_bytes: 18712
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N= sc.nextInt();

        int p[]=new int[N];
        for (int i=0;i<N;i++){
            p[i]=sc.nextInt();
        }
        int count=0;

        for (int i=0; i<N;i++){
            if (p[i] != i+1){
                count++;
            }
        }
        if (count==0||count==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }


    }




}


Measured memory_bytes: 20820
import bisect
q=int(input())
ans=[]

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, int((n**0.5)//1+2)):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1] and is_prime[i//2]]
    return table

l_2017=sieve(10**5+1)[1:]

for i in range(q):
    l,r=map(int,input().split())
    ans.append(bisect.bisect_right(l_2017,r)-bisect.bisect_left(l_2017,l))

print(*ans,sep="\n")

Measured memory_bytes: 14928
#include <stdio.h>
 
#define N 10000
 
main()
{
  int i, j, n, q, count = 0;
  int s[N], t[N];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &s[i]);
    }
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    {
      scanf("%d", &t[i]);
    }
 
  for(i = 0; i < q; i++)
    {
      for(j = 0; j < n; j++)
    {
      if(t[i] == s[j])
        {
          count++;
          break;
        }
    }
    }
 
  printf("%d\n", count);
return 0;
}

Measured memory_bytes: 648
#include<stdio.h>
int main(void)
{
  char s[4];
  int i,j;
  int count=0;
  scanf ("%s",&s);
  for(i=0;i<4;i++){
    for (j=0;j<4;j++){
      if(s[i]==s[j]){
        count++;
      }
    }
  }
  if (count != 8){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return 0;
}

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

int main() {
  long long a,b,n;
  cin>>a>>b>>n;
  long long k,l,s;
  k=a/b;
  l=a%b;
  if(n>=b)s=b-1;
  else s=n;
  cout<<k*s+l*s/b<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  for(int i = 0; i < N; i++){ //PWGY
   
  string S;
  cin >> S;
  
  if(S == "P" || S == "W" || S == "G" ){
  
       if(i == N-1){
       cout << "Three" << endl;
       break;
       }   
     
       else{
       continue;
       }  
   }
 
  
  else if(S == "Y"){
  cout << "Four" << endl;
  break;
  }
    
 
    
    
  }
  
  
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = arrayInt(sc, n);
		sc.close();
		int odd = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 1) {
				odd++;
			}
		}
		System.out.println(odd % 2 == 0 ? "YES" : "NO");
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


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

const int INF = 1001001001;
const int NV=100100;

int main() {
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<N;i++){
    cout<<s.at(i)<<t.at(i);
  }
  cout<<endl;  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  if(a==b) cout << "EQUAL" << endl;
  else if(a.size()>b.size())cout << "GREATER" << endl;
  else if(a.size()<b.size()) cout << "LESS" << endl;
  else{
    for(int i=0;i<a.size();i++){ 
      if((int)a[i]>(int)b[i]){
        cout << "GREATER" << endl;
        break;
      }
      else if((int)a[i]<(int)b[i]){
        cout << "LESS" << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#s , t = 'red' , 'blue'
#a , b = 3,4
#u = 'red'

s,t = map(str,input().split())
a,b = map(int,input().split())
u = str(input())

if u == s :
  a -= 1
else :
  b -= 1

print('{} {}'.format(a,b))

Measured memory_bytes: 2940
n ,l = map(int, input().split())
apple = []
for i in range(n):
    apple.append(l + i)

min_num = 10 ** 5
sum_num = sum(apple)
for i in range(n):
    tmp = abs(sum_num - (sum_num - apple[i]))
    if tmp < min_num:
        min_num = min(tmp, min_num)
        flag = apple[i]

if flag >= 0:
    print(sum(apple) - min_num)
else:
    print(sum(apple) + min_num)

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int n,q;
ll k;
std::vector<int> a();

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

    cin >> n >> k >> q;

    std::vector<int> a(q);
    rep(i,q) cin >> a[i];

    std::vector<int> correct(n,0);
    rep(i,q) correct[a[i]-1]++;

    rep(i,n){
        if(correct[i]>=q-k+1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 1408
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
  function compareNumbers(a, b) {
 	 return a - b;
	}
  a.sort(compareNumbers);
 console.log(a[0]+a[1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29632
n = int(input())
arr = list(map(int, input().split()))
print(*arr)
for i in range(1, n):
    key = arr[i]
    j = i - 1
    while j >= 0 and arr[j] > key:
        arr[j + 1] = arr[j]
        j -= 1
    arr[j + 1] = key
    print(*arr)


Measured memory_bytes: 5980
N = int(input())
A = list(map(int, input().split()))
X = [0] * N
X[0] = sum(A) - 2*(sum(A[1::2]))
for i in range(1, N):
    X[i] = 2*A[i-1] - X[i-1]
print(' '.join(str(x) for x in X))

Measured memory_bytes: 19096
#include <stdio.h>
 
int main() {
 
  int n,a[100] = {0};
  int i,j,k,l;
  int sum;
  int suma[30];
  j = 0;
  while(1) {
 int max = -1;
  int min = 10001;
   sum = 0;
 
  scanf("%d",&n);
  if(n == 0){
    break ;}
 
  for(i=0;i<n;i++) {
 
    scanf("%d",&a[i]);
    sum = sum + a[i];
    if(min > a[i] ) {
      min = a[i];
    } if( max < a[i]) {
      max  = a[i];
    }
  } 
 sum = (sum-max-min) / (n-2);
 suma[j] = sum;
 j++;
 
  }
 
  //  printf("sum = %d\n",sum);
  // printf("max = %d min = %d",max,min);
 
  for(i = 0; i < j; i++) {
 
  printf("%d\n",suma[i]);
   
  }
 
  return 0;
 
}

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


int main()
{
	int ans = 0;
	for (int i = 1; i <= 5; i++) {
		int x;
		cin >> x;
		if (x == 0) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;
}


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

int main(){
  int a, b, c, k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if (k < a) printf("%d", k);
  else if (k <= a && k <= a + b) printf("%d", a);
  else printf("%d", a - (k - a - b));
}


Measured memory_bytes: 3752
//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define LINF  0x3f3f3f3f3f3f3f3fll
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 

const ll mod = 999983;
#define mx 1000005
const ll mxi = 3005;

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    ll fl = 0;
    for(int i=0;i<s1.length();i++)
    {
        if(s1[i]!=s2[i])
        {
            return cout<<"No" , 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep1(i,N) cin>>nums[i];
    
    ll cnt=0;
    int pr=0;
    rep1(i,N){
        if((nums[i]+pr)%2){
            cnt+=(nums[i]+pr)/2;
            if(nums[i]) pr=1;
            else pr=0;
        }else{
            cnt+=(nums[i]+pr)/2;
            pr=0;
        }
    }
    cout1(cnt)
}

Measured memory_bytes: 640
import collections
n = int(input())
v = input().split()
v_int = [int(i) for i in v]
v_odd = []
v_even = []
for i in range(int(n/2)):
  v_even.append(v_int[i*2])
  v_odd.append(v_int[i*2+1])
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)
max_odd = 0
second_odd = 0
max_key_odd = 0
for key in c_odd:
  if max_odd < c_odd[key]:
    second_odd = max_odd
    max_odd = c_odd[key]
    max_key_odd = key
  elif second_odd < c_odd[key]:
    second_odd = c_odd[key]
    
max_even = 0
second_even = 0
max_key_even = 0
for key in c_even:
  if max_even < c_even[key]:
    second_even = max_even
    max_even = c_even[key]
    max_key_even = key
  elif second_even < c_even[key]:
    second_even = c_even[key]
    
if max_key_even != max_key_odd:
  print(int(n)- max_even - max_odd)
else:
  if max_even > max_odd:
    if max_even == second_even:
      print(int(n) - max_even - max_odd)
    else:
      print(int(n) - max_even - second_odd)
  elif max_even < max_odd:
    if max_odd == second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)
  else : 
    if second_odd > second_even:
      print(int(n) - max_even - second_odd)
    else :
      print(int(n) - max_odd - second_even)

Measured memory_bytes: 23660
n = int(input())
A_list = list(map(int, input().split()))
ans = 0
dp = [[0, 0] for _ in range(n+1)]
dp[0][0] = 0
dp[0][1] = -float("inf")
for i in range(n-1):
    dp[i+1][0] = max(dp[i][0] + A_list[i], dp[i][1] - A_list[i])
    dp[i+1][1] = max(dp[i][0] - A_list[i], dp[i][1] + A_list[i])
dp[n][0] = max(dp[n-1][0] + A_list[n-1], dp[n-1][1] - A_list[n-1])
print(dp[n][0])


Measured memory_bytes: 73376
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a;
    int l,t,u,k;
    cin >> a;
    l = a.length();
    
    t = 0;
  	u = 0;
  	k = 0;
	if(l % 2 == 1){
    	u = 1;
    }
  	
    for(int i=0; i<l; i++){
        if(t == 0){
            if(a[i] == 'h'){
                t = 1;
              	if(u == 1){
                	if(i == l-1){
                    	k = 0;
                    }  
                }
            }
          	else{
            	k = 0;
                i = l;
            }
        }
        else{
            if(a[i] == 'i'){
                    k += 1;
                    t = 0;
            }
      		else{
              k = 0;
              i = l;
            }
        }
    }

    if(k > 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

bool check(string s,char c)
{
	for(auto x:s)
	{
		if(x==c) return true;
	}
	return false;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
    	string s;
    	cin>>s;
    	if(s=="ABC") cout<<"ARC";
    	else cout<<"ABC";
    }

	return 0;
}

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

int main() {
  ll x;
  cin>>x;
  for(ll i=-1000;i<=1000;i++){
    for(ll j=-1000;j<=1000;j++){
      if((i-j)*(i*i*i*i+i*i*i*j+i*i*j*j+i*j*j*j+j*j*j*j)==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}

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

using namespace std;

int main(void) {
    long long int N, M;
    cin >> N >> M;

    vector<long long int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());

    long long int sumB = 0;
    vector< pair<int,int> > CB;
    for(int j=0; j<M; j++) {
        int B, C;
        cin >> B >> C;
        sumB += B;
        CB.emplace_back(C, B);
    }
    sort(CB.rbegin(), CB.rend());

    int end = min(N, sumB);
    int now = 0;
    for(int j=0; now<N && j<M; j++) {
        for(int k=0; k<CB.at(j).second && now<N; k++) {
            if(A.at(now) < CB.at(j).first) {
                A.at(now) = CB.at(j).first;
            } else {
                break;
            }
            now++;
        }
    }
    cout << accumulate(A.begin(), A.end(), 0LL) << endl;
    return 0;
}

Measured memory_bytes: 2168
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array([int(_) for _ in read().split()], dtype=np.int64)
ABC = ABCQST[:3 * M]
ST = ABCQST[3 * M + 1:]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = G2 <= L
G4 = floyd_warshall(G3, directed=0)
G4[G4 == 0] = 1
G4[G4 == np.inf] = 0
G4 -= 1
print(*G4[S, T].astype(np.int64), sep='\n')


Measured memory_bytes: 35428
n = gets.to_i
ary = []
new_ary = []

(1..n / 2).each do |a|
  b = n - a
  ary << [a, b]
end

ary.each do |a, b|
  sum_a = 0
  while a > 0
    sum_a += a % 10
    a /= 10
  end

  sum_b = 0
  while b > 0
    sum_b += b % 10
    b /= 10
  end

  new_ary << sum_a + sum_b
end

puts new_ary.min

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

int main()
{
  string s,t;
  cin>>s>>t;
  int ans = 1e9;
  for(int si = 0; si<s.size(); ++si){
    if(si + t.size() > s.size()) break;
    int cnt = 0;
    for(int i=0; i<t.size(); i++){
      if(s[i+si] != t[i]) cnt++;
    }
    ans = min(ans, cnt);    
  }
  cout<< ans;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; (i) < ((int)(n)); ++(i))
const ll INF = 1e10;
const ll MOD = 1e9 + 7;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
// MAXの値に注意
const int MAX = 20001;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll ans = 1;
    int S;
    cin >> S;
    if(S < 3)
        cout << 0 << endl;
    else {
        int s = S - 6;
        COMinit();
        for(int i = 1; s >= 0; i++) {
            ans = (ans + COM(i + s, i)) % MOD;
            s -= 3;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4092
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int h,n;
  cin>>h>>n;
  int sum=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    sum+=a;
  }

  cout<<(sum>=h?"Yes":"No")<<endl;

  return 0;
}




Measured memory_bytes: 256
# coding: utf-8
N = int(input())
H = input().split()
ans = 1

for i in range(1,N):
  tmp = 0
  for j in range(i):
    if int(H[i]) < int(H[j]):
      tmp = 1
      break
  if tmp == 0:
    ans += 1
    
print(ans)

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

struct restaurant {
  char s[11];
  int p;
};

int n;


vector <restaurant> v;

int ap[101];

void read() {
  cin >> n;
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i].s >> v[i].p;
    ap[v[i].p] = i + 1;
  }
}

bool cmp(restaurant a, restaurant b) {
  if (strcmp(a.s, b.s) > 0)
    return 0;
  else if (strcmp(a.s, b.s) == 0) {
    if (a.p < b.p)
      return 0;
    else return 1;
  } else return 1;
}

void solve() {
  sort(v.begin(), v.end(), cmp);
  
  for(auto x : v) {
    cout << ap[x.p] << "\n";
  }
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int x;
  int coins[6] = {500, 5, 100, 50, 10, 1};
  int after[6];
  int point = 0;
  scanf("%d", &x);
  for(int i = 0; i < 6; i++) {
    after[i] = x / coins[i];
    x %= coins[i];
    if(i == 0) {
      point += after[i] * 1000;
    } else if(i == 1) {
      point += after[i] * 5;
    }
  }
  printf("%d", point);
  return 0;
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e5 + 5 ; 
const int M = 10 + 5 ; 
int n, m, cnt, dp[N][M], head[N], col[N] ; 
struct Q {
	int v, d, c ; 
} q[N] ;
struct E {
	int to, next ; 
} e[N << 1] ;
void add( int x, int y ) {
	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,
	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 
}
void dfs( int x, int d, int c ) {
	if( d < 0 ) return ;
	if( !col[x] ) col[x] = c ; 
	if( dp[x][d] ) return ;
	dp[x][d] = 1 ; 
	Next( i, x ) {
		int v = e[i].to ; 
		dfs( v, d - 1, c ) ;
	}
}
signed main()
{
	n = gi(), m = gi() ; int u, v ;
	rep( i, 1, m ) u = gi(), v = gi(), add( u, v ) ;
	int T = gi() ;
	rep( i, 1, T ) q[i].v = gi(), q[i].d = gi(), q[i].c = gi() ;
	for( re int i = T; i; -- i ) {
		dfs( q[i].v, q[i].d, q[i].c ) ;
	}
	rep( i, 1, n ) printf("%d\n", col[i] ) ;
	return 0 ;
}

Measured memory_bytes: 9984
import sys
import math

def is_prime(num):
    if num < 2: return False
    elif num == 2: return True
    elif num % 2 == 0: return False
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False
    return True

def call_is_prime(n):
    return [i for i in range(1,n) if is_prime(i)]


def main():
    
    input = sys.stdin.readline
    x = int(input())
    primes = call_is_prime(x+1000)
    ans = [i for i in primes if i>=x]
    print(min(ans))


if __name__ == "__main__":
    main()



Measured memory_bytes: 9340
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <iomanip>
using namespace std;

int gcd(long long a,long long b){
    if(b == 0) return a;
    return gcd( b , a % b);
}

int find(string str, const string& word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos; pos += word.size()) {
    ++count;
  }
  return count;
}

int main(){
    int n,k;
    cin >> n >> k;
    int k_ = 0;
    double win = 0.0;
    double p = 0.0;
    if( k < n){
        win += (double)(n+1-k) / (double) n;
        for(int i=1; i < k; i++){
            k_ = i;
            p = (double) 1 / (double) n; 
            while(k_ < k){
                k_ = 2*k_;
                p =  p * 0.5;
            }
            win += p;
        }
    }
    else{
       for(int i=1; i < n+1; i++){
            k_ = i;
            p = (double) 1 / (double) n; 
            while(k_ < k){
                k_ = 2*k_;
                p =  p * 0.5;
            }
            win += p;
        } 
    }
    cout << fixed;
    cout << setprecision(12) << win << endl;
}

Measured memory_bytes: 256
<?php
list($n,$m,$x,$y) = explode(" ",trim(fgets(STDIN)));
$l = explode(" ",trim(fgets(STDIN)));
$r = explode(" ",trim(fgets(STDIN)));
$a = max($l);
$b = min($r);
if($a<$b&&$b>$x){
  while($a<$b){
    $a++;
    if($a>=$x&&$a<=$y){
      echo "No War";
      exit;
    }
  }
  if($a>=$b){
    echo "War";
  }
}else{
  echo "War";
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int W,H,N;
    cin >> W >> H >> N;
    // true is white
    vector<vector<bool>> v(H,vector<bool>(W, true));
    REP(_,N) {
        int x,y,a;
        cin >> x >> y >> a;
        if (a==1)  REP(i,H)REP (j,x) v[i][j] = false;
        if (a==2)  REP(i,H)FOR (j,x,W) v[i][j] = false;
        if (a==3)  REP(i,y)REP (j,W) v[i][j] = false;
        if (a==4)  FOR(i,y,H)REP (j,W) v[i][j] = false;
    }
    int cnt =  0;
    REP(i,H)REP(j,W) cnt += v[i][j];
    cout << cnt << endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>

int main(void){
  int c,i,g=0,j=0;
  
  scanf("%d",&c);
  
  for(i=1;i <= 10;i++){
    	g = c - (1000*i);
    	j = c -(1000*(i+1));
    if(0 < g){
     
    }
    else{
    	if(0 <= abs(g) && abs(g) < 1000){	
          if(abs(g) < abs(j)){
          	printf("%d",abs(g));
            break;
          }
          else{
          	printf("%d",abs(j));
            break;
          }
    	}
    }
  }
  
  return 0;
}

Measured memory_bytes: 1736
N = int(input())
a = list(map(int, input().split()))

N = 10**5
cnt = [0 for i in range(N+2)]
# index 0 == -1
for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1

print(max(cnt))


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

signed main () {
	int n, k, p;
	cin >> n >> k;
	vector < double > pref(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		cin >> p;
		pref[i + 1] = pref[i] + (double(p + 1) / 2.0);
	}
	double ans = 0;
	for (int i = k; i <= n; ++i)
		ans = max(ans, pref[i] - pref[i - k]);
	cout << fixed << setprecision(30) << ans << '\n';
}


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

int main(){
    int H,W;
    cin >> H >> W;
    string c;
    for (int i = 0 ; i < W + 2; i++){
        cout << "#";
    }
    cout << endl;
    for (int i = 0; i < H ; i++){
        cin >> c;
        cout << "#" << c << "#" << endl;
    }
    for (int i = 0; i < W + 2; i++){
        cout << "#";
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=1e5+100;
int n,a,b,c,sh[N];
string f,s;
signed main()
{
	scanf("%d%d%d%d",&n,&a,&b,&c);
	for (int i=1;i<=n;i++)
	{
		cin>>s;
		if (s[0]=='A' && s[1]=='B') sh[i]=1;
		if (s[0]=='B' && s[1]=='C') sh[i]=2;
		if (s[0]=='A' && s[1]=='C') sh[i]=3;
	}
	for (int i=1;i<=n;i++)
	{
		if (sh[i]==1)
		{
			if (a==0 && b==0)
			{
				printf("No\n");
				return 0;
			}
			if (a==b && a==1 && c==0)
			{
				if (sh[i+1]==1 || i==n) f.push_back('A');
				else if (sh[i+1]==2) f.push_back('B');
				else if (sh[i+1]==3) f.push_back('A');
			}
			else
			if (a>b) f.push_back('B');
			else f.push_back('A');
			if (f[(int)f.size()-1]=='A') a++,b--;
			else a--,b++;
		}
		if (sh[i]==2)
		{
			if (b==0 && c==0)
			{
				printf("No\n");
				return 0;
			}
			if (b==c && b==1 && a==0)
			{
				if (sh[i+1]==1) f.push_back('B');
				else if (sh[i+1]==2 || i==n) f.push_back('B');
				else if (sh[i+1]==3) f.push_back('C');
			}
			else
			if (b>c) f.push_back('C');
			else f.push_back('B');
			if (f[(int)f.size()-1]=='B') b++,c--;
			else b--,c++;
		}
		if (sh[i]==3)
		{
			if (a==0 && c==0)
			{
				printf("No\n");
				return 0;
			}
			if (a==c && a==1 && b==0)
			{
				if (sh[i+1]==1) f.push_back('A');
				else if (sh[i+1]==2) f.push_back('C');
				else if (sh[i+1]==3 || i==n) f.push_back('A');
			}
			else
			if (a>c) f.push_back('C');
			else f.push_back('A');
			if (f[(int)f.size()-1]=='A') a++,c--;
			else a--,c++;
		}
	}
	printf("Yes\n");
	for (int i=0;i<(int)f.size();i++) printf("%c\n",f[i]);
}

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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;

  long long ans=a*c;
  ans=max(ans,a*d);
  ans=max(ans,b*c);
  ans=max(ans,b*d);

  cout << ans << endl;

}

Measured memory_bytes: 3628
n = int(input())
for i in range(n):
	s = input()

	ss = set()

	for i in range(len(s)-1):
		s1 = s[0:i+1]
		s2 = s[i+1:]
		ss.add(s1+s2)
		ss.add(s1+s2[::-1])
		ss.add(s1[::-1]+s2)
		ss.add(s1[::-1]+s2[::-1])
		ss.add(s2+s1)
		ss.add(s2+s1[::-1])
		ss.add(s2[::-1]+s1)
		ss.add(s2[::-1]+s1[::-1])
	print(len(ss))

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

using Int = int;
using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

int main(){
	Int k, n;
	cin >> k >> n;
	vector<Int> a(n);
	RC(i, n) cin >> a[i];
	Int ans = 0;
	RC(i, n - 1) anth(ans, a[i + 1] - a[i]);
	anth(ans, k + a[0] - a[n - 1]);
	cout << k - ans << endl;
}


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

int main()
{
    int H, W;
    char a[102][102];

    cin >> H >> W;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i <= H + 1; i++)
    {
        for (int j = 0; j <= W + 1; j++)
        {
            if (i == 0 || i == H + 1 || j == 0 || j == W + 1)
            {
                cout << "#";
            }
            else
            {
                cout << a[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  uint32_t N = 0;
  std::string S;
  std::cin >> N >> S;
  uint32_t count = 0;
  for (size_t i = 0; i < N - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') count++;
  }
  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define Mod 998244353
#define ha "YES"
#define na "NO"
#define sp " "
typedef long long ll;

void IO()
{
#ifndef ONLINE_JUDGE
	freopen("pracin.txt", "r", stdin);
	freopen("pracout.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	fast;
}
vector<bool> used;
vector<vector<int>> adj;
vector<int> dir[200005];
vector<int> a, b;
//bipartite graph or not using bfs

void bfs(int i)
{
	queue<int> q;
	q.push(i);
	used[i] = 1;
	a.push_back(i);
	while (!q.empty())
	{	i = q.front();
		q.pop();
		for (auto vertex : adj[i])
		{
			if (used[vertex] == -1)
			{
				used[vertex] = used[i] ^ 1;
				if (used[vertex] == 1) a.push_back(vertex);
				else b.push_back(vertex);
				q.push(vertex);
			}
			if (used[vertex] == used[i]) {
				cout << -1;
				exit(0);
			}

		}


	}
}
// binnary exponention (logn)
ll binary_exponention(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binary_exponention(a, b / 2);
	if (b % 2)
		return res * res * a % Mod;

	return res * res % Mod;
}


// remember the question's fine details
// BE CAREFUL OF EDGE CASES....
// always check for edges cases
//  n == 1, n = size - 1, n is prime ,we




void solve()
{

	int n, m; cin >> n >> m;
	char  mat[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)  cin >> mat[i][j];

	int dp[n][m];
	dp[0][0] =  1;
	for (int j = 1; j < m; j++)
	{
		if (mat[0][j] == '#') dp[0][j] = 0;
		else  dp[0][j] = dp[0][j - 1];
	}
	for (int j = 1; j < n; j++)
	{
		if (mat[j][0] == '#') dp[j][0] = 0;
		else  dp[j][0] = dp[j - 1][0];
	}
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
		{
			if (mat[i][j] == '#') dp[i][j] = 0;
			else dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	cout << dp[n - 1][m - 1];
}


int main()
{
	IO();

	// int t; cin >> t; while (t--)
	solve();
}

Measured memory_bytes: 13180
a, b, c, x, y = map(int, input().split())
ans = 50000 * 10 ** 5
for i in range(max(x, y) + 1):
  ansa = max(x - i, 0)
  ansb = max(y - i, 0)
  sm = a * ansa + b * ansb + 2 * c * i 
  if ans > sm:
    ans = sm
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include <string.h>
#include <math.h>
#include <unordered_map>


using namespace std;


int n, k, a[200000], at;

std::unordered_map<int, int> um;
vector<int> v;

int main()
{
	int tmp;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> at;
		auto no = um.find(at);
		if (no == um.end()) {
			um.emplace(at, 1);
		}
		else {
			no->second ++;
		}
	}

	for (auto it = um.begin(); it != um.end(); ++it) {
		v.push_back(it->second);
	}


	tmp = 0;
	sort(v.begin(), v.end());

	for (int i = v.size(); i > k; i--) {
		tmp+= v[v.size()-i];
	}

	cout << tmp << endl;

	return 0;
}


Measured memory_bytes: 10312
n = int(input())
ai = [int(i) for i in input().split()]

tmp = 0
ans = 0
old = 0

a_mnmx = [[0 for i in range(2)] for j in range(n+1)]
#print(a_max)
old = ai[n]

a_mnmx[n][0] = old
a_mnmx[n][1] = old

for i in range(n):
    a_mnmx[n-i-1][0] = (a_mnmx[n-i][0]+1)//2 + ai[n-i-1]
    a_mnmx[n-i-1][1] = a_mnmx[n-i][1] + ai[n-i-1]
    
#print(a_mnmx)

if a_mnmx[0][1] < 1 or a_mnmx[0][0] > 1:
    print(-1)
    exit()

old = 1
ans = 1

for i in range(n):
    old = min(a_mnmx[i+1][1],old*2)
    ans += old
    old -= ai[i+1]
    #print(old)
    
print(ans)

Measured memory_bytes: 31056