akhauriyash/Code-Regression huggingface dataset:
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  string t,p;
  cin>>t>>p;
  int m[600005]={};
  int p1=0;
  for(int i=0;i<t.size();i++){
    if(t[i]==p[p1]){
      m[i]++;
      p1++;
      if(p1==p.size())break;
    }
  }
  if(p1!=p.size()){
    cout<<"no"<<endl;
    return 0;
  }
  int p2=p.size()-1;
  for(int i=t.size()-1;i>=0;i--){
    if(t[i]==p[p2]){
      m[i]++;
      p2--;
      if(p2==-1)break;
    }
  }

bool f=true;
for(int i=0;i<t.size();i++){
  if(m[i]==1){
    f=false;
    break;
  }
 }
cout<<(f?"yes":"no")<<endl;
return 0;
}

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

b = list(map(int,input().split()))

l = []
cnt =0
a=0
for i in range(n):
	l.append(list(map(int,input().split())))
  
for i in range(n):
	for j in range(m):
		a += b[j]*l[i][j]
	a += c
	if a > 0:
		cnt += 1
	a =0	
print(cnt)

Measured memory_bytes: 3064
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        double[] n = io.r<double>(' ');

        io.w(n[0] * n[1] * Math.Sin(n[2] * 2 * Math.PI / 360) / 2);
        io.w(n[0] + n[1] + Math.Sqrt(Math.Pow(n[0], 2) + Math.Pow(n[1], 2) - 2 * n[0] * n[1] * Math.Cos(n[2] * 2 * Math.PI / 360)));
        io.w(n[1] * Math.Sin(n[2] * 2 * Math.PI / 360));
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 9948
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,t,a,cnt=0,ans=-1;
int head[200005],td[200005],ad[200005];

struct edge
{
	int next;
	int to;
}e[200005];

inline void add_edge(int u,int v)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}

inline void dfst(int now,int fath)
{
	td[now]=td[fath]+1;
	for (int i=head[now];i;i=e[i].next)
	{
		if (e[i].to!=fath)  dfst(e[i].to,now);
	}
}

inline void dfsa(int now,int fath)
{
	ad[now]=ad[fath]+1;
	for (int i=head[now];i;i=e[i].next)
	{
		if (e[i].to!=fath)  dfsa(e[i].to,now);
	}
}

signed main()
{
	cin>>n>>t>>a;
	for (int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
		add_edge(v,u);
	}
	dfst(t,0);
	dfsa(a,0);
	
	for (int i=1;i<=n;i++)
	{
		td[i]--;
		ad[i]--;
	}
	for (int i=1;i<=n;i++)
	{
		if (td[i]<ad[i])  ans=max(ans,ad[i]-1);
	}
	cout<<ans<<endl;
	
	return 0; 
}

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


int main(){
	int a,b;
	cin >> a >> b;
	if(a>=13){
		cout << b << endl;
	}
	else if(a>=6){
		cout << b/2 << endl;
	}
	else{
		cout << 0 << endl;
	}
	
	return 0;
}

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

int input(int *x,int *h);
int main()
{
	int x,h;
	double l,s;
	while(input(&x,&h)==0)
	{
		l=sqrt((double)x*x/4+h*h);
		s=l*x*2+x*x;
		printf("%lf\n",s);
	}
	return 0;
}

int input(int *x,int *h)
{
	scanf("%d",x);
	scanf("%d",h);
	if(*x==0&&*h==0){return 1;}
	else{return 0;}
}

Measured memory_bytes: 0
import sys
from collections import defaultdict
from heapq import heappush, heappop, heapify
input = sys.stdin.readline

INF = 10**19
n, m, s = map(int, input().split())
edges = defaultdict(lambda: defaultdict(lambda: [INF, INF]))
cd = []
max_a = 0

for i in range(m):
    u, v, a, b = map(int, input().split())
    max_a = max(max_a, a)
    edges[u-1][v-1] = [a, b]
    edges[v-1][u-1] = [a, b]

for i in range(n):
    c, d = map(int, input().split())
    cd.append([c, d])

# 解答ACする
# Dijakstraの状態を(頂点、所持している銀貨の枚数, cost)で持つ
SIZE = max_a * n + 1
# SIZE = 2550
if s > SIZE:
    s = SIZE
nodes = [[INF for _ in range(SIZE+1)] for _ in range(n)]
nodes[0][s] = 0

def dijakstra():
    goals = set({0})
    que = [(0, 0, s)]
    heapify(que)
    while 10**6 > len(que) > 0:
        if len(goals) >= n:
            break
        cost, num, silver = heappop(que)
        if num not in goals:
            goals.add(num)
        c, d = cd[num]
        s_tmp = min(SIZE, silver+c)
        if silver < SIZE and s_tmp != silver:
            if nodes[num][s_tmp] > cost + d:
                heappush(que, (cost + d, num, s_tmp))
                nodes[num][s_tmp] = min(nodes[num][s_tmp], cost + d)
        for v in edges[num].keys():
            a, b = edges[num][v]
            if silver >= a:
                if nodes[v][silver-a] > cost + b:
                    heappush(que, (cost + b, v, silver - a))
                    nodes[v][silver - a] = min(nodes[v][silver - a], cost + b)

dijakstra()
for i in range(1, n):
    print(min(nodes[i]))

Measured memory_bytes: 96144
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
h = list(map(int, input().split()))

ans = 0
def rec(s): #str, 
    # print("s: ", s)
    global ans
    if len(s) == 0:
        return 
    elif len(s) == 1:
        ans += s[0]
        return 
    elif len(s) == 2:

        ans += max(s)
        return 

    min_ = min(s)
    l_idx = []
    for e,i in enumerate(s):
        if i == min_ : # and  (e != 0 and e!= (len(s)-1)) :
            l_idx.append(e)
        s[e] -= min_

    # print("\t after s:", s)
    # print("\t l_idx s:", l_idx)

    ans += min_

    pre_pos = 0

    for e,l in enumerate(l_idx):
        # print("\tpre_pos:i=> {}:{}".format(pre_pos, l))
        rec(s[pre_pos:l])

        pre_pos = l+1
    if l_idx[-1] != len(s)-1:
        # print("LAST ON: l_idx[-1]:last: ", l_idx[-1]+1, "list: ", s[l_idx[-1]+1:])
        # return 

                
        rec(s[l_idx[-1]+1:])
   

rec(h)
print(ans)


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

template <typename Tp, size_t Nb>
auto make_vector(std::vector<size_t> &sizes, Tp const &x) {
    if constexpr (Nb == 1) {
        return std::vector<Tp>(sizes[0], x);
    } else {
        size_t size = sizes[Nb - 1];
        sizes.pop_back();
        return std::vector(size, make_vector<Tp, Nb - 1>(sizes, x));
    }
}

template <typename Tp, size_t Nb>
auto make_vector(size_t const (&sizes)[Nb], Tp const &x = Tp()) {
    std::vector<size_t> s(Nb);
    for (size_t i = 0; i < Nb; ++i)
        s[i] = sizes[Nb - i - 1];
    return make_vector<Tp, Nb>(s, x);
}

using p = pair<ll, ll>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, t;
    cin >> n >> t;
    vector<p> v(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        v[i] = p(a, b);
    }
    sort(v.begin(), v.end(), [&](const p &a, const p &b) {
        if (a.first == b.first) {
            return a.second > b.second;
        }
        return a.first < b.first;
    });

    auto dp = make_vector({(size_t)n - 1, (size_t)t}, 0LL);
    ll ans = v[0].second;

    rep(j, t) {
        ll time = v[0].first, value = v[0].second;
        if (j >= time) {
            dp[0][j] = value;
        }
        ans = max(ans, dp[0][t - 1] + v[0 + 1].second);
    }

    repd(i, 1, n - 1) {
        ll time = v[i].first, value = v[i].second;
        rep(j, t) {
            if (j - time < 0) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - time] + value);
            }
        }
        ans = max(ans, dp[i][t - 1] + v[i + 1].second);
    }

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



Measured memory_bytes: 73668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
int n;
char str[500009];
struct Binary_Indexed_Trees
{
    int c[500009];
    void add(int x,int y)
    {
        for(;x<=n;x+=x&-x)c[x]+=y;
    }
    int ask(int x)
    {
        int ans=0;
        for(;x;x-=x&-x)ans+=c[x];
        return ans;
    }
}ss[26];
int main()
{
    scanf("%d%s",&n,str+1);
    for(int i=1;i<=n;i++){
        ss[str[i]-'a'].add(i,1);
    }
    int q;scanf("%d",&q);
    while(q--)
    {
        int d;scanf("%d",&d);
        if(d==1){
            int pos;char sss[3];scanf("%d%s",&pos,sss+1);
            ss[str[pos]-'a'].add(pos,-1);
            ss[sss[1]-'a'].add(pos,1);
            str[pos]=sss[1];
        }
        else{
            int ans=0;int l,r;scanf("%d%d",&l,&r);
            for(int i=0;i<26;i++){
                if(ss[i].ask(r)-ss[i].ask(l-1))ans++;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 51584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n;
  cin >> N;
  int sum=0;
  
  n = N;
  
  while(N){
    sum += N % 10;
    N /= 10;
  }
  
  if(n % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String [] inp = buffer.readLine().split(" ");
        int n = Integer.parseInt(inp[0]), maxDis = Integer.parseInt(inp[1]);
        int cnt = 0;
        for (int pos = 0; pos < n; pos++) {
            inp = buffer.readLine().split(" ");
            long x = Integer.parseInt(inp[0]), y = Integer.parseInt(inp[1]);
//            if (x*x+y*y<0)continue;
            double value = Math.sqrt((x*x)+(y*y));
            if (value<=maxDis) {
                cnt++;
            }
        }
        sb.append(cnt+"\n");
        System.out.println(sb);
    }
}


Measured memory_bytes: 56248
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	long N, K;
	long min;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Long.parseLong(tokens[0]);
		K = Long.parseLong(tokens[1]);
	}

	void calc() {
		min = N;
		min = Math.min(min, N % K);
		min = Math.min(min, K - N % K);

	}

	void showResult() {
		System.out.println(min);
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    LL a[n];
    loop(i,0,n) cin>>a[i];

    LL sum[n];
    loop(i,0,n)
    {
        if(i) sum[i] = sum[i-1] + a[i];
        else sum[i] = a[i];
    }

    LL ans = 0, ans1;
    loop(i,0,n)
    {
        ans1 = (sum[n-1] - sum[i]) % MOD;
        ans1 = (a[i] * ans1) % MOD;
        ans = (ans + ans1) % MOD;
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 6744
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
 
import math
def ok(x):
    t = 0
    for i in range(n):
        r = h[i] - b*x
        if r < 0:
            continue
        else:
            t += math.ceil(r/(a-b))
    if t <= x:
        return True
    else:
        return False
 
l = 0
r = 10**14+1
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Measured memory_bytes: 52460
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int ll;
ll n,m,k,l;
bool cmp(const pair<ll,ll> l,const pair<ll,ll> k){
  return l.second<k.second;
}
ll mlower_b(vector<pair<ll,ll>>& vec, ll val) {
  ll l=0;
  ll h=vec.size();
  while (l<h) {
    ll mid=l+(h-l)/2;
    ll midval=vec[mid].first;
    if (midval<val) l=mid+1;
    else h=mid;
  }
  return l;
}
int main(){
  cin >> n>>m;
  vector <pair<ll,ll>> v[n];
  ll y[m],p[m];
  for(ll i=0;i<m;i++){
    cin >> p[i]>>y[i];
    v[p[i]-1].push_back(make_pair(y[i],i));
  }
  for(ll i=0;i<n;i++){
    sort(v[i].begin(),v[i].end());
  }
  for(ll i=0;i<m;i++){
    ll j=mlower_b(v[p[i]-1],y[i]);
      printf("%06lld",p[i]);
      printf("%06lld\n",j+1);
    }
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n, m, q; cin >> n >> m >> q;
    vector<VL> imos(n, VL(n, 0));
    FOR(i, 0, m) {
        int l, r; cin >> l >> r;
        l--, r--;
        imos[l][r]++;
    }

    FOR(i, 0, n)FOR(j, 0, n - 1)imos[i][j + 1] += imos[i][j];
    FOR(i, 0, n - 1)FOR(j, 0, n)imos[i + 1][j] += imos[i][j];

    FOR(i, 0, q) {
        int l, r; cin >> l >> r;
        l--, r--;
        ll ans = imos[r][r];

        if (0 < l) {
            ans += imos[l - 1][l - 1];
            ans -= imos[l - 1][r];
            ans -= imos[r][l - 1];
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 2944
#include<stdio.h>
  
#define MAX 500000
  
int Tree[MAX];  
int n;
  
void maxHeapify(int i){
  int largest ,exchange, l, r;
  l = getLeft(i);
  r = getRight(i);
    
  if((n+1 >l) && (Tree[l] > Tree[i])) largest = l;
  
  else largest = i;
    
  if((n+1 > r) && (Tree[r] > Tree[largest])) largest = r;
  
  if (largest != i){
  
    exchange = Tree[i];
    Tree[i] = Tree[largest];
    Tree[largest] = exchange;
    maxHeapify(largest);
  
  } 
}
  
void buildMaxHeap(){
  int i;
  for (i=(n/2); i+1>1; i--){
    maxHeapify(i);
     }
}
   
int getLeft(int i){
  return (2*i);
}
  
int getRight(int i){
  return (2*i + 1);
}
int getParent(int i){
  return i/2;
}
 
  
main()
{
  int i;
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
  
    scanf("%d",&Tree[i]);
  
  }
  
  buildMaxHeap();
  
  for(i=1; i<=n; i++){
      
    printf(" %d",Tree[i]);
  
  }
  
  printf("\n");
  
  return 0;
}

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

int n, m;
bool search(int* bit, int p, int x, int &ans){
  for (int i = p; i < n; i++) {
    if(bit[i] == x){
      ans += i - p;
      bit[i] = (x+1)&1;
      bit[p] = x&1;
      return true;
    }
  }
  return false;
}

int main(int argc, char *argv[]){
  cin >> n >> m;
  int bit[n], len[m], bcopy[n];
  for (int i = 0; i < n; i++) {
    cin >> bit[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> len[i];
  }
  //1 0??????
  int x, ans[2] = {0}, tmp;
  for (int k = 0; k < 2; k++) {
    tmp = 0;
    x = k;
    for (int i = 0; i < n; i++) {
      bcopy[i] = bit[i];
    }
    for (int i = 0; i < m; i++) {
      x = (x+1)&1;
      for (int j = 0; j < len[i]; j++) {
        if(bcopy[j + tmp] != x){
          if(!search(bcopy, j + tmp, x, ans[k]))
            ans[k] = 1e9;
        }
      }
      tmp += len[i];
    }
  }
  std::cout << min(ans[0], ans[1]) << std::endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf();

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i+=2) {
    int cou = 0;
        for (int j = 1; j <= N; j++) {
            if (i%j == 0) {
                cou++;
            }
        }
        if (cou == 8) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
#include <functional>
#include <iomanip>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }



int main(int argc, char* argv[])
{
	cout << std::fixed << std::setprecision(10);

	for (;;) {
		int N, M;

		cin >> N >> M;
		if (cin.fail()) break;

		bitset<100001> b;
		vector<int> v(N + 1, 1);
		b.set(1);
		for (int i = 0; i < M; i++) {
			int x, y;
			cin >> x >> y;
			if (b[x]) {
				b.set(y);
			}
			if (--v[x] == 0) {
				b.set(x, false);
			}
			v[y]++;
		}
		int result = 0;
		for (int i = 1; i <= N; i++) {
			if (b[i] && v[i] > 0) result++;
		}

		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int s; cin >> s;
  set<int> se{s};
  for (int i = 2; ; ++i) {
    if (s & 1) {
      s = 3 * s + 1;
    } else {
      s /= 2;
    }
    if (se.count(s)) {
      return cout << i << '\n', 0;
    }
    se.insert(s);
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100000
 
int main(){
  int n, q, time[N], head = 0, tail = 0, t_sum = 0, i;
  char name[N][11];
   
  scanf("%d%d" ,&n ,&q);
  for(i = 0; i < n; i++){
    scanf("%s%d", name[i], &time[i]);
    tail += 1;
  }
   
  if(tail == 1){
    printf("%s %d\n", name[head], time[head]);
    return 0;
  }
 
  while(head != tail){
    if(time[head] > q){
      t_sum += q;
      time[head] -= q;
      strcpy(name[tail], name[head]);
      time[tail] = time[head];
      tail += 1;
      if(tail >= N) tail = 0;
    }
    else{
      t_sum += time[head];
      printf("%s %d\n", name[head], t_sum);
    }
    head += 1;
    if(head >= N) head = 0;
  }
  return 0;
}

Measured memory_bytes: 2076
#include<string.h>

#include<iostream>

using namespace std;

int main() 

{

 char a[100010];

 long int n;

	cin >> n;

	cin >> a;

	for (int i = 0; i <n; i++)

	{

		if (a[i] == '\0')

			break;

		cout << a[i];

	}

	if (strlen(a) > n)

	{

		cout << "..." << endl;

	}

}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

char S[1000010], T[1000010];
int N;
void solve(){
	scanf("%d%s%s", &N, S+1, T+1);
	if(!strcmp(S+1, T+1)){
		printf("0");
		return;
	}
	int que[1000010], *fr = que, *re = que, ans = 0;
	for(int i=N, j=N;i>=1;i--)if(T[i] != T[i-1]){
		j = min(i, j);
		while(j > 0 && S[j] != T[i])--j;
		if(j == 0){
			printf("-1");
			return;
		}
		while(re < fr && *re - (fr-re) >= i)re++;
		if(i != j){
			*fr++ = j;
			ans = max(ans, (int)(fr - re));
		}
	}
	printf("%d", ans + 1);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 6144
<?php
fscanf(STDIN, "%d %d %d %d", $A, $B, $H, $M);

$minutes = $H * 60 + $M;

$A_degree = (pi() * $minutes / 360);
$B_degree = (pi() * $minutes / 30);

$c_degree = $B_degree - $A_degree;

$C = sqrt($A * $A + $B * $B - 2 * $A * $B * cos($c_degree));
echo $C, "\n";


Measured memory_bytes: 16612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
 
 
int main(){
    string S; cin >> S;
    string T = "";
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'T'){
            if(T.size() > 0 && T[T.size()-1] == 'S') T.erase(T.end()-1);
            else T.insert(T.end(), S[i]);
        }
        else T.insert(T.end(), S[i]);
    } 
    cout << T.size() << endl;


}

Measured memory_bytes: 776
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

const int INF = 1e9;

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

	int maxi = -INF, mini = INF;
	ll sum = 0;
	rep(i,0,n) {
		maxi = max(maxi, a[i]);			
		mini = min(mini, a[i]);
		sum += a[i];
	}

	cout << mini << " " << maxi << " " << sum << endl;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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;}

ll dist[210][210];

int main() {
  int n; cin >> n;
  int p[n],q[n];
  FOR(i,0,n-1) cin >> p[i];
  FOR(i,0,n-1) cin >> q[i];


  int snuke[n];
  FOR(i,0,n-1) snuke[i] = i+1;

  int ansa,ansb;
  int ref = 0;

  do{
    ++ref;
    // cout << snuke[0] << snuke[1] << snuke[2] << " ";
    // cout << p[0] << p[1] << p[2] << endl;
    
    bool allp,allq;
    allp = true; allq = true;
    FOR(i,0,n-1){
      if(snuke[i]!=p[i]) allp = false;
      if(snuke[i]!=q[i]) allq = false;
    }
    if(allp) ansa = ref;
    if(allq) ansb = ref; 

  } while (next_permutation(snuke,snuke+n));

  // cout << ansa << " " << ansb << endl;

  cout << abs(ansa-ansb) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x,a;
    cin>>x>>a;
    if(x<a)cout<<0;
    else
    cout<<10<<endl;
    return 0;
}

Measured memory_bytes: 384
x0, y0, x1, y1 = gets.chomp.split.map(&:to_f)
len1 = (x1 - x0) ** 2 + (y1 - y0) ** 2

gets.to_i.times{
    x2, y2 = gets.chomp.split.map(&:to_f)
    len2 = (x2 - x0) ** 2 + (y2 - y0) ** 2
    yonline = Rational((y1 - y0) * (x2 - x0) + (x1 - x0) * y0, x1 - x0) if x0 != x1

    arr = []
    if x0 < x1
        arr = [yonline, Rational(y2, 1), (x1 - x0) * (x2 - x0)]
    elsif x0 > x1
        arr = [Rational(y2, 1), yonline, (x1 - x0) * (x2 - x0)]
    else
        if y0 < y1
            arr = [x2, x0, (y1 - y0) * (y2 - y0)]
        else
            arr = [x0, x2, (y1 - y0) * (y2 - y0)]
        end
    end
    judge = ""
    if arr[0] < arr[1]
        judge = "COUNTER_CLOCKWISE"
    elsif arr[0] > arr[1]
        judge = "CLOCKWISE"
    else
        if arr[2] < 0
            judge = "ONLINE_BACK"
        else
            if len1 < len2
                judge = "ONLINE_FRONT"
            else
                judge = "ON_SEGMENT"
            end
        end
    end
    puts judge
}



Measured memory_bytes: 8976
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  vector<int> v(3); cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(), v.end());
  int cnt = 2 * v[2] - v[0] - v[1];
  if (cnt % 2 == 0) cout << cnt/2 << endl;
  else              cout << (cnt + 3)/2 << endl;
}


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

b = sorted(a, reverse=True)


ans=1

if min(b) == 0:
    print(0)
    exit(0)

for i in range(n):
    ans *= b[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)



print(ans)

Measured memory_bytes: 21660
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

long long num(long long n) {
	return pow(2, n + 2) - 3;
}

long long fff(long long n) {
	return pow(2, n+1) - 1;
}

long long uno(long long n, long long x) {
	if (n == 0)return 1;
	if (x == 1)return 0;
	if (x <= num(n - 1) + 1)return uno(n - 1, x - 1);
	if (x == num(n - 1) + 2)return fff(n - 1) + 1;
	if (x == num(n))return fff(n);
	return fff(n - 1) + uno(n - 1, x - num(n - 1) - 2)+1;
}


int main()
{
	long long n, x;
	cin >> n >> x;
	cout << uno(n, x)<<endl;
	
    return 0;

	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define SORT(x) (sort(x.begin(),x.end()))
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    int N,M,C;cin>>N>>M>>C;
    int B[27],A[27][27],T,y;
    y=0;
    rep(i,M){
        cin >> B[i];
    }
    rep(i,N){
        T=0;
        rep(j,M){
            cin >> A[i][j];
            T+=A[i][j]*B[j];
        }
        if(T+C>0){
            y++;
        }
    }
    cout << y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long llong;

int N, A, B, C, D, ans;
char s[10000][15];
bool flag = false, flagb = false;

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		flag = false;
		flagb = false;
		for (int j = 0;; j++)
		{
			if (j == 0 && s[i][j] == 'B')
			{
				A++;
				flagb = true;
			}
			if (flag && s[i][j] == 'B')
			{
				C++; flag = false;
			}
			else if (flag && s[i][j] == '\0')
			{
				B++; 
				if (flagb) D++;
				break;
			}
			flag = false;
			if (s[i][j] == 'A') flag = true;
			
			if (s[i][j] == '\0') break;
		}
		
	}

	
	if (A == B && A == D && A != 0)
		ans= C + A - 1;
	else
		ans = C + min(A, B);
		
	if (ans <= -1) cout << 0;
	else cout << ans;

	return 0;
}

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

int like[100005];

bool is_prime(int n){
    for(int i = 2; i*i <= n ; i++){
        if(n%i == 0)return false;
    }
    return n != 1;
}

void init() {
  for(int i = 1;i < 100001; i++) {
    like[0] = 0;
    if ((i & 1) && is_prime(i) && is_prime((i+1)/2)) like[i] = like[i-1] + 1; 
    else like[i] = like[i-1];
  }
}

int main(){
  init();
  int Q;
  cin >> Q;

  rep(i,Q) {
    int l,r;
    cin >> l >> r;
    cout << like[r] - like[l-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int N;


int main()
{

    cin >> N;

    if (N%10 == 2 || N%10 == 4 || N%10 == 5 || N%10 == 7 || N%10 == 9)
    {
        cout << "hon";
    }
    else if (N%10 == 0 ||N%10 == 1 || N%10 == 6 || N%10 == 8  )
    {
        cout << "pon";
    }
    else if (N%10 == 3)
        cout << "bon";

    return 0;
}

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

#define MD 1000000007

int dp[2097157], P[25];
int N, A[25][25];
int U[25], n, h;

int solve()
{
    if (dp[h] != -1) return(dp[h]);
    int c = N - n;
    if (c == N)
    {
        dp[h] = 1;
        return(1);
    }
    int res = 0;
    n--;
    for (int i = 0; i <= n; i++) if (A[c][U[i]])
    {
        h -= P[U[i]];
        if (i < n)
        {
            int tmp = U[i];
            U[i] = U[n];
            res = (res + solve()) % MD;
            U[i] = tmp;
        }
        else res = (res + solve()) % MD;
        h += P[U[i]];
    }
    n++;
    dp[h] = res;
    return(res);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for (int i = 0; i < N; i++) P[i] = 1 << i;
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> A[i][j];
    for (int i = 0; i < N; i++) U[i] = i;
    n = N;
    h = (1 << N) - 1;
    int lim = 1 << N;
    for (int i = 0; i < lim; i++) dp[i] = -1;
    cout << solve() << '\n';
    return(0);
}

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

using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
int main()
{
    string a;
    cin >> a;
    int count = 0;
    int i = 0;
    while (i < 3)
    {
        if (a[i] == 'R')
        {
            count++;
        }
        i++;
    }
    if (count == 2)
    {
        if (a[0] == 'R' && a[2] == 'R')
        {
            count = 1;
        }
    }
    cout << count;
}

Measured memory_bytes: 3624
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	h := stdin.ReadInt()
	w := stdin.ReadInt()
	n := stdin.ReadInt()
	sr := stdin.ReadInt()
	sc := stdin.ReadInt()
	s := stdin.Read() // Takahashi: 取り除く
	t := stdin.Read() // Aoki: 残す

	var x int

	// 右に逃げる戦略
	x = sc
	for i := 0; i < n; i++ {
		if s[i] == 'R' {
			x++
			if !(1 <= x && x <= w) {
				stdout.Println("NO")
				return
			}
		}
		if t[i] == 'L' && 1 <= x-1 && x-1 <= w {
			x--
		}
	}

	// 左に逃げる戦略
	x = sc
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			x--
			if !(1 <= x && x <= w) {
				stdout.Println("NO")
				return
			}
		}
		if t[i] == 'R' && 1 <= x+1 && x+1 <= w {
			x++
		}
	}

	// 上に逃げる戦略
	x = sr
	for i := 0; i < n; i++ {
		if s[i] == 'U' {
			x--
			if !(1 <= x && x <= h) {
				stdout.Println("NO")
				return
			}
		}
		if t[i] == 'D' && 1 <= x+1 && x+1 <= h {
			x++
		}
	}

	// 下に逃げる戦略
	x = sr
	for i := 0; i < n; i++ {
		if s[i] == 'D' {
			x++
			if !(1 <= x && x <= h) {
				stdout.Println("NO")
				return
			}
		}
		if t[i] == 'U' && 1 <= x-1 && x-1 <= h {
			x--
		}
	}

	stdout.Println("YES")
}

func main() {
	stdout := NewStdout()
	exec(NewStdin(bufio.ScanWords), stdout)
	stdout.Flush()
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 1536
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a<=8 && b<=8){
		    System.out.println("Yay!");
		}else{
		    System.out.println(":(");
		}
    }
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>A>>B;
	if(B-A<=0) cout<<"delicious"<<endl;
	else if(B-A<=X) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
p = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        x = math.gcd(i,j)
        if(x == 1):
            p += n
        else:
            for k in range(1,n+1):
                p += math.gcd(x,k)
print(p)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
T GCD(T a, T b) {
	if (b == 0)return a;
	return GCD(b, (T)(a % b));
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL K;
	cin >> K;
	LL sum = 0;
	for (LL a = 1; a <= K; a++) {
		for (LL b = 1; b <= K; b++) {
			for (LL c = 1; c <= K; c++) {
				sum += GCD(GCD(a, b), c);
			}
		}
	}
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


struct UnionFind {
    vector<int> par, rank;

    UnionFind(int n) {
        par.resize(n), rank.resize(n, 0);
        for(int i = 0; i < n; i++) par[i] = i; 
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vpair edges;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edges.emplace_back(a, b);
    }
    int ans = 0;
    rep(i, m) {
        UnionFind uf(n);
        rep(j, m) {
            if (j == i) continue;
            auto e = edges[j];
            uf.unite(e.fi, e.se);
        }
        bool check = false;
        srep(j, n, 1) {
            if (!uf.same(0, j)) check = true;
        }
        if (check) ans++;
    }

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

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> ls, rs;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int tail = 0, bottom = 0;
        for (char c : s) {
            tail += (c == '(') ? 1 : -1;
            bottom = min(bottom, tail);
        }
        if (tail >= 0) ls.emplace_back(bottom, tail);
        else rs.emplace_back(bottom-tail, -tail);
    }
    auto joind_tail = [](vector<pair<int, int>>& xs) {
        sort(xs.begin(), xs.end(), greater());
        int res = 0;
        for (auto [bottom, tail] : xs) {
            if (res + bottom < 0) return -1;
            res += tail;
        }
        return res;
    };
    int l = joind_tail(ls), r = joind_tail(rs);
    if (l != -1 && r != -1 && l == r) puts("Yes");
    else puts("No");
}


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

int main()
{    
    int n, u, v;
    cin >> n >> u >> v;
    u -= 1;
    v -= 1;
    vector<vector<int>> g(n);
    rep(i,n-1)
    {
        int a, b;
        cin >> a >> b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }

    stack<pair<int, int>> st;
    bool seen[n] = {false};
    st.push({u, 0});
    int route[n] = {-1};
    int d = 0;

    while(!st.empty())
    {
        d = st.top().second;
        int cv = st.top().first;
        st.pop();

        seen[cv] = true;
        route[d] = cv;

        if(cv == v) break;
        for(auto nv : g[cv])
        {
            if(seen[nv]) continue;
            st.push({nv, d+1});
        }        
    }

    int d_rn = (d+1)/2 - 1;
    int rn = route[d_rn];
    int fn = route[d_rn + 1];

    for(auto& s:seen) s = false;
    while(!st.empty()) st.pop();

    int max_d = 0;
    st.push({rn, 0});
    seen[fn] = true;

    while(!st.empty())
    {
        int cd = st.top().second;
        max_d = max(max_d, cd);
        int cv = st.top().first;
        st.pop();
        seen[cv] = true;
        for(auto nv : g[cv])
        {
            if(seen[nv]) continue;
            st.push({nv, cd+1});
        }
    }

    int ans = d_rn + (max_d - 1) + (1 + int(d%2==0));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#include<vector>
#include<queue>

using namespace std;
#define ll long long

int main()
{
    //int tc; cin>>tc;
    
        ll n,w; cin>>n>>w;
        vector<ll> val(n+1),weit(n+1);
        for(int i=0;i<n;i++)
        {
             cin>>weit[i]; cin>>val[i];
        }
        ll sum = 100005;
        ll dp[sum+5];
        for(int i=0;i<=sum;i++)
        {
            dp[i] = INT_MIN;
        }
        dp[0]=0;
        for(ll i=0;i<n;i++)
        {
            for(ll j=sum;j>=0;j--)
            {
                dp[j] = max(dp[j],j>=weit[i]?dp[j-weit[i]]+val[i]:INT_MIN);
            }
        }
        ll ans=0;
        for(int i=0;i<=w;i++)
        {
            ans = max(ans,dp[i]);
        }
        cout<<ans<<endl;
    
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}


//main関数
int main() {
    ll n , k; cin >> n >> k;
    vl have(n),d(k);
    vvl a(k,vl(n));
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            cin >> a[i][j];
            a[i][j]--;
            have[a[i][j]]++;
        }
    }

    ll ans = 0;
    rep(i,n){
        if(have[i] == 0) ans ++;
    }

    cout << ans << endl;
}

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

int main()
{
	int n, c, tcnt = 0, hcnt = 0;
	char tstr[128], hstr[128];

	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%s %s", tstr, hstr);

		c = strcmp(tstr, hstr);
		if(c == 0)
		{
			++tcnt;
			++hcnt;
		}
		else if(c < 0)
		{
			hcnt += 3;
		}
		else
		{
			tcnt += 3;
		}
	}
	printf("%d %d\n", tcnt, hcnt);
	return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>
#include <math.h>
int main()
{
  int i,n,num[10000],count=0,j,flag=0;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&num[i]);
    }

  for(i=0;i<n;i++)
    {
      if(num[i] == 2)
	{
	  count++;
	  continue;
	}
      if(num[i]<2 || num[i]%2 == 0)
	{
	  continue;
	}
      for(j=3;j<=sqrt(num[i]);j+=2)
	{
	  if(num[i]%j == 0)
	    {
	      flag=1;
	      break;
	    }
	}
      if(flag == 0)
	{
	  count++;
	}
      flag=0;
    }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 628