akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int MN = 2010;

int N, K;
int psum[MN][MN];

int calc(int x1, int y1) {
    int x2 = x1 + K - 1;
    int y2 = y1 + K - 1;
    if(x1 < 0) x1 = 0;
    if(y1 < 0) y1 = 0;
    if(x2 >= 2*K) x2 = 2*K - 1;
    if(y2 >= 2*K) y2 = 2*K - 1;
    if(x1 > x2 || y1 > y2) return 0;

    int ret = 0;
    ret += psum[x2][y2];
    if(x1) ret -= psum[x1 - 1][y2];
    if(y1) ret -= psum[x2][y1 - 1];
    if(x1 && y1) ret += psum[x1 - 1][y1 - 1];

    return ret;
}

int main() {
    scanf("%d %d", &N, &K);

    for(int i = 0; i < N; i++) {
        int x, y; char c; scanf("%d %d %c", &x, &y, &c);

        if(c == 'B') {
            x %= (2*K);
            y %= (2*K);

            psum[x][y]++;
        }
        else {
            x += K;
            x %= (2*K);
            y %= (2*K);

            psum[x][y]++;
        }
    }

    for(int i = 0; i < 2*K; i++) {
        for(int j = 0; j < 2*K; j++) {
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }

    int ans = 0;
    for(int i = 0; i < 2*K; i++) {
        for(int j = 0; j < 2*K; j++) {
            int tmp = 0;
            for(int a = -2; a <= 2; a++) {
                for(int b = -2; b <= 2; b++) {
                    if((a + b) % 2 == 0) {
                        tmp += calc(i + a * K, j + b * K);
                    }
                }
            }

            ans = max(ans, tmp);
        }
    }

    cout << ans;
}


Measured memory_bytes: 16000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        sc.close();

        //この問題で考えられる貨幣
        int[] coin = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};

        int[] dp = new int[100000+1];

        dp[0] = 0;

        for (int i = 1; i <= N; i ++) {

            int min = Integer.MAX_VALUE;

            for (int j = 0; j < coin.length; j++ ) {

                if (i >= coin[j]) {
                	//全貨幣の中から最適な支払いパターンを検索する
                    min = Math.min(min, Math.min(dp[i-1] + 1, dp[i-coin[j]] +1));
                }
            }

            dp[i] = min;
        }

        System.out.println(dp[N]);
    }

}


Measured memory_bytes: 23764
#include<iostream> 
int main()
{
  int ret[9] = {111,222,333,444,555,666,777,888,999};
  int i = 0;
  int buf;
  std::cin >> i;
  for(int j = 0; j < 9; j ++)
  {
    if(i <= ret[j]){
      buf = ret[j];
      break;
    }
  }
  std::cout << buf << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i];

	deque<ll> s;
	for (ll i = 0; i < N; ++i)
	{
		if (i & 1)
			s.push_front(A[i]);
		else
			s.push_back(A[i]);
	}

	if (N & 1) reverse(s.begin(), s.end());

	for (ll i = 0; i < N; ++i)
		std::cout << (i ? " " : "") << s.at(i);
	std::cout << std::endl;
}

Measured memory_bytes: 5376
def result(n)
  # $stderr.puts C.to_s
  puts n
  exit
end

N = $stdin.gets.to_i
C = $stdin.gets.strip.split(//)
rp = 0
wp = C.length - 1
cnt = 0
loop do
  while C[rp] == 'R'
    if (rp += 1) == wp
      result cnt
    end
  end
  while C[wp] == 'W'
    if (wp -= 1) == rp
      result cnt
    end
  end
  C[rp] = 'R'
  C[wp] = 'W'
  cnt += 1
  # $stderr.puts "#{rp} #{wp}"
end


Measured memory_bytes: 33000
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,z,w;
    cin>>n>>z>>w;
    vector<long> a(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    long t=abs(a[n-1]-w);
    if(n==1)
        cout<<t;
    else
        cout<<max(abs(a[n-2]-a[n-1]),t);
}

Measured memory_bytes: 256
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
   int a[33]={0,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};
   int k;
   while(cin>>k)
   {
       cout<<a[k]<<'\n';
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int N;
ll L[100];
int main(void){
    cin >> N;
    REP(i,N) cin >> L[i];
    ll cnt = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if(L[i]==L[j] or L[j]==L[k] or L[k]==L[i]) continue;
                if((L[i]+L[j] > L[k] and L[k] > L[i] and L[k] > L[j]) or (L[i]+L[k] > L[j] and L[j] > L[i] and L[j] > L[k]) or (L[k]+L[j] > L[i] and L[i] > L[k] and L[i] > L[j]))
                {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3552
import sys
INPUT = sys.stdin.readline

def SINGLE_INT(): return int(INPUT())
def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))
def MULTIPLE_INT_MAP(): return map(int, INPUT().split())
def SINGLE_STRING(): return INPUT()
def MULTIPLE_STRING(): return INPUT().split()

N, K = MULTIPLE_INT_MAP()

if K == 1:
    print(0)
else:
    print(N-K)

Measured memory_bytes: 3316
#include <cstdio>

int main()
{
    int n;
    scanf("%d", &n);

    //配列の初期化
    bool card[4][13];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
            card[i][j] = false;
    }

    for (int i = 0; i < n; i++)
    {
        //カードの収納
        char c;
        scanf("\n%c", &c);

        int x;
        scanf("%d", &x);

        //配列にtrueを代入していく
        //スペードの場合
        if (c == 'S')
        {
            card[0][x - 1] = true;
        }
        //ハートの場合
        else if (c == 'H')
        {
            card[1][x - 1] = true;
        }
        //クラブの場合
        else if (c == 'C')
        {
            card[2][x - 1] = true;
        }
        //ダイヤの場合
        else if (c == 'D')
        {
            card[3][x - 1] = true;
        }
    }

    char gara[4] = {'S', 'H', 'C', 'D'};

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (card[i][j] == false)
                printf("%c %d\n", gara[i], j + 1);
        }
    }

    return 0;
}


Measured memory_bytes: 2668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
vector<pair<ll,ll>>v1;
#include <boost/math/common_factor.hpp> 


int main()
{
  ll a,b,c,d,n1,n2,n11,n3,n4,n22,z1,n5,n6,n33,ans;
  cin>>a>>b>>c>>d;

  n1 = (a-1)/c;
  n2 = b/c;
   n11 = n2 - n1;

    n3 = (a-1)/d;
  n4 = b/d;
  n22 = n4-n3;

  z1 = boost::math::lcm(c,d);


n5 = (a-1)/z1;
  n6 = b/z1;

  n33 = n6 - n5;

  ans = n11 + n22 - n33;

ll  n10 = b-a+1;
   ans = n10 - ans;

  cout<<ans<<endl;

  return 0;
}


   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    vector<int> L(N);
    for(int i = 0;i < N;i++){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    int sum = 0;
    for(int i = 0;i < N-1;i++){
        sum += L[i];
    }
    if(sum > L[N-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int main(void){
    int ans = 700;
    
    string s;
    cin >> s;
    
    for ( int i = 0; i < 3; i++ ){
        if ( s[i] == 'o' )ans += 100;
    }
    prtd1(ans);
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */		
int check(string s)
{
   int i=0,j=s.size()-1,flag=0;
   while(i<=j)
   {
      if(s[i]==s[j])
      ;
      else flag=1;
      i++;j--;
   }
   return flag;
}
void solve()
{  string s,s1="",s2="";int i;
   cin>>s;int n=s.size();
   for(i=0;i<(n-1)/2;i++)
   s1.pb(s[i]);
   for(i=(n+3)/2 -1 ;i<n;i++)
   s2.pb(s[i]);
   if(check(s1)== 0 && check(s2)==0 && check(s)==0)
   cout<<"Yes";else cout<<"No";
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case #"<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int l,r;
     cin>>l>>r;
     int res=1e9;
     FOR(i,l,r)
     {
     	  if(i%2019==0)
     	  {
     	  	  cout<<0<<endl;
     	  	  return 0;
     	  }

     }
    FOR(i,l,r)
    {
    	 FOR(j,i+1,r)
    	 {
    	 	  res=min(res,(i*j)%2019);
    	 }
    }
    cout<<res<<endl;
     time();
     return 0;
}

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

using namespace std;

int main(){
	int n, k, s;
	cin >> n >> k >> s;
	if(s == 1000000000){
		for(int i = 0; i < k; i++){
			cout << s << ' ';
		}
		for(int i = k; i < n; i++){
			cout << s - 1 << ' ';
		}
	}else{
		for(int i = 0; i < k; i++){
			cout << s << ' ';
		}
		for(int i = k; i < n; i++){
			cout << s + 1 << ' ';
		}
	}
}

Measured memory_bytes: 1280
# C
N = int(input())
# A = list(map(int, input().split()))
order_number = {}


for num, order in enumerate(map(int, input().split())):
    order_number[num+1] = order

for order, number in sorted(order_number.items(), key=lambda x: x[1]):
    print(order, end=" ")
print()

Measured memory_bytes: 29804
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

	int j=0,o=0,i=0;
	int best=INT_MIN;

void up(){
	if(o<=j&&o<=i)
	best=max(best,min(j,min(o,i)));
	
}
int main(){
	string s;
	cin>>s;
	char prev=' ';
	REP(c,s.size()){
		switch(s[c]){
		case 'J':
			if(prev=='J'){
				j++;
			}else{
				up();
				j=1;o=0;i=0;
			}
			break;
		case 'O':
			if(prev=='O'){
				o++;
			}else if(prev=='J'){
				o=1;
			}else{
				up();
				j=0;o=0;i=0;
			}
			break;
		case 'I':
			switch(prev){
			case 'J':
				up();
				j=0;o=0;i=0;break;
			case 'O':
				i=1;
				break;
			case 'I':
				i++;break;
			}
			break;
		}
		prev=s[c];
	}
	up();


	cout<<best<<endl;

}

Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int64_t N, X;

int main() {

  cin >> N >> X;

  int64_t ret = N;

  int64_t n = N-X, x = X;
  while (true) {
    ret += (n / x) * 2 * x;

    int64_t t = x;
    x = n % x;
    n = t;

    if (x == 0) {
      ret -= t;
      break;
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll t=sqrt(n),res=(a*n/b)-a*(n/b);
	if(b>t){
		for(ll i=b-1;i<=n;i+=b)
		res=max(res,(a*i/b)-a*(i/b));
	}
	else{
		for(ll i=0;i<b;i++)
		res=min(res,((a*i)%b)-a*(i%b));
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 1000000007;

ll powmod(ll x, ll n){
    ll ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }
        else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}
ll gcd(ll a,ll b){
    while(b!=0){
        a %= b;
        if(a==0) return b;
        b %= a;
    }
    return a;
}
signed main(){
    int n; cin >> n;
    map<Pll,ll> mp;
    int zero_zero=0;
    int zero_x=0,zero_y=0;
    rep(i,n){
        ll a,b; cin >> a >> b;
        if(a==0&&b==0){
            zero_zero++;
        }else if(a==0){
            zero_x++;
        }else if(b==0){
            zero_y++;
        }else{
            ll g=gcd(llabs(a),llabs(b));
            a/=g; b/=g;
            if(a<0){
                a=-a; b=-b;
            }
            mp[{a,b}]++;
        }
    }
    ll ans=1;
    ll res=1;
    res+=powmod(2,zero_y)-1; res%=MOD;
    res+=powmod(2,zero_x)-1; res%=MOD;
    ans*=res; ans%=MOD;
    map<Pll,bool> used;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        Pll p=itr->fi;
        if(used[p]) continue;
        Pll p1;
        if(p.se>0) p1={p.se,-p.fi};
        else p1={-p.se,p.fi};
        
        used[p]=1; used[p1]=1;
        ll x=mp[p],y=mp[p1];
        res=0;
        res+=powmod(2,y); res%=MOD;
        res+=powmod(2,x); res%=MOD;
        res--;
        ans*=res; ans%=MOD;
    }
    ans+=zero_zero-1;
    cout << (ans+MOD)%MOD << endl;
    return 0;
}



Measured memory_bytes: 53496
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

int N,M;
int A[100],B[100];
vector<int> V[10];
bool used[10];
int ans = 0;

void dfs(int X){
    bool end = 1;
    REP(i,N) if(!used[i] && i != X) end = 0;
    if(end){
        ans++;
        return;
    }if(used[X])return;else used[X] = 1;
    REP(i,V[X].size()){
        dfs(V[X][i]);
    }
    used[X] = 0;
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);cin >> N >> M;
    REP(i,M){
        cin >> A[i] >> B[i];--A[i];--B[i];
        V[A[i]].pb(B[i]);V[B[i]].pb(A[i]);
    }
	dfs(0);
    cout << ans << endl;
}

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

int main(){
    std::vector< int > A(5);
    for(int i=0; i<5; i++){
        std::cin >> A[i];
    }
    for(int i=0; i<5; i++){
        if(A[i] == 0){
            std::cout << i+1 << std::endl;
            return 0;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int long long h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int a=0;
	for(int i=0;i<n;i++){
		if(a<=h[i]-1){
			a=h[i]-1;
		}
		else if(a<=h[i]){
			a=h[i];
		}
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = gets.chomp.to_i
s = []
h = {}
m = 0
x, y = [], []
n.times do |i|
  x[i], y[i] = gets.chomp.split.map(&:to_i)
end
n.times do |i|
  n.times do |j|
    l = [x[i] - x[j], y[i] - y[j]]
    next if l == [0, 0]
    next if s.include?([-l[0], -l[1]])
    if !s.include?(l)
      s << l
      h[l] = 1
      m = 1 if m == 0
    else
      h[l] += 1
      m = h[l] if m < h[l]
    end
  end
end
puts n - m


Measured memory_bytes: 1916
N,K,*D = map(int, open(0).read().split())
Ds = set(D)
item = set([0,1,2,3,4,5,6,7,8,9]) - Ds
strs = set(str(x) for x in item)
for i in range(N,10000):
    s = set(str(i))
    if s.issubset(strs):
        print(i)
        break
else:
    il = list(item)
    il.sort()
    if il[0] == 0:
        ans = [str(il[1])] + ([str(il[0])]*len(str(N)))
        print(''.join(ans))
    else:
        ans = ([str(il[0])]*(len(str(N))+1))
        print(''.join(ans))

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

namespace AtTest.Msolutions2019
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            string s = Read();
            int win = 0;
            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'o') win++;
            }
            win += 15 - s.Length;
            WriteLine(win >= 8 ? "YES" : "NO");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
if(a + b == c + d){cout << "Balanced" << endl;}
  else if(a + b > c + d){cout << "Left" << endl;}
  else{cout << "Right" << endl;}
  }

Measured memory_bytes: 384
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 60;
const ll inf = 1e18;

ll a[N];

ll ceil_div(ll x, ll y);

int main()
{
	int n;
	cin >> n;
	priority_queue <ll> q;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		q.push(a[i]);
	}

	ll s = 0;
	while (q.top() > n - 1 - s)
	{
		ll cur = q.top();
		q.pop();
		ll p = ceil_div(cur - n + s + 1, n + 1);
		cur -= p * (n + 1);
		s += p;
		q.push(cur);
	}

	cout << s << endl;
}

ll ceil_div(ll x, ll y)
{
	return (x / y) + !!(x % y);
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  out(nin()<=8&&nin()<=8?'Yay!':':(')
}
main()

Measured memory_bytes: 7372
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

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

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
void File()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	/*freopen("output.txt", "w", stdout);
	freopen("story.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

int main()
{
	fast();
	//File();
	int x, y, m, n, o;
	cin >> x >> y >> n >> m >> o;
	vector<int> red(n);
	vector<int> green(m);
	priority_queue<int> all;
	for (int i = 0; i < n; i++)
		cin >> red[i];
	for (int i = 0; i < m; i++)
		cin >> green[i];
	for (int i = 0; i < o; i++)
	{
		int x;
		cin >> x;
		all.push(x);
	}
	sort(all(red));
	sort(all(green));
	ll res = 0;
	for (int i = sz(red) - 1, k = 0; i >= 0 && k < x; i--, k++)
	{
		all.push(red[i]);
	}
	for (int i = sz(green) - 1, k = 0; i >= 0 && k < y; i--, k++)
		all.push(green[i]);
	for (int i = 1; i <= x + y; i++)
	{
		res += all.top();
		all.pop();
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3316
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b; readV(a, b);
  writeln((a-1)*(b-1));
}


Measured memory_bytes: 256
/*input
1231213
1000000000000000000
*/
#include <bits/stdc++.h>
#pragma GCC optmize("O2")
using namespace std;
#define int unsigned long long
#define F first
#define S second
#define pii pair<int, int>
int pomo(int n) {
    if(n == 1) return 1;
    else return 1e18 + 1;
}
main () {
    string s; cin >> s;
    int k; cin >> k;
    int sum = 0;
    for(auto it: s) {
        sum += pomo(it - '0');
        if(sum >= k) return cout << it, 0;
    }
}

Measured memory_bytes: 256
while True:
    h = map(int, raw_input().split())
    if h[0] == 0:
        break
    t = 0
    a = 0
    for c in sorted(h, reverse=True):
        if 2 <= c <= 9:
            t += c
        elif 10 <= c:
            t += 10
        elif c == 1:
            a += 1
            
    t += a
    if 21 < t:
        print 0
    else:
        for i in range(a):
            if 21 < t + 10:
                print t
                break
            else:
                t += 10
        else:
            print t

Measured memory_bytes: 4224
#include<stdio.h>

main(){
    int a, b, c, d, x;

    // Aの入力
    scanf("%d", &a);
    // Bの入力
    scanf("%d", &b);
    // Cの入力
    scanf("%d", &c);
    // Dの入力
    scanf("%d", &d);
    
    x = 0;
    x +=  a<b ?a : b; 
    x += c<d ? c : d; 

    // 出力
    printf("%d\n", x);
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int a, b;
  
  scanf("%d %d", &a, &b);
  
  if(a%3 == 0 || b%3 == 0 || (a + b)%3 == 0){
    printf("Possible\n");
  } else {
    printf("Impossible\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static const long long MOD_NUM = 1000000007LL;

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}

static void D_task()
{
	LLONG H;
	get1int<LLONG>(H);

	LLONG cnt = 1;
	LLONG divCnt = 1;
	LLONG rest = H / 2;
	while (rest) {
		cnt += tp_pow<LLONG>(2, divCnt);
		rest = rest / 2;
		divCnt++;
	}
	printf("%lld\n", cnt);
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Array.IO
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf
import Debug.Trace


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

mul [] [] = 0
mul (a:as) (b:bs) = (a*b) + mul as bs

mulmat :: [[Int]] -> [[Int]] -> [[Int]]
mulmat [] _ = []
mulmat a b = let b' = transpose b
             in map (\a0 -> map (mul a0) b') a

main = do
    [n,m,l] <- replicateM 3 readInt
    a <- replicateM n $ replicateM m readInt
    b <- replicateM m $ replicateM l readInt
    mapM_ prints $ mulmat a b


Measured memory_bytes: 16480
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    cout << "Christmas";
    int D;
    cin >> D;
    rep(i, 0, 25 - D)
    {
        cout << " Eve";
    }
    cout << endl;
}


Measured memory_bytes: 256
while input = STDIN.gets.split(" ")
  n = input[0].to_i
  x = input[1].to_i

if n == 0 && x == 0
  break
end

num = 0
  for i in 1..n  do
    a = i
    for j in 1..n do if j > i
      b = j
      for k in 1..n  do if k >j
        c = k
        if a + b + c == x
          num +=1
        end
      end
      end end
    end end
  puts num
end


Measured memory_bytes: 6864
package main

import (
	"fmt"
	"strings"
)

func indexes(s, subs string) []int {
	var a []int
	var p int
	for {
		i := strings.Index(s, subs)
		if i == -1 {
			break
		}
		a = append(a, i+p)
		s = s[i+1:]
		p += i + 1
	}
	return a
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ns := make([]string, n)
	ms := make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&ns[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&ms[i])
	}
	for i := 0; i <= n-m; i++ {
		for _, v := range indexes(ns[i], ms[0]) {
			found := true
			for j := 0; j < m; j++ {
				if strings.Index(ns[i+j][v:], ms[j]) != 0 {
					found = false
					break
				}
			}
			if found {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(abs(c-a) <= d || (abs(a-b) <= d &&  abs(b-c) <=d )){
		cout << "Yes";
	}
	else
		cout << "No";
}


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

struct apples{
    long long co;
    long long de;
};

bool cmp(apples a,apples b){
    return a.de>b.de;
}

int main(){
    long long x,y,a,b,c,ans=0,no=0;
    cin>>x>>y>>a>>b>>c;
    apples apple[a+b+c];
    for(long long i=0;i<a;i++){
        cin>>apple[i].de;
        apple[i].co=1;//red
    }
    for(long long i=a;i<a+b;i++){
        cin>>apple[i].de;
        apple[i].co=2;//green
    }
    for(long long i=a+b;i<a+b+c;i++){
        cin>>apple[i].de;
        apple[i].co=0;//no
    }
    sort(apple,apple+a+b+c,cmp);

    for(long long i=0;i<a+b+c;i++){
        if(apple[i].co==1&&x){
            ans+=apple[i].de;
            x--;
        }
        else if(apple[i].co==2&&y){
            ans+=apple[i].de;
            y--;
        }
        else if(apple[i].co==0){
            ans+=apple[i].de;
            no++;
        }
        if(x+y-no==0){
            cout<<ans;
            return 0;
        }
    }
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  (s == "ABC") ? cout << "ARC" : cout << "ABC";
  cout << "\n";
return 0;
}


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

int main()
{
    int N,M;
    cin >> N >> M;

    vector<int> city(N+1);
    for (int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;

        city.at(a)++;
        city.at(b)++;
    }

    for (int i=1; i<=N; i++) {
        cout << city.at(i) << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
const ll mod= 1e9+7;
const int inf=1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2)cout<<b-a<<endl;
  else cout<<a-b<<endl;
  
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	ll ans = 0;
	for (int i = n - 2; i >= 0; i--) {
		ans = (ans + a[i] * a[i + 1]) % MOD;
		a[i] = (a[i] + a[i + 1]) % MOD;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * Every number can be formed from 1 by repeatedly applying this operation
 * 1) multiply it by 10
 * 2) add 1
 * You need to find the shortest path from 1 to a k multiple
 * you can do bfs but it becomes a lot more because you can go down 45(99999) levels
 * and 2^45 is large
 * but you can see that it is not required to visit some node later with some modulo
 * which has already been visited
 * */


int main() {
	ll k;
	cin >> k;
	vector <int> dist(k, 50);
	deque <ll> dq;
	dq.push_front(1);
	dist[1] = 1;
	while(!dq.empty()) {
		ll x = dq.front();
		if (x == 0) {
			cout << dist[0];
			return 0;
		}
		dq.pop_front();
		if (dist[(x * 10) % k] > dist[x]) {
			dist[(x * 10) % k] = dist[x];
			dq.push_front((x * 10) % k);
		}
		if (dist[(x + 1) % k] > dist[x] + 1) {
			dist[(x + 1) % k] = dist[x] + 1;
			dq.push_back((x + 1) % k);
		}
	}	
	assert(false);
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;
void solve(){
    int n,m;
    cin>>n>>m;
    unordered_set<int> tt;
    unordered_map<int,int> t;
    LL ans2 = 0;
    for(int i = 0;i<m;i++){
        int x;
        string y;
        cin>>x;
        cin>>y;
        if(tt.count(x-1)) continue;
        if(y=="AC"){
            ans2+=t[x-1];
            tt.insert(x-1);
            continue;
        }
        t[x-1]++;
    }
    LL ans1 = tt.size();
    cout<<ans1<<" "<<ans2<<endl;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 8520
def main():
  import sys
  sys.setrecursionlimit(500000)
  input = sys.stdin.readline

  N, Q = map(int, input().split())
  G = [set() for _ in range(N)]
  cnt = [0]*N
  visited = [0]*N

  for _ in range(N-1):
      a, b = map(int, input().split())
      a -= 1
      b -= 1
      G[a].add(b)
      G[b].add(a)

  for i in range(Q):
      node, x = map(int, input().split())
      node -= 1
      cnt[node] += x

  visited[0]=1
  st = [0]
  while st:
      v = st.pop()
      for u in G[v]:
          if visited[u]:
              continue
          visited[u] = 1
          cnt[u] += cnt[v]
          st.append(u)    

  print(*cnt)
if __name__ == '__main__':
    main()

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  set<ll> s;
  map<ll,ll> m;
  rep(i,n){
    ll a; cin>>a;
    s.insert(a);
    m[a]++;
  }
  ll d=s.size()-k;
  if(d<=0){
    cout<<0<<endl;
    return 0;
  }
  vll v;
  for(auto e: m){
    v.push_back(e.second);
  }
  vsort(v);
  ll ans=0;
  rep(i,d){
    ans+=v[i];
  }
  cout<<ans<<endl;
}

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

int gcd(int x, int y)
{
    int r;
    if(x == 0 || y == 0){
        fprintf(stderr, "error\n");
        return 0;
    }
    while((r = x % y) != 0) 
    {
        x = y;
        y = r;
    }
    return y;
}
int main(void){
    int n,X,sa1=0,sa2 = 0;
    long long x,xx;
    cin >> n >> X;
    if(n == 1){
        cin >> x;
        cout << abs(X-x);
        return 0;
    }
    cin >> x; sa1 = abs(X-x);
    for(int i=0;i<n;i++){
        cin >> xx;
        sa2 = abs(X-xx);
        int g = gcd(sa1,sa2);
        sa1 = g;
    }
    cout << sa1;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class segment_tree{
    private:
        static int calc_size(int n){
            int m = 1;
            while(m < n){
                m *= 2;
            }
            return m;
        }

        T query(int s, int t, int i, int l, int r) const {
            if(r <= s || t <= l){
                return init;
            }

            if(s <= l && r <= t){
                return node[i];
            }

            int m = l + (r - l) / 2;
            T vl = query(s, t, i * 2 + 1, l, m);
            T vr = query(s, t, i * 2 + 2, m, r);
            return f(vl, vr);
        }

    public:
        int n;
        vector<T> node;
        T init;
        function<T(T, T)> f;

        segment_tree(int n, T init, function<T(T, T)> f)
            : n(calc_size(n)), node(calc_size(n) * 2, init), init(init), f(f){}

        void update(int i, const T& x){
            i += (n - 1);
            node[i] = x;
            while(i > 0){
                i = (i - 1) / 2;
                node[i] = f(node[2*i+1], node[2*i+2]);
            }
        }

        //[s, t)
        T query(int s, int t) const {
            return query(s, t, 0, 0, n);
        }
};

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    //Range Minimum Query
    segment_tree<int> st(k+1, INF, [](int a, int b){return min(a, b);});
    set<int> s;
    int i;
    for(i = 0; i < n; i++){
        if(a[i] > k){
            continue;
        }
        s.insert(a[i]);
        st.update(a[i], i);
        if((int)s.size() >= k){
            break;
        }
    }

    if((int)s.size() < k){
        cout << 0 << endl;
        return 0;
    }

    int ans = INF;
    for(; i < n; i++){
        if(a[i] > k){
            continue;
        }
        st.update(a[i], i);

        int mini = st.query(1, k+1);

        if(i - mini + 1 < ans){
            ans = i - mini + 1;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 10492
import sys
import io
import numpy as np
import itertools

def parse(inp):
    N=int(next(inp).split()[0])
    A=np.array(next(inp).split(),dtype=int)
    B=np.array(next(inp).split(),dtype=int)
    return N,A,B


def magic(D):
    moved = sum(D < 0)
    if (moved == 0): return 0
    s_minus = sum(D[D < 0])

    pluslist = np.sort(D[D > 0])[::-1]

    for i in itertools.accumulate(pluslist):
        moved += 1
        if (i > abs(s_minus)):
            break

    return moved


def main(inp):
    N = inp[0]
    A = inp[1]
    B = inp[2]
    D = np.empty(N, dtype=int)
    for i in range(N):
        D[i] = A[i] - B[i]

    if (A.sum() < B.sum()):
        return -1
    else:
        return magic(D)


print(main(parse(sys.stdin)))



Measured memory_bytes: 24844
n = input()
S = map(int,raw_input().split())
m = input()
T = map(int,raw_input().split())
C=0
def binarySearch(A,p):
    lens = len(A)
    ll = -1
    ul = lens-1
    ms=(ll+ul)/2
    while (ll+1<ul):
    	ms=(ll+ul)/2
        if A[ms] >= p:
            ul =ms
        elif A[ms] < p:
            ll =ms
    return A[ul]==p

for item in T:
    if binarySearch(S,item):
        C += 1
print C

Measured memory_bytes: 14852
while True:
	n=int(input())
	if n==0:
		exit()
	else:
		aa=[]
		for i in range(n):
			l,p,a,b,c,d,e,f,s,m=input().split()
			p=int(p)
			a=int(a)
			b=int(b)
			c=int(c)
			d=int(d)
			e=int(e)
			f=int(f)
			s=int(s)
			m=int(m)
			time=a+b+c+(d+e)*m
			pro=s*m*f-p
			aa.append([pro/time,l])
		aa.sort(key=lambda x:(-x[0],x[1]))
		for i in range(n):
			print(aa[i][1])
		print("#")
			


Measured memory_bytes: 5616
import numpy as np
N, M = list(map(int, input().split()))
A = [int(_) for _ in input().split()]
x = np.zeros(2 ** 18)
for a in A:
  x[a] += 1

y = np.fft.fft(x)

for k in range(len(y)):
  y[k] *= y[k]

x = np.fft.ifft(y).real

happiness = 0
for i in reversed(range(0, len(x))):
  happiness += i * min(int(x[i] + 0.5), M)
  M -= int(x[i] + 0.5)
  if M <= 0:
    break

print(happiness)

Measured memory_bytes: 43100
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll n,k; cin >> n >> k;
    if((n+1)/2>=k) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256