akhauriyash/Code-Regression huggingface dataset:
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split()))for i in range(n)]
cnt=0
for i in range(n):
    total=0
    for j in range(m):
        total+=B[j]*A[i][j]
    total+=c
    if 0<total:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for (int i = 0; i < length; i++) {
                char ch = line.charAt(i);
                if (Character.isLowerCase(ch)) {
                    ch=Character.toUpperCase(ch);
                } else {
                    ch=Character.toLowerCase(ch);
                }
                answer+=ch;
            }
            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 31648
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  string S; cin>>S;
  ll q; cin>>q;
  vector<ll> K(q);
  rep(i,q) cin>>K[i];

  foreach(k,K){
    vector<ll> DMC(3);
    ll cnt=0;
    ll ans=0;
    queue<char> Q;
    foreach(s,S){
      // push
      if(s=='D'){
        DMC[0]++;
      }else if(s=='M'){
        DMC[1]++;
        cnt+=DMC[0];
      }else if(s=='C'){
        DMC[2]++;
        ans+=cnt;
      }
      Q.push(s);

      // pop
      if(Q.size()<k) continue;
      char t=Q.front(); Q.pop();
      if(t=='D'){
        DMC[0]--;
        cnt-=DMC[1];
      }else if(t=='M'){
        DMC[1]--;
      }else if(t=='C'){
        DMC[2]--;
      }
    }
    cout<<ans<<"\n";
  }
}

Measured memory_bytes: 2332
def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return f, invs


def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    return c0, a0, b0


def solve(n, a, b, k):
    MOD = 998244353
    fn, invs = prepare(n, MOD)

    if a < b:
        a, b = b, a
    c, x, y = ex_euclid(a, b)
    d, m = divmod(k, c)
    if m != 0:
        return 0
    ac, bc = a // c, b // c
    x, y = x * d, y * d
    if x < 0:
        f = ((x % bc) - x) // bc
        x += bc * f
        y -= ac * f
    else:
        f, x = divmod(x, bc)
        y += ac * f
    if y > n:
        f = (y - n - 1) // ac + 1
        x += bc * f
        y -= ac * f
    # print(x, y, a * x + b * y)

    ans = 0
    base = fn * fn % MOD
    while x <= n and y >= 0:
        tmp = base * invs[x]
        tmp %= MOD
        tmp *= invs[n - x]
        tmp %= MOD
        tmp *= invs[y]
        tmp %= MOD
        tmp *= invs[n - y]
        ans += tmp
        ans %= MOD
        x += bc
        y -= ac

    return ans


n, a, b, k = map(int, input().split())

print(solve(n, a, b, k))


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

    vector<int>a(n+2,0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    vector<int>left(n+2,0);
    for (int i=1;i<=n+1;i++) {
        left[i]=max(a[i],left[i-1]);
    }

    vector<int>right(n+2,0);
    for (int i=n;i>=0;i--) {
        right[i]=max(a[i],right[i+1]);
    }

    int answer=0;
    for (int i=1;i<=n;i++) {
        cout<<max(left[i-1],right[i+1])<<endl;
    }
}

Measured memory_bytes: 3968
// https://atcoder.jp/contests/abc052/tasks/arc067_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
const int MOD = 1e9 + 7;

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <size_t max_N, size_t prime_size> struct Prime {
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            if (sieve[i]) {
                prime[counter] = i;
                ++counter;
                if (counter > prime_size)
                    break;
            }
            for (int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    constexpr auto p = Prime<100000, 9592>();
    unordered_map<ll, ll> mp;
    ll ans = 1;
    FOR(i, 2, n + 1) {
        // 素数の場合
        if (p.sieve[i]) {
            // n!の中で素因数iは何乗か？
            ll tot = 0;
            for (int j = i; j <= n; j *= i) { // 2,4,8...
                tot += n / j;                 // 12/2 + 12/4 + 12/8
            }
            //約数の個数*(tot+1)%modで更新
            ans = (ans * (tot + 1)) % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<pair<int, int> > v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        pair<int, int> p = make_pair(a, b);
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    ll t = k;
    int ans = 0;
    for(int i = 0; i < v.size(); i++){
        int a = v[i].first;
        int b = v[i].second;
        t -= b;
        if(t <= 0){
            ans = a;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string ans;
    stringstream ss;
    stringstream rs;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    for(;true;){
        int rank;
        int a;
        a = abs(n);
        rank = a % 2;
        n = (n - rank) / (-2);
        ss << rank;
        if (n == 1 or n == -1){
            break;
        }
    }
    if (n == 1){
        ss << 1;
    }else{
        ss << 11;
    }
    ss >> ans;
    reverse(ans.begin(),ans.end());
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){int i,j,k,c,t,b;Scanner s=new Scanner(System.in);for(;(t=s.nextInt())>0;System.out.println(b))for(b=0,i=1;i<=t;i++)for(j=i+2;j<=t;b+=c==t?1:0,j++)for(c=0,k=i;k<j;k++)c+=k;}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int n, s;
ll ans;
int x[maxn];
ll p[maxn];
ll ttm[maxn];
int ls[maxn], pp[maxn];
void caltm(int a) {
	if (!ls[a]) return ;
	else if (ttm[a]) return ;
	else caltm(ls[a]), ttm[a] = ttm[ls[a]] + pp[a];
}
int main() {
	int a, b, c;
	ll k;
	cin >> a >> b >> c >> k;
	if (k & 1) cout << b - a;
	else cout << a - b;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int x;
    cin >> x;
    int temp = 0;
    REP(i, 0, x)
    {
        temp += i + 1;

        if (x <= temp)
        {
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main (String...args) {
        Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int answer = -1;
        for (int i=b*10; i<(b+1)*10; i++) if (i*8/100==a){ answer = i; break;}
        System.out.println(answer);}
}

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

const ll MOD = 1e9+7;
int l[2000];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l[i];
	}
	sort(l,l+n);
	for(int i=n-1;i>-1;i--)
	{
		for(int j=i-1;j>-1;j--)
		{
			ll tmp=upper_bound(l,l+n,l[i]+l[j]-1)-upper_bound(l,l+n,l[i]-l[j]);
			if(l[i]>l[i]-l[j] && l[i]<l[i]+l[j])
				tmp--;
			if(l[j]>l[i]-l[j] && l[j]<l[i]+l[j])
				tmp--;
			//cerr<<tmp<<endl;
			ans+=max(tmp,0LL);
		}
	}
	ans/=3;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int x;
    cin >> x;

    if (x < 1200)
        cout << "ABC";
    else
        cout << "ARC";
    
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3552
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

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

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}


int solve( ){

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

int count=0,count1=0;
rep(i,0,n)
{
  if(s[i]=='#')count++;
  else
    count1++;
}
int ans=min(count1,count);
int cnt=0,cnt1=0;
rep(i,0,n)
{
    if(s[i]=='#')cnt++;
    else cnt1++;
    ans=min(ans,cnt+count1-cnt1);
}
cout<<ans;
return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);


 //sieve();
  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;
    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 //  cout << "Processor time taken is "
   //   << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

#define rep0(n) for(int i=0;i<n;i++)
#define rep(n) for(int i=1;i<=n;i++)

double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;

int yesno(bool flag, string yes, string no) {
	if (flag)cout << yes << endl;
	else cout << no << endl;
	return 0;
}

int printint(int n) {
	cout << n << endl;
	return 0;
}

int prints(string s) {
	cout << s << endl;
	return 0;
}

int ans;

int main() {

	int n, d, x;
	int a[110];
	cin >> n >> d >> x;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ans += (d - 1) / a[i] + 1;
	}
	ans += x;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int box(int r,int g,int b,int N){
    int count = 0;
    for (int  i = 0; i < N/r+1; i++){
        for (int  j = 0; j < (N-i*r)/g+1; j++){
            if((N-(i*r+j*g))%b == 0)
                count++;
        }
    }
    return count;
}


int main(){
    int N,R,G,B;
    cin >> R >> G >> B >> N;

    cout << box(R,G,B,N) << endl;

    return 0;

}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dp = [[0] * w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i == j == 0:
            continue
        elif i == 0:
            dp[i][j] = dp[i][j - 1]
            if not s[i][j] == s[i][j - 1]:
                dp[i][j] += 1
        elif j == 0:
            dp[i][j] = dp[i - 1][j]
            if not s[i][j] == s[i - 1][j]:
                dp[i][j] += 1
        else:
            a, b = dp[i][j - 1], dp[i - 1][j]
            if not s[i][j] == s[i][j - 1]:
                a += 1
            if not s[i][j] == s[i - 1][j]:
                b += 1
            dp[i][j] = min(a, b)
print((dp[h - 1][w - 1] - dp[0][0] + [s[0][0], s[h - 1][w - 1]].count("#")) // 2)

Measured memory_bytes: 3188
N = int(input())
list = list(map(int, input().split(' ')))
a1_list = [0]
#　累積和
for a1 in list:
    # print(a1)
    a1_list.append(a1+a1_list[-1])
a1_list.pop(0)
list_sum = a1_list[-1]
# print(list_sum)
abstmp=1000
numtmp=0
for i in range(len(a1_list)):
    # print("abstmp"+str(abstmp))
    if(abs((list_sum - a1_list[i])-a1_list[i]) < abstmp):
        abstmp = abs((list_sum - a1_list[i])-a1_list[i])
print(abstmp)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

bool mark[12][12];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void dfs(int y, int x, vector<string> &tb){
	mark[y][x] = true;

	FOR(i, 4){
		if (x + dx[i] < 0 || x + dx[i] >= 12 || y + dy[i] < 0 || y + dy[i] >= 12) continue;
		if (tb[y + dy[i]][x + dx[i]] == '1' && !mark[y + dy[i]][x + dx[i]]){
			dfs(y + dy[i], x + dx[i], tb);
		}
	}
	return;
}

int main(){
	while (1){
		string s; cin >> s;
		if (cin.eof()) return 0;

		memset(mark, false, sizeof(mark));

		vector<string> tb(12, "");
		tb[0] = s;
		REP(i, 1, 12){
			cin >> tb[i];
		}

		int ans = 0;
		FOR(i, 12){
			FOR(j, 12){
				if (tb[i][j] == '1' && !mark[i][j]){
					dfs(i, j, tb);
					ans++;
				}
			}
		}

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

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int dp[n];
	dp[0]=0; dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4408
S = input().rstrip()
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            func = S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]
            if eval(func) == 7:
                print(func + '=7')
                exit()


Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
  int S,h,m,s;
  scanf("%d",&S);
  h=S/3600;
  m=(S-(h*3600))/60;
  s=S-(h*3600)-(m*60);
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define bye(x) return void (cout <<(x) << endl);
#define all(e) (e).begin(), (e).end()
#define pb push_back

template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}


int n, m;

struct S {
  int idx;
  int cost;
  bool operator< (const struct S& other) const {
    if (cost == other.cost) return idx > other.idx;
    return cost > other.cost;
  }
};

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  string s; cin >> s;
  ++n;


  priority_queue<S> pq;
  pq.push({0,0});

  vector<int> prev(n);
  for (int i = 1; i < n; i++) {
    if (s[i] == '1') continue;
    while (!pq.empty() && pq.top().idx < i - m) pq.pop();
    if (pq.empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto s = pq.top();
    pq.push({i, s.cost + 1});
    prev[i] = s.idx;
  }
  vector<int> ans;
  int p = n - 1;
  while (p != 0) {
    int np = prev[p];
    ans.push_back(p - np);
    p = np;
  }
  reverse(ans.begin(),ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 1480
#include <cstdio>
#include <cstring>
int n, l[44]; char c[12];
int main() {
	while (scanf("%d", &n), n) {
		for (int i = 0; i < n; i++) scanf("%s", c), l[i] = strlen(c);
		for (int i = 0; i < n; i++) {
			int s = 0, v = 0;
			for (int j = i; j < n && s < 5; j++) {
				v += l[j];
				if (3 % (s + 1) == 0) {
					if (v > 5) break;
					else if (v == 5) s++, v = 0;
				}
				else {
					if (v > 7) break;
					else if (v == 7) s++, v = 0;
				}
			}
			if (s == 5) {
				printf("%d\n", i + 1); break;
			}
		}
	}
}

Measured memory_bytes: 2592
# coding: utf-8
# linearSearch
def linear(n,s,key):
    s[n:] = [key]
    i = 0
    while s[i] != key:
        i += 1
    return i != n
n = int(input())
s = list(map(int,input().split()))
input()
t = list(map(int,input().split()))
cnt = 0
for i in t:
    if linear(n,s,i):
        cnt += 1
print(cnt)

Measured memory_bytes: 8516
def f(n):
    rootn = int((N**0.5)+1)
    A = range(1, rootn)
    min_output = 11
    for i in A:
        if (N % i) == 0:
            ilen = len(str(i))
            B = len(str(N//i))
            if ilen < B:
                if min_output > B:
                    min_output = B
            else:
                if min_output > ilen:
                    min_output = ilen
    return min_output
N = int(input())
print(f(N))

Measured memory_bytes: 3060
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	long long cur=1;
	for(int i=0;i<=a;i++){
		cur=cur*2+1;
	}
	printf("%lld\n",cur-1);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k;
    cin >> n >> k;
    ll b=k+1;
    ll a=k;
    ll ans=0;
    while(b<=n){
        while(a<=n){
            if(a==0) ans--;
            if(a+b<=n) ans+=(b-k);
            else ans+=min(b-k,n-a+1);
            a+=b;
        }
        a=k;
        b++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;

class Main {
    private static void swap(int[] a, int i, int j) {
        a[i] = a[i] + a[j];
        a[j] = a[i] - a[j];
        a[i] = a[i] - a[j];
    }

    public static void main(String[] args) {
        Scanner get = new Scanner(System.in);
        int[] a = new int[3];
        for(int i = 0; i < 3; ++i) {
            a[i] = get.nextInt();
        }
        swap(a, 0, 1);
        swap(a, 0, 2);
        for(int i = 0; i < 3; ++i) {
            System.out.print(a[i] + " ");
        }
    }
}

Measured memory_bytes: 22736
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#define MAX 101

int n;
int p[MAX];
int ans;

int min(int x, int y){
    if(x <= y) return x;
    else return y;
}

int Matrix_chain(int p[]){
  int i,j,k,l;
  int q;
  int m[MAX][MAX];

  for(i = 1; i <= n; i++) {
      m[i][i] = 0;
  }

  for(l = 2; l <= n; l++){
      for(i=1; i <= n-l+1; i++){
          j = i+l-1;
          m[i][j] = INT_MAX;

          for(k = i; k <= j-1; k++){
              q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
              m[i][j] = min(m[i][j],q);
          }
      }
  }

  ans = m[1][n];
  return ans;
}

int main() {
    int i;
    int r, c;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d", &r, &c);
        if(i == 0){
            p[i] = r;
            p[i+1] = c;
        }
        else p[i+1] = c;
    }

    p[n] = c;
    printf("%d\n", Matrix_chain(p));
    return 0;
}

Measured memory_bytes: 636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int n;
  cin >> n;
  bool f = false;
  REP(i, 10) {
    REP(j, 10) {
      if (i * j == n) {
        f = true;
      }
    }
  }
  if (f)
    yOUT;
  else
    nOUT;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 384
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let mut graph = vec![vec![]; 4];
    for _ in 0..3 {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut count = 0;
    for i in 0..4 {
        if graph[i].len() == 1 {
            count += 1;
        }
    }
    if count == 2 {
        println!("YES");
    } else {
        println!("NO");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

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

    string input ="", output = "";

    while(getline(cin, input)) {
        for (int i = 0; i < input.size(); i++) {
            if (input[i] >= 'a' && input[i] <= 'z')
                cout << char(input[i] + ('A' - 'a'));
            else
                cout << char(input[i]);
        }
        cout << endl;
    }
    //cout << output;
}

Measured memory_bytes: 1176
# https://atcoder.jp/contests/abc106/tasks/abc106_b

def divisors(n)
  ret = 0;
  1.upto(n) do |i|
    break if i * i > n
    if n % i == 0
      ret += 1
      ret += 1 if i != n / i
    end
  end
  ret
end

N = gets.to_i
vs = (1..N).select(&:odd?).select { |i| divisors(i) == 8 }

puts vs.size


Measured memory_bytes: 1788
L, R = gets.chomp.split(' ').map { |i| { scale: i.to_i/2019, mod: i.to_i%2019 } }

if L[:scale] == R[:scale]
    left = L[:mod]
    right = R[:mod]
    puts (left..right).to_a.combination(2).reduce(2019) {
        |min, numset| [min, numset[0]*numset[1]%2019].min
    }
else
    puts 0
end


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

char a[16][16];

bool is1(int i,int j){
	return i >= 0 && i < 8 && j >= 0 && j < 8 && a[i][j] == '1';
}

int main(){
	while(1){
start:
		for(int i = 0; i < 8;i++){
			if(scanf("%s",a[i]) != 1){
				return 0;
			}
		}

		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				if(a[i][j] == '1'){
					if(is1(i,j+1) && is1(i+1,j) && is1(i+1,j+1)){
						puts("A");
					}
					else if (is1(i+1,j) && is1(i+2,j) && is1(i+3,j)){
						puts("B");
					}
					else if(is1(i,j+1) && is1(i,j+2) && is1(i,j+3)){
						puts("C");
					}
					else if(is1(i+1,j-1) && is1(i+1,j) && is1(i+2,j-1)){
						puts("D");
					}
					else if(is1(i,j+1) && is1(i+1,j+1) && is1(i+1,j+2)){
						puts("E");
					}
					else if(is1(i+1,j) && is1(i+1,j+1) && is1(i+2,j+1)){
						puts("F");
					}
					else if(is1(i,j+1) && is1(i+1,j-1) && is1(i+1,j)){
						puts("G");
					}

					goto start;	
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3080
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,m;
  cin >> n >> m;
  ll cnt[n];
  bool exist[n];
  fill(cnt,cnt+n,1);
  fill(exist,exist+n,false);
  exist[0] = true;
  REP(i,m){
    ll x,y;
    cin >> x >> y;
    x--,y--;
    if(cnt[x]==1){
      if(exist[x]){
        exist[x] = false;
        exist[y] = true;
      }else{

      }
    }else{
      if(exist[x]){
        exist[y] = true;
      }else{

      }
    }
    cnt[x]--, cnt[y]++;
  }
  ll ans = 0;
  REP(i,n) ans += exist[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

vector<ll> parent, counter;
vector<vector<ll>> child, node;

void makeTree(ll num, ll parentNum){
    parent[num] = parentNum;
    for(int i = 0; i < node[num].size(); i++){
        if(node[num][i] == parentNum)continue;
        child[num].pb(node[num][i]);
        makeTree(node[num][i], num);
    }
}
void solve(ll num, ll parentNum){
    counter[num] += counter[parentNum];
    for(int i = 0; i < child[num].size(); i++){
        solve(child[num][i], num);
    }
}

int main(){

    ll N, Q;
    cin >> N >> Q;
    parent = vector<ll>(N+1);
    counter = vector<ll>(N+1, 0);
    child = vector<vector<ll>>(N+1);
    node = vector<vector<ll>>(N+1);
    ll a, b;
    for(int i = 0; i < N-1; i++){
        cin >> a >> b;
        node[a].pb(b);
        node[b].pb(a);
    }
    makeTree(1, 0);
    ll p, x;
    for(int i = 0; i < Q; i++){
        cin >> p >> x;
        counter[p] += x;
    }
    solve(1, 0);
    for(int i = 1; i <= N; i++){
        if(i != 1)cout << SPACE;
        cout << counter[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 36736
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int x1, y1, x2, y2, x3, y3; cin>>x1>>y1>>x2>>y2>>x3>>y3;
    double a = hypot(abs(x1 - x2), abs(y1 - y2));
    double b = hypot(abs(x2 - x3), abs(y2 - y3));
    double c = hypot(abs(x3 - x1), abs(y3 - y1));
    double s = (a + b + c) / 2;
    double S = sqrt(s * (s - a) * (s - b) * (s - c));
    double r = S / s;

    double ok = 0, ng = 1e9;
    double maxedge = max({a, b, c});
    for(int i=0; i<1000; i++){
        double mid = (ok + ng) / 2;

        if(maxedge * (r - mid) / r >= 2 * mid) ok = mid;
        else ng = mid;
    }

    cout << fixed << setprecision(10) << ok << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

/*#define Conn(x,y) x##y
#define ToChar(x) #@x
#define ToStr(x) #x*/


typedef long long int ll;

ll num[ten5];
ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//set<char> sch;
//set<string> sStr;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    long long int m,n,o,i,j,k=1;
    string s,s1;
    cin>>s;
    cin>>s1;
    for(i=0;i<s.size();i++)
    {
        if(num[s[i]]==0)
            num[s[i]]=s1[i];
        else
        {
            if(num[s[i]] != s1[i])
            {
                cout<<"No";
                return 0;
            }
        }
        if(num2[s1[i]]==0)
            num2[s1[i]]=s[i];
        else
            if(num2[s1[i]] != s[i])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}





Measured memory_bytes: 3920
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()){
    int u = S.top();
    S.pop();
    for(int i = 0;i<G[u].size();i++){
      int v = G[u][i];
      if(color[v]==NIL){
	color[v] = c;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  for(int i = 0; i< n; i++) color[i] = NIL;
  for(int u = 0; u<n;u++){
    if(color[u] == NIL) dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;

  cin>>n>>m;

  for(int i = 0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  assignColor();

  cin>>q;

  for(int i = 0;i<q;i++){
    cin>>s>>t;
    if(color[s] == color[t]){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 8984
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int main(){
int a[3]={read(),read(),read()};
sort(a,a+3);
write(a[2]-a[0]),pl;
}

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

#define AAA 10

void solve(long long X)
{
    long long a;
    for (long long i = X;; ++i)
    {
        int flag = 1;
        for (long long j = 2; j < i; ++j)
        {
            if (i % j == 0)
            {
                flag = 0;
                continue;
                
            }
        }
        if(flag){
          cout<< i << endl;
          return;  
        } 
        

    }
}

int main()
{
    long long X;
    scanf("%lld", &X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int s[10000];
    int n,q,i,j,c=0,t;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>s[i];
    cin>>q;
    for(i=0;i<q;i++)
    {
        cin>>t;
        for(j=0;j<n;j++)
        {
            if(s[j]==t)
                break;
        }
        if(j<n)
            c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define int long long
using namespace std;
int solve(int a, int b) {
	// cout << a << ' ' << b << '\n';
	if(a < b) swap(a, b);
	if(b == 0) return 0;
	if(a % b == 0) return 2 * a - b;
	int res = a / b;

	return 2 * res * b +  solve(a % b, b);
}
int N, X;
signed main() {
	cin >> N >> X;
	cout << N + solve(N - X, X);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        while (s.length() != 2) {
            s = s.substring(0, s.length() - 2);
            String s1 = s.substring(0, s.length() / 2 - 1);
            String s2 = s.substring(s.length() / 2, s.length() - 1);
            if (s1.equals(s2)) {
                System.out.println(s.length());
                System.exit(0);
            }
        }
        System.out.println(1);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	vector<int> a{ 0,1,3,1,2,1,2,1,1,2,1,2,1, };
	int x, y;
	cin >> x >> y;

	cout << (a[x] == a[y] ? "Yes" : "No") << endl;

}

Measured memory_bytes: 3592
#include<stdio.h>
void insertionSort(int[], int);
int main(){
    int n,i;
    int a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    }
 insertionSort(a,n);
 return 0;
}
void insertionSort(int A[],int N){
    int i,j,v;
    for(j=0;j<N;j++){
      if(j!=0) printf(" ");
      printf("%d",A[j]);
    }
   printf("\n");
     for(i=1;i<N;i++){
    v = A[i];
    j = i - 1;
   while (j >= 0 && A[j] > v){
   A[j+1] = A[j];
     j--;
    A[j+1] = v;
   } 
   for(j=0;j<N;j++){
     if(j!=0) printf(" ");
     printf("%d",A[j]);
   }
     printf("\n");
     }
}



Measured memory_bytes: 2124
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static final int[][] d = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int W = sc.nextInt();
			if (W == 0) {
				sc.close();
				break;
			}
			int H = sc.nextInt();

			char[][] mapL = new char[H + 2][];
			char[][] mapR = new char[H + 2][];

			char[] wall = new char[W + 2];
			Arrays.fill(wall, '#');
			mapL[0] = wall;
			mapR[0] = wall;
			mapL[H + 1] = wall;
			mapR[H + 1] = wall;

			for (int i = 0; i < H; i++) {
				String lineL = "#" + sc.next() + "#";
				mapL[i + 1] = lineL.toCharArray();
				String lineR = "#" + sc.next() + "#";
				mapR[i + 1] = lineR.toCharArray();
			}

			Integer[] posi = new Integer[4];
			for (int i = 0; i < mapL.length; i++) {
				for (int j = 0; j < mapL[i].length; j++) {
					if (mapL[i][j] == 'L') {
						posi[0] = i;
						posi[1] = j;
					}
					if (mapR[i][j] == 'R') {
						posi[2] = i;
						posi[3] = j;
					}
				}
			}

			boolean[][] used = new boolean[5051][5051];
			Deque<Integer[]> bfs = new ArrayDeque<Integer[]>();
			bfs.addLast(posi);
			used[posi[0] * 100 + posi[1]][posi[2] * 100 + posi[3]] = true;
			boolean cleared = false;
			bfs: while (!bfs.isEmpty()) {
				Integer[] poll = bfs.pollFirst();
				int iL = poll[0];
				int jL = poll[1];
				int iR = poll[2];
				int jR = poll[3];

				for (int i = 0; i < d.length; i++) {
					char nextL = mapL[iL + d[i][0]][jL + d[i][1]];
					char nextR = mapR[iR + d[i][0]][jR - d[i][1]];

					if (nextL == '#' && nextR == '#') {
						continue;
					} else if (nextL == '%' && nextR == '%') {
						// YES
						cleared = true;
						break bfs;
					} else if ((nextL == '%' && nextR != '%') || (nextL != '%' && nextR == '%')) {
						continue;
					} else {
						if (nextL == '#' && nextR == '.' && !used[iL * 100 + jL][(iR + d[i][0]) * 100 + jR - d[i][1]]) {
							used[iL * 100 + jL][(iR + d[i][0]) * 100 + jR - d[i][1]] = true;
							Integer[] push = { iL, jL, iR + d[i][0], jR - d[i][1] };
							bfs.addLast(push);
						} else if (nextR == '#' && nextL == '.'
								&& !used[(iL + d[i][0]) * 100 + jL + d[i][1]][iR * 100 + jR]) {
							used[(iL + d[i][0]) * 100 + jL + d[i][1]][iR * 100 + jR] = true;
							Integer[] push = { iL + d[i][0], jL + d[i][1], iR, jR };
							bfs.addLast(push);
						} else if (nextL == '.' && nextR == '.'
								&& !used[(iL + d[i][0]) * 100 + jL + d[i][1]][(iR + d[i][0]) * 100 + jR - d[i][1]]) {
							used[(iL + d[i][0]) * 100 + jL + d[i][1]][(iR + d[i][0]) * 100 + jR - d[i][1]] = true;
							Integer[] push = { iL + d[i][0], jL + d[i][1], iR + d[i][0], jR - d[i][1] };
							bfs.addLast(push);
						}
					}
				}
			}
			if (cleared) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
			System.gc();

		}

	}
}

Measured memory_bytes: 169368
import sys
from heapq import heappush, heappop

q = []

while True:
    order = sys.stdin.readline().split()
    
    if order[0] == 'end':
        break
    
    if order[0] == 'extract':
        print(-heappop(q))
    else:
        heappush(q, -int(order[1]))

Measured memory_bytes: 47532
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] array = str.split(" ");
        int[] a =new int[3];
        int sum = 0;;
 
        for(int i = 0; i < 3; i++){
            a[i] = Integer.parseInt(array[i]);
            sum = sum + a[i];
        }
        
        if(a[0]>a[1] && a[0]>a[2]){
        	sum = sum - a[0];
        } else if(a[1]>a[0] && a[1]>a[2]){
        	sum = sum - a[1];
        } else{
        	sum = sum - a[2];
        }
        
        System.out.println(sum);
 
	}
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> d(n);
  for(int i = 0; i < n; i++) cin >> d.at(i);
  
  int ans = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      ans += d.at(i) * d.at(j);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    long long int x=0,y=0,z=0,N,Y;
    cin >> N >> Y;
    Y /= 1000;
    for(x=0;x<=N;x++){
        for(y=0;y<=N;y++){
            z = N-x-y;
            if(Y==x*10+y*5+z&&z>=0){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll ans=0;
  rep(i,n){
    if(i==0){
      ans+=a[i]/2;
      a[i]=a[i]%2;
    }
    else{
      if(a[i-1]==1&&a[i]>=1){
        a[i-1]--;
        a[i]--;
        ans++;
      }
      ans+=a[i]/2;
      a[i]=a[i]%2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024