akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define MAX_NUM 999999
int numbers[MAX_NUM] = {-1, -1};
int isPrime(int num) {
    int i;
    if(numbers[num]) {
        return 0;
    }
    for(i=num << 1; i<=MAX_NUM; i+=num) {
        numbers[i] = -1;
    }
    return 1;
}

int main() {
    int i, n, count;
    while(scanf("%d", &n) != EOF){
        count = 0;
        for(i=2; i<=n; ++i) {
            count += isPrime(i);
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 6504
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 200000;
LL ai[N], bi[N], all, ans;
string opt;
int n, m;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i)
    {
        int a;
        if (i == 1) opt = "+"; else cin >> opt;
        cin >> a; all += a;
        if (opt == "-") ai[++ m] = a;
        else bi[m] += a;
    }
    if (m == 0) ans = all;
    for (int i = 1; i <= m; ++ i)
    {
        all -= (ai[i] + bi[i]);
        ans = max(ans, all - ai[i] - bi[i]);
        all += (-ai[i] + bi[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
n, p = map(int, raw_input().split())
if n == 1:
    print p
elif n > 40:
    print 1
else:
    ans = 1
    i = 2
    while 1:
        k = pow(i, n)
        if k > p:
            break
        while p % k == 0:
            ans *= i
            p /= k
        i += 1
    print ans


Measured memory_bytes: 2568
#include<stdio.h>
int strlng(char a[])
{
    int i;
    for(i=1; a[i]!='\0'; i++)
    {

    }
    return i;
}
char* string_rotate(char s[])
{
    char *p;
    int i, n;
    n = strlng(s);
    char swap;
    swap = s[0];
    for(i=0; i<n-1; i++)
    {
        s[i]=s[i+1];
    }
    s[i] = swap;
    p = s;
    return p;
}
int string_cmpr(char a[], char b[])
{
        int i, n;
        n = strlng(a);
        for(i=0; i<n; i++)
        {
                if(a[i]==b[i]) continue;
                else return 0;
        }
        return 1;
}
int main()
{
    char s[150], t[150];
    scanf("%s", s);
    scanf("%s", t);
    int i, x=0, n;
    char *p;
    n = strlng(s);
    for(i=0; i<n; i++)
    {
        x = string_cmpr(s, t);
        if(x==1)
        {
            printf("Yes\n");
            return 0;
        }
        else
        {
            p = string_rotate(s);
            /*printf("%s", s);
            int n = strlng(s);
            for(int i=0; i<n; i++)
            {
                printf("%c", *(p+i));
            }
            printf("\n");
            */
        }
    }
    if(x==0) printf("No\n");
    return 0;
}


Measured memory_bytes: 128
def koi(i,o):    
    for t in range(i):
        if t%2==0:
            for y in range(o):
                if y%2==0:
                    print("#",end="")
                else:
                    print(".",end="")
        else:
            for y in range(o):
                if y%2==0:
                    print(".",end="")
                else:
                    print("#",end="")
        print()
while True:
    x,y=map(int,input().split())
    if x==0 and y==0:
        break
    koi(x,y)
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;

template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

int main() {
    cin >> N;
    vector<ll> a(N);
    map<ll, int> m;
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        m[a[i]]++;
    }

    sort(ALL(a), greater<ll>());
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (m[a[i]] == 0) continue;
        for (int t = 0; t < 32; t++) {
            ll two = 1LL << (ll)t;
            if (two - a[i] > 0) {
                if (two - a[i] != a[i]) {
                    if (m[two - a[i]] >= 1) {
                        ans += 1;
                        m[a[i]]--;
                        m[two - a[i]]--;
                        break;
                    }
                } else {
                    if (m[two - a[i]] >= 2) {
                        ans += 1;
                        m[a[i]]--;
                        m[two - a[i]]--;
                        break;
                    }
                }
            }
        }
        //debug(ans);
    }
    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int num = -1;
    for (int i = 0; i < s.length() - 1; ++i) {
        if (s[i] != s[i + 1]) {
            int currentK = max((int)s.length() - i - 1, i + 1);
            num = num < 0 ? currentK : min(currentK, num);
        }
    }
    if (num < 0) {
        num = s.length();
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N;
vi L;

int main()
{
    cin >> N;
    L = vi(N);
    REP(i, N)
    {
        cin >> L[i];
    }
    SORT(L);

    ll s = 0;
    REP(i, N - 1)
    {
        s += L[i];
    }
    string ans = L[N - 1] < s ? "Yes" : "No";

    OUT(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer cout<<endl<<"answer : ";
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>x>>y;
        p = x+y;
        q=x-y;
        z=x*y;
        ans=max(p,max(q,z));
        cout<<ans<<endl;

    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

template<typename T>
struct BIT {
    int n;
    vector<T> dat;
 
    BIT(int n=0){
        initialize(n);
    }
 
    void initialize(int nin){
        n = nin;
        dat.resize(n);
        for(int i = 0; i<n; i++) dat[i] = 0;
    }
 
    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }
 
    T sum_between(int i, int j){
        if(i > j) return 0;
        return sum(j) - sum(i-1);
    }
 
    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }
 
    // a[0]+...+a[ret+1] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
  int n;cin>>n;
  int a[n],place[n+1];
  BIT<int> bit(n+1);
  rep(i,n){
    cin>>a[i];
    place[a[i]]=i+1;
  }
  ll ans=0;
  rep(i,n){
    bit.plus(place[i+1],1);
    int left=place[i+1]-bit.lower_bound(bit.sum(place[i+1])-1);
    int right=bit.lower_bound(bit.sum(place[i+1])+1)-place[i+1];
    ans+=(ll)left*right*(i+1);
  }
  cout<<ans<<endl;
}






Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		
		int[] b = new int[m];
		Arrays.setAll(b, i -> sc.nextInt());
		
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < m; j++) {
				int a = sc.nextInt();
				sum += a * b[j];
			}
			sum += c;
			
			if (sum > 0) cnt++;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
}




Measured memory_bytes: 33060
#include<bits/stdc++.h>
using namespace std;
int a[100000*2+7];
vector<int>b;
vector<int>c;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
		{
			if(i%2==0)
				b.emplace_back(a[i]);
			else
				c.emplace_back(a[i]);	
		}
	if(n%2==0)
	{
		cout<<b[b.size()-1];
		for(int i=b.size()-2;i>=0;i--)
			cout<<" "<<b[i];
		for(int i=0;i<c.size();i++)
			cout<<" "<<c[i];
	}
	else
	{
		cout<<c[c.size()-1];
		for(int i=c.size()-2;i>=0;i--)
			cout<<" "<<c[i];
		for(int i=0;i<b.size();i++)
			cout<<" "<<b[i];
	}
	return 0;
}

Measured memory_bytes: 3956
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
ld = [0]*26
score = 0

def dec(day):
    ans = 0
    for i in range(26):
        ans += c[i]*(day-ld2[i])
    return ans

rss = [[0,0] for i in range(d+1)]

for i in range(1,d//2):
    st = rss[i-1][0]
    ma = float('INf')*(-1)
    for t in range(26):
        ld2=ld.copy()
        ld2[t]=i
        score=st+s[i-1][t]-dec(i)
        ma = max(score,ma)
        if score==ma:
            t2=t+1
    ld[t2-1]=i
    rss[i][1]=t2
    rss[i][0]=ma

st = rss[d//2-1][0]
score=st+s[d//2][15]-dec(d//2+1)
ld[t2-1]=d//2
rss[d//2][1]=15
rss[d//2][0]=score

for i in range(d//2+1,d+1):
    st = rss[i-1][0]
    ma = float('INf')*(-1)
    for t in range(26):
        ld2=ld.copy()
        ld2[t]=i
        score=st+s[i-1][t]-dec(i)
        ma = max(score,ma)
        if score==ma:
            t2=t+1
    ld[t2-1]=i
    rss[i][1]=t2
    rss[i][0]=ma

rss=rss[1:]
for i in rss:
    print(i[1])


Measured memory_bytes: 9352
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int k[1000][1000], x[1000][1000], n, cnt, maxn = -10000000;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%d", &k[i][j]);
		}
	}
	for (int i = 1; i <= n; i++) {
		cnt = 0;
		for (int j = 1; j <= n; j++) {
			cnt += k[i][j];
			x[i][j] = cnt + x[i - 1][j];
		}
	}
	if (n <= 200) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = i + 1; k <= n; k++) {
					for (int l = j + 1; l <= n; l++) {
						if (k - i >= 3 && l - j >= 3) {
							maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) - (x[i + 1][j + 1] + x[k - 1][l - 1] - x[i + 1][l - 1] - x[k - 1][j + 1]));
						}
						else {
							maxn = max(maxn, x[i][j] + x[k][l] - x[i][l] - x[k][j]);
						}
					}
				}
			}
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = i + 1; k <= n; k++) {
					if (k - i >= 180) {
						for (int l = j + 1; l <= n; l++) {
							if (l - j >= 180) {
								maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) - (x[i + 1][j + 1] + x[k - 1][l - 1] - x[i + 1][l - 1] - x[k - 1][j + 1]));
							}
						}
					}
				}
			}
		}
	}
	cout << maxn << endl;
}

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

#define endl '\n'

using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[26];
	memset(a, 0, sizeof a);
	for(int i=0; i<n*m; i++) {
		char c;
		cin >> c;
		a[c-'a']++;
	}
	if(n % 2 == 0 && m % 2 == 0) {
		for(int i=0; i<26; i++) {
			if(a[i] % 4 > 0) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}
	if(n % 2 == 1 && m % 2 == 1) {
		int cnt = 0, idx;
		for(int i=0; i<26; i++) {
			if(a[i] % 2 == 1) {
				cnt++;
				idx = i;
			}
		}
		if(cnt != 1) {
			cout << "No" << endl;
			return 0;
		}
		a[idx]--;
		cnt = 0;
		for(int i=0; i<26; i++) {
			if(a[i] % 4 > 0) {
				cnt++;
			}
		}
		int need = (n/2) + (m/2) - cnt;
		if(need < 0 || need % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
		cout << "Yes" << endl;
		return 0;
	}
	if(n%2 == 0) swap(n, m);
	int cnt = 0;
	for(int i=0; i<26; i++) {
		if(a[i]%2 == 1) {
			cout << "No" << endl;
			return 0;
		}
		if(a[i] % 4 > 0) cnt++;
	}
	int need = (m/2) - cnt;
	if(need < 0 || need % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e9)
#define N 105
using namespace std;
int n,r[N],c[N],dp[N][N];

void matrixChainOrder(){
  for(int l=2;l<=n;l++){
    for(int i=0;i<=n-l;i++){
      int j=i+l-1;
      dp[i][j]=INF;
      for(int k=i;k<j;k++)
	dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
    }
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>r[i]>>c[i];
  matrixChainOrder();
  cout<<dp[0][n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1204
n,m=gets.split.map(&:to_i)
pss=m.times.map{gets.split}
check=Array.new(n).map{Array.new(2,0)}
pss.each do |pn,sn|
  pn=pn.to_i-1
  if check[pn][0]==0
    if sn=="WA"
      check[pn][1]+=1
    else
      check[pn][0]+=1
    end
  end
end
ac=0
wa=0
check.each do |a,w|
  ac+=a
  wa+=w if a==1
end
puts [ac,wa].join(" ")



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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
  char b;
  char ans;
  cin >> b;
  if (b=='A') ans = 'T';
  else if (b == 'C') ans = 'G';
  else if (b == 'G') ans = 'C';
  else ans = 'A';
  cout << ans <<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int P = sc.nextInt();
      int Q = sc.nextInt();
      int R = sc.nextInt();
      System.out.println(Math.min(Math.min(P+Q,Q+R),R+P));
    }
}     

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    string s;
    cin >> s;
    int cnt = 0;
    rep1(i, s.size()){
      if(s[i] != s[i - 1])++cnt;
    }
    pri(cnt);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 1020
/**
 *      ABC 52 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-05 02:41:23
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;

    return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    vector<char> n(4);
    REP(i, 4) cin >> n[i];
    sort(n.begin(), n.end());

    string s;
    REP(i, 4) s.push_back(n[i]);

    if (stoi(s) == 1479) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  char str[10001],joi[4]="JOI",ioi[4]="IOI";
  int i,j,a,b;

  while(scanf("%[^\n]%*c",str)!=EOF){
    a=b=0;
    for(i=0;i<strlen(str)-1;i++){
      if(str[i+1]=='O' && str[i+2]=='I'){
	if(str[i]=='J')a++;
	else if(str[i]=='I')b++;
      }
    }
    printf("%d\n%d\n",a,b);
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str1 = sc.next();
    String str2 = sc.next();
    String str3 = sc.next();
    String str4 = str1.toUpperCase();
    String str5 = str2.toUpperCase();
    String str6 = str3.toUpperCase();
    char str7 = str4.charAt(0);
    char str8 = str5.charAt(0);
    char str9 = str6.charAt(0);
    System.out.println(str7+""+str8+""+str9);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N,M,X;
cin >> N >> M >> X;
vector<int> A(M);
for(int i=0; i<M; i++)
{
    cin >> A.at(i);
}
int chkA=0,chkB=0;
for(int i=0; i<M; i++)
{
    if(A.at(i)<X)
    {
        chkA++;
    }
    else
    {
        chkB++;
    }
}
cout << min(chkA,chkB) << endl;
}

Measured memory_bytes: 3624
from itertools import permutations
n,m=map(int,input().split())
lst=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    lst[a-1].append(b-1)
    lst[b-1].append(a-1)
kumi=list(permutations(range(1,n)))
ans=0
for i in kumi:
    switch=1
    prev=0
    for j in range(n-1):
        if not i[j] in lst[prev]:
            switch=0
            break
        prev=i[j]
    if switch==1:
        ans+=1
print(ans)

Measured memory_bytes: 69720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        
        if (y > x) {
        	int tmp = x;
        	x = y;
        	y = tmp;
        }
        
        while (x >= y) {
        	if (x % y == 0) {
        		break;
        	}
        	int temp = y;
        	y = x % temp;
        	x = temp;
        }
        
        System.out.println(y);
	}

}


Measured memory_bytes: 26240
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll a[101] = {};
int main() {
	ll n; cin >> n;
	repe(i, 1, n)cin >> a[i];

	ll cnt = 0;
	repe(i, 2, n) {
		if (a[i] == a[i - 1]) {
			a[i] = 1000;
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,a[202020],ans,l,r,k;
bool ck(long long xx)
{
	long long sum=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)//检查0
		{
			if(xx>=0)
			{
				sum+=n-1;
			}
		}
		else if(a[i]<0)
		{
			long long mx=xx/a[i];
			if(mx*a[i]>xx)
			{
				mx++;
			}
			int id=lower_bound(a,a+n,mx)-a;
			sum+=n-id;
			if(id<=i)
			{
				sum--;
			}
		}
		else
		{
			long long mx=xx/a[i];//a[j]的最大值
			if(mx*a[i]>xx)
			{
				mx--;
			}
			int id=upper_bound(a,a+n,mx)-a-1;
			if(id<0)
			{
				continue;
			}
			sum+=id+1;
			if(id>=i)
			{
				sum--;//a[i]*a[i]肯定是不行的
			}
		}
	}
	return (sum/2)>=k;
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	l=-1e18-100;
	r=1e18+100;
	while(l<r)
	{
		long long md=l+(r-l)/2;
		if(ck(md))
		{
			r=md;
		}
		else
		{
			l=md+1;
		}
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC031
{
    class B
    {
        static int _Mod = 1000000007;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> C = new List<int>();
            for (int i = 0; i < N; i++)
            {
                int c = int.Parse(Console.ReadLine());
                C.Add(c);
            }

            long[] counter = new long[N+1]; counter[0] = 1;
            //色番号ごとの直近の番号
            Dictionary<int, int> dic = new Dictionary<int, int>();

            int kprev = 0;
            for(int i = 0; i < C.Count; i++)
            {
                int k = C[i];
                long count = counter[i];
                if (k != kprev)
                {
                    if (!dic.ContainsKey(k))
                    {
                        dic.Add(k, 0);
                    }
                    else
                    {
                        int index = dic[k];
                        count += counter[index]; count %= _Mod;
                    }
                }
                counter[i + 1] = count;
                dic[k] = i+1;

                kprev = k;
            }
            Console.WriteLine(counter[N]);
        }
    }
}


Measured memory_bytes: 30556
using System;

namespace Atcoder001
{
    class Program
    {
        static void Main(string[] args)
        {
            int amount = int.Parse(Console.ReadLine());
            string[] answers = new string[amount];
            for(int i = 0; i < amount; i++)
            {
                answers[i] = Console.ReadLine();
            }

            int[] count = new int[4];
            foreach(string answer in answers)
            {
                if(answer.Equals("AC"))
                {
                    count[0] += 1;
                }
                else if(answer.Equals("WA"))
                {
                    count[1] += 1;
                }
                else if (answer.Equals("TLE"))
                {
                    count[2] += 1;
                }
                else if (answer.Equals("RE"))
                {
                    count[3] += 1;
                }
            }
            
            Console.WriteLine("AC x " + count[0]);
            Console.WriteLine("WA x " + count[1]);
            Console.WriteLine("TLE x " + count[2]);
            Console.WriteLine("RE x " + count[3]);
        }
    }
}

Measured memory_bytes: 31336
import java.util.Scanner;

public class Main {

	public static int digit(int n) {
		int tmp = n;
		if(n == 0)return 1;
		int count = 0;
		while(tmp != 0) {
			tmp /= 10;
			++count;
		}
		return count;
	}
	
	public static int sumdigit(int n) {
		int d = digit(n);
		int tmp = n, sum = 0;
		for(int i = 0; i < d; ++i) {
			int tmp2 = tmp / 10;
			tmp -= tmp2 * 10;
			sum += tmp;
			tmp = tmp2;
		}
		return sum;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a =sc.nextInt(), b = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 1; i <= n; ++i) {
			int tmp = sumdigit(i);
			if(tmp >= a && tmp <= b)ans += i;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22612
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

h=int(input().rstrip())
w=int(input().rstrip())
n=int(input().rstrip())
print(n//max(h,w)+1 if n%max(h,w)!=0 else n//max(h,w))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main(){
    long long N, D;
    cin >> N >> D;
    vector<pair<long long, long long>> P(N);
    for(int i=0; i<N; ++i){
        long long X, Y; cin >> X >> Y;
        P[i] = {X, Y};
    }

    int ans = 0;
    for(int i=0; i<N; ++i){
        long long dist = P[i].first * P[i].first + P[i].second* P[i].second;
        long long limit = D * D;
        if(dist <= limit) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t H, W;
	std::cin >> H >> W;
	boost::multi_array<char, 2> s(boost::extents[H][W]);
	for (int64_t i : boost::irange<int64_t>(0, H))
	{
		for (int64_t j : boost::irange<int64_t>(0, W))
		{
			std::cin >> s[i][j];
		}
	}

	bool can = true;

	for (int64_t i = 0; i < H; i++)
	{
		for (int64_t j = 0; j < W; j++)
		{
			if (s[i][j] == '.') continue;

			bool next_black = false;
			if (i != 0 && s[i - 1][j] == '#') next_black = true;
			if (i != H - 1 && s[i + 1][j] == '#') next_black = true;
			if (j != 0 && s[i][j - 1] == '#') next_black = true;
			if (j != W - 1 && s[i][j + 1] == '#') next_black = true;
			if (!next_black) can = false;
		}
	}

	std::string ans = can ? "Yes" : "No";
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 3600
import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int N, D, X, a, day, ans;
        N = Integer.parseInt(sc.next());
        D = Integer.parseInt(sc.next());
        X = Integer.parseInt(sc.next());
        ans = 0;
        for (int i = 0; i < N; i++){
            a = Integer.parseInt(sc.next());
            day = 1;
            while (day <= D){
                ans += 1;
                day += a;
            }
        }
        out.println(ans + X);
        out.flush();
    }
}

Measured memory_bytes: 21716
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val M = sc.nextInt()
  val C = sc.nextInt()
  sc.useDelimiter("\n")
  val B = sc.next().split(' ').map(_.toInt).toList
  val sums = for (_ <- 0 until N) yield {
    B.zip(sc.next().split(' ').map(_.toInt).toList)
       .map{ case (x, y) => x * y}.sum
  }
  val result = sums.map(sum => if(sum + C > 0) 1 else 0).sum
  println(result) 
}

Measured memory_bytes: 55756
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(a[k-1])


Measured memory_bytes: 38448
#include <iostream>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n,m;
ll dp[310][310][310];

int main() {
    scanf("%d%d",&n,&m);
    memset(dp,0,sizeof(dp));
    dp[0][1][1]=1;
    for (int i=0;i<m;i++) {
        for (int j=1;j<=n;j++) {
            for (int k=1;k<=n;k++) {
                dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k]*(n-j))%MOD;
                dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(j-k))%MOD;
                dp[i+1][j][j]=(dp[i+1][j][j]+dp[i][j][k]*k)%MOD;
            }
        }
    }
    printf("%lld\n",dp[m][n][n]);
}


Measured memory_bytes: 232960
n,k = (int(x) for x in input().split())
h = [int(x) for x in input().split()]
sum = 0
result = True
h.sort(reverse=True)

if k < n:
    for i in range(k,len(h)):
        sum += h[i]
else:
    result = False

if result:
    print(sum)
else:
    print(0)

Measured memory_bytes: 26020
#!/usr/bin/perl

my ($a,$b,$c) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $d = $c - ($a + $b);

if( $d <= 2 ){
  print "No\n";
  exit(0);
}

if( 4 * $a * $b < $d * $d ){
  print "Yes\n";
} else {
  print "No\n";
}
exit(0);



Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[20];
	int c[20];

	int ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		ans += b;
	}
	for (int i = 0; i < n - 1; i++)
		cin >> c[i];

	for (int i = 1; i < n; i++)
	{
		if (i <= n - 1 && a[i - 1] + 1 == a[i])ans += c[a[i - 1] - 1];
	}

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

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
"""
B - Grid Compression
https://atcoder.jp/contests/abc107/tasks/abc107_b

"""
import sys


def solve(H, W, grid):
    res = [row for row in grid if not(len(set(row)) == 1 and row[0] == '.')]
    return list(zip(*[row for row in list(reversed([list(m) for m in zip(*res)])) if not (len(set(row)) == 1 and row[0] == '.')][::-1]))


def main(args):
    H, W = map(int, input().split())
    grid = [list(input()) for _ in range(H)]
    ans = solve(H, W, grid)
    for row in ans:
        print(''.join(row))


if __name__ == '__main__':
    main(sys.argv[1:])


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

int n;
int a[1000];
int b = 0;

int main() {
  cin >> n;
  for (; b < n;) {
    cin >> a[b];
    ++b;
  }
  int c = n - 1;
  for (; 0 <= c ;) {
    cout << a[c];
    if(0 < c) {
      cout << " ";
    }
    --c;
  }
  cout << endl;
}

Measured memory_bytes: 3040
def S(n):
    num = 0
    for c in str(n):
        num += int(c)
    return num

def norm(n):
    return n / S(n)

k = int(input())
j = 1
order = 1
for i in range(k):
    print(j) #, norm(j))
    if norm(j + 10 ** (order - 1)) > norm(j + 10 ** (order)):
        order += 1
    j += 10 ** (order - 1)


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

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

int main() {
    // 前処理
    COMinit();

    int n,m;cin>>n>>m;
    long long ans=fac[m]*finv[m-n]%MOD*fac[m]%MOD*finv[m-n]%MOD,sum=0;
    for(int i=1;i<=n;++i){
        long long k=COM(n,i)*fac[m]%MOD*finv[m-n]%MOD*fac[m-i]%MOD*finv[m-n]%MOD;
        if(i%2==0)sum-=k;
        else sum+=k;
        while(sum<0)sum+=MOD;
        sum%=MOD;
    }
    ans-=sum;
    while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 15580
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.dat = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i:
            s += self.dat[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.dat[i] += x
            i += i & -i


N, Q = [int(_) for _ in input().split()]
Query = [input().split() for _ in range(Q)]
BIT0 = BinaryIndexedTree(N + 1)
BIT1 = BinaryIndexedTree(N + 1)
#sum'([0,p))=sum([0,p)) if p<a
#sum'([0,p))=sum([0,p))+p*x-(a-1)*x if a<=p<b
#sum'([0,p))=sum([0,p))+(b-(a-1))*x if b<=p
for query in Query:
    c, *array = query
    array = list(map(int, array))
    if c == '1':
        a, b = array
        a -= 1
        res = 0
        res += b * BIT1.sum(b) + BIT0.sum(b)
        res -= a * BIT1.sum(a) + BIT0.sum(a)
        print(res)
    else:
        a, b, x = array
        b += 1
        BIT1.add(a, x)
        BIT0.add(a, -(a - 1) * x)
        BIT1.add(b, -x)
        BIT0.add(b, (b - 1) * x)



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



long long int res=100000000;
long long int sum=0;




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

int x[n];

for(int i=0;i<n;i++)cin >>x[i];

sort(x,x+n);

for(int j=x[0];j<=x[n-1];j++){

for(int i=0;i<n;i++){
sum+=(x[i]-j)*(x[i]-j);
}
res=min(res,sum);
sum=0;

}

cout <<res<<"\n";


}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>
const long long INF=1e18;

using namespace std;

int main(void) {
    long long A;
    double B;
    cin>>A>>B;

    long long ans=B*100+0.5;
    ans*=A;
    ans/=100;

    cout<<ans<<endl;
}


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

int main() {
    int n;
    string s[10] = {"pon", "pon", "hon", "bon", "hon",
                    "hon", "pon", "hon", "pon", "hon"};
    cin >> n;

    cout << s[n % 10] << endl;

    return 0;
}

Measured memory_bytes: 3560
N, A, B, C, D = map(int, input().split())
S = input()
canCross = False
for i, s in enumerate(S, start=1):
  if A < i < max(C, D) and s == '#' and (S[i-2] == '#' or S[i] == '#'):
    print('No')
    exit()
  if B <= i <= min(C, D) and s == '.' and S[i-2] == '.' and S[i] == '.':
    canCross = True
if C < D:
  print('Yes')
else:
  if canCross:
    print('Yes')
  else:
    print('No')
  

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

int main() {
  int n;
  long long ans=0;

  cin >> n;

  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0) {ans+=i;}
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long a, b, c, d;
    scan(a, b, c, d);
    if (a + b > c + d)
    {
        writeln("Left");
    }
    else if (a + b < c + d)
    {
        writeln("Right");
    }
    else
    {
        writeln("Balanced");
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


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

a.sort()
c=[0]*(10**6+1)
ans=0
for i in range(n):
    x=a[i]
    if c[x]:
        continue
    else:
        if i<=n-2:
            if x!=a[i+1]:
                ans+=1
        else:
            ans+=1
        for j in range(x,10**6+1,x):
            c[j]=1
print(ans)

Measured memory_bytes: 106116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int a;
  cin >> a;
  int ans = 1;
  while(ans * 2 <= a){
    ans *= 2;
  }
  

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
 
const int MOD = 1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n,W;
    cin>>n>>W;
    int w[n], v[n];
    int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    int dp[100005];
    for(int i=0;i<1e5+5;i++)
        dp[i]=1e16;
    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=1e5+4;j>=v[i];j--)
        {
            dp[j]=min(dp[j], dp[j-v[i]]+w[i]);
        }
    }

    int ans=0;
    for(int i=0;i<1e5+5;i++)
    {
        if(dp[i]<=W)
            ans=i;
    }

    cout<<ans;



    return 0;
} 

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

int main() {
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(s.at(k-1) == 'A'){
    s.at(k-1) = 'a';
  }
  if(s.at(k-1) == 'B'){
    s.at(k-1) = 'b';
  }
  if(s.at(k-1) == 'C'){
    s.at(k-1) = 'c';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, k; cin >> a >> b >> k;
    ll sa = min(a, k);
    a -= sa;
    k -= sa;
    ll sb = min(b, k);
    b -= sb;
    cout << a << ' ' << b << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;




int main(){
  int N, M; cin >> N >> M;
  int wa[N];
  bool ac[N];
  rep(i,N){
    wa[i] = 0; ac[i] = false;
  }
  int p[M]; string s[M];
  int wa_counter = 0, ac_counter = 0;
  rep(i,M){
    cin >> p[i] >> s[i]; --p[i];
    if (s[i] == "WA" && !ac[p[i]]){
      ++wa[p[i]];
    }
    if (s[i] == "AC" && !ac[p[i]]){
      ac_counter++;
      ac[p[i]] = true;
      wa_counter += wa[p[i]];
    }
    
  }
  cout << ac_counter << " " << wa_counter << endl;

  return 0;
}

Measured memory_bytes: 6656
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

typedef struct{int s,e,c;}Edge;
int par[NUM];
int UF(){for(int i=0;i<NUM;i++)par[i]=-1;}
int Root(int x){if(par[x]<0)return x;else return par[x]=Root(par[x]);}
int Size(int x){return -par[Root(x)];}
bool Same(int x,int y){return Root(x)==Root(y);}
void Unite(int x,int y){x=Root(x);y=Root(y);if(x!=y){if(Size(x)<Size(y))swap(&x,&y);par[x]+=par[y];par[y]=x;}}
int cmpc(const void* a,const void* b){return ((Edge*)a)->c-((Edge*)b)->c;}
int Kruscal(Edge* edge,int n){int i,ans=0;Edge e;qsort(edge,n,sizeof(Edge),cmpc);UF();FOR(i,0,n){e=edge[i];if(!Same(e.s,e.e)){Unite(e.s,e.e);ans+=e.c;}}return ans;}


int main(){
  int i,a=0,b=0,s,ans=0;
	char S[NUM];
  scanf("%s",S);
	s=strlen(S);
	FOR(i,0,s){
		if(S[i]=='0')a++;
		else b++;
	}

  printf("%d\n",MIN(a,b)*2);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n, k, h, ans = 0;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> h;
        if(h >= k)
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3552
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[][] dp=new int[10][10];
        for(int k=1;k<=n;k++)
        {
           int j=k%10;
           String s=String.valueOf(k);
           int i=s.charAt(0)-'0';
           dp[i][j]++;
        }
        int res=0;
        for(int i=0;i<=9;i++)
            for(int j=0;j<=9;j++)
            {
                res+=dp[i][j]*dp[j][i];
            }
        System.out.println(res);
    }
}


Measured memory_bytes: 32596
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> count;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    count[A.at(i)]++;
  }
  int ans = 0;
  for(auto n=count.begin(); n!=count.end(); n++){
    if(n->second%2!=0){
      ans++;
    }
  }
  cout << ans;
  return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = LONG_LONG_MAX;
    ll sum = 0;
    ll count = 0;
    rep(i,n){
        // sum[even] >= 0
        sum += a[i];
        if(i % 2 == 0){
            if(sum <= 0){
                count += (1 - sum);
                sum = 1;
            }
        }else{
            if(sum >= 0){
                count += (sum - (-1));
                sum = -1;
            }
        }
    }
    ans = min(ans, count);
    sum = 0; 
    count = 0;
    rep(i,n){
        // sum[odd] >= 0
        sum += a[i];
        if(i % 2 != 0){
            if(sum <= 0){
                count += (1 - sum);
                sum = 1;
            }
        }else{
            if(sum >= 0){
                count += (sum - (-1));
                sum = -1;
            }
        }
    }
    ans = min(ans, count);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll precal[1<<16];
ll memo[1<<16];
ll dp(int mask){
    if((mask-1)&mask == 0){
        return precal[mask];
    }
    if(memo[mask] != -1)
        return memo[mask];
    ll res = precal[mask];
    //printf("from %d:\n",mask);
    for(int s=(mask-1)&mask;s>0;s=(s-1)&mask){
        if(s<mask-s)break;
        //printf("%d %d\n",mask,s);
        res = max(res,dp(s)+precal[mask-s]);
    }
    memo[mask] = res;
    return res;
}

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
     int n;
     scanf("%d",&n);
     vector<vector<ll>>A(n+1,vector<ll>(n+1,0));
     for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%lld",&A[i][j]);
        }
     }
     for(int mask=0;mask<(1<<n);mask++){
        ll res = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if((mask & (1<<i)) && (mask & (1<<j))){
                    res = res + A[i][j];
                }
            }
        }
        precal[mask] = res;

     }
     memset(memo,-1,sizeof(memo));
     ll res = dp((1<<n)-1);
     printf("%lld\n",res);
	 return 0;
}


Measured memory_bytes: 1280
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N, MOD = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    adjL[x].append(y)
    adjL[y].append(x)

def ReRooting(adjL):
    def merge(val1, val2):
        return val1 * val2 % MOD
    def calcValue(val1):
        return (val1 + 1) % MOD

    numV = len(adjL)
    vRoot = 0
    useds = [False] * numV
    useds[vRoot] = True
    vs = [vRoot]
    pars = [-1] * numV
    stack = [vRoot]
    while stack:
        v = stack.pop()
        for v2 in adjL[v]:
            if not useds[v2]:
                useds[v2] = True
                vs.append(v2)
                pars[v2] = v
                stack.append(v2)

    anss = [0] * numV
    dpUpFrom, dpDownTo, accLs, accRs = [1]*numV, [1]*numV, [1]*numV, [1]*numV
    for v in reversed(vs):
        vPar = pars[v]
        tmp = 1
        for v2 in adjL[v]:
            if v2 == vPar: continue
            accLs[v2] = tmp
            tmp = merge(tmp, dpUpFrom[v2])
        tmp = 1
        for v2 in reversed(adjL[v]):
            if v2 == vPar: continue
            accRs[v2] = tmp
            tmp = merge(tmp, dpUpFrom[v2])
        anss[v] = tmp
        dpUpFrom[v] = calcValue(tmp)

    for v in vs:
        vPar = pars[v]
        dpDownToV = dpDownTo[v]
        anss[v] = merge(anss[v], dpDownToV)
        for v2 in adjL[v]:
            if v2 == vPar: continue
            tmp = merge(accLs[v2], accRs[v2])
            tmp = merge(tmp, dpDownToV)
            dpDownTo[v2] = calcValue(tmp)
    return anss

anss = ReRooting(adjL)
print('\n'.join(map(str, anss)))


Measured memory_bytes: 41012