akhauriyash/Code-Regression huggingface dataset:
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

string form(int x) {
  string ret = to_string(x);
  while(ret.size() < 6) {
    ret = "0" + ret;
  }
  return ret;
}

int main(){
  
  int n, m; cin >> n >> m;
  vector<lint> p(m);
  vector<lint> y(m);
  vector<set<lint>> st(n);
  for(int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    st[p[i] - 1].insert(y[i]);
  }

  map<lint, lint> mp;
  for(int i = 0; i < n; i++) {
    int id = 1;
    for(auto x : st[i]) {
      mp[x] = id;
      id++;
    }
  }

  for(int i = 0; i < m; i++) {
    cout << form(p[i]) << form(mp[y[i]]) << endl;
  }

  return 0;
}


Measured memory_bytes: 18688
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j][k] - sum is i, j number of elements, first k elements
    OPT[i][j][k] = OPT[i-x[k]][j-1][k-1] if j-th element is taken
                   OPT[i][j][k-1]

    OPT[A*j][j][k] for all k
    """
    N, A = read_ints()
    x = read_ints()
    OPT = [[[0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N*max(x)+1)]
    for k in range(N+1):
        OPT[0][0][k] = 1
    for i in range(len(OPT)):
        for j in range(1, N+1):
            for k in range(j, N+1):
                if i-x[k-1] >= 0:
                    OPT[i][j][k] += OPT[i-x[k-1]][j-1][k-1]
                OPT[i][j][k] += OPT[i][j][k-1]
    T = 0
    for j in range(1, N+1):
        if A*j < len(OPT):
            T += OPT[A*j][j][N]
    return T


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 139160
# include<iostream>
 # include<algorithm>
 # include<cmath>
 using namespace std;
 const int MOD = pow(10,9)+7;
 int main()
 {
 unsigned long long  N,K;
 	 cin>>N>>K;
 	 int A[N];
 	 for(int i=0;i<N;i++)
 	{
 	 	 cin>>A[i];
	}
 unsigned	long long sum = 0;
    for(int i=0;i<N;i++)
    {
    	 for(int j=i+1;j<N;j++)
    	 {
    	 	 if(A[i]>A[j])
    	 	 {
    	 	 	 sum++;
			  }
		 }
	}

    sum*=K;
    sum = sum%MOD;
    unsigned long long sum1=0;
    for(int i=0;i<N;i++)
    {
    	for(int j=0;j<N;j++)
    	{
    		 if(A[i]>A[j])
    		 {
    		 	 sum1++;
			 }
		}
	}
	sum1 = sum1*(((K-1)*K/2)%MOD);
	sum1 = sum1%MOD;
	
 unsigned	long long  sum2 = (sum+sum1)%MOD;
	cout<<sum2<<endl;
	
	
	
 }

Measured memory_bytes: 256
import math
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(float, input().split()))
    mu = sum(s) / n
    dev = 0
    for d in s:
        dev += (d - mu)**2
    stdev = math.sqrt(dev / n)
    print(stdev)



Measured memory_bytes: 5768
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll H, N; std::cin >> H >> N;
  std::vector<int> A(N);
  rep(i,N) std::cin >> A[i];

  ll Sum = 0;
  rep(i,N) Sum += A[i];

  if ( H > Sum ) std::cout << "No" << std::endl;
  else std::cout << "Yes" << std::endl;
  return 0;
}


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

bool dp[100001];

int main(){
    int n,k;
    scanf(" %d %d",&n,&k);
    int nums[n];
    for(int i = 0; i < n;++i) scanf(" %d",&nums[i]);
    dp[0] = false;
    for(int i = 1; i <=k;++i){
        for(int j = 0; j < n;++j){
            if(i - nums[j] >= 0)
                dp[i] = dp[i] | !dp[i-nums[j]];
        }
    }
    if(dp[k])
        puts("First");
    else puts("Second");
    return 0;
}


Measured memory_bytes: 384
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
v1 = V[0::2]
v2 = V[1::2]
v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()
v1c.append((0, 0))
v2c.append((0, 0))

if v1c[0][0]==v2c[0][0]:
    print(min(N-v1c[0][1]-v2c[1][1], N-v1c[1][1]-v2c[0][1]))
else:
    print(N-v1c[0][1]-v2c[0][1])


Measured memory_bytes: 21084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main {
 
    public static void main(String[] args) throws IOException {
 
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
 
        String input;
         
         while (!(input = in.readLine()).equals("0 0")) {
 
             String[] HW = input.split(" ");
 
             int H = Integer.parseInt(HW[0]);
             int W = Integer.parseInt(HW[1]);
 
             for(int i=0;i<H;i++){
                 for(int j=0;j<W;j++){
                     System.out.print("#");
                 }
                 System.out.println();
             }
             System.out.println();
              
         }
 
    }
}

Measured memory_bytes: 31248
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define fi first
#define se second

vector<P> G;
signed main(){
	int h, w, n;
	scanf("%lld%lld%lld", &h, &w, &n);
	
	for(int i = 0;i < n;i++){
		int x[2], y[2];
		scanf("%lld%lld%lld%lld", &y[0], &x[0], &y[1], &x[1]);
		if(y[0] && y[0] != h && x[0] && x[0] != w)continue;
		if(y[1] && y[1] != h && x[1] && x[1] != w)continue;
		
		for(int j = 0;j < 2;j++){
			if(y[j] == 0)G.push_back(P(x[j], i));
			else if(x[j] == w)G.push_back(P(1+w+y[j], i));
			else if(y[j] == h)G.push_back(P(2+h+w+(w-x[j]), i));
			else if(x[j] == 0)G.push_back(P(3+2*w+h+(h-y[j]), i));
		}
	}
	sort(G.begin(), G.end());
	
	stack<int> st;
	map<int,int> mp;
	int ans = 1;
	for(int i = 0;i < G.size();i++){
		//for(int j = 0;j < G[i].size();j++){
			int p = G[i].se;
			if(!st.empty()){
				if(st.top() == p)st.pop();
				else st.push(p);
				/*if(mp[p] == 0){
					mp[p] = 1;
					st.push(p);
				}else{
					if(st.top() == p){st.pop();mp[p] = 0;}
					else ans = 0;
				}*/
			}else{st.push(p);mp[p] = 1;}
		//}
	}
	if(st.empty())printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  double n,m,d; cin >> n >> m >> d;
  double ans = (n-d)*(m-1)/(n*n);
  if(d != 0) ans *= 2;
  cout << fixed << setprecision(10) << ans << endl;
}

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;

int main() {
    ll N, A, S = 0;
    cin >> N;
    rep(i, N) {
        cin >> A;
        S += A;
    }
    if (S % 2) cout << "NO\n";
    else cout << "YES\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    if(B<=C||D<=A){
        printf("0");    //ok
    }else if(A<=C){
        if(D<=B){
            printf("%d",D-C);
        }else{
            printf("%d",B-C);
        }
    }else if(C<A){
        if(B<=D){
            printf("%d",B-A);
        }else{
            printf("%d",D-A);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using pint = pair<ll, ll>;

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main(){
    ll N;
    cin >> N;
    ll out = 1;
    for (int i = 0; i < N; i++) {
      ll a;
      cin >> a;
      out = lcm(out, a);
    }
    cout << out<< endl;

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, d, k = 0;
    cin >> n >> d;
    long long x[n], y[n];
    for (long long i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i];
        if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) k++;
    }
    cout << k;
}

Measured memory_bytes: 6772
using System;

namespace caddi2018_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool ret = true;
            for (int i = 0; i < n; i++) if (int.Parse(Console.ReadLine()) % 2 == 1) ret = false;
            Console.WriteLine(!ret ? "first" : "second");
        }
    }
}

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

int main() {

    int n;
    cin >> n;
    
    rep(i, n) {
        rep(j, n) if(n - 4*i == 7*j) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String);
    if s == "AAA" || s == "BBB" {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 8572
a = []

n,k = map(int, input().split())
for x in range(k+1):
  a.append(0)
q = input()

p = 0
c = 0
mx = 0

for i in range(n-1):
  p = p+1
  c = c+1  
  if q[i] == q[i+1]:
    lalala = 1

  elif (int(q[i]) == 1) & (int(q[i+1]) == 0) :
    p = p-a[0]
    if p > mx:
      mx = p
    
  elif (int(q[i]) == 0) & (int(q[i+1]) == 1):
    a.pop(0)
    a.append(c)
    c = 0

if int(q[n-1]) == 1:
  if p+1- a[0]> mx:
    mx = p +1 - a[0]
else:
  if p+1 -a[1] > mx:
    mx = p  -a[1] +1
  
  


print(mx)

Measured memory_bytes: 4016
#include<stdio.h>
int main(){
	char a[3];
	scanf("%s",a);
	bool f=0,b=0;
	if(a[0]=='A') f=1;
	else if(a[0]=='B') b=1;
	if(a[1]=='A') f=1;
	else if(a[1]=='B') b=1;
	if(a[2]=='A') f=1;
	else if(a[2]=='B') b=1; 
	if(f==1&&b==1) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        int a = readInt();
        pw.println(a + a * a + a * a * a);
        pw.close();
    }
}


Measured memory_bytes: 32964
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
  int n,cnt=0;
  long x,a[100],sa[100][100],flag=0;
  scanf("%d %ld",&n,&x);
  for(int i=0;i<n;i++)
    scanf("%ld",&a[i]);
  sort(a,a+n);
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      sa[i][j]=a[j]-a[i];
  for(int i=0;i<n;i++){
    if(x>=a[i]){
      cnt++;
      x-=a[i];
    }
    else
      break;
  }
  if(cnt>0&&x!=0&&n-cnt==0){
    cnt--;
  }
  printf("%d\n",cnt+flag);
}

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

typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define fi first
#define se second
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n;
    cin >> n;

    map<int,int> mp;
    int num;
    for (int i=0; i<n; ++i) {
        cin >> num;
        mp[num-1]++;
        mp[num]++;
        mp[num+1]++;
    }

    int maxi = 0;
    for (auto e:mp)
        maxi = max(maxi, e.se);

    cout << maxi << endl;
}}

Measured memory_bytes: 4736
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);
  int[] a; readA(n, a);

  auto p = new int[][](m+1);
  foreach (int i, ai; a) p[ai] ~= i;

  auto k = 0, c = 0L;
  foreach (i; 0..n-1)
    if (a[i] > a[i+1]) {
      ++k;
      c += a[i+1];
    } else {
      c += a[i+1]-a[i];
    }

  auto ans = c;
  foreach (i; 1..m) {
    c -= k;

    foreach (j; p[i]) {
      if (j > 0) {
        --k;
        c += a[j-1] > a[j] ? a[j]+m-a[j-1] : a[j]-a[j-1];
      }
      if (j < n-1)
        ++k;
    }

    ans = min(ans, c);
  }

  writeln(ans);
}


Measured memory_bytes: 4924
import copy
H, W, K = list(map(int, input().split()))
c = []
for _ in range(H):
    s = input()
    tmp = []
    for one in s:
        if one=='#':
            tmp.append(1)
        else:
            tmp.append(0)
    c.append(tmp)


h = 1<<H
w = 1<<W
cnt = 0
for j in range(h):
    tmp_c = copy.deepcopy(c)#.copy()
    for p in range(H):
        if j>>p & 1==1:
            tmp_c[p] = [0]*W
    
    for i in range(w):
        tm_c = copy.deepcopy(tmp_c)#.copy()
        for q in range(W):
            if i>>q & 1==1:
                for k in range(H):
                    tm_c[k][q] = 0
        if sum([sum(one) for one in tm_c])==K:
            cnt+=1
print(cnt)

Measured memory_bytes: 76340
n = int(raw_input())
m = int(raw_input())
cards = range(n * 2)
for i in range(m):
    k = int(raw_input())
    if k == 0:
        cards = [c for (a,b) in zip(cards[:n],cards[n:]) for c in (a,b)]
    else:
        cards = cards[k:] + cards[:k]

for c in cards:
    print c + 1

Measured memory_bytes: 4240
n,k = map(int, input().split())
vl = list(map(int, input().split()))    

ans = 0
ab_max = min(n,k)
for l in range(ab_max+1):
    for r in range(ab_max+1):
        if l+r > k: continue
        if l > n-r: continue
        ls = vl[:l]
        rs = vl[n-r:]
        # print(ls,rs)
        vals = ls + rs
        rem = k-(l+r)
        # print(rem)
        vals.sort()
        curr_sum = sum(vals)
        for i in range(rem):
            if i >= len(vals): break
            if vals[i] < 0: curr_sum -= vals[i]
            else: break
        # print(curr_sum)
        ans = max(ans,curr_sum)

print(ans)
        

Measured memory_bytes: 73776
#include <cstdio>

int main() {
	int a, b, c;
	scanf("%d %d %d\n", &a, &b, &c);
	if (a < b) {
		if (b < c) {
			printf("%d %d %d\n", a, b, c);
		} else {
			if (a < c) {
				printf("%d %d %d\n", a, c, b);
			} else {
				printf("%d %d %d\n", c, a, b);
			}
		}
	} else {
		if (b > c) {
			printf("%d %d %d\n", c, b, a);
		} else {
			if (a < c) {
				printf("%d %d %d\n", b, a, c);
			} else {
				printf("%d %d %d\n", b, c, a);
			}
		}
	}
}

Measured memory_bytes: 1028
#include<stdio.h>
int main(){
  int i,j,k,l,n,o,max,mi;
  while(scanf("%d %d",&l,&n),l||n){
    int a[2][101][101]={0};
    int m[2][101][101]={0};
    while(l--){
      scanf("%d %d %d %d",&i,&j,&k,&o);
      m[0][i][j]=m[0][j][i]=k;
      m[1][i][j]=m[1][j][i]=o;
    }
    for(o=0;o<2;o++){
      for(i=1;i<=n;i++){//start
	int c[101]={0};
	c[i]=1;
	mi=i;
	for(k=0;k<n;k++){
	  for(j=1;j<=n;j++){
	    if(c[j]==1)continue;
	    if(m[o][mi][j]==0)continue;
	    if(a[o][i][j]==0)a[o][i][j]=a[o][i][mi]+m[o][mi][j];
	    else if(a[o][i][j]>a[o][i][mi]+m[o][mi][j]){
	            a[o][i][j]=a[o][i][mi]+m[o][mi][j];
	    }
	  }
	  max=2100000000;
	  for(j=1;j<=n;j++){
	    if(c[j]==1)continue;
	    if(a[o][i][j]==0)continue;
	    if(max>a[o][i][j]){
	      max=a[o][i][j];
	      mi=j;
	    }
	  }
	  c[mi]=1;
	}
      }
    }
    scanf("%d",&n);
    while(n--){
      scanf("%d %d %d",&i,&j,&k);
      printf("%d\n",a[k][i][j]);
    }
  }
  return 0;
}

Measured memory_bytes: 764
n = int(input())
a = list(map(int, input().split()))

r = 0
ref = 0
ans = 0
for l in range(n):
    while r < n and ref & a[r] == 0:
        ref ^= a[r]
        r += 1

    ans += r-l

    if r == l:
        r += 1
    else:
        #refからa[l]削除
        ref ^= a[l]
print(ans)


Measured memory_bytes: 24844
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main()
{
    int num;
    cin >> num;
    
    if(num == 0)
    {
        cout << 1 << endl;
    }
    if (num == 1)
    {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;

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

  int ans = n;
  for(int i = 0; i <= n; i++){
    int tmp = (i - sum[i]) + (sum[n] - sum[i]);
    ans = min(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1404
io = STDIN
a,b=io.gets.split.map(&:to_i)
def calc(x)
  if x.even?
    ((x/2).even? ? 0 : 1)^x
  else
    ((x+1)/2).even? ? 0 : 1
  end
end
p calc(a-1)^calc(b)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll> > edges[n];
    bool flg[n]={};
    ll inf = 1LL<<60;
    ll place[n];
    rep(i,n){place[i]=inf;}
    rep(i,m){
        ll l,r,d;
        cin>>l>>r>>d;
        l--;r--;
        edges[r].push_back(make_pair(l,d));
        edges[l].push_back(make_pair(r,-d));
    }
    ll cur=0;
    queue<ll> que;
    while(cur<n){
        DEBUG{cout << cur << endl;}
        place[cur]=0;
        flg[cur]=true;
        que.push(cur);
        while(!que.empty()){
            ll now = que.front();
            for(auto x:edges[now]){
                if(place[x.first]==inf){
                    que.push(x.first);
                    place[x.first]=place[now]+x.second;
                    flg[x.first]=true;
                }else if(place[x.first]!=place[now]+x.second){
                    printf("No\n");
                    return 0;
                }
            }
            que.pop();
        }
        while(cur<n&&flg[cur]){
            cur++;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <regex>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stack>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

ll X[100005], Y[100005], t[100005];

ll mhd(ll x1, ll y1, ll x2, ll y2) {
    return abs(x1 - x2) + abs(y1 - y2);
} 

int main () {
    ll N;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> t[i] >> X[i] >> Y[i];
    }
    for (int i = 0; i < N; i++)
    {
        ll dt = t[i + 1] - t[i];
        ll d = mhd(X[i], Y[i], X[i + 1], Y[i + 1]);
        if(dt < d) {
            cout << "No" << endl;
            return 0;
        }else {
            if((dt - d) % 2 == 1) {
                cout << "No" << endl; 
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 2560
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

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


int rec(string status, vector<vector<int>> s, vector<int> p,int N, int M);

int main(){
    int i;
    int j;
    int N,M;
    int tmp;
    
    
    cin >> N >> M;
    vector<int> k(M);
    vector< vector<int> > s(M);
    vector<int> p(M);
    
    for(i=0;i<M;i++){
        cin >> k[i];
        for(j=0;j<k[i];j++){
            cin >> tmp;
            s[i].push_back(tmp);
        }
    }
    for(i=0;i<M;i++) cin >> p[i];
    
    
    cout << rec("0",s,p,N,M) + rec("1",s,p,N,M) << endl;
    
    
    
    return 0;
}

int rec(string status, vector<vector<int>> s, vector<int> p, int N, int M)
{
    int i,j;
    int tmp;
    
    
    
    if(status.length() < N){
        return rec(status+"0", s, p, N, M) + rec(status+"1", s, p, N, M);
    } else {
        for(i=0;i<M;i++){
            tmp = 0;
            
            for(j=0 ; j < s[i].size() ; j++){
                tmp += status[ s[i][j]-1 ];
            }
            if(tmp % 2 != p[i]) return 0;
        }
        // cout << status << endl;
        return 1;
    }
}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

vector<int> v;

int solve(int i, int rest)
{
	if(i == v.size()){
		if(rest == 1) return 1;
		else return 0;
	}
	int ans = 0;
	for(int j = 1; j <= v[i] + 1; j++){
		if(rest % j == 0) ans += solve(i + 1, rest / j);
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	int cnt[101] = {};
	for(int i = 1; i <= n; i++){
		int tmp = i;
		for(int j = 2; j <= n; j++){
			if(tmp % j == 0){
				cnt[j]++;
				tmp /= j;
				j--;
			}
		}
	}
	for(int i = 2; i <= 100; i++){
		if(cnt[i] > 0){
			v.push_back(cnt[i]);
		}
	}
	cout << solve(0, 75) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
        int n,k;
    scanf("%d %d",&n,&k);
    char str[n];
    for(int i=0;i<n;i++){
        scanf("%s",&str[i]);
    }
    str[k-1]=str[k-1]+32;
    printf("%s\n",str);
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll d,t,s;
    cin>>d>>t>>s;
    
    if(t*s>=d)
        cout<<"Yes"<<endl;
    
    else 
        cout<<"No"<<endl;
        
	return 0;
}


Measured memory_bytes: 3636
a = ["AC", "WA", "TLE", "RE"]
ans = [0]*4
n = int(input())
l = [input() for _ in range(n)]
for i in l:
    for j in range(4):
        if i == a[j]:
            ans[j] += 1

for k in range(4):
    print(a[k] + " x " + str(ans[k]))

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    int n;
    cin>>n;
    //vector<int>v(n);
    int cnt[n+1]={};

    rep(i,n-1){
        int a;
        cin>>a;
        cnt[a]++;
    }
    rep2(i,n){
        cout<<cnt[i]<<endl;
    }


    //sort(v.begin(),v.end());

    //int cnt[100010]={};
    /*
    rep(i,n-1){
        cnt[v[i]]++;
    }
    map<int,int>ans;
    rep2(i,100000){
        if(cnt[i]){
        ans.emplace(make_pair(i,cnt[i]));
        }
    }
    rep(i,n){
        auto it=ans.find(v[i]);
        it++;
        if(it==ans.end()){
            cout<<"0"<<endl;
        }
        else{
            cout<<it->first<<endl;
        }
    }
    */
    return 0;

}
/*


*/


Measured memory_bytes: 4332
#include <iostream>                                                      
using namespace std;                                                     
                                                                         
int main() {                                                             
  int a, b, c;                                                           
  cin >> a >> b >> c;                                                    
  int ans = 0;                                                           
  for (int i=a; i<=b; i++) {                                             
    if (c%i==0) {                                                        
      ans++;                                                             
    }                                                                    
  }                                                                      
  cout << ans << endl;                                                   
  return 0;                                                              
}                                                                        
                      

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

int main()
{
    int a,b=0;
    
    while (cin >> a >> b){
        a += b;
    for (b=1; a>=10; b++) {
        a /= 10;
    }
        cout << b << endl;
    }
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 10;
int n,m;
bool g[N][N];
int ans = 0;
void solve(int v,vector<int> city){
	if (city.size() == n){
		ans++;
	//	printv(city);
		return;
	}
	for(int i = 1; i <= n; i++)
		if (g[v][i]){
			bool ok = 1;
			for(int j = 0; j < city.size(); j++)
				if (i == city[j])
					ok = 0;
			if (ok){
				vector<int> t = city;
				t.push_back(i);
				solve(i,t);
			}
		}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x,y;
		cin >> x >> y;
		g[x][y] = g[y][x] = 1;
	}
	solve(1,{1});
	cout << ans << endl;
  	return 0;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = 1 << 30;
  for (int i = 0; i < N - K + 1; ++i) ans = min(ans, h[i + K - 1] - h[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>n;
    
    c=0;
    mii m;
    // vi v(50);
    // fo(i,50)
    // {
    //     v[i]=i*(i+1)/2;
    // }
    while(n%2==0)n/=2,m[2]++;

    for(i=3;i*i<=n;i+=2)
    {
      while(n%i==0)n/=i,m[i]++;

    }
    
    if(n!=1)m[n]++;
    
    for(auto p:m)
    {
        x=p.ss;
        y=1;
        while(y*(y+1)/2<=x)y++;
        c+=y-1;
    }


    cout<< c <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}


Measured memory_bytes: 3648
def resolve():
    n = int(input())
    ans = [0] * 2
    for i in range(n):
        s = input().split()
        if s[0] == s[1]:
            ans[0] += 1
            ans[1] += 1
        elif s[0] < s[1]:
            ans[1] += 3
        else:
            ans[0] += 3
    print(*ans)


resolve()



Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
using namespace std;

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

      int t=1;
      //cin>>t;
      while(t--)
      {
               int x,n,res=0;
               cin>>x>>n;
               if(n==0)
                    res = x;
               else{
               int a[n];
               set<int>s;
               for(int i=0;i<n;++i)
               {
                    cin>>a[i];
                    s.insert(a[i]);
               }
               sort(a,a+n);
               int l = a[0];
               int r = a[n-1];
               int diff = INT_MAX;

               for(int i=l;i<=200;++i)
               {
                    if(s.count(i)==0)
                    {
                         if(abs(i-x)<diff)
                         {
                              diff = abs(i-x);
                              res = i;
                         }
                    }
               }
               for(int i=-200;i<l;++i)
               {
                    if(abs(i-x)<diff)
                    {
                         diff = abs(i-x);
                         res = i;
                    }
                    else if(abs(i-x)==diff)
                         res = i;
               }
      }

               cout<<res;
      }
}


Measured memory_bytes: 3648
#include<string>
#include<cmath>
#include<iostream>

using namespace std;
 
int main(){
	int n, ans;
	double xa,ya,ra,xb,yb,rb,ab;

	cin >>n;
	while(n--){
		cin >>xa>>ya>>ra>>xb>>yb>>rb;
		
		ab=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		ans=1;
		if(ab>(ra+rb)) ans=0;
		if(ra>(ab+rb)) ans=2;
		if(rb>(ab+ra)) ans=-2;

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

Measured memory_bytes: 1232
#include<iostream>

using namespace std;

int main()
{
 while(1){
 char str[150];
 int pointA=0;
 int pointB=0;
 int j=1;
 cin>>str;
 if(str[0]=='0'){break;}
 while(str[j]!='\0'){
	if(str[j]=='A'){
		pointA++;}
	if(str[j]=='B'){
		pointB++;}
	j++;
 }
 if(pointA>pointB)pointA++;
 if(pointA<pointB)pointB++;
 cout<<pointA<<' '<<pointB<<'\n';
 }
return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

class DisjointSet{
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int v, e, s, t, w;
    cin >> v >> e;

    DisjointSet uf(v);

    priority_queue<pair<int, pair<int,int>>> pq;

    for(int i = 0; i < e; i++){
        cin >> s >> t >> w;
        pq.push({-w, {s, t}});
    }

    int ans = 0;

    while(!pq.empty()){
        auto x = pq.top();  pq.pop();
        if(!uf.same(x.second.first, x.second.second)){
            ans += -x.first;
            uf.unite(x.second.first, x.second.second);
        }
    }

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


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

bool check(string s) {
    if (s.size() == 0) return true;
    if (s[0] == 'm') {
        int i = 1, flag = 0;
        while(i < s.size() && !(flag == 0 && s[i] == 'e')) {
            if (s[i] == 'm') flag++;
            else if (s[i] == 'w') flag--;
            else if (s[i] != 'e') return false;
            i++;
        }
        if (i == s.size()) return false;
        if (!check(s.substr(1, i - 1))) return false;
        if (s[s.size() - 1] == 'w' && check(s.substr(i + 1, s.size() - 2 - i))) return true;
        return false;
    } else {
        return false;
    }
}

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    if (check(s)) cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
    return 0;
}

Measured memory_bytes: 3232
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, A, B;
    ll ans = 0;

    cin >> N >> A >> B;

    for (int i = 1; i <= N; i++) {
        int sum = 0;
        int x = i;
        rep(i, 5) {
            sum += x % 10;
            x /= 10;
        }
        if (sum >= A && sum <= B) ans += i;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a>=13){
      System.out.println(b);
    }else if(5<a && a<13){
      System.out.println(b/2);
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 23636
from collections import deque


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.sort()
    ans = 0
    B = deque(A)
    edge = [B.popleft()] * 2
    while len(B):
        a = abs(edge[0] - B[0])
        b = abs(edge[0] - B[len(B) - 1])
        c = abs(edge[1] - B[0])
        d = abs(edge[1] - B[len(B) - 1])
        if max(a, b, c, d) == a:
            edge[0] = B.popleft()
            ans += a
        elif max(a, b, c, d) == b:
            edge[0] = B.pop()
            ans += b
        elif max(a, b, c, d) == c:
            edge[1] = B.popleft()
            ans += c
        else:
            edge[1] = B.pop()
            ans += d
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 58072
#16:44
n,m = map(int,input().split())
div = []
rdiv = []
for i in range(1,int(m**.5)):
  if m % i == 0:
    div.append(i)
    rdiv.append(m//i)
if m % int(m**.5) == 0:
  div.append(int(m**.5))
rdiv.reverse()
div += rdiv
for x in div:
  if x >= n:
    print(m//x)
    break

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

vector<long> v;
long n;

void tfs(long x) 
{
    long xx = x * 10;
    
    long a = xx + 3;
    if (a > n) return;
    v.push_back(a);
    long b = xx + 5;
    if (b > n) return;
    v.push_back(b);
    long c = xx + 7;
    if (c > n) return;
    v.push_back(c);
    tfs(a);
    tfs(b);
    tfs(c);
}

int main()
{
    cin >> n;
    int ans = 0;

    tfs(3);
    tfs(5);
    tfs(7);

    for (auto num: v) {
        int t = 0;
        int f = 0;
        int s = 0;
        while (num > 0) {
            int tmp = num % 10;
            if (tmp == 3) ++t;
            if (tmp == 5) ++f;
            if (tmp == 7) ++s;
            num /= 10;
        }
        if (t && f && s) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> P(N,0);
    Map where;
    for(ll i=0;i<N;i++){
        cin>>P[i];
        where[P[i]]=i;
    ;}

    ll ans=0;
    
    //Sにでかい順に格納
    multiset<ll> S;
    S.insert(-1);
    S.insert(-1);
    S.insert(N);
    S.insert(N);
    ll e=0;

    //一つずつ真の値に変えていく
    for(ll i=N;i>=1;i--){
        ll k=where[i];
        S.insert(k);
        ll a,b,c,d,y,x;
        auto t=S.lower_bound(k);
        auto p=t,q=t,r=t,s=t;
        p--;p--;q--;r++;s++;s++;

        ans+=(*q-*p)*(*r-k)+(k-*q)*(*s-*r);
        e+=ans;
    }

    cout<<e<<endl;

    return 0;
}


Measured memory_bytes: 11904