akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

bool solve() {
    string S;
    cin >> S;
    if (S == "0") return false;
    int N = S.size();
    int ans = 0;
    map<int, int> cnt;
    int now = 0;
    cnt[now]++;
    REP(i, N) {
        if (i & 1)
            now -= (S[i] - '0');
        else
            now += (S[i] - '0');
        now = (now + 11) % 11;
        ans += cnt[now];
        if (i + 1 < N && S[i + 1] == '0') continue;
        cnt[now]++;
    }
    cout << ans << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 3352
#coding:utf-8
#R[i][j]:i行j列目に光を置いた時右に伸びる光の長さ
H,W = list(map(int,input().split()))
S = [0] * (H+2)
wall = ''
for _ in range(W+2):
    wall += '#'
S[0] = wall
S[H+1] = wall
for h in range(H):
    S[h+1] = '#' + input() + '#'
#print(S)
# R = [[0] * (W+2) for _ in range(H+2)]
# L = [[0] * (W+2) for _ in range(H+2)]
# U = [[0] * (W+2) for _ in range(H+2)]
# D = [[0] * (W+2) for _ in range(H+2)]
dp = [[0] * (W+2) for _ in range(H+2)]
start = 0
maxdp = 0
for h in range(1,H+1):
    flag = False
    for w in range(W+2):
        if S[h][w] == '#' :
            if flag == False :
                start = w
            else:
                for i in range(start+1,w):
                    dp[h][i] += w - i - 1
                    dp[h][i] += i - start - 1
                    if dp[h][i] > maxdp:
                        maxdp = dp[h][i]
                flag = False
                start = w
        else:
            flag = True
for w in range(1,W+1):
    for h in range(H+2):
        if S[h][w] == '#':
            if flag == False:
                start = h
            else:
                for i in range(start+1,h):
                    dp[i][w] += h - i - 1
                    dp[i][w] += i - start -1
                    if dp[i][w] > maxdp:
                        maxdp = dp[i][w]
                flag = False
                start = h
        else:
            flag = True
print(maxdp+1)


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

int main() {
  string s;
  cin >> s;
  
  bool flg = true;
  for(int i = 0; i < s.size(); i++) {
    if(i % 2 == 0) {
      if(s.at(i) == 'L') flg = false;
    } else {
      if(s.at(i) == 'R') flg = false;
    }
  }
  if(flg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 200005
#define ll long long
#define db double
#define pb push_back
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,a,b,ecnt,last[N],fa[N],flag,top;ll Max1,Max2,l,r,mid;
struct node
{
	ll x,y;
	friend bool operator<(node t1,node t2) {return t1.x<t2.x||t1.x==t2.x&&t1.y<t2.y;}
}sta[N];
std::vector<node>S[N];
struct road{int to,v,nex;}e[N];
void adde(int u,int v,int w) {e[++ecnt]=(road){v,w,last[u]},last[u]=ecnt;}
void dfs(int x,ll d=0)
{
	if(d>Max1) Max2=Max1,Max1=d;
	else Max2=max(Max2,d);
	for(int k=last[x];k;k=e[k].nex) dfs(e[k].to,d+e[k].v);
}
void Solve(int x)
{
	if(flag) return;
	int to1=0,to2=0;S[x].clear();
	for(int k=last[x];k;k=e[k].nex)
	{
		to1?to2=e[k].to:to1=e[k].to;
		for(int i=0,sz=S[e[k].to].size();i<sz;i++)
			S[e[k].to][i].x+=e[k].v,S[e[k].to][i].y+=e[k].v;
	}
	if(!to1) return void(S[x].pb({0,0}));
	int sz1=S[to1].size(),sz2=S[to2].size();
	if(sz1>sz2) std::swap(to1,to2),std::swap(sz1,sz2);
	std::reverse(S[to2].begin(),S[to2].end());
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].x+S[to2][j].y>mid;j--);
		if(~j) sta[++top]={S[to2][j].x,S[to1][i].y};
	}
	std::reverse(S[to1].begin(),S[to1].end());
	std::reverse(S[to2].begin(),S[to2].end());
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].y+S[to2][j].x>mid;j--);
		if(~j) sta[++top]={S[to1][i].x,S[to2][j].y};
	}
	if(!top) return void(flag=1);
	std::sort(sta+1,sta+1+top);
	node tmp;S[x].pb(tmp=sta[1]);
	for(int i=2;i<=top;i++) if(sta[i].x>tmp.x&&sta[i].y<tmp.y) tmp=sta[i],S[x].pb(tmp);
	top=0;
}
bool Judge()
{
	flag=0;
	for(int i=n;i;i--) Solve(i);
	return !flag;
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&a,&b),adde(a,i,b);
	dfs(1);
	for(l=0,r=Max1+Max2;l<r;) mid=l+r>>1,Judge()?r=mid:l=mid+1;
	printf("%lld\n",l);
	return 0;
}

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

using namespace std;

int dp[3005][3005];
string s, t;

void dfs(int i, int j){
    if(i == 0 || j == 0)
        return;
    if(s[i - 1] != t[j - 1]){
        if(dp[i - 1][j] >= dp[i][j - 1]) dfs(i - 1, j);
        else dfs(i, j - 1);
    }
    else{
        dfs(i - 1, j - 1);
        cout << s[i - 1];
    }
}

int main()
{
    getline(cin, s);
    getline(cin, t);
    int n = int(s.size()), m = int(t.size());
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
        }
    }
    dfs(n, m);
    return 0;
}


Measured memory_bytes: 35840
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll N, M;
cin >> N >> M;
    ll ans = 0;
    ll x = min(N, M / 2);
    M -= x * 2;
    ans += x;
    ans += M / 4;
    cout << ans << endl;
    return 0;
}

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

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



signed main(){

	string s;
	int K;
	cin >> s;
	cin >> K;

	for(int i=0; i<s.length(); i++){
		if('z'-s[i]+1 <= K && s[i]!='a'){
			K-='z'-s[i]+1;
			s[i] = 'a';
		}
	}
	s[s.length()-1] += K%26;
	if(s[s.length()-1] > 'z')
		s[s.length()-1] -= 26;

	cout << s << endl;

	return 0;
}


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

const long long INF = 1LL << 60;

int LIS(const vector<long long> &a) {
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for (int i = 0; i < N; ++i) {
        auto it = upper_bound(dp.begin(), dp.end(), a[i]);
        *it = a[i];
    }

    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main() {
    int N;
    cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    reverse(a.begin(), a.end());
    cout << LIS(a) << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=1e5;
long bit[MAX_N+1],n;

LL sum(int i){
    LL s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

int add(long i,long x){
    while(i<=n){
        bit[i]+=x;
        i+=i&-i;
    }
    return 0;
}

int main(){
    CLR(bit);
    cin>>n;
    vector<long>a(n);
    REP(i,n){
        cin>>a[i];
        add(i+1,a[i]);
    }
    LL cnt1=0;
    FOR(i,1,n+1){
        if(sum(i)==0){
            cnt1++;
            if(i%2)add(i,1);
            else add(i,-1);
        }else{
            if(i%2&&sum(i)<0){
                cnt1+=abs(sum(i))+1;
                add(i,abs(sum(i))+1);
            }else if(i%2==0&&sum(i)>0){
                cnt1+=abs(sum(i))+1;
                add(i,-abs(sum(i))-1);
            }
        }
    }
    CLR(bit);
    REP(i,n){
        add(i+1,a[i]);
    }
    LL cnt2=0;
    FOR(i,1,n+1){
        if(sum(i)==0){
            cnt2++;
            if(i%2==0)add(i,1);
            else add(i,-1);
        }else{
            if(i%2==0&&sum(i)<0){
                cnt2+=abs(sum(i))+1;
                add(i,abs(sum(i))+1);
            }else if(i%2&&sum(i)>0){
                cnt2+=abs(sum(i))+1;
                add(i,-abs(sum(i))-1);
            }
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
    return 0;
}

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

int main(){
  int n,k;cin >> n>>k;
  
  int ans = 0;
  int h;
  for(int i=0; i<n; i++){
    cin >> h;
    if(h>=k)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc147/tasks/abc147_c
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
const int SZ = 16;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, ans = 0;
    cin >> N;
    vector<vector<int>> t(N), f(N);
    REP(i, N) {
        int A;
        cin >> A;
        REP(j, A) {
            int x, y;
            cin >> x >> y;
            if (y == 1) {
                t[i].emplace_back(x - 1);
            } else {
                f[i].emplace_back(x - 1);
            }
        }
    }
    REP(i, (1LL) << N) {
        bitset<SZ> bt, bf;
        // 矛盾したらダメ
        bool flag = true;
        REP(j, N) {
            if (i & (1LL << j)) {
                // trueリスト
                for (auto &x : t[j]) {
                    if (!(i & (1LL << x))) {
                        flag = false;
                        break;
                    }
                    bt.set(x);
                }
                // falseリスト
                for (auto &x : f[j]) {
                    if ((i & (1LL << x))) {
                        flag = false;
                        break;
                    }
                    bf.set(x);
                }
            }
        }
        REP(j, N) {
            if (bt[j] & bf[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans = max(ans, __builtin_popcount(i));
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000000007;
int n,m;
ll fac[100005],inv[100005],a[20],b[20],d[20][100005],ans[100005];

ll C(ll x,ll y){return x<y?0:fac[x]*inv[y]%cys*inv[x-y]%cys;}
ll mod(ll x){return x>=cys?x-cys:x;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint(); m=readint();
	fac[0]=inv[0]=1;
	for(int i=1;i<=(1<<n);i++) fac[i]=fac[i-1]*i%cys;
	inv[1<<n]=qpow(fac[1<<n],cys-2);
	for(int i=(1<<n)-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	for(int i=1;i<=m;i++) a[i]=readint();
	reverse(a+1,a+m+1);
	for(int i=1;i<=n;i++) b[i]=1<<(i-1);
	d[0][0]=1;
	for(int i=1;i<=m;i++){
		for(int j=0;j<(1<<n);j++){
			d[i][j]=d[i-1][j];
			int now=0;
			for(int k=1;k<=n;k++) if((j>>(k-1))&1) now+=b[k];
			for(int k=1;k<=n;k++){
				if(!((j>>(k-1))&1)) continue;
				d[i][j]=mod(d[i][j]+d[i-1][j^(1<<(k-1))]*C((1<<n)-a[i]-now+b[k],b[k]-1)%cys*fac[b[k]]%cys);
			}
		}
	}
	ll ret=0;
	for(int i=0;i<(1<<n);i++){
		int now=0,cnt=0;
		for(int j=1;j<=n;j++) if((i>>(j-1))&1) now+=b[j],cnt++;
		ans[i]=d[m][i]*fac[(1<<n)-now-1]%cys;
		for(int j=1;j<=n;j++) if(!((i>>(j-1))&1)) ans[i]=ans[i]*inv[b[j]]%cys*fac[b[j]]%cys;
		if(cnt&1) ret=mod(ret+cys-ans[i]);
		else ret=mod(ret+ans[i]);
	}
	printf("%lld\n",ret*(1<<n)%cys);
	return 0;
}

Measured memory_bytes: 14592
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int n,m;
    
    cin >> n >> m;
    vector<int> v(n,0);
    for (int i = 0; i < m; ++i)
    {
        int a,b;
        cin >>a >>b;
        v[a-1]++;
        v[b-1]++;
    }

    for (int i = 0; i < n; ++i)
    {
        cout <<v[i] <<endl;
    }
    
    return 0;
}






Measured memory_bytes: 256
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();    
        int x = sc.nextInt();    
        int t = sc.nextInt();
        if (n % x == 0) {
            System.out.println(n / x * t);
        } else {
            System.out.println((n / x + 1)* t);
        }
    }
}


Measured memory_bytes: 35916
def main():
    h, w, k = map(int, input().split())
    s = [input().rstrip() for _ in range(h)]
    t = [[0]*(w+1) for _ in range(h+1)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "1":
                t[i+1][j+1] = 1
    for i in range(1, h+1):
        for j in range(1, w+1):
            t[i][j] += t[i-1][j] + t[i][j-1] - t[i-1][j-1]
#    for i in range(h+1):
#        print(t[i])
    ans = 10**9
    for i in range(2**(h-1)):
        a, b = 0, 0
        buf = [0]
        for j in range(h-1):
            if ((1<<j) & i) > 0:
                a += 1
                buf.append(j+1)
        buf.append(h)
        x = 0
        F = True
        for j in range(1, w+1):
            f = False
            for l in range(1, len(buf)):
                if t[buf[l]][j] - t[buf[l-1]][j] - t[buf[l]][x] + t[buf[l-1]][x] > k:
                    f = True
            if f:
                b += 1
                x = j-1
                for l in range(1, len(buf)):
                    if t[buf[l]][j] - t[buf[l-1]][j] - t[buf[l]][j-1] + t[buf[l-1]][j-1] > k:
                        F = False
                        break
        if a + b < ans and F:
#            print(a, b, i, x)
            ans = a + b
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

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

    long long ans = LLONG_MAX;

    for (long long i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ans = min(ans, i + n / i - 2);
        }
    }
    cout << ans << "\n";
    return 0;
}


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

namespace ConsoleApp1
{

    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var ds = new int[3];
            for (int i = 0; i < 3; i++)
            {
                ds[i] = int.Parse(s[i]);
            }
            Console.WriteLine(Math.Min(ds[0] * ds[1], ds[2]));
            /*
            int count = 0;
            Array.Sort(ds);
            if (ds.Length % 2 == 1)
            {
                Console.WriteLine(0);
            }
            else if (ds[ds.Length / 2 - 1] == ds[ds.Length / 2])
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(ds[ds.Length / 2] - ds[ds.Length / 2 - 1]);
            }
            */

            

#if DEBUG
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
        }
    }
}


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

def main():
    H,W,D = map(int,input().split())
    A = [None] * (H*W+1)
    for i in range(H):
        j = 1
        for x in input().split():
            # [消費魔力の総和, 座標]
            A[int(x)] = [0,(i+1,j)]
            j += 1

    # 累積和を求める O(H*W)
    for i in range(1,H*W+1):
        if i <= D:
            continue
        A[i][0] += A[i-D][0]
        A[i][0] += abs(A[i][1][0] - A[i-D][1][0])
        A[i][0] += abs(A[i][1][1] - A[i-D][1][1])

    # クエリ O(1)
    Q = int(input())
    for _ in range(Q):
        L, R = map(int,input().split())

        print(A[R][0] - A[L][0])

if __name__ == "__main__":
    main()

Measured memory_bytes: 24132
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const MOD: i64 = 1000000007;

fn main(){
    input!{
        N: i32,
        A: i64,
        B: i64,
        X: [i64; N],
    }

    let mut ans: i64 = 0;

    for i in 0..N-1 {
        ans += std::cmp::min((X[(i + 1) as usize] - X[i as usize]) * A, B);
    }

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

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

int main(){
 int a;
 int b;
 int c;
 int w;
cin >> a>>b>>c;
if (a>b){
w=a;
a=b;
b=w;
}
if (b>c){
w=b;
b=c;
c=w;
}
if (a>b){
w=a;
a=b;
b=w;
}
cout << a<< " "<<b<<" "<<c<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        string s=to_string(i);
        if(s.size()%2==1) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	string A[3];
	FOR(i, 0, 3) cin >> A[i];
	
	string ans;
	FOR(i, 0, 3) {
		ans += toupper(A[i][0]);
	}

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


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

template <class Monoid>
struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid UNITY;
  int SIZE_R;
  vector<Monoid> dat;

  SegTree(int n, const Func f, const Monoid &unity) : F(f), UNITY(unity) {
    init(n);
  }
  void init(int n) {
    SIZE_R = 1;
    while (SIZE_R < n) SIZE_R *= 2;
    dat.assign(SIZE_R * 2, UNITY);
  }

  /* set, a is 0-indexed */
  void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
  void build() {
    for (int k = SIZE_R - 1; k > 0; --k) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }

  /* update a, a is 0-indexed */
  void update(int a, const Monoid &v) {
    int k = a + SIZE_R;
    dat[k] = v;
    while (k >>= 1) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }

  /* get [a, b), a and b are 0-indexed */
  Monoid get(int a, int b) {
    Monoid vleft = UNITY, vright = UNITY;
    for (int left = a + SIZE_R, right = b + SIZE_R; left < right;
         left >>= 1, right >>= 1) {
      if (left & 1) vleft = F(vleft, dat[left++]);
      if (right & 1) vright = F(dat[--right], vright);
    }
    return F(vleft, vright);
  }
  inline Monoid operator[](int a) { return dat[a + SIZE_R]; }

  /* debug */
  void print() {
    for (int i = 0; i < SIZE_R; ++i) {
      cout << (*this)[i];
      if (i != SIZE_R - 1) cout << ",";
    }
    cout << endl;
  }
};

void solve(int N, std::vector<int> h, std::vector<long long> a) {
  SegTree<int64> dp(
      N + 1, [](int64 a, int64 b) { return max<int64>(a, b); }, 0LL);
  dp.update(h[0], a[0]);
  int64 res = a[0];
  for (int i = 1; i < N; ++i) {
    int ht = h[i];
    int64 bmax = dp.get(0, ht) + a[i];
    dp.update(ht, bmax);
    res = max(res, bmax);
  }
  cout << res << endl;
}

int main() {
  int N;
  cin >> N;
  std::vector<int> h(N);
  for (auto &&v : h) {
    cin >> v;
  }
  std::vector<long long> a(N);
  for (auto &&v : a) {
    cin >> v;
  }
  solve(N, std::move(h), std::move(a));
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void dfs(const vvi& g,const vl& a,int p,int u,vl& xs)
{
	int m=0;
	for(int v:g[u]) if(v!=p) m++;
	if(m==0){
		xs[u]=a[u];
		return;
	}
	ll sum=0,mx=0;
	for(int v:g[u]) if(v!=p){
		dfs(g,a,u,v,xs);
		sum+=xs[v];
		mx=max(mx,xs[v]);
	}
	xs[u]=2*a[u]-sum;
	if(xs[u]<0||sum-xs[u]<0||(sum-xs[u])/2>sum-mx)
		throw "invalid";
	if(u==0){
		if(m==1&&xs[u]!=sum)
			throw "invalid(root)";
		if(m>1&&xs[u]>0)
			throw "invalid(root)";
	}
}

bool solve(vvi g,vl a)
{
	int n=a.size();
	vl xs(n);
	try{
		dfs(g,a,-1,0,xs);
		return true;
	}
	catch(...){
		return false;
	}
}

int main()
{
	// 3:37
	for(int n;cin>>n&&n;){
		vl a(n);
		rep(i,n) cin>>a[i];
		vvi g(n);
		rep(i,n-1){
			int u,v; cin>>u>>v; u--,v--;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		cout<<(solve(g,a)?"YES":"NO")<<endl;
	}
}


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

#define endl '\n'

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

    long long a,b,k; cin >> a >> b >> k;

    long long x = min(k, a);
    a -= x;
    k -= x;
    x = min(k,b);
    b -=x;
    k-=x;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
N=int(input())
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[N-1])

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

int main(){
	LL n,a,b;
	cin>>n>>a>>b;
	LL sum = a+b;
	LL res = n/sum;
	res = res*a;
//	cout<<res<<"\n";
//	cout<<res%sum<<"\n";
	res += min(n%sum,a);
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))

print("Yes" if dice1.issame(dice2) else "No")

Measured memory_bytes: 6784
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
char b;

void solve() {

	cin >> b;
	char ans;

	if (b == 'A') ans = 'T';
	if (b == 'T') ans = 'A';
	if (b == 'C') ans = 'G';
	if (b == 'G') ans = 'C';

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

int  main()
{
	string s; cin >> s;
	cout << s.front() << s.size()-2 << s.back() << endl;
	return (0);
}

Measured memory_bytes: 256
# include <iostream>
# define pf push_front
# define pb push_back
# define mp make_pair
# define pr printf
# define se second
# define si size()
# define sc scanf
# define fi first
# define er erase
# define be begin
# define ss size
# define Int __int64
# define INF 100000000000000008
# define MOD 1000000007
# define MN 500500
# define eps 0.0000000000000000018
# define mem(a) memset(a,0,sizeof(a))
# define cpy(b,a) memcpy(b,a,sizeof(a))
#define fast ios_base::sync_with_stdio(false)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;
char a1[55][55] = {'#'};
char a[55][55]= {'.'};
int main() {
	int m,n,i,j,ans;
	cin>>n>>m;
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			ans=0;
			if(a[i][j]=='.'){
				if(i>0 && a[i-1][j]=='#')ans++;
				if(j>0 && a[i][j-1]=='#')ans++;
				if(i>0 && j>0 && a[i-1][j-1]=='#')ans++;
				if(i>0 && j+1<m && a[i-1][j+1]=='#')ans++;
				if(i+1<n && j>0 && a[i+1][j-1]=='#')ans++;
				if(j+1<m && a[i][j+1]=='#')ans++;
				if(i+1<n && a[i+1][j]=='#')ans++;
				if(i+1<n && j+1<m && a[i+1][j+1]=='#')ans++;
				a1[i][j]=ans +48;
			}
			else a1[i][j]=a[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)cout<<a1[i][j];
			cout<<endl;
	}
	return 0;
}
/* and its only us now */


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi  std::vector<std::vector<int> >
#define vvl  std::vector<std::vector<long long> >
typedef long long int ll;
using namespace std;

#define MAX_N 100000
int par[MAX_N];
int size[MAX_N];
void init(int nu) {
  for(int iu=0;iu<nu;iu++){
    par[iu] = iu;
    size[iu] = 1;
  }
}
int find(int xu){
  if(par[xu] == xu) return xu;
  return par[xu] = find(par[xu]);
}
void unite(int xu, int yu){
  xu=find(xu);
  yu=find(yu);
  if(xu == yu) return;
  if(size[xu] < size[yu]){
    par[xu] = yu;
    size[yu] += size[xu];
  }else{
    par[yu] = xu;
    size[xu] += size[yu];
  }
}
bool same(int xu, int yu){
  return find(xu) == find(yu);
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  std::cin >> N >> M;
  init(N+1);
  std::vector<ll> convenience(M+1);
  vvi bridge = vv(M, 2, 0, int);
  range(i, M) std::cin >> bridge[i][0] >> bridge[i][1];
  convenience[M] = 0;
  for(int i=M-1;i>=0;i--){
    if(!same(bridge[i][0], bridge[i][1])){
      convenience[i] = convenience[i+1] + size[par[bridge[i][0]]] * size[par[bridge[i][1]]];
      unite(bridge[i][0], bridge[i][1]);
    }else{
      convenience[i] = convenience[i+1];
    }
  }
  ranges(i, 1, M+1) std::cout << convenience[0] - convenience[i]<< '\n';
  return 0;
}


Measured memory_bytes: 8320
using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double sumnum = 0;
            int Min = 1000000;
            int Max = -1000000;

            int inputnum = int.Parse(Console.ReadLine());


            string[] objectdata = Console.ReadLine().Split(' ');

            for(int i = 0; i < inputnum; i++)
            {
                int castdata = int.Parse(objectdata[i]);


                if (Min > castdata) Min = castdata;


                if (Max < castdata) Max = castdata;

                sumnum += castdata;
            }

            Console.WriteLine("{0} {1} {2}", Min, Max, sumnum);
        }

    }

}

Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> K >> D;
    X = abs(X);
    ll k = X / D;
    if (k >= K) {
        cout << X - K * D << endl;
    } else {
        if ((k - K) & 1) {
            ll tmp = X % D;
            cout << abs(tmp - D) << endl;
        } else {
            ll tmp = X % D;
            cout << abs(tmp) << endl;
        }
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<string,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
map<string,int> mp;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
for(int d=1;d<s.size();d++){
    int cnt=0;
    int now=-1;
    for(int i=0;i<s.size();i++){
        if(i+d<s.size()&&s[i]==s[i+d]&&i!=now){
            if(cnt==0)now=i+d;
            cnt++;
        }
        else{
            ans=max(cnt,ans);
            cnt=0;
            now=-1;
        }
    }
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
/******************
*  Writer: Oh no  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
bool d8(int n){
	int res=0;
	for(int i=1;i<=n;i++){
		if(n%i==0)res++;
	}
	return res==8;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans=0,n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(d8(i)&&i%2)ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int c = in.nextInt();
            int k = in.nextInt();
            int[] t = new int[n];
            for (int i = 0; i < n; ++i) {
                t[i] = in.nextInt();
            }
            Arrays.sort(t);
            int people = 0;
            int start = 0;
            int res = 0;
            for (int tt : t) {
                if (people > 0 && tt - start > k) {
                    ++res;
                    people = 0;
                }
                if (people == 0) {
                    start = tt;
                }
                ++people;
                if (people == c) {
                    ++res;
                    people = 0;
                }
            }
            if (people > 0) {
                ++res;
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 36844
#include <stdio.h>
void Heap(int, int);
int H, A[251];
int main(){
        int i;

        scanf("%d", &H);
        for(i = 1; i<=H; i++) {
                scanf("%d", &A[i]);
        }
        Heap(1, H);
        return 0;
}


void Heap(int j, int M) {
        A[0] = 0;
        for(j = 1; j <= M; j++) {
                printf("node %d: key = %d, ", j, A[j]);

                if(j/2 >= 1) printf("parent key = %d, ", A[j/2]);
                if(2 * j <= M) printf("left key = %d, ", A[j*2]);
                if(2 * j +1 <= M) printf("right key = %d, ", A[j*2+1]);
              //  printf(" ");
                printf("\n");
        }
}

Measured memory_bytes: 600
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

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

  LL N,K;
  cin >> N >> K;

  vector<LL> v(N);

  REP(i,N){
    cin >> v[i];
  }

  BACKSORT(v);

  vector<bool> KKK(K + 1, false);

  KKK[0] = true;

  set<LL> fuhituyou;

  REP(i,N){
    fuhituyou.insert(v[i]);
    REP(kk,K){
      LL j = K - kk-1;
      if (KKK[j])
      {
        if(j+v[i]>=K){
          //hituyou
          fuhituyou.erase(v[i]);
        }
        else
        {
          KKK[j + v[i]] = true;
        }
      }
    }
  }

  LL cnt = 0;

  SORT(v);

  v.push_back(-1);

  REP(i,N+1){
    if(fuhituyou.count(v[i])==0){
      cout << i << endl;
      break;
    }
    if(v[i]==-1){
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
int main() {
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;

  int score = 0;
  char h[N];
  for (int i = 0; i < N; i++) {
    char t = T[i];

    char p = 'x';
    if (i - K >= 0) {
      p = h[i - K];
    }

    char w;
    int s;
    switch(t) {
      case 'r':
        w = 'p';
        s = P;
        break;
      case 's':
        w = 'r';
        s = R;
        break;
      case 'p':
        w = 's';
        s = S;
        break;
      default:
        break;
    }

    if (p != w) {
      h[i] = w;
      score += s;
    } else {
      h[i] = 'x';
    }
  }

  cout << score << endl;

  return 0;
}


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

int main(int argc, const char * argv[]) {
    int N, Y; cin >> N >> Y;
    
    int tenThou, fiveThou;
    for(tenThou = 0; tenThou <= (int) Y / 10000; tenThou++) {
        for(fiveThou = 0; fiveThou <= (int) Y / 5000; fiveThou++) {
            if((N-tenThou-fiveThou) >=0 && ((tenThou * 10000) + (fiveThou * 5000) + ((N-tenThou-fiveThou)*1000) == Y)) {
                cout << tenThou << " " << fiveThou << " " << N - tenThou - fiveThou << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 888
/**
 * Infected Computer
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int m = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | m) == 0) break;

			boolean[] ps = new boolean[n + 1];
			Queue<int[]> ts = new PriorityQueue<int[]>(11, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return o1[0] - o2[0];
				}
			});

			StringTokenizer st;
			for (int i = 0; i < m; i++) {
				st = new StringTokenizer(br.readLine());
				int t, s, d;
				t = parseInt(st.nextToken());
				s = parseInt(st.nextToken());
				d = parseInt(st.nextToken());
				ts.offer(new int[]{t, s, d});
			}

			ps[1] = true;
			int count = 1;
			while (!ts.isEmpty()) {
				int[] t = ts.poll();
				if (ps[t[1]] && !ps[t[2]]) {
					ps[t[2]] = true;
					count++;
				}
			}
			System.out.println(count);
		} //end while
	} //end main
}

Measured memory_bytes: 58500
#pragma comment(linker, "/STACK: 2000000")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
#define PI 3.14159265358979
const ll mod=998244353;
int n, a[200010], ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i];
    sort(a+1, a+n+1, greater<int>());
    for(int i=2; i<=n; i++) ans+=a[(i+1)/2];
    cout<<ans;
}



Measured memory_bytes: 5188
#include<bits/stdc++.h>
#define int long long
using namespace std;
int l,r,mid,ans,n,k,a[200010],maxn=0;
int jyz(int x)
{
    int sp=0;
    for (int i=1;i<=n;i++) sp+=(a[i]-1)/x;
    return sp;
}
signed main()
{
    ;;;;;
    cin>>n>>k;
    for (int i=1;i<=n;i++) scanf("%lld",&a[i]),maxn=max(maxn,a[i]);
    l=1,r=maxn;
    while (l!=r)
    {
        mid=(l+r)/2;
        if (jyz(mid)<=k) r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 5316
a,b = map(int,input().split())
a_l = ""
b_l = ""
for i in range(b):
  a_l += str(a)
for j in range(a):
  b_l += str(b)
if a>b:
  print(b_l)
elif b<a:
  print(a_l)
else:
  print(a_l)

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

int main() {
  // 入力
  int N, M, C;
  cin >> N >> M >> C;

  int B[M];
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  int A[N][M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  //処理
  int ans = 0;
  int source;
  for (int i = 0; i < N; i++) {
    source = C;
    for (int j = 0; j < M; j++) {
      source += (A[i][j] * B[j]);
    }
    if (source > 0) {
      ans++;
    }
  }

  //出力
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define all(n)      (n).begin(), (n).end()
#define ll long long 
#define PI 3.14159265358979323846

void solve(){
	int r; cin >> r;
	long double ans;
	ans = (2.000000000000 * PI * (long double)r);
	cout << ans << endl;
	

}


int main (){
	
	//Write from here.
	
		solve();
	
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>

using namespace std;

/** Problem0060 : Card Game **/
int main()
{
	int c1, c2, c3, yes, no;
	
	while (cin >> c1 >> c2 >> c3) {
		yes=0; no=0;
		for (int i=0; i<10; i++) {
			if (i+1 != c1 && i+1 != c2 && i+1 != c3) {
				if (c1+c2+i+1 <= 20) {
					yes++;
				} else {
					no++;
				}
			}
		}
		cout << (yes>=no ? "YES" : "NO") << endl;
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B; cin >> N >> A >> B;
    int cnt0=0,cnt1=0,cnt2=0;
    for (;N--;){
        int P; cin >> P;
        if (P<=A) ++cnt0;
        else if (P<=B) ++cnt1;
        else ++cnt2;
    }
    cout << min({cnt0,cnt1,cnt2}) << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	final int N = 4;
	final int N2 = 16;
	final int LIMIT = 45;

	class Puzzle {
		int[] board = new int[N2];
		int space, md;
		Puzzle() {}
		Puzzle(Puzzle p) {
			space = p.space;
			md = p.md;
			for (int i = 0; i < N2; i++)
				board[i] = p.board[i];
		}
		int getAllMD() {
			int sum = 0;
			for (int i = 0; i < N2; i++) {
				if (board[i] == N2) continue;
				sum += mdt[i][board[i] - 1];
			}
			return sum;
		}
		void swap(int next, int cur) {
			int tmp = this.board[cur];
			this.board[cur] = this.board[next];
			this.board[next] = tmp;
		}
	}

	int limit = 0;
	int[] path = new int[LIMIT];
	int[][] mdt = new int[N2][N2];
	Puzzle state = null;
	char[] dir = {'r', 'u', 'l', 'd'};
	int[] dx = { 0, -1, 0, 1 };
	int[] dy = { 1, 0, -1, 0 };

	void run() {
		Scanner scan = new Scanner(System.in);
		
		for (int i = 0; i < N2; i++)
			for (int j = 0; j < N2; j++)
				mdt[i][j] = Math.abs(i / N - j / N) + Math.abs(i % N - j % N);

		Puzzle p = new Puzzle();
		
		for (int i = 0; i < N2; i++) {
			p.board[i] = scan.nextInt();
			if (p.board[i] == 0) {
				p.board[i] = N2;
				p.space = i;
			}
		}
		iterative_deepening(p);
	}
	boolean dfs(int depth, int prev) {
		if (state.md == 0) return true;
		if (depth + state.md > limit) return false;

		int sx = state.space / N;
		int sy = state.space % N;
		for (int i = 0; i < 4; i++) {
			int tx = sx + dx[i];
			int ty = sy + dy[i];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			if (Math.max(prev, i) - Math.min(prev, i) == 2) continue;
			Puzzle p = new Puzzle(state);
			state.md -= mdt[tx * N + ty][state.board[tx * N + ty] - 1];
			state.md += mdt[sx * N + sy][state.board[tx * N + ty] - 1];
			state.swap(tx * N + ty, sx * N + sy);
			state.space = tx * N + ty;
			if (dfs(depth + 1, i)) {
				path[depth] = i;
				return true;
			}
			state = p;
		}
		return false;
	}
	void iterative_deepening(Puzzle p) {
		p.md = p.getAllMD();
		
		for (limit = p.md; limit <= LIMIT; limit++) {
			state = new Puzzle(p);
			if (dfs(0, -100)) {
				System.out.println(limit);
				return;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}




Measured memory_bytes: 282968
let rec select acc trace = function
  | [] -> acc
  | x :: xs -> select ((trace, x, xs) :: acc) (x :: trace) xs
let select xs = select [] [] xs

let rec solve acc = function
  | [] -> acc
  | bs ->
      select bs
      |> List.rev
      |> List.mapi (fun i x -> i, x)
      |> List.rev
      |> List.find (fun (i, (hd, b, tl)) -> i + 1 = b)
      |> (fun (_, (hd, b, tl)) -> solve (b :: acc) (List.rev_append hd tl))
let solve = solve []

let () = Scanf.scanf "%d\n" @@ fun n ->
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  try List.iter (Printf.printf "%d\n") @@ solve @@ Array.to_list bs
  with Not_found -> print_endline "-1"



Measured memory_bytes: 1408