akhauriyash/Code-Regression huggingface dataset:
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int n; cin >> n;

    cout << (n/2) + (n % 2) << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	int ans = 0;
	while (a + w < b) {
		b--;
		ans++;
	}
	while (b + w < a) {
		a--;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    int i, j, k, n, m, x;
    int **skills, *costs;
    scanf("%d %d %d", &n, &m, &x);

    costs = (int*)malloc(sizeof(int) * n);
    skills = (int**)malloc(sizeof(int*) * n);
    for(i = 0; i < n; i++) {
        skills[i] = (int*)malloc(sizeof(int) * m);
    }

    for(i = 0; i < n; i++) {
        scanf("%d", &costs[i]);
        for(j = 0; j < m; j++) {
            scanf("%d", &skills[i][j]);
        }
    }
    int beki = 1;
    int mincost = 0;
    int bit, cost, skill_lv, failure_flag, suc_flag=0;

    for(i = 0; i < n; i++) {
        beki *= 2;
        mincost += costs[i];
    }
    for(i = 0; i < beki; i++) {
        failure_flag = 0;
        cost = 0;
        bit = i;
        for(k = 0; k < n; k++) {
            if(bit % 2)
                cost += costs[k];
            bit /= 2;
        }
        if(cost > mincost) {
            continue;
        }
        for(j = 0; j < m; j++) {
            skill_lv = 0;
            bit = i;
            for(k = 0; k < n; k++) {
                if(bit % 2) {
                    skill_lv += skills[k][j];
                }
                bit /= 2;
            }
            if(skill_lv < x) {
                failure_flag = 1;
                break;
            }
        }
        if(!failure_flag) {
            mincost = cost;
            suc_flag = 1;
        }
    }

    if(!suc_flag) printf("-1\n");
    else printf("%d\n", mincost);
    return 0;
}

Measured memory_bytes: 1700
num = [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]
print(num[int(input())-1])

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b,c,d,e,f=0;
  cin>>a>>b>>c>>d>>e;
  if(a+b<=2*c)
    f+=a*d+b*e;
  else{
    f+=2*c*min(d,e);
    if(d<e)
      swap(a,b),swap(d,e);
    if(a>2*c)
      f+=2*c*(d-e);
    else
      f+=a*(d-e);
  }
  cout<<f<<endl;
}

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

typedef long long ll;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll aa = a + (x - (a % x));
  ll bb = b + (x - (b % x));
  ll res = (bb - aa) / x + (a % x == 0 ? 1 : 0);

  cout << res << endl;
  return 0;
}


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

int abc158c(int a, int b) {
  for (int i = 1; i <= 10000; i++) {
    if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
      return i;
    }
  }
  return -1;
}

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

  cout << abc158c(a, b) << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	int m, d;
	cin >> m >> d;
	int ans = 0;
	REPN(i, 2, 9) {
		REPN(j, 2, 9) {
			//cout << i << " " << j << " " << m << " " << d << endl;
			if (i * j <= m && 10 * i + j <= d) {
				//cout << i << " " << j << endl;
				ans++;
			}
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
	int i,str_len;
	char str[200];
	fgets(str,sizeof(str),stdin);
	if(str==NULL){
		fprintf(stderr, "Error.\n");
	}
	str_len=strlen(str)-1;
	str[str_len]='\0';
	for(i=0;i<str_len;i++){
		if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
	}
	printf("%s\n",str);
	return 0;
}

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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int a[101];
int main() {
	int n = in();

	rep(i, n) {
		int b = in();
		if (b > 3200) b = 3200;
		a[b / 400]++;
	}

	int cnt = 0;
	rep(i, 8) {
		if (a[i]) cnt++;
	}

	cout << max(1, cnt) << " " << cnt + a[8] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
	
int n, C;

int weight[100001];
int value[100001];

long long int memo[101][100001];

long long int dp (int ob, int wt) { // wt is weight of knapsack left now, ob is object considered now
	if (ob == n or wt == 0)
		return 0;
	if (memo[ob][wt] != -1)
		return memo[ob][wt];
	long long int ans = dp(ob + 1, wt); // don't take this object
	if (weight[ob] <= wt)
		ans = max(ans, value[ob] + dp(ob + 1, wt - weight[ob])); // take this object
	memo[ob][wt] = ans;
	return ans;
}

int main () {
	cin >> n >> C;
	for (int i = 0; i < n; i++)
		cin >> weight[i] >> value[i];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= C; j++)
			memo[i][j] = -1;
	cout << dp(0, C) << '\n';
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    if(n<=3||n==5||n==6||n==9||n==10||n==13||n==17){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 256
s = input()

left = s[:len(s)//2]
right = s[len(s)//2+1:]

def kaibun(s):
    n_iter = len(s)//2
    ans = True
    for i in range(n_iter):
        if s[i] != s[-1-i]:
            ans = False
            break
    return ans


if kaibun(left)==True and kaibun(right)==True and kaibun(s)==True:
    print('Yes')
else:
    print('No')

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

typedef struct node *link;
struct node {
	int item;
	link next;
	link back;
};

void printlist(link h) {
	link t;
	for (t = h; t != NULL; t = t->next) {
		printf("%d", t->item);
		if (t->next != NULL) printf(" ");
	}
	printf("\n");
}


int main(void) {
	int n, i, d;
	link t, head = NULL;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		char comm[20];
		scanf("%s", comm);
		if (strlen(comm) < 7) scanf("%d", &d);

		if (comm[0] == 'i') {
			//printf("Command[%d] is insert %d => ", i + 1, d);
			link new = malloc(sizeof(link));
			new->item = d;
			new->next = head;
			if (head == NULL) new->back = new;
			else {
				new->back = head->back;
				head->back = new;
			}
			head = new;
		}
		else if (comm[0] == 'd') {
			if (comm[6] == 'F' || (strlen(comm) < 7 && head->item == d)) {
				if (head->next == NULL) {
					free(head);
					head = NULL;
				}
				else {
					t = head;
					head = head->next;
					head->back = t->back;
					free(t);
				}
			}
			else if (comm[6] == 'L') {
				if (head->back == head) {
					free(head);
					head = NULL;
				}
				else {
					t = head->back;
					head->back = t->back;
					t->back->next = NULL;
					free(t);
				}
			}
			else {
				link prev;
				t = head;
				while (t->item != d && t->next != NULL) {
					prev = t;
					t = t->next;
				}
				if (t->item == d) {
					prev->next = t->next;
					if (t->next == NULL) t->next = head;
					t->next->back = prev;
					free(t);
				}
			}
		}
	}

	printlist(head);

	return 0;
}

Measured memory_bytes: 32920
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            switch(op){
              case "+":
                  System.out.println(a+b);
                  break;
              case "-":
                  System.out.println(a-b);
                  break;
              case "*":
                  System.out.println(a*b);
                  break;
              case "/":
                  System.out.println(a/b);
                  break;
              case "?":
                  return;
            }
        }
    }
}



Measured memory_bytes: 26296
x[3]={1,0,0};
main(t)
{
  char a,b;
  for(;~scanf(" %c,%c",&a,&b);)
    {
      a-=65;b-=65;
      t=x[a];
      x[a]=x[b];
      x[b]=t;
    }
  for(t=0;t<3;t++)
    if(x[t]==1)
      printf("%c\n",65+t);
  exit(0);      
}

Measured memory_bytes: 0
class xyh_list:
    def __init__(self, xyh):
        self.x = xyh[0]
        self.y = xyh[1]
        self.h = xyh[2]

n = int(input())

xyh = []

for i in range(n):
    xyh.append(xyh_list(list(map(int, input().split()))))

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp.h != 0:
                temp = xyhTemp.h + abs(i - xyhTemp.x) + abs(j - xyhTemp.y)

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p.h == 0 and constant - abs(i - p.x) - abs(j - p.y) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)
        


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[3005][3005];
int main(){
	string s,t;
	cin>>s>>t;
	memset(dp,0,sizeof(dp));
	for(int i=0;i<(int)s.length();i++){
		for(int j=0;j<(int)t.length();j++){
			if(s[i]==t[j]){
				dp[i+1][j+1]=dp[i][j]+1;
				}
				else{
					dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
					}
			}
		}
	string res;
	int i=s.length();
	int j=t.length();
	while(i>0&&j>0){
			if(s[i-1]==t[j-1]){
				res+=s[i-1];
				i--;
				j--;
				}
			else if(dp[i-1][j]>dp[i][j-1]){
				i--;
				}
				else{
					j--;
					}

	}
		reverse(begin(res),end(res));
		cout<<res;
	return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if((a+b)%2==0) {
    cout << (a+b)/2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
int a[2005][2005];
int p[2005][2005];
int r[2005][2005];
int d[2005][2005];
int main(){
    scanf("%d%d%d",&n,&m,&q);
    memset(a,-1,sizeof(a));
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            char x;
            scanf(" %c",&x);
            a[i][j] = x == '1';
            if (a[i][j-1] == 1 && a[i][j] == 1){
                r[i][j-1] = 1;
            }
            if (a[i-1][j] == 1 && a[i][j] == 1){
                d[i-1][j] = 1;
            }
            p[i][j] = p[i-1][j] + p[i][j-1] - p[i-1][j-1] + a[i][j];
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            r[i][j] += (r[i-1][j]+r[i][j-1]-r[i-1][j-1]);
            d[i][j] += (d[i-1][j]+d[i][j-1]-d[i-1][j-1]);
        }
    }
    for (int i = 0; i < q; i++){
        int sx,sy,ex,ey;
        scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
        int numblue = p[ex][ey] - p[ex][sy-1] - p[sx-1][ey] + p[sx-1][sy-1];
        int numdown = d[ex-1][ey] - d[ex-1][sy-1] - d[sx-1][ey] + d[sx-1][sy-1];
        int numright = r[ex][ey-1] - r[ex][sy-1] - r[sx-1][ey-1] + r[sx-1][sy-1];
        //printf("%d %d %d\n",numblue,numdown,numright);
        printf("%d\n",numblue-numdown-numright);
    }
}


Measured memory_bytes: 64640
import math 

def is_prime(n):
	if n == 1:
		return False
		
	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False
			
	return True
	
n = int(input())

X = n

for i in range(n,10**6):
	if is_prime(i):
		break
		
print(i)

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

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

  vector<vector<int>> alph(n, vector<int>(26, 0));

  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    for (int j = 0; j < (int)s.size(); j++)
    {
      alph[i][s[j] - 'a']++;
    }
  }

  string ans = "";

  for (int i = 0; i < 26; i++)
  {
    bool doing = true;
    while (doing)
    {
      for (int j = 0; j < n; j++)
      {
        if (alph[j][i] == 0) 
        {
          doing = false;
          break;
        }
        else alph[j][i]--;
      }
      if (doing) ans += i + 'a';
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<math.h>
using namespace std;
 
int main(){
  double a,b,h,m,d;
  cin >> a >> b >> h >> m;
  d=sqrt(a*a+b*b-2*a*b*cos(M_PI*(11*m-60*h)/360));
  printf("%.10lf",d);
}

Measured memory_bytes: 4192
a,s,d=map(int,input().split())
lis=list(map(int,input().split()))
c=0
for i in range(a):
  l=list(map(int,input().split()))    
  sum=d
  for k in range(s):
    sum+=lis[k]*l[k]
  if sum>0:
    c+=1
print(c)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int kR = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		int[] np = new int[n];

		for(int i=0; i<q; i++) {
			int a = Integer.parseInt(sc.next());
			np[a-1]++;
		}

		StringBuilder sb = new StringBuilder();
		for(int j=0; j<n; j++) {
			if(kR - q + np[j] > 0) {
				sb.append("Yes");
			} else {
				sb.append("No");
			}
			if(j < n - 1) {
				sb.append("\n");
			}
		}
		System.out.println(sb);

		sc.close();
	}
}


Measured memory_bytes: 46384
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int t;
    int d;
    
    bool operator<( const Data& right ) const {
        return d > right.d;
    }
};



int main(){
    int N, K;
    vector<Data> v{};
    
    cin >> N >> K;
    for (int i=0;i<N;i++) {
        Data temp;
        cin >> temp.t >> temp.d;
        v.push_back(temp);
    }
    
    sort(v.begin(), v.end());
//    cout << endl;
//    for (int i=0;i<N;i++) cout << v[i].t << " " << v[i].d << endl;
    
    vector<long long> result{};
    
    // まずは上位K個を最初の候補にする。この時species種類のネタがあるとする。
    // 次に、(species+1)種類での最大満足度は、上位K個のうち重複するネタのリストremove_listの最後尾の一つを消去し、
    // 新たなネタの寿司一つを追加することで達成される。
    vector<int> list[100001];
    vector<int> remove_list{};
    long long temp_result = 0;
    int species = 0;
    for (int i=0;i<K;i++) { // v[i]
        temp_result += v[i].d;
        if (list[v[i].t].size()==0) species += 1;
        else remove_list.push_back(v[i].d);
        list[v[i].t].push_back(1);
    }
    result.push_back((long long)species*species+temp_result);
    //cout << species << endl;
    //cout << list[1].size() << endl;
    
    // (species+1)から最大K種類まで行う
    // 追加寿司は探索開始点をループ越しに受け継いでいってよいのでどんどん下にいく。最後まで来たらストップ。
    int start = K;
    for (int i=species+1;i<=K;i++) {
        temp_result -= remove_list[remove_list.size()-1-(i-species-1)];
        while (true) {
            if (list[v[start].t].size()==0) {
                temp_result += v[start].d;
                list[v[start].t].push_back(1);
                break;
            }
            start += 1;
            if (start==N) break;
        }
        start += 1;
        if (start==N+1) break;
        
        result.push_back((long long)i*i+temp_result);
        if (start==N) break;
    }
    
//    cout << endl;
//    for (int i=0;i<result.size();i++) cout << i+species << " " << result[i] << endl;
    cout << *max_element(result.begin(),result.end()) << endl;
    
    return 0;
}


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

using namespace std;

int main() {
	vector<int> furui(250000, 0);
	furui[0] = 1;
	furui[1] = 1;
	for (int i = 2; i * i <= 250000; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j <= 250000/i ; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int a;
	while (cin >> a) {
		if (a == 0) {
			break;
		}
		int counter = 0;
		for (int i = a+1; i <= 2*a; i++) {
			if (furui[i] == 0) {
				counter++;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << 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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  double ans = (double)w * (double)h / (double)2;
  bool z = true;
  if(w/2!=x||h/2!=y){
    z = false;
  }
  cout << fixed << setprecision(3) << ans << " ";
  if(z){
    print(1);
  }
  else{
    print(0);
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128

const int maxn = 3e5;
std::vector<int> G[maxn];
int len = 1;
int d[maxn];
int bfs(int x) {
	queue<int> q;
	q.push(x);
	memset(d, 0, sizeof(d));
	int res = 0;
	d[x] = 1;
	bitset<maxn> vis;
	vis[x] = 1;
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(auto i : G[u]) {
			if(!vis[i]) {
				q.push(i);
				vis[i] = 1;
				d[i] = d[u] + 1;
				if(d[i] > len) {
					res = i;
					len = d[i];
				}
			}
		}
	}
	return res;
}

signed main()
{
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i < n; ++i) {
    	int u, v;
    	cin >> u >> v;
    	G[u].eb(v);
    	G[v].eb(u);
    }
    int x = bfs(1);
    bfs(x);
    bitset<maxn> sg;
    sg[1] = 1;
    for(int i = 3; i <= len; ++i) {
    	sg[i] = !(sg[i - 1] && sg[i - 2]);
    }
    if(sg[len]) {
    	cout << "First" << endl;
    } else {
    	cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 19184
a,b,c=(int(x)for x in input().split())
division =[]
if a>=b:
    x=a
    while x>0:
        if a%x==0 and b%x==0:
            division.append(x)
            x -=1
        else:
            x -=1
else:
    x=b
    while x>0:
        if a%x==0 and b%x==0:
            division.append(x)
            x -=1
        else:
            x -=1

print(division[c-1])



Measured memory_bytes: 3060
class Integer
  def combination(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*) / k.factorial
  end

  def factorial
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end

n = gets.chomp.to_i
s = (1..n).map { gets.chomp.chars.sort.join.intern }
puts s.group_by { |sn| sn }.values.inject(0) { |sum, v| sum + v.count.combination(2) }


Measured memory_bytes: 46716
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}
func mul(a int64, b int64) int64 {
	return (a * b) % mod
}

func power(x int64, y int64) int64 {
	if y == 0 {
		return 1
	} else if y%2 == 0 {
		ans := int64(power(x, y/2)) % mod
		ans = mul(ans, ans)
		return ans
	} else {
		ans := int64(power(x, y/2)) % mod
		ans = mul(mul(ans, ans), x)
		return ans
	}
}

var mod = int64(1000000007)

func comb(n int, k int) int64 {
	x := int64(1)
	y := int64(1)
	for i := 0; i < k; i++ {
		x = mul((int64(n - i)), x)
		y = mul(int64(i+1), y)
	}
	invy := power(y, mod-2)
	return mul(x, invy)
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	var ans int64

	fac := make([]int64, n+2, n+2)
	invfac := make([]int64, n+2, n+2)

	// prepare factrorial
	fac[0] = 1
	invfac[0] = 1
	for i := 1; i <= n+1; i++ {
		fac[i] = (int64(i) * fac[i-1]) % mod
	}
	invfac[n+1] = power(fac[n+1], mod-2)
	for i := n; i > 0; i-- {
		invfac[i] = (invfac[i+1] * int64(i+1)) % mod
	}
	for i := 0; i < n && i <= k; i++ {
		c1 := mul(mul(fac[n], invfac[n-i]), invfac[i])
		c2 := mul(mul(fac[n-1], invfac[n-1-i]), invfac[i])
		ans = (ans + mul(c1, c2)) % mod
	}
	fmt.Println(ans)
}


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

int main() {
int a, b;
while (1) {
cin >> a >> b;
if (a == 0 && b == 0) {
break;
}
if ( a < b) {
cout << a << " " << b << endl;
} else {
cout << b << " " << a << endl;
}
}
return 0;
}


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string toUpper(string s ){
    string t=s;
    for(int i=0;i<s.size();i++){
        t[i]=toupper(s[i]);
    }
    return t;
}
int main(){
    string target,source;
    cin >>target;
    target=toUpper(target);
    int cnt=0;
    while(1){
        cin>>source;
        if(source=="END_OF_TEXT")break;
        source=toUpper(source);
        if(target==source)cnt++;
        
    }
    cout << cnt <<endl;
    
    return 0;
}


Measured memory_bytes: 3172
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i].first.first >> in[i].first.second;
    in[i].second = i;
  }
  auto comp = [] (pair<pair<string, int>, int> x, pair<pair<string, int>, int> y) {
    if (x.first.first != y.first.first) return x.first.first < y.first.first;
    return x.first.second > y.first.second;
  };
  sort(in.begin(), in.end(), comp);
  for (int i = 0; i < n; i++) {
    cout << in[i].second + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

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

    int n;
    long long k;
    cin >> n >> k;

    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            long long t = 0;
            if(A[i] > A[j]){
                t = k * (1 + k) / 2; 
            }else if(A[i] < A[j]){
                t = k * (k - 1) / 2;
            }
            ans = (ans + t) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
string s;
int gx,gy;
int sx,sy;
int x,y;
vector<int> v1,v2;
int n;
bool b[30000];
vector<int> G;
bool calc(vector<int>& v){
	memset(b,0,sizeof(b));
	n/=2;
	b[0]=1;
	rep(i,v.size()){
		int z=v[i];
		for(int j=n;j>=z;j--){
			b[j]|=b[j-z];
		}
	}
	return b[n];
}

int main()
{
	cin>>s>>gx>>gy;
	int id=0;
	bool b=0;
	int cnt=0;
	while(id<s.size()&&s[id]=='F'){
		cnt++;
		id++;
	}
	gx-=cnt;
	while(id<s.size()){
		id++;
		b=!b;
		cnt=0;
		while(id<s.size()&&s[id]=='F'){
			id++;
			cnt++;
		}
		if(cnt){
		 	if(b){
		 		v2.pb(cnt);
		 		sy-=cnt;
		 	}
			else{
				v1.pb(cnt);
				sx-=cnt;
			}
		}
	}
	n=gx-sx;
	if(n<0||n%2||!calc(v1)){
		puts("No");
		return 0;
	}
	n=gy-sy;
	if(n<0||n%2||!calc(v2)){
		puts("No");
		return 0;
	}
	puts("Yes");
}

Measured memory_bytes: 256
//
//  Created by Henry Cafaro
//  Copyright © 2020 Henry Cafaro. All rights reserved.
//

# include <iostream>
# include <string>
# include <vector>
# include <algorithm>
# include <bitset>
# include <queue>
# include <cstring>


#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,k;
    
    cin >> h >> w >>k;
    
    int arr[6][6] = {};
    
    string s;
    for(int i = 0; i < h; i++){
        cin >> s;
        for(int j = 0; j < w; j++){
            if(s[j] == '#'){
                arr[i][j] = 1;
            }
        }
    }
    
    int ct = 0;
    
    for (int i = 0; i < (1<<h); i++){
        for(int j = 0; j < (1<<w); j++){
            int sum = 0;
            for(int x = 0; x < h; x++){
                for(int y = 0; y < w; y++){
                    if(!(i & (1 << x))){
                        if(!(j & (1 << y))){
                            sum += arr[x][y];
                            
                        }
                    }
                }
            }
            if(sum == k) {ct++;}
            
        }
    }
    
    
        
   
    
    cout << ct << endl;
    
    
    
    
    
    
    
    
}


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

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

  vector<pair<long long, int>> dt(N);
  for(int i = 0; i < N; i++){
    int t;
    long long d;
    cin >> t >> d;
    t--;
    dt[i] = make_pair(d, t);
  }
  sort(dt.rbegin(), dt.rend());

  /*
  for(auto x: dt){
    cout << x.second << '\t' << x.first << endl;
  }
  */

  long long d_sum = 0;
  vector<bool> checked(N, false);
  int t_cnt = 0;
  multiset<long long> dups;
  for(int i = 0; i < K; i++){
    d_sum += dt[i].first;
    if(!checked[dt[i].second]){
      t_cnt++;
      checked[dt[i].second] = true;
    }else{
      dups.insert(dt[i].first);
    }
  }

  long long ans = d_sum + t_cnt * t_cnt;
  for(int i = K; i < N; i++){
    //cout << i << endl;
    //cout << dups.size() << endl;
    if(dups.size() == 0){
      break;
    }
    if(!checked[dt[i].second]){
      auto dup_min = dups.begin();
      d_sum -= *dup_min;
      dups.erase(dup_min);
      d_sum += dt[i].first;
      t_cnt++;
      checked[dt[i].second] = true;
      ans = max(ans, d_sum + t_cnt * t_cnt);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 4224
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn usize() -> usize {
    read()
}

fn vec_usize(n: usize) -> Vec<usize> {
    let mut vec = Vec::new();
    for _ in 0..n {
        vec.push(usize())
    }
    vec
}

fn main() {
    let mut result = 0;

    let n = usize();
    let fs = vec_usize(n);

    let sum: usize = fs.clone().into_iter().sum();
    let avg = sum as f64 / fs.len() as f64;
    let mut min = n as f64;
    for i in 0..n - 1 {
        let rem = (fs[i] as f64 - avg).abs();
        if rem < min {
            result = i;
            min = rem;
        }
    }

    println!("{}", result);
}


Measured memory_bytes: 2108
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],b[maxn],n;
using namespace std;
int main(){
	int i,l,r;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+1+n),sort(b+1,b+1+n);
	if(n%2)l=a[(n+1)/2],r=b[(n+1)/2];
	else l=a[n/2]+a[n/2+1],r=b[n/2]+b[n/2+1];
	printf("%d\n",r-l+1);
	return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.length(), a = n/2;
  bool b = true;
  for (int i = 0; i < a; ++i){
	  if (s[i] != s[n-1-i]) b = false;
  }
  for (int i = 0;  i < a/2; ++i){
	if (s[i] != s[a - 1 - i]) b = false;
	if (s[a +1 + i] != s[n-1-i]) b = false;
  }
  (b) ? cout << "Yes\n" : cout << "No\n";
return 0;
}


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

int main()
{
    string s; cin >> s;
    int ans = 0;
    int cnt = 0;
    rep(i,3){
        if(s[i] == 'R') {
            cnt++;
            ans = max(cnt, ans);
        }else{
            cnt=0;
        }
    }
    cout << ans << endl;

}
/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 3620
#template
def inputlist(): return [int(j) for j in input().split()]
def listinput(): return input().split()
#template
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)
N,K = inputlist()
print(len(base10to(N,K)))

Measured memory_bytes: 9112
import java.util.Scanner;

public class Main{
	public static int count=0;
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,n,m=0;
        n=scan.nextInt();
        int arr[]=new int[n];
        int g[]=new int[n+1];
        for(i=0;i<n;i++) {
            arr[i]=scan.nextInt();
        }
        while(true) {
            m++;
            g[m]=(int)(Math.pow(3,m)-1)/2;
            if((Math.pow(3,m+1)-1)/2>n)break;
        }
        System.out.println(m);
        for(i=m;i>0;i--) {
        	if(i>1) {
        		System.out.print(g[i]+" ");
        	}
        	else {
        		System.out.println(g[i]);
        	}
        	arr=insert(arr,n,g[i]);
        }
        System.out.println(count);
        show(arr,n);
        scan.close();
    }
	static int[] insert(int A[],int N,int g) {
		int i,j,v;
		for(i=1;i<N;i++){
            v=A[i];
            j=i-g;
            while(j>=0 && A[j]>v ){
                A[j+g]=A[j];
                j-=g;
                count++;
                A[j+g]=v;
            }
        }
		return A;
	}
	static void show(int A[],int n) {
		int i;
		for(i=0;i<n;i++) {
        	System.out.println(A[i]);
        }
	}
}


Measured memory_bytes: 303168
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    string s,t;
    cin>>s>>t;
    int n=s.size();
    bool f =true;
    rep(i,n) {
        if(!(s[i]==t[i])) {
            cout <<"No"<<endl;
            f =false;
            break;
        }
    }
    if(f) {
        cout <<"Yes"<<endl;
    }
}

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

int main() {
  int n;
  cin>>n;
  int h[n];
  for (int i=0; i<n; i++) cin>>h[i];
  int v = h[0] - 1;
  for (int i=1; i<n; i++) {
    if (h[i] < v) {
      cout<<"No"<<endl;
      return 0;
    } else if (h[i] == v) {
      continue;
    } else {
      v = h[i] - 1;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  REP(i, n)
  {
    int a;
    cin >> a;
    q.push(a);
  }
  REP(i, m)
  {
    int a = q.top();
    q.pop();
    q.push(a / 2);
  }
  ll anser = 0;
  REP(i, n)
  {
    anser += q.top();
    q.pop();
  }
  cout << anser << endl;
  return 0;
}

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

using static Input;
using static Util;
class Program
{
    static int N;
    static int X;
    static int Y;
    static void INPUT()
    {
        N = NextInt();
        X = NextInt();
        Y = NextInt();
    }

    static void OUT()
    {
        var a = new int[N];
        for (var i = 1; i <= N; i++)
        {
            for (var j = i + 1; j <= N; j++)
            {
                var min = Math.Min(Math.Abs(j - i), Math.Abs(i - X) + 1 + Math.Abs(j - Y));
                a[min]++;
            }
        }

        Console.WriteLine(string.Join("\n", a.Skip(1)));
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
    speed_up
    ll a,b,t;cin>>a>>b>>t;
    ll ans=t/a;ans*=b;
    cout<<ans;
    
     
	
	
	
	
	
	
 return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
#include <queue>
#include <bitset>
#include <numeric>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;



bool IsPrime(int num)
{
    if (num < 2)           return false;
    else if (num == 2)     return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    int X;

    //入力
    cin >> X;
    int i=X;
    while(!IsPrime(i)) i++;
    cout << i << endl;
    

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
X = sorted((S[:i] + T + S[i + len(T):]).replace('?', 'a')
           for i in range(len(S) - len(T) + 1)
           if all(s == '?' or s == t for s, t in zip(S[i:i + len(T)], T)))
print(X[0] if len(X) > 0 else 'UNRESTORABLE')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(b-a<=0){
    cout << "delicious" << endl;
  }
  else if(b-a>0&&b-a<=x){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}
  

Measured memory_bytes: 3592
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
//#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    int x=0,y=0;
    int a[n]={0},b[n]={0};
    for(int i=0;i<m;i++){
        int z;
        string s;
        cin>>z>>s;
        if(s=="AC"){
            a[z-1]++;
        }
        else{
            if(a[z-1]==0)b[z-1]++;
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]!=0){x++;y+=b[i];}
    }
    cout<<x<<" "<<y;
    return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int INF = 1e9;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, a, b, c;
	scanf("%d%d%d%d", &n, &a, &b, &c);
	vi l(n);
	for (int i = 0; i < n; i++) scanf("%d", &l[i]);

	int answer = INF;
	vi p(n);
	for (int i = 0; i < n; i++) p[i] = i;
	do {
		for (int i = 0; i < n; i++) {
			int costa = 0;
			for (int x = 0; x <= i; x++) costa += l[p[x]];
			costa = abs(costa - a) + i * 10;
			for (int j = i+1; j < n; j++) {
				int costb = 0;
				for (int x = i+1; x <= j; x++) costb += l[p[x]];
				costb = abs(costb - b) + (j - i - 1) * 10;
				for (int k = j+1; k < n; k++) {
					int costc = 0;
					for (int x = j+1; x <= k; x++) costc += l[p[x]];
					costc = abs(costc - c) + (k - j - 1) * 10;
					answer = min(answer, costa + costb + costc);
				}
			}
		}
	} while (next_permutation(all(p)));
	printf("%d\n", answer);
}


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

using namespace std;
using ll = long long;

int const N = 200 * 1000 + 16;

int a[N];
int n, k;

struct node {
  ll x;
  int s = 1;
  int y = rand();

  node* l = 0;
  node* r = 0;

  node(ll v) {
    x = v;
  }

  ~node() {
    delete l;
    delete r;
  }

  node* upd() {
    s = 1;
    s += l ? l->s : 0;
    s += r ? r->s : 0;
    return this;
  }
};

struct treap {
  node* root = 0;

  ~treap() {
    delete root;
  }

  node* join(node* l, node* r) {
    if(not l) return r;
    if(not r) return l;

    if(l->y < r->y) {
      l->r = join(l->r, r);
      return l->upd();
    } else {
      r->l = join(l, r->l);
      return r->upd();
    }
  }

  pair<node*,node*> split(node* p, ll x) {
    if(not p) return make_pair(nullptr,nullptr);

    if(x < p->x) {
      auto t = split(p->l, x);
      p->l = t.second;
      t.second = p->upd();
      return t;
    } else {
      auto t = split(p->r, x);
      p->r = t.first;
      t.first = p->upd();
      return t;
    }
  }

  void insert(ll x) {
    auto t = split(root, x);
    root = join(t.first, join(new node(x), t.second));
  }

  int query(ll x) {
    auto t = split(root, x);
    int cnt = t.first ? t.first->s : 0;
    root = join(t.first, t.second);
    return cnt;
  }
};

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n >> k;
  copy_n(istream_iterator<int>(cin), n, a);

  treap t;
  t.insert(0);
  ll ans = 0;
  ll sum = 0;
  for(int i = 0; i < n; ++i) {
    sum += a[i];
    ll v = sum - 1ll * i * k - k;
    ans += t.query(v);
    t.insert(sum - 1ll * (i+1) * k);
  }

  cout << ans << endl;
}

Measured memory_bytes: 10368
import numpy as np

N = int(input())

def solve(n):
    ans = []
    tmp = n
    for i in range(2, int(np.sqrt(n))+1):
        if tmp%i == 0:
            cnt = 0
            while tmp%i==0:
                cnt += 1
                tmp //= i
            ans.append(cnt)
    if tmp != 1:
        ans.append(1)
    return ans

a = solve(N)

def z_num(k):
    tmp = 1
    d = 2
    while True:
        if tmp <= k and tmp+d > k:
            return d-1
        tmp += d
        d += 1
    
b = list(map(z_num, a))
b = np.array(b)

ans = int(b.sum())

print(ans)

Measured memory_bytes: 27248
N, M = map(int, input().split())
WA = [0] * N
AC = [0] * N
for i in range(M):
    p,s = input().split()
    p = int(p)
    if AC[p-1] == 0:
        if s == "AC":
            AC[p-1] = 1
        else:
            WA[p-1] += 1
wa = 0
for j in range(N):
    if AC[j] == 1:
        wa += WA[j]
print(sum(AC),wa)

Measured memory_bytes: 4596
String = input()
sbstr_list = ['R' + substr + 'L' for substr in String.split('LR')]
sbstr_list[0] = sbstr_list[0][1:]
sbstr_list[-1] = sbstr_list[-1][:-1]
for sbstr in sbstr_list:
    length = len(sbstr)
    subans = ["0"] * length
    pos = sbstr.find('RL')
    # print(pos)
    subans[pos] = str(1 + pos//2 + (length-pos-1)//2)
    subans[pos+1] = str(1 + (pos+1)//2 + (length-pos-2)//2)
    print(" ".join(subans), end=' ')
print('')


Measured memory_bytes: 48220
n, *h = map(int, open(0).read().split())
dp = [1e10] * n
dp[0] = 0
for i in range(n):
    if i+1 < n:
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
    if i+2 < n:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2]))
print(dp[n-1])

Measured memory_bytes: 20340
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = 1<<30;

struct edge{int to, cost;};

int ans[100010];
int used[100010] = {0};
int n;
vector<edge> G[100010];

void DFS(int node, int color){
	ans[node] = color;
	used[node] = 1;
	for (int i = 0; i < G[node].size(); i++) {
		int to = G[node][i].to, cost = G[node][i].cost;
		if(used[to])continue;
		DFS(to, color ^ cost);
	}
	return;
}

int main(){
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--;v--;w %= 2;
		G[u].push_back({v,w});
		G[v].push_back({u,w});
	}
	DFS(0, 0);
	rep(i,n) cout << ans[i] << endl;
	return 0;
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  n = min( n%k,n );
  while(true){
    ll pre = n;
    n = min(abs(n-k),n);
    if( pre == n ) break;
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int length;
    string String;

    cin >> length;
    cin >> String;

    if(String.length() == length)
        if(length % 2 != 0)
            cout << "No" << endl;
        else if(String.substr(0,length/2) == String.substr(length/2,length/2))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256