akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
k=[0]*(n+1)
r=[[] for i in range(n+1)]
R=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    r[a].append(b)
    r[b].append(a)
    R[a].append(b)
    R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
    p=data.popleft()
    for i in r[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            k[i]=p
            data.append(i)
    r[p]=[]
if not all(dep[i+1]>=0 for i in range(n)):
    print("No")
else:
    print("Yes")
    for i in range(2,n+1):
        print(k[i])


Measured memory_bytes: 113200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}
const int MAX = 25;
vector<vector<char>> maze(MAX,vector<char> (MAX));
vector<vector<bool>> checked(MAX,vector<bool> (MAX,false));
int H,W;
int dx[] = {0,-1,0,1};
int dy[] = {-1,0,1,0};
typedef struct{
  int cur;
  int x;
  int y;
}T;

//x,yスタートで最も遠い距離
int bfs(int x,int y){
  queue<T> que;
  que.push({0,x,y});
  int cur = 0;

  while(!que.empty()){
    T t = que.front();
    que.pop();
    if(checked[t.x][t.y])continue;
    checked[t.x][t.y] = true;
    cur = max(cur,t.cur);
    rep(i,4){
      int nx = t.x + dx[i], ny = t.y + dy[i];
      if(nx >= 0 && nx < W && ny >= 0 && ny < H && maze[nx][ny] !='#'){
        que.push({t.cur+1,nx,ny});
      }
    }
  }
  return cur;
}


int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> H >> W;
  rep(y,H)rep(x,W)cin >> maze[x][y];
  int ans = 0;
  rep(y,H)rep(x,W){
    if(maze[x][y] == '#')continue;
    rep(ny,H)rep(nx,W) checked[nx][ny] = false;
    ans = max(ans,bfs(x,y));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
main = do
    _ <- getLine
    hs <- (map read) . words <$> getLine
    print $ sum [countNumBlocks n (dropWhile (<n) hs) | n <- [1..100]]
    
countNumBlocks :: Int -> [Int] -> Int
countNumBlocks n [] = 0
countNumBlocks n xs = 1 + countNumBlocks n (dropWhile (<n) . dropWhile (>=n) $ xs)

Measured memory_bytes: 1020
#include<iostream>
#include<cstdlib>

using namespace std;

typedef long long int ll;

ll data[200001];
ll sum[200001];

int main(){
  int N;
  cin>>N;
  ll minimum = 0;
  for(int i=0;i<N;i++) {
    cin>>data[i];
    minimum += abs(data[i]);
  }
  for(int i=N-1;i>=0;i--){
    sum[i]=data[i]+(((i+1)<N)?sum[i+1]:0);
  }
  //  for(int i=0;i<N;i++)cout<<sum[i] << " " ;
  //  cout<<endl;

  for(int i=0;i<N-1;i++){
    ll x = sum[0] - sum[i+1];
    ll y = sum[i+1];
    //    cout << x << " " << y <<endl;
    ll diff = abs(x-y);
    //    cout << diff <<endl;
    if (minimum > diff) {
      minimum = diff;
    }
  }

  cout << minimum << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

int main() {
	cin >> n;
	int now = 1;
	while (now * 2 <= n) {
		now *= 2;
	}
	cout << now << endl;
}

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

int main(){
	int n,m; //n:buy count  m:pack count
	
	while(std::cin >> n >> m){
		if(n == 0 && m == 0)
			break;
		
		std::vector<int> price;
		price.resize(n);
		for(int i=0; i<n; ++i){
			std::cin >> price[i];
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

		int sum=0;
		for(int i=0; i<n; ++i){
			if((i+1)%m != 0)
				sum += price[i];
		}
		
		std::cout << sum << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] count = new int[26];
            while (true)
            {
                string input = Console.ReadLine();
                if (input == null)
                    break;

                input = input.ToLower();

                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] >= 'a' && input[i] <= 'z')
                    {
                        count[input[i] - 'a']++;
                    }
                }
            }

            for(int i= 0;i<count.Length;i++)
            {
                Console.WriteLine(string.Format("{0} : {1}", (char)(i + 'a'), count[i]));
            }
          }
     }
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> vec(N+1);
  for (ll i = 2; i<=N; i++) {
    ll a; cin >> a;
    vec.at(a)++;
  }
  for (ll i = 1; i <= N; i++) {
    cout << vec.at(i) << "\n";
  }
  

  return 0;
}



Measured memory_bytes: 4776
""""
4 2
1 1 3 4
"""
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()

p = 10**9+7

fact = [1]*(N+1)
inv = [0]*(N+1)
inv[1] = 1
fact_inv = [1]*(N+1)
fact_inv = [1]*(N+1)
for i in range(2, N+1):
    fact[i] = (fact[i-1]*i) % p
    inv[i] = (-inv[p % i]*(p//i)) % p
    fact_inv[i] = (fact_inv[i-1]*inv[i] % p)


def cmb_mod(n, k, p):
    return (fact[n]*fact_inv[k]*fact_inv[n-k]) % p


max_sum = 0
min_sum = 0
for i in range(K-1, N):
    n_C_k = cmb_mod(i, K-1, p)
    max_sum += A[i] * n_C_k
    min_sum += A[N-i-1] * n_C_k
    max_sum = max_sum
    min_sum = min_sum

print((max_sum - min_sum) % p)

Measured memory_bytes: 19544
#include <iostream>
#include <iomanip>
#define pi 3.14159265358979
using namespace std;
 
int main()
{
    double x;

    cin >> x;
    double z = x*pi;
    cout << fixed << setprecision(6) << z*x  << " " << z*2<<endl;
    return 0;
}

Measured memory_bytes: 3252
from math import log2
N, K = map(int, input().split())
p = 0.0
if N >= K:
    p1 = (N-K+1)/N
    p2 = 1.0
    p += p1
    temp = 0.0
    for i in range(1, K): # 1 to K-1
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p2 *= temp*(1/N)
    p += p2
else:
    temp = 0
    for i in range(1, N+1): # 1 to N
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p = temp*(1.0/N)
print(p)            

Measured memory_bytes: 3064
//https://atcoder.jp/contests/abc154/tasks/abc154_c
//C - Distinct or Not
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    sort(an.begin(),an.end());
    bool ans=true; //yes
    FOR(i,1,N){
        if(an.at(i-1)==an.at(i)) {
            ans=false;
            break;
        }
    }
    cout<<(ans?"YES":"NO")<<endl;    
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0
A[1] = abs(h[1]-h[0])

if N > 2:
    for i in range(2,N):
        p = A[i-1] + abs(h[i-1] - h[i])
        q = A[i-2] + abs(h[i-2] - h[i])
        if  p < A[i]:
            A[i] = p
        if q < A[i]:
            A[i] = q
    print(A[N-1])

else:
    print(abs(h[1]-h[0]))

Measured memory_bytes: 52208
#include <stdio.h>
int main(void){
    char s[5];
    scanf("%s",s);
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) printf("Yes");
    else if(s[0]==s[2] && s[1]!=s[2] && s[1]==s[3]) printf("Yes");
    else if(s[0]==s[3] && s[3]!=s[1] && s[1]==s[2]) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    string s;
    cin >> s;
    vector<vector<ll>> v(26, vector<ll>(1, -1));
    for(ll i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i);
    for(ll i = 0; i < 26; i++) v[i].push_back(s.size());
    ll ans = s.size() - 1;
    for(ll i = 0; i < 26; i++){
        ll tmp = 0;
        for(ll j = 0; j < v[i].size() - 1; j++) tmp = max(tmp, v[i][j + 1] - v[i][j] - 1);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int i;
	int count=0;
	cin>>a;
	for(i=0;i<a.size();i++){
		if(a[i]=='o')	count++;
	}
	cout<<700+count*100;
	cout<<endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
Bi = list(map(int, input().split()))

count = 0

for _ in range(N):
    Ai = map(int, input().split())

    sum = C
    for a, b in zip(Ai, Bi.copy()):
        sum += a*b

    if sum > 0:
        count += 1

print(str(count))





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

int main () {
  int n,k;
  cin>>n>>k;
  int a[n];
  for (int i=0;i<n;i++) {
    cin>>a[i];
  }
  int dp[100101];
  long long p=100000000000;
  for (int i=0;i<100101;i++) {
    dp[i]=p;
  }
  dp[0]=0;
  if (n==2) {
    cout<<abs(a[1]-a[0])<<endl;
  }
  else {
    for (int i=0;i<n;i++) {
      for (int j=1;j<k+1;j++) {
        if (dp[i+j]>dp[i]+abs(a[i]-a[i+j])) {
          dp[i+j]=dp[i]+abs(a[i]-a[i+j]);
        }
      }
    }
    cout<<dp[n-1]<<endl;
  }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int num, tim, i;
  int t[1000000] = {0};
  int oyu = 0;
  scanf("%d %d", &num, &tim);
  for(i = 0; i < num; i++){
    scanf("%d", &t[i]);
  }
  for(i = 0; i < num - 1; i++){
    if(tim < t[i+1] - t[i]){
       oyu += tim;
    }else {
      oyu += t[i+1] - t[i];
    }
  }
  oyu = oyu + tim;
  printf("%d\n", oyu);
  return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    int a,b; cin >> a >> b;
    cout << ((a*b % 2 == 1)?"Yes":"No") << endl;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll H1,m1,H2,m2,k;
	cin >> H1>>m1>>H2>>m2>>k;
	cout << m2 -m1+(H2-H1)*60-k;
}


Measured memory_bytes: 3612
input = gets.chomp.split("")
last = input[0]
len = 1
arr = []
(input.length).times{|t|
if input[t+1] == last then
  len +=1
else
  arr.push(len)
  len = 1
  last = input[t+1]
end
}
t = 0
while t<arr.length do
(arr[t]-1).times{
  print "0 "
}
print (arr[t].to_f/2).ceil + arr[t+1]/2," "
print arr[t]/2 + (arr[t+1].to_f/2.0).ceil," "

(arr[t+1]-1).times{
  print "0 "
}
t +=2
end

Measured memory_bytes: 10492
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b;
  cin>>a>>b;
  int x=max(a,b);
  int y=min(a,b);
  int z=max(x-1,y);
  cout<<x+z<<endl;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    int D ;

    cin >> D ;

    if (D == 25)
    {
        cout << "Christmas" ;
    }
    else if (D == 24)
    {
        cout << "Christmas Eve" ;
    }
    else if (D == 23)
    {
        cout << "Christmas Eve Eve" ;
    }
    else if (D == 22)
    {
        cout << "Christmas Eve Eve Eve";
    }

    return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  string s;
  int n;
  cin>>s>>n;
  int co=0;
  while(n--){
	string in;
	cin>>in;
	in+=in;
	if(in.find(s,0)!=string::npos)co++;
  }
  cout<<co<<endl;
}

Measured memory_bytes: 1212
#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 k,a,b;cin>>k>>a>>b;
	if(a>=k){
		puts("1");
		return 0;
	}
	if(a-b<=0){
		puts("-1");
		return 0;
	}
	ll d=(k/(a-b))*2;d=max(0LL,d-6);
	ll c=d/2*(a-b);
	while(1){
		c+=a;
		d++;
		if(c>=k){
			cout<<d<<endl;
			return 0;
		}
		c-=b;
		d++;
	}
}


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

int main(){
  int a,b,c,k;
    cin >>a>>b>>c>>k;
    int sum=0;
    for(int i=0;i<k;i++){
        if(a>0){
            sum++;
            a-=1;
        }
        else if(b>0){
            b-=1;
        }
        else{
            sum--;
            c-=1;
        }
    }
    
    cout <<  sum << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;

int main()
{
	scanf("%d", &N);
	i64 ret = 1;
	for (int i = 2; i <= N; ++i) {
		bool flg = true;
		for (int j = 2; j * j <= i; ++j) {
			if (i % j == 0) flg = false;
		}
		if (flg) {
			int ord = 0;
			int v = N;
			while (v) {
				ord += v / i;
				v /= i;
			}
			ret = ret * (ord + 1) % MOD;
		}
	}
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int k,a,b;
	cin>>k>>a>>b;
	bool ok=false;
	FOR(i,a,b+1){
		if(i%k==0){
			ok=true;
		}
	}
	if(ok){
		cout<<"OK"<<endl;
	}
	else{
		cout<<"NG"<<endl;
	}
}

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


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    for (int i = 1;; i++) {
        if (i > a || i > b) {
            break;
        }
        if (a % i == 0 && b % i == 0) {
            v.push_back(i);
        }
    }

    cout << v[v.size() - k];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 0x3f3f3f3f
using namespace std;
typedef long long ll; 
int main()
{
	std::ios::sync_with_stdio(false);
	ll a,v,b,w;
	double t;
	cin>>a>>v>>b>>w>>t;
	if(w>=v) {
		cout<<"NO";
		return 0;
	}
	ll dis=b-a;
	double tim;
	if(dis<=0)
	{
		dis=-dis;
		tim=dis*1.0/(v-w);
		if(tim>t) {
			cout<<"NO";
			return 0;
		}
		else
		{
			cout<<"YES";
			return 0;
		}
	}
	 tim=dis*1.0/(v-w);
	if(tim>t) cout<<"NO";
	else cout<<"YES";
	return 0;
 } 

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

string replace_all(string str, string from, string to) {
  int fromSize = from.size();
  int toSize = to.size();
  int pos = str.find(from);

  while (pos != std::string::npos) {
    str.replace(pos, fromSize, to);
    pos = str.find(from, pos + toSize);
  }
  return str;
}

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  int len = s.size();
  string s_d = replace_all(s, "BC", "D");
  int a_cnt = 0;
  REP(i, s_d.size()) {
    if (s_d[i] == 'A') {
      a_cnt++;
    } else if (s_d[i] == 'D') {
      ans += a_cnt;
    } else {
      a_cnt = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3928
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll c(26, HIGHINF);
  REP(_, n) {
    string s; cin >> s;
    vll tmp(26, 0);
    REP(i, s.size()) tmp[s[i] - 'a']++;
    REP(i, 26) chmin(c[i], tmp[i]);
  }
  REP(i, 26) {
    REP(j, c[i]) {
      cout << (char)('a' + i);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import math


def resolve():
    import sys
    input = sys.stdin.readline
    row1 = [int(x) for x in input().rstrip().split(" ")]
    row2 = [int(x) for x in input().rstrip().split(" ")]

    n = row1[0]
    minx = min(row2)
    maxx = max(row2)

    min_sum = float('inf')
    index = -1
    for i in range(minx,maxx+1):
        tmp = sum([(x-i)**2 for x in row2])
        if tmp < min_sum:
            min_sum = tmp
    print(min_sum)







if __name__ == "__main__":
    resolve()


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

int main(){
  int m1,d1,m2,d2,ans = 0;
  
  cin >> m1 >> d1 >> m2 >> d2;
  
  if(m1 == 1 && d1 == 31 && m2 == 2 && d2 == 1){
    ans = 1;
  }else if(m1 == 2 && d1 == 28 && m2 == 3 && d2 == 1){
    ans = 1;
  }else if(m1 == 3 && d1 == 31 && m2 == 4 && d2 == 1){
    ans = 1;
  }else if(m1 == 4 && d1 == 30 && m2 == 5 && d2 == 1){
    ans = 1;
  }else if(m1 == 5 && d1 == 31 && m2 == 6 && d2 == 1){
    ans = 1;
  }else if(m1 == 6 && d1 == 30 && m2 == 7 && d2 == 1){
    ans = 1;
  }else if(m1 == 7 && d1 == 31 && m2 == 8 && d2 == 1){
    ans = 1;
  }else if(m1 == 8 && d1 == 31 && m2 == 9 && d2 == 1){
    ans = 1;
  }else if(m1 == 9 && d1 == 30 && m2 == 10 && d2 == 1){
    ans = 1;
  }else if(m1 == 10 && d1 == 31 && m2 == 11 && d2 == 1){
    ans = 1;
  }else if(m1 == 11 && d1 == 30 && m2 == 12 && d2 == 1){
    ans = 1;
  }else if(m1 == 12 && d1 == 31 && m2 == 1 && d2 == 1){
    ans = 1;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    static boolean [][] grid;
    static int [] bishopr = {-1,1,-1,1};
    static int [] bishopc = {1,1,-1,-1};
    static long H,W,cnt;
    public static void main(String args[]) throws IOException {
           
        int N  = in.nextInt();
        if(N%1000!=0)
        out.println(1000-(N%1000));
        else{
            out.println(0);
        }

        out.flush();
        }
       static boolean isValid (int r, int c){
           if(r>=0&&r<H&&c>=0&&c<W){
               return true;
           }
           return false;
       }
        private static void dfs(int r, int c) {
            for(int i=0;i<4;i++){
                int nr = bishopr[i] +r;
                int nc = bishopc[i]+c;
                if(isValid(nr, nc)&&!grid[nr][nc]){
                    cnt++;
                    grid[nr][nc] = true;
                    dfs(nr, nc);
                }
            }
        }

        static boolean isEven(long a) {
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
    

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 32912
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
 
int main()
{
int n, a[1000];
cin >> n;
for (int i=1; i<=2*n; i++)
cin >> a[i];
for (int i=1; i<=2*n-1; i++)
for (int j=i+1; j<=2*n; j++)
if (a[j]<a[i])
{
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
int ans = 0;
for (int i=1; i<=2*n; i++)
if (i%2==0)
{
ans+=a[i-1];
}
cout << ans;
}

Measured memory_bytes: 764
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
//#define ForJ(n) for(int j=0;j<n;j++)
//#define ForK(n) for(int k=0;k<n;k++)
#define Pr(n) cout<<n<<endl;
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;


signed  main(){
    int r,d,x;
    cin>>r>>d>>x;
    int befor = x;
    For(10, i){
        Pr(r*befor-d)
        befor= r*befor-d;
    }
    return 0;
}



Measured memory_bytes: 256
import Control.Applicative((<$>))
import Control.Monad
-- import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
----------------------------------------------

-- ????????°?????? ver.
-- expr   = term   | expr +- term
-- term   = factor | term */ factor
-- factor = number | (expr)

-- ????????°?????? ver.
-- expr   = term   | term (+- expr)
-- term   = factor | factor (*/ term)
-- factor = number | (expr)

type Op = Char
data Tree = Leaf Int | Node Tree Op Tree deriving Show
type Keisan = String -> (Tree -> Tree) -> (Tree,String)

expr :: Keisan
expr ss tr =
  let (t,state) = term ss id in
  if state == "" then (tr t,state)
  else if head state == '+' then expr (tail state) (Node (tr t) '+')
  else if head state == '-' then expr (tail state) (Node (tr t) '-')
  else (tr t,state)

term :: Keisan
term ss tr =
  let (f,state) = factor ss id in
  if state == "" then (tr f,state)
  else if head state == '*' then term (tail state) (Node (tr f) '*')
  else if head state == '/' then term (tail state) (Node (tr f) '/')
  else (tr f,state)

factor :: Keisan
factor ss tr =
  if head ss == '(' then let (e,state) = expr (tail ss) id in (tr e,tail state)
  else let (e,state) = getNumber ss in ((tr . Leaf . read) e,state)
    where
      getNumber = takeWhile2 (\x -> x `elem` ['0'..'9'])

takeWhile2 :: (a -> Bool) -> [a] -> ([a],[a])
takeWhile2 cond l = aux [] l
  where
    aux acc [] = (reverse acc, [])
    aux acc (x:xs)
      | cond x = aux (x:acc) xs
      | otherwise = (reverse acc, x:xs)

-- solver ss = floor.calc.fst $ expr ss id
solver ss = calc.fst $ expr ss id
-- solver ss = fst $ expr ss id
calc (Leaf a) = a
calc (Node a '+' b) = calc a + calc b
calc (Node a '-' b) = calc a - calc b
calc (Node a '/' b) = calc a `quot` calc b
-- calc (Node a '/' b) = calc a / calc b
calc (Node a '*' b) = calc a * calc b

main :: IO ()
main = do
  n  <- getInt
  es <- replicateM n getLine
  -- let es = ["0+3*2*2+1=","4-2*3=","4*(8+4+3)=","1-(1-1*4*3/2)-1=","1-(6/1000000000*1000000000)"]
  mapM_ (print.solver.(takeWhile ('=' /=))) es

Measured memory_bytes: 4152
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
	int l,r,largest;
	int copy = 0;
	
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l<=H && A[l]>A[i]){
		largest = l;
	}else {
		largest = i;
	}
	
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	
	if(largest != i){
		copy = A[i];
		A[i] = A[largest];
		A[largest] = copy;
		maxHeapify(largest);
	}
}

int main (){
	int i;
	scanf("%d",&H);
	
	for(i=1;i<= H;i++){
		scanf("%d",&A[i]);
	}
	
	for(i=H/2;i>= 1;i--){
		maxHeapify(i);
	}
	
	for(int i = 1;i <= H;i++){
		printf(" %d",A[i]);
	}
	
	printf("\n");
	return 0;
}




Measured memory_bytes: 3664
import operator
s = [int(i) for i in list(input())]

op = []
op.append( operator.add )
op.append( operator.sub )


for i in range(2) :
  for j in range(2) :
    for k in range(2) :

      r = op[i](s[0],s[1])

      r = op[j](r,s[2])

      r = op[k](r,s[3])

      if r == 7 :
        op1 = "+" if i == 0 else "-"
        op2 = "+" if j == 0 else "-"
        op3 = "+" if k == 0 else "-"
        print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])+"=7")
        exit()
      
      


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string n;
    cin >> n;
    if (n == "ABC")cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3600
import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
a = [0]+[I() for _ in range(N)]
ans,now = 0,1
for _ in range(N):
    temp = a[now]
    ans += 1
    if temp==2:
        print(ans)
        break
    now = temp
else:
    print(-1)


Measured memory_bytes: 7852
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>

#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int32_t main()
{
  fast ;


  int n; cin >> n;
  int a, b, c; cin >> a >> b >> c;
  int dp[n][3];
  dp[0][0] = a, dp[0][1] = b, dp[0][2] = c;
  for (int i = 1; i < n; i++)
  {
    cin >> a >> b >> c;
    dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = c + max(dp[i - 1][1], dp[i - 1][0]);
  }
  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));


}



Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

int main(void){
    int N,s[105];
    char S[105];
    int r[105];//0~N-1の文字の左までの右にある文字カウント　'('-'')''
    int l[105];//0~N-1のもじの右までの左にある文字カウント
    scanf("%d",&N);
    scanf("%s",S);
    int t1=0,t2=0;
    rep(i,N){
        if(S[i]=='(')s[i]=1;
        if(S[i]==')')s[i]=-1;
        if(i==0)l[i]=s[i];
        else l[i]=s[i]+l[i-1];
    }
    rep(i,N){
        if(i==0)r[N-1-i]=s[N-1-i];
        else r[N-1-i]=s[N-1-i]+r[N-i];
    }
    
    rep(i,N+1){
        if(i==0){
            if(r[0]<0)t1=-r[0];
            if(l[N-1]+t1>0)t2=l[N-1]+t1;
        }else if(i==N){
            t2=l[i-1]+t1;
        }else{
            if(l[i-1]+t1<0){
                t1-=l[i-1]+t1;
            }
        }
    }
    rep(i,t1)printf("(");
    rep(i,N)printf("%c",S[i]);
    rep(i,t2)printf(")");
    printf("\n");
}
    


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int takentime=0,n;
	long long int in[6];
	cin>>n;
	for(int i=1; i<=5; i++)
		cin>>in[i];
	
	takentime=5;
	takentime+=max({(n-1)/in[1],(n-1)/in[2],(n-1)/in[3],(n-1)/in[4],(n-1)/in[5]});
	cout<<takentime<<endl;

	return 0;
}





/*
5
3
2
4
3
5
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements <=num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//Sort(v);
//v.erase(unique(all(v)),v.end());
//It keeps unique elements in sorted order....
//#define int long long int
void solve(){
	string s;
	cin>>s;
	if(s.length()==6){
		if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
 else cout<<"No"<<endl;
 
 
}
 
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
} 

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    H = readInts()
    allzero = False
    cnt = 0
    while True:
        for i in range(n):
            allzero = True
            if H[i] > 0:
                allzero = False
                left = i
                break
                # ここで左がわを決めておく
        #print(left)
        if allzero:
            print(cnt)
            exit()
        i = left
        right = left
        while i < n and H[i] > 0:
            right += 1
            i += 1
            if i >= n:
                break
        for j in range(left,right):
            #print(j)
            H[j] -=1
        #print(*H)
        cnt += 1

if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,ara[1000],n=0,ara2[1000],k=0,c=1,max=0,mode,m;

    while (scanf ("%d",&m)!=EOF)
    {
        ara[n]=m;
        n++;
    }
    for (i=0;i<n-1;i++)
    {
        mode=0;
        for (j=i+1;j<n;j++)
        {
            if (ara[i]==ara[j])
            {
                mode++;
            }
        }
        if ((mode>max) && (mode!=0))
        {
            k=0;
            max=mode;
            ara2[k]=ara[i];
            k++;
        }
        else if (mode==max)
        {
            ara2[k]=ara[i];
            k++;
        }
    }
        sort(ara2,ara2+k);
        for (i=0;i<k;i++)
        {
            printf("%d\n",ara2[i]);
        }
        return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    int p[n] = {0};
    for(int i = 0;i<n;++i)
    {
	int tmp;
	cin>>tmp;
	p[i] = tmp;
    }
    sort(p,p+n);
    int res = 0;
    for(int i = 0;i<k;++i)
    {
	res = res + p[i];
    }
    cout<<res<<"\n";
}

Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int S = sc.nextInt();
        int W = sc.nextInt();

        if (W >= S) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35616
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+j*100+k*50 == x:
        ans += 1
print(ans)
      


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin>>n>>m>>x;
    vector<int>c(n);
    vector<vector<int>>a(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        cin>>c[i];
        for (int j = 0; j < m; j++)
        {
            cin>>a[i][j];
        }
    }
    int perms=1<<n;
    int ans = 12345678;
    bool flag = true;
    for (int p = 0; p < perms; p++)
    {
        vector<int> level(m, 0);
        int cost = 0; flag = true;
        for (int i = 0; i < n; i++)
        {
            if ((p >> i) & 1)
            {
                cost += c[i];
                for (int j = 0; j < m; j++)
                {
                    level[j] += a[i][j];
                }
            }
        }
        for (int j = 0; j < m; j++)
        {
            if (level[j] < x) flag = false;
        }
        if (flag) ans = min(ans, cost);
    }
    if (ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
N, Q = map(int, input().split())
S = input()
A = []
a = 0
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    a += 1
    A.append(a)
  else:
    A.append(a)
for i in range(Q):
  l, r = map(int, input().split())
  if l>=2:
    ans = A[r-2]-A[l-2]
    print(ans)
  else:
    ans = A[r-2]
    print(ans)

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
int main(){
    string s;
    cin >> s;
    int answer=0;
    int cur=0;
    int b=0;
    for(auto c:s){
        if(c == 'R'){
            if(b == 0){
                cur = 1;
                b  = 1;
                answer = max(cur, answer);
            }else{
                cur += 1;
                answer = max(cur, answer);
            }
            
        }else{
            cur = 0;
            b = 0;
        }
    }
    cout << answer;
    return 0;
}

Measured memory_bytes: 3592
import math
n = int(input())
i = x = 1
ans = ""
inc = True
while True:
    if (x % 3) == 0 and inc:
        ans = " " + str(i)
        print(ans, end='')
    elif (x % 10) == 3:
        ans = " " + str(i)
        print(ans, end='')
    else:
        x //= 10
        if x != 0:
            inc = False
            continue
    i += 1
    if i <= n:
        x = i
        inc = True
        continue
    break
print()



Measured memory_bytes: 5920
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =  998244353;
const int INV2 = (MOD+1)/2;
vector<int> hen[200000];int ans[200000];
int basho[200000],basho2[200000];
bool used[200000];

template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
 SegmentTree<int,int> rmq(200001,
			   [](int a,int b){return max(a,b);},
			   [](int a,int b){return b;},
			   0);
void dfs(int a){
 used[a]=true;
 ans[a]=rmq.query(0,basho[a])+1;
 rmq.update(basho2[a],ans[a]);
 for(auto&& i :hen[a])if(!used[i])dfs(i);
 rmq.update(basho2[a],0);

  
}
void dfs2(int a){
  used[a]=true;
  for(auto&& i :hen[a])if(!used[i]){
    ans[i]=max(ans[i],ans[a]);
    dfs2(i);
  }
}

     signed main(){
       
        int n;
        cin>>n;
        int x;
        pair<int,int> a0[n];
        for(int i=0;i<n;i++){
          cin>>x;
          a0[i]=make_pair(x,i);
        }
        sort(a0,a0+n);
        basho[a0[0].second]=0;
        basho2[a0[0].second]=0;
        int i0=0;
        for(int i=0;i<n;i++){
          if(a0[i0].first!=a0[i].first)i0=i;
          basho[a0[i].second]=i0;
          basho2[a0[i].second]=i;
        }
        int u,v;
        for(int i=0;i<n-1;i++){
          cin>>u>>v;u--;v--;
          hen[u].push_back(v);
          hen[v].push_back(u);
        }

        fill(used,used+n,false);
     
        dfs(0);
         fill(used,used+n,false);
     
        dfs2(0);
        for(int i=0;i<n;i++)cout<<ans[i]<<endl;


        





}


        


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

def main():
    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    cd = [list(map(int, input().split())) for i in range(M)]

    ans = [0] * N
    for i in range(N):
        x, y = ab[i]
        c, d = cd[0]
        min_d = abs(c - x) + abs(d - y)
        min_index = 0
        for j in range(M):
            c, d = cd[j]
            tmp = abs(c - x) + abs(d - y)
            if tmp < min_d:
                min_d = tmp
                min_index = j
        ans[i] = min_index
    
    for i in range(N):
        print(ans[i]+1)
            

if __name__ == "__main__":
    main()

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

int main(){
  string s,t;
  cin>>s>>t;
  int ans=100000;
  for(int i=0;i<s.size()-t.size()+1;i++){
    int x=0;
    string u=s.substr(i,t.size());
    for(int j=0;j<t.size();j++){
      if(u[j]!=t[j]){
        x++;
      }
    }
    ans=min(ans,x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
#include<utility>
using namespace std;
using ll = long long;

int main(){
    ll n,k;
    cin >> n >> k;
    ll cnt = 0;
    while(n!=0){
        n/=k;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

typedef int32_t i32;
typedef uint32_t u32;
typedef uint64_t u64;

const u32 mod = 998244353;

u32 mod_pow (u32 r, u32 n) {
  u32 t = 1;
  u32 s = r;
  while (n > 0) {
    if (n & 1) t = (u64) t * s % mod;
    s = (u64) s * s % mod;
    n >>= 1;
  }
  return t;
}

void run (void) {
  i32 n;
  scanf ("%" SCNu32, &n);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 sum = 0;
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
    sum += a[i];
  }
  u32 *dp = (u32 *) calloc (sum + 1 + 300, sizeof (u32)) + 300;
  dp[0] = 1;
  for (i32 i = 0, s = 0; i < n; s += a[i++]) {
    for (i32 j = s + a[i]; j >= 0; --j) {
      dp[j] = 2 * dp[j] + dp[j - a[i]];
      while (dp[j] >= mod) dp[j] -= mod;
    }
  }
  u32 ans = mod_pow (3, n);
  for (i32 i = (sum + 1)/ 2; i <= sum; ++i) {
    ans = (ans + 3 * (mod - dp[i])) % mod;
  }
  if (sum % 2 == 0) {
    memset (dp, 0, sizeof (u32) * (sum + 1));
    dp[0] = 1;
    for (i32 i = 0, s = 0; i < n; s += a[i++]) {
      for (i32 j = s + a[i]; j >= 0; --j) {
	dp[j] += dp[j - a[i]];
	while (dp[j] >= mod) dp[j] -= mod;
      }
    }
    ans = (ans + 3 * dp[sum / 2]) % mod;
  }
  printf ("%" PRIu32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 512
n = int(input())
a, b = map(int, input().split())
p_lst = list(map(int, input().split()))
cnt_1 = cnt_2 = cnt_3 = 0
for p in p_lst:
    if p <= a:cnt_1 += 1
    elif p <= b:cnt_2 += 1
    else:cnt_3 += 1
print(min(cnt_1, cnt_2, cnt_3))

Measured memory_bytes: 38384