akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    int N,A,B,C,D,ans;
    bool F=true;
    string S,T;
int main(){
    cin>>N;
    if(N%3==0)ans=N/3;
    else ans=N/3;
    if(ans<0)ans=0;
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int dp[5005][5005];

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;

    for (int i=n-1; i>=0; i--) {
        for (int j=n-1; j>=0; j--) {
            if (s[i]==s[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
    rep(i, n) rep(j, n) {
        if (i>=j) continue;
        int v = dp[i][j];
        if (v<=j-i) ans = max(ans, v);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 98048
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
ll mod=1e9+7;
ll n,k;
ll g2(ll a, ll b){
	if(b==1) return a;
	ll g=g2(a,b/2);
	g=(g*g)%mod;
	if(b%2 !=0 ) g=(g*a)%mod;
	return g;
}
ll g1( ll x){
	ll ans=1;
	for(ll i=2;i<=x;i++){
		ans=(g2(i,mod-2)*ans)%mod;
	}
	return ans;
}
ll g(ll a, ll b){
	if(b==0) return 1;
	if( b > a) return 0;
	ll ans=1;
	for(ll i=2;i<=a;i++){
		ans=(ans*i)%mod;
	}
	return (((ans*g1(b))%mod)*g1(a-b))%mod;
}
ll f(ll r){
	if(r>k) return 0;
	ll x=n-k;
	if(x < r-1) return 0;
	x-=r-1;
	return (g(k-1,r-1)*g(x+r,r))%mod;
}
int main(){
  /*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
    */
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>k;
	for(ll i=1;i<=k;i++){
		cout<<f(i)<<"\n";
	}
}

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

int main(){
    int A;
    cin>>A;
    int len=1;
    while(len*(len+1)/2<A) len++;
    int diff=len*(len+1)/2-A;
    cout<<string(len-diff,')')<<'('<<string(diff,')')<<string(len-1,'(')<<endl;

    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,K,X,Y;
  cin>>N>>K>>X>>Y;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(i<=K)ans+=X;
    else ans+=Y;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
v_list = input().split(" ")
v_list = [int(v) for v in v_list]
v_list.sort()

avg = 0
for i in range(1, N):
  if i == 1:
    avg = (v_list[0] + v_list[1])/2
  else:
    avg = (avg + v_list[i])/2
print(avg)



Measured memory_bytes: 3060
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

#[fastout]
fn main() {
    input!(a:i64, b:f64);
    let b = b * 100f64 + 0.001;
    let b = b as i64;
    println!("{}", a * b / 100);
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n, m;
  cin >> n >> m;
  int cur = 1;
  int times = 0;
  while (cur < m){
      cur -= 1;
      cur += n;
      times++;
  }
  cout << times;
  return 0; 
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  ll wcnt = 0, ans = 0;
  bool b = false;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == 'B') b = true;
    if (s[i] == 'W') {
      ans += i - wcnt;
      wcnt++;
    }
  }

  cout << (b ? ans : 0) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
using namespace std;

int main(){
map<string,int> hito;
int n,m;
string s;
cin>>n;
for(int q=0;q<n;q++){
cin>>s;
hito[s]=1;
}
cin>>m;
int j=0;
for(int q=0;q<m;q++){
cin>>s;
if(hito.find(s)==hito.end()) cout<<"Unknown "<<s<<endl;
else{
if(j%2==1)cout<<"Closed by "<<s<<endl;
else cout<<"Opened by " <<s<<endl;
j++;
}
}


return 0;
}

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

int C[100001];

int main()
{
	int n; cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int a;cin >> a;
		if (!C[a])cnt++;
		C[a]++;
	}

	int s=0;
	for (int i = 1; i < 100001; i++) {
		if (C[i]) {
			C[i] %= 2;
			if (C[i] == 0)C[i] += 2;
		}
		if (C[i] == 2)s++;
	}

	s %= 2;

	cout << cnt - s << endl;

    return 0;
}



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

int main()
{
	queue<ll int> q;
	ll int i,k,x;
	for(i=1;i<10;i++)
	{
		q.push(i);
	}
	cin>>k;
	k--;
	while(k--)
	{
		x=q.front();
		q.pop();
		
		if (x%10!=0)
		{
			q.push(10*x+x%10-1);
		}
		q.push(10*x+x%10);
			
		if (x%10!=9)
		{
			q.push(10*x+x%10+1);
		}
		
		
		
		
		
	}
	cout<<q.front()<<endl;
	
}





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

using namespace std;

int main(){
    cout.precision(10);
    int i,n,a,b,d=0,g;
    cin >> n >> a >> b ;
    long long c[n],ans=0,e = 0,comb=1;
    long long f[55][55];
    for(i=0;i<n;i++){
        cin >> c[i];
    }

    sort(c,c+n);

    for(i=0;i<a;i++){
        ans += c[n-1-i];
    }
    cout << (long double)ans/(long double)a << endl;

    for(i=0;i<n;i++){
        if(c[i] == c[n-a]){
            d++;
        }
        if(c[i] > c[n-a]){
            e += 1;
        }
    }

    if(c[n-1-a]==c[n-1]){
        f[d][0]=1;
        for(i=1;i<=n;i++){
            f[d][i] = (f[d][i-1]*(d+1-i))/i ;
        }
        g = min(b,d);
        for(i=a;i<=g;i++){
            e += f[d][i];
        }
        cout << e << endl;
        return 0;
    }

        for(i=1;i<=(a-e);i++){
            comb = ((d+1-i)*comb)/i;
        }
        cout << comb << endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
    int a[9], match[9];
    int i, j, n;
    for(i=0;i<9;i++){
        std::cin >> a[i];
        match[i]=0;
    }
    std::cin >> n;
    int b;
    for(i=0;i<n;i++){
        std::cin >> b;
        for(j=0;j<9;j++){
            if(a[j]==b){
                match[j]=1;
                break;
            }
        }
    }
    int bingo[8][3] = {
        {0, 1, 2},
        {3, 4, 5},
        {6, 7, 8},
        {0, 3, 6},
        {1, 4, 7},
        {2, 5, 8},
        {0, 4, 8},
        {2, 4, 6},
    };
    for(i=0;i<8;i++){
        int m = 0;
        for(j=0;j<3;j++)m+=match[bingo[i][j]];
        if(m==3){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    
    std::cout << "No" << std::endl;
    return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
vector<int> to[100005];

int ans[100005];
bool kit[100005];


int main()
{
    int n,m;
    cin >> n >> m;
    
    for(int i=0;i<m;i++){
        int a, b;
      cin >> a >> b;
      --a; --b;
      to[a].push_back(b);
      to[b].push_back(a);
    }

    for(int i=0;i<n;i++){
        ans[i] = INF;
    }

    queue<int> q;
    vector<int> d(n,INF);
    vector<int> pre(n,-1);

    d[0] = 0;
    q.push(0);
    while(!q.empty()){
        int now = q.front();
        q.pop();

        for(int j : to[now]){
            if(d[j] != INF) continue;
            d[j] = d[now]+1;
            pre[j] = now;
            q.push(j);
        }
    }

    cout << "Yes"<<endl;

    for(int i=1;i<n;i++){
        cout << pre[i] + 1 <<endl;
    }
    return 0;
}

Measured memory_bytes: 11064
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int dp[51];
	int cut[51];
	int i,j,k;
	int high=0;
	int MIN=INT_MAX; 
	int MAX;
	int low=-1;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>cut[i];
		high+=cut[i];
		low=max(low,cut[i]);
	}
	for(k=low;k<high;k++){
		//cout<<" K=" <<k<<endl;
		for(i=0;i<51;i++){
			dp[i]=0;
		}
		int sum=0;
		dp[0]=cut[0];
		for(i=0;i<n;i++){
			if((dp[i]+cut[i+1])>k)	break;
			dp[i+1]=dp[i]+cut[i+1];
		}
		for(i=0;i<n;i++){
			int sum=0;
			//cout<<"i="<<i<<endl<<endl<<endl;
			for(j=i+1;j<n;j++){
				sum+=cut[j];
				if(sum>k)	break;
				//cout<<"SUM="<<sum<<endl<<endl;
				//cout<<"dp[j]="<<dp[j]<<"dp[i]"<<dp[i]<<"sum"<<sum<<endl<<endl;
				dp[j]=max(dp[j],min(dp[i],sum));
				//cout<<"DP[j]"<<dp[j]<<endl<<endl;
			}
			
		}
		/*for(i=0;i<n;i++){
			cout<<dp[i]<<endl;
		}
		cout<<endl;*/
		MIN=min(MIN,k-dp[n-1]);
	}
	cout<<MIN<<endl;
	return 0;
}


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

int main() {
	int A, B;
	double K;

	//AとBを読み込む
	scanf("%d %d", &A, &B);

	//Kの値の計算
	K = (A + B) / 2.0;

	(ceil(K) != floor(K)) ? printf("IMPOSSIBLE\n") : printf("%d\n", (int) K);
}

Measured memory_bytes: 128
def main():
  s = str(input())
  ans = s.replace('?', 'z')
  flag = False
  t = str(input())
  for i in range(len(s)-len(t)+1):
    temp_flag = True
    temp_ans = list(s)
    for j in range(len(t)):
      if s[i + j] == '?':
        temp_ans[i + j] = t[j]
        continue
      elif s[i+j] != t[j]:
        temp_flag = False
    if temp_flag:
      flag = True
      temp_ans = "".join(temp_ans)
      temp_ans = temp_ans.replace('?', 'a')
      ans = min(ans, temp_ans)
  if flag:
    print(ans)
  else:
    print("UNRESTORABLE")
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
     String[] O=sc.nextLine().split(" ");
   //  String[] E=sc.nextLine().split("");

//int n=Integer.parseInt(nyuA);

int H=Integer.parseInt(O[0]);
int W=Integer.parseInt(O[1]);

String[] line=new String[H];

for(int i=0;i<H;i++){
line[i]=sc.nextLine();
}

for(int i=0;i<W+2;i++)
System.out.print("#");

System.out.println();

for(int i=0;i<H;i++){
System.out.print("#");
System.out.print(line[i]);
System.out.println("#");
}

for(int i=0;i<W+2;i++)
System.out.print("#");

System.out.println();


//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        vec.at(i) = P(A,i);
    }
    sort(vec.begin(),vec.end());
    vector<int> ret(N);
    for(int i = 0;i < N;i++) {
        if(i < N / 2) {
            ret.at(vec.at(i).second) = vec.at(N / 2).first;
        }
        else {
            ret.at(vec.at(i).second) = vec.at(N / 2 - 1).first;
        }
    }
    for(int i = 0;i < N;i++) {
        cout << ret.at(i) << endl;
    }
}

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

long long n, x;

vector<long long> brg;
vector<long long> pa;

long long solve(long long n, long long x){
  if(n == 0) return 1;
  if(x <= 1) return 0;
   
  else if(x <= brg.at(n-1) + 1) return solve(n-1, x-1);
  else if(x == brg.at(n-1) + 2) return pa.at(n-1) + 1;
  else if(x <= 2 * brg.at(n-1) + 2) return solve(n-1, x-brg.at(n-1)-2) + pa.at(n-1) + 1;
  else return pa.at(n-1) * 2 + 1;
}

int main(){
  cin >> n >> x;
  
  brg.resize(n+1);
  pa.resize(n+1);
  brg.at(0) = 1;
  pa.at(0) = 1;
  for(int i = 1; i < n+1; ++i){
    brg.at(i) = brg.at(i-1) * 2 + 3;
    pa.at(i) = pa.at(i-1) * 2 + 1;
  }
  
  cout << solve(n, x) << endl;
}

Measured memory_bytes: 256
def main():
    _ = int(input())
    s = input()

    ans = 0

    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j), a + 1)
            if b == -1:
                continue
            for k in range(10):
                c = s.find(str(k), b + 1)
                if c == -1:
                    continue
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

int counting[110] = {0};

int main()
{
    int N, temp;
    cin >> N;
    vector <int> arr;

    for (int i = 0; i < N; i++)
    {
        cin >> temp;
        arr.push_back(temp);
    }

    int ans = 1;
    vector<int> ans_arr;
    for (int i = 0; i < N; i++)
    {
        int input = 0, idx = arr.size();
        while(idx!=0)
        {
            if (arr[idx-1] == idx)
            {
                input = arr[idx-1];
                arr.erase(arr.begin()+idx-1);
                break;
            }
            idx--;
        }
        if (input == 0)
        {
            ans = 0;
            break;
        }
        else
        {
            ans_arr.push_back(input);
        }

    }


    if (ans == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        for (int i = 0; i < N; i++)
        {
            cout << ans_arr[N-1-i] << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

if n == 1 and m == 1:
    print(1)
    exit()

if n == 1:
    print(m-2)
    exit()
    
if m == 1:
    print(n-2)
    exit()

print(n*m-2*n-2*m+4)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

const int M = 1000005;

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

    vector<int> cnt(M);
    for (auto x : a) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i < M; i += x) {
            cnt[i]++;
        }
    }
    int ans = 0;
    for (auto x : a) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7968
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N = 0;
int cost[100010];
int x[100010];
int main() {
	scanf("%d",&N);
	int total=0;
	x[0] = 0;
	for (int i = 1; i <= N;i++) {
		scanf("%d",&x[i]);
		cost[i - 1] = abs(x[i]-x[i-1]);
		total += cost[i-1];
	}
	cost[N] = abs(x[N]);
	total += cost[N];
	x[N + 1] = 0;
	for (int i = 1; i <= N; i++) {
		printf("%d\n",total - (cost[i - 1] + cost[i]) + abs(x[i - 1] - x[i + 1]) );
	}
}


Measured memory_bytes: 1920
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int f[1005][1005]={};
int dp[1005][1005];
int h,w,n;

int main()
{
while(1)
{
	scanf("%d %d %d",&h,&w,&n); if(!n) return 0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			scanf("%d",&f[i][j]);
		}
	}
	memset(dp,0,sizeof(dp));
	dp[1][1]=n-1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(dp[i-1][j]%2==1) dp[i][j]+=max(0,(dp[i-1][j]+(!f[i-1][j]?1:-1))/2);
			else dp[i][j]+=max(0,(dp[i-1][j])/2);
			
			if(dp[i][j-1]%2==1) dp[i][j]+=max(0,(dp[i][j-1]+(f[i][j-1]?1:-1))/2);
			else dp[i][j]+=max(0,(dp[i][j-1])/2);
		}
	}
	int nx=1,ny=1;
	while(nx<=h && ny<=w)
	{
		bool x=f[nx][ny];
		bool y=(dp[nx][ny]%2);
		if((x+y)%2==1) ny++;
		else nx++;
	} 
	printf("%d %d\n",nx,ny);
}
}

Measured memory_bytes: 9068
import sys
from collections import deque


def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())


H, W = IN_LI()
s = [IN_S() for _ in range(H)]

dh = [-1, 0, 1, 0]
dw = [0, -1, 0, 1]

dist = [[-1] * W for j in range(H)]
dist[0][0] = 0

q = deque()
q.append([0, 0])

while q:
    now = q.popleft()
    now_h = now[0]
    now_w = now[1]

    for i in range(4):
        next_h = now_h + dh[i]
        next_w = now_w + dw[i]

        if not (0 <= next_h < H and 0 <= next_w < W):
            continue
        if s[next_h][next_w] == '#':
            continue

        if dist[next_h][next_w] == -1:
            q.append([next_h, next_w])
            dist[next_h][next_w] = dist[now_h][now_w] + 1

if dist[-1][-1] == -1:
    print(-1)
    exit()

white = sum([i.count('.') for i in s])
ans = white - (dist[-1][-1] + 1)
print(ans)


Measured memory_bytes: 9420
N, M = map(int, input().split())
s = []
for _ in range(M):
    kss = list(map(int, input().split()))
    s.append(set([x - 1 for x in kss[1:]]))
p = list(map(int, input().split()))

ans = 0
for bit in range(1 << N):
    on_counts = [0] * M
    for i in range(N):
        if bit & (1 << i):
            for m in range(M):
                if i in s[m]:
                    on_counts[m] += 1
    if [x % 2 for x in on_counts] == p:
        ans += 1
print(ans)

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

int main(void){
  string a,b,c;
  cin >> a >> b >> c;
  string A[2];
  string B[2];
  string C[2];
  A[0] = a.front();
  A[1] = a.back();
  B[0] = b.front();
  B[1] = b.back();
  C[0] = c.front();
  C[1] = c.back();
  if(A[1] == B[0] && B[1] == C[0]){
    cout << "YES" << "\n";
  }
  else{
    cout << "NO" << "\n";
  }
}


Measured memory_bytes: 256
a, b, k = (map(int, input().split()))
s = set()
for i in range(k):
    if(a+i>b):
        break
    s.add(a+i)
for i in range(k):
    if(b-i<a):
        break
    s.add(b-i)
a = list(s)
a = sorted(a, key=lambda x: x, reverse=False)
for i in a:
    print(i)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007

int main()
{
    double r;
    cin>>r;
    double ans=2*pi*r;
    cout<<setprecision(10)<<fixed<<ans<<endl;
}


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

int main(){

    string s;

    cin >> s;

    int b=0,r=0;
    rep(i,s.size()){
        if(s[i]=='1'){
            b++;
        }else{
            r++;
        }
    }

    cout << min(b,r)*2 <<endl;

    return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())

li = []
for i in range(m):
    a, b = map(int, input().split())
    tpl = (a,b)
    li.append(tpl)

city = []
for i in range(n+1):
    city.append(0)

for i in range(1,n+1):
    for j in range(m):
        if i in li[j]:
            city[i] += 1
    print(city[i])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*int a, b, c;
	cin >> a >> b >> c;
	int ans;
	if (a - b > c)ans = 0; else ans = c - a + b;
	cout<<ans;*/


	/*int N;
	cin >> N;
	int ans = 0;
	int i, j = 10;
	for (i = 1; i <=N;i++) {
		if (i >= j / 10 && i < j)ans++;
		else {
			i = 10 * i - 1;
			j *= 100;
		}
	}
	cout << ans;*/


	/*int N;
	cin >> N;
	vector<int>h(N + 1);
	rep(i, N)cin >> h[i + 1];
	rep(i, N) {
		if (h[i + 1] > h[i])h[i + 1]--;
		if (h[i + 1] < h[i]) {
			cout << "No"; return 0;
		}
	}
	cout << "Yes";*/


	string s;
	cin >> s;
	int i, j;
	vector<int>ans(s.size());
	int r = 1, l = 0;
	for (i = 1; i < s.size(); i++) {
		if (s[i] == 'R') { r++; continue; }
		if (s[i] == 'L') {
			for (j = i; j < s.size(); j++) {
				if (s[j] == 'L') {
					l++;
					if (j != s.size() - 1) { continue; }
					else {
						ans[i - 1] = (r + 1) / 2 + l / 2;
						ans[i] = r + l - ans[i - 1];
						i = s.size();
						r = 0;
						l = 0;
						break;
					}
				}
				if (s[j] == 'R') {
					ans[i - 1] = (r + 1) / 2 + l / 2;
					ans[i] = r + l - ans[i - 1];
					i = j - 1;
					r = 0;
					l = 0;
					break;
				}
			}
		}
	}
	rep(i, s.size())cout << ans[i] << " ";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int x = 0;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    x = a[x]-1;
    if (x == 1) {
      count = i+1;
      break;
    }
  }
  if (count !=0) {
    cout << count << endl;
  }
  else {
    cout << count-1 << endl;
  }
}

Measured memory_bytes: 3764
#include <iostream>
//#include <array>
#include <algorithm>
#include <functional>

int main()
{
    long n, a, b;
    std::cin >> n >> a >> b;
    std::cout << std::min(a, b) << " " << ((a + b - n) < 0 ? 0 : (a + b - n)) << std::endl;
    return 0;
}

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

const int MOD = 1e+9 + 7;


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


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

    vector<long long> dp(N+1);
    dp[0] = 1;

    int idx;
    if( M > 0 and a[0] == 1 ){
        dp[1] = 0;
        idx = 1;
    }else{
        dp[1] = 1;
        idx = 0;
    }
    for( int i = 2; i <= N; ++i ){
        if( idx < M and i == a[idx] ){
            dp[i] = 0;
            ++idx;
        }else{
            dp[i] = (dp[i-1]+dp[i-2]) % MOD;
        }
    }
    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1408
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   string t = "ACGT";

   int ans = 0;
   int cnt = 0;
   rep(i, 0, s.size()) {
      bool isACGT = false;
      rep(j, 0, t.size()) {
         if (s[i] == t[j]) isACGT = true;
      }
      if (isACGT) {
         cnt++;
         chmax(ans, cnt);
      } else {
         cnt = 0;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
n= int(input())
s=0
a=[]


def solve(p):
	x,y = p[0][0], p[0][1]
	t=0
	for i in range(1,n):
		# print(x,y)
		t+= (( x- p[i][0])**2 + (y- p[i][1])**2)**0.5
		x= p[i][0]
		y= p[i][1]

	return t

import itertools
for _ in range(n):
	x,y= map(int,input().split())
	a.append([x,y])


z = list(itertools.permutations(a))

for i in z:
	# print(i)
	s+=solve(i)
# print(s)








for i in range(1,n+1):
	s/= i
print(s)

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int m=INT_MAX;
    rep(i,n-k+1){
        m = min(m,h[i+k-1]-h[i]);
    }

    cout << m <<endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//    idx len sum
ll dp[55][55][2505];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,a;cin>>n>>a;
    ll x[n+1];for(ll i=1;i<=n;i++)cin>>x[i];
    for(ll idx=0;idx<=n;idx++)dp[idx][0][0]=1;
    for(ll idx=1;idx<=n;idx++){
        for(ll len=1;len<=idx;len++){
            for(ll sum=0;sum<=2500;sum++){
                dp[idx][len][sum]=dp[idx-1][len][sum];
                if(sum-x[idx]>=0)
                    dp[idx][len][sum]+=dp[idx-1][len-1][sum-x[idx]];
            }
        }
    }

    ll ans = 0;
    for(ll len=1;len<=n;len++){
        ll req = a*len;
        ans+=dp[n][len][req];
        //cout<<len<<" "<<req<<"  "<<dp[n][len][req]<<endl;
    }

    cout<<ans;
}




Measured memory_bytes: 53504
#include <stdio.h>

#define N 100000

typedef struct {
  char name[10];
  int time;
} Queue; 

Queue Q[N];

int head=0,tail,n;


void enqueue(Queue x){
  Q[tail] = x;
  if(tail + 1 == n){
    tail = 0;
  }else{
    tail++;
  }
}

Queue dequeue(void){
  Queue r;
  r = Q[head];
  if(head + 1 == n){
    head = 0;
  }else{
    head++;
  }
  return r;
}


int main(void){
  int q,i,elaps=0,count=0;
  Queue data;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].time);
  }
  
  while(count != n){
    data = dequeue();
    if(data.time <=  q){
      elaps += data.time;
      count++;
      printf("%s %d\n",data.name,elaps);
    }else{
      elaps += q;
      data.time -= q;
      enqueue(data);
    }
  }

  
  return 0;
}



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

using namespace std;

vector<int> height;

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

  int n, h, prev = 0;
  cin >> n;
  int res = 0;
  while (n--) {
    cin >> h;
    res += (h > prev ? h-prev : 0);
    prev = h;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if (y == NIL) {
		root = z;
	}else {
		if (z->key < y->key) {
			y->left = z;
		}else {
			y->right = z;
		}
	}
}

void inOrder(Node* u){
	if (u == NIL) {
		return;
	}
	inOrder(u->left);
	printf(" %d", u->key);
	inOrder(u->right);
}

void preOrder(Node* u)
{
	if (u == NIL) {
		return;
	}
	printf(" %d", u->key);
	preOrder(u->left);
	preOrder(u->right);
}

int main(int argc, char *argv[]) {
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}else if (com == "print") {
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 26736
/*
      author : nishi5451
      created: 12.08.2020 11:34:28
*/

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


int main(){
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
    return 0;
}

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

namespace ABC132
{
    class Program
    {


        static void Main(string[] args)
        {
            string Str = Console.ReadLine().Trim();
            int n = int.Parse(Str);

            Str = Console.ReadLine().Trim();
            string[] StrArr = Str.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
            int[] p = StrArr.Select(int.Parse).ToArray();
            int cnt = 0;

            for (int i = 1; i < n-1; i++)
            {
                if ((p[i] > p[i - 1]) && (p[i] > p[i + 1]))
                {

                }
                else if ((p[i] < p[i - 1]) && (p[i] < p[i + 1]))
                {

                }else
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);

        }

    }
}


Measured memory_bytes: 13396
import sys

N, K = map(int, input().split())
steps = list(map(int, input().split()))

dp = [sys.maxsize] * N
dp[0] = 0
for i in range(1, N):
    limit = K if K <= i else i
    for j in range(1, limit + 1):
        a = abs(steps[i] - steps[i - j]) + dp[i - j]
        dp[i] = a if a < dp[i] else dp[i]

print(dp[N - 1])


Measured memory_bytes: 84816
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)420;


int main(void) {
   ll N;
   cin>>N;
   vector<array<ll,65>> A(N);
   rep(i,0,N) {
      ll a;
      cin>>a;
      ll b = a;
      int j = 0;
      while (1) {
         A[i][j] = b%2;
         b /= 2;
         j++;
         if (j==65) break;
      }
   }
   // rep(i,0,N) {
   //    rep(j,0,65) {
   //       cout<<A[i][j];
   //    }
   //    cout<<endl;
   // }
   array<ll,65> sum;
   rep(i,0,65) sum[i] = 0;
   rep(i,0,65) {
      rep(j,0,N) {
         sum[i] += A[j][i];
      }
   }
   array<ll,65> ans;
   rep(i,0,65) ans[i] = 0;
   rep(i,0,N) {
      rep(j,0,65) {
         if (A[i][j]) ans[j] += N - sum[j];
         else ans[j] += sum[j];
      }
   }
   rep(i,0,65) ans[i] /= 2;
   rep(i,0,65) ans[i] %= MOD;
   // rep(i,0,65) cout<<ans[i];
   // cout<<endl;
   ll ans2 = 0;
   ll now = 1;
   rep(i,0,65) {
      ans2 += now*ans[i];
      now *= 2;
      ans2 %= MOD;
      now %= MOD;
   }
   cout<<(ans2+MOD)%MOD<<endl;


   return 0;
}

Measured memory_bytes: 152576
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        sc.close();

        int max = 0;

        for(int i = 0; i < N; i++){
            if(s.substring(i).equals(t.substring(0, N-i)))
                max = Math.max(max, s.substring(i).length());
        }

        System.out.println(2*N-max);
    }
}

Measured memory_bytes: 21972
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vi X(N);
  cin >> X;
  int ans = INF;
  rep(p, 0, 101) {
    int tmp = 0;
    rep(i, 0, N) { tmp += (X[i] - p) * (X[i] - p); }
    chmin(ans, tmp);
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int A[20];
int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> A[i];
  }
  set <int> possible_sums;
  for(int bit_set = 0; bit_set < (1 << n); bit_set++){
    int tmp_sum = 0;
    for(int i = 0; i < n; i++){
      if((((bit_set) >> i) & 1) == 1){
        tmp_sum += A[i];
      }
    }
    possible_sums.insert(tmp_sum);
  }

  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int m;
    cin >> m;
    if(possible_sums.find(m) != possible_sums.end()){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
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; }

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

struct Point{
  double x, y;
  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x+p.x, y+p.y); }
  Point operator - (Point p) { return Point(x-p.x, y-p.y); }
  Point operator * (double a) { return Point(x*a, y*a); }
  Point operator / (double a) { return Point(x/a, y/a); }

  double abs() { return sqrt(norm()); }
  double norm() { return x*x + y*y; }

  bool operator < (const Point &p) const{
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

typedef Point Vector;

struct Segment{
  Point p1, p2;
};

double dot(Vector a, Vector b){
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b){
  return a.x*b.y - a.y*b.x;
}

Point project(Segment s, Point p){
  Vector a = s.p2 - s.p1;
  Vector b = p - s.p1;
  return s.p1 + a * (dot(a, b)/a.norm());
}

Point reflect(Segment s, Point p){
  return p + (project(s, p) - p)*2;
}

static const int Counter_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a, b) > EPS) return Counter_CLOCKWISE;
  else if(cross(a, b) < -EPS) return CLOCKWISE;
  else if(dot(a, b) < -EPS) return ONLINE_BACK;
  else if(a.norm() < b.norm()) return ONLINE_FRONT;
  else return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4){
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
          ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 );
}

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

  rep(i, q){
    double x1, y1, x2, y2;
    double x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    cin >> x3 >> y3 >> x4 >> y4;
    Point p1 = Point(x1, y1);
    Point p2 = Point(x2, y2);
    Point p3 = Point(x3, y3);
    Point p4 = Point(x4, y4);
    cout << intersect(p1, p2, p3, p4) << endl;
  }

  return 0;

}





Measured memory_bytes: 3232
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
    int n;
    cin>>n;
    int a=0,w=0,t=0,r=0;
    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        if(s=="AC") a++;
        else if(s=="WA") w++;
        else if(s=="TLE") t++;
        else if(s=="RE") r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
}
int main()
{
    io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3624
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 8)
h,n=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda abi:(abi[1]/abi[0],abi[0]))

@lru_cache(maxsize=None)
def dp(i):
  if i<=0:
    return 0
  else:
    ans=float('inf')
    for a,b in ab:
      val=b+dp(i-a)
      if val<ans:
        ans=val
      else:
        break
    return ans

print(dp(h))

Measured memory_bytes: 30180
#include<iostream>

using namespace std;

int main(void) {
	int a, b, c, x;
	int count = 0;

	cin >> a >> b >> c >> x;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					count++;
				}
			}
		}
	}

	cout << count << endl;

	return 0;
}

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

int R, S, P;

int win(char c) {
  int ret = 0;
  if (c == 'r') ret += P;
  if (c == 's') ret += R;
  if (c == 'p') ret += S;
  return ret;
}

int main() {
  int N, K;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i < K) {
      ans += win(T.at(i));
      continue;
    }
    if (T.at(i) == T.at(i - K)) T.at(i) = ' ';
    else ans += win(T.at(i));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3748
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    string c; cin >> c;
    int cntr = 0, cntw = 0;
    rep(i, n) {
        if(c[i] == 'R') ++ cntr;
        else ++ cntw;
    }
    int ret = 0;
    rep(i, n) {
        if(i < cntr && c[i] == 'W') ++ ret;
        if(i >= cntr && c[i] == 'R') ++ ret;
    }
    cout << (ret) / 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
ll a[3003][3003]={0},k,r,c;
ll dp[3003][3003][4]={0};
int main(void)
{
	scanf("%lld%lld%lld",&r,&c,&k);
	for(ll i=0;i<k;i++)
	{
		ll r1,c1,v1;
		scanf("%lld%lld%lld",&r1,&c1,&v1);
		a[r1][c1]=v1;
	}
	dp[1][1][1]=a[1][1];
	for(ll i=1;i<=r;i++)
	{
		for(ll j=1;j<=c;j++)
		{
			for(ll k=0;k<=3;k++)
			{
				dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
				dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
				dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+a[i+1][j]);
				if(k<3)
				{
					dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+a[i][j+1]);
				}
			}
		}
	}
	printf("%lld\n",max(max(dp[r][c][0],dp[r][c][1]),max(dp[r][c][2],dp[r][c][3])));
}

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

using namespace std;
 
const long long inf = 1e18;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;

ll n,m,k;
vector <double> ps;
double dp[3000][3000];
// double solve(int ind,int h) {
// 	if (ind == n) {
// 		if (h <= n / 2)
// 			return 0;
// 		return 1;
// 	}
// 	if (dp[ind][h])
// 		return dp[ind][h];
// 	return dp[ind][h] = (ps[ind] * solve(ind+1,h+1)) + (((double)1 - ps[ind]) * solve(ind+1,h)  );
// }
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//memset(dp,-1,sizeof dp);
	cin >> n;
	fr(i,0,n) {
		double x;
		cin >> x;
		ps.pb(x);
	}
	dp[0][0] = 1;
	fr(i,1,n+1) {
		fr(j,0,n+1) {
			dp[i][j] = ps[i-1] * dp[i-1][j-1];
			dp[i][j] += ((double)1 - ps[i-1]) * dp[i-1][j]; 
		} 
	}
	double ans = 0;
	for (int i = n/2 + 1;i <= n;i++) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
import sys
from itertools import accumulate

input = sys.stdin.readline


def solve(H, W, D, A, Q, LR):
    position = [None] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = [0] * (H * W + 1)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = list(accumulate(mp[d::D]))

    ans = [str(mp[r] - mp[l]) for l, r in LR]
    ans = "\n".join(ans)
    return ans


def main():
    H, W, D = map(int, input().split())
    A = [None] * H
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = [None] * Q
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = solve(H, W, D, A, Q, LR)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44180
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

vector<int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int n, m;
vector<vector<int>> ban;

bool ok(int i, int j) {
	return i >= 0 && j >= 0 && i < n && j < m && !ban[i][j];
} 

int bfs(int st, int en) {
	vector<int> d(n * m, n * m + 2);
	d[st] = 0;
	queue<int> q;
	q.push(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		int i = v / m;
		int j = v % m;
		for (int k = 0; k < 4; k++) {
			int ni = i + dx[k];
			int nj = j + dy[k];
			if (!ok(ni, nj)) continue;
			int nv = ni * m + nj;
			if (d[nv] > d[v] + 1) {
				d[nv] = d[v] + 1;
				q.push(nv);
			}
		}
	}
	return d[en];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    ban.resize(n, vector<int> (m));
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < m; j++) {
    		char c;
    		cin >> c;
    		ban[i][j] = (c == '#');
    	}
    }
    int ans = 0;
    for (int f = 0; f < n * m; f++) {
    	for (int s = 0; s < n * m; s++) {
    		if (ok(f / m, f % m) && ok(s / m, s % m)) {
    			ans = max(ans, bfs(f, s));
    		}
    	}
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256