akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main (void){
    int N,i;
    unsigned long long int result;
    unsigned long long int A[100000];
    result = 1;
    scanf("%d",&N);
    for(i=0;i<N;i++) {
        scanf("%lld",&A[i]);
       if( A[i] == 0 ){
           printf("0");
           return 0;
       }
    }
      for(i=0;i<N;i++){
         if(A[i] <=1000000000000000000/result){
             result= result * A[i];
        }else{
             printf("-1\n");
             return 0;
    }
  }
     printf("%lld\n",result);
    return 0;
}

Measured memory_bytes: 2516
#include <iostream>
#include <cmath>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <algorithm>
#include <set>
#include <vector>
#include <map>

#define ll long long

using namespace std;

int main() {

    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;

    cout << n * (n - 1) / 2 + m * (m - 1) / 2;

}


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

using namespace std;

int main()
{
	// 2<=K<=100
	int K;

	cin >> K;
	int K2 = K / 2;

	// Kが奇数
	if (K%2) {
		K2 = K2 * (K2 + 1);

	}// Kが偶数
	else {
		K2 = K2 * K2;
	}

	cout << K2;

    return 0;
}


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

int main()
{
    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    if (p == 5 || p == 2)
    {
        ll cnt = 0;
        for (ll j = 0; j < s.length(); j++)
        {
            auto num = s[j] - '0';
            if (num % p == 0)
            {
                cnt += j + 1;
            }
        }

        cout << cnt << endl;
        return 0;
    }

    string reversed = s;
    reverse(reversed.begin(), reversed.end());

    vector<ll> mods = {};
    auto mod = 0;
    auto digit_mod = 1;
    for (auto i = 0; i < reversed.length(); i++)
    {
        auto digit = reversed[i] - '0';
        if (i != 0)
        {
            digit_mod = digit_mod * 10 % p;
        }
        mod = (mod + digit_mod * digit) % p;
        mods.push_back(mod);
    }

    reverse(mods.begin(), mods.end());
    map<ll, ll> comb = {};

    for (auto i = 0; i < mods.size(); i++)
    {
        auto m = mods[i];
        if (comb.count(m))
        {
            comb[m] = comb[m] + 1;
        }
        else
        {
            comb[m] = 1;
        }
    }

    ll cnt = 0;
    for (auto value : comb)
    {
        if (value.first == 0)
        {
            cnt += value.second;
        }

        if (value.second > 1)
        {
            cnt += value.second * (value.second - 1) / 2;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 2808
import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val A = Array(2, {readInputLine().split(" ").map{it.toInt()}.toIntArray()})
    
    val dp = Array(2, {IntArray(N, {-1})})
    
    dp[0][0] = A[0][0]
    for (i in 1 until N) {
        dp[0][i] = dp[0][i - 1] + A[0][i]
    }
    dp[1][0] = dp[0][0] + A[1][0]
    for (i in 1 until N) {
        dp[1][i] = Math.max(dp[1][i - 1], dp[0][i]) + A[1][i]
    }
    
    println(dp[1][N - 1])
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

void solve(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++i)
        cout << s[i] << t[i];
    cout << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

s = [list(input()) for _ in range(H)]

memo = [[None] * W for _ in range(H)]
memo[0][0] = (1 if s[0][0] == '#' else 0)

def dp(y, x):
    if memo[y][x] != None: return memo[y][x]
    #
    rets = []
    if y > 0:
        if s[y - 1][x] == '.' and s[y][x] == '#':
            rets.append(dp(y - 1, x) + 1)
        else:
            rets.append(dp(y - 1, x))
    if x > 0:
        if s[y][x - 1] == '.' and s[y][x] == '#':
            rets.append(dp(y, x - 1) + 1)
        else:
            rets.append(dp(y, x - 1))
    #
    ret = min(rets)
    memo[y][x] = ret
    return ret

print(dp(H - 1, W - 1))

Measured memory_bytes: 45532
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define Fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int M =1e9+7;

class graph
{
    public:
    vector<int> *g;
    int n;
    graph(int v)
    {
        n=v;
        g= new vector<int>[n];
    }
    void addedge(int u,int v)
    {
        g[u].pb(v);
        g[v].pb(u);
    }
};
void solve()
{
   int n;
   cin>>n;
   unordered_map<string,int> m;
   vector<string> v;
   for(int i=1;i<=n;i++)
   {
   	string str;
   	cin>>str;
  // 	v.pb(str);
    m[str]++;
   }
   int max=0;
   for(auto i=m.begin();i!=m.end();i++)
   {
   	if(i->second>max)
   		max=i->second;
   }
   for(auto i=m.begin();i!=m.end();i++)
   {
   	if(i->second==max)
   		v.pb(i->first);

   }
   sort(v.begin(),v.end());
   for(auto i:v)
   	cout<<i<<endl;
}
signed main()
{
    Fast;
    
    
    solve();
    
 return 0;    
}


Measured memory_bytes: 25284
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>
 
#define INF 100000000
#define EPS 1e-9
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
  
#define MAX_N 200

int N;
int n, d;

struct BLOCK{
  int x, y;
}block[MAX_N+1];

vector<P> ans_list;

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

int main(){
  
  while(true){
    
    cin >> N;
    if(N == 0)
      break;

    block[0].x = block[0].y = 0;

    int WR = 0, WL = 0, HU = 0, HD = 0;

    for(int i = 0; i < N-1; i++){
      cin >> n >> d;
      int X = block[i+1].x = block[n].x + dx[d];
      int Y = block[i+1].y = block[n].y + dy[d];
      WR = max(X, WR);
      WL = min(X, WL);
      HU = max(Y, HU);
      HD = min(Y, HD);
    }

    ans_list.push_back(P(WR-WL+1,HU-HD+1));

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i].first << " " << ans_list[i].second << endl;
  }

  return 0;
  
}

Measured memory_bytes: 1196
#include <stdio.h>

int main(void)
{
	int s, a, b, c, d;	
	scanf("%d",&s);
	
	a=s/1000;
	b=(s%1000) / 100;
	c=(s%100) /10;
	d=s%10;
	
	if(a==b || b==c || c==d)
	printf("Bad\n");
	else
	printf("Good\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

i64 mpow(i64 x, i64 n, i64 mod)
{
    i64 ret = 1;
    while(n!=0)
    {
        if(n&1) ret = ret * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ret;
}

int main()
{
    int n,m;
    cin >> n >> m;
    int mod = 1e9+7;

    unordered_map<int,int> ps;
    int tmp = m;
    for(int i=2;i*i<=m;++i)
    {
        while(tmp%i == 0)
        {
            if(ps.count(i) == 0)
                ps[i] = 0;
            ps[i]++;
            tmp /= i;
        }

        if(tmp == 1)
            break;
    }

    if(tmp > 1)
    {
        if(ps.count(tmp) == 0)
        ps[tmp] = 0;
        ps[tmp]++;
    }    

    i64 ret = 1;
    i64 m0 = 1; // ((n-1)!)^(M-1) mod M
    rep(i,n-1)
        m0 = m0 * mpow(i+1,mod-1,mod) % mod;

    for(auto& p:ps)
    {
        int k = p.second;
        ret = ret * m0 % mod;
        rep(i,k)
        {
            ret = ret * (n-1+i+1) % mod;
            ret = ret * mpow(i+1,mod-2,mod) % mod;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define maxn 10005
int n,ans,au[maxn],av[maxn];
int main()
{
	scanf("%d",&n);
	if(n%2)
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				if(i!=n-j) ans++,au[ans]=i,av[ans]=j;
	}
	else
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				if(i!=n-j+1) ans++,au[ans]=i,av[ans]=j;
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++) printf("%d %d\n",au[i],av[i]);
}

Measured memory_bytes: 256
// AOJ Volume 1 Problem 0150 Twin Prime

#include <stdio.h>
#include <string.h>

int main(void)
{
    int prime[10001];
    int i, j;
    int n;
    
    memset(prime, 0, sizeof(prime));
    for (i = 2; i * i <= 10000; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= 10000; j += i){
                prime[j] = 1;
            }
        }
    }
/*    
    for (i = 1; i < 1000; i++){
        if (prime[i] == 0){
            printf("%d ", i);
        }
    }
*/

    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }

        for (i = n; i >= 2; i--){
            if (prime[i] == 0 && prime[i - 2] == 0){
                printf("%d %d\n", i - 2, i);
                break;
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

/*
 * a1, a2, a3, a4, a5, a6
 * | choose
 * v
 * a1, a3, a4, a6
 * pick up two (a3, a4)
 * the order of two is desided by the order 'min(h3, h4 - p3) and min(h4, h3 - p4)' that indicates the available level of zabuton before the two.
 * if this order is a total order. dispite the way of choice, order of people is stable.
 * and, this order is equivalent to the order of 'h3 + p3 and h4 + p4'. so, this is clearly a total order.
*/

static const int INF = (int)1e10;

using namespace std;

bool hp_order(pair<int, int> l, pair<int, int> r) {
    return l.first+l.second < r.first+r.second;
}

void solve(int n, vector<pair<int, int> > hp) {
    sort(hp.begin(), hp.end(), hp_order);
    vector< vector<int> > dp(n, vector<int>(n+1, 0));
    for (int i = 0; i < n+1; i++) {
        dp[0][i] = INF;
    }
    dp[0][0] = 0; dp[0][1] = hp[0].second;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < n+1; j++) {
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] > hp[i].first ? INF : dp[i-1][j-1] + hp[i].second);
        }
    }
    int ret = n;
    for (int i = 0; i < n+1; i++) {
        if (dp[n-1][i] == INF) {
            ret = i-1;
            break;
        }
    }
    std::cout << ret << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector< pair<int, int> > hp(n);
    for (int i = 0; i < n; i++) {
        std::cin >> hp[i].first >> hp[i].second;
    }
    solve(n, hp);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  LL h,w;
  cin >> h >> w;
  LL ans=1000000000000000;
  if(h%3){
    ans=min(ans,w);
  }else{
    ans=0;
  }
  if(w%3){
    ans=min(ans,h);
  }else{
    ans=0;
  }
  for(int i=1;i<h;i++){
    ans=min(ans,max(i*w,(h-i)*((w+1)/2))-min(i*w,(h-i)*(w/2)));
  }
  for(int i=1;i<w;i++){
    ans=min(ans,max(i*h,(w-i)*((h+1)/2))-min(i*h,(w-i)*(h/2)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/12
# Filename: main 
# Author: acto_mini

def main():
    N, Y = map(int, input().split())
    print()

    for i in range(N + 1):
        for j in range(N + 1 - i):
            k = N - i - j
            if Y == (10000 * i + 5000 * j + 1000 * k):
                print(i, j, k)
                exit()
    print("-1 -1 -1")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int64_t> us(N);
  vector<int64_t> vs(N);

  int64_t x, y;
  cin >> x >> y;
  int mod = abs(x + y) % 2;
  us[0] = x + y, vs[0] = x - y;
  for (int n = 1; n < N; ++n) {
    cin >> x >> y;
    if (mod != abs(x + y) % 2) {
      cout << -1 << endl;
      return 0;
    }
    us[n] = x + y, vs[n] = x - y;
  }
  int m = 31 + (mod^1);
  cout << m << endl;
  vector<int64_t> ds(m);
  for (int i = 0, size = ds.size(); i < size; ++i) {
    ds[i] = 1ll << max(30 - i, 0);
    if (i) cout << " ";
    cout << ds[i];
  }
  cout << endl;
  for (int n = 0; n < N; ++n) {
    string dir = "";
    int64_t u = us[n], v = vs[n]; 
    for (int64_t d : ds) {
      if (u >= 0) {
        if (v >= 0) {
          dir += "R";
          u -= d, v -= d;
        } else {
          dir += "U";
          u -= d, v += d;
        }
      } else {
        if (v >= 0) {
          dir += "D";
          u += d, v -= d;
        } else {
          dir += "L";
          u += d, v += d;
        }
      }
    }
    cout << dir << endl;
  }
  return 0;
}


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

int main(){
	int sss,h,m,s;
	
	cin >> sss;
	h = sss / 3600;
	m = (sss % 3600) / 60;
	s = sss % 60;

	cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int N,T,c,t,i,mn=INF;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>N>>T;
  for(i=0;i<N;i++){
    cin>>c>>t;
    if(t>T)continue;
    mn=min(c, mn);
  }
  if(mn==INF){
    cout<<"TLE"<<endl;
  }else{
    cout<<mn<<endl;
  }
  return 0;
}


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

int main()
{
    int n;
    set <string> c;
    string str;
    vector<string> s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>str;
        s.push_back(str);
        int l=str.length();
        sort(str.begin(),str.end());
        c.insert(str);
    }

    map<string,int> m;
    for(auto x:c)
    {
        m[x]=0;
    }

    for(int i=0;i<n;i++)
    {
        sort(s[i].begin(),s[i].end());
        m[s[i]]++;
    }
    long int ans=0;
    for(auto x:c)
    {
        ans+=((long)m[x]*(m[x]-1))/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 21364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    double x,k,sum=0;

    double ara[100000];
    cin>>n;
    for(i=1; i<=n; i++)
    {

        cin>>ara[i];

        sum=sum+((1)/ara[i]);
    }
    x=((1)/sum);
    cout<<x<<endl;
    return 0;
}


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

int N;
int a[100010];
int K;

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

	int N; cin >> N;
	cout << pow(N, 3) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    wl = Counter(S)
    return 'YES' if (wl['o'] + 15-len(S)) >= 8 else 'NO'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7748
#include <bits/stdc++.h>
 
using namespace std;
 
template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}
 
 
struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }
 
}comp_functor;

 
int main() 
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    
    long long int i,j,t,n,l,c=0,q,ans=0,a[200005]={0},f=0,x,temp,h[200005]={0};
    
    string s;
    
   // cin>>n;
    
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    
    sort(a,a+3);
    
    ans = a[2]-a[0];
    
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> tmp(N),V;
    rep(i,0,N)cin >> tmp[i];
    V.push_back(tmp[0]);
    rep(i,1,N)if(tmp[i-1] != tmp[i])V.push_back(tmp[i]);
    N = V.size();
    //rep(i,0,N)cout << V[i] << " ";cout << endl;
    ll ans[N] = {};
    ans[0] = 1;
    vector<int> idx(200010, -1);
    idx[V[0]] = 0;
    rep(i,1,N){
        if(idx[V[i]] == -1){
            idx[V[i]] = i;
            ans[i] = ans[i-1];
        }else{
            ans[i] = (ans[i-1] + ans[ idx[V[i]] ]) % MOD;
            idx[V[i]] = i;
        }
    }
    cout << ans[N-1] << endl;
}

Measured memory_bytes: 4340
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    int N; cin >> N;
    int ans(INF);
    FORS(a, 1, N/2){
        int A(a), B(N-a), cnt(0);
        while(A){
            cnt += A % 10; A /= 10;
        }
        while(B){
            cnt += B % 10; B /= 10;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, C = gets.split.map(&:to_i)

# インデックスは0から
xs, vs = [], []
N.times do |i|
    xs[i], vs[i] = gets.split.map(&:to_i)
end

# スタートから最長で寿司iまで食べてそのまま帰るときの獲得カロリー最大値
max_leave = Array.new(N, 0)
# スタートから最長で寿司iまで食べてスタートに戻るときの獲得カロリー最大値
max_return = Array.new(N, 0)

# 累積和で求める。
# 場合分け面倒なので0だけ最初に計算
sum_leave = vs[0] - xs[0]
sum_return = vs[0] - xs[0] * 2
max_leave[0] = [sum_leave, 0].max
max_return[0] = [sum_return, 0].max

(N-1).times do |i|
    # 寿司i+1と寿司iとの距離
    dist = xs[i+1] - xs[i]
    # 寿司i+1を食べて、距離ぶんカロリーを消費する。returnのほうは帰り道があるので*2
    sum_leave  += vs[i+1] - dist
    sum_return += vs[i+1] - dist * 2
    # i+1を食べる場合はこの時点でのsum、食べない場合は1つ前のmax。大きい方を採用
    max_leave[i+1] = [max_leave[i], sum_leave].max
    max_return[i+1] = [max_return[i], sum_return].max
end

# 時計回りの計算完了、保存する
max_leave_cw = max_leave
max_return_cw = max_return


# 反時計回りの計算をしたいが、このままやるとインデックス付けをミスるので
# 入力を反転させて実装全部コピペする
xs.reverse!
xs.map!{|x| C - x}
vs.reverse!

# コピペ
max_leave = Array.new(N, 0)
max_return = Array.new(N, 0)

sum_leave = vs[0] - xs[0]
sum_return = vs[0] - xs[0] * 2
max_leave[0] = [sum_leave, 0].max
max_return[0] = [sum_return, 0].max

(N-1).times do |i|
    dist = xs[i+1] - xs[i]
    sum_leave  += vs[i+1] - dist
    sum_return += vs[i+1] - dist * 2
    max_leave[i+1] = [max_leave[i], sum_leave].max
    max_return[i+1] = [max_return[i], sum_return].max
end

# 反時計回り計算完了、反転を戻しつつ保存する。
max_leave_ccw = max_leave.reverse
max_return_ccw = max_return.reverse


# 答えを求める。
# まずは逆走せずに時計または反時計だけで回るパターンの最大値。以下で求まる。
ans = [max_leave_cw.max, max_leave_ccw.max].max

# 時計回りに移動→スタートまで逆走→反時計回りに移動→帰るパターン。またはその逆
# 時計回りに寿司iまで回ったときには、反時計回りには寿司i+1までしか回れない。
(N - 1).times do |i|
    cal = [
        max_return_cw[i] + max_leave_ccw[i+1],
        max_leave_cw[i] + max_return_ccw[i+1]
    ].max
    ans = cal if ans < cal
end

puts ans

Measured memory_bytes: 8272
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = a; i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)

constexpr int mod = 1000000007;

inline bool valid(char c, int x) {
	return c == '?' || c - '0' == x;
}

int main() {
	for(string A, B, C; cin >> A && A != "0";) {
		cin >> B >> C;

		const int n = A.size();
		vector<int> dp(2, 0);
		dp[0] = 1;

		for(int i = n - 1; i >= 0; --i) {
			vector<int> next(2, 0);

			REP(a, i == 0, 10) {
				if(!valid(A[i], a)) continue;

				REP(b, i == 0, 10) {
					if(!valid(B[i], b)) continue;

					rep(carry, 2) {
						const int sum = a + b + carry;
						if(!valid(C[i], sum % 10)) continue;
						(next[sum / 10] += dp[carry]) %= mod;
					}
				}
			}

			dp = move(next);
		}

		cout << dp[0] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_4D
{
    class Program
    {
        //static void Main(string[] args)
        //{
        //    string inputText = Console.ReadLine();
        //    int n = int.Parse(inputText);

        //    inputText = Console.ReadLine();
        //    string[] words = inputText.Split(' ');

        //    if (words.Length < n)
        //    {
        //        return;
        //    }

        //    int[] intArray = new int[n];
        //    for (int i = 0; i < n; ++i)
        //    {
        //        intArray[i] = int.Parse(words[i]);
        //    }

        //    int minIndex = 0;
        //    int maxIndex = 0;
        //    long sum = 0;
        //    for (int i = 0; i < intArray.Length; ++i)
        //    {
        //        sum += intArray[i];
        //        if (intArray[i] < intArray[minIndex])
        //        {
        //            minIndex = i;
        //        }
        //        if (intArray[maxIndex] < intArray[i])
        //        {
        //            maxIndex = i;
        //        }
        //    }

        //    Console.WriteLine("{0} {1} {2}", intArray[minIndex], intArray[maxIndex], sum);
        //}

        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var count = int.Parse(text);

            text = Console.ReadLine();
            var min = 0;
            var max = 0;
            var sum = 0L;

            var words = text.Split(' ');
            for (var i = 0; i < count; ++i)
            {
                var value = int.Parse(words[i]);
                if (i == 0) {
                    min = value;
                    max = value;
                    sum = value;
                }
                else {
                    min = value < min ? value : min;
                    max = max < value ? value : max;
                    sum += value;
                }
            }

            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}

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

long long int N, M, a, b;
vector<pair<long long, long long>> p;

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 0; i < M; ++i){
        scanf("%lld%lld", &a, &b);
        p.emplace_back(a, b - 1);
    }
    sort(p.rbegin(), p.rend());
    a = 0;
    b = 0;
    for(auto i : p){
        if(i.first <= b && i.second >= b){
            continue;
        }
        ++a;
        b = i.first;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		char op = sc.next().toCharArray()[0];
		int B = sc.nextInt();

		if (op == '+') {
			System.out.println(A + B);
		} else {
			System.out.println(A - B);
		}
	}
}


Measured memory_bytes: 9684
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int main()
{
	long n;
	cin >> n;
	cout << (long long)(((long long)n - 1) * (long long)n / 2);
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> d(H);
    vector<int> v(26, 0);
    for (int i = 0; i < H; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i].size(); j++) {
            v[d[i][j] - 'a']++;
        }
    }
    int one = 0, two = 0;
    for (int i = 0; i < 26; i++) {
        v[i] %= 4;
        two += v[i] / 2;
        one += v[i] % 2;
    }

    bool flag = true;
    if (one > 1) flag = false;
    if (one != 1 && H % 2 != 0 && W % 2 != 0) {
        flag = false;
    }
    int rest = 0;
    if (H % 2 == 1) {
        rest += W / 2;
    }
    if (W % 2 == 1) {
        rest += H / 2;
    }
    if (rest < two) {
        flag = false;
    }
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

const int MAX_N = 100001; // 100000 だと N=100000 で WA (memo[100000] != -1なので)
int memo[MAX_N]; // memo[n] には、調査済みなら rec(n) まだなら -1 が入る


// n 円引き出すのに必要な操作の回数の最小値 rec(n) を調べる
int rec(int n) {
  if(n == 0) return 0; // 終端条件
  if(memo[n] != -1) return memo[n]; // 既に rec(n) を調べているなら return

  int res = n; // 十分大きくとる

  // "最初に 3^0, 3^1, 3^2, ... 円引き出したときにかかる操作の回数の最小値" を調べてより良いなら更新
  // 最初に 3^i 円引き出したとき、求める最小値は rec(n - 3^i) + 1 であり、これは再帰的に求められる
  for(int pow6=1; pow6<=n; pow6*=6) res = min(res, rec(n-pow6)+1); 
  
  // 同様に、"最初に 9^0, 9^1, 9^2, ... 円引き出したときにかかる操作の回数の最小値" を調べていく
  for(int pow9=1; pow9<=n; pow9*=9) res = min(res, rec(n-pow9)+1);

  return memo[n] = res; // memo[n] を -1 から rec(n) に変えて return
}


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

  REP(i,MAX_N) memo[i] = -1; // memo を -1 で初期化
  cout<<rec(N)<<endl; // 答えは rec(N)
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

char s[100010];

int main() {
    int k, n;
    scanf("%d", &k);
    scanf("%s", s);
    n = strlen(s);
    if(n <= k) printf("%s\n", s);
    else {
        for(int i = 0; i < k; i++) {
            printf("%c", s[i]);
        }
        printf("...\n");
    }

    return 0;
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))
c = 0
if N%2 == 0:
    dp = [[0,0] for _ in range(N//2)]
    dp[0][0] = A[0]
    dp[0][1] = A[1]
    for i in range(N//2-1):
        dp[i+1][0] = dp[i][0] + A[2*i+2]
        dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3])
    # print(dp)
    print(max(dp[N//2-1][0],dp[N//2-1][1]))
else:
    dp = [[0,0,0] for _ in range(N//2)]
    # print(dp)
    # 初期化
    dp[0][0] = A[0]
    dp[0][1] = A[1]
    dp[0][2] = A[2]
    for i in range(N//2-1):
        dp[i+1][0] = dp[i][0] + A[2*i+2]
        dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3])
        dp[i+1][2] = max(dp[i][0] + A[2*i+4], dp[i][1] + A[2*i+4], dp[i][2] + A[2*i+4])
    # print(dp)
    print(max(dp[N//2-1][0],dp[N//2-1][1],dp[N//2-1][2]))

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

class Program
{
    public static void Main()
    {
        var n = ReadLine();
        var m = ReadLine();
        int count = 0;
        for(int i = 0; i < n.Length; i++)
        {
            if(n[i] != m[i])
                count++;
        }
        WriteLine(count);
        ReadLine();
    }
}

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

int const N = 100000, inf = 1e9;
int n, m, osz[N + 1];
bool has[N + 1];
vector<pair<int, int> > g[N + 1];

void no() { printf("-1\n"); }

int main(){
	scanf("%d%d", &n, &m);
	int an = 0;
	f(i, 0, m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		++osz[a];
		has[b] = true;
		g[a].emplace_back(b, c);
		if (a != b)++an;
	}
	
	f(i, 1, n + 1)if (!has[i])return no(), 0;
	
	stack<int> st;
	f(i, 1, n + 1)if (g[i].size() > 1)st.push(i);
	ll s = 0;
	while (!st.empty()){
		int id = st.top();
		st.pop();
		vector<pair<int, int> > &v = g[id];
		f(i, 0, v.size())if (v[i].first != id){
			int to = v[i].first;
			if (g[to].size() == 1 && g[to][0].first != to)st.push(to);
			g[to].emplace_back(to, 0);
			s += v[i].second - 1;
			swap(v[i], v.back());
			v.pop_back();
			--i;
		}
	}
	
	vector<ll> cy, v1, v2;
	f(i, 1, n + 1)if (has[i]){
		has[i] = false;
		if (g[i][0].first != i){
			int t = i;
			ll sm = 0;
			bool easy = false;
			do{
				has[t] = false;
				if (osz[t] > 1)easy = true;
				sm += g[t][0].second - 1;
				t = g[t][0].first;
			}while (t != i);
			if (easy)s += sm;
			else cy.push_back(sm);
		}else if (g[i].size() == 1 && osz[i] == 1)v1.push_back(g[i][0].second - 2);
		else for (auto z: g[i])v2.push_back(z.second - 1);
	}
	
	sort(cy.begin(), cy.end(), greater<ll>());
	sort(v1.begin(), v1.end(), greater<ll>());
	while (!v1.empty() && v1.back() <= 0)v1.pop_back();
	sort(v2.begin(), v2.end(), greater<ll>());
	while (!v2.empty() && v2.back() <= 0)v2.pop_back();
	
	if (s == 0 && !cy.empty()){
		if (v2.empty())return no(), 0;
		++an;
		s += v2[0];
		v2.erase(v2.begin());
	}
	an += cy.size();
	int need = 0;
	for (int t: cy){
		if (s <= 0)++need;
		--s;
		s += t;
	}
	
	int d = inf, j = v2.size();
	ll o = 0, th = 0;
	f(i, 0, v2.size())o += v2[i];
	f(i, 0, v1.size() + 1){
		if (i)th += v1[i - 1];
		while (j && o + th - v2[j - 1] >= need){
			--j;
			o -= v2[j];
		}
		if (o + th >= need)d = min(d, 2 * i + j);
	}
	
	printf("%d\n", d == inf ? -1 : an + d);
}

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

int main(){
	long long int n,k, temp;
	cin>>n>>k;
	long long int h[n+1];
	for (int i=1;i<=n;i++)
		cin>>h[i];
	long long int dp[n+1], ind  = 1;
	dp[1] = 0;
	for (long long int i=2;i<=n;i++){
		temp = LONG_MAX;
		for (long long int j=max(ind,i-k);j<i;j++){
			temp = min(temp, dp[j] + abs(h[j] - h[i]));
		}
		dp[i] = temp;
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	static int N;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		sc.close();

		dfs("", 'a');
	}

	public static void dfs(String s, char max) {
		if (s.length() == N) {
			System.out.println(s);
		} else {
			for (char c = 'a'; c <= max; c++) {
				dfs(s + c, ((c == max) ? (char) (max + 1) : max));
			}
		}
	}
}


Measured memory_bytes: 42524
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n; cin >> n;
	long long res = 1e18;
	for(long long a = 1; a * a <= n; a++) {
		if(n % a) continue;
		long long b = n / a;
		res = min(res, b + a - 2);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, a, b, c, d;

    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

    int price_a = ceil(1.0 * n / a) * b;
    int price_c = ceil(1.0 * n / c) * d;

    printf("%d\n", price_a <= price_c ? price_a : price_c);

    return 0;
}



Measured memory_bytes: 2144
import math
from itertools import permutations

l=[int(input()) for i in range(5)]
result=sum(math.ceil(l[i]/10)*10 for i in range(5))
orders=list(permutations(l,5))

for order in orders:
  tmp=order[0]
  for i in range(1,5):
    tmp+=math.ceil(order[i]/10)*10
  result=min(result,tmp)

print(result)


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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> arr(n);
	for (int i=0; i<n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	string res = "";
	for (string str : arr) {
		res += str;
	}
	cout << res;
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n,m;
    cin>>n>>m;
    map< int,int>  v;
    for (int i=0;i<=n;i++)
    {
        v[i]=0;
    }
    int p,cor=0,inc=0;
    string s;
    for (int i=0;i<m;i++)
    {
        cin>>p>>s;
        if (v[p]!=-1 && s.compare("WA")==0)
        {
            v[p]++;
        }
        else if(v[p]!=-1 && s.compare("AC")==0)
        {
            inc+=v[p];
            cor++;
            v[p]=-1;
        }
    }
    cout<<cor<<" "<<inc<<"\n";  
  return 0;
 }

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

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

using namespace std;

int main() {
    int n,cnt = 0, a_last = 0, b_first = 0, u = 0;
    cin >> n;
    string s;
    rep(i, n){
        cin >> s;
        rep(j, s.length() - 1){
            if(s[j] == 'A' && s[j+1] == 'B'){
                cnt++;
            }
        }
        if(s[s.length() - 1] == 'A' && s[0] == 'B'){
            u++;
            continue;
        }
        if(s[s.length() - 1] == 'A') a_last++;
        if(s[0] == 'B') b_first++;
    }
    int k = 0;
    if(u != 0 && a_last != 0){
        a_last--;
        k++;
    }
    if(u != 0 && b_first != 0){
        b_first--;
        k++;
    }
    if(u == 0){
        cout << cnt + min(a_last, b_first) << endl;
    }else{
        cout << cnt + (u - 1) + min(a_last, b_first) + k << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h> 
using namespace std;
int main(){
	long long int n , a , b , res,rem;
	cin>>n>>a>>b;
     res =(n/(a+b)) * a;
     rem = (n%(a+b));
    if(a<rem)
     cout<<res+a;
     else
     cout<<res+rem;
}


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

#define sc(a) scanf("%d",&a)
#define scm(a,b) scanf("%d%d",&a,&b)
#define fl(c,i,n) for(int i=c;i<n;i++)
#define f(i,n) for(int i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long int
#define ull unsigned long long int
#define inf INT_MAX
#define linf LLONG_MAX
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
//#define mp make_pair
#define nl printf("\n")
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pii pair<int,int>
#define MAXN 500005
#define MOD 1000000007

template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
/*int fact[MAXN];
int invfact[MAXN];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<MAXN;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[MAXN-1] = inv(fact[MAXN-1], MOD-2);
    for(int i=MAXN-1;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}*/
int n, m, a, b, q, v[200005], d[200005], c[200005], col[200005];
vector<int> g[200005];
int mp[200005];
void dfs(int v, int d, int c){
    if(mp[v]>=d) return;
    mp[v] = d;
    if(col[v]==0)   col[v] = c;
    for(int i=0;i<(int)g[v].size();i++){
        int x = g[v][i];
        dfs(x, d-1, c);
    }
}
void solve(){
    sc(n);
    sc(m);
    f(i, m){
        sc(a);
        sc(b);
        g[a].pb(b);
        g[b].pb(a);
    }
    sc(q);
    mem(col);
    f(i, 200005)    mp[i] = -1;
    f(i, q){
        sc(v[i]);
        sc(d[i]);
        sc(c[i]);
    }
    for(int i=q-1;i>=0;i--){
        dfs(v[i], d[i], c[i]);
    }
    f(i, n+1){
        if(i==0)    continue;
        printf("%d\n", col[i]);
    }
}
int main(){
    /*FILE *fin = freopen("C-small-attempt0.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("C-small.out", "w", stdout);*/
	//init();
    solve();
    return 0;
}


Measured memory_bytes: 12408
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let h: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 0;
    let mut cnt = 0;
    for i in 0..n - 1 {
        if h[i] >= h[i + 1] {
            cnt += 1;
        } else {
            ans = std::cmp::max(ans, cnt);
            cnt = 0;
        }
    }
    ans = std::cmp::max(ans, cnt);
    println!("{}", ans);
}


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

using namespace std;

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


int nd=d*2+1;
/*for(int i =1; i<=n; ++i){//forで回す必要ないね、ワルだけ
    nd = nd*i;
    ans += 1;
    if(nd>=n) break;
}*/
if(n%nd == 0){
    cout << n / nd << endl;
}else {
    cout << n / nd + 1 << endl;
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define PI 3.14159265359
 
int main(){
  ll X, A, B, i, j;
  
  cin >> X;
  
  for (ll A = -200; A <= 200; A++){
    for(ll B = -200; B <= 200; B++){
      if(pow(A, 5) - pow(B, 5) == X){
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 4056
import std.stdio,std.conv,std.algorithm,std.array;

void main(){
    char[101][101] map;
    while(true){
        int w,h;
        readf("%d %d\n",&h,&w);
        if(!w&&!h)break;
        bool[102*102*102] memo;
        foreach(y;0..h){
            map[y][0..w]=readln[0..w];
        }
        int x,y;
        loop:while(1){
            if(memo[y*102+x]){
                "LOOP".writeln;
                break;
            }
            memo[y*102+x]=true;
            final switch(map[y][x]){
                case '>':++x;break;
                case '<':--x;break;
                case 'v':++y;break;
                case '^':--y;break;
                case '.':
                    writeln(x," ",y);
                    break loop;
            } 
        }
    }
}

Measured memory_bytes: 2124
'use strict'
function Main(input) {
  const arr = input.split(" ");
  let count5 = 0, count7 = 0;
  
  arr.forEach(a => {
    if(a == 5){
      count5++;
    }else if(a == 7){
      count7++;
    }
  });
 
  console.log(count5 === 2 && count7 === 1 ? 'YES' : 'NO');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

long long n, w;

using ii=pair<long long, long long>;
queue< ii > q;

long long a, b;

long long maks[102][100005];

int main(void)
{
	
	cin >> n >> w;
	
	for(long long i=0;i<n;i++)
	{
		
		cin >> a >> b;
		
		q.push( {a, b} );
		
	}
	
	ii r=q.front();
	q.pop();
	
	for(long long i=0;i<w;i++)
	{
		
		if(r.first<=i+1)
		{
			
			maks[0][i]=r.second;
			
		}
			
	}
	
	for(long long i=1;i<n;i++)
	{
		
		r=q.front();
		q.pop();
		
		for(long long a=0;a<w;a++)
		{
			
			long long p1=0;
			
			if(r.first<a+1)
			{
				
				p1=maks[i-1][a-r.first]+r.second;
				
			}
			
			maks[i][a]=max(p1, maks[i-1][a]);
			
		}
		
	}
	
	cout << maks[n-1][w-1];
	
	return(0);
	
}


Measured memory_bytes: 78336
import java.util.*;

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

        String S = sc.next();
        String T = sc.next();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String U = sc.next();

        if(S.equals(U)){
            A = A - 1;
        }
        else if(T.equals(U)){
            B = B - 1;
        }
        System.out.println(A + " " + B);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << endl;
}

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

Measured memory_bytes: 256