akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, par[1000010], ranks[1000010], a, b, c, dist[1000010], all, newNode[1000010];
vector<pi> e[1000010];
vi adj[1000010];
bool used[1000010];

inline int find(int x)
{
	return par[x]==x?x:par[x]=find(par[x]);
}

inline void unite(int x, int y)
{
	x=find(x), y=find(y);
	if(x==y)
		return;
	if(ranks[x]<ranks[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(ranks[x]==ranks[y])
			ranks[x]++;
	}
}

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		while(M--)
		{
			a=in(), b=in();
			e[in()].eb(mp(a, b));
		}
		all=N;
		Forn(i, 1000000)
		{
			if(!e[i].size())
				continue;
			int pa;
			foreach(it, e[i])
	        {
	            used[it->f]=used[it->s]=false,
	            newNode[it->f]=newNode[it->s]=-1,
	            ranks[it->f]=ranks[it->s]=0;
	            par[it->f]=it->f;
				par[it->s]=it->s;
	        }
			foreach(it, e[i])
				unite(it->f, it->s);
			foreach(it, e[i])
	        {
	            if(!used[it->f])
	            {
	                used[it->f]=true;
	                pa=find(it->f);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->f].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->f);
	            }
	            if(!used[it->s])
	            {
	                used[it->s]=true;
	                pa=find(it->s);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->s].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->s);
	            }
	        }
		}
		queue<int> q;
		q.push(1);
		memset(dist, -1, sizeof(dist));
		dist[1]=0;
		while(!q.empty())
		{
			int cur=q.front();
			q.pop();
			foreach(it, adj[cur])
				if(dist[*it]<0)
					dist[*it]=dist[cur]+1, q.push(*it);
		}
		if(dist[N]<0)
			puts("-1");
		else
			printf("%d\n", dist[N]>>1);
		forn(i, all+1)
	    {
	    	e[i].clear();
	    	adj[i].clear();
	    	used[i]=0;
	    	newNode[i]=0;
	    }
	}
	return 0;
}


Measured memory_bytes: 72960
pa, pb, pab, na, nb = map(int, input().split())

'''
1. そのまま
2. 少ない方全てをabで

3. abいっぱいで余らせる
'''

ans1 = pa * na + pb * nb
ans2 = pab * min(na, nb) * 2 + (pa if(na > nb) else pb) * abs(na - nb)
ans3 = pab * max(na, nb) * 2

print(min(ans1, ans2, ans3))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5+10;
int dst(vector<int>A,vector<int>B)
{
    int s=0;
    for(int i=0;i<A.size();i++){
        s = s + (A[i]-B[i])*(A[i]-B[i]);
    }
    return s;
}
int main ()
{
    ll N,D;
    cin >> N >> D;
    vector<int>Points[N+10];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            int x;
            cin >> x;
            Points[i].push_back(x);
        }
    }
    int c=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int d = dst(Points[i],Points[j]);
            int sq = sqrt(d);
            if(d==sq*sq)c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int count = 0;
  int result = 0;
  int n[1000];
  int x[1000];
  
  while(true){
    scanf("%d %d", &n[count], &x[count]);
    if(n[count] == 0 && x[count] == 0) break;
    count++;
  }
  for(int i = 0; i < count; i++){
    result = 0;
    for(int a=1; a <= n[i]; a++){
      for(int b=1; b <= n[i]; b++){
	for(int c=1; c <= n[i]; c++){
	  if(a != b && b !=c && c != a && a < b && b < c&& (a+b+c) == x[i]){
	    //printf("Est: %d %d %d\n",a,b,c);
	    result++;
	  }
	}
      }
    }
    printf("%d\n",result);
  }
}



Measured memory_bytes: 2704
#include <iostream>
#include<cmath>
using namespace std;
int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;


   if(sqrt((b-a)*(b-a))<=d&&sqrt((c-b)*(c-b))<=d||sqrt((a-c)*(a-c))<=d){
       cout<<"Yes";
   }
   else  cout<<"No";

    }


Measured memory_bytes: 256
N = gets.chomp.to_i
S = gets.chomp.split('')

e_count = 0
S.each do |s|
  e_count += 1 if s == 'E'
end

min = Float::INFINITY
S.each do |s|
  e_count -= 1 if s == 'E'
  min = [min, e_count].min
  e_count += 1 if s == 'W'
end

puts min


Measured memory_bytes: 38172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;

void solve() {
    ll x,y,d;
    cin >> x >> y >> d;
    if(x % d) x += d - x % d;
    if(y < x) cout << 0 << endl;
    else cout << 1 + (y - x)/d << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
const int N = 1e5 + 5;
int n,m;
vector<int> b;
vector<int> adj[N];
int a[N];
int vis[N];
map<int,int> cnt;
void dfs(int u){
    vis[u] = 1;
    cnt[u]++;
    cnt[a[u]]++;
    b.pb(u);
    for(auto v : adj[u]){
        if(!vis[v]){
            dfs(v);        
        }
    }
}
void init(){
    for(auto x : b){
        if(cnt[x] == 2){
            a[x] = x;
        }
    }
    cnt.clear();
    b.clear();
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    for(int i = 0; i < m; i++){
        int x , y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            dfs(i);
            init();
        }
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == i){
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 20704
#include <bits/stdc++.h>
using namespace std;
vector <long long> V;
vector <vector <long long> > DP; // ile place za zmergowanie na przedziale [i, j]
int main(){
    ios_base::sync_with_stdio(0);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++){
        long long x;
        cin >> x;
        V.push_back(x);
    }
    DP.resize(N+1, vector <long long>(N+1, 9999999999999));
    for (int i = 0; i < N; i++){
        DP[i][i] = 0;
    }
    for (int i = 1; i < N; i++){
        V[i] += V[i-1];
    }
    for (int dlug = 2; dlug <= N; dlug++){
        for (int pocz = 0; pocz <= N-dlug; pocz++){
            int kon = pocz + dlug - 1;
            for (int mid = pocz; mid < kon; mid++){
                long long Suma = (pocz == 0) ? V[kon] : V[kon] - V[pocz-1];
                DP[pocz][kon] = min(DP[pocz][kon], DP[pocz][mid] + DP[mid+1][kon] + Suma);
            }
        }
    }
    // for (int i = 0; i < N; i++){
    //     for (int j = 0; j < N; j++){
    //         cerr << DP[i][j] << " \n"[j==N-1];
    //     }
    // }

    cout << DP[0][N-1];
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main() {

	int a = 0;
	int b = 0;
	int c = 0;

	cin >> a >> b >> c;

	if (a < b && b < c) {

		cout << "Yes" << endl;

	}
	else {

		cout << "No" << endl;

	}

	return 0;

}

Measured memory_bytes: 3100
n, m = map(int, input().strip().split())
graph = {i:[] for i in range(1, n+1)}

deg = [0 for i in range(n+1)]
for i in range(m):
    v1, v2 = map(int, input().strip().split())
    graph[v1].append(v2)
    deg[v2] += 1

Q = []
for i in range(1, n+1):
    if deg[i] == 0:
        Q.append(i)

dp = [0 for i in range(n+1)]

while len(Q):
    curr = Q.pop()
    for i in graph[curr]:
        dp[i] = max(dp[i], dp[curr]+1)
        deg[i] -= 1
        if deg[i] == 0:
            Q.append(i)

print(max(dp))

Measured memory_bytes: 90328
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
using namespace std;

struct data{
    int num;
    char s[11];
    int p;
    bool operator<(const data &ob)const{
        if(strcmp(this->s,ob.s)==0){
            return (this->p>ob.p);
        }
        return (strcmp(this->s,ob.s)<0);
    }
};

int main(void){
    int n;
    vector<data> d;//(100);
    data tmp;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %d",tmp.s,&(tmp.p));
        tmp.num = i+1;
        d.push_back(tmp);
    }

    sort(d.begin(),d.end());

    for(int i=0;i<n;i++){
        tmp = d[i];
        printf("%d\n",tmp.num);
    }

    return 0;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;
    
    reverse(S.begin(), S.end());
    for(int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
    
    bool can = true;
    for(int i = 0; i < S.size();) {
        bool can2 = false;
        
        for(int j = 0; j < 4; ++j) {
            string d = divide[j];
            if(S.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2) {
            can = false;
            break;
        }
    }
    
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double a,b,h,m;cin >> a >> b >> h >> m;
  printf("%.12lf\n",sqrt(a*a+b*b-2*a*b*cos(2*M_PI*((h+m/60)/12-m/60))));
}

Measured memory_bytes: 4200
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;

int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    vector<int> a(n);
    vector<int> b(m);
    for(int i = 0; i<n;i++){
        cin >> a[i];
    }
    for(int i = 0; i<m;i++){
        cin >> b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[n-1] < b[0] && b[0] > x && a[n-1] < y){
        cout << "No War" << endl;
    }
    else{
        cout << "War" << endl;
    }


    return 0;
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    i64 ans = 0;
    if(n%2){
        for(int i=0;i<n/2;++i)ans -= v[i]*2;
        for(int i=n/2;i<n;++i)ans += v[i]*2;
        ans -= v[n/2];
        ans -= v[n/2+1];
        i64 tmp = 0;
        for(int i=0;i<=n/2;++i)tmp -= v[i]*2;
        tmp += v[n/2];
        tmp += v[n/2-1];
        for(int i=n/2+1;i<n;++i)tmp += v[i]*2;
        ans = max(ans, tmp);
    }else{
        for(int i=0;i<n/2;++i)ans -= v[i]*2;
        ans += v[n/2-1];
        for(int i=n/2;i<n;++i)ans += v[i]*2;
        ans -= v[n/2];
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

string i2c = "753";
map<char, int> c2i = {{'7', 0}, {'5', 1}, {'3', 2}};

int main()
{
    int N, res = 0;
    cin >> N;
    
    for(int a = 3; a < 10; ++a) {
        for(int b = 0; b < pow(3, a); ++b) {
            string S;
            int tmp = b;
            for(int i = 0; i < a; ++i) {
                S.push_back(i2c[tmp%3]);
                tmp /= 3;
            }
            bool check[3];
            fill(check, check + 3, true);
            for(char c : S) check[c2i[c]] = false;
            bool jd = false;
            for(int i = 0; i < 3; ++i) if(check[i]) jd = true;
            if(jd) continue;
            if(stoi(S) <= N) ++res;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) ok = false;
  }
  cout << (ok ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AizuOnlineJudgement.ITP1_2_B
{
	public static class Program
	{
		public static void Main (string[] args)
		{
			var abc = Console.ReadLine ().Split (' ').Select (s => int.Parse (s)).ToArray ();
			Console.WriteLine (abc[0] < abc[1] && abc[1] < abc[2] ? "Yes" : "No");
		}
	}
}



Measured memory_bytes: 9320
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

const int MOD = (int)1e9 + 7;
const int N = 100000 + 5;

int n;
long long A[2];
long long a[N];
int f[2][N];
set<int> bad[2];

void solve()
{
    ios::sync_with_stdio(false);
    cin >> n >> A[0] >> A[1];
    for(int i = 1; i <= n; ++ i) {
        cin >> a[i];
    }
    for(int i = 1; i < n; ++ i) {
        for(int j = 0; j < 2; ++ j) {
            if (a[i + 1] - a[i] < A[j]) {
                bad[j].insert(i + 1);
            }
        }
    }
    bad[0].insert(n + 1);
    bad[1].insert(n + 1);

    f[0][1] = 1; f[0][2] = -1;
    f[1][1] = 1; f[1][2] = -1;

    for(int i = 1; i <= n; ++ i) {
        for(int j = 0; j < 2; ++ j) {
            int lim = *bad[j].upper_bound(i);
            int st = i + 1;
            if (i != 1) {
                st = lower_bound(a + 1, a + n + 1, a[i - 1] + A[j ^ 1]) - a;
                st = max(st, i + 1);
            }
            if (st <= lim) {
                (f[j ^ 1][st] += f[j][i]) %= MOD;
                (f[j ^ 1][lim + 1] += (MOD - f[j][i])) %= MOD;
            }
        }
        (f[0][i + 1] += f[0][i]) %= MOD;
        (f[1][i + 1] += f[1][i]) %= MOD;
    }

    cout << (f[0][n + 1] + f[1][n + 1]) % MOD << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 11136
import math

data = input().split()

n = int(data[0])
k = int(data[1])

div = n//k
n2 = n - div*k
if div==0:
	n2 += k

ans = []
for i in range(2):
	ans.append(abs(n2-k))
	n2 = abs(n2-k)

print(min(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int A[N],B[N];
    int ans=0;
    priority_queue<int> q;
    rep(i,N){
        cin>>A[i]>>B[i];
        q.push(A[i]+B[i]);
        ans-=B[i];
    }
    rep(i,(N+1)/2){
        ans+=q.top();
        if(q.size()>0){
            q.pop();
        }
        if(q.size()>0){
            q.pop();
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll n;
	cin >> n;
	vec p(n, 0);
	REP(i, n) {
		cin >> p[i];
	}

	ll ans = 0;
	FOR(i, 1, n - 1) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
		else if (p[i + 1] < p[i] && p[i] < p[i - 1]) ans++;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll ans = -1;
  int t = 5;
  for(int i = 1; i <= 5; i++){
    int x;
    cin >> x;
    if(x == 0) ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    string s1,s2;
    cin >> s1 >> s2;
    for(int i = 0;i < 3;i++){
        if(s1[i] != s2[2-i]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	while(cin>>H>>W) {
		vector<string> m(H);
		REP(i, H) cin>>m[i];
		REP(i, H) m[i]="#"+m[i]+"#";
		string sp(W+2, '#');
		cout<<sp<<endl;
		REP(i, H) cout<<m[i]<<endl;
		cout<<sp<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Reflection.Metadata.Ecma335;

namespace ABC165_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //整数入力
            long k = long.Parse(Console.ReadLine());

            //整数配列入力
            long[] vals = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long a = vals[0];
            long b = vals[1];

            long k_max = b / k * k;
                        
            if (k_max >= a){
                Console.WriteLine("OK");
            }   else {
                Console.WriteLine("NG");
            }
        }
    }
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i64 h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    i64 ans = w * (h / 2);
    if (h % 2 == 1) ans += (w + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,x,t;
   cin >> n >> x >> t;
   cout << t*((n+x-1)/x);
   return 0;
} 

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

int main(){
  string S;
  cin>>S;
  int ans=0;
  int count=0;
  while(count<S.size()){
    char s=S.at(count);
    while(count<S.size() && s==S.at(count)){
      ++count;
    }
    ++ans;
  }

  cout<<ans-1<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
struct Node
{
	int a,b;
	inline void myh()
	{
		if(b==59) a++,b=0;else b++;
		if(a==24) a=0;
	}
	bool operator !=(const Node &x){return a!=x.a||b!=x.b;}
}A,B;
int main()
{
	cin>>A.a>>A.b>>B.a>>B.b;
	int tot=0;
	while(A!=B) A.myh(),tot++;
	int k;cin>>k;
	cout<<tot-k<<endl;
}

Measured memory_bytes: 3616
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
#define int long long
using namespace std;
signed main() {
    string S, T;
    cin >> S >> T;
    cout << T + S << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*2
int a[3][nn];int n; 
int tp[nn*4];int nega[2];
struct fenwicktree{
	int tree[nn];
	void upd(int x,int y)
	{
		for(x;x<nn;x+=x&-x) tree[x]+=y;
	}
	int ask(int x)
	{
		int y=0;
		for(x;x;x-=x&-x) y+=tree[x];
		return y;
	}
}bit[2];
int ct[nn];
#define err {puts("No");exit(0);}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<3;i++) for(int j=0;j<n;j++) scanf("%d",&a[i][j]);
	for(int i=0;i<n;i++) tp[3*i+1]=i+1;
	for(int i=0;i<n;i++)
	{
		if(a[0][i]+1==a[1][i] and a[1][i]+1==a[2][i])
		{
			if(!tp[a[0][i]]) err
			ct[i]=tp[a[0][i]];
			if((ct[i]-1-i)%2) err
		}
		else if(a[0][i]-1==a[1][i] and a[1][i]-1==a[2][i])
		{
			nega[i%2]++;
			if(!tp[a[2][i]]) err
			ct[i]=tp[a[2][i]];
			if((ct[i]-1-i)%2) err
		}
		else err
	}
	for(int i=0;i<n;i++)
	{
		nega[(i+1)%2]+=(i/2)-bit[i%2].ask(ct[i]);
		bit[i%2].upd(ct[i],1);
	}
	if(nega[0]%2 or nega[1]%2) err
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 4736
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>

using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
    ll T;
    cin >> T;
    for (int i = 0; i < T; ++i){
        ll A,B,C,D;
        cin >> A >> B >> C >> D;
        if (A - B < 0){
            cout << "No" << endl;
            continue;
        }
        if (B - D > 0){
            cout << "No" << endl;
            continue;
        }
        if (B <= C){
            cout << "Yes" << endl;
            continue;
        }
        ll g = __gcd(B,D);
        ll m = B - g + (A % g);
        if (m > C){
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	vector<tuple<ll, int, int>> pr;
	ll n, k;
	cin >> n >> k;
	vector<int> a, f;
	rep (i, n) {
		int tmp; cin >> tmp;
		a.push_back(tmp);
	}
	rep (i, n) {
		int tmp; cin >> tmp;
		f.push_back(tmp);
	}
	sort(all(a));
	reverse(all(a));
	sort(all(f));
	rep (i, n) {
		pr.push_back(make_tuple((ll)a[i] * f[i], a[i], f[i]));
	}
	sort(all(pr));
	reverse(all(pr));
	// for (auto k : pr) cout << (get<0>(k)) << endl;
	// 二分探索でいける！
	ll ng = -1, ok = get<0>(pr[0]) + 1;
	while (ok - ng > 1LL) {
		ll med = (ok + ng) / 2LL, tmp = 0; // 必要な修行数
		// cout << "med:" << med << endl;
		for (auto k : pr) {
			// cout << get<1>(k) << "*" << get<2>(k) << " -> " << med / get<2>(k) << "*" << get<2>(k) << endl;
			if (get<0>(k) > med) {
				tmp += (get<1>(k) - med / get<2>(k));
			}
		}
		if (tmp <= k) ok = med;
		else ng = med;
	}
	cout << ok << endl;
	// cout << ng << endl;
	return 0;
}

Measured memory_bytes: 7920
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, M, a, b, c[55];
int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) cin >> a >> b, a--, b--, c[a]++, c[b]++;
	for (int i = 0; i < N; i++) cout << c[i] << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {


        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var B = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long sum = 0;

        for (long i = 0; i < N; i++)
        {
            if (A[i] < B[i])
            {
                long a = A[i + 1];
                A[i + 1] -= (B[i] - A[i]);

                if (A[i + 1] < 0)
                {
                    sum += A[i] + a;
                    A[i + 1] = 0;
                }
                else if (A[i + 1] >= 0)
                {
                    sum += B[i];
                }
            }
            else
            {
                sum += B[i];
            }

        }

        Console.WriteLine(sum);

    }
}

Measured memory_bytes: 35804
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>
#include <string>

typedef int64_t lint;
#define LINT_MAX INT32_MAX
#define LINT_MIN INT32_MIN

using namespace std;

int main(void) {
    int a,b;
    cin >> a >> b;
    if(a <= 8 && b <= 8)
        cout << "Yay!";
    else
        cout << ":(";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define rep(n,m) for(int i = n; i < m; i++)



int main(void) {
	int h, w;
	cin >> h >> w;
	string rows[50];
	rep(0, h) {
		cin >> rows[i];
	}
	int xdif[3]{-1,0,1};
	int ydif[3]{ -1,0,1 };
	
	rep (0, h) {
		for (int j = 0; j < w; j++) {
			int count = 0;
			bool isBomb = false;
			for (int x = 0; x < 3; x++) {				
				if (rows[i][j] == '#') {
					isBomb = true;
					break;
				}
				for (int y = 0; y < 3; y++) {
					if (i == 0 && x == 0) continue;
					if (j == 0 && y== 0) continue;
					if (i == h - 1 && x == 2) continue;
					if (j == w - 1 && y == 2) continue;
					if (rows[i + xdif[x]][j + ydif[y]] == '#') count++;
				}
				
			}
			if (isBomb) cout << '#';
			else  cout << count;
			if (j == w - 1) cout << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int m; scanf("%d", &m);
	ll ans = -1;
	ll sm = 0;
	REP(i, m){
		ll d, c; scanf("%lld%lld", &d, &c);
		ans += c;
		sm += d * c;
	}
	DEBUG("ans=%lld sm=%lld\n", ans, sm);
	ans += (sm - 1) / 9;
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int queue[MAX], color[MAX], M[MAX][MAX], d[MAX];
int end, top;
 
void enqueue(int n){
 
 if(end == MAX)
   end = 0;
   queue[end] = n;
   end++;
 
}
 
int dequeue(){
int retval;
 
  if(top == MAX)
   top = 0;
  retval = queue[top];
  top++;
 
  return retval;
}
 
void bfs(int s, int f){
int u, count = 0;
 enqueue(s);
 
  while(end != top){
   u = dequeue();
   color[u] = BLACK;
    while(M[u][count] != 0){
     if(color[M[u][count]] == WHITE){
      enqueue(M[u][count]);
      color[M[u][count]] = GRAY;
      d[M[u][count]] = d[u] + 1;
     }
     count += 1;
 }
 
    count = 0;
  }
 
}
 
int main(){
int count = 0, n, count2, id, num;
 scanf("%d", &n);
 for(count; count < n; count++){
  scanf("%d %d", &id, &num);
   for(count2 = 0; count2 < num; count2++){
     scanf("%d", &M[id][count2]);
   }
 
 }
 
 
 bfs(1, 0);
 
 for(count2 = 0; count2 < n; count2++){
   if(d[count2 + 1] != 0 || count2 == 0)
   printf("%d %d\n", count2+1, d[count2+1]);
   else
   printf("%d %d\n", count2+1, -1);
 
 }
 
 
 return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<long long> vll;

#define pub push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define umap unordered_map
#define uset unordered_set

#define forn(i, n)     for(ll i = 0; i< (ll)n; i++)
#define forf(i, x, y)  for(ll i=(x); i<=(ll)y; i++)
#define forb(i, x, y)  for(ll i=(x); i>=(ll)y; i--)
#define lpt() 		   ll T; std::cin>>T; while(T--)

#define nl "\n"
#define newl std::cout<<"\n";
#define bug(x) std::cerr<<"debug "<<#x<<" : "<<x<<"\n";
#define all(x) x.begin(),x.end()
#define fastio() ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);

template<typename X> std::ostream& operator<< (std::ostream& out, std::vector<X> v)
{ for(auto &i : v) out<<i<<" "; return out; }
template<typename X, typename Y> std::ostream& operator<< (std::ostream& out, std::pair<X,Y> p)
{ out<<p.first<<" "<<p.second; return out; }

static const long long mod = 1000000007;

using namespace std;

string s,t,ans="";
ll dp[3005][3005];

ll lcs(ll i,ll j)
{
	ll &k = dp[i][j];
	if(k!=-1)
		return k;
	if(s[i]=='.' or t[j]=='.')
		return k = 0;
	if(s[i]==t[j])
		return k = 1+lcs(i+1,j+1);
	return k = max(lcs(i,j+1),lcs(i+1,j));
}

string print_lcs()
{
	s+="."; t+=".";
	ll n = lcs(0,0);
	for(int i = 0; i<3005; i++)
	{
		if(n==0)
			break;
		for(int j=0; j<3005; j++)
		{
			if(n==0)
				break;
			if(dp[i][j]==n and s[i]==t[j])
			{	
				ans+=s[i];
				n--;
				i++;
			} 
		}
	}
	return ans;
}

int main()
{fastio()
	
	cin>>s>>t;
	memset(dp,-1,sizeof dp);
	cout<<print_lcs()<<nl;

return 0;}


Measured memory_bytes: 71040
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int n,x=0;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
if((n-i-1)%2==0)
x+=a[i];
else
x-=a[i];
}
cout << x;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	int a = M / N, b = M % N;
	while (a > 0) {
		if (b % a == 0) {
			cout << a << "\n";
			break;
		}
		--a;
		b += N;
	}

	return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7

def solve(N, X):
    return sum((2 * k - N + 1) * x for k, x in enumerate(X)) % mod


N, M, *XY = map(int, open(0).read().split())
X, Y = XY[:N], XY[N:]

print(solve(N, X) * solve(M, Y) % mod)

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

#define IPS 1e-10

int main() {
    double n, d;
    int b[12];

    while (cin >> n) {
        if (n < 0) break;
        if (255.9375 < n) goto NA;
        fill(b, b+12, 0);
        d = 128;
        for (int i = 0; n > IPS && i < 12; i++) {
            b[i] = n / d;
            n -= b[i] * d;
            d *= 0.5;
        }
        
        if (n > IPS) goto NA;
        for (int i = 0; i < 12; i++) {
            cout << b[i];
            if (i == 7) cout << '.';
        }
        cout << endl;
        continue;

        NA:
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
namespace BasicMath {
    // 二つの値の最大値を求める関数
    static Int Max(const Int a, const Int b);
    // 二つの値の最大値を求める関数
    Int Max(const Int a, const Int b) {
        if (a >= b) {
            return a;
        } else {
            return b;
        }
    }
}
using namespace BasicMath;

int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    cout  << a + b + c - Max(a, Max(b, c)) << endl;
    return 0;
}



Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

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

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double dist = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
    printf("%.8f\n", dist);
    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    map<int,int> maps;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        auto itr = maps.find(a);
        if(itr != maps.end()){
            maps.erase(itr);
        } else {
            maps[a] = 1;
        }
    }
    int count = 0;
    for(auto itr = maps.begin();itr != maps.end();itr++){
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int SZ = 20010;
pair<int, P> data[SZ];
bool infected[SZ];

int main(){
  int N, M;
  while(cin >> N >> M && (N + M) > 0){
    memset(infected, 0, sizeof(infected));

    int count = 1;
    infected[1] = true;
    
    REP(i, M){
      cin  >> data[i].first >> data[i].second.first >> data[i].second.second;
    }
    sort(data, data + M);
    
    REP(i, M){
      int s = data[i].second.first;
      int d = data[i].second.second;
      
      if(infected[s] && !infected[d]){
        count++;
        infected[d] = true;
      }
    }
    cout << count << endl;
  }
  return 0;
  
}

Measured memory_bytes: 1668
/***  بسم الله الرحمن ا لرحيم   ***/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl                         '\n'
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define test int t;cin>>t;while(t--)
const int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 2e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y)) * y); }
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int n,cost;
vector<int>we,val;
ll memo[105][100005];
ll dp(int i, int v) {
	if (i == n) {
		if(!v)return 0;
		return OO;
	}
	ll& ret = memo[i][v];
	if (~ret)return ret;
	ret = min(dp(i + 1, v - val[i]) + we[i], dp(i + 1, v));
	return ret;
}
void solve() {
	cin >> n>>cost;
	we = vector<int>(n);
	val = vector<int>(n);
	for (int i = 0; i < n; i++)cin >> we[i] >> val[i];
	mem(memo, -1);
	for (int i = 100000; i >= 0; i--) {
		if (dp(0, i) <= cost) { cout << i; break; }
	}
}
int main() {
	file();
//	test {
		solve();
		
//	}
	return 0;
}

Measured memory_bytes: 85660
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a>=b && a>=c) cout<<10*a+b+c<<endl;
	if(b>a && b>=c) cout<<10*b+a+c<<endl;
	if(c>a && c>b) cout<<10*c+a+b<<endl;
}

Measured memory_bytes: 256
function main(input) {
    var line = input.split(' ');
    var A = line[0];
    var B = line[1];
    var answer = A <= 8 && B <= 8 ? 'Yay!' : ':(';
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using ll = long long;

// 最大公約数（a > b）
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

// 最小公倍数（a > b）
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  int N;
  cin >> N;
  ll T[N];
  for (int i = 0; i < N; i++) cin >> T[i];

  sort(T, T + N);
  ll ans = T[N-1];
  for (int i = 0; i < N - 1; i++) {
    if (ans % T[i] == 0) continue;
    ans = lcm(ans, T[i]);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

int main(){
    int  n;
    cin >> n;
    map<string,int> cnt;
    rep(i, n){
        string s;
        cin >> s;
        cnt[s]++;
    }  
    for(string s : {"AC", "WA", "TLE", "RE"}){
        cout << s << " x " << cnt[s] << endl;
    }
    return 0;
}

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

bool A[110][110];

int main (){
	int n,a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<A[i][j]<<(j==n?"\n":" ");
		}
	}
	return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    string s;
    cin >> s;
    cin >> k;
    n = s.size();
    for(i=0;i<n;i++){
        if(s[i]!='a'&&'z'-s[i]+1<=k){
            k -= 'z' - s[i] + 1;
            s[i] = 'a';
            //cout << 'z'-s[i]+1 << endl;
        }
        if(k==0)break;
    }
    k%=26;
    if(k>0){
        s[n-1]='a'+((s[i-1]-'a'+k)%26);
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
import math
n = int(input())
n_sqrt = math.sqrt(n)

l = [2] * (n - 1)
l[0] = 1

for i in range(2, math.floor(n_sqrt) + 1):
  k = (n - 1) // i
  for j in range(2, k+1):
    l[j * i - 1] += 2 if j > n_sqrt else 1
    
print(sum(l))

Measured memory_bytes: 16520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  ll money = 1000;
  ll kabu = 0;
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  bool up = false;
  rep(i, n-1){
    bool cup;
    
    if(vec[i+1] > vec[i]) cup = true;
    else if(vec[i+1] < vec[i]) cup = false;
    else continue;
    
    if(up && cup) continue;
    else if(!up && cup){
      kabu = money / vec[i];
      money %= vec[i];
    }
    else if(up && !cup){
      money += kabu*vec[i];
      kabu = 0;
    }
    else continue;
    
    up = cup;
  }
  if(up) money += kabu*vec.back();
  cout << money << endl;
  return 0;
}
  
  
  
  

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

const long long INF = 1000000000000000001LL;

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

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

  sort(A, A+N);
  if(A[0]==0) {
      cout << 0 << endl;
      return 0;    
  }
  long long ans=1;
  long long beforeAns=1;

  
  for (int i = 0; i < N; i++) {
 
    ans*=A[i];
    //check overflow.
    if(beforeAns>ans||ans/INF>0LL){
      cout << -1 << endl;
      return 0;
    }
    beforeAns=ans;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
	int n; scanf("%d\n", &n);

	string rect = "Hoshino";

	for (int t = 0; t < n; ++t) {
		char c; int pos = 0;
		while ((c = getchar()) != EOF) {
			if (c != rect[pos]) pos = c == rect[0];
			else if (++pos == rect.size()) pos = 0, c = 'a';
			cout << c;
		}
	}
}

Measured memory_bytes: 1196
#include "iostream"
#include "vector"
using namespace std;

int main()
{

	int N = 0;
	int L = 0;
	cin >> N;
	cin >> L;

	int sum = 0;
	for (int i = 1; i <= N; ++i)
	{
		auto temp = L + i - 1;
		sum += temp;
	}

	int tsumamiIndex = 0;
	if (L >= 1)
	{
		tsumamiIndex = 1;
	}
	else if (L <= -N)
	{
		tsumamiIndex = N;
	}
	else
	{
		tsumamiIndex = 1 - L;
	}

	auto aji = tsumamiIndex - 1 + L;
	sum -= aji;

	cout << sum;
	cin >> aji;
	return 0;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n,k;
  std::cin >> n >> k;
  vt<int> x(n);
  rep(i,n)
    std::cin >> x[i];

  int ans = 0;
  rep(i,n){
    k - x[i] < x[i] ? ans += (k - x[i])*2 : ans += x[i]*2;
  }

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


Measured memory_bytes: 256