akhauriyash/Code-Regression huggingface dataset:
listw = []
for i in range(10):
    w = int(input())
    listw.append(w)

listk = []
for i in range(10):
    k = int(input())
    listk.append(k)

for i in range(10):
    for j in range(9,0,-1):
        if listw[j-1]<listw[j]:
            listw[j-1],listw[j] = listw[j],listw[j-1]

for i in range(10):
    for j in range(9,0,-1):
        if listk[j-1]<listk[j]:
            listk[j-1],listk[j] = listk[j],listk[j-1]

W = listw[0] + listw[1] + listw[2]
K = listk[0] + listk[1] + listk[2]

print(W,K)


Measured memory_bytes: 5600
w = gets.chomp.downcase
count = 0
while line = gets do
  t = line.chomp
  if t=="END_OF_TEXT"
    break
  end
  t = t.downcase.split(" ")
  for x in t do
    if w==x
      count += 1
    end
  end
end
printf("%d\n",count)


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

using ll=long long;

int main() {
  int N; cin >>N;
  vector<int> d(N);
  rep(i,0,N) {cin >>d[i];}
  sort(d.begin(),d.end());
  cout <<d[N/2]-d[N/2-1] <<endl;
  return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define int long long
#define rint register int
#define fo(i, n) for(rint i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
const int N = 3e5 + 2333;
vector<int> vec;
int ban[N], n, sum = 0;
inline void add(int u) {
  if((int) vec.size() == n - 1 || ban[u]) return ;
  vec.push_back(u); ban[u] = 1; sum += u;
}

main(void) {
  read(n);
  for(int i = 1, j = 1; i <= n - 1; j ++)
    if(j % 2 == 0 || j % 3 == 0) ++ i, add(j);
  for(int i = 1; i <= 30000; i ++)
    if(!ban[i] && __gcd(i, sum) != 1 && (i + sum) % 6 == 0) {
      vec.push_back(i); break;
    }
  foreach(u, vec) cout << *u << " "; puts("");
}


Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<map>
#define LL long long
using namespace std;
const int NN=100 +13;
const int mod=998244353;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
int n;
char s[NN]={};
#define PP __int128
#define PU pair<PP,int>
map<PU,LL> f;
LL dp(PP x,int l){
	if(l==0)return 1;
	if(l==1)return x+1;
	LL res=f[make_pair(x,l)];
	if(res)return res-1;
	res+=dp(x&1,1)*dp(x>>1,l-1)%mod;
	PP tp;
	for(int len=1;len<=l;++len){
		tp=0;
		for(int i=0;i<len;++i){
			tp|=x&(((PP)1)<<(i));
		}
		for(int i=len;i<l;++i){
			if((x&(((PP)1)<<(i)))==0&&(tp&(((PP)1)<<(i%len)))!=0)tp-=(((PP)1)<<(i%len));
			if(i%len==len-1){
				res+=dp(tp,len)*dp(x>>(i+1),l-i-1);
				res%=mod;
			}
		}
	}
	f[make_pair(x,l)]=res+1;
	return res;
}
int main(){
	//freopen("test.in","r",stdin);
	scanf("%s",s);
	n=strlen(s);
	PP x=0;
	for(int i=n-1;i>=0;--i){
		x=x*2+s[i]-'0';
	}
	printf("%lld\n",dp(x,n));
}

Measured memory_bytes: 4480
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

  ll a, b, c;

  cin >> a >> b >> c;

  if (((a % 2) + (b % 2) + (c % 2)) < 3) {
    cout << 0 << endl;
  } else {
    ll xs[3] = {a, b, c};
    sort(xs, xs+3);
    cout << xs[0] * xs[1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
    int n;
    int cnt = 0;
    cin >> n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b,b+n);
    LP(i,n){
if(a[i] != b[i])cnt++;
    }
    if(cnt == 0 || cnt == 2)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define mod 1000000007
#define D 26
#define maxn 100005
int n,cnt[D],ans=1;
char s[maxn];
int main()
{
	scanf("%d%s",&n,s);
	for(int i=0;i<n;i++) cnt[s[i]-'a']++;
	for(int i=0;i<D;i++) ans=1ll*ans*(cnt[i]+1)%mod;
	printf("%d\n",(ans+mod-1)%mod);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,ll>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,a[MAXN],p[MAXN];ll ans;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	Rep(i,1,n)a[i]=p[i]=read();
	sort(p+1,p+n+1);
	Rep(i,1,n)a[i]=lower_bound(p+1,p+n+1,a[i])-p,ans+=i+a[i]&1;
	cout<<ans/2<<'\n';
	return 0;
}




Measured memory_bytes: 4392
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static Scanner sc = null;
    static PrintWriter pw = null;

    static {

        try {
            sc = new Scanner(System.in);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static final long MOD = 1_000_000_007;

    private static String data;

    private static int[][] dd;

    public static void main(String[] args) {
        data = sc.next();
        dd = new int[data.length()][2];
        int l = data.length() - 1;
        for (int t = 0; t < dd.length; t++) {
            dd[t][0] = -1;
            dd[t][1] = -1;
        }

        for (int endIndex = 0 ; endIndex < data.length() ; endIndex++) {
            int ii = data.charAt(endIndex) - '0';
            for (int overcharge = 0 ; overcharge<= 1 ; overcharge++) {
                ii += overcharge;
                dd[endIndex][overcharge] = Math.min((endIndex == 0 ? 0 : dd[endIndex - 1][0]) + ii,
                        (endIndex == 0 ? 1 : dd[endIndex - 1][1]) + 10 - ii);
            }

        }


        System.out.println(dd[l][0]);
    }





}


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

int debug = 0;

const int N = 2010;
int a[11][N], h, w, k, ans;

main() {
    cin >> h >> w >> k;
    rep(i, 0, h) {
        string s;
        cin >> s;
        rep(j, 0, w) {
            a[i][j] = s[j] - '0';
        }
    }
    ans = N * N;
    rep(mask, 0, (1 << (h - 1))) {
        int cur = (int)__builtin_popcount(mask);
        vector <int> cnt(h, 0);
        rep(j, 0, w) {
            rep(i, 0, h) {
                cnt[i] += a[i][j];
            }
            int f = 0, c = 0;
            rep(i, 0, h) {
                c += cnt[i];
                if (c > k) {
                    f = 1;
                    break;
                }
                if ((mask >> i)&1) {
                    c = 0;
                }
            }
            if (f) {
                cur++;
                rep(i, 0, h) {
                    cnt[i] = a[i][j];
                }
            }
            f = 0, c = 0;
            rep(i, 0, h) {
                c += cnt[i];
                if (c > k) {
                    f = 1;
                    break;
                }
                if ((mask >> i)&1) {
                    c = 0;
                }
            }
            if (f) {
                cur = N*N;
                break;
            }
        }
        if (debug) {
            cerr << " mask: " << mask << " cur: " << cur << '\n';
        }
        ans = min(ans, cur);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m float64
	var mr, hr, r, c float64

	fmt.Scan(&a, &b, &h, &m)

	mr = m * 6
	hr = h*30 + m/2

	if mr-hr > hr-mr {
		r = hr - mr
	} else {
		r = mr - hr
	}
	if r < 0 {
		r += 360
	}

	rn := (r / 180) * math.Pi
	c = math.Sqrt(a*a + b*b - 2*a*b*math.Cos(rn))

	fmt.Print(c)

}


Measured memory_bytes: 1820
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = tmp[0];
            int P = tmp[1];
            WriteLine((A * 3 + P) / 2);
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<cmath>

constexpr size_t f(size_t n){
    return n == 0 ? 1 : f(n - 1) * n;
}

int main(){
    
    size_t n;
    std::cin >> n;

    std::vector<std::pair<int, int>> xy;

    for(size_t i = 0; i < n; i++){
        size_t x, y;
        std::cin >> x >> y;
        xy.emplace_back(x, y);
    }

    std::sort(xy.begin(), xy.end());

    auto sum = 0.0;

    do{
        for(size_t i = 0; i < xy.size() - 1; i++){
            sum += std::sqrt(std::pow(xy[i].first - xy[i + 1].first, 2.0) + std::pow(xy[i].second - xy[i + 1].second, 2.0));
        }
    }while(std::next_permutation(xy.begin(), xy.end()));

    std::printf("%f\n", sum / f(n));
    
    return 0;
}


Measured memory_bytes: 256
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())

N,W=LI()
INL = [tuple(LI()) for i in range(N)]
DP=[[10**18]*100001 for _ in range(N+1)]
DP[0][0] = 0

for i, (w, v) in enumerate(INL, 1):
    # print(i,w,v)
    for j in range(100001):
        DP[i][j] = min(DP[i-1][j], DP[i][j])
        if (j+v) <= 100000:
            DP[i][j+v] = min(DP[i-1][j+v], DP[i-1][j]+w)

res = 0
for v, w in enumerate(DP[N]):
    if w <= W:
        res = max(res, v)

# print(DP[1][0], DP[1][10])
print(res)


Measured memory_bytes: 122464
using static System.Console;

public static class Program
{
    public static void Main()
    {
        var score = int.Parse(ReadLine());
        if(score < 600)
        {
            WriteLine(8);
        }
        else if(score < 800)
        {
            WriteLine(7);
        }
        else if (score < 1000)
        {
            WriteLine(6);
        }
        else if (score < 1200)
        {
            WriteLine(5);
        }
        else if (score < 1400)
        {
            WriteLine(4);
        }
        else if (score < 1600)
        {
            WriteLine(3);
        }
        else if (score < 1800)
        {
            WriteLine(2);
        }
        else if (score < 2000)
        {
            WriteLine(1);
        }
    }
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        string str = to_string(i);
        int sum = 0;
        for(int j = 0; j < str.size(); j++){
            sum += (int)(str.at(j) - '0');
        }
        if(a <= sum && sum <= b){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  String s=sc.next();
	  int max=0;
	  for(int i=0;i<s.length();i++) {
		  int count=0;
		  for(int j=i;j<s.length();j++) {
			  if(s.substring(j, j+1).equals("A")||s.substring(j, j+1).equals("C")||s.substring(j, j+1).equals("G")||s.substring(j, j+1).equals("T"))count++;
			  else break;
		  }
		  max=Math.max(max, count);
	  }
	  System.out.println(max);
  }
}


Measured memory_bytes: 35708
n, m = gets.split(" ").map{|ch| ch.to_i}
A = Array.new(n){gets.split(" ").map{|aij| aij.to_i}}
b = Array.new(m){gets.to_i}

for i in 0..n-1
  aij = 0
  for j in 0..m-1
    aij += A[i][j]*b[j]
  end
  puts aij
end

Measured memory_bytes: 8924
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
n = onem()
data = []
edges = []
for i in range(n):
    kkk = l()
    data.append([i]+ kkk)
ddd = sorted(data,key = lambda x:x[1])
bbb = sorted(data,key = lambda x:x[2])

Ne = cl.defaultdict(list)
for i in range(1,n):
    Ne[ddd[i-1][0]].append((ddd[i][0],ddd[i][1]-ddd[i-1][1]))
    Ne[ddd[i][0]].append((ddd[i-1][0],ddd[i][1]-ddd[i-1][1]))
    Ne[bbb[i-1][0]].append((bbb[i][0],bbb[i][2]-bbb[i-1][2]))
    Ne[bbb[i][0]].append((bbb[i-1][0],bbb[i][2]-bbb[i-1][2]))

is_used = [False for i in range(n+1)]
h = []
hq.heappush(h,(0,1))
ans = 0

while h:
    d,n = hq.heappop(h)
    if is_used[n]:
        continue
    ans += d
    is_used[n] = True
    for z,x in Ne[n]:

        if not is_used[z]:
            hq.heappush(h,(x,z))

print(ans)





Measured memory_bytes: 125784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll const mod = 1000000007;
#define inf 1000000000000000000

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x){
    return power(x,mod-2,mod)%mod;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    //cin>>t;
    //cout<<t<<endl;
    //while(t--)
    {
        ll n,k;
        cin>>n>>k;
       // cout<<t<<" "<<n<<" "<<k<<endl;
        ll a[n];
        for(ll i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        ll fact[n+1];
        fact[0]=1;
        for(ll i=1;i<=n;i++)
        {
            fact[i]=(i*fact[i-1])%mod;
        }
        ll comb[n+1]={0};
        for(ll i=k-1;i<=n;i++)
        {
            comb[i]=(((fact[i]*modInv(fact[k-1]))%mod)*modInv(fact[i-k+1])%mod)%mod;
           // cout<<i<<" "<<comb[i]<<endl;
        }
        
        ll ans1=0;
        ll ans2=0;
        for(ll i=0;i<n;i++)
        {
            ans1=((ans1+(a[i]*comb[n-i-1])%mod)%mod+mod)%mod;
            //cout<<ans1<<endl;
        }
        ll z=0;
        for(ll i=n-1;i>=0;i--)
        {
            ans2=((ans2+(a[i]*comb[n-z-1])%mod)%mod+mod)%mod;
           // cout<<ans2<<endl;
            z++;
        }
        cout<<(ans2-ans1+mod)%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        if(K*500>=X){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 21844
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    k = I()
    a = set(list(range(1,10)))
    for i in range(1,16):
        for j in range(1,20*i):
            a.add(int('{}{}'.format(j,'9'*i)))
    m = inf
    for c in sorted(list(a))[::-1]:
        t = 0
        n = c
        while n > 0:
            t += n % 10
            n //= 10
        tm = c / t
        if m < tm - eps:
            a.remove(c)
        else:
            m = tm
    l = sorted(list(a))
    return '\n'.join(map(str,l[:k]))


print(main())



Measured memory_bytes: 6736
def main():
    s = input()
    ans = True
    for i in range(len(s)):
        if i % 2 == 0 and s[i] == "L":
            ans = False
        elif i % 2 == 1 and s[i] == "R":
            ans = False
    print("Yes" if ans else "No")


if __name__ == "__main__":
    main()


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

int top,S[1000];

void push(int k){
  S[++top]=k;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int x,y;
  char s[100];
  top=0;
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }else if(s[0]=='-'){
      y=pop();
      x=pop();
      push(x-y);
    }else if(s[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }else push(atoi(s));
  }

  printf("%d\n",pop());

  return 0;

}



Measured memory_bytes: 2124
#include<iostream>
using namespace std;
int main ()
{
    int a,b,t,sum=0;
    float tt;

    cin>>a>>b>>t;
    tt=t+0.5;

    for (int  i=a; i<=tt; i=i+a)
    {
        //if(i%3==0 && a<t)
            sum=sum+b;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3560
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

	int n,m,c;
struct node{
    int index,cnt,cost;
    node(int index,int cnt,int cost):index(index),cnt(cnt),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};
const int MAX=INT_MAX/10;
const int NONE=-1;

int main(){
	while(cin>>n>>m>>c,n){
		vvi dist(n,vi(n,MAX));
		REP(i,m){
			int f,t,cc;
			cin>>f>>t>>cc;
			dist[f-1][t-1]=cc;
		}
        priority_queue<node> q;
        q.push(node(0,0,0));
        vvi cost(n,vi(m+1,MAX));
        cost[0][0]=0;
        while(!q.empty()){
            node cnode=q.top();q.pop();
            if(cost[cnode.index][cnode.cnt]<cnode.cost){
                continue;
            }
			REP(i,n){
				if(dist[cnode.index][i]!=MAX){
					REP(j,2){
						int newcost=cost[cnode.index][cnode.cnt]+(j?dist[cnode.index][i]:0);
						if(newcost<=c&&cnode.cnt+(1-j)<m+1&&newcost<cost[i][cnode.cnt+(1-j)]){
							cost[i][cnode.cnt+(1-j)]=newcost;
							q.push(node(i,cnode.cnt+(1-j),newcost));
						}
					}
				}
			}
        }
		int ans=MAX;
		REP(i,m+1){
			if(cost[n-1][i]<=c){
				ans=i;
				break;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2960
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
   int n,a[110][110],b,c,d,i,j,s,k;
   scanf("%d",&n);
   for(i=0;i<2;i++)
    {
        for(j=0;j<n;j++)
            scanf("%d",&a[i][j]);
    }
    s=a[0][0];b=0;c=-100000;k=0;d=0;
        for(i=0;i<n;i++)
        {
            d=a[0][i]+d;
            b=d;
            for(j=i;j<n;j++)
                {
                    b=a[1][j]+b;

                }if(b>=c)
                       c=b;
        }
        printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Seg = Tuple!(int, "s", int, "t");
alias Point = Tuple!(int, "x", bool, "r");

void main() {
    int n, c;
    scan(n, c);

    auto cs = new Seg[][](c, 0);

    foreach (i ; 0 .. n) {
        int si, ti, ci;
        scan(si, ti, ci);
        cs[ci-1] ~= Seg(si, ti);
    }

    foreach (i ; 0 .. c) {
        cs[i].sort();
    }

    //auto ims = new int[](2 * 10^^5 + 1);
    auto pts = new Point[](0);

    foreach (i ; 0 .. c) {
        if (cs[i].empty) continue;
        pts ~= Point(cs[i][0].s, 0);
        pts ~= Point(cs[i][0].t, 1);

        foreach (j ; 1 .. cs[i].length) {
            if (cs[i][j].s == cs[i][j-1].t) {
                pts.back.x = cs[i][j].t;
            }
            else {
                pts ~= Point(cs[i][j].s, 0);
                pts ~= Point(cs[i][j].t, 1);
            }
        }
    }

    pts.sort();

    int ans;
    int w;

    foreach (pt ; pts) {
        if (pt.r) w--;
        else w++;

        ans = max(ans, w);
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 5244
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	ll n, m;
	cin >> n >> m;
	ll ans;
	if (n == 1) {
		if (m == 1)ans = 1;
		else ans = m - 2;
	}
	else {
		if (m == 1)ans = n - 2;
		else {
			ans = (n - 2)*(m - 2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
i = 0
lis = []
while True:
    if N % 26 == 0:
        lis.append(26)
        N -= 26
        
    else:
        lis.append(N%26)
    N = N//26
    if N == 0:
        break
    
for i in range(len(lis)-1,-1,-1):
    print(chr(lis[i]+96),end = "")


Measured memory_bytes: 9160
w,h,n = map(int,input().split())
a = [list(map(int,input().split()))for _ in range(n)]
z1 = [0,0]
z2 = [w,h]
for i in range (n):
    if a[i][2] == 1 and z1[0] <= a[i][0]:
        z1[0] = a[i][0]
    elif a[i][2] == 2 and z2[0] >= a[i][0]:
        z2[0] = a[i][0]
    elif a[i][2] == 3 and z1[1] <= a[i][1] :
        z1[1] = a[i][1]
    elif a[i][2] == 4 and z2[1] >= a[i][1] :
        z2[1] = a[i][1]
if z2[0] > z1[0] and z2[1] > z1[1]:
    print((z2[0]-z1[0])*(z2[1]-z1[1]))
else:
    print(0)

Measured memory_bytes: 3064
S = input()
T = input()
X = "UNRESTORABLE"
res = []
for inds, s in enumerate(S):
    if (inds + len(T) > len(S)):
        break
    for indt, t in enumerate(T):
        if S[inds + indt] == t or S[inds+indt] == "?":
            pass
        else:
            break
    else:
        res.append(S[:inds]+T + S[inds + len(T):len(S)])

if (len(res) > 0):
    ans = res[0].replace("?", "a")
    for i in res:
        ans = min(i.replace("?", "a"), ans)
    print(ans)
else:
    print(X)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    String s = sc.next();

    if (a >= 3200) {
      System.out.println(s);
    } else {
      System.out.println("red");
    }

  }
}

Measured memory_bytes: 35588
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x=INT()
    flg=0
    for i in range(x,0,-1):
        for j in range(2,10):
            for k in range(32):
                if k**j==i:
                    flg=1
        if flg==1:
            ct=i
            break
    print(ct)
            
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
let get_input n =
	let rec loop n acc =
		if n = 0 then acc
		else 
			read_line ()
			|> Str.split (Str.regexp " ")
			|> (fun [a; b] -> loop (n - 1) ((int_of_string a, int_of_string b) :: acc))
	in	
	loop n []

let solve lst =
	let rec loop lst acc =
		match lst with
		| [] -> acc
		| (a, b) :: xs -> 
			loop xs (acc + (b - (a + acc) mod b) mod b)
	in
	loop lst 0
	
let () =
	let n = read_int () in
	let lst = get_input n in
	solve lst
	|> print_int
	|> print_newline


Measured memory_bytes: 7936
class UnionFind:
	"""Union-Find, 
	http://www.slideshare.net/chokudai/union-find-49066733"""

	def __init__(self, N):
		self.par = [i for i in range(N)]
		self.rank = [0 for i in range(N)]

	def root(self, x):
		if(self.par[x]==x):
			return x
		else:
			self.par[x] = self.root(self.par[x])
			return self.par[x]

	def same(self, x, y):
		return self.root(x)==self.root(y)

	def unite(self, x, y):
		x = self.root(x)
		y = self.root(y)
		if x==y:
			return
		if self.rank[x]<self.rank[y]:
			self.par[x] = y
		else:
			self.par[y] = x
			if self.rank[x]==self.rank[y]:
				self.rank[x] = self.rank[x]+1
		return

N, K, L = map(lambda x:int(x), input().split())
P = [0]*K
Q = [0]*K
R = [0]*L
S = [0]*L
for i in range(K):
	P[i], Q[i] = map(lambda x:int(x), input().split())
for i in range(L):
	R[i], S[i] = map(lambda x:int(x), input().split())

uf_k = UnionFind(N)
uf_l = UnionFind(N)

for i in range(K):
	uf_k.unite(P[i]-1, Q[i]-1)
for i in range(L):
	uf_l.unite(R[i]-1, S[i]-1)

k_groups = [uf_k.root(i) for i in range(N)]
l_groups = [uf_l.root(i) for i in range(N)]

kl_groups = [(k_groups[i], l_groups[i]) for i in range(N)]
kl_groups_origin = kl_groups
kl_groups = sorted(kl_groups)

results_dict = {}

idx = 0
count = 1
pair = kl_groups[0]
for i in range(1, N):
	if kl_groups[i]==pair:
		count = count+1
	else:
		results_dict[pair] = count
		pair = kl_groups[i]
		count = 1
results_dict[pair] = count

for i in range(N):
	pair = kl_groups_origin[i]
	print(results_dict[pair], end=" ")


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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	string s,t;
	cin>>s>>t;
	ll m=s.size(),n=t.size();
	ll dp[m+1][n+1];
	rep(i,0,m+1){
		rep(j,0,n+1){
			if(i==0||j==0){
				dp[i][j]=0;
				continue;
			}
			if(s[i-1]==t[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	// rep(i,0,m+1){
	// 	rep(j,0,n+1){
	// 		test2(xp[i][j].ff,xp[i][j].ss)
	// 	}
	// 	cout<<"\n";
	// }
	string s1="";
	pair<ll,ll> p={m,n};
	// cout<<dp[1][1];
	while(p.ff!=0&&p.ss!=0){
		// test2(s[p.ff],t[p.ss])
		// test2(p.ff,p.ss)
		if(s[p.ff-1]==t[p.ss-1]){
			s1+=s[p.ff-1];
			p={p.ff-1,p.ss-1};
			continue;
		}
		
		if(dp[p.ff-1][p.ss]>=dp[p.ff][p.ss-1]){
			p={p.ff-1,p.ss};
		}
		else{
			p={p.ff,p.ss-1};
		}
		// test2(p.ff,p.ss)
	}
	reverse(s1.begin(),s1.end());

	cout<<s1<<"\n";
	
	
	return 0;
}

Measured memory_bytes: 73944
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M, P = (int(i) for i in input().split())
    adj_list = [[] for _ in range(N)]
    radj_list = [[] for _ in range(N)]
    ok = [False]*N
    edge = []
    for i in range(M):
        a, b, c = (int(i) for i in input().split())
        c -= P
        adj_list[a-1].append(b-1)
        radj_list[b-1].append(a-1)
        edge.append((a-1, b-1, -c))

    def dfs(G, v):
        seen = [False]*N
        todo = [v]
        seen[v] = True
        while todo:
            u = todo.pop()
            for next_v in G[u]:
                if seen[next_v]:
                    continue
                seen[next_v] = True
                todo.append(next_v)
        return seen

    i = 0
    for s, rs in zip(dfs(adj_list, 0), dfs(radj_list, N-1)):
        ok[i] = s and rs
        i += 1

    # Bellman_ford
    d = [10**12]*N
    d[0] = 0
    update = True
    step = 0
    while update:
        update = False
        for a, b, c in edge:
            if not(ok[a]) or not(ok[b]):
                continue
            newD = d[a] + c
            if newD < d[b]:
                update = True
                d[b] = newD
        step += 1
        if step > N:
            return print(-1)
    print(max(0, d[N-1]*-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 46188
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>

using namespace std;

int main()
{
  const double c = 633.0 / 81.0;
  double a;

  while ( cin >> a )
    cout << fixed << setprecision(7) << c * a << endl;
  
  return 0;
}

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

public class Main {
  private static int solve(int n, int[] ls, int[] rs) {
    int lMax = ls[0];
    int rMin = rs[0];
    for (int i = 1; i < n; i++) {
      lMax = Math.max(ls[i], lMax);
      rMin = Math.min(rs[i], rMin);
    }
    return Math.max(rMin - lMax + 1, 0);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int m = reader.nextInt();
    int n = reader.nextInt();
    int[] ls = new int[n];
    int[] rs = new int[n];
    for (int i = 0; i < n; i++) {
      ls[i] = reader.nextInt();
      rs[i] = reader.nextInt();
    }
    out.println(solve(n, ls, rs));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 46820
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
ll di = 1e9+7;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n+1, 1);
  for(int i=0;i<m;i++){
    int st;
    cin >> st;
    a[st] = 0;
  }
  vector<ll>dp(n+1);
  dp[0] = 1;
  for(int now=0;now < n;++now){
    for(int next=now+1;next<=min(n,now+2);++next){
      if(a[next]){
        dp[next]+=dp[now];
        dp[next]%=di;
      }
     }
  }
  cout << dp[n] << endl;
    
  
  
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#define rep(i, n) for (int i = 1; i < n + 1; i++)

using namespace std;

int _firstList[1000009];
int _lastList[1000009];

int _miniOne = 2147483647;
int _miniTwo = 2147483647;

int _first;
int _last;
int _youhui;
int _ans = 0;

int _youFList[1000009];
int _youLList[1000009];
int _jiage[1000009];

void CParseIn () {
	memset(_youFList, 0, sizeof(_youFList));
	memset(_youLList, 0, sizeof(_youLList));
	memset(_jiage, 0, sizeof(_jiage));
	
	
	cin >> _first >> _last >> _youhui;
	
	rep (i, _first) {
		
		cin >> _firstList[i];
	}
	
	rep(i, _last) {
		
		cin >> _lastList[i];
	}
	
	rep(i, _youhui) {
		cin >> _youFList[i] >> _youLList[i] >> _jiage[i];
	}
}

void Core () {
	
	rep(i, _first) {
		_miniOne = min(_miniOne, _firstList[i]);
	}
	
	rep(i, _last) {
		_miniTwo = min(_miniTwo, _lastList[i]);
	}
	
	_ans = _miniOne + _miniTwo;
	
	rep(i, _youhui) {
		_ans = min(_ans, _firstList[_youFList[i]] + _lastList[_youLList[i]] - _jiage[i]);
	}
}

void CWriteOut () {
	cout << _ans << endl;
}

int main () {
	
	CParseIn();
	Core();
	CWriteOut();
	
	return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vec p(N);
    rep(i,N) cin>>p.at(i);
    sort(p.begin(),p.end());
    N /= 2;
    ll ans = p.at(N) - p.at(N-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	final Scanner sc = new Scanner(System.in);
	int a,b,c;
	a=sc.nextInt();
	b=sc.nextInt();
	c=sc.nextInt();
	if(a<b &&b<c) System.out.println("Yes");
	else System.out.println("No");
    }

}

Measured memory_bytes: 17352
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
	int q,a,b;
	int s,t;
	cin>>q;
	set<int>m;
	for(;q--;){
		cin>>a;
		if(a==0)cin>>s,m.insert(s),cout<<m.size()<<endl;
		if(a==1)cin>>s,cout<<m.count(s)<<endl;
		if(a==2)cin>>s,m.erase(s);
		if(a==3){cin>>s>>t;auto it1=m.lower_bound(s),it2=m.upper_bound(t);for(;it1!=it2;++it1)cout<<*it1<<endl;}
	}
}



Measured memory_bytes: 12376
def calc_cost( data_list, target ):
    num = len(data_list)
    if num == 0:
        return -1
    length = sum( data_list )
    cost = (num - 1) * 10 
    cost += abs( target - length)
    return cost 

N,A,B,C = map(int,input().split())
data = []

for _ in range(N):
    data.append(int(input()))

ans = -1
for n in range(4**N):
    pat = n 
    data_a = []
    data_b = []
    data_c = []

    for i in range( N ):
        l = pat % 4
        if l == 0:
            pass
        elif l == 1:
            data_a.append(data[i])
        elif l == 2:
            data_b.append(data[i])
        elif l == 3:
            data_c.append(data[i])
        pat //= 4

    cost_a = calc_cost( data_a, A)
    cost_b = calc_cost( data_b, B)
    cost_c = calc_cost( data_c, C)

    if cost_a != -1 and cost_b != -1 and cost_c != -1:
        cost = cost_a+cost_b+cost_c
        if ans == -1:
            ans = cost
        else:
            if ans > cost:
                ans = cost

print(ans)


Measured memory_bytes: 3064
from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys
input = sys.stdin.readline

MAX = 1e9

def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c

    link = wf(link)

    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(int(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 31024
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List

getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main::IO()
main = do
    n:_ <- getVals
    dat <- forM [1..n] (\_ -> do
        x:y:_<-getVals
        return (x,y))
    print $ solver dat

urDir::[(Int,Int)]->Int
urDir coords = let sorted = sort $ map (\ (x,y) -> x+y) coords in 
               abs (head sorted - last sorted)

ulDir::[(Int,Int)]->Int
ulDir coords = let sorted = sort $ map (\ (x,y) -> x-y) coords in 
               abs (head sorted - last sorted)

solver::[(Int,Int)] -> Int
solver coords = max (urDir coords) (ulDir coords)

Measured memory_bytes: 79412
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] S = new long[n];

		for(int i = 0; i < n; i++) {
			S[i] = sc.nextLong();
		}

		int q = sc.nextInt();
		int count = 0;

		for(int j = 0; j < q; j++) {
			long T = sc.nextLong();
			for(int i = 0; i < n; i++) {
				if(T < S[i]) {
					break;
				} else if(T == S[i]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}

}


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

#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);}
int lcm(int a,int b){
	return a/gcd(a,b)*b;}

int main(){
	int n,m;
	cin>>n>>m;
	cout<<gcd(n,m)<<endl;
	return 0;
}




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

using namespace std;

typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 1e5 + 85 - 69;
int cnt[maxn];
bool prob[maxn];
int n, m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cnt[i] = 1;
	prob[0] = true;
	for(int i = 0; i < m; i++){
		int fi, se;
		cin >> fi >> se;
		fi--, se--;
		if(prob[fi]){
			if(cnt[fi] == 1)
				prob[fi] = 0;
			cnt[fi]--;
			prob[se] = true;
			cnt[se]++;
		}
		else{
			cnt[fi]--;
			cnt[se]++;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
		ans += prob[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int l = s.length();
  for(int i = 0;i<l;i++)
  {
    for(int j =i+1;j<l;j++)
    {
      if(s[i]==s[j])
      {
        cout<<"no"<<endl;
        return 0;
      }
    }
  }
  cout<<"yes"<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s=="ABC") cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;

  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  Node *parent,*left,*right;
};

Node *root,*NIL;

void Preorder(Node *pp){
  if(pp==NIL)return;
  cout<<" "<<pp->key;
  Preorder(pp->left);
  Preorder(pp->right);
}
void Inorder(Node *in){
  if(in==NIL)return;
  Inorder(in->left);
  cout<<" "<<in->key;
  Inorder(in->right);
}

void insert(int k){
  Node *z;
  Node *y=NIL; //x's parent
  Node *x=root; //T's root
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(1){
    if(x==NIL)break;
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else {
    if(z->key<y->key){
      y->left=z;
    }
    else {
      y->right=z;
    }
  }
}
int main(){
  int n=0,in=0;
  int i=0;
  string cel;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>cel;
    if(cel=="insert"){
      cin>>in;
      insert(in);
    }
    else if(cel=="print"){
      Inorder(root);
      cout<<endl;
      Preorder(root);
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 26604
/*
 * C.cpp
 *
 *  Created on: Jul 6, 2020
 *      Author: baibhavkumar
 */
#include<bits/stdc++.h>
using namespace std;

int main(){
	int X,Y;
	scanf("%d%d",&X,&Y);
	string ans = "No";
	for(int i=0;i<X+1;i++){
		int b=X-i;
		if(2 * i + 4 * b == Y){
			ans="Yes";
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3720
#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>
#include <math.h>
#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() {
    Int N;
    cin >> N;

    vi d = vi(N);
    mapii dm;

    rep(i,N){
        int in;
        cin >> in;
        d[i] = in;
        dm[in]++;
    }

    if(d[0]!=0){
        cout << 0 << endl;
        return 0;
    }

    Int ans=1;

    REP(i,1,N){
        ans *= dm[d[i]-1];
        ans %= 998244353;
    }


    cout << ans<< endl;

    return 0;
}

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

int main(){
  int a[4];
  int n;
  
  while(1){
    cin>>n;
    if(n==0) break;
    int nmax,nmin;
    int co=0;
    while(1){
      if(n==0 || n==6174) break;
      co++;
      for(int i=0;i<4;i++){
	a[i] = n%10;
	n/=10;
      }
      nmax=0,nmin=0;
      sort(a,a+4);
      for(int i=0;i<4;i++){
	nmin = nmin*10+a[i];
	nmax = nmax*10+a[3-i];
      }
      n=nmax-nmin;
    }
    if(n==0) cout<<"NA"<<endl;
    else cout <<co<<endl;
  }


  return 0;
}

Measured memory_bytes: 1176
import java.util.*;

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

        long n = sc.nextLong();

        long ans = 0;
        
        if (n % 2 == 1) {
        System.out.println(ans);
        return;
        }

        long num = 10;
        for (int i = 0; i < 100; i++) {
            if (n >= num) {
                ans += n / num;
                num = num * 5; 
            } else {
                break;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    string s;
    cin >> n >> s;
    ll r = 0, w = 0;
    ll ans = M;
    rep(i,0,n)	if(s[i]=='R')	r++;
    ans = r;
    rep(i,0,n){
    	if(s[i]=='R')	r--;
    	if(s[i]=='W')	w++;
    	ans = min(ans, max(r, w));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x": " << x << endl;
inline int lowbit(int x) { return x & -x; }
typedef long long LL;
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

LL a[N];
LL b[N];
int bits[N];

inline void update(int pos) {
    for (; pos < N; pos += lowbit(pos))
        bits[pos]++;
}
inline int query(int pos) {
    int res = 0;
    for (; pos; pos -= lowbit(pos))
        res += bits[pos];
    return res;
}

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // purple_bro
    int n, k;

    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        a[i] -= k;
        a[i] += a[i - 1];
        b[i] = a[i];
    }

    b[n + 1] = 0;
    sort(b + 1, b + 1 + n + 1);
    int tot = unique(b + 1, b + 1 + n + 1) - b - 1;

    int pos = lower_bound(b + 1, b + 1 + tot, 0) - b;
    update(pos);

    LL ans = 0;

    for (int i = 1; i <= n; i++) {
        int pos = lower_bound(b + 1, b + 1 + tot, a[i]) - b;
        ans += query(pos);
        update(pos);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 4096