akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define M 100000007
typedef pair<int,int> P;
/*int main(){
	cout<<8979879<<endl;
}*/
int ri[3001][3001];
int main(void){
	int n,m,k,
		i,j,
		mx,t,ans,
		a[100001],b[100001],l[100001],s[3000],
		d[3001];
		
	priority_queue<P,vector<P>,greater<P> > que;
	
	cin>>n>>m>>k;
	for(i=0;i<m;i++) cin>>a[i]>>b[i]>>l[i];
	for(i=0;i<k;i++) cin>>s[i];
//	for(i=0;i<k;i++) cout<<s[i]<<endl;
	
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) ri[i][j]=M;
	for(i=0;i<m;i++) ri[a[i]][b[i]]=l[i],ri[b[i]][a[i]]=l[i];
/*	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)cout<<ri[i][j]<<' ';
		cout<<endl;
	}*/
	
	int leng[3001];
	for(i=1;i<=n;i++) leng[i]=M;
	for(i=0;i<k;i++){
		leng[s[i]]=0;
		que.push(P(0,s[i]));
	}
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(leng[v]<p.first) continue;
		for(j=1;j<=n;j++){
			t=leng[v]+ri[v][j];
//			cout<<j<<' '<<leng[j]<<' '<<t<<endl;
			if(leng[j]>t){
				leng[j]=t;
//				cout<<leng[j]<<' '<<j<<endl;
				que.push(P(leng[j],j));
			}
		}
	}
/*	for(i=1;i<=n;i++) cout<<leng[i]<<' ';
	cout<<endl;*/
	ans=0;
	for(i=1;i<=n;i++){
		int mx=0,mi=M,y;
		double x;
		for(j=1;j<=n;j++){
			if(ri[i][j]!=M){
				if(leng[i]!=0){
					mx=max(mx,ri[i][j]+leng[j]);
					mi=min(mi,ri[i][j]+leng[j]);
				}
				else{
					mx=max(mx,ri[i][j]);
					mi=min(mi,ri[i][j]);
				}
			}
		}
		x=(double)(mx+mi)/2;
//		cout<<x<<' '<<mx<<' '<<mi<<endl;
		y=round(x);
		ans=max(ans,y);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 39652
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val list = readLine.split(" ").map(_.toInt).toList
        readInt
        readLine.split(" ").map(_.toInt).foreach { target =>
            if (search(list, len, target, 0)) println("yes") else println("no")
        }
    }
    def search(haystack: List[Int], len: Int, target: Int, count: Int): Boolean = {
        if (len == count) false
        else if (combinationExists(haystack, 0, target, count)) true
        else search(haystack, len, target, count + 1)
    }
    // haystack から count 個の要素を足し合わせて target になる組み合わせがあるかどうかを調べる。
    def combinationExists(haystack: List[Int], sum: Int, target: Int, count: Int): Boolean = {
        if (count == 0) {
            if (sum == target) true else false
        } else {
            haystack match {
                case Nil => false
                case x :: xs => {
                    if (sum > target) return false
                    if (combinationExists(xs, sum + x, target, count - 1)) true
                    else combinationExists(xs, sum, target, count)
                }
            }
        }
    }
}


Measured memory_bytes: 44288
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  int n;
  cin >> n;
  int seat[n] = { };
  cout << 0 << endl;
  string s;
  cin >> s;
  if(s != "Vacant"){
    if(s == "Male") seat[0] = 1;
    else seat[0] = -1;
    cout << n-1 << endl;
    string s;
    cin >> s;
    if(s != "Vacant"){ 
      if(s == "Male") seat[n-1] = 1;
      else seat[n-1] = -1;
      int f = 0, l = n-1;
      while(true){
        int m = (f+l)/2;
        cout << m << endl;
        string s;
        cin >> s;
        if(s == "Male") seat[m] = 1;
        else seat[m] = -1;
        if(s == "Vacant") break;
        if(((m-f)%2 == 0 && seat[m] != seat[f]) || ((m-f)%2 == 1 && seat[m] == seat[f])){
          l = m;
        }
        else f = m;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1236
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define mod 1000000007
#define sz(x) ((int) (x.size()))

using namespace std;

long long add(long long a, long long b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

long long mul(long long a, long long b) {
	return (a * b) % mod;
}

long long power(long long a, long long b) {
	if(b == 0) return 1;
	long long foo = power(a, b/2);
	foo = mul(foo, foo);
	if(b&1) return mul(a, foo);
	return foo;
}

long long F[200002];
long long IF[200002];

void calcFIF(int max_n) {
	F[0] = 1;
	for(int i=1; i<max_n; i++) F[i] = (F[i-1] * i) % mod;
	IF[max_n-1] = power(F[max_n-1], mod-2);
	for(int i=max_n-1; i>0; i--) IF[i-1] = (IF[i] * i) % mod;
}

long long get(int x, int y, int xx, int yy) {
	int R = xx - x;
	int L = yy - y;
	return mul(F[R+L], mul(IF[R], IF[L]));
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b, n, m;
	cin >> n >> m >> a >> b;
	calcFIF(200002);
	long long ans = 0;
	for(int i=0; i<n-a; i++) ans = add(ans, mul(get(0, 0, i, b-1), get(i, b, n-1, m-1)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

ans = None
d_ls = make_divisors(x)
for d in d_ls:
    for a in range(0, 1000):
        b = a-d
        c = a**5-b**5
        if c==x:
          ans = (a, b)
          break
    if ans is not None:
      break
print(ans[0], ans[1])

Measured memory_bytes: 9468
from collections import deque

def testcase_ends():
    n = int(input())
    if n == 0:
        return 1

    sub = [input().split() for i in range(n)]
    gamma = input()
    delta = input()

    q = deque()
    q.append((gamma, 0))
    res = 10000
    while q:
        s, i = q.popleft()
        for alpha, beta in sub:
            if alpha not in s: continue

            t = s.replace(alpha, beta)
            if t == delta:
                res = min(res, i+1)
                continue
            elif len(t) >= len(delta):
                continue

            q.append((t, i+1))

    if res == 10000: res = -1
    print(res)
    return 0

def main():
    while not testcase_ends():
        pass

if __name__ == '__main__':
    main()



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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,k,m;
  string s,t;
  cin >>k>>a>>b;
  m=a/k;
  if(a%k!=0)m++;
  if(k*m>b){
    cout <<"NG";
  }else{
    cout <<"OK";
  }
}

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

int main() {
    int a, b, c, d, maxv_BD, minv_BD, maxv_AC, minv_AC, cnt = 0;
    cin >> a >> b >> c >> d;
    maxv_BD = max(b, d);
    minv_BD = min(b, d);
    maxv_AC = max(a, c);
    minv_AC = min(a, c);
    for (int i = minv_AC; i <= minv_BD; i++) {
        if (i > maxv_AC) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
import math
#import collections
#from collections import deque
#from bisect import bisect_left
K = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
s = 0
d = 0
e = 0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            d = math.gcd(c,b)
            e = math.gcd(a,d)
            if a == b and b == c:
                s += e
            elif a != b and b != c :
                s += 6 * e
            else:
                s += 3 * e
print(s)

Measured memory_bytes: 9188
#include<iostream>
#include<queue>

using namespace std;

struct edge{
  int t,c,rev;
};

bool u[52][52][1<<10];

struct S{
  int g,r,c,b;
  bool operator<(S s)const{
    return c>s.c;
  };
};

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    int d[52]={},e[52];
    e[1]=0;
    e[n]=1000;
    int nalt[1234]={};
    int nth[52]={};
    for(int i=2;i<n;i++){
      cin>>d[i]>>e[i];
      nth[i]=nalt[e[i]]++;
    }
    vector<edge> G[52];
    while(m--){
      int a,b,c;
      cin>>a>>b>>c;
      if(e[a]<=e[b]){
	G[a].push_back({b,c,false});
      }
      if(e[b]<=e[a]){
	G[b].push_back({a,c,true});
      }
    }
    fill(**begin(u),**end(u),false);
    priority_queue<S> que;
    que.push({1,1,0,0});
    while(!que.empty()){
      auto c=que.top();
      if(c.g==n&&c.r==n)break;
      que.pop();
      if(u[c.g][c.r][c.b]++)continue;
      for(auto f:G[c.g]){
	if(f.rev)continue;
	int nb=(e[f.t]>e[c.r])?0:c.b;
	int nc=c.c+d[f.t]+f.c;
	if(e[f.t]>=e[c.r]){
	  if(!(nb>>nth[f.t]&1)){
	    nb|=1<<nth[f.t];
	  }else{
	    nc-=d[f.t];
	  }
	}
	if(!u[f.t][c.r][nb]){
	  que.push({f.t,c.r,nc,nb});
	}
      }
      for(auto f:G[c.r]){
	if(!f.rev)continue;
	int nb=(e[f.t]>e[c.g])?0:c.b;
	int nc=c.c+d[f.t]+f.c;
	if(e[f.t]>=e[c.g]){
	  if(!(nb>>nth[f.t]&1)){
	    nb|=1<<nth[f.t];
	  }else{
	    nc-=d[f.t];
	  }
	}
	if(!u[c.g][f.t][nb]){
	  que.push({c.g,f.t,nc,nb});
	}
      }
    }
    cout<<(que.empty()?-1:que.top().c)<<endl;
  }
}

Measured memory_bytes: 37692
def partition(A):
    p = 1
    r = len(A) - 1
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            key = A[i]
            A[i] = A[j]
            A[j] = key
    key = A[i + 1]
    A[i + 1] = A[r]
    A[r] = key
    print(' '.join(list(map(str, A[1:i + 1]))) + ' [' + str(A[i + 1]) + '] ' + ' '.join(list(map(str, A[i + 2:]))))
    return A, A[i + 1]

N = int(input())
X = list(map(int, input().split()))
N = [0]
N.extend(X)
partition(N)


Measured memory_bytes: 16388
#include <stdio.h>

int
main(void)
{
	int i, j, n, m;
	int a[100][1000];
	int b[1000];
	int c[1000];

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

	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &a[i][j]);

	for (i = 0; i < m; i++)
		scanf("%d", &b[i]);

	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			c[i] += a[i][j] * b[j];

	for (i = 0; i < n; i++)
		printf("%d\n", c[i]);

	return 0;
}



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

using namespace std;
char s[500005],t[500005];
char st[2000000];
int pre[2000000];
bool ab[500005];
int cnt[500005],sy[500005];

int main()
{
    scanf("%s",t);scanf("%s",s);
    int slen = strlen(s);int tlen = strlen(t);
    int alen = slen+1;
    memcpy(st,s,sizeof(char)*slen);
    st[slen] = '#';

    while(alen-slen-1<max(2*slen,2*tlen)){
        memcpy(st+alen,t,sizeof(char)*tlen);
        alen+=tlen;
    }

    for (int i = 1; i < alen; i++) {
    int j = pre[i - 1];
    while (j > 0 && st[i] != st[j]) j = pre[j - 1];
    if (st[i] == st[j]) j++;
    pre[i] = j;
  }
    int tlen2 = 2*tlen;
    for(int i=1;i<=tlen;++i){
        if(pre[alen-i]==slen) {
            ab[(tlen2-i-slen%tlen+1)%tlen] = true;
        }
    }

    bool minf = false;
    for(int i=0;i<tlen&&!minf;++i){
        int ncnt = 1,j=i;
        while(ab[j]&&cnt[j]<ncnt){
            if(sy[j]==i+1){
                minf = true;break;
            }
            cnt[j]=ncnt++;
            sy[j] = i+1;
            j=(j+slen)%tlen;
        }
    }

    int ans = 0;
    for(int i=0;i<tlen;++i) ans = max(ans,cnt[i]);
    if(minf) ans = -1;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define mp make_pair
#define frab(i, a, b) for (int i = a; i < b; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1000000007;
const ll P1 = 17;
const ll P2 = 19;
const ld PI = acos(-1);
const ll MAX = 63211236 + 10;
const ll INF = 1e9 + 10;
const ld EPS = 1e-9;
const int M = 5e3 + 2;
const int N = 305;

int a[N][N];
bool ok[N][N];
bool trash[N];
int b[N];

int main() {
    //freopen("a.in", "r", stdin);
    int n, m;
    cin >> n >> m;
    fr(i, n)
        fr(j, m)
            cin >> a[i][j];
    int ans = n;
    fr(i1, m - 1) {
        fill(b, b + m + 1, 0);
        fr(i, n) {
            fr(j, m)
                if (!trash[a[i][j]]) {
                    b[a[i][j]]++;
                    break;
                }
        }
        int t = max_element(b + 1, b + m + 1) - b;
        ans = min(ans, b[t]);
        trash[t] = true;
    }
    cout << ans;
}


Measured memory_bytes: 640
/*
トポロジカルソートができる⇔DAG(閉路がない有向グラフ)である

vector<int>を引数にすることを前提にしている

O(V+E)

edgeなどを使う場合には、eの所をe.toにする必要がある
（逆に言えばそれだけでいい）
verify:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B
参考:
https://ferin-tech.hatenablog.com/entry/2017/01/24/184750
*/

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
using Graph=vector<vector<int>>;

//DAGではない場合、空のvectorを返す
template<typename G>
vector<int> TopologicalSort(G &v){
    int sz=(int)v.size();
    vector<int> cnt(sz,0);
    vector<int> ret;
    stack<int> st;
    for(int i=0;i<sz;i++){
        for(auto &e:v[i]){
            cnt[e]++;
        }
    }
    for(int i=0;i<sz;i++){
        if(cnt[i]==0) st.push(i);
    }
    while(!st.empty()){
        int now=st.top(); st.pop();
        ret.push_back(now);
        for(auto &e:v[now]){
            cnt[e]--;
            if(cnt[e]==0) st.push(e);
        }
    }
    if(ret.size()!=sz) return vector<int>();
    return ret; 
}

signed main(){
    int v,e;
    cin>>v>>e;
    Graph g(v);
    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
    }
    vector<int> ret=TopologicalSort(g);
    for(auto i:ret){
        cout<<i<<endl;
    }
}


Measured memory_bytes: 3772
var
    h,w,d,q,i,j,k,tmp,ans_cnt: Longint;
    a:array[1..300,1..300] of Longint;
    index:array[1..90000,1..2] of Longint;
    l,r: Longint;
    step: array[1..90000] of Longint;
begin
    readln(h,w,d);
    for i := 1 to h do
    begin
        for j := 1 to w do
        begin
            read(a[i][j]);
            index[a[i][j]][1]:=i;
            index[a[i][j]][2]:=j;
        end;
    end;
    for i := d+1 to h*w do
    begin
        step[i]:=step[i-d]+abs(index[i][1]-index[i-d][1])+abs(index[i][2]-index[i-d][2]);;
    end;
    read(q);
    for i := 1 to q do
    begin
        readln(l,r);
        writeln(step[r]-step[l]);
    end;
end.

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X;
    int sen, go;
    
    scanf("%d", &X);
    
    sen = X/500;
    //printf("%d\n",sen);
    go = (X-sen*500)/5;
    //printf("%d\n", go);
    
    printf("%d\n", sen*1000 + go*5);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
  int n, m, c;
  std::cin >> n >> m >> c;

  std::vector<int> b(m);
  for (auto&& bi : b) std::cin >> bi;

  std::vector<std::vector<int>> a(n);
  for (auto&& ai : a) {
    ai.resize(m);
    for (auto&& aij : ai) std::cin >> aij;
  }

  int count = 0;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) sum += a[i][j] * b[j];
    if (sum + c > 0) ++count;
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k<a){
    cout << k << endl;
  }
  else if(a<=k&&k<=a+b){
    cout << a << endl;
  }
  else{
    cout << a-(k-(a+b)) << endl;
  }
}

Measured memory_bytes: 3596
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

int main(void){
    int D,T,S;
    cin >> D >> T >> S;
    if(D<=T*S) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

  int N,M;
  cin >> N >> M;
  string A[N],B[M];
  REP(i,N) cin >> A[i];
  REP(i,M) cin >> B[i];

  if (N == M) {
    bool isOK = true;
    REP(i,N) isOK &= A[i] == B[i];
    isOK ? Yes() : No();
    return 0;
  }

  REP(yn,N-M) {
    REP(xn,N-M) {
      bool isOK = true;
      REP(ym,M) {
        REP(xm,M) {
          isOK &= (A[yn+ym][xn+xm] == B[ym][xm]);
        }
      }
      if (isOK) {
        Yes();
        return 0;
      }
    }
  }

  No();
}



Measured memory_bytes: 3652
otoshidama = list(map(int, input().split()))
thousand_yen = int(otoshidama[1]/1000)
first_list = [0, 0, thousand_yen]
exchange_1 = min(int((thousand_yen - otoshidama[0]) // 4), int(thousand_yen // 5))
second_list = [0, exchange_1, thousand_yen - 5 * exchange_1]
exchange_2 = second_list[0] + second_list[1] + second_list[2] - otoshidama[0]
third_list = [exchange_2, exchange_1 - 2 * exchange_2, thousand_yen - 5 * exchange_1]
if third_list[0] < 0 or third_list[1] < 0 or third_list[2] < 0:
    print("-1 -1 -1")
else:
    print(str(third_list[0]),  str(third_list[1]),  str(third_list[2]))

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = (1..N).map { it to readLine()!!.toInt() }.sortedByDescending { it.second }
    val (m1, m2) = A
    for (i in 1..N) {
        val t = if (i != m1.first) m1.second else m2.second
        println(t)
    }
}

Measured memory_bytes: 87264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)
 
int main(void) {
  int card[3][3],n;
  rep(i,0,3){
    rep(j,0,3){
      card[i][j]=0;
    }
  }
    
  int tmp;
  rep(i,0,3){cin>>tmp;card[0][i]=tmp;}
  rep(i,0,3){cin>>tmp;card[1][i]=tmp;}
  rep(i,0,3){cin>>tmp;card[2][i]=tmp;}
  
  cin>>n;
  rep(i,0,n){
    cin>>tmp;
    rep(i,0,3){
      rep(j,0,3){
        if(card[i][j]==tmp){card[i][j]=0;}
      }
    }
  }
  
  bool empty=0;
  if(card[0][0]==0&&card[0][1]==0&&card[0][2]==0){empty=1;}
  if(card[1][0]==0&&card[1][1]==0&&card[1][2]==0){empty=1;}
  if(card[2][0]==0&&card[2][1]==0&&card[2][2]==0){empty=1;}
  if(card[0][0]==0&&card[1][0]==0&&card[2][0]==0){empty=1;}
  if(card[0][1]==0&&card[1][1]==0&&card[2][1]==0){empty=1;}
  if(card[0][2]==0&&card[1][2]==0&&card[2][2]==0){empty=1;}
  if(card[0][0]==0&&card[1][1]==0&&card[2][2]==0){empty=1;}
  if(card[0][2]==0&&card[1][1]==0&&card[2][0]==0){empty=1;}
  
  if(empty==1){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}

  return 0;
}


Measured memory_bytes: 256
let nm = readLine()!.split(separator: " ").map { Int($0)! }
let n = nm[0], m = nm[1]
let h = readLine()!.split(separator: " ").map { Int($0)! }

var bool = Array(repeating: true, count: n)
for _ in 0..<m {
  let ab = readLine()!.split(separator: " ").map { Int($0)! }
  let a = ab[0] - 1, b = ab[1] - 1
  if h[b] < h[a] {
    bool[b] = false
  }
  if h[a] < h[b] {
    bool[a] = false
  }
  if h[a] == h[b] {
    bool[a] = false
    bool[b] = false
  }
}
let result = bool.filter { $0 }.count
print(result)

Measured memory_bytes: 13732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    for (int i = 1; i < n + 1; i++) {
        ll zans = 0;
        ll t = i;
        while (t > 0) {
            zans += t % 10;
            t /= 10;
        }
        if (zans >= a && zans <= b)ans+=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define MOD 100000
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<int,bool> IB;
typedef long long ll;
typedef unsigned long long ull;
int h,w;                 //       FROM    AVAILABLE
int imap[110][110][2][2];//[y][x][L or B][A or U]
                         //       0    1  0    1
 
int main(){
 
  while(true){
    cin >> w >> h;
    if(w+h == 0)break;
    rep(i,h+1)rep(j,w+1)imap[i][j][0][0] = imap[i][j][0][1] = imap[i][j][1][0] = imap[i][j][1][1] = 0;
    rep(i,max(h,w)+1)imap[0][i][0][0] = imap[i][0][1][0] = 1;
     
    REP(i,1,h){
      REP(j,1,w){
    imap[i][j][0][0] += (imap[i][j-1][0][0] + imap[i][j-1][0][1])%MOD;//OK
    imap[i][j][0][1] += imap[i][j-1][1][0]%MOD;
    imap[i][j][1][0] += (imap[i-1][j][1][0] + imap[i-1][j][1][1])%MOD;
    imap[i][j][1][1] += imap[i-1][j][0][0]%MOD;
      }
    }
    int total;
    total = 0;
    rep(i,2)rep(j,2)total += imap[h-1][w-1][i][j];
    cout << total%MOD << endl;
     
 
  }
return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 510;

int n, m, d;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d%d", &n, &m, &d);
	REP(i, 0, n)
	{
		REP(j, 0, m)
			if (((i + j) / d) & 1) 
			{
				if (((i - j + m) / d) & 1) putchar('R');
				else putchar('G');
			}
			else 
			{
				if (((i - j + m) / d) & 1) putchar('B');
				else putchar('Y');
			}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<climits>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int *height=new int[n];
    int *dp=new int[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>height[i];
    }
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        int option1=abs(height[i]-height[i-1])+dp[i-1];
        int option2= (i==2) ? INT_MAX : abs(height[i]-height[i-2])+dp[i-2];
        dp[i]=min(option1,option2);
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    if (X == D || X == -1 * D) {
        if (K % 2 == 1) {
            cout << 0 << endl;
        }
        else {
            if (X < 0) {
                X *= -1;
            }
            cout << X << endl;
        }
        return 0;
    }
    ll a = floor(X / D);
    ll b = X % D;
    if (a < 0) {
        a *= -1;
    }
    if (K > a) {
        X = b;
        K -= a;
        if (K % 2 == 1) {
            if (X > 0) {
                X -= D;
            }
            else {
                X += D;
            }
        }
        if (X < 0) {
            X *= -1;
        }
        cout << X << endl;
    }
    else {
        if (X > 0) {
            X -= D * K;
        }
        else {
            X += D * K;
        }
        if (X < 0) {
            X *= -1;
        }
        cout << X << endl;
    }
}

Measured memory_bytes: 3624
H, W = map(int, input().split())
graph = [list(input()) for _ in range(H)]
one_steps = ((1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, 1), (1, -1), (-1, -1))
for x in range(H):
    for y in range(W):
        count = 0
        if graph[x][y] == ".":
            for dx, dy in one_steps:
                if (0 <= x + dx < H) and (0 <= y + dy < W):
                    if graph[x + dx][y + dy] == "#":
                        count += 1
            graph[x][y] = str(count)


for line in graph:
    print("".join(line))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[10];
    cin>>s;
    int a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    for(int i=43;i<=45;i+=2){
        for(int j=43;j<=45;j+=2){
            for(int k=43;k<=45;k+=2){
                int ans=a;
                if(i==43) ans+=b;
                else ans-=b;
                if(j==43) ans+=c;
                else
                    ans-=c;                if(k==43){
                    ans+=d;
                }
                else{
                    ans-=d;
                }
                if(ans==7){
                    cout<<a<<char(i)<<b<<char(j)<<c<<char(k)<<d<<"=7"<<endl;//只要输出一种
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    int s = 0;
    map<int, int> mp;
    for(int i = 1, x; i <= n; ++i) {
        cin >> x;
        s += x;
        mp[s % m] += 1;
    }
    int ans = 0;
    for(auto& v : mp) {
        if(v.fi == 0) ans += v.se;
        ans += (v.se) * (v.se - 1) / 2;
    }
    cout << ans << endl;
}

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

int main(){
  
  char N[3];
  cin >> N;
  
  int count = 0;
  
  for(int i=0; i<3; ++i){
    if(N[i] == '1'){
        ++ count;
    }else{
        ;
    }
  }
  
  cout << count << endl;
  
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  vector<int> L(N);
  REP(i, N) L[i] = nextInt();
  sort(ALL(L));

  ll ans = 0;
  // REP(a, N) REP(b, N) REP(c, N) {
  //   if (a < b && b < c) {
  //     if (L[c] < L[a]+L[b]) {
  //       cout << L[a] << " " << L[b] << " " << L[c] << endl;
  //       ans++;
  //     }
  //   }
  // }
  for (int c = 2; c < N; c++) {
    int a = 0;
    for (int b = c-1; b >= 0; b--) {
      while (a < b && L[a] + L[b] <= L[c]) {
        a++;
      }
      if (a >= b) break;
      ans += b - a;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

using namespace std;
double a, b, c, d, e, f;
double x, y;


void function(){
	if(a == 0){
		y = c/b;
		x = (f - c*e/b)/d;
	}else if(b == 0){
		x = c/a;
		y = (f - c*d/a)/e;
	}else if(d == 0){
		y = f/e;
		x = (c - f*b/e)/a;
	}else if(e == 0){
		x = f/d;
		y = (c - a*f/d)/b;
	}else{
		y = (c - a*f/d)/(b - a*e/d);
		x = (c - b*y)/a;
	}
	return;
}


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

	for(int i=0 ; i<n ; i++){
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		a = 2*(x2 - x1);
		b = 2*(y2 - y1);
		c = (x2 - x1)*(x1 + x2) + (y2 - y1)*(y1 + y2);

		d = 2*(x3 - x1);
		e = 2*(y3 - y1);
		f = (x3 - x1)*(x3 + x1) + (y3 - y1)*(y1 + y3);

		function();
		double r;
		r = sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1));

		printf("%.3lf %.3lf %.3lf\n",x, y, r);
	}
	return 0;
}

Measured memory_bytes: 1244
n, q = map(int, input().split())
s = input()
l = [0 for i in range(q)]
r = [0 for i in range(q)]
for i in range(q):
  l[i], r[i] = map(int, input().split())
ac = [0, 0]
for i in range(len(s) - 1):
  x = 1 if s[i:i+2] == 'AC' else 0
  ac.append(ac[i + 1] + x)
for i in range(q):
  print(ac[r[i]] - ac[l[i]])


Measured memory_bytes: 15740
'use strict';
var Main = function(stdin) {
  var line = stdin.split('\n');
  var param = line[0].split(' ').map(Number);
  var result = (function(a,b) {
  	
  	if (a < b) {
  		return 'a < b';
  	} else if (a > b) {
  		return 'a > b';
  	} else {
  		return 'a == b';
  	}

  }(
  	param[0],param[1]
  ));
  console.log(result);
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7384
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int S;
    int h;
    int m;
    int s;
    scanf("%d", &S);
    h=S/3600;
    m=(S-h*3600)/60;
    s=S-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,minh,maxh;
	cin>>n;
	int a[n];
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}
	minh = a[0];
	maxh = a[1]-a[0];
	for(int i = 1;i<n;i++){
		maxh = max(maxh,a[i]-minh);
		minh = min(minh,a[i]);
		
	}
	cout<<maxh<<endl;
	return 0;
}











/*int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}
	int syueki = a[1] -a[0];
	for(int i = 0;i<n-1;i++){
		for(int j = i+1;j<n;j++){
			syueki = max(syueki,a[j]-a[i]);
		}
	}
	cout<<syueki<<endl;
}*/


Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    string t;
    cin >> t;
    for(auto c : t){
        if(c == '?'){
            cout << "D";
        } else {
            cout << c;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3732
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B = get_ints

count = A-1
if B >= A
  count += 1
end

puts count


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

using namespace std;
typedef long long ll;

int N;
int A, B, C, D;
string S;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> A >> B >> C >> D >> S;

    A--, B--, C--, D--;
    bool bad = false;
    for (int i = A; i < max (C, D); i++)
    {
        if (S[i] == '#' && S[i+1] == '#')
        {
            bad = true;
        }
    }

    bool good = true;
    if (C > D)
    {
        good = false;
        for (int i = B; i <= D; i++)
        {
            if (S[i] == '.' && S[i+1] == '.' && S[i-1] == '.')
                good = true;
        }
    }

    if (bad || !good)
        cout << "No\n";
    else
        cout << "Yes\n";
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>

using namespace std;

#define maxn 100001

vector<int> adj[maxn];
vector<int> block[maxn];

int vis[maxn], col[maxn];

void dfs(int v, int c){
    vis[v]=1;
    col[v]=c;
    for(int u:adj[v]){
        if(vis[u]) continue;
        dfs(u,c);
    }
}

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

    int n, m, k;
    cin >> n >> m >> k;
    int u, v;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 0; i < k; i++) {
        cin >> u >> v;
        block[u].push_back(v);
        block[v].push_back(u);
    }
    int c = 1;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) dfs(i, c);
        c++;
    }
    int cnt[c];
    for (int i = 0; i < c; i++) cnt[i] = 0;
    for (int i = 1; i <= n; i++) cnt[col[i]]++;
    int res[n + 1];
    for (int i = 1; i <= n; i++) {
        res[i] = cnt[col[i]] - adj[i].size() - 1;
        for (int j:block[i]) {
            if (col[i] == col[j]) res[i]--;
        }
    }
    for (int i = 1; i <= n; i++) cout << res[i] << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 13432
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007;
lint di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
lint dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "ImPossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()

int main(){
  
  lint n; cin >> n;
  vector<lint> a(n);
  for(lint i = 0; i < n; i++)
    cin >> a[i];
  auto b = a;
  sort(all(b));

  rep(i, n){
    rep(j, n){
      swap(a[i], a[j]);
      if(a == b){
        YES();
        return 0;
      }
      swap(a[i], a[j]);
    }
  }
  NO();

  return 0;
}


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

int main(){
  int n,m,i,t,s,d;
  for(;cin>>n>>m,n;){
    vector<pair<int,pair<int,int> > >V;
    set<int> S;
    S.insert(1);
    for(i=0;i<m;i++){
      cin>>t>>s>>d;
      V.push_back(make_pair(t,make_pair(s,d)));
    }
    sort(V.begin(),V.end());
    for(i=0;i<m;i++)
      if(S.find(V[i].second.first)!=S.end())
        S.insert(V[i].second.second);
    cout<<S.size()<<endl;
  }
}

Measured memory_bytes: 1532
#include"bits/stdc++.h"
#include<iomanip>
#define fout cout<<fixed<<setprecision(15)
using namespace std;
double ans,n,k;
main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int cnt=0;
        double f=1,j=i;
        if(j<k){
            while(1){
                j*=2;
                if(j>=k){
                    cnt++;
                    break;
                }
                else cnt++;
            }
            for(int p=0;p<cnt;p++)f/=2;
        }
        ans+=(f/n);
    }
    fout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int k,n;
    cin >> n >> k;
    vec<int> p(n);
    for (auto &&e : p)
    {
        cin >> e;
    }
    sort(p.begin(),p.end());
    int ans=0;
    for (int i = 0; i < k; i++)
    {
        ans += p.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
int a, b, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7;

scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &a2);
scanf("%d", &b2);
scanf("%d", &a3);
scanf("%d", &b3);
scanf("%d", &a4);
scanf("%d", &b4);
scanf("%d", &a5);
scanf("%d", &b5);
scanf("%d", &a6);
scanf("%d", &b6);
scanf("%d %d", &a7, &b7);

printf("%d\n", a -b);
printf("%d\n", a2 - b2);
printf("%d\n", a3 - b3);
printf("%d\n", a4 - b4);
printf("%d\n", a5 - b5);
printf("%d\n", a6 - b6);
printf("%d\n", a7 - b7);
return 0;
}

Measured memory_bytes: 1856
w,h,n = map(int,input().split())
xika=[0]
xijo=[w]
yika=[0]
yijo=[h]
x = 0
for x in range (n):
    listA = list(map(int,input().split()))
    if listA[2] == 1:
        xika.append(listA[0])
    elif listA[2] == 2:
        xijo.append(listA[0])
    elif listA[2] == 3:
        yika.append(listA[1])
    else:
        yijo.append(listA[1])
    x += 1
xika.sort()
xijo.sort()
yika.sort()
yijo.sort()
if xika[-1]>xijo[0] or yika[-1]>yijo[0]:
    print(0)
else:
    print((xijo[0]-xika[-1])*(yijo[0]-yika[-1]))

Measured memory_bytes: 3064
macro_rules! input {
    ($t : ty) => {{
        use std::io::BufRead;
        let tmp_handle = std::io::stdin();
        let mut handle = tmp_handle.lock();
        let mut buf = String::new();
        handle.read_line(&mut buf).unwrap();
        let tmp_var: $t = buf.trim().parse().unwrap(); 
        buf.clear();
        tmp_var
    }};
    ($t : ty, $size : expr) => {{
        use std::io::BufRead;
        let tmp_handle = std::io::stdin();
        let mut handle = tmp_handle.lock();
        let mut buf = String::new();
        handle.read_line(&mut buf).unwrap();
        let tmp_var: $t = buf.trim().split_whitespace()
            .map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp_var
    }};
}
#[derive(Debug)]
pub struct UnionFind {
    parents: Vec<usize>,
    rank: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        let mut parents: Vec<usize> = Vec::with_capacity(n);
        for i in 0..n {
            parents.push(i);
        }
        let rank = vec![1; n];
        UnionFind {
            parents: parents,
            rank: rank,
        }
    }
    pub fn find(&mut self, x: usize) -> usize {
        if self.parents[x] == x {
            x
        } else {
            let par = self.parents[x];
            let root = self.find(par);
            self.parents[x] = root;
            root
        }
    }
    // union x and y
    pub fn union(&mut self, x: usize, y: usize) {
        let x_root = self.find(x);
        let y_root = self.find(y);
        // if x_root == y_root, do nothing
        if x_root == y_root { return (); }
        if self.rank[x_root] > self.rank[y_root] {
            // x <--- y
            self.parents[y_root] = x_root;
        } else {
            // y <--- x
            self.parents[x_root] = y_root;
            if self.rank[x_root] == self.rank[y_root] {
                self.rank[y_root] += 1;
            }
        }
    }
}
fn main() {
    let config = input!(Vec<usize>, 3);
    let mut load_uf = UnionFind::new(config[0]);
    let mut train_uf = UnionFind::new(config[0]);
    for k in 0..config[1] {
        let load = input!(Vec<usize>, 2);
        load_uf.union(load[0]-1, load[1]-1);
    }
    for l in 0..config[2] {
        let train = input!(Vec<usize>, 2);
        train_uf.union(train[0]-1, train[1]-1);
    }
    use std::collections::HashMap;
    let mut hash_map: HashMap<(usize, usize), usize> = HashMap::with_capacity(config[0]);
    let mut table: Vec<(usize, usize)> = Vec::with_capacity(config[0]);
    for city in 0..config[0] {
        let uf = (load_uf.find(city), train_uf.find(city)); 
        table.push(uf);
        let entry = hash_map.entry(uf).or_insert(0);
        *entry += 1;
    }
    for (i, t) in table.iter().enumerate() {
        if i != config[0]-1 {
            print!("{} ", hash_map.get(t).unwrap());
        } else {
            print!("{}\n", hash_map.get(t).unwrap());
        }
    }
}


Measured memory_bytes: 25340
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(ll i=(b)-1, i>=a; --i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scanv(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#define square(x) x*x
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
ll n,k;
string s;
void input(){
    cin>>n>>s>>k;
}
void src(){
    rep(i,n){
        cout<<((s[k-1]==s[i])? s[i]:'*');
    }
}    
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
}

Measured memory_bytes: 256
#include <iostream>
#include <float.h>
#include <cfloat>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <errno.h>
#include <cerrno>
#include <assert.h>
#include <cassert> 
#include <map>
#include <memory.h>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <vector> 
#include <cstdio> 
#include <set>
#include <string.h>
#include <stdio.h>
#include <new>
#include <memory>
#include <cmath>
#include <queue>
#include <cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define mp make_pair 
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define pii pair<int,int>  
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{ll a,b,c;
 cin>>a>>b>>c;
 int ans=max(a,max(b,c));
 if(ans==a)
 {if(ans%2==0)
  cout<<0<<endl;
  else
  cout<<b*c<<endl;
 }
  else if(ans==b)
 {if(ans%2==0)
  cout<<0<<endl;
  else
  cout<<a*c<<endl;
 }
  else
 {if(ans%2==0)
  cout<<0<<endl;
  else
  cout<<a*b<<endl;
 } 
 system("pause"); 
 return 0;
}

Measured memory_bytes: 504
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int[] p=new int[N+1];
      int ac=0,n,ans=0;
      int[] pena=new int[N+1];
      String res;
      for(int i=0;i<M;i++){
        n = sc.nextInt();
        res = sc.next();
        if(res.equals("AC")){
          if(p[n]!=1){
            p[n]=1;
            ac++;
            ans +=pena[n];
          }
        }else if(res.equals("WA")){
          if(p[n]!=1){
            pena[n]++;
          }
        }
      }
     System.out.print(ac);
     System.out.print(" ");
     System.out.println(ans);
   }
}

Measured memory_bytes: 65344
N, A = map(int, input().split())

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


X = max(max(x), A)

dp = [[0 for i in range(2*N*X+1)] for j in range(N+1)]

dp[0][N*X] = 1

y = []

for i in range(N):
    tmp = x[i]-A
    y.append(tmp)

for i in range(N):
    for j in range(2*N*X+1):
        if j-y[i]<0 or j-y[i]>2*N*X:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = dp[i][j] + dp[i][j-y[i]]
            
print(dp[N][N*X]-1)

Measured memory_bytes: 5744