akhauriyash/Code-Regression huggingface dataset:
"""

問題文

4 つの街があり、順に 1,2,3,4 と番号が付いています。 道が 3 本あり、i 本目の道は異なる街 ai,bi を双方向に結んでいます。 同じ街の対の間を結ぶ道が複数あることはありません。街同士を行き来する手段は、道以外にはありません。 どの 2 つの街の間も、道を何本か通ることで行き来することができます。

すべての道をちょうど 1 回ずつ通ることですべての街を訪れることが可能かどうか判定してください。
制約

    1≤ai,bi≤4(1≤i≤3)
    ai と bi は異なる (1≤i≤3)
    同じ街の対の間を結ぶ道は複数存在しない
    どの 2 つの街の間も、道を何本か通ることで行き来することができる
"""

def func(a_list , b_list) : 
    dic = {}
    for a in a_list : 
        if not a in dic : 
            dic[a] = 1
        else : 
            dic[a] += 1
    
    for b in b_list : 
        if not b in dic : 
            dic[b] = 1
        else : 
            dic[b] += 1

    cnt = 0
    for key in dic : 
        if dic[key] == 1: cnt += 1
    if cnt == 3: 
        return "NO"
    else : 
        return "YES"


if not func([4 , 1, 2], [2 , 3, 3]) == "YES" : 
    raise Exception("test 1 fail")

if not func([3 , 2, 1], [2 , 4, 2]) == "NO" : 
    raise Exception("test 2 fail")

if not func([2 , 3, 4], [1 , 2, 3]) == "YES" : 
    raise Exception("test 3 fail")

a_list = []
b_list = []
for i in range(3) : 
    s = input().split(" ")
    a_list.append(int(s[0]))
    b_list.append(int(s[1]))
print(func(a_list , b_list))


Measured memory_bytes: 3064
#define DEBUG(...) cerr << __VA_ARGS__ << endl;

#ifndef CDEBUG
#undef DEBUG
#define DEBUG(...) ((void)0);
#define NDEBUG
#endif

#define ran(i, a, b) for (auto i = (a); i < (b); i++)

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;
#ifndef M_PI
const double M_PI = acos(-1.0);
#endif


int main() {
  iostream::sync_with_stdio(false);
  string t;
  cin>>t;
  ll res = 0;
  int n = t.size();
  int cnt0 = 0;
  int cnt1 = 0;
  int pair1 = 0;
  for(int i=0; i<n; ++i){
    if(t[i] == '1'){
      ++cnt1;
      if(i!=n-1 && t[i+1] == '1'){
        ++pair1;
        ++i;
        ++cnt1;
      } else {
        res -= (cnt0+(i%2))/2;
      }
    } else {
      ++cnt0;
    }
  }
  res -= (ll)pair1*cnt0;
  for(int i=1; i<cnt1; i+=2){
    res -= cnt1;
  }
  for(int i=0; i<cnt1; i+=2){
    res -= i;
  }
  res += (ll)cnt1*n;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if (a <= c && c <= b) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),k=s.nextInt();
		int[] a=new int[n];
		Arrays.setAll(a,i->s.nextInt());

		int v=0,j=Math.min(n,k);
		for(int l=0;l<=j;++l){
			for(int r=0;l+r<=j;++r){
				Queue<Integer> q=new PriorityQueue<>();
				for(int i=0;i<l;++i)
					q.add(a[i]);
				for(int i=0;i<r;++i)
					q.add(a[n-1-i]);
				for(int i=k-l-r;i>0&&!q.isEmpty()&&q.peek()<0;--i)
					q.poll();
				v=Math.max(v,q.stream().mapToInt(i->i).sum());
			}
		}
		System.out.println(v);
	}
}


Measured memory_bytes: 26836
S = input()
ans = 0
mods = [0] * 2019
mods[0] = 1
curr = 0
x = 1
for d in reversed(S):
    curr = (curr + int(d) * x) % 2019
    ans += mods[curr % 2019]
    mods[curr % 2019] += 1
    x = x * 10 % 2019
print(ans)


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  vector<int> v(n);
  REP (i, n) {
    cin >> v[i];
  }

  int ans = 0;
  while (true) {
    int start = -1;
    REP (i, n) {
      if (v[i] > 0) {
        start = i;
        break;
      }
    }
    if (start == -1) break;
    ans++;
    FOR (i, start, n) {
      if (v[i] > 0) {
        v[i]--;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int inf = 10000000;
    static Scanner sc = new Scanner(System.in);
    static final int h = sc.nextInt();
    static final int w = sc.nextInt();
    static char[][] maze = new char[h][w];
    static int[][] distance = new int[h][w];
    static final int[] dx = {1, 0, -1, 0};
    static final int[] dy = {0, 1, 0, -1};
    static class Pair {
        public int x;
        public int y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        int sx = 0;
        int sy = 0;
        for (int i = 0 ; i < h ; i++) {
            maze[i] = sc.next().toCharArray();
        }
        for (int[] dis : distance) {
            Arrays.fill(dis, inf);
        }
        int max = 0;
        for (int i = 0 ; i < h ; i++) {
            for (int j = 0 ; j < w ; j++) {
                Queue<Pair> que = new ArrayDeque<>();
                if (maze[i][j] == '.') {
                    sx = i;
                    sy = j;
                    que.add(new Pair(sx, sy));
                    distance[sx][sy] = 0;
                    //検索の本体。キューの中身を一つ取り、その周り4マスの距離を確定させ、キューに詰める。
                    while (!que.isEmpty()) {
                        Pair p = que.poll();
                        for (int k = 0 ; k < 4 ; k++) {
                            int nx = p.x + dx[k];
                            int ny = p.y + dy[k];
                            if (inRange(nx, ny) && maze[nx][ny] != '#' && distance[nx][ny] == inf) {
                                que.add(new Pair(nx, ny));
                                distance[nx][ny] = distance[p.x][p.y] + 1;
                            }
                        }
                    }
                }

                for (int l = 0 ; l < h ; l++) {
                    for (int k = 0 ; k < w ; k++) {
                        if (distance[l][k] != inf) {
                            max = Math.max(max, distance[l][k]);
                        }
                    }
                }
                for (int[] dis : distance) {
                    Arrays.fill(dis, inf);
                }

            }
        }

        System.out.println(max);

    }

    static boolean inRange(int x, int y) {
        return x >= 0 && x < h && y >= 0 && y < w;
    }



}


Measured memory_bytes: 25668
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin >> n;
	
	string s1, s2;
	cin >> s1 >> s2;
	int i = 0;

	vector<int> a;
	while(i < s1.length()) {
		if (s1[i] == s1[i + 1]) {
			a.push_back(2);
			i += 2;
		}
		else {
			a.push_back(1);
			i++;
		}
	}
	ll ans;
	if (a[0] == 2)ans = 6;
	else ans = 3;

	for (int i = 1; i < a.size(); i++) {
		if (a[i - 1] == 1) {
			ans *= 2;
			ans = ans % 1000000007;
		}
		else if (a[i] == 2) {
			ans *= 3;
			ans = ans % 1000000007;
		}
	}

	cout << ans%1000000007 << endl;

	return 0;
}


Measured memory_bytes: 256
t, x, y = 0, 0, 0
for i in range(int(input())):
  next_t, next_x, next_y = map(int, input().split())
  diff = abs(x - next_x) + abs(y - next_y)

  if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1:
    print("No")
    exit(0)
  t, x, y = next_t, next_x, next_y
print("Yes")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

n, m, l = list(map(int, input().split()))

A = [[0 for _ in range(m)] for _ in range(n)]
B = [[0 for _ in range(l)] for _ in range(m)]
C = [[0 for _ in range(l)] for _ in range(n)]

for row in range(n):
    arow = list(map(int, input().split()))
    for j in range(m):
        A[row][j] = arow[j]

for row in range(m):
    brow = list(map(int, input().split()))
    for j in range(l):
        B[row][j] = brow[j]

for row in range(n):
    for col in range(l):
        sum_v = 0
        for k in range(m):
            sum_v += A[row][k] * B[k][col]
        C[row][col] = sum_v

for row in range(n):
    for col in range(l):
        if col < l - 1:
            print(C[row][col], end=" ")
        else:
            print(C[row][col], end="")
    print()


Measured memory_bytes: 7072
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    string A;

    cin >> A;



    cout << ++A[0] << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,K;
#define M 100005
struct Edge{
	int to,nx,id,v;
}edge[M<<1];
int h[M],tt;
void link(int a,int b,int id,int v){
	edge[++tt].to=b;
	edge[tt].nx=h[a];
	edge[tt].id=id;
	edge[tt].v=v;
	h[a]=tt;
}
#define DEG(i,st) for(int i=h[st];i;i=edge[i].nx)
#define LL long long
int fa[M][19],dep[M];
LL Ans[M];
LL dis[M];
void DFS(int F,int now){
	dep[now]=dep[F]+1;
	fa[now][0]=F;
	for(int i=1;i<19;i++)
		fa[now][i]=fa[fa[now][i-1]][i-1];
	DEG(i,now){
		int to=edge[i].to;
		if(to==F)continue;
		dis[to]=dis[now]+edge[i].v;
		DFS(now,to);
	}	
}
struct Node{
	int id,col,f,to;
};
vector<Node>Q[M];
int LCA(int a,int b){
	if(dep[a]>dep[b])swap(a,b);
	int stp=dep[b]-dep[a];
	for(int i=0;i<19;i++)
		if((1<<i)&stp)b=fa[b][i];
	if(a==b)return a;
	for(int i=18;~i;--i)
		if(fa[a][i]!=fa[b][i])
			a=fa[a][i],b=fa[b][i];
	return fa[a][0];
}
int V[M],ID[M];
int cnt[M];
LL Cnt[M];
void dfs(int F,int now){
	if(F){
		Cnt[ID[now]]+=V[now];
		cnt[ID[now]]++;
	}
	DEG(i,now){
		int to=edge[i].to;
		if(to==F)continue;
		V[to]=edge[i].v;
		ID[to]=edge[i].id;
		dfs(now,to);
	}
	for(int i=0;i<Q[now].size();i++){
		Node Now=Q[now][i];
		LL d=dis[now];
		d-=Cnt[Now.col];
		d+=1LL*cnt[Now.col]*Now.to;
		Ans[Now.id]+=d*Now.f;
	}
	if(F){
		Cnt[ID[now]]-=V[now];
		cnt[ID[now]]--;
	}
}
int main(){
	cin>>n>>K;
	for(int i=1,a,b,c,d;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		link(a,b,c,d),link(b,a,c,d);
	}
	DFS(0,1);
	for(int x,y,u,v,i=1;i<=K;i++){
		scanf("%d%d%d%d",&x,&y,&u,&v);
		int l=LCA(u,v);
		Q[u].push_back((Node){i,x,1,y});
		Q[v].push_back((Node){i,x,1,y});
		Q[l].push_back((Node){i,x,-2,y});
	}
	dfs(0,1);
	for(int i=1;i<=K;i++)
		printf("%lld\n",Ans[i]);
	return 0;
}

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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if ( H == 0 && W == 0 ) break;
        
        for ( int i = 0; i < H; i++ ){
            for ( int j = 0; j < W; j++ ){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int n,red=0,blue=0;
  cin>>n;
  rep(i,n)
  {
    char s;
    cin>>s;
    if(s=='R') red++;
    else blue++;
  }
  if(red>blue) cout<<"Yes";
  else cout<<"No";

  cout<<endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();


		Set<Integer> adj[] = new HashSet[n+1];
		for(int i = 1; i<adj.length; i++) {
			adj[i] = new HashSet<Integer>();
		}


		for(int i = 0; i < m; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();

			adj[a].add(b);
			adj[b].add(a);
		}

		int[] dist = new int[n+1];
		dist[0] = 0;
		int[] ans = new int[n+1];

		Set<Integer> endcheck = new HashSet<>();
		endcheck.add(1);
		Set<Integer> start = new HashSet<>();
		start.add(1);

		do {
			Set<Integer> tmpst = new HashSet<>();

			Iterator<Integer> stit = start.iterator();
			while(stit.hasNext()) {
				int v1 = stit.next();

				int tdist = dist[v1] + 1;

				Iterator<Integer> adjit = adj[v1].iterator();
				while(adjit.hasNext()) {
					int v2 = adjit.next();
					if(!endcheck.contains(v2)) {
						tmpst.add(v2);

						if(dist[v2] < 1 || dist[v2] > tdist) {
							dist[v2] = tdist;
							ans[v2] = v1;
						}
					}

				}
			}

			start = tmpst;
			endcheck.addAll(tmpst);

		}while(endcheck.size() < n);

		System.out.println("Yes");
		for(int i = 2; i < n+1; i++) {
			System.out.println(ans[i]);
		}


	}

}


Measured memory_bytes: 105272
#include <iostream>
#include <iomanip>

using namespace std;

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

  double answer;
  if (n == 1) {
    answer = 1;
  } else if (n % 2 == 0) {
    answer = 0.5;
  } else {
    answer = ((n / 2) + 1.0) / n;
  }

  cout << setprecision(7) << answer << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cmath> 
#include <cctype>
#include <vector>
#include <map> 
#include <iomanip>//cout << fixed << setprecision(x) 
using namespace std;

const int maxn = 100000 + 5;
const int INF = 0x3f3f3f3f;

int main()
{
	int A, B, K;
	
	cin >> A >> B >> K;
	
	for (int i = 1; i <= K; i++)
	{
		if (i & 1)
		{
			if (A & 1)
			{
				A--;
				
				B += A/2;
				
				A /= 2;
			}
			else
			{
				B += A/2;
				
				A /= 2;
			}
		}
		else
		{
			if (B & 1)
			{
				B--;
				
				A += B/2;
				
				B /= 2;
			}
			else
			{
				A += B/2; 
				
				B /= 2;
			}
		}
	}
	
	cout << A << " " << B << endl;

	return 0;	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	unsigned long int n;
	int i;
	unsigned long int num = 1;
	
	scanf("%lu", &n);
	num = 1;
	if(n >= 1 && n <= 20){
		for(i = 1; i <= n; i++){
			num = num * i;
		}
	
	printf("%lu\n", num);
	
	}
		
	return 0;
}

Measured memory_bytes: 600
"""
考え方としては、各数が何回足されるか、何回引かれるか、というのを計算すればよい。
Aを昇順に並べらべたとき、K番目に存在する数（＝K番目に小さい数）は、A[:K]の集合でのみ最大値になるので、1回足される。
K+1番目に存在する数は、K番目までの数の中からその数字以外でK-1個選んだ集合でのみ最大値になるので、K C (K-1) 回足される。
という風に各数の足される回数を求めていく。
引かれる回数に関しても同様に求める。
"""
mod = 10**9 +7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
A.sort()

#各数を足す
for i in range(K-1,N):
    a = A[i]
    ans += a*cmb(i,K-1,p)
    
#各数を引く
A = A[::-1]
for i in range(K-1,N):
    a = A[i]
    ans -= a*cmb(i,K-1,p)

ans %= mod

print(ans)

Measured memory_bytes: 94784
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,m,i,x,y,num[100005];
  bool r[100005]={false};
  
  cin >> n >> m;
  for (i=1;i<=n;i++) num[i]=1;
  r[1]=true;
  
  for (i=0;i<m;i++){
    cin >> x >> y;
    num[x]--;
    num[y]++;
    if (r[x]) r[y]=true;
    if (num[x]==0) r[x]=false;
  }
  
  int ans=0;
  for (i=1;i<=n;i++){
    if (r[i]) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void){
  int i,j,n;
  int a[5];
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&n);
  for(i=0;i<4;i++){
    for(j=i;j<5;j++){
      if(a[i]-a[j]>n || a[j]-a[i]>n){
        printf(":(\n");
        return 0;
      }
    }
  }
  printf("Yay!\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int n, beau = 1e9 + 7, i;
  	long long ans;
	char s1[60], s2[60];
	cin >> n;
	cin >> s1;
	cin >> s2;
	if (s1[0] == s2[0]) {
	    ans = 3;
	    i = 1;
	} else {
	    ans = 6;
	    i = 2;
	}
	while (i < n) {
	    if (s1[i] == s2[i]) {
	        if (s1[i - 1] == s2[i - 1]) ans *= 2;
	        else ans *= 1;
	        i++;
	    } else {
	        if (s1[i - 1] == s2[i - 1]) ans *= 2;
	        else ans *= 3;
	        i += 2;
	    }
	    if (ans > beau) ans %= beau;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    if(n < 100) {
        cout << int(pow(100, d) * n) << endl;
    } else {
        cout << int(pow(100, d) * (n+1)) << endl;
    } 

    return 0;
}



Measured memory_bytes: 256
n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
C=sum(cost)
#print(cost)
for i in range(1,n+1):
    Co=C-(abs(a[i+1]-a[i]))-abs((a[i]-a[i-1]))+abs(a[i+1]-a[i-1])
    print(Co)


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            long a = cin.ReadLong;
            int[,] map = new int[2, a];
            for(int i = 0; i < 2; i++)
                for(int j = 0; j < a; j++)
                    map[i,j] = cin.ReadInt;

            int max = 0;
            for (int j = 0; j < a; j++)
            {
                int ame = 0;
                for (int i = 0; i <= j; i++)
                    ame += map[0, i];
                for (int i = j; i < a; i++)
                    ame += map[1, i];
                if (max < ame) max = ame;
            }

            Console.WriteLine(max);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
N=int(input())
dp=[float("inf")]*(10**5+10)
dp[0]=0
for i in range(1,N+1):
	dp[i]=1+dp[i-1]
	X=6
	Y=9
	j=1
	k=1
	while(i>=X**j):
		dp[i]=min(dp[i],1+dp[i-X**j])
		j+=1
	while(i>=Y**k):
		dp[i]=min(dp[i],1+dp[i-Y**k])
		k+=1
print(dp[N])


Measured memory_bytes: 3828
#include<iostream>

int main(){
    int a,b;
    char str;
    while(1){
        std::cin>>a>>str>>b;
        if(str=='+')std::cout<<a+b<<"\n";
        if(str=='-')std::cout<<a-b<<"\n";
        if(str=='*')std::cout<<a*b<<"\n";
        if(str=='/')std::cout<<a/b<<"\n";
        if(str=='?')break;
    }
    
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    long long n,a,b,i,ac,bc;
    cin>>n>>a>>b;
    i=abs(a-b);
    ac=a-1;bc=n-b;
    if(i%2==0)cout<<i/2;
    else cout<<(b-a+1)/2+min(ac,bc);
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll i,j,x=inf,a,b,c,d,m,n;
   cin>>n;
   vector<ll>v;
   for(i=0;i<n;i++)
   {
       cin>>m;
       v.pb(m);
   }
   for(i=1;i<=100;i++)
   {
       c=0;
       for(j=0;j<v.size();j++)
       {
           c=c+(v[j]-i)*(v[j]-i);
       }
       x=min(x,c);
   }
   cout<<x<<endl;
}


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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	string s;
	cin>>s;
	int res=0,dem=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='R')
			dem++;
		else{
			res=max(res,dem);
			dem=0;
		}
	}
	res=max(res,dem);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int array[] = new int[num];
        for(int i=0;i<num;i++){
            array[i] = sc.nextInt();
        }
        for(int i=num;i>0;i--){
            System.out.print(array[i-1]);
            if(i-1>0){
                System.out.print(" ");
            } else {
                System.out.println("");
            }
        }
    }
}



Measured memory_bytes: 26272
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int a,b,i;
    cin>>s;
    a=s.length();
    sort(s.begin(),s.end());
    for(i=0;i<a-1;i++){
        if(s[i]==s[i+1]){
            cout<<"no"<<endl;
            return 0;
        }
    }

    cout<<"yes"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define oo 405
using namespace std;
int n, m, vis[oo], tot;
int mat[oo][oo];
int main ()
{
    scanf("%d%d", &n, &m);
    for(int i = 1, x, y; i <= m; ++ i)
    {
        scanf("%d%d", &x, &y);
        if(vis[x]) vis[y] = 1;
        else if(vis[y]) vis[x] = 1;
        else if(mat[x][y]) vis[x] = vis[y] = 1;
        else
        {
            mat[x][y] = mat[y][x] = 1;
            for(int j = 1; j <= n; ++ j)
            if(mat[x][j]) mat[y][j] = mat[j][y] = 1;
            for(int j = 1; j <= n; ++ j)
            if(mat[y][j]) mat[x][j] = mat[j][x] = 1;
        }
    }
    for(int i = 1; i <= n; ++ i)
    for(int j = i + 1; j <= n; ++ j)
    if(!vis[i] && !vis[j] && !mat[i][j]) ++ tot;
    printf("%d", tot); return 0;
}

Measured memory_bytes: 896
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| push(a)}
  end

  def push(element)
    @data.push(element)
    bottom_up
  end

  def pop
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def size
    @data.size
  end

  def parent_idx(target_idx)
    (target_idx - (target_idx.even? ? 2 : 1)) / 2
  end

  def bottom_up
    target_idx = size - 1
    return if target_idx == 0
    parent_idx = parent_idx(target_idx)
    while (@data[parent_idx] > @data[target_idx])
      swap(parent_idx, target_idx)
      target_idx = parent_idx
      break if target_idx == 0
      parent_idx = parent_idx(target_idx)
    end
  end

  def top_down
    target_idx = 0

    # child がある場合
    while (has_child?(target_idx))
      child_left_idx = target_idx*2+1
      child_right_idx = target_idx*2+2

      # 右側の child が無い場合
      if @data[child_right_idx].nil?
        if @data[target_idx] > @data[child_left_idx]
          swap(target_idx, child_left_idx)
        end
        return
      end

      if @data[child_left_idx] < @data[child_right_idx]
        if @data[target_idx] > @data[child_left_idx]
          swap(target_idx, child_left_idx)
          target_idx = child_left_idx
        else
          return
        end
      else
        if @data[target_idx] > @data[child_right_idx]
          swap(target_idx, child_right_idx)
          target_idx = child_right_idx
        else
          return
        end
      end
    end
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < (@data.size - 1)
  end
end


N, M = gets.chomp.split(' ').map(&:to_i)

AB = []
N.times do |i|
  AB[i] = gets.chomp.split(' ').map(&:to_i)
end

group_by_day = Hash[AB.group_by{|v|v[0]}.sort]

day_fee = Array.new(M){[]}
group_by_day.each do |k,v|
  day_fee[k-1] = v.map{|j| j[1]}
end

# require 'pry'
# binding.pry

ans = 0
pq = PriorityQueue.new
day_fee.each_with_index do |fees, idx|
  break if idx > M - 1
  fees.each do |fee|
    pq.push(fee*(-1))
  end
  ans += pq.pop.to_i
  # p pq
  # p pq.pop*(-1)
end

puts ans*(-1)


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

const int32_t MAX_N = 2e5;

struct IndexTree {
	int32_t treeSize;
	int32_t data[MAX_N + 5];	

	void init(int32_t _treeSize) {
		treeSize = _treeSize;
	}

	void add(int32_t ind, int32_t val = 1) {
		while(ind <= treeSize) {
			data[ind] += val;
			ind += (ind & (-ind));
		}
	}

	int32_t get(int32_t ind) {
		int32_t ans = 0;

		while(ind > 0) {
			ans += data[ind];
			ind -= (ind & (-ind));
		}

		return ans;
	}
};

IndexTree indTree;

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

	int32_t n, k;
	std::cin >> n >> k;

	std::vector< int32_t > v(n);
	for(int32_t i = 0; i < n; i++) {
		std::cin >> v[i];
		v[i]++;
	}

	indTree.init(n);

	int32_t invs = 0;
	for(int32_t i = 0; i < k; i++) {
		invs += i - indTree.get(v[i]);
		indTree.add(v[i]);
	}

	bool countedSorted = (invs == 0);

	int32_t ans = 1;
	for(int32_t i = k; i < n; i++) {
		indTree.add(v[i - k], -1);
		int32_t invs1 = indTree.get(v[i - k]);
		int32_t invs2 = k - 1 - indTree.get(v[i]);
		indTree.add(v[i]);

		invs += -invs1 + invs2;
		if(invs1 != 0 || invs2 != 0) {
			if(invs == 0 && !countedSorted) {
				ans++;
				countedSorted = true;
			}
			else if(invs != 0) {
				ans++;	
			}
		}
	}

	std::cout << ans << '\n';
}



Measured memory_bytes: 1792
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  s=chomp(readline())
  x=0
  m=0
  for i in s
    if i=='I'
      x+=1
    else
      x-=1
    end
    m=max(m,x)
  end
  println(m)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 109508
import collections

N = input()
A = map(int, raw_input().split())
C = collections.Counter(A)
K = C.keys()
K.sort(reverse=1)
res = 0
for i in K:
    for j in xrange(60):
        p = 2 ** j
        if i <= p:
            break
    if i == p:
      res += C[i] // 2
      C[i] = C[i] // 2 * 2
    else:
      num = min(C[i], C[p - i])
      res += num
      C[i] -= num
      C[p - i] -= num
print res


Measured memory_bytes: 55204
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define temT template<typename T>
using namespace std;
const int N=int(1e3)+10;

char s[N]; int n;

int main(){
	scanf("%s",s+1),n=strlen(s+1);
	if(s[n]=='s') s[++n]='e';
	s[++n]='s'; printf("%s",s+1);
	return 0;
} 

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

int main()
{
    int a,b,x;
    while(scanf("%d%d%d",&a,&b,&x)==3)
    {
        printf("%s\n",a+b>=x && a <= x?"YES":"NO");
    }
    return 0;
}


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

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    ll ans = 0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                int comb = 500*i + 100*j + 50*k;
                if(comb == x) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))

#define POS(i,j) (((i)%b)*(m+1)+(j))

const int b=54;
char *ans=NULL;
int top=0;
void calc(char *s,char *t,int n,int m,int *nextN,int *nextM){
  short *dp=(short *)calloc((b+1)*(m+1),sizeof(short));
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(s[i]==t[j]){
	dp[POS(i+1,j+1)]=dp[POS(i,j)]+1;
      } else {
	dp[POS(i+1,j+1)]=MAX(dp[POS(i+1,j)],dp[POS(i,j+1)]);
      }
    }
  }
  i=n;
  j=m;
  while(i>MAX(0,n-b) && j>0){
    if(s[i-1]==t[j-1]){
      ans[top++]=s[i-1];
      i--;
      j--;
    } else if(dp[POS(i,j)]==dp[POS(i,j-1)]){
      j--;
    } else {
      i--;
    }
  }
  *nextN=i;
  *nextM=j;
}

void run(void){
  char *s=(char *)calloc(3001,sizeof(char));
  char *t=(char *)calloc(3001,sizeof(char));
  scanf("%s",s);
  scanf("%s",t);
  int n=strlen(s);
  int m=strlen(t);
  ans=(char *)calloc(n+1,sizeof(char));
  while(n>0 && m>0){
    calc(s,t,n,m,&n,&m);
  }
  while(top>0){
    putchar(ans[--top]);
  }
  putchar('\n');
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 17920
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

int n;
vi a;

ll f(int prt){
    ll sum = 0;
    ll cost = 0;
    rep(i, n){
        sum += a[i];
        if(i % 2 == prt){
            if(sum > 0) continue;
            cost += 1 - sum;
            sum = 1;
        }else{
            if(sum < 0) continue;
            cost += sum + 1;
            sum = -1;
        }
    }
    return cost;
}

void Main() {
    cin >> n;
    a.resize(n);

    rep(i, n) cin >> a[i];
    cout << min(f(0), f(1)) << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  string s;
  int n=0;
  cin>>s;
  if(s=="SUN")n=7;
  if(s=="MON")n=6;
  if(s=="TUE")n=5;
  if(s=="WED")n=4;
  if(s=="THU")n=3;
  if(s=="FRI")n=2;
  if(s=="SAT")n=1;
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
#define ll long long int
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}



int main() {
	string S, T;
	cin >> S >> T;
	int A, B;
	cin >> A >> B;
	string U;
	cin >> U;
	if (U == S)
		cout << A - 1 << " " << B;
	else
		cout << A<<" " << B - 1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 5e2+9, M = 3e6+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int n;
int arr[30][30];
LL memo[30][M],csum[N];
LL solve(int idx=0,int mask=0)
{
  if(mask==((1<<n)-1)) return 1;

  LL &ret = memo[idx][mask];
  if(~ret) return ret;
  ret = 0;
  for(int i=0;i<n;++i) if(arr[idx][i] && !(mask&(1<<i))) ret += solve(idx+1,mask|(1<<i))%MOD;
  return ret%MOD;
}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d",&n);
  for(int i=0;i<n;++i)  for(int j=0;j<n;++j) scanf("%d",&arr[i][j]);
  printf("%lld\n",solve());
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 703488
#include<bits/stdc++.h>
#define int long long int
using namespace std;
map<int, pair<int, int>> mp;
#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i = 0; i <= 500; i++) {
			for (int j = 0; j <= i; j++) {
				mp[i * i * i * i * i - j * j * j * j * j] = {i, j};
				mp[i * i * i * i * i + j * j * j * j * j] = {i, -j};
			}
		}
		cout << mp[n].first << " " << mp[n].second << endl;
	}
	return 0;
}

Measured memory_bytes: 19312
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        switch (s)
        {
            case "SSS":
                Console.WriteLine(0);
                break;
            case "SSR":
                case "SRS":
                    case "RSS":
                        case "RSR":
                            Console.WriteLine(1);
                            break;
            case "SRR":
                case "RRS":
                    Console.WriteLine(2);
                    break;
            case "RRR":
                Console.WriteLine(3);
                break;
        }
    }
}

Measured memory_bytes: 17884
;; #!/usr/bin/env sbcl --script

(defun main ()
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'fixnum))
         (dp (make-array n :element-type 'fixnum :initial-element (floor most-positive-fixnum 2))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (flet ((relax (from to)
             (let* ((from-val (aref dp from))
                    (to-val (aref dp to))
                    (diff (abs (- (aref a to) (aref a from)))))
               (setf (aref dp to) (min to-val (+ from-val diff))))))
      (setf (aref dp 0) 0)
      (dotimes (i n)
        (dotimes (j k)
          (when (< (+ i (1+ j)) n) (relax i (+ i (1+ j)))))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


Measured memory_bytes: 59752
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int amari = a % b;
  bool OK = false;
  for (int i = 0; i <= b; i++)
  {
    if (amari * i % b == c)
    {
      OK = true;
      break;
    }
  }
  if (OK)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M,x[100001],y[100001];
	int kosu[100001];
	bool able[100001]={};
	scan(N>>M);
	rep(i,N) kosu[i]=1;
	rep(i,M){
		scan(x[i]>>y[i]);
		x[i]--; y[i]--;
	}
	able[0]=1;
	rep(i,M){
		able[y[i]]|=able[x[i]];
		if(kosu[x[i]]==1) able[x[i]]=0;
		kosu[x[i]]--;
		kosu[y[i]]++;
	}
	int ans=0;
	rep(i,N) ans+=able[i];
	prin(ans);
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>

using namespace std;

int main(){
  char s[5];
  for(int i=0;i<4;i++)cin >> s[i];
  int a=int(s[0])-'0';
  int b=int(s[1])-'0';
  int c=int(s[2])-'0';
  int d=int(s[3])-'0';
  bool ans=false;
  for(int i=-1;i<=1;i+=2){
    for(int j=-1;j<=1;j+=2){
      for(int k=-1;k<=1;k+=2){
        if(a+b*i+c*j+d*k==7){
          ans=true;
          cout << a;
          cout << (i==1?'+':'-');
          cout << b;
          cout << (j==1?'+':'-');
          cout << c;
          cout << (k==1?'+':'-');
          cout << d << "=7" << endl;
          break;
        }
      }
      if(ans)break;
    }
    if(ans)break;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = -1;

int a, b;

int main(){
//	freopen("input.txt", "r", stdin);
	while(scanf("%d %d", &a, &b) >= 1){
        if(a+b == 15){ cout << '+' << endl; continue;}
        if(a*b == 15){ cout << '*' << endl; continue;}
        cout << 'x' << endl;
    }
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [float('-inf')] + list(map(int, input().split()))
ans = max(C)
for start in range(1, N+1):
    now = start
    score = 0
    c_list = []
    for k in range(1, K+1):
        now = P[now]
        cost = C[now]
        score += cost
        c_list += [cost]
        ans = max(ans, score)
        if now == start:
            Kmk = K-k
            # score = score + score * (Kmk // len(c_list))
            roop = (Kmk // len(c_list))
            score = score + score * max(0, roop-1)
            ans = max(score, ans)
            if roop >= 1:
                for ci in c_list:
                    score += ci
                    ans = max(score, ans)
            for i in range(Kmk % len(c_list)):
                score += c_list[i]
                ans = max(score, ans)
            break
        

print(ans)

Measured memory_bytes: 83240
import java.util.*;

public class Main{
   public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int l=0,s=0,tmp=0;
	    String n="";
	    int[] nint = new int[4];
	    int count = 0;
	 
	    while(sc.hasNext()){
	        n = sc.next();
	        if(n.equals("0000")) break;
	 
	        count = 0;l = 0;s = 0;
	 
	        for(int i = 0;i<nint.length;i++) nint[i] = Integer.parseInt(String.valueOf(n.charAt(i)));
	         
	        boolean check = true;
	        for(int i = 0;i<nint.length;i++){
	        for(int j = 0;j<nint.length;j++){
	            if(nint[i]!=nint[j]) check = false; 
	        }
	        }
	        
	        if(check){ System.out.println("NA"); continue; }
	 
	        while(l-s!=6174 && !n.equals("6174")){
	        Arrays.sort(nint);
	        l = 0;s = 0;
	         
	        l += nint[0] * 1;
	        l += nint[1] * 10;
	        l += nint[2] * 100;
	        l += nint[3] * 1000;
	         
	        s += nint[3] * 1;
	        s += nint[2] * 10;
	        s += nint[1] * 100;
	        s += nint[0] * 1000;
	 
	        tmp = l-s;
	        nint[0] = tmp%10; tmp /= 10;
	        nint[1] = tmp%10; tmp /= 10;
	        nint[2] = tmp%10; tmp /= 10;
	        nint[3] = tmp%10; tmp /= 10; 
	         
	        count++;
	        }
	 
	        System.out.println(count);
	    }
	    }
	}

Measured memory_bytes: 32160
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N, M;
	cin >> N >> M;
	int ans = 0;
	if (N * 2 == M)cout << N;
	else if (N * 2 > M) {
		ans = M / 2;
		cout << ans;
	}
	else {
		ans += N;
		M -= N * 2;
		ans += M / 4;
		cout << ans;
	}
}

Measured memory_bytes: 256
import os
import math

n = int(input())
x = []
y = []
ans = 0
for i in range(n):
    a,b = (int(x) for x in input().split())
    x.append(a)
    y.append(b)

def d(x1,y1,x2,y2):
    return (((x1-x2)**2+(y1-y2)**2)**0.5)

for j in range(n):
    for k in range(j+1,n):
        ans += 2*d(x[j],y[j],x[k],y[k])
print(ans/n)


Measured memory_bytes: 3064
n,w = gets.chomp.split.map(&:to_i)
wv_arr = n.times.map{gets.chomp.split(" ").map(&:to_i)}

dp = Array.new(w+1, 0)

n.times do |i|
  part_w, part_v = wv_arr[i]
  w.downto(0) do |sum_w|
    a = dp[sum_w - part_w] + part_v
    b = dp[sum_w]
    if sum_w - part_w >= 0 && a > b
      dp[sum_w] = a
    else
      dp[sum_w] = b
    end
  end
end

puts dp[w]

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int a, b;

  CIN(a >> b);

  int ca = 0;
  int cb = 0;

  for (int i = 0; i < b; i++) {
    ca *= 10;
    ca += a;
  }
  for (int i = 0; i < a; i++) {
    cb *= 10;
    cb += b;
  }

  int m = max(ca, cb);

  COUT(m);

  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int count_zero=0;
  int count_one=0;
  for(int i=0;i<N;i++){
    if(S.at(i) == '0'){
      count_zero ++;
    }else{
      count_one ++;
    }
  }
  cout << min(count_zero,count_one)*2 << endl;
}

Measured memory_bytes: 512
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

tmp_i = [a_input[i]-i for i in range(n)]
tmp_j = [-a_input[i]-i for i in range(n)]

count_i = Counter(tmp_i)
count_j = Counter(tmp_j)

ans=0
for k,v in count_i.items():
    ans+=v*count_j.get(k,0)
print(ans)

Measured memory_bytes: 63348
S_ = input()
T = input()
loop = len(S_) - len(T) + 1
stringlist = []

# check S_ in T
for n in range(loop):
    chance = True
    for i in range(len(T)):
        if S_[n+i] == T[i] or S_[n+i] == "?":
            pass
        else:
            chance = False
            break

    if chance:
        tmp = S_[:n] + T + S_[n+len(T):]
        stringlist.append(tmp)

if len(stringlist) == 0:
    print("UNRESTORABLE")
else:
    stringlist.sort()
    String = stringlist[0]
    S = ""
    for i in range(len(S_)):
        if String[i] == "?":
            S += "a"
        else:
            S += String[i]
    print(S)





Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())

    sum = 0
    for i in range(n+1):
        if i % 3 == 0:
            continue
        elif i % 5 == 0:
            continue
        else:
            sum += i

    print(sum)

# else:
    # do nothing


Measured memory_bytes: 9164
#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx","popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve() {
	string s;
	cin >> s;
	if(s == "ABC")
		cout << "ARC\n";
	else
		cout << "ABC\n";
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll t=1;
	for(ll tt=1; tt <= t; tt++) {
		//cout << "case #" << tt << ":\n";
		solve();
	}

	return 0;
}



Measured memory_bytes: 3624