akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int X = in.i();
        int money = X;
        int ans = money / 500 * 1000;
        money -= money / 500 * 500;
        ans += money / 5 * 5;
        out.println(ans);
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 21204
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		List<Long> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextLong());
		}
		sc.close();

		solve(list);

	}

	static void solve(List<Long> list) {

		int count = 0;

		while (list.size() > 0) {

			for (int i = 0; i < list.size(); i++) {
				long n = list.get(i);
				if (n % 2 != 0) {
					list.remove(i);
				} else {
					list.add(n / 2);
					list.remove(i);
					count++;
				}
			}
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 41632
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    string N;
    cin >> N;
    int count = 0;
    set<char> S;
    rep(i, 4)
    {
        S.insert(N[i]);
    }
    rep(i, 4)
    {
        count = 0;
        rep(j, 4)
        {
            if (N[i] == N[j])
            {
                count++;
            }
        }
        if (count >= 3)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    if (S.size() == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def main():
    import numpy as np
    k, q = map(int, input().split())
    d = np.array(list(map(int, input().split())), dtype=np.int64)
    nxm = [list(map(int, input().split())) for _ in [0]*q]
    for n, x, m in nxm:
        d2 = np.sum((d[:(n-2) % k+1]-1) % m+1)
        d3 = np.sum((d[(n-2) % k+1:]-1) % m+1)
        print(n-1-(x % m+(d2+d3)*((n-2)//k)+d2)//m)


main()


Measured memory_bytes: 28052
object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }
  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val a = new Array[Int](n)
    for(i <- 0 until n){
      a(i) = sc.nextInt
    }

    var sum = 0L
    var opeCount1 = 0L
    // 正、負、正、負（偶数インデックスが正）とする
    for (i <- 0 until n) {
      sum = sum + a(i)

      if (i % 2 == 0) {
        if (sum <= 0) {
          opeCount1 += -sum + 1
          sum = 1
        }
      } else {
        if (sum >= 0) {
          opeCount1 += sum + 1
          sum = -1
        }
      }
    }

    sum = 0L
    var opeCount2 = 0L
    // 負、正、負、正（奇数インデックスが正）とする
    for (i <- 0 until n) {
      sum = sum + a(i)

      if (i % 2 != 0) {
        if (sum <= 0) {
          opeCount2 += -sum + 1
          sum = 1
        }
      } else {
        if (sum >= 0) {
          opeCount2 += sum + 1
          sum = -1
        }
      }
    }

    println(math.min(opeCount1, opeCount2))
  }


  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val a = new Array[Int](n)
    for(i <- 0 until n){
      a(i) = sc.nextInt
    }

    var prevSum = a(0)
    var opeCount = 0

    for (i <- 1 until n) {
      val currSum = prevSum + a(i)

      if (prevSum < 0 && currSum < 0) {
        opeCount += math.abs(currSum) + 1
        prevSum = 1
      } else if (prevSum > 0 && currSum > 0) {
        opeCount += math.abs(currSum) + 1
        prevSum = -1
      } else {
        if (currSum == 0) {
          opeCount += 1
          if (prevSum < 0) {
            prevSum = 1
          } else {
            prevSum = -1
          }
        } else {
          prevSum = prevSum + a(i)
        }
      }
    }

    println(opeCount)
  }

}


Measured memory_bytes: 51952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  int count = 0;
  int left = 0;
  int right = s.length() - 1;
  while (left < right)
  {
    if (s.at(left) != s.at(right))
      count++;
    left++;
    right--;
  }
  std::cout << count << std::endl;
  return 0;
}

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

int main()
{
    int n;
    scanf("%d",&n);
    if(n<1200) printf("ABC\n");
    else if(n<2800) printf("ARC\n");
    else printf("AGC\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

// MainT1P2018D
public class Main {

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			final int N = in.nextInt();
			int d = 8*N + 1;
			int dr = (int)Math.sqrt(d);
			if (dr * dr != d) {
				System.out.println("No");
				return;
			}

			final int k = (1 + dr) / 2;

			final int[] startIdx = new int[k - 1];
			{
				int idx = 1;
				for (int i = 0; i < k - 1; ++i) {
					startIdx[i] = idx;
					idx += i + 1;
				}
			}

			System.out.println("Yes");
			System.out.println(k);
			{
				System.out.print(k - 1);
				for (int i = 0; i < k - 1; ++i) {
					System.out.print(' ');
					System.out.print(startIdx[i] + i);
				}
				System.out.println();
			}
			for (int i = 0; i < k - 1; ++i) {
				System.out.print(k - 1);
				for (int j = 0; j < i; ++j) {
					System.out.print(' ');
					System.out.print(startIdx[i] + j);
				}
				for (int j = i; j < k - 1; ++j) {
					System.out.print(' ');
					System.out.print(startIdx[j] + i);
				}
				System.out.println();
			}
		}
	}
}


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

int main()
{
  long long A, B, K;
  cin >> A >> B >> K;

  if (K > A)
  {
    K -= A;
    A = 0;
    if (K > B)
    {
      B = 0;
    }
    else
    {
      B -= K;
    }
  }
  else
    A -= K;

  cout << A << " " << B << endl;
  return 0;
}

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

int main() {
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll t=0;
	for(ll i=0;i<n;i++){
		if(a[i]%2==0){
			if(a[i]%3==0 || a[i]%5==0){
				continue;
			}
			else{
				t=1;
				break;
			}
		}
	}
	if(t==1){
		cout<<"DENIED";
	}
	else{
		cout<<"APPROVED";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    //010101...or101010101...の2パターンどっちに寄せるか
    //2パターンと入力の違いの数をとって最小値出せばいいか
    string s;
    cin>>s;
    int c1=0,c2=0;
    for(int i=0;i<s.size();i++)//0101...
    {
        if(i%2==0)
        {
            if(s[i]=='1')
            c1++;
        }
        else
        {
            if(s[i]=='0')
            c1++;
        }
    }
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]=='0')
            c2++;
        }
        else
        {
            if(s[i]=='1')
            c2++;
        }
    }
    cout<<min(c1,c2)<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		for(int i=0;i<N;i++) a[i]=sc.nextInt();
		sc.close();
		
		long dp[][] = new long[N+1][N+1];
		for(int i=0;i<N;i++) dp[i][i]=0;
		
		for(int len = 1;len<=N;len++) {
			for(int i=0;i+len<=N;i++) {
				int j=i+len;
				
				//先手番 //N-lenは操作回数を表す。
				if((N-len)%2==0) {
					dp[i][j] = Math.max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1]);
				}
				else {
					dp[i][j] = Math.min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1]);
				}
			}
		}
		System.out.println(dp[0][N]);
	}
}


Measured memory_bytes: 128784
list1 = []
while True:
    x,y = map(int,input().split())
    if x==0 and y==0:
        break
    else:
        if x>y:
            x,y = y,x
        list1.append([x,y])

for i in range(len(list1)):
    print(list1[i][0],list1[i][1])
    


Measured memory_bytes: 6136
s = input()
ans = [0] * len(s)
for i in range(2):
    cnt = 0
    for j in range(len(s)):
        if s[j] == 'R':
            cnt += 1
        else:
            ans[j-1] += (cnt+1)//2
            ans[j] += cnt//2
            cnt = 0

    ans = ans[::-1]
    s = s[::-1]
    s = s.replace('R', 'X').replace('L', 'R').replace('X', 'L')

for i in range(len(s)):
    print(ans[i], end=' ')
print()


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;

void _() {
    ill(a);
    ill(b);
    cout << (a>b?a-1:a);
};


int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 256
import heapq
INFTY = 10**10
def f(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
xs,ys,xt,yt = map(int,input().split())
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
A.insert(0,[xs,ys,0])
A.append([xt,yt,0])
dist = [INFTY for _ in range(N+2)]
hist = [0 for _ in range(N+2)]
heap = [(0,0)]
dist[0]=0
hist[0]=1
while heap:
    d,x = heapq.heappop(heap)
    if dist[x]<d:continue
    hist[x]=1
    for i in range(N+2):
        if hist[i]==0:
            if dist[i]>d+max(f(A[x][:2],A[i][:2])-(A[x][2]+A[i][2]),0):
                dist[i]=d+max(f(A[x][:2],A[i][:2])-(A[x][2]+A[i][2]),0)
                heapq.heappush(heap,(dist[i],i))
print(dist[N+1])

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int s = 0;
    rep(i,n) s ^= a[i];
    rep(i,n) a[i] ^= s;
    rep(i,n) cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 3988
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			int p=in.nextInt();
			if((n|p)==0)
				return;
			int N[]=new int[n];
			int i=0;
			int r=p;
			for(;;)
			{
				if(r!=0)
				{
					N[i]++;
					r--;
				}
				else
				{
					r=N[i];
					N[i]=0;
				}
				if(N[i]==p)
					break;
				i++;
				i%=n;
			}
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 20260
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;

const double PI=3.14159265358979323846;

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double mi = h * 60 + m;
    double ji = 2 * PI * (double)mi / 720;
    double hun = 2 * PI * (double)mi / 60;
    double sa = abs(ji - hun);
    double cc = a * a + b * b - 2 * a * b * cos(sa);
    double c = sqrt(cc);
    cout << setprecision(20) <<  c << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	char s;
	cin >> s;
	if('a'<=s && s<='z') cout << 'a' << endl;
	else cout << 'A' << endl;;
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  
  string s[n];
  rep(i,n) cin >> s[i];
  
  for(int i = 1; i < n; i++){
    int sizel = s[i-1].size(); 
    rep(j,i){
      if(s[i][0] != s[i-1][sizel-1] || s[i] == s[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 3604
import scala.io.StdIn


object Main extends App {
  val Array(a, b)  = StdIn.readLine.split(" ").map(_.toInt)

  def solve(a: Int, b: Int) : Int  = {
    if (a <= 5) {
      0
    } else if (6 <=a && a <=12) {
      b / 2
    } else {
      b
    }
  }
  println(solve(a, b))

}
  



Measured memory_bytes: 25416
import java.io.*;
import java.io.IOException;
import java.util.*;

class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long N;
        N = sc.nextLong();
        solve(N);
    }

    static void solve(long N){
        if(Math.floor(Math.ceil(N/1.08)*1.08) == N) System.out.println((int)Math.ceil(N/1.08)); 
        else System.out.println(":(");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


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

#define ll long long

int main(){
    int A,B;
    cin >> A >> B;
    int a = A * B;
    int b = A + B;
    int c = A - B;
    int ans = max(a,b);
    cout << max(ans,c) << endl;
}

Measured memory_bytes: 256
using System;
namespace inonoa{
    class Ino{
        static void Main(){
            string[] n_y = Console.ReadLine().Split();
            int n = int.Parse(n_y[0]);
            long y = long.Parse(n_y[1]);

            for(int i=0;i<n+1;i++){
                for(int j=0;j<n+1-i;j++){
                    long k = (y-i*10000-j*5000)/1000;
                    if(i+j+k==n){Console.WriteLine(i.ToString()+" "+j.ToString()+" "+k.ToString()); return;}
                }
            }

            Console.WriteLine("-1 -1 -1");
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
ll a[210];
ll sum=0;
int judge(ll n){
	ll ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==0) return sum;
		if(a[i]%2==0) {
		ans++;
		a[i]=a[i]/2;
		}
		else return sum;
	}
	if(ans==n) {
		sum++;
		judge(ans);
	}
	else return sum;
}
int main(){
	ios::sync_with_stdio(0);
	ll n;
	cin>>n;
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0) return 0;
	}
	ll m=judge(n);
	cout<<m<<endl;
		return 0;
}

Measured memory_bytes: 256
/* author   : mpily :-()
title : Competing.cpp
time :Tue May 12 09:52:55 2020
🤣️
*/
#include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>>ed;
vector<int>col;
vector<pair<int,int>>con; 
int ans = 0;
void dfs(int pos, int prevc){
	int c = 1 ;
	for(int x : ed[pos]){
		if(c == prevc)
			c++;
		if(!col[x-1]){
			col[x-1] = c;
			ans = max(ans,c);
			int nxt = con[x-1].first^con[x-1].second;
			nxt^=pos;
			dfs(nxt,c);
			c++;
		}
	}

}
int main(){
	cin >> n;
	ed.resize(n);
	col.resize(n-1);
	con.resize(n-1);
	for(int i = 0; i < n-1; ++i){
		int a,b;
		cin >> a >> b;
		a--;b--;
		ed[a].push_back(i+1);
		ed[b].push_back(i+1);
		con[i].first = a;
		con[i].second = b;
	}
	dfs(0,-1);
	cout << ans <<"\n";
	for(int x : col){
		cout << x <<"\n";
	}
	return 0;
}

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

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

typedef vector<int> vi;

int main() {
	int n;
	while (cin >> n, n) {
		vi v;
		FOR(i, 1, n) v.push_back((i * i) % n);
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		
		vi ans((n - 1) / 2 + 1, 0);
		REP(i, v.size()) REP(j, v.size()) if (i != j) {
			int x = v[i] - v[j];
			if (x < 0) x += n;
			if (x > (n - 1) / 2) x = n - x;
			ans[x]++;
		}
		FOR(i, 1, (n - 1) / 2 + 1) printf("%d\n", ans[i]);
		
	}
	return 0;
}

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

int main(){
	int N;
	cin>>N;
	int v[N];
	int c[N];
	int dif[N];
	int sum=0;
	for(int i=0;i<N;i++){
		int kari;
		cin>>kari;
		v[i]=kari;
	}
	for(int i=0;i<N;i++){
		int kari2;
		cin>>kari2;
		c[i]=kari2;
		dif[i]=v[i]-c[i];
		if(dif[i]>0)	sum += dif[i];
	}
	cout<<sum;
	return 0;
}
		
	


Measured memory_bytes: 256
import java.util.*;

public class Main{
  
  
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<Integer> list = new ArrayList<Integer>();
    
    for(int i = 0; i < N; i++)
    {
      if( (i + 1) % 2 == 1)
      {
      	list.add(sc.nextInt());
      }
      else
      {
        sc.nextInt();
      }
    }
    
    long s = list.stream().filter(v -> v % 2 == 1).count();
    
    System.out.println(s);
    
  }
  
}


Measured memory_bytes: 35996
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n,k,q;
int a;
int s[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k>>q;
	int res=0;
	for(int i=1;i<=q;i++){
		cin>>a;
		s[a]++;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if((q-s[i])>=k){
			cout<<"No"<<endl;
		}
		else
			cout<<"Yes"<<endl;
	}
	return 0;
}


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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int num = 0;
    int _max = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'I') {
            num += 1;
        } else {
            num -= 1;
        }
        _max = max(num, _max);
    }
    cout << _max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define REP(i, n) for(i = 0; i < n; i++)

int main(void) {
    int n, u, k, v;
    int i, j;

    scanf("%d", &n);
    int M[n][n];
    REP(i, n) REP(j, n) M[i][j] = 0;

    REP(i, n) {
        scanf("%d %d", &u, &k);
        REP(j, k) {
            scanf("%d", &v);
            M[u - 1][v - 1] = 1;
        }
    }

    REP(i, n) {
        REP(j, n - 1) {
            printf("%d ", M[i][j]);
        }
        printf("%d\n", M[i][j]);
    }
    return 0;
}

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

int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    string s;
    int n;
    cin>>n;
    cin>>s;
    string g;
    g="ABC";
    //int n=s.length();
    int ans=0;
    for(int i=0;i<=n-3;i++){
        string t=s.substr(i,3);
        if(t.compare(g)==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp.to!(char[]);
  auto q = readln.chomp.to!int;
  auto r = 1;
  string a = "";
  string b = "";
  foreach (_; 0..q) {
    auto x = readln.chomp.split;
    if (x[0].to!int == 1) {
      r *= -1;
    } else {
      if (x[1].to!int == 1) {
        if (r == 1) {
          a = x[2] ~ a;
        } else {
          b = b ~ x[2];
        }
      } else {
        if (r == -1) {
          a = x[2] ~ a;
        } else {
          b = b ~ x[2];
        }
      }
    }
  }
  s = a ~ s ~ b;
  if (r == -1) {
    reverse(s);
  }
  s.writeln;
}


Measured memory_bytes: 5784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<((a+b+c>=22) ? "bust":"win")<<endl;
    return 0;
}

Measured memory_bytes: 256
o = input()
e = input()
ans = []
n = len(o)
i = 0
while i < n:
	ans.append(o[i])
	if i < len(e):
		ans.append(e[i])
	i+=1
for i in range(len(ans)):
	if i != len(ans)-1:
		print(ans[i],end="")
	else:
		print(ans[i])

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  set<char> c;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); ++i) c.insert(s[i]);
  if (s.length() == c.size())
    cout << "yes";
  else
    cout << "no";

  return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;



ll sec(ll h, ll m, ll s)
{
    ll res;
    res = h*60*60;
    res += m*60;
    res += s;
    return res;
}

int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(true);
    ll n = -1;
    ll tmax = sec(24, 0, 0);
    vll res;
    while(true) {
        //puts("here");
        scanf("%lld", &n);
        if (n == 0) break;
        ll h, m, s, hh, mm, ss;
        vll acc(tmax+2, 0);
        rep(i, 0, n) {
            //rewind(stdin);
            scanf("%lld:%lld:%lld %lld:%lld:%lld", &h, &m, &s, &hh, &mm, &ss);
            acc[sec(h,m,s)] += 1;
            acc[sec(hh,mm,ss)] -= 1;
        }

        rep(i, 0, tmax+1) {
            acc[i+1] += acc[i];
        }
        //for (ll el:acc) {
          //  cout << el << ' ';
        //}
        cout << *max_element(all(acc)) << endl;
    }
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
const int max = 51;

int n, s;
int cnt = 0;

void dfs(int i, int sum, int total){
    if(total == n and sum == s){
        cnt++;
        return;
    }
    //足す場合
    if(i < 10 and total != n) dfs(i+1, sum+i, total+1);
    //足さない場足
    if(i < 10 and total != n) dfs(i+1, sum, total);
}

int main(){
    while(1){
        cnt = 0;
        cin >> n >> s;
        if(n == 0 and s == 0) break;
        dfs(0,0,0);
        cout << cnt << endl;
    }

    return 0;
}



Measured memory_bytes: 3060
#include <stdio.h>
#define M 1000000007
#define N 200016

unsigned long ulget();
inline unsigned long ulget()
{
    register unsigned long t = 0;
    register char c;
    while((c = getchar() - '0') >= 0)
    {
        t = t * 10 + c;
    }
    return t;
}

unsigned int colorlastdp[N];
int main()
{
    unsigned int dp[N];
    unsigned int n = ulget();
    dp[0] = 0; dp[1] = 1;
    unsigned int color, lastcolor;
    lastcolor = ulget();
    colorlastdp[lastcolor] = 1;
    for (register unsigned int i = 2; i <= n; i++)
    {
        color = ulget();
        dp[i] = dp[i-1];
        if (color != lastcolor)
            dp[i] = (dp[i] + colorlastdp[color]) % M;
        colorlastdp[color] = dp[i];
        lastcolor = color;
        //printf("%d %d %d\n", i, color, dp[i]);
    }
    printf("%u", dp[n]);
}

Measured memory_bytes: 3136
import heapq

N,K = (int(i) for i in input().split())
V = list(map(int,input().split()))
minimum = min(N,K)

ans = 0
for i in range(minimum+1):
    for j in range(minimum-i+1):
        AB = []
        for k in range(i):
            heapq.heappush(AB,V[k])
        for k in range(j):
            heapq.heappush(AB,V[N-k-1])
        cnt = K - i - j
        if i == 0 and j == 0:
            continue
        while cnt > 0 and AB[0] < 0:
            heapq.heappop(AB)
            cnt -= 1
            if AB == []:
                break
        if sum(AB) > ans:
            ans = sum(AB)

print(ans)


Measured memory_bytes: 51804
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  map<pair<ll,ll>,ll>cnt;
  rep(i,0,n)
  {
    double x;
    cin>>x;
    a=llround(x*1e9);
    ll two=0,five=0;
    while(a%2==0)
    {
      a/=2;
      two++;
    }
    while(a%5==0)
    {
      a/=5;
      five++;
    }
    ++cnt[{two, five}];
  }
  ll ans=0;
  for(auto p1:cnt)
  {
    for(auto p2:cnt)
    {
      if(p1.first.first+p2.first.first>=18 && 
      p1.first.second+p2.first.second>=18)
        {
          if(p1<p2)
          ans+=(ll)(p1.second*p2.second);
        else if(p1==p2)
        ans+=(ll)p1.second*(p1.second-1)/2;
        }
    }
  }
  cout<<ans;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int A, B, T, ans;
    cin >> A >> B >> T;

    ans = T/A * B;
    cout << ans << endl;
    
}

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

long long n, x, h, l, r, ans;
map <long long, bool> ada;

int main() {
	cin >> x >> n;
	for(int i = 0; i < n; i++){
		cin >> h;
		ada[h] = 1;
	}
	l = r = x;
	while(1){
		if(ada[l])l--;
		else{ans = l; break;}
		if(ada[r])r++;
		else{ans = r; break;}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3612
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: i64,
        d: i64,
        xy : [(i64,i64); n],
    }

    let mut ans: i64 = 0;

    for &(x, y) in xy.iter() {
        if x*x + y*y <= d*d {
            ans += 1;
        }
    }

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


Measured memory_bytes: 7788
def judge(ex,torf,i):
	if i==3:
		return eval(ex)
	else:
		return judge(ex,torf+[True],i+1) or judge(ex,torf+[False],i+1)
		
while 1:
	ex=raw_input().split("|")
	if ex[0]=="#":break
	for j in range(len(ex)):
		dic=[]
		ex[j]=list(ex[j])[1:-1]
		for i in range(len(ex[j])):
			if ex[j][i]=="&":ex[j][i]="and"
			elif ex[j][i]=="~":ex[j][i]="not"
			else:
				if ex[j][i] not in dic:
					dic.append(ex[j][i])
					ex[j][i]="torf["+str(len(dic)-1)+"]"
				else:
					ex[j][i]="torf["+str(dic.index(ex[j][i]))+"]"
		ex[j]=" ".join(map(str,ex[j]))
	for clause in ex:
		if judge(clause,[],0):
			print "yes"
			break
	else:
		print "no"

Measured memory_bytes: 4288
import itertools
k=int(input())
def solve(a,b):
	if a<b:
		if b%a==0:
			return a
		else:
			return solve(a,b%a)
	if a%b==0:
		return b
	else:
		return solve(b,a%b)
arr=[i+1 for i in range(k)]
l=list(itertools.combinations_with_replacement(arr,3))
#l = [p for p in itertools.product(arr, repeat=3)]
s=0
dic={}

for i in l:
	a,b,c=i
	if a==b and a==c:
		s+=solve(c,solve(a,b))
	elif a==b or b==c or a==c:
		s+=3*(solve(c,solve(a,b)))
	else:
		s+=6*(solve(c,solve(a,b)))
print(s)

Measured memory_bytes: 105492
#include<stdio.h>
 
int main(void){
  long N;
  long sum=0;
  long i;
  
  scanf("%ld",&N);
  for(i=1; i<=N; i++){
  	if(i%3!=0 && i%5!=0)
      sum+=i;
  }
  printf("%ld",sum); 
  return 0;
}

Measured memory_bytes: 1708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();

		if (a.equals("H")) {
			if (b.equals("H")) {
				System.out.println("H");
			} else {
				System.out.println("D");
			}
		} else {
			if (b.equals("H")) {
				System.out.println("D");
			} else {
				System.out.println("H");
			}
		}
	}

}


Measured memory_bytes: 21332
N = int(input())
W = list(map(int,input().split()))
diff = 10**8

summleft = [W[0]]
summright = [W[-1]]
for i in range(N-2):
    summleft.append(summleft[i]+W[i+1])
    summright.append(summright[i]+W[-1-i-1])
summright.reverse()

for i in range(N-1):
    if abs(summleft[i] - summright[i])<diff:
        diff =abs(summleft[i] - summright[i])
        
print(diff)

Measured memory_bytes: 3064
while True:
    (n, p) = [int(x) for x in input().split()]
    if n==0 and p==0:
        exit()
    s = [0 for _ in range(n)]
    i = 0
    q = p
    while True:
#        print(i,q,s)
        if q == 0:
            q = s[i]
            s[i] = 0
        else:
            s[i] += 1
            q -= 1
            if q==0 and s[i]==p:
                print(i)
                break
        i = (i+1)%n

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

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

const int mod = 1000000007;
ll dp[22][1 << 22];
ll a[22][22];

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

  dp[0][0] = 1;
  rep(msk, 1 << n) rep(i, n) if (i == __builtin_popcount(msk))
      rep(j, n) if (!(msk & 1 << j) && a[i][j])
        (dp[i + 1][msk | 1 << j] += dp[i][msk]) %= mod;


  cout << dp[n][(1 << n) - 1] << endl;
  return 0;
}


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

int main(){
	int n;
	vector<int> high;
	
	for(int i=0 ; i<10 ; i++){
		cin >> n;
		high.push_back( n );
	}
	
	sort( high.begin() , high.end() );

	for(int i=9 ; i>=7 ; i--){
		cout << high.at( i ) << endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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 LCM(int a, int b) { return a * b / GCD(a, b); }

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

signed main()
{
  int n; cin>>n;
  vector<pii> r(n);
  vector<pii> b(n);
  rep(i,n){
    int a,b; cin>>a>>b;
    r[i]=pii(a,b);
  }
  rep(i,n){
    int c,d; cin>>c>>d;
    b[i]=pii(c,d);
  }
  sort(r.rbegin(),r.rend());
  sort(b.rbegin(),b.rend());
  
  int ans=0;
  int bi=0;
  priority_queue<int, vi, greater<int>> q;
  rep(i,n){
    while(bi<n && r[i].first<b[bi].first){
      q.push(b[bi].second);
      bi++;
    }
    vi tmp;
    while(!q.empty()){
      int by=q.top(); q.pop();
      if(r[i].second<by) {
        ans++;
        break;
      }
      else tmp.push_back(by);
    }
    for(auto e: tmp){
      q.push(e);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)
#define upper(h,val) upper_bound(h.begin(),h.end(),val)
#define mint modint<998244353>
#define end_s(a) cout <<a<<endl;return 0
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) { pa[x] = y; }
}
V<string> solve2(int a, int b) {
	if (a < 0 || b < 0) { return {}; }
	if (a == 0 && b == 0) {
		V<string> ans(1, "");
		return ans;
	}
	V<string> ans = solve2(a - 1, b);
	V<string> nans;
	for (auto x : ans) { nans.push_back(x+"A"); }
	V<string> ans2 = solve2(a, b - 1);
	for (auto x : ans2) { nans.push_back(x+"B"); }
	return nans;
}
signed main() {
	string ss = "asgManOkuChoKeiGaiJosJouKosKanSeiSaiGokGgsAsgNytFksMts";
	V<string> s(18,"");
	rep(i, 18) {
		rep(j, 3) {
			s[i] = s[i]+ss[i * 3 + j];
		}
	}
	s[0] = "";
	s[6] = "Jo";
	s[8] = "Ko";
	while (true) {
		int m, n; cin >> m >> n;
		if (n == 0) { return 0; }
		vel ans(18, 0);
		ans[0] = 1;
		rep(i, n) {
			rep(j, 18) {ans[j] *= m;}
			rep(j, 17) { ans[j + 1] += ans[j] / 10000; ans[j] %= 10000; }
		}
		for(int i=17;i>=0;i--){
			if (ans[i] > 0) { 
				cout << ans[i]<<s[i];
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
int MOD=1e9+7;
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double> vec(n);
    for(int i=0;i<n;i++){
        double x;
        cin >> x;
        vec[i]=x;
    }
    double dp[n+1][n+2];
    for(int i=0;i<2;i++){
        if(i==0){
            dp[1][0]=1-vec[0];
        }else{
            dp[1][1]=vec[0];
        }
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0){
                dp[i][0]=dp[i-1][0]*(1-vec[i-1]);
            }else if(j==i){
                dp[i][j]=dp[i-1][j-1]*vec[i-1];
            }else{
                dp[i][j] = dp[i-1][j-1]*vec[i-1];
                dp[i][j] += dp[i-1][j]*(1.0-vec[i-1]);
            }
        }
    }
    double res=0;
    //cout<<dp[1][1]<<endl;
    for(int i=n/2+1;i<=n;i++){
        res += dp[n][i];
      // cout<<dp[n][i]<<endl;
    }
    cout<<setprecision(10)<<res<<endl;
}


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

int n, m;
bool dp[100001];
int cnt[100001];

void solve(){
    dp[1] = true;
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        dp[y] |= dp[x];
        cnt[x]--;
        cnt[y]++;
        if(cnt[x] == 0) dp[x] = false;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(dp[i]) ans++;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cnt[i] = 1;
    solve();
    return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;
vector<ll> v;

int main () {
  cin >> N;
  Rep(i, 3 * N) {
    ll tmp;
    cin >> tmp;
    v.push_back(tmp);
  }

  sort(All(v), greater<ll>());

  ll ans = 0;

  Rep(i, N) {
    ans += v[2 * i + 1];
  }

  cout << ans << "\n";
}

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g (n);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }
    string ans = "IMPOSSIBLE";
    queue<int> que;
    for(int v : g.at(0)){
        que.push(v);
    }
    while(!que.empty()){
        int v = que.front();
        for(int np : g.at(v)){
            if(np == n-1) ans = "POSSIBLE";
        }
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 12400
from bisect import bisect_left as bl
from itertools import accumulate
INF = 10 ** 20

def get_score(acc, head, end):
  sec_head = acc[head - 1]
  sec_end = acc[end]
  sec_sum = sec_end - sec_head
  cut = bl(acc, sec_head + sec_sum // 2) - 1
  score = INF
  reta, retb = None, None
  for i in range(cut - 2, cut + 3):
    if head <= i < end: 
      a = acc[i] - sec_head
      b = sec_end - acc[i]
      if score > abs(a - b):
        score = abs(a - b)
        reta, retb = a, b
  return (reta, retb)

n = int(input())
acc = [0]
acc += accumulate(map(int, input().split()))

ans = INF
for i in range(2, n - 1):
  p, q = get_score(acc, 1, i)
  r, s = get_score(acc, i + 1, n)
  if not None in (p, q, r, s):
    ans = min(ans, max(p, q, r, s) - min(p, q, r, s))
print(ans)

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

int main(){
  int n; cin >> n;
  int border[] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
  bool color[8];
  for(int i=0; i<8; i++) color[i]=false;

  int a[n];
  int target=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    bool f=true;
    for(int j=0; j<8; j++){
      if(a[i]<border[j]){
        color[j] = true;
        f=false;
        break;
      }
    }
    if(f) target++;
  }

  int colorcnt = 0;
  for(int i=0; i<8; i++){
    if(color[i])colorcnt++;
  }

  cout << max(colorcnt, 1) << " " << colorcnt+target << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int par[100010];
int rnk[100010];

// 初期化
void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

// 親探し
int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

// 併合
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) par[x] = y;
    else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

// 同じ木にあるか
bool same(int x, int y) {
    return find(x) == find(y);
}

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

    init(n);
    for (int i = 0; i < k; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        unite(a - 1, b - 1);
    }

    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(find(i));
    }

    cout << len(s) << endl;
}


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;

using Flow = ll; 
const Flow MXL = 0x3f3f3f3f3f3f3f3fll; 
const Flow oo = 0x3f3f3f3f; 
const int mxn = 100000; 
const int mxm = 1000000; 

struct Graph {
	int n, m, fe[mxn], ne[mxm], ev[mxm]; Flow f[mxm];
	void clear(int n)
	{ this->n = n; fill(fe, fe + n + 1, 0); m = 1; }
	void add_(int x, int y, Flow F)
	{ ne[++m] = fe[x]; fe[x] = m; ev[m] = y; f[m] = F; }
	void add1(int x, int y, Flow F)
	{ add_(x, y, F); add_(y, x, 0); }
	int T, arc[mxn], lev[mxn];
	Flow extend(int x, Flow lim) {
		if (x == T) return lim;
		Flow re = 0;
		for (int &e = arc[x]; e; e = ne[e])
			if (f[e] && lev[ev[e]] == lev[x] + 1) { 
				Flow t = extend(ev[e], min(lim - re, f[e]));
				if (t) { 
					f[e] -= t, f[e ^ 1] += t;
					if ((re += t) == lim) break; 
			}}
		if (!re) lev[x] = 0; 
		return re;
	}
	int q[mxn], *qb, *qe;
	Flow dinic(int S, int T) {
		Flow re = 0; this->T = T;
		for (;;) {
			fill(lev, lev + n + 1, 0);
			copy(fe, fe + n + 1, arc);
			for (qb = qe = q, lev[*qe++ = S] = 1; qb != qe;) {
				int x = *qb++;
				if (lev[T]) break;
				for (int e = fe[x]; e; e = ne[e])
					if (f[e] && !lev[ev[e]])
						lev[*qe++ = ev[e]] = lev[x] + 1;
			}
			if (!lev[T]) break;
			re += extend(S, MXL);
		}
		return re;
	}
}G;

int h, w, S, T, tot; 
#define numr(x) ((x)+tot*2)
#define numc(x) ((x)+tot*2+h) 
#define ind(x) ((x)*2-1)
#define oud(x) ((x)*2)
char s[200][200]; 
int main() {
	scanf( "%d%d", &h, &w ); 
	for (int i = 1; i <= h; ++i) scanf( "%s",s[i]+1); 
	tot = 0; 
	for (int i = 1; i <= h; ++i) 
		for (int j = 1; j <= w; ++j) 
			if (s[i][j] != '.') tot++; 
	G.clear(numc(w));  
	int tmp = 0;
	for (int i = 1; i <= h; ++i) 
		for (int j = 1; j <= w; ++j) 
			if (s[i][j] != '.') {
				int x = ++tmp; 
				if (s[i][j] == 'S') S = x; 
				else if (s[i][j] == 'T') T = x; 
				G.add1(numr(i),ind(x),oo); 
				G.add1(numc(j),ind(x),oo); 
				G.add1(oud(x),numr(i),oo); 
				G.add1(oud(x),numc(j),oo); 
				G.add1(ind(x),oud(x),1); 
			}
	//for (int i = 1; i <= h; ++i) G.add1(ind(numr(i)),oud(numr(i)),oo); 
	//for (int i = 1; i <= w; ++i) G.add1(ind(numc(i)),oud(numc(i)),oo); 
	int ans = G.dinic(oud(S),ind(T)); 
	if (ans > tot) ans = -1; 
	cout<<ans<<endl; 
}


Measured memory_bytes: 7040