akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  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;
  }
};


int main()
{
  int n,m; cin >> n >> m;
  vi s(n), t(m);
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i];

  vector<vector<mint>> dp(n+1, vector<mint>(m+1));
  vector<vector<mint>> sum(n+2, vector<mint>(m+2));
  rep(i,n+2) {
    sum[i][1].x = 1;    
  }
  rep(i,m+2) {
    sum[1][i].x = 1;    
  }  
  
  mint res(1);
  rep1(i,n) {
    rep1(j,m) {
      if(s[i-1] == t[j-1]) {
	dp[i][j] = sum[i][j];
      }
      else {
	dp[i][j].x = 0;
      }
      sum[i+1][j+1] = dp[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
      res += dp[i][j];
    }
  }
  cout << res.x << "\n";
  
  
  return 0;
}


Measured memory_bytes: 65908
// C - Exception Handling
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int> > a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.begin(), a.end(), greater<pair<int, int> >());
	for (int i = 0; i < n; i++)
		 cout << (a[0].second != i ? a[0].first : a[1].first) << endl;

	return 0;
}


Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (~scanf("%d", &N)) {
    vector<int> color(N);
    for (auto& x : color) scanf("%d", &x), --x;
    vec<int, 2> G(N);
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      --b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    vector<int> size(N);
    auto dfs1 = [&](auto& f, int v, int p = -1) -> void {
      size[v] = 1;
      for (int u : G[v]) {
        if (u != p) {
          f(f, u, v);
          size[v] += size[u];
        }
      }
    };
    dfs1(dfs1, 0);
    vector<ll> res(N, 1ll * (N + 1) * N / 2);
    vec<int, 2> stacks(N, {N});
    auto dfs2 = [&](auto& f, int v, int p = -1) -> void {
      int c = color[v];
      for (int u : G[v]) {
        if (u == p) continue;
        stacks[c].push_back(size[u]);
        f(f, u, v);
        int sz = stacks[c].back();
        res[c] -= 1ll * (sz + 1) * sz / 2;
        stacks[c].pop_back();
      }
      stacks[c].back() -= size[v];
    };
    dfs2(dfs2, 0);
    for (int c = 0; c < N; c++) {
      int sz = stacks[c].back();
      res[c] -= 1ll * (sz + 1) * sz / 2;
    }
    for (ll x : res) cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 47748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int cnt[100010];

int main()
{
	int n; read(n);
	for(;n--;){
		int x; read(x);
		++cnt[x];
	}
	int ans=0;
	for(int i=1; i<int(1e5); ++i){
		ans=max(ans, cnt[i]+cnt[i-1]+cnt[i+1]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = v[::2], v[1::2]
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()

if len(set(v)) == 1:
    print(n//2)
elif vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    print(n - max(vv1[1][1] + vv2[0][1], vv1[0][1] + vv2[1][1]))

Measured memory_bytes: 25180
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int age = Integer.parseInt(sc.next());
    int fee = Integer.parseInt(sc.next());
    if(age <= 5) System.out.println(0);
    else if(age <= 12) System.out.println(fee / 2);
    else System.out.println(fee);
  }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    char a;
    cin >> a;
    cout << ++ a;
    return 0;
}


Measured memory_bytes: 256
import math

n,k = (int(x) for x in input().split())
ans = 0
a = n*(k-1)
b = (k-1)*(k-2)//2

for i in range(k,n+2):
    a = a + n
    b = b + (i-1)
    c = a - b
    ans += c - b + 1
print(ans%(10**9+7))

Measured memory_bytes: 9220
using System;
namespace kozaiyApp
{
    public class DWall
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);
            int V = 10; // 頂点の数

            int[,] c = new int[V, V]; // 魔力テーブル これが隣接行列
            for (int i = 0; i < V; i++)
            {
                string[] inputC = Console.ReadLine().Split(' ');
                for (int j = 0; j < V; j++)
                {
                    c[i, j] = int.Parse(inputC[j]);
                }
            }

            // ワーシャルフロイド法
            for (int k = 0; k < V; k++)
            {
                for (int i = 0; i < V; i++)
                {
                    for (int j = 0; j < V; j++)
                    {
                        c[i, j] = Math.Min(c[i, j], c[i, k] + c[k, j]);
                    }
                }
            }

            int ans = 0;
            for (int i = 0; i < H; i++)
            {
                string[] inputA = Console.ReadLine().Split(' ');
                for (int j = 0; j < W; j++)
                {
                    int A = int.Parse(inputA[j]);
                    if (A == -1 || A == 1) continue;
                    ans += c[A, 1]; // A -> 1　の最短経路コストはc[A, 1]
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
bool cmp(pair<int,int> &a,pair<int,int> &b){
    return a.second < b.second;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int N;
    cin >> N;
    vector<pair<int,int>> LR(N);
    rep(i,N){
        int X,L;
        cin >> X >> L;
        LR[i].first  = X-L;
        LR[i].second = X+L; 
    }
    sort(ALL(LR),cmp);
    /*
    for(auto x:LR){
        cout << x.first << " " << x.second << endl;
    }
    */
    int left = -1e9-1;
    int ans = 0;
    for(auto x:LR){
        if(left<= x.first){
            left = x.second;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

int main()
{
	long n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	for (long i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	
	vector<ll> d(n);
	d[0] = 0;
	for (long i = 1; i < n; i += 2)
		d[i + 1] = (a[i] - a[i - 1]) * 2 + d[i - 1];
	d[1] = (a[0] - a[n - 1]) * 2 + d[n - 1];
	for (long i = 2; i < n - 1; i += 2)
		d[i + 1] = (a[i] - a[i - 1]) * 2 + d[i - 1];

	ll sumD = 0;
	for (long i = 1; i < n; i++)
		sumD += d[i];
	sum = (sum - sumD) / n;
	for (long i = 0; i < n; i++)
		printf("%lld ", sum + d[i]);

	return 0;
}


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

typedef long long ll;
typedef vector<ll> vec;


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

    vec dp(N,1e+15);    
    dp[0] = 0;

    for (ll i = 0; i < N; i++)
    {
        if( i+1 < N )
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));        
        if( i+2 < N )
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    cout << dp[N-1] << endl;
    


}

Measured memory_bytes: 4720
#include <stdio.h>

int main()
{
  int x, y, r, d;

  scanf("%d%d", &x, &y);

  if(x < y){
    d = x;
    x = y;
    y = d;
  }

  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  printf("%d\n", x);

  return 0;
}



Measured memory_bytes: 2084
import java.util.Scanner;

/**
 * @author yoshida3203
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		String S=sc.next();
//		char[]a=S.toCharArray();

		if(S.equals("Sunny")){
			System.out.println("Cloudy");
		}else if(S.equals("Cloudy")){
			System.out.println("Rainy");
		}else{
			System.out.println("Sunny");
		}

	}
}



Measured memory_bytes: 35556
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define pbb pair<bool,bool>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod (ll)(1e9+7) 
#define hmod 1286031825167LL
using namespace std;

int n,k,l,dsu_road[200005],dsu_rail[200005],u,v;
map <pii,int> m;
int find_road(int x){
	if (dsu_road[x] == x)
	return x;
	return dsu_road[x]=find_road(dsu_road[x]);
}
int find_rail(int x){
	if (dsu_rail[x] == x)
	return x;
	return dsu_rail[x]=find_rail(dsu_rail[x]);
}
int main(){	
    ios::sync_with_stdio(false);
    cin >> n >> k >> l;
    for (int i=1;i<=n;i++){
    	dsu_road[i]=i;
    	dsu_rail[i]=i;
	}
	for (int i=1;i<=k;i++){
		cin >> u >> v;
		dsu_road[find_road(u)]=find_road(v);
	}
	for (int i=1;i<=l;i++){
		cin >> u >> v;
		dsu_rail[find_rail(u)]=find_rail(v);
	}
	for (int i=1;i<=n;i++){
		m[mp(find_road(i),find_rail(i))]++;
	}
	for (int i=1;i<=n;i++){
		cout << m[mp(find_road(i),find_rail(i))] << " ";
	}
	cout << "\n";
    return 0;
}	

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

const int MAX = 300005;
const int MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    // 計算例
    int n,a,b;
    ll k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    rep(i,n+1){
      if((k-a*i)%b==0&&(k-a*i)/b<=n){
        //cout << i << (k-a*i)/b << endl;
        ans += COM(n,i) * COM(n,(k-a*i)/b);
        ans %= 998244353;
      }
    }
    cout << ans << endl;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, n;
    cin >> h >> n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    int sum = 0;
    for(int i=0; i<n; i++) sum += a[i];
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

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

int K;

int solve(const vector<int>& A, const vector<int>& B, vector<int> C, int i, int k, int borrow)
{
  int ret = 0;
  if (i >= C.size()) {
    reverse(C.begin(), C.end());
    for (i = 0; i < 10; ++i) {
      ret *= 10;
      ret += C[i];
    }
    return ret;
  }

  if (A[i] - borrow >= B[i]) {
    C[i] = A[i] - borrow - B[i];
    ret = max(ret, solve(A, B, C, i+1, k, 0));
  } else {
    C[i] = A[i] - borrow + 10 - B[i];
    if (k < K)
      ret = max(ret, solve(A, B, C, i+1, k+1, 0));
    ret = max(ret, solve(A, B, C, i+1, k, 1));
  }
  return ret;
}

int main()
{
  string A, B;
  while (cin >> A >> B >> K) {
    vector<int> AA(10, 0), BB(10, 0), C(10, 0);
    for (int i = 0; i < A.size(); ++i)
      AA[i] = A[A.size()-i-1] - '0';
    for (int i = 0; i < B.size(); ++i)
      BB[i] = B[B.size()-i-1] - '0';

    cout << solve(AA, BB, C, 0, 0, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  int L,R;
  cin >> L >> R;
  int modL = L % 2019;
  int modR = R % 2019;
  if (R - L >= 2018){
    cout << 0 << endl;
    return 0;
  }
  else if (modL > modR){
    cout << 0 << endl;
    return 0;
  }
  int N = 2019;
  for (int i = modL; i < modR; i++) {
    for (int j = i+1; j <= modR; j++) {
      if (i != j){
        int M = ((i*j) % 2019) % 2019;
        if (M < N){
          N = M;
        }
      }
    }
  }
  cout << N << endl;
}   

Measured memory_bytes: 3560
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    int a, b, c;
    cin >> a >> b >> c;
    if(2 * max(a,max(b,c)) == a + b + c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            Console.WriteLine(String.Join(" ", Console.ReadLine().Split().Select(p => int.Parse(p)).OrderBy(p => p).Select(p => p.ToString()).ToArray()));
        }
    }
}

Measured memory_bytes: 6444
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;

int main(){
        int n,i,v,u,w;
        cin >> n;
        queue<tuple<int,int,int>> q;
        vector<int> a(n,-1);
        tuple<int,int,int> t;
        cin >> v >> u >> w;
        --v; --u;
        if(w%2==0){a.at(v) = 0; a.at(u) = 0;}
        else{a.at(v) = 0; a.at(u) = 1;}
        for(i=1;i<n-1;++i){
                cin >> v >> u >> w;
                --v; --u;
                if(a.at(v)==-1&&a.at(u)==-1){
                        q.push(make_tuple(v, u, w));
                        continue;
                }
                if(a.at(v)!=-1){
                        if(w%2==0) a.at(u) = a.at(v);
                        else a.at(u) = (a.at(v)+1)%2;
                }
                if(a.at(u)!=-1){
                        if(w%2==0) a.at(v) = a.at(u);
                        else a.at(v) = (a.at(u)+1)%2;
                }
        }
        while(!q.empty()){
                t = q.front(); q.pop();
                v = get<0>(t); u = get<1>(t); w = get<2>(t);
                if(a.at(v)==-1&&a.at(u)==-1){
                        q.push(t);
                        continue;
                }
                if(a.at(v)!=-1){
                        if(w%2==0) a.at(u) = a.at(v);
                        else a.at(u) = (a.at(v)+1)%2;
                }
                if(a.at(u)!=-1){
                        if(w%2==0) a.at(v) = a.at(u);
                        else a.at(v) = (a.at(u)+1)%2;
                }
        }
        for(i=0;i<n;++i) cout << a.at(i) << endl;
        return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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;
}

int main()
{
  ll N;
  cin >> N;
  vector<P> A(N-1);
  vector<vector<ll>> List(N,vector<ll> ());
  REP(i,N-1){
    cin >> A[i].first >> A[i].second;
    A[i].fi--;
    A[i].se--;
    List[A[i].fi].push_back(A[i].se);
    List[A[i].se].push_back(A[i].fi);
  }
  
  queue<ll> que;
  que.push(0);
  vector<ll> dist(N,-1);
  dist[0]=0;
  while(!que.empty()){
    ll v=que.front();
    que.pop();
    for(auto nv:List[v]){
      if(dist[nv]!=-1) continue;
      que.push(nv);
      dist[nv]=dist[v]+1;
    }
  }

  queue<ll> que2;
  que2.push(N-1);
  ll snuke;
  ll fennec;
  while(!que2.empty()){
    ll v=que2.front();
    que2.pop();
    for(auto nv:List[v]){
      if(dist[nv]!=dist[v]-1) continue;
      que2.push(nv); 
      if(dist[nv]==dist[N-1]/2){
        fennec=nv;
        snuke=v;
      }
    }
  }

  queue<ll> que3;
  que3.push(fennec);
  vector<ll> dist3(N,-1);
  dist3[fennec]=0;
  ll cntf=1;
  while(!que3.empty()){
    ll v=que3.front();
    que3.pop();
    for(auto nv:List[v]){
      if(dist3[nv]!=-1||nv==snuke) continue;
      que3.push(nv);
      dist3[nv]=0;
      cntf++;
    }
  }

  if(cntf>N-cntf){
    cout << "Fennec" << endl;
  }else{
    cout << "Snuke" << endl;
  }
}


Measured memory_bytes: 12500
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,D;
    cin>>N>>D;
    int a=D*2+1;
    if(N%a==0) cout<<N/a<<endl;
    else cout<<N/a+1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#define N 101

using namespace std;

int visited[N], discovery[N], finish[N], tt, n;
vector<int> G[N];

void dfs(int u) {
    visited[u] = 1;
    discovery[u] = ++tt;
    for (int i = 0; i < G[u].size(); i++) {
        if (visited[G[u][i]] == 0) {
            dfs(G[u][i]);
        }
    }
    finish[u] = ++tt;
}

int main() {
    int u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    memset(visited, 0, sizeof(visited));
    tt = 0;

    for (int i = 0; i < n; i++) {
        if (visited[i] == 0) {
            dfs(i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << discovery[i] << " " << finish[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

string k;
int d,n;
int f[10001][100],g[10001][100];

int fdp(int ind,int r)
{
	if(ind==n)
	{
		if(r==0)
			return 1;
		return 0;
	}
	if(f[ind][r]!=-1)
		return f[ind][r];
	f[ind][r]=0;
	fo(i,10)
	{
		f[ind][r]=(f[ind][r] + fdp(ind+1,((r-i)%d+d)%d))%mod;
	}
	return f[ind][r];
}

int gdp(int ind,int r)
{
	if(ind==n)
	{
		if(r==0)
			return 1;
		return 0;
	}
	if(g[ind][r]!=-1)
		return g[ind][r];
	g[ind][r]=0;
	fo(i,k[ind]-'0')
	{
		g[ind][r]=(g[ind][r] + fdp(ind+1,((r-i)%d+d)%d))%mod;
	}
	g[ind][r]=(g[ind][r] + gdp(ind+1,((r-k[ind]+'0')%d+d)%d))%mod;
	return g[ind][r];
}


signed main()
{
	fio
	cin>>k>>d;
	n=k.size();
	memset(f,-1,sizeof(f));
	memset(g,-1,sizeof(g));
	cout<<((gdp(0,0)-1)%mod+mod)%mod<<'\n';
	printclock;
}

Measured memory_bytes: 16512
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
int main() {
	int N;
	string s;
	cin >> N >> s;
	if (N >= 3200)cout << s << endl;
	else cout << "red" << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD (1000000007ll)
#define ALL(x) x.begin(), x.end()

using namespace std;
struct node
{
    int id;
    int root;
    vector<int> to;
    vector<int> from;
};
int main()
{
    int n, m;
    cin >> n >> m;
    node t[n];
    rep(i, n)
    {
        t[i] = node{i, -1, {}, {}};
    }
    rep(i, n + m - 1)
    {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        t[from].to.push_back(to);
        t[to].from.push_back(from);
    }
    int rootid = 0;
    while (!t[rootid].from.empty())
    {
        rootid = t[rootid].from[0];
    }
    //cout << rootid << endl;
    int nowid = rootid;
    int nextid;
    t[rootid].root = -1;
    queue<int> que;
    que.push(rootid);
    while (!que.empty())
    { //!t[nowid].to.empty())
        int nowid = que.front();
        que.pop();

        for (auto ind : t[nowid].to)
        {
            if (t[ind].from.size() == 1)
            {
                t[ind].root = nowid;
                que.push(ind);
            }
            t[ind].from.erase(remove(ALL(t[ind].from), nowid), t[ind].from.end());
        }
    }

    rep(i, n)
    {
        cout << t[i].root + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 12544
#include<iostream>
using namespace std;
template<int N>struct a{
	long ar[N+1];
	constexpr a():ar(){
		ar[0]=1;
		for(long i=1;i<=N;i++)ar[i]=ar[i-1]*i%1000000007;
	}
};
constexpr auto ans=a<100000>();
int n;
main(){
	cin>>n;
	cout<<ans.ar[n]<<endl;
}


Measured memory_bytes: 256
[N,K] = list(map(int,input().split()))
P = list(map(int,input().split()))
EP = []
for i in range(N):
    EP.append((P[i]+1)/2)

SP = [0]*(N-K+1)
S0 = 0
for j in range(K):
    S0 += EP[j]
SP[0] = S0
for i in range(1,len(SP)):
    SP[i] = SP[i-1]+EP[i+K-1]-EP[i-1]

print(max(SP))

Measured memory_bytes: 76936
hours_p_distance, hours_q_distance, hours_r_distance = map(int, input().split())
 
root_p_q = hours_p_distance + hours_q_distance
root_p_r = hours_p_distance + hours_r_distance
root_q_r = hours_q_distance + hours_r_distance
 
print(min(root_p_q, root_p_r, root_q_r))

Measured memory_bytes: 9064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->
      a.q != b.q ? a.q-b.q : a.p-b.p
    );
    for (int i = 0; i < N; i++) {
      int X = sc.nextInt();
      int L = sc.nextInt();
      pq.offer(new Pair(X-L, X+L));
    }
    
    int ans = 1;
    Pair last = pq.poll();
    while (!pq.isEmpty()) {
      Pair now = pq.poll();
      if (last.q <= now.p) {
        ans++;
        last = now;
      }
    }
    
    System.out.println(ans);
  }
  
  static class Pair {
    private final int p;
    private final int q;
    Pair(int p, int q) {
      this.p = p;
      this.q = q;
    }
  }
}

Measured memory_bytes: 92236
#include<stdio.h>
typedef long int li;
li f(li a){
  li s=0;
  if((a%4)*((a+1)%4))s=1;
  return (a%2)?s:s^a;  
}
int main(){
  li a,b;
  scanf("%ld%ld",&a,&b);
  a=f(a-1);  b=f(b);
  printf("%ld",a^b);
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  String a[]=sc.next().split("",0);
  int count=0;
  String b=a[0];
  for(int i=1;i<a.length;i++){
    if(!b.equals(a[i])){b=a[i];count++;}
  }
  System.out.println(count);
}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

set<int> S;
int main(){
fast;
int x, n;
cin>>x>>n;
S.clear();
for(int i=0;i<n;i++) {
    int v;
    cin>>v;
    S.insert(v);
}

if(S.find(x)==S.end()) {
    cout<<x<<endl;
    return 0;
}

int ans1, ans2;
for(int i=x+1;i<=101;i++) {
    if(S.find(i)==S.end()) {
        ans1=i;
        break;
    }
}
for(int i=x-1;i>=0;i--) {
    if(S.find(i)==S.end()) {
        ans2=i;
        break;
    }
}

if(abs(x-ans2) <= abs(x-ans1)) {
    cout<<ans2<<endl;
} else {
    cout<<ans1<<endl;
}
return 0;
}

Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c!=1000000000){
  rep(i,a){
    if(b-1<i)
      cout<<1000000000<<' ';
    else
      cout<<c<<' ';
    }
    }
  else{
   rep(i,a){
    if(b-1<i)
      cout<<1<<' ';
    else 
      cout<<c<<' ';
  }
    }
}

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

using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

int st[202], l;

string str;

int main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  getline(cin, str);
  
  bool f = true;
  for(char c : str) {
  	if('0' <= c && c <= '9') {
  		if(f)st[l++] = c - '0';
  		else st[l-1] = st[l-1] * 10 + (c - '0');
  		f = false;
  	}else if(c=='+') {
  		st[l-2] = st[l-2] + st[l-1];
  		l--;
  	}else if(c=='-') {
  		st[l-2] = st[l-2] - st[l-1];
  		l--;
  	}else if(c=='*') {
  		st[l-2] = st[l-2] * st[l-1];
  		l--;
  	}else {
  		f = true;
  		//rep(i, l)cout<<st[i]<<' ';
  		//cout<<endl;
  	}
  }
  
  cout<<st[l-1]<<endl;
  
  return 0;
}



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

long get_max(long *array, int size) {
  int i;
  long max = -1000000;
  for (i = 0; i < size; i++) {
    if (max < array[i]) max = array[i];
  }
  return max;
}

long get_min(long *array, int size) {
  int i;
  long min = 1000000;
  for (i = 0; i < size; i++) {
    if (min > array[i]) min = array[i];
  }
  return min;
}

long get_sum(long *array, int size) {
  int i;
  long sum = 0;
  for (i = 0; i < size; i++) sum += array[i];
  return sum;
}

int main(int argc, char const *argv[])
{
  unsigned int n, i;
  cin >> n;

  long array[n];
  for (i = 0; i < n; i++) cin >> array[i];

  cout << get_min(array, n) << " " << get_max(array, n) << " " << get_sum(array, n) << "\n";

  return 0;
}



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

void Main() {
    // input
    u_int32_t N;
    cin >> N;

    u_int32_t nums[N+1];
    
    for (u_int32_t i = 0; i <= N; i++) {
        nums[i] = 0;
    }

    for (u_int32_t i = 2; i <= N; i++) {
        u_int32_t A;
        cin >> A;
        nums[A]++;
    }

    for (u_int32_t i = 1; i <= N; i++) {
        cout << nums[i] << endl;
    }


    // translate


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4324
#include<stdio.h>
    #include<string.h>
    int main(void){
    int A,B,C,D,E,N,M,x,y,i,j,cou=0,cou2=99999999,v[1000000],w[1000000],min_i,en=0;
        char S[100],W[100],s[10],X,Y;
    scanf("%c",&X);
    if(X=='A'){
        printf("T");
    }
    else if(X=='T'){
        printf("A");
    }
    else if(X=='C'){
        printf("G");
    }
    else if(X=='G'){
        printf("C");
    }
    
    return 0;
    }

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

int main(){
  int five_count = 0;
  int j = 0;
  for(int i = 0;i<3;i++){
  	cin >> j;
    if(j==5)
      five_count++;
  }
  if(five_count == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import itertools
import numpy as np
N,M = map(int,input().split())
H = list(map(int,input().split()))
n=[1]*N
for i in range(0,M):
    m = list(map(int,input().split()))
    if H[m[0]-1] > H[m[1]-1]:
        n[m[1]-1]=0
    elif H[m[0]-1] == H[m[1]-1]:
        n[m[0]-1]=0
        n[m[1]-1]=0
    else:
        n[m[0]-1]=0
print(n.count(1))

Measured memory_bytes: 38448
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	ll n; cin>>n;
	ll ans=0;
	if(n%2==0){			
		n/=10;
		ans=n;
		while(n){
			n/=5;
			ans+=n;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    s = readline().rstrip().decode()
    check = {'ABC': 'ARC', 'ARC': 'ABC'}
    print(check[s])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
	int A,B;
	cin >> A >> B;
	if(A==1) A = 14;
	if(B==1) B = 14;
	if(A>B) cout << "Alice" <<endl;
	else if (A<B) cout << "Bob" <<endl;
	else cout << "Draw" <<endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def dfs(x):
        fx = f[x]
        for y in v[x]:
            if d[y]:
                d[y] = 0
                f[y] += fx
                dfs(y)
    n,q = LI()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    f = [0]*n
    for i in range(q):
        p,x = LI()
        p -= 1
        f[p] += x
    d = [1]*n
    d[0] = 0
    q = deque([0])
    while q:
        x = q.popleft()
        fx = f[x]
        for y in v[x]:
            if d[y]:
                d[y] = 0
                f[y] += fx
                q.append(y)
    print(*f,sep=" ")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 96532
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 101;
const int INF = 1<<28;
 
int main()
{
    int n,cost[MAX][MAX],a,b,c;
    while (cin >> n, n) {
	fill(cost[0], cost[MAX], INF);
 
	int M = 0;
	for (int i = 0; i < n; i++) {
	    cin >> a >> b >> c;
	    cost[a][b] = cost[b][a] = c;
	    M = max(M, max(a, b));
	}
	++M;
	for (int k = 0; k < M; k++) {
	    for (int i = 0; i < M; i++) {
		for (int j = 0; j < M; j++) {
		    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
		}
	    }
	}
	int ans = INF, sum, num;
	for (int i = 0; i < M; i++) {
	    sum = 0;
	    for (int j = 0; j < M; j++) {
		if (i == j) continue;
		sum += cost[i][j];
	    }
	    if (sum < ans) {
		ans = sum;
		num = i;
	    }
	}
	cout << num << ' ' << ans << endl;
    }
    return 0;
}

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

int main() {
 int data[5];
  for(int i=0; i<5; i++){
    cin >> data[i];
  }
  for(int i=0; i<5; i++){
    if(data[i]==0){
      cout << i+1;
      break;
    }
  }
}


Measured memory_bytes: 3632
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(){
    
    long long int i,j,s;
    cin >> s;
    long long int dp[s+1];
    memset(dp,0,sizeof(dp));
    dp[0] = 1;
    for(i = 1;i<=s;i++){
        for(j = 3;j<=s;j++){
            if(i - j >= 0) dp[i] = (dp[i] + dp[i - j]) % MOD;
        }
    }
      cout << dp[s] << endl;
    return 0;
}

Measured memory_bytes: 3608
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    k = int(input())
    a, b = map(int, input().split())
    for i in range(a, b + 1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')

main()

Measured memory_bytes: 9060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long[] a = new long[5];
		long n = sc.nextLong();
		for(int i = 0; i < 5; i++) {
			a[i] = sc.nextLong();
		}
		long min = a[0];
		for(int i = 0; i < 5; i++) {
			if(min > a[i]) {
				min = a[i];
			}
		}
		long ans = 0;
		ans += (n + min - 1)/min;
		ans += 4;
		
		System.out.println(ans);
		sc.close();
	}
	
}



Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int arr[N];
pair<int, int> DP[N];

pair<int, int> merge(pair<int, int> A, pair<int, int> B) {
  set<pair<int, int>> st; // maximum Val, without repeat index
  st.insert({-arr[A.first], A.first});
  st.insert({-arr[A.second], A.second});
  st.insert({-arr[B.first], B.first});
  st.insert({-arr[B.second], B.second});
  pair<int, int> ans;
  ans.first = (*st.begin()).second;
  st.erase(st.begin());
  ans.second = (*st.begin()).second;
  return ans;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  // problem on SOS DP
  int n;
  cin >> n;
  for (int i = 0; i < (1 << n); ++i) {
    cin >> arr[i];
    DP[i] = {i, (1 << n)};
  }
  for (int i = 0; i < n; ++i) {
    for (int mask = 0; mask < (1 << n); ++mask) {
      if(mask & (1 << i)) {
        DP[mask] = merge(DP[mask], DP[mask ^ (1 << i)]); // SOS
      }
    }
  }
  int best = 0;
  for (int i = 0; i < (1 << n); ++i) {
    best = max(best, arr[DP[i].first] + arr[DP[i].second]);
    if(i)
      cout << best << '\n';
  }
  return 0;
}


Measured memory_bytes: 7168
#include "stdio.h"
int main(){
    int A,B,C,D,P,result;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    scanf("%d",&P);
    if (C < P){
        if (A * P <= B + D * (P-C)) result = A * P;
        else if (A * P > B + D * (P-C))result = B + D * (P-C);
    }else{
        if (A * P <= B) result = A * P;
        else if (A * P > B)result = B;
    }
    printf("%d\n",result);
    return 0;
}

Measured memory_bytes: 596
N = int(input())
S = []
P = []
res = [-1]*N
for i in range(N):
    tmp = input().split()
    S.append(tmp[0])
    P.append(int(tmp[1]))
    this = 1
    for j in range(i):
        if S[i] < S[j]:
            res[j] += 1
            continue
        if S[i] == S[j]:
            if P[i] > P[j]:
                res[j] += 1
                continue
        this += 1
    res[i] = this
ans = [-1]*N
for i, v in enumerate(res):
    ans[v-1] = i + 1
for v in ans:
    print(v)


Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String ssc = sc.nextLine();
		String[] assc = ssc.split(" ");
		int inn = Integer.parseInt(assc[0]);
		int inm = Integer.parseInt(assc[1]);
		int[][] iainn = new int[inn][inn];
		int sil = 0;
		int sir = 0;
		int retcount = 0;
		int retflag = 0;
		String[] siroot = new String[inm];
		for(int i=0;i<inn;i++){
			for(int j=0;j<inn;j++){
				iainn[i][j] = 1000;
			}
		}
		for(int i=0;i<inm;i++){
			ssc = sc.nextLine();
			siroot[i] = ssc;
		}
		for(int ing=0;ing<inm;ing++){
			for(int i=0;i<inm;i++){
				if(ing==i){
					continue;
				}
				ssc = siroot[i];
				assc = ssc.split(" ");
				sil = Integer.parseInt(assc[0]);
				sir = Integer.parseInt(assc[1]);
				sil--;
				sir--;
				iainn[sil][sir] = 1;
				iainn[sir][sil] = 1;
			}
			for(int x=0;x<inn;x++){
				for(int y=0;y<inn;y++){
					for(int z=0;z<inn;z++){
						if(iainn[y][z] > iainn[y][x] + iainn[x][z]){
							iainn[y][z] = iainn[y][x] + iainn[x][z];
						}
					}
				}
			}
			for(int j=0;j<inn;j++){
				for(int k=0;k<inn;k++){
					if(j==k){
						continue;
					}
					else if(iainn[j][k]>=1000){
						retflag++;
					}
					else{
						iainn[j][k] = 1000;
					}
				}
			}
			if(retflag!=0){
				retcount++;
				retflag = 0;
			}
		}
		System.out.println(retcount);
    }
}


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

using namespace std;

template <class T> void chkmax(T& x, T y) {
  x = x > y ? x : y;
}

template <class T> void chkmin(T& x, T y) {
  x = x < y ? x : y;
}

template <class T> void read(T& x) {
  x = 0; char ch = 0; int f = 1;
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  x *= f;
}

template <class T> void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}

template <class T> void writeln(T x) {
  write(x), puts("");
}

int main() {
  string s; 
  cin >> s;
  int n = (int)s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      a[i + 1] = max(a[i + 1], a[i] + 1);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += a[i];
  }
  writeln(ans);
  return 0; 
}

Measured memory_bytes: 2948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int N = S.length();

		String S_front = S.substring(0, (N-1)/2);
		String S_back = S.substring((N+3)/2-1, N);

		String ans = "No";
		if(checkSentence(S) && checkSentence(S_front) && checkSentence(S_back)) {
			ans = "Yes";
		}

		System.out.println(ans);
	}

	//回文チェック
	public static boolean checkSentence(String s) {
		boolean b = true;

		int checkindex = s.length() / 2;
		for(int i=0; i<checkindex; i++) {
			if(s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				b = false;
				break;
			}
		}


		return b;
	}

}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String N = sc.nextLine();

        Integer a = Integer.parseInt(N.substring(0, 2));
        Integer b = Integer.parseInt(N.substring(2, 4));

        System.out.println(result(a, b));
    }

    public static String exec(String N) {

        Integer a = Integer.parseInt(N.substring(0, 2));
        Integer b = Integer.parseInt(N.substring(2, 4));
        return result(a, b);
    }

    private static String result(int a, int b) {
        boolean isYYMM = isYY(a) && isMM(b);
        boolean isMMYY = isYY(b) && isMM(a);
        if (isYYMM && isMMYY) {
            return "AMBIGUOUS";
        } else if (isYYMM) {
            return "YYMM";
        } else if (isMMYY) {
            return "MMYY";
        } else {
            return "NA";
        }
    }

    private static boolean isYY(int yy) {
        return yy >= 0 && yy <= 99;
    }

    private static boolean isMM(int MM) {
        return MM > 0 && MM < 13;
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    string s; cin>>s;
    int k; cin>>k;
    for(int i=0;i<n;i++){
        if(s[i]!=s[k-1]) s[i]='*';
    }
    cout<<s<<endl;
    return 0;
}


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

bool is_prime[1121];
int prime[1121];
int dp[15][1121];

int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i <= 1120; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = i * 2; j <= 1120; j += i)is_prime[j] = false;
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i <= p; i++) {
		for (int j = 14; j >= 1; j--) {
			for (int k = prime[i - 1]; k <= 1120; k++) {
				dp[j][k] += dp[j - 1][k - prime[i - 1]];
			}
		}
	}

	int n, k;
	while (scanf("%d%d", &n, &k), n)printf("%d\n", dp[k][n]);
}

Measured memory_bytes: 3248
import java.util.*;

public class Main {
	double EPS = 10.e-08;
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [][] data = new int[n][26];
			
			for(int i = 0; i < n; i++){
				String s = sc.next();
				for(int j = 0 ; j < s.length(); j++){
					data[i][s.charAt(j) - 'a']++;
				}
			}
			
			HashMap<String, Integer> map = new HashMap<>();
			for(int i = 0; i < n; i++){
				StringBuilder sb = new StringBuilder();
				for(int j = 0; j < 26; j++){
					sb.append(" " + data[i][j]);
				}
				
				if(map.containsKey(sb.toString())){
					map.put(sb.toString(), map.get(sb.toString()) + 1);
				}
				else {
					map.put(sb.toString(), 1);
				}
			}
			
			long count = 0;
			for(String key: map.keySet()) {
				long current =  map.get(key);
				count += current * (current - 1) / 2;
			}
			
			System.out.println(count);
			
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 181300
#include <iostream>

using namespace std;

int a;
string s;
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    cin >> a >> s;
    if(a < 3200)
    {
        cout << "red";
    }
    else
    {
        cout << s;
    }
    return 0;
}


Measured memory_bytes: 256
N = input()
N = int(N)+1
X = [0]
C = [0]*360

for i in range(1,N):
    x = input()
    X.append(x.split())
    i_start = (int(X[i][0])-1)*30+int(X[i][1])-1
    i_end = i_start+int(X[i][2])-1

    for j in range(i_start,i_end+1):
        C[j%360] = max(C[j%360],int(X[i][3]))

    for k in range(1,int(X[i][3])+1):
        C[(i_start-k+360)%360] = max(C[(i_start-k+360)%360],int(X[i][3])-k)
        C[(i_end+k)%360] = max(C[(i_end+k)%360],int(X[i][3])-k)

print(min(C))

Measured memory_bytes: 7768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 998244353;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    vector<ll> hai;
    ll n,x,m;
    cin>>n>>x>>m;
    bool judgeloop=false;
    bool judge1=false;
    bool judge0=false;
    ll markloop;
    rep(i,m){
        hai.push_back(x);
        if(i+1>=n) break;
        if(hai[i]==1) {
            judge1=true;
            break;
        }
        if(hai[i]==0){
            judge0=true;
            break;
        }
        x*=x;
        x%=m;
        ll elen=hai.size();
        rep(j,elen){
            if(hai[j]==x){
                judgeloop=true;
                markloop=j;
                break;
            }
        }
    }

    ll ans=0;
    ll len=hai.size();
    if(judge0){
        rep(i,len){
            ans+=hai[i];
        }
        //cout<<1<<endl;
    }
    else if(judge1){
        rep(i,len){
            ans+=hai[i];
        }
        ans+=(n-len);
        //cout<<2<<endl;
    }
    else if(judgeloop){
        ll imlen=len-markloop;
        ll loop=(n-markloop)/imlen;
        ll resi=(n-markloop)%imlen;
        ll sum=0;
        rep(i,markloop){
            ans+=hai[i];
        }
        rep(i,imlen){
            sum+=hai[markloop+i];
        }
        ans+=(sum*loop);
        rep(i,resi){
            ans+=hai[markloop+i];
        }
        //cout<<3<<endl;
    }
    else{
        rep(i,len){
            ans+=hai[i];
        }
        //cout<<4<<endl;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4320