akhauriyash/Code-Regression huggingface dataset:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()

    print(s.replace(',', ' '))

if __name__ == '__main__':
    main()


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

int main(){
    vector <int> a(5);
    rep(i,5){
        cin >> a[i];
    }

    int ans=0,m=10,m2,m3;
    rep(i,5){
        if(a[i]%10==0){
            ans+=a[i];
        }
        else{
            m2=a[i]%10;
            m=min(m,m2);
            ans+=(a[i]/10+1)*10;
        }
    }

    if(m==10){
        cout << ans << endl;
    }
    else{
    ans+=m-10;
    cout << ans << endl;
    }

    

    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
using namespace std;
int n,l,m,a;
int main(){
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> l;
		a += l;
		if (m < l)m = l;
	}
	a -= m;
	if (a > m)cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2,LOGN = 20;

ll i,n,Q,a,b,c,d;
vi adj[N], w[N];
ll st[LOGN][N], D[N];
ll p[N][3], td[N], g[N][3], cnt[N], tot[N];
struct S{
    ll a,b,c,d,l,i;
} q[N];

void Dfs(ll v,ll par,ll d,ll p)
{
    st[0][v] = par;
    D[v] = d;
    td[v] = p;
    for(auto it: adj[v]) if(it.f != par)
        Dfs(it.f, v, d + 1,p + it.se.se);
}
void go()
{
    Dfs(1,1,1,0);
    for(ll i = 1;i < LOGN;i += 1) for(ll j = 1;j <= n;j += 1)
        st[i][j] = st[i - 1][st[i - 1][j]];
}
ll lca(ll a,ll b)
{
    if(D[a] > D[b]) swap(a, b);
    ll d = D[b] - D[a];
    for(ll i = 0;i < LOGN;i += 1) if(d & (1 << i))
        b = st[i][b];
    if(a == b) return a;
    for(ll i = LOGN - 1;i >= 0;i -= 1) if(st[i][a] != st[i][b]){
        a = st[i][a];
        b = st[i][b];
    }
    return st[0][a];
}
void dfs(ll v,ll par)
{
    for(auto it: w[v]){
        p[it.se.f][it.se.se] = tot[it.f];
        g[it.se.f][it.se.se] = cnt[it.f];
    }
    
    for(auto it: adj[v]) if(it.f != par){
        tot[it.se.f] += it.se.se;
        cnt[it.se.f] += 1;
        
        dfs(it.f, v);
        
        tot[it.se.f] -= it.se.se;
        cnt[it.se.f] -= 1;
    }
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>Q;
    rep(i,1,n){
        cin>>a>>b>>c>>d;
        adj[a].pb({b,{c,d}}); adj[b].pb({a,{c,d}});
    }
    go();
    
    rep(i,0,Q){
        cin>>a>>b>>c>>d;
        q[i].a = a; q[i].b = b; q[i].c = c; q[i].d = d;
        q[i].l = lca(c, d);
        
        w[c].pb({a, {i, 0}}); w[d].pb({a, {i, 1}});
        w[q[i].l].pb({a, {i, 2}});
    }
    dfs(1,1);
    
    rep(i,0,Q)
        cout<<td[q[i].c] + td[q[i].d] - 2 * td[q[i].l] - (p[i][0] + p[i][1] - 2 * p[i][2]) + q[i].b * (g[i][0] + g[i][1] - 2 * g[i][2])<<endl;
    
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> h(N+1, 0);
    for (int i = 1; i < N+1; i++) cin >> h[i];

    int count = 0;
    for (int i = 1; i < N+1; i++) {
        if (h[i-1] < h[i]) count += h[i] - h[i-1];
    }

    cout << count << endl;
}

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

using namespace std;

int main(){
	long long n, k, h[200000];

	cin >> n >> k;
	for(long long i = 0; i < n; i++)
		cin >> h[i];
	sort(h, h+n);
	long long r = 0;
	for(long long i = 0; i < n - k; i++)
		r += h[i];
	cout << r << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
//#include <tuple>
//#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const int N = 14;

int dp[N][1 << N];

int G[N][N];

int commonlen(string a, string b){
	int len = min(a.size(), b.size());
	int res = 0;
	FOR(k, 1, len + 1){
		int ai = a.size() - k;
		int bi = 0;

		bool ok = true;
		for (int i = 0; i < k; ++i){
			if (a[ai + i] != b[bi + i]) ok = false;
		}
		if (ok) res = k;
	}
	return res;
}

int n;
int rec(int v, int x){
	if (x + 1 == (1 << n)) return 0;

	int &res = dp[v][x];
	if (res >= 0) return res;
	res = 0;

	rep(i, n){
		if (x&(1 << i)) continue;
		res = max(res, rec(i, x | (1 << i)) + G[v][i]);
	}
	return res;
}

int main(){
	while (cin >> n, n){
		vector<string> v(n);
		int sum = 0;
		rep(i, n) cin >> v[i], sum += v[i].size();
		MEMSET(G, 0);
		rep(i, n) rep(j, n) G[i][j] = commonlen(v[i], v[j]);

		int bits = 0;
		rep(i, n) rep(j, n){
			if (i == j) continue;
			if (v[j].find(v[i]) == -1) continue;
			bits |= 1 << i;
			sum -= v[i].size();
			break;
		}

		int tmp = 0;
		MEMSET(dp, -1);
		rep(i, n) if (~bits&(1 << i)) tmp = max(tmp, rec(i, bits | (1 << i)));

		cout << sum - tmp << endl;
	}

	return 0;
}

Measured memory_bytes: 2120
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

double memo[301][301][301];
int N;

double dp(int a,int b,int c){
  if(memo[a][b][c]>=0.0)return memo[a][b][c];
  if(a==0 && b==0 && c==0)return 0.0;
  double res=N;
  if(a>0)res+=dp(a-1,b,c)*a;
  if(b>0)res+=dp(a+1,b-1,c)*b;
  if(c>0)res+=dp(a,b+1,c-1)*c;
  res/=(a+b+c);
  return memo[a][b][c]=res;
}
int main(){
  cin>>N;
  map<int,int> m;
  REP(i,N){
    int a;
    cin>>a;
    m[a]+=1;
  }
  REP(i,301)REP(j,301)REP(k,301)memo[i][j][k]=-1;
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(12);
  cout<<dp(m[1],m[2],m[3])<<endl;
  return 0;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int h,w;cin>>h>>w;
  char m[50][50];rep(i,h)rep(j,w)cin>>m[j][i];
  rep(i,h){
    rep(j,w){
      if(m[j][i] == '.')continue;
      int count = 0;
      rep(l,4){
        int s = j + fd[l].first, t = i + fd[l].second;
        if(s < 0 || t < 0 || s >= w || t >= h){
          count++;
          continue;
        }
        if(m[s][t] == '#')count++;
      }
      if(count){
        continue;
      }else{
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
// 参考: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a_list: [usize; n - 1],
    };

    let mut hash: HashMap<usize, i64> = HashMap::new();
    for key in 1..(n + 1) {
        hash.insert(key, 0);
    }

    for i in &a_list {
        hash.insert(*i, hash.get(i).unwrap() + 1);
    }

    for i in 1..(n + 1) {
        println!("{}", hash.get(&i).unwrap());
    }
}


Measured memory_bytes: 11464
#include<stdio.h>
#include<math.h>

int main(){
  while(1){
    int n, s[1000], i;
    double ave = 0, a = 0;
    
    scanf("%d", &n);

    if(n == 0) break;
    
    for(i=0; i<n; ++i){
      scanf("%d", &s[i]);
      ave += s[i];
    }
    
    ave /= n;
    
    for(i=0; i<n; ++i){
      a += pow(s[i] - ave, 2);
    }
    
    a /= n;
    
    printf("%lf\n", sqrt(a));
  }
  
  return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b;
	t = 1;
	while(t--) {
	 cin >> a >> b;
	 cout << a * a - b << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
ll h,w;
string s[100];
ll mini[100][100];

ll hoge(ll x,ll y){
    rep(i,0,h-1)rep(j,0,w-1)mini[i][j]=inf;
    mini[x][y]=0;
    queue<l_l> que;
    que.push(make_pair(x,y));
    l_l p;
    ll xx,yy;
    while(que.size()>0){
        p=que.front();que.pop();
        //cout<<p.first<<p.second<<endl;
        xx=p.first+1;
        yy=p.second;
        if(0<=xx && xx<=h-1 && 0<=yy && yy<=w-1){
            if(s[xx][yy]=='.'){
                if(mini[xx][yy]==inf){
                    mini[xx][yy]=mini[p.first][p.second]+1;
                    que.push(make_pair(xx,yy));
                }
            }
        }
        xx=p.first-1;
        yy=p.second;
        if(0<=xx && xx<=h-1 && 0<=yy && yy<=w-1){
            if(s[xx][yy]=='.'){
                if(mini[xx][yy]==inf){
                mini[xx][yy]=mini[p.first][p.second]+1;
                que.push(make_pair(xx,yy));
                }
            }
        }
        xx=p.first;
        yy=p.second+1;
        if(0<=xx && xx<=h-1 && 0<=yy && yy<=w-1){
            if(s[xx][yy]=='.'){
                if(mini[xx][yy]==inf){
                    mini[xx][yy]=mini[p.first][p.second]+1;
                    que.push(make_pair(xx,yy));
                }
            }
        }
        xx=p.first;
        yy=p.second-1;
        if(0<=xx && xx<=h-1 && 0<=yy && yy<=w-1){
            if(s[xx][yy]=='.'){
                if(mini[xx][yy]==inf){
                    mini[xx][yy]=mini[p.first][p.second]+1;
                    que.push(make_pair(xx,yy));
                }
            }
        }
    }
    ll ans=-1;
    rep(i,0,h-1){
        rep(j,0,w-1){
            //cout<<mini[i][j];
            if(mini[i][j]!=inf){
                ans=max(ans,mini[i][j]);
            }
        }
        //cout<<endl;
    }
    //cout<<endl;
    return ans;
}

int main(){
    cin>>h>>w;
    rep(i,0,h-1){
        cin>>s[i];
    }
    ll ans=-1;
    
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(s[i][j]=='.'){
                ans=max(ans,hoge(i,j));
            }
        }
    }
    cout<<ans<<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;
using pii = pair<int,int>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };

int main() {
    int H, W;
    cin >> H >> W;
    char A[1010][1010];
    queue <pair<pii,int>>q;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> A[i][j];
            if (A[i][j] == '#') {
                q.push({ {i,j},0 });
            }
        }
    }
    int ans = 0;
    while (!q.empty()) {
        auto key = q.front();
        ans = max(ans, key.second);
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int ny = key.first.first + dy[i];
            int nx = key.first.second + dx[i];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W||A[ny][nx]=='#') {
                continue;
            }
            else {
                A[ny][nx] = '#';
                q.push({ { ny,nx }, key.second + 1 });
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13328
n=int(input())
a=[[0]*3 for i in range(n+1)]
for i in range(1,n+1):
    t,x,y=map(int,input().split())
    a[i][0]=t
    a[i][1]=x
    a[i][2]=y

for i in range(n):
    dist=abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])
    if dist>a[i+1][0]-a[i][0] or (dist-a[i+1][0]-a[i][0])%2==1 :
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 19572
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();
			int count = 0;
			
			if(S.substring(0, 1).equals("7")) count++;
			if(S.substring(1, 2).equals("7")) count++;
			if(S.substring(2, 3).equals("7")) count++;
			
			System.out.println(count>0?"Yes":"No");
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 35636
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
    
using namespace std;

typedef long long ll;


int main() {
    int n[4];
    vector<int> c = {1,9,4,7};
    int a = 0;
    for (int i = 0; i<4; i++) {
        cin >> n[i];
        for (int j = 0; j<c.size(); j++) {
            if (n[i] == c.at(j)) {
                c.erase(c.begin() + j);
                a++;
            }
        }
    }
    if (a==4) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main(void){
    unsigned int m;
    scanf("%d", &m);
    
    if(m%2==0||m%5==0){
        printf("-1");
        return 0;
    }
    
    unsigned int i,k,s;
    

    for(i=0;;i++){
        if(i==0){
        s=7%m;
        k=7;
        }else{
        k*=10;
        k%=m;
        s+=k;
        s%=m;
        }   
    if(s==0){
      printf("%d",i+1);
    break;
    }
    }
    
  return 0;
}

Measured memory_bytes: 1736
N = input()

if N == "SUN":
    print("7")
elif N == "MON":
    print("6")
elif N == "TUE":
    print("5")
elif N == "WED":
    print("4")
elif N == "THU":
    print("3")
elif N == "FRI":
    print("2")
else:
    print("1")

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  int ans{};
  if (S == "RRR") {
    ans = 3;
  } else if (S == "RRS" || S == "SRR") {
    ans = 2;
  } else if (S != "SSS") {
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define sum(a) accumulate(begin(a), end(a), 0)


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



int main() {
    ll N;
    cin >> N;
    vector<ll> yon, gusu, kisu;
    rep(i, 0, N) {
        ll temp;
        cin >> temp;
        if (temp % 4 == 0) {
            yon.push_back(temp);
        }
        else if (temp % 2 == 0) {
            gusu.push_back(temp);
        }
        else {
            kisu.push_back(temp);
        }
    }

    if (kisu.size() == 0) {
        cout << "Yes" << endl;
    }
    else if (kisu.size() <= yon.size()) {
        cout << "Yes" << endl;
    }
    else if (gusu.size() == 0 && kisu.size() - 1 == yon.size()) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;

}

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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<vector<P>>data(n);
  rep(i,n){
    int a;
    cin >> a;
    rep(j,a){
      int x,y;
      cin >> x >> y;
      x--;
      data[i].push_back(P(x,y));
    }
  }
  for(int bit = 0;bit < (1<<n);bit++){
    int temp = 0;
    bool flag = true;
    vector<int>d(n,-1);
    rep(i,n){
      if(bit & (1<<i)) d[i] = 1;
      else d[i] = 0;
    }
    rep(i,n){
      if(bit & (1<<i)){
        for(auto j:data[i]){
          if(j.second != d[j.first]){
            if(d[j.first] == -1) d[j.first] = j.second;
            else flag = false;
          }
        }
      }
    }
    if(flag){
      rep(i,n) if(bit & (1<<i)) temp++;
    }
    ans = max(ans,temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC158
{
    class MainClass
    {

        // static int[] s;

        public static void Main(string[] args)
        {
            string s = ReadLine();
            for(int i = 0;i<s.Length-1;i++){
                if(s[i]!=s[i+1]){
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");

        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

int main(void){
    char s[110];
    scanf("%s",s);
    int n = strlen(s), ctr = 0;

    REP(i,n/2){
        if(s[i] != s[n-i-1]) ctr++;
    }
    printf("%d",ctr);
    return 0;
}

Measured memory_bytes: 128
max_p=-10**11
n=int(input())
min_r=int(input())
for i in range(n-1):
    r = int(input())
    p = r-min_r
    if p>max_p:
        max_p = p
    if r<min_r:
        min_r = r
    print
print(max_p)


Measured memory_bytes: 5612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct dijkstra{
    struct edge{int to; int cost;};
    vector<vector<edge>> graph;
    vector<int> dist;
    int MAX_dist;

    // 頂点数を入れる
    dijkstra(int n): graph(n,vector<edge>(0)){
        MAX_dist = inf;
    dist.resize(n,MAX_dist);
    }

    // 一方向に辺を追加
    void add(int from, int to, int cost){
        graph[from].push_back({to, cost});
        return;
    }

    // 双方向に辺を追加
    void add_both(int edge_one, int edge_two, int cost){
        graph[edge_one].push_back({edge_two,cost});
        graph[edge_two].push_back({edge_one,cost});
        return;
    }

    // 計算する
    void culc(int s){
        priority_queue<P, vector<P>, greater<P>> que;
        dist[s]=0;
        que.emplace(0,s);
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(dist[v]<p.first) continue;
            for(auto e: graph[v]){
                if(dist[e.to]>dist[v]+e.cost){
                    dist[e.to]=dist[v]+e.cost;
                    que.emplace(dist[e.to],e.to);
                }
            }
        }
    }

    // 距離を出す
    int ans(int t){
        return dist[t];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    vector<vector<int>> g(n,vector<int>(0));
    int x,y;
    rep(i,m){
        cin>>x>>y;
        x --,y --;
        g[x].emplace_back(y);
    }
    int s,t;
    cin>>s>>t;
    s--,t--;

    dijkstra dk(n*3);
    rep(i,n){
        for(auto z:g[i]){
            dk.add(i,z+n,1);
            dk.add(i+n,z+n+n,1);
            dk.add(i+n+n,z,1);
        }
    }

    dk.culc(s);
    int ans=dk.ans(t);
    if(ans==dk.MAX_dist) cout<<-1<<endl;
    else cout<<ans/3<<endl;
    return 0;
}/*
./problem.exe
*/

Measured memory_bytes: 26156
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 4e3 + 4;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;

double a[N];

long double dp[N][N];

int main () {
	boost;
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 1 ; i <= n ; ++ i) {
		for (int j = 0 ; j < N ; ++ j) {
			dp[i][j] += dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]);
		}
	}
	long double ans = 0;
	for (int i = n / 2 + 1 ; i < N ; ++ i) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision (11);
	cout << ans;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int temp[MAX];

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, Q;
	int l, r;
	string S;
	
	cin>>N>>Q>>S;
	
	for(int i = 1; i < S.size(); i++){
		if(S[i] == 'C' && S[i-1] == 'A') temp[i]++;
		temp[i+1] += temp[i];
		
	}
	// for(int i = 0; i < S.size(); i++){
		// cout<<i<<" = "<<temp[i]<<endl;
	// }
	for(int i = 0; i < Q; i++){
		cin>>l>>r;
		cout<<temp[r-1]-temp[l-1]<<endl;
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1872
import sys


stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a = ns()
if a[0] == a[1] and a[1] == a[2] or a[1] == a[2] and a[2] == a[3]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    lint n,a,b;std::cin>>n>>a>>b;
    std::cout<<(a==b||a<b&&1<n?(n-2)*(b-a)+1:0)<<'\n';
}


Measured memory_bytes: 256
def count(n,l):
    c = 0
    for a in l:
        c += a.count(n)
    return c

H, W, K = [int(i) for i in input().split()]
cake = [list(input()) for i in range(H)]
dec = []
c = 1
for a in range(H):
    for b in range(W):
        if cake[a][b] == "#":
            dec.append([a,b])
            cake[a][b] = c
            c += 1

# for a in cake:
#     print(a)

for i,a in enumerate(dec,1):
    x,y = a
    while y > 0 and cake[x][y-1] == ".":
        cake[x][y-1] = i
        y -= 1
    y = a[1]
    while y < W - 1 and cake[x][y+1] == ".":
        cake[x][y+1] = i
        y += 1

# print()
# for a in cake:
#     print(a)

for a in range(len(cake)):
    if cake[a].count(".") == W:
        b = a
        if a != 0:
            # while cake[b].count(".") == W:
            #     b -= 1
            cake[a] = cake[a-1]
        else:
            while cake[b].count(".") == W:
                b += 1
            cake[a] = cake[b]

# print()
for a in cake:
    print(" ".join(map(str, a)))

Measured memory_bytes: 16884
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    ll X = abs(A-B);
    rep(pc, N){
        ll lp = pc*C, rp = pc*D;
        ll lm = (N-1-pc)*C, rm = (N-1-pc)*D;
        if(lp-rm <= X && X <= rp-lm){
            cout << "YES" << endstr; return 0;
        }
    }
    cout << "NO" << endstr;
    return 0;
}


Measured memory_bytes: 256
import itertools
n=int(input())
p=list(map(int, input().split()))
q=list(map(int, input().split()))

retu=range(1,n+1)
cnt=0
cp=0
cq=0
for r in itertools.permutations(retu):
    rr = [r[i] for i in range(n)]
    cnt+=1
    if rr == p:
        cp=cnt
    if rr == q:
        cq=cnt
print(abs(cp-cq))

Measured memory_bytes: 9188
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

int main() {
  int n, m;
  cin >> n >> m;
  vi x(n);
  vvi group(m);
  vi eachnum(100005, 0);
  rep (i, n) {
    cin >> x[i];
    group[x[i] % m].eb(x[i]);
    eachnum[x[i]] += 1;
  }
  rep (i, m) {
    sort(all(group[i]));
  }
  vi pairnum(m, 0);
  rep (i, 100005) {
    if (eachnum[i] >= 2) {
      pairnum[i % m] += eachnum[i] / 2;
    }
  }

  int ans = 0;
  ans += (int)group[0].size() / 2;
  if (m % 2 == 0) {
    ans += (int)group[m/2].size() / 2;
  }
  FOR (i, 1, (m-1)/2 + 1) {
    int j = m - i;
    int is, js;
    is = group[i].size();
    js = group[j].size();
    ans += min(is, js);
    int maxi;
    int diff;
    if (is == js) {
      continue;
    } else if (is > js) {
      maxi = i;
      diff = is - js;
    } else {
      maxi = j;
      diff = js - is;
    }
    ans += min(pairnum[maxi], diff/2);
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 6912
class Solution:
    def solve(self, x: int, y: int) -> int:

        if (2*x - y) % 3 != 0 or (-x + 2*y) % 3 != 0:
            return 0

        m = (2*x - y) // 3
        n = (-x + 2*y) // 3

        if m < 0 or n < 0:
            return 0

        # calculate {m+n}C{n}
        def egcd(a, b):
            if a == 0:
                return b, 0, 1
            else:
                g, y, x = egcd(b % a, a)
                return g, x - (b // a) * y, y

        def modinv(a, m):
            g, x, y = egcd(a, m)
            if g != 1:
                raise Exception('modular inverse does not exist')
            else:
                return x % m

        def convination(n: int, r: int, mod: int = 10**9+7) -> int:
            r = min(r, n-r)
            res = 1
            for i in range(r):
                res = res * (n-i) * modinv(i+1, mod) % mod
            return res

        return convination(n+m, m)


if __name__ == '__main__':

    # standard input
    x, y = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(x, y))


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

int main(){
    int N,K,num=1;
    cin >> N >> K;
    
    for(int i = 0; i < N; i++){
        if(num*2 <= num + K){
            num *= 2;
        }
        else{
            num += K;
        }       
    }
    cout << num << endl;
}


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

using namespace std;
using ii = pair<int, int>;

const int MAX { 310 };

string A[MAX];
int B[MAX][MAX];

ii next_to_fill(const set<int>& zs, int H)
{
    for (auto z : zs)
    {
        if (z == 0)
        {
            if (zs.count(1) == 0)
                return ii(0, 1);
            else
                continue;
        }

        if (z == H - 1)
        {
            if (zs.count(H - 2) == 0)
                return ii(H - 1, H - 2);
            else
                continue;
        }

        if (zs.count(z - 1) == 0)
            return ii(z, z - 1);

        if (zs.count(z + 1) == 0)
            return ii(z, z + 1);
    }

    return ii(-1, -1);
}

int solve(int H, int W, int)
{
    int next = 1;
    set<int> zs;

    for (int i = 0; i < H; ++i)
    {
        int found = 0;

        for (int j = 0; j < W; ++j)
            if (A[i][j] == '#')
                ++found;

        if (found == 0)
        {
            zs.insert(i);
            continue;
        }

        int j = 0;

        while (A[i][j] == '.')
            B[i][j++] = next;

        B[i][j++] = next;

        while (j < W)
        {
            if (A[i][j] == '#')
                next++;

            B[i][j++] = next;
        }

        ++next;
    }

    while (not zs.empty())
    {
        auto p = next_to_fill(zs, H);
        auto i = p.first, L = p.second;

//cout << "i = " << i << ", L = " << L << "\n";
        for (int j = 0; j < W; ++j)
            B[i][j] = B[L][j];

        zs.erase(i);
    }

    return 0;
}

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

    int H, W, K;
    cin >> H >> W >> K;

    for (int i = 0; i < H; ++i)
        cin >> A[i];

    solve(H, W, K);

    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j)
            cout << B[i][j] << (j + 1 == W ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 1280
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    vector<vector<char>> base(h, vector<char>(w, '#'));
    char v0[] = {'6', '3', '1', '4'};
    char v2[] = {'1', '3', '6', '4'};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(i % 4 == 0) base[i][j] = v0[j % 4];
            if(i % 4 == 1) if(j % 2 == 0) base[i][j] = '2';
            if(i % 4 == 2) base[i][j] = v2[j % 4];
            if(i % 4 == 3) if(j % 2 == 0) base[i][j] = '5';
        }
    }

    queue<P> que;
    que.emplace(0, 0);
    vector<vector<bool>> visited(h, vector<bool>(w, false));
    visited[0][0] = true;
    
    while(que.size()){
        int cy, cx; tie(cy, cx) = que.front(); que.pop();

        if(cy == h - 1 && cx == w - 1){
            cout << "YES" << endl;
            return 0;
        }

        for(int i=0; i<4; i++){
            int ny = cy + dy[i], nx = cx + dx[i];
        
            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
            if(s[ny][nx] == '#') continue;
            if(s[ny][nx] != base[ny][nx]) continue;
            if(visited[ny][nx]) continue;

            visited[ny][nx] = true;
            que.emplace(ny, nx);
        }
    }

    cout << "NO" << endl;

    return 0;
}


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

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  int d,e,answer;
  answer=0;
  
  for(int i=0;i<a;i++){
    cin>>d>>e;
    if(d>=b&&e>=c){
      answer++;
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	Abra_Ka_Dabra

	string x;
	cin>>x;
	int ans;
	if(x=="RRR") ans=3;
	else if(x=="RRS"||x=="SRR") ans=2;
	else if(find(x.begin(), x.end(), 'R')!=x.end()) ans=1;
	else ans = 0;
	cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;
const int MOD = 998244353;

int main()
{
    ll N, S;
    cin >> N >> S;

    vector<ll> values(N);
    rep(i, 0, N) cin >> values[i];

    vector<vector<ll>> dp(N+1, vector<ll>(S+2, 0));
    dp[0][0] = 1;
    rep(i, 0, N)
        rep(s, 0, S+1)
        {
            // not T
            dp[i+1][s] += dp[i][s];
            // not U
            dp[i+1][s] += dp[i][s];
            // U
            ll next = min(S+1, s + values[i]);
            dp[i+1][next] += dp[i][s];

            dp[i+1][s] %= MOD;
            dp[i+1][next] %= MOD;

            // cout << i << ' ' << s << endl;
            // pvec(dp[i+1]);
        }

    // rep(i, 0, N+1)
    //     pvec(dp[i]);

    cout << dp[N][S] << endl;

    return 0;
}


Measured memory_bytes: 73680
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll n,k;
ll ans;
int main(){
	scanf("%lld %lld",&n,&k);
	printf("%lld",min(n-n/k*k,-(n-n/k*k-k)));
	return 0;
}


Measured memory_bytes: 760
# coding: utf-8
N, M = map(int, input().split())
ac, wa = 0, 0
l = {}
T = {}
idx, sta = -1, -1
for i in range(M):
    tmp = input().split()
    p = int(tmp[0])
    s = tmp[1]
    if p not in l.keys():
        l[p] = 0
        T[p] = False
    if s == "AC" and not T[p]:
        ac += 1
        T[p] = True
    if s == "WA" and not T[p]:
        wa += 1
        l[p] += 1
cnt = 0
for k in l.keys():
    if not T[k]:
        cnt += l[k]
print(ac, wa-cnt)

Measured memory_bytes: 21192
def main():
  while True:
    w, h = map(int, input().split())
    if not w:
      break
  
    n = int(input())
  
    xlst = [0, w - 1]
    ylst = [0, h - 1]
    plst = []
  
    for i in range(n):
      x1, y1, x2, y2 = map(int, input().split())
      plst.append([x1,y1,x2 - 1,y2 - 1])
      xlst.append(x1)
      xlst.append(x2)
      xlst.append(x2 - 1)
      ylst.append(y1)
      ylst.append(y2)
      ylst.append(y2 - 1)
  
    xlst = list(set(xlst))
    ylst = list(set(ylst))
    sorted_xlst = sorted(xlst)
    sorted_ylst = sorted(ylst)
  
    xdic = {}
    ydic = {}
  
    for i, v in enumerate(sorted_xlst):
      xdic[v] = i
    for i, v in enumerate(sorted_ylst):
      ydic[v] = i
    
    neww = xdic[sorted_xlst[-1]]
    newh = ydic[sorted_ylst[-1]]

    painted = [[1] * (newh + 2)]
    for _ in range(neww):
      painted.append([1] + [0] * newh +  [1])
    painted.append([1] * (newh + 2))  
  
    for p in plst:
      x1, y1, x2, y2 = p
      x1, y1, x2, y2 = xdic[x1] + 1, ydic[y1] + 1, xdic[x2] + 1, ydic[y2] + 1
      for x in range(x1, x2 + 1):
        for y in range(y1, y2 + 1):
          painted[x][y] = 1
          
    ans = 0
    que = []
    app = que.append
    pp = que.pop  
    for x in range(1, neww + 1):
      for y in range(1, newh + 1):
        if not painted[x][y]:
          ans += 1
          painted[x][y] = 1
          app((x,y))
          while que:
            px, py = pp()
            for tx, ty in [(px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1)]:
              if not painted[tx][ty]:
                painted[tx][ty] = 1
                app((tx,ty))
    print(ans)

main()


Measured memory_bytes: 21832
# Python Program to find the count of 
# numbers in a range where the number 
# does not contain more than K non 
# zero digits 

# This function returns the count of 
# required numbers from 0 to num 
def countInRangeUtil(pos, cnt, tight, num): 

	# Last position 
	if pos == len(num): 

		# If count of non zero digits 
		# is less than or equal to K 
		if cnt == K: 
			return 1
		return 0

	# If this result is already computed 
	# simply return it 
	if dp[pos][cnt][tight] != -1: 
		return dp[pos][cnt][tight] 

	ans = 0

	# Maximum limit upto which we can place 
	# digit. If tight is 1, means number has 
	# already become smaller so we can place 
	# any digit, otherwise num[pos] 
	limit = 9 if tight else num[pos] 

	for dig in range(limit + 1): 
		currCnt = cnt 

		# If the current digit is nonzero 
		# increment currCnt 
		if dig != 0: 
			currCnt += 1

		currTight = tight 

		# At this position, number becomes 
		# smaller 
		if dig < num[pos]: 
			currTight = 1

		# Next recursive call 
		ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 

	dp[pos][cnt][tight] = ans 
	return dp[pos][cnt][tight] 

# This function converts a number into its 
# digit vector and uses above function to compute 
# the answer 
def countInRange(x): 
	global dp, K, M 

	num = [] 
	while x: 
		num.append(x % 10) 
		x //= 10

	num.reverse() 

	# Initialize dp 
	dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
	return countInRangeUtil(0, 0, 0, num) 

# Driver Code 

# states - position, count, tight 
dp = [] 
M = 101

# K is the number of non zero digits 
K = 0

L = 1
R = int(input())
K = int(input())
print(countInRange(R) - countInRange(L - 1)) 





Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	vll a(N + 1), b(N + 1);
	repn(i, N) cin >> a[i];
	repn(i, N) cin >> b[i];

	ll ab = 0;
	ll ba = 0;
	repn(i, N) {
		if (a[i] > b[i]) { ab += a[i] - b[i]; }
		else { ba += (b[i] - a[i])/2; }
	}

	if (ab <= ba) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

Measured memory_bytes: 3772
n,m = map(int,input().split())
a = list(map(lambda z:int(z)-1,input().split()))
pre = [i for i in range(n)]
for _ in range(m):
  x,y = map(lambda z:int(z)-1,input().split())
  while pre[x] != x:
    x = pre[x]
  while pre[y] != y:
    y = pre[y]
  if x == y:
    continue
  elif x < y:
    pre[y] = x
  else:
    pre[x] = y
home1 = [10**6 for _ in range(n)]
home2 = [10**6 for _ in range(n)]
for i in range(n):
  I = i
  while pre[I] != I:
    I = pre[I]
  home1[i] = I
  home2[a[i]] = I
ans = 0
for i in range(n):
  if home1[i] == home2[i]:
    ans += 1
print(ans)

Measured memory_bytes: 72428
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), p.begin() + k, 0);
}

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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if(a%2&&b%2&&c%2){
    vector<long long> x;
    x={a,b,c};
    sort(x.begin(),x.end());
    cout << x.at(0)*x.at(1) << endl;
  }
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int h,n,sum=0,x;
	cin>>h>>n;
	while(n--){
		cin>>x;
		sum+=x;
	}
	if(sum>=h){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
    return 0;
}

Measured memory_bytes: 256