akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    static final int MOD = 1000000007;  // 10**9 + 7

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static StringTokenizer st;
    private static int N;
    private static int K;

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

    public static void main(String[] args) throws IOException {
        N = readInt();
        K = readInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i]=readInt();
        }

        pw.println((solve(A) + MOD) % MOD);
        pw.close();
    }

    private static long solve(long[] A) {
        Arrays.sort(A);

        if (A[0] >= 0) {
            return productMod(A, N - K, N);
        }
        if (A[N - 1] <= 0) {
            if (K % 2 == 0) return productMod(A, 0, K);
            else return productMod(A, N - K, N);
        }

        if (K == N) {
            return productMod(A,0, N);
        }

        // A[0] < 0 < A[N-1] and K < N now.
        // Answer cannot be negative now, since A[0] * product(A, 1, K) and
        // product(A, 1, K) * A[N-1] cannot be negative at the same time.

        int lastNegativeIndex = 0;
        while (A[lastNegativeIndex + 1] < 0) lastNegativeIndex++;

        int firstPositiveIndex = N - 1;
        while (A[firstPositiveIndex - 1] > 0) firstPositiveIndex--;

        if ((lastNegativeIndex + 1) / 2 * 2 + N - firstPositiveIndex < K) return 0;
        // Answer must be > 0 now.

        // Two pointers
        int negativeIndex = 0;
        int positiveIndex = (K % 2 == 0) ? N - 1 : N - 2;
        long answer = (K % 2 == 0) ? 1 : A[N - 1];
        long count = (K % 2 == 0) ? 0 : 1;
        // count == K (mod 2) now

        // Choose either two positive factors or two negative factors.
        while ((count < K) && (negativeIndex < lastNegativeIndex || positiveIndex > firstPositiveIndex)) {
            long pN = (negativeIndex < lastNegativeIndex) ?
                    A[negativeIndex] * A[negativeIndex + 1] : 0;
            long pP = (positiveIndex > firstPositiveIndex) ?
                    A[positiveIndex] * A[positiveIndex - 1] : 0;

            if (pN <= pP) {
                answer = answer * (pP % MOD) % MOD;
                positiveIndex -= 2;
            } else {
                answer = answer * (pN % MOD) % MOD;
                negativeIndex += 2;
            }

            count += 2;
        }

        assert count == K : "Not enough numbers in the product";
        return answer;
    }

    static long productMod(long[] A, int start, int endExclusive) {
        long p = 1;
        for (int i = start; i < endExclusive; i++) {
            p = p * A[i] % MOD;
        }
        return p;
    }
}


Measured memory_bytes: 57160
import sys
inputs = sys.stdin.readline
def main():
	ans = 1
	a = 0
	b = 0
	flg2 = 0
	N, M = map(int,inputs().split())
	A =[0]*(M+1)
	for i in range(M):
		a = int(inputs())
		A[i] = a-1-b
		b = a + 1
	A[M] = N - b
	A.sort()
	if A [0] < 0:
		flg2 = 1
	p = 1
	q = 1
	t = 0
	flg = 0
	while (A[t]<2):
		t = t+1
		if t > M:
			flg = 1
			break
	for k in range(2,N+1):
		r = p + q
		p = q
		q = r
		if flg == 1:
			break
		while (A[t] == k):
			ans = ans*r%1000000007
			t += 1
			if t == M+1:
				flg = 1
				break
		if flg == 1:
			break
	if flg2 == 0:
		print(ans%1000000007)
	else:
		print(0)
main()

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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> ame(2,vector<int>(N));
  vector<vector<int>> sum(2,vector<int>(N));
  for(int i=0;i<N;i++){
    cin>>ame.at(0).at(i);
    if(i>0){
      sum.at(0).at(i)=sum.at(0).at(i-1)+ame.at(0).at(i);
    }else{
      sum.at(0).at(0)=ame.at(0).at(0);
    }
  }
  for(int i=0;i<N;i++){
    cin>>ame.at(1).at(i);
    if(i>0){
      sum.at(1).at(i)=max(sum.at(1).at(i-1)+ame.at(1).at(i),sum.at(0).at(i)+ame.at(1).at(i));
    }else{
      sum.at(1).at(0)=sum.at(0).at(0)+ame.at(1).at(i);
    }
  }
  cout<<sum.at(1).at(N-1)<<endl;
  
}

Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int n;
const int maxn = 2e5 + 2;
ll ans = 0;
vi v[maxn];
void dfs(int u,int p){
	for(auto x:v[u]){
		if(x == p)continue;
		else if(x < u){
			ll temp = 0;
			temp = x*(u-x);
			ans += temp;
		}
		else{
			ll temp = (x-u)*(n-x+1);
			ans += temp; 
		}
		dfs(x,u);
	}
	// cout<<u<<" "<<ans<<"\n";
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	ans = n;
	dfs(1,1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 23896
#include <bits/stdc++.h>
using namespace std;
long long dp[52][2501],n,a,sum,s;
int main()
{
	cin>>n>>a;
	dp[0][0]=1;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		for(int k=n-1;k>=0;k--)
			for(int l=2500-s;l>=0;l--) 
			     dp[k+1][l+s]+=dp[k][l];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=2500;j++)
			sum+=dp[i][j]*(j==i*a);
	cout<<sum<<endl;
}

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

int main()
{
    int a,b,tb,n = 1;
    cin >> a >> b;
    tb = b;
    while(tb){
        tb /= 10;
        n *= 10;
    }

    for(int i = 1; i < 320; i++)
        if(i * i == a * n + b) tb = 1;

    cout << (tb == 1 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

string rev(string s)
{
    int n=s.length();
    string r(n,'0');
    for(int i=s.length()-1;i>-1;i--)
        r[n-1-i]=s[i];
    return r;
}

int main()
{
    fastio;
    string s;
    cin >> s;
    int q;
    cin >> q;
    string s1="",s2="";
    int f=0;
    for(int i=0;i<q;i++)
    {
        int t;
        cin >> t;
        if(t==1)
            f=(f+1)%2;
        else
        {
            int a;char c;
            cin >> a >> c;
            if(f==0)
            {
                string s3(1,c);
                if(a==1)
                    s1=s3+s1;
                else
                    s2=s2+s3;
            }
            else
            {
                string s3(1,c);
                if(a==1)
                    s2=s2+s3;
                else
                    s1=s3+s1;
            }
        }
    }
    //cout << s1 <<  " " << s2 << endl;
    if(f==0)
        cout << s1+s+s2 << endl;
    else
    {
        cout << rev(s2)+rev(s)+rev(s1) << endl;
    }
}

Measured memory_bytes: 1660
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		long x = 0;
		int count = 0;
		while (Math.pow(2, count + 1) <= k) {
			count++;
		}
		while (count >= 0) {
			long tmp = x + (long) Math.pow(2, count);
			if (tmp > k) {
				count--;
				continue;
			}
			long sum = 0;
			long osum = 0;
			for (int i = 0; i < n; i++) {
				sum += tmp ^ a[i];
				osum += x ^ a[i];
			}
			if (sum >= osum) {
				x = tmp;
			}
			count--;
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += x ^ a[i];
		}
		System.out.println(ans);
	}
}

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

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

  if (a + b >= c){
    cout << "No" <<endl;
  }
  else if (4*a*b >= (c-a-b)*(c-a-b)){
    cout << "No" <<endl;
  }
  else {
    cout << "Yes"<< endl;
  }
  
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    int n,a,b,c,x;
    cin>>n>>a>>b>>c>>x;
    if(!n&&!a&&!b&&!c&&!x)break;
    vector<int> y(n);
    for(int i=0;i<n;i++)cin>>y[i];
    int np=0;
    bool f=false;
    if(x==y[0])np++;
    for(int i=0;i<=10000;i++){
      if(np==n){
        cout<<i<<endl;
        f=true;
        break;
      }
      x=(a*x+b)%c;
      if(x==y[np])np++;
    }
    if(!f)cout<<-1<<endl;
  }
}



Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    ll ans = 1e18;
    for(int i=k-1;i<n;i++){
        ll che = min(abs(a.at(i-k+1)),abs(a.at(i)))+abs(a.at(i-k+1)-a.at(i));
        ans = min(ans,che);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<lint> a(m), b(m);
    UnionFind uf(n);
    lint ret = n - 1;
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        if (uf.unite(a[i], b[i]))
            ret--;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6104
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int cnt[13]; CLR(cnt);
  cnt[0] = 1;
  FOR(i,0,N) {
    int d; cin >> d;
    cnt[min(d, 24-d)]++;
  }
  if(cnt[0] >= 2 || cnt[12] >= 2) {
    cout << 0 << endl;
    return 0;
  }
  FOR(i,1,12) {
    if(cnt[i] >= 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  int ans = 0;
  FOR(i,0,1<<11) {
    vector<int> v;
    v.push_back(0);
    if(cnt[12]) v.push_back(12);
    FOR(j,0,11) {
      // 1~11
      if(cnt[j+1] == 1) {
        if((i>>j)&1) v.push_back(j+1);
        else v.push_back(23-j);
      }
      else if(cnt[j+1] == 2) {
        v.push_back(j+1);
        v.push_back(23-j);
      }
    }
    sort(v.begin(), v.end());
    int mn = 1e9;
    FOR(i,0,v.size()) {
      //cout << v[i] << endl;
      int j = (i + 1) % v.size();
      mn = min(mn, min(abs(v[i]-v[j]), 24-abs(v[i]-v[j])));
    }
    ans = max(ans, mn);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
	int K, T;
	cin >> K >> T;
	vector<int> a;
	for (int i = 0; i < T; i++) {
		int buff;
		cin >> buff;
		a.push_back(buff);
	}
	int previndex = -1;
	int answer = 0;
	for (int i = 0; i < K; i++) {
		int maximum = 0;
		int maximumindex = -1;
		for (int j = 0; j < T; j++) {
			if (a[j] > maximum && previndex != j) {
				maximum = a[j];
				maximumindex = j;
			}
		}
		if (maximumindex != -1) {
			a[maximumindex]--;
			previndex = maximumindex;
		}
		else {
			break;
		}
	}
	for (int i = 0; i < T; i++) {
		if (a[i] != 0) {
			answer += a[i];
		}
	}
	cout << answer << endl;
}

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();
        char[] c = s.toCharArray();

        long k = sc.nextLong();

        long ans = 0;

        int cnt = 1;
        for (int i=0; i<s.length()-1; i++){
            if (c[i]==c[i+1]) {
                cnt++;
            }
        }

        if (cnt==s.length()){
            System.out.println(((long)s.length()*k)/2);
        }else {
            if (c[0]==c[s.length()-1]){
                String t = s+s;

                char[] cc = t.toCharArray();
                long tmp = 0;
                for (int j=0; j<t.length()-1; j++){
                    if (cc[j]==cc[j+1]){
                        tmp++;
                        j++;
                    }
                }
                for (int j=0; j<s.length()-1; j++){
                    if (c[j]==c[j+1]){
                        ans++;
                        j++;
                    }
                }

                if (tmp == ans*2){
                    System.out.println(ans*k);
                }else {
                    System.out.println(ans+(ans+1)*(k-1));
                }

            }else {
                for (int i=0; i<s.length()-1; i++){
                    if (c[i]==c[i+1]){
                        ans++;
                        i++;
                    }
                }
                System.out.println(ans*k);
            }
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long lli;
typedef lli elm;
typedef vector<vector<elm> > mat;

const lli mod = 1000000009LL;

mat getE(int n) {
  mat e(n, vector<elm>(n, 0));
  for(int i = 0; i < n; ++i) {
    e[i][i] = 1;
  }
  return e;
}

mat multiply(const mat &a, const mat &b) {
  if(a.size() == 0 || b.size() == 0 ||
     a[0].size() != b.size()) return mat();
  int s = a.size();
  int t = b.size();
  int u = b[0].size();
  mat c(s, vector<elm>(u, 0));
  for(int i = 0; i < s; ++i) {
    for(int j = 0; j < u; ++j) {
      for(int k = 0; k < t; ++k) {
        c[i][j] += (a[i][k] * b[k][j]) % mod;
        c[i][j] %= mod;
      }
    }
  }
  return c;
}

mat pow(const mat &a, const lli &n) {
  if(n == 0) return getE(a.size());
  mat b = pow(multiply(a, a), n/2);
  if(n & 1) return multiply(b, a);
  else return b;
}

lli W, H, N;
vector<pair<lli,lli> > pos;

int main() {
  while(cin >> W >> H >> N && (W|H|N)) {
    pos.clear();
    for(int i = 0; i < N; ++i) {
      lli x, y;
      cin >> x >> y;
      pos.push_back(make_pair(y-1,x-1));
    }
    pos.push_back(make_pair(H-1,0));
    ++N;
    sort(pos.begin(), pos.end());
    mat A = getE(W);
    for(int i = 0; i < W; ++i) {
      for(int j = 0; j < W; ++j) {
        A[i][j] = (abs(i-j) <= 1);
      }
    }
    mat x = vector<vector<lli> >(1, vector<lli>(W, 0LL));
    x[0][0] = 1LL;
    for(lli i = 0, y = 0; i < N; ) {
      lli dy = pos[i].first - y;
      y = pos[i].first;
      x = multiply(x, pow(A,dy));
      while(i < N && pos[i].first == y) {
        x[0][pos[i++].second] = 0;
      }
    }
    static int tc = 0;
    cout << "Case " << ++tc << ": " << x[0][W-1] << endl;
  }
  return 0;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A == B){
        cout << C << endl;
    }
    else if(B == C){
        cout << A << endl;
    }
    else{
        cout << B << endl;
    }
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

ll calc(ll x) {
  if (x == 1) return 1;
  return 2 * calc(x / 2) + 1;
}

int main() {
  ll h;

  cin >> h;

  ll ans = calc(h);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx[]= {0,0,1,-1,-1,1,-1,1};
int fy[]= {1,-1,0,0,-1,1,1,-1};
int fx1[]={0,1,1,1,0,-1,-1,-1};
int fy1[]={1,1,0,-1,-1,-1,0,1};*/



int main()
{
    FIO;
  //  #ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
  //  #endif
    int n,m,i,p,ans1=0,ans2=0,a[100010],b[100010];
	string s;
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		a[i]=0,b[i]=0;
	}    

	for(int i=0;i<m;i++){
		cin>>p>>s;
		if(s=="WA"&&a[p]==0)
			b[p]++;
		if(s=="AC"&&a[p]==0){
			++ans1;
			ans2+=b[p];
			a[p]=1;
		}
	}
	cout<<ans1<<" "<<ans2<<endl;
   

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int ans=0;
    string s;cin>>s;
    rep(i,s.size()){
        if(s.at(i)=='1'){
            ans++;
        }
    }
    cout<<ans<<endl;


}


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

vector<string> search(string S, char c, int K){
  set<string> A;
  for(int i=0; i<S.length(); i++){
    if (S[i] == c){
      for(int j=i+1; j<=i+K; j++){
        A.insert(S.substr(i, j-i));
      }
    }
  }

  vector<string> res;
  for(auto itr = A.begin(); itr != A.end(); itr++){
    res.push_back(*itr);
  }

  sort(res.begin(), res.end());
  return res;
}

int main(){
  string S; int K; cin >> S>> K;

  for(int i=0; i<26; i++){
    char c = 'a' + i;
    vector<string> res = search(S, c, K);

    //for(int j=0; j<res.size(); j++) cout << res[j] << endl;

    if(res.size() >= K){
      cout << res[K-1] << endl;
      return 0;
    } else {
      K -= res.size();
    }
  }
}


Measured memory_bytes: 384
import math


n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))

d1 = []
d2 = []
d3 = []
for i, j in zip(x, y):
    d1.append(abs(i - j))
    d2.append(abs(i - j)**2)
    d3.append(abs(i - j)**3)

print(sum(d1))
print(math.sqrt(sum(d2)))
print(sum(d3)**(1/3))
print(max(d1))




Measured memory_bytes: 5724
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll h = in(), w = in();
	auto grid = VV(char, h, w);
	REP(i, h) {
		string foo = in<string>();
		REP(j, w) {
			grid[i][j] = foo[j];
		}
	}
	if (grid[h - 1][w - 1] == '#') {
		cout << -1 << endl;
	} else {
		auto maze = VV(ll, h, w); REP(i, h)REP(j, w)maze[i][j] = grid[i][j] == '.' ? 0 : INFLL;
		ll dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
		queue<pair<ll, ll>>que;
		que.push(make_pair(w - 1, h - 1));
		auto is_walked = VVI(bool, h, w, false);
		is_walked[h - 1][w - 1] = true;
		while (!que.empty()) {
			auto pos = que.front(); que.pop();
			REP(i, 4) {
				ll x = pos.first + dx[i], y = pos.second + dy[i];
				if (0 <= x && x <= w - 1 && 0 <= y && y <= h - 1 && grid[y][x] == '.' && !is_walked[y][x]) {
					que.push(make_pair(x, y));
					is_walked[y][x] = true;
					maze[y][x] = maze[pos.second][pos.first] + 1;
				}
			}
		}
		if (!is_walked[0][0]) {
			cout << -1 << endl;
		} else {
			vector<pair<ll, ll>>path;
			path.push_back(make_pair(0, 0));
			int x_now = 0, y_now = 0;
			while (true) {
				pair<ll, ll>next;
				ll min_val = INFLL;
				REP(i, 4) {
					ll x = x_now + dx[i], y = y_now + dy[i];
					if (0 <= x && x <= w - 1 && 0 <= y && y <= h - 1) {
						if (maze[y][x] < min_val) {
							min_val = maze[y][x];
							next = make_pair(x, y);
						}
					}
				}
				path.push_back(next);
				x_now = next.first;
				y_now = next.second;
				if (x_now == w - 1 && y_now == h - 1)break;
			}
			ll res = 0;
			REP(i, h) {
				REP(j, w) {
					if (grid[i][j] == '.'&&find(ALL(path), make_pair(j, i)) == path.end()) {
						++res;
					}
				}
			}
			cout << res << endl;
		}
	}
}

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

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int ans = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i)  {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<int>()); //降順
  ans += v[0] / 2;
  for (int i = 1; i < n; ++i)  {
    ans += v[i];
  }

  cout << ans << "\n";
  return 0;
}

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

int main (){
  int h, w;
  while (true) {
    std::cin >> h >> w;
    if (h == 0 && w == 0){
      return 0;
    }else{
      for (size_t i = 0; i < h; i++) {
        for (size_t j = 0; j < w; j++) {
          std::cout << "#";
        }
        std::cout << std::endl;
      }
    }
    std::cout << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int N,M,Tcnt=0;;
    cin >>N;
    vi T(N);
    FOR(i,0,N-1){
        cin >>T[i];
        Tcnt+=T[i];
    }
    cin >>M;
    vi P(M),X(M);
    FOR(i,0,M-1){
        cin >>P[i]>>X[i];
        cout <<(Tcnt+X[i]-T[P[i]-1])<<endl;
    }


    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


void add_weight(const vector<vector<int>> &a, vector<int> &weight, int p, int past){
    for(auto item : a[p]){
	if(item == past)continue;
	weight[item] += weight[p];
	add_weight(a, weight, item, p);
    }
}


int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int>> a(n+1);
    vector<int> weight(n+1, 0);
    rep(i,n-1){
	int tmp1,tmp2;
	cin >> tmp1 >> tmp2;
	a[tmp1].push_back(tmp2);
	a[tmp2].push_back(tmp1);
    }

    rep(i,q){
	int p,x;
	cin >> p >> x;
	weight[p] += x;
    }
    add_weight(a, weight, 1, 0);
    
    irep(i,1,n+1){
	cout << weight[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 29696
#include<stdio.h>
int main(){
int a,b,c,d=0,e;
scanf("%d %d %d",&a,&b,&c);
while(a*7+b<c){
d=d+7;
c=c-(a*7+b);
}
if(a*7>c){
e=c/a;
if(c%a!=0){
e++;
}
d=d+e;
}
else{
d=d+7;
}
printf("%d\n",d);
return 0;
}


Measured memory_bytes: 2104
n,k,q,a,i,W[100002]={0};main(){scanf("%d%d%d",&n,&k,&q);for(i=0;i<q;i++){scanf("%d",&a);W[a]++;}for(i=1;i<=n;i++){if(W[i]+k>q)printf("Yes\n");else printf("No\n");}}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class Main {

	public static void main(String[] args) {
//		String baseUrl = "C:\\Users\\kuriyama.akira\\git-repository\\hobby\\AIZU_ONLINE_JUDGE\\Java\\";
//		String filePath = baseUrl +  "inp_itp_1_9_c.txt";
//		FileInputStream fis = null; 
//		try { 
//			fis = new FileInputStream(new File(filePath));
//		}catch(FileNotFoundException e){
//			e.printStackTrace();
//		}
//		BufferedReader br = new BufferedReader(new InputStreamReader(fis));
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int taro = 0;
		int hana = 0;
		
		try {
			int N = Integer.parseInt(br.readLine()); 
			String tmp;
			while((tmp = br.readLine()) != null) {
				
				List<String> line = Arrays.asList(tmp.split("\\s"));
				String taroC = line.get(0);
				String hanaC = line.get(1);
				int result =taroC.compareTo(hanaC); 
				if(result ==0) {
					taro++;
					hana++;
				}else if(result >0) {
					taro+=3;
				}else {
					hana+=3;
				}
			}
			br.close();
		}catch(IOException e) {
			e.printStackTrace();
		}

		System.out.printf("%d %d\n",taro,hana);		
	}
}



Measured memory_bytes: 27120
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

class Work
{
    public:
        int days,earn;
    Work(int _days,int _earn)
    {
        days=_days;
        earn=_earn;
    }
};
        
bool operator< (const Work &a, const Work &b)
{
    return a.earn < b.earn;
}
int main(void)
{
    int N,M;
    int ans=0;
    vector<int> work[100005];
    cin >> N >> M;
    priority_queue<Work,vector<Work>> pq;
    for(int i=0;i<N;i++)
    {
        int A,B;
        cin >> A >> B;
        work[A].push_back(B);
    }
    for(int i=M-1;i>=0;i--)
    {
        int rest=M-i;
        for(int i=0;i<int(work[rest].size());i++)
        {
            pq.push(Work(rest,work[rest][i]));
        }
        if(!pq.empty()) ans+=pq.top().earn,pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
using System;
using System.Linq;
using System.Collections.Generic;

namespace CF2017qB
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] D = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int M = int.Parse(Console.ReadLine());
            int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Dictionary<int, int> dictD = new Dictionary<int, int>();
            for (int i = 0; i < N; i++)
            {
                if (!dictD.ContainsKey(D[i])) { dictD.Add(D[i], 1); }
                else { dictD[D[i]]++; }
            }

            Dictionary<int, int> dictT = new Dictionary<int, int>();
            for (int i = 0; i < M; i++)
            {
                if (!dictT.ContainsKey(T[i])) { dictT.Add(T[i], 1); }
                else { dictT[T[i]]++; }
            }

            foreach (var i in dictT)
            {
                if (!dictD.ContainsKey(i.Key) || dictD[i.Key] < i.Value) { Console.WriteLine("NO"); return; }
            }

            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 58688
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

llong gcd(llong a, llong b){
  while(1){
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

llong lcm(llong a, llong b){
  return a / gcd(a, b) * b;
}

int main(){

  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;

  llong len_s = s.length(), len_t = t.length();

  llong ans = lcm(len_s, len_t);
  map<int, char> mp;
  REP(i,len_s){
    int idx = i * (ans / len_s);
    mp[idx] = s[i];
  }

  REP(i,len_t){
    int idx = i * (ans / len_t);
    if(mp.find(idx) != mp.end() && mp[idx] != t[i]){
      cout << "-1\n";
      return 0;
    }
    mp[idx] = t[i];
  }

  cout << ans << endl;

  return 0;
}



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

int main(){
	int N, K; cin >> N >> K;
	++K;

	vector<long long> XL, XR;
	XL.push_back(0);
	XR.push_back(0);
	for(int i=0; i<N; ++i){
		int x; cin >> x;
		if(x < 0) XL.push_back(-x);
		else if(x > 0) XR.push_back(x);
		else --K;
	}

	sort(XL.begin(), XL.end());

	long long ans = (long long)1e18;
	for(int i=K-1; i>=0; --i){
		if(i < XR.size() && K-1-i < XL.size()){
			long long a = XR[i], b = XL[K-1-i];
			if(a > b) swap(a, b);

			ans = min(2*a + b, ans);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;

int n,p;
char C[11];
int X[11];

void solve(int x,int p){
    REP(i,p+2){
        X[x]=i;
        if(x==n-1){
            REP(j,n) cout<<C[X[j]];
            cout<<endl;
        }
        else solve(x+1,max(p,X[x]));
    }
}


int main(){
    cin>>n;
    REP(i,10) C[i]='a'+i;

    X[0]=0;
    if(n==1) cout<<'a'<<endl;
    else solve(1,0);
}

Measured memory_bytes: 1536
#include<iostream>

int main(void){
    int n, m;
    std::cin >> n >> m;
    int lmax, rmin;
    lmax = 0;
    rmin = 1e9;
    for(int i = 0; i < m; i++){
        int l, r;
        std::cin >> l >> r;
        lmax = std::max(lmax, l);
        rmin = std::min(rmin, r);
    }
    if(lmax > rmin) std::cout << 0 << std::endl;
    else std::cout << rmin - lmax + 1<< std::endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}
 
 
ll bp(ll a, ll n){
	ll r = 1;
	while(n) {
		if(n & 1) r = (r * a) % mod;
		a = (a * a) % mod;
		n >>= 1;
	}
	return r;
}
 
void solve(){
	string s, t;
	cin >> s >> t;
	cout << t << s;
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    for(int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}


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

namespace agc002_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool flag = true;
            for (int i = 1; i < x[0] && flag; i++)
            {
                if (a[i - 1] + a[i] >= x[1])
                {
                    flag = false;
                    Console.WriteLine("Possible");
                    for (int j = 1; j < i; j++) Console.WriteLine(j);
                    for (int j = x[0] - 1; j >= i; j--) Console.WriteLine(j);
                }
            }
            if (flag) Console.WriteLine("Impossible");
        }
    }
}

Measured memory_bytes: 29404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int arr[101];
int main(){
	
	int n,k; cin>>n>>k;
	ll ans = k;
	for(int i = 1; i < n; i++){
		ans *= (k-1);
	}
	cout<<ans<<"\n";
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    pair<int,int> p[8];
    rep(i, N) cin >> p[i].first >> p[i].second;
    double ans = 0;
    int cnt = 0;
    sort(p, p + N);
    do {
        rep(i, N - 1) {
            int x = p[i].first - p[i + 1].first;
            int y = p[i].second - p[i + 1].second;
            ans += sqrt((x * x + y * y));
        }
        cnt++;
    }while(next_permutation(p, p + N));
    cout << fixed<< setprecision(12) << ans /cnt  << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a = 0;
  int i;
  char moji[3];
  if(scanf("%s",moji)==1){
  	
  }
  for(i=0;i< sizeof(moji);i++){
    	if(moji[i] == '1')a++;
    }
  printf("%d",a);
  
  return 0;
}


Measured memory_bytes: 128
import fractions
from functools import reduce
import math
import sys

def num_double(n):
	return int(n/2)

def main():
  N,M=map(int,input().split())
  numList=list(map(int,input().split()))
  numList=list(map(num_double,numList))
  numList=list(set(numList))
  
  count=0
  flag=0
  finFlag=0
  evenCount=0
  
  while flag==0:
    evenCount=0
    for i in range(len(numList)):
      if(numList[i]%2==0):
        evenCount+=1
    if(evenCount==len(numList)):
      numList=list(map(num_double,numList))
      M=math.floor(M/2)
    elif(evenCount==0):
      flag=1
    else:
      flag=1
      finFlag=1
  
  if(finFlag==1):
    print(count)
    sys.exit()
  
  else:
    def lcm_base(x, y):
        return (x * y) // fractions.gcd(x, y)

    def lcm_list(numbers):
        return reduce(lcm_base, numbers, 1)

    endFlag=0
    nowMagnification=1
    nowNum=0
    startNum=lcm_list(numList)

    while endFlag==0:
      nowNum=startNum*nowMagnification
      if(1<=nowNum)and(nowNum<=M):
        count+=1
        nowMagnification+=2
        continue
      else:
        endFlag=1

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 89580
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void dfs(vector<vector<int>> &tree, vector<int> &ans, int now, int bf, int &index){
  for(auto nx : tree.at(now)){
    if(nx == bf) continue;
    ans.at(nx) = index++;
    dfs(tree, ans, nx, now, index);
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> tree(n, vector<int>());
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  vector<int> c(n);
  rep(i, n) cin >> c.at(i);
  sort(ALL(c), greater<int>());
  vector<int> ans(n, 0);
  ans.at(0) = 0;
  int index = 1;
  dfs(tree, ans, 0, -1, index);
  ll sum = 0;
  rep2(i, 1, n) sum += c.at(i);
  cout << sum << endl;
  rep(i, n){
    if(i != 0) cout << " ";
    cout << c.at(ans.at(i));
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4776
-- vim: set fdm=marker : -- {{{
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.Fix (fix)
import Data.Maybe
import Data.Array.Unboxed
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
-- }}}

-- Input functions with ByteString
-- {{{
tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

readInt :: Num a => BS.ByteString -> a
readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntTuple :: Num a => BS.ByteString -> (a, a)
readIntTuple = tuplify2 . map readInt . BS.words
readIntList :: Num a => BS.ByteString -> [a]
readIntList = map readInt . BS.words

getInt :: Num a => IO a
getInt = readInt <$> BS.getLine
getIntList :: Num a => IO [a]
getIntList = readIntList <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents
-- }}}

main = do
    [n,x] <- getIntList :: IO [Int]
    ls <- getIntList :: IO [Int]
    print $ solve x ls + 1

solve :: Int -> [Int] -> Int
solve x ls = length $ filter (<= x) ys where
    ys = scanl1 (+) ls


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

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

using namespace std;

typedef pair<int, int> pii;

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

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

const int N = 101;
int a[N];

int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	//abcde,fghihgf,edcba
	s[5] = s[13] = ' ';
	cout << s << endl;
  	return 0;
}


Measured memory_bytes: 384
n = int(input())

p = list(map(int,input().split()))
q = list(map(int,input().split()))

ls = [1,1,2,6,24,120,720,5040,40320]

p_copy = p.copy()
q_copy = q.copy()

def mycalc(ls,th):
    ans = [ i for i in ls if i<th ]
    return ans

ans = mycalc(p,7)

a = 0
for i in range(n-2):
    p_copy.remove(p[i])
    g = mycalc(p_copy,p[i])
    a += (len(g))*ls[n-i-1]
if p_copy[0]<p_copy[1]:
    a += 1
else:
    a += 2

r = list(range(1,n+1))
b = 0
for i in range(n-2):
    q_copy.remove(q[i])
    g = mycalc(q_copy,q[i])
    b += (len(g))*ls[n-i-1]
if q_copy[0]<q_copy[1]:
    b += 1
else:
    b += 2

print(abs(a-b))

Measured memory_bytes: 3064
;; C - Guess The Number

(defun solve (n sc)
  (let ((buf (make-array n :initial-element nil)))
    (loop for (s . c) in sc
          for prev = (aref buf (1- s))
       do (setf (aref buf (1- s))
                (if (and prev (/= prev c)) 'error c)))
    (if (or (find 'error buf) (and (eql (aref buf 0) 0) (> n 1)))
        -1
        (loop for i below n
          unless (aref buf i)
              do (setf (aref buf i) (if (and (= i 0) (> n 1)) 1 0))
          finally (return (map 'string #'digit-char buf))))))

(let* ((n  (read))
       (m  (read))
       (sc (loop repeat m collect (cons (read) (read)))))
  (princ (solve n sc)))


Measured memory_bytes: 20192
import Data.List
import Control.Monad

solver::[Int]->Maybe [Int]
solver [] = Just []
solver ls = let idxed = zip ls [1..]  in
            let l = (filter (\(v,i)->v==i) idxed) in
            if l == [] then Nothing
                       else let (v,erase_id) = maximumBy (\ x -> \ y ->compare (snd x) (snd y)) l in
                            do
                              rest<-solver [ v |(v,i)<-idxed,i/=erase_id]
                              return (v:rest)

main::IO()
main=do
  nc<-getLine
  let n = read nc::Int
  dat<-return.map read.words=<<getLine
  case solver dat of
    Nothing -> print (-1)
    Just ls -> forM_  (reverse ls) (\v->print v)

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

int main() {
  int a = 0;
  int b = 0;
    
  cin >> a >> b;  
  
  int c = a * b;  
  
  if (c % 2 == 0){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}
    
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 2e5 + 5, M = 1e6 + 5;

int a[N], b[N];

int main()
{
    int n, k, mn = 1e9;
    int ans = 0;
    scanf("%d%d", &n, &k);
    k--;
    for(int i = 0 ; i < n ; i++) scanf("%d", a + i);
    for(int i = 0 ; i < n ; i++)
    {
        if(a[i] == 1)
        {
            for(int j = i - k ; j < n and j <= i + k ; j++)
                mn = min(mn, (j + k - 1) / k + (n - (j + k) - 2 + k) / k + 1);
            return printf("%d\n", mn), 0;
        }
    }
    return 0;
}


Measured memory_bytes: 640