akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    int n;
    int k;
    int[] h;

    Main(int n, int k, int[] h) {
        this.n = n;
        this.k = k;
        this.h = h;
    }

    /**
     * 
     * @return greeting message
     */
    public int solve() {

        int p = 0;

        for (int hi : h) {
            if (hi >= k) {
                p++;
            }
        }
        return p;
    }

    public static void main(String[] args) {

        // input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // solve
        int p = new Main(n, k, h).solve();

        // display
        System.out.println(p);
    }

}


Measured memory_bytes: 49300
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max(A * B, C * D) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int sx, sy, tx, ty;

    cin >> sx >> sy >> tx >> ty;

    string res = "";

    REP(i, ty - sy)
    res = res + "U";
    REP(i, tx - sx)
    res = res + "R";
    REP(i, ty - sy)
    res = res + "D";
    REP(i, tx - sx)
    res = res + "L";
    res = res + "L";

    REP(i, ty - sy + 1)
    res = res + "U";
    REP(i, tx - sx + 1)
    res = res + "R";
    res = res + "D";
    res = res + "R";
    REP(i, ty - sy + 1)
    res = res + "D";
    REP(i, tx - sx + 1)
    res = res + "L";
    res = res + "U";

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve113(int p, int q) {
    vector<int> fractional, remainder;
    int beginIndex = -1;
    remainder.push_back(p);
    while (p) {
        int i = p * 10 / q;
        int j = p * 10 % q;
        if (find(ALL(remainder), j) != remainder.end()) {
            fractional.push_back(i);
            beginIndex = find(ALL(remainder),j) - remainder.begin();
            break;
        }else {
            fractional.push_back(i);
            remainder.push_back(j);
        }
        p = j;
    }
    REP(i,fractional.size()-1) {
        cout << fractional[i];
    }
    cout << fractional.back() << endl;
    if (beginIndex != -1) {
        REP(i,fractional.size()) {
            if (i >= beginIndex) cout << "^";
            else cout << " ";
        }
        cout << endl;
    }
}

int main() {
    int p, q;
    while (cin >> p >> q) {
        solve113(p,q);
    }
    return 0;
}

Measured memory_bytes: 1220
program main

  implicit none
  
  character(10) :: s, t, u
  integer :: a, b
  

  read(*,*) s, t
  read(*,*) a, b
  read(*,*) u

  if( u == s ) then
    print*, a-1, b
  else if( u == t ) then
    print*, a, b-1
  else
    print*, a, b
  end if
  
end program main


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

 

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


    int n;
    cin>>n;
    int a[n][n-1];
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>a[i][j];
            a[i][j]--;
        }
    }

    int ans = 0;
    int now[n] = {};
    while(true){
        bool used[n] = {};
        bool all = true;
        for(int i=0;i<n;i++){
            if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
            int t = a[i][now[i]];
            if(i == a[t][now[t]]){
                used[i] = true;
                used[t] = true;
                now[i]++;
                now[t]++;
                all = false;
            }
        }
        if(all){
            bool ok = true;
            for(int i=0;i<n;i++){
                if(now[i]!=n-1) ok =false;
            }
            if(ok){
                cout << ans << endl;
                return 0;
            }
            cout << -1 << endl;
            return 0;
        }
        ans++;
        //cerr<<ans<<endl;
    }

}

Measured memory_bytes: 4224
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vpii = vector<pii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { if (a > b) { a = b; return true; } else return false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { if (a < b) { a = b; return true; } else return false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b;
  cin >> a >> b;
  cout << (a + b >= 10 ? "error" : to_string(a + b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    double A[100];
    int N;
    cin>>N;
    double sum=0;
    for(int i=0;i<N;i++){
    cin>>A[i];
    //cout<<A[i]<<endl;
    sum+=1/A[i];
    }
    //cout<<sum<<endl;
    cout<<1/sum<<endl;
}


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

int main(){
	string s;
  cin>>s;
  int a;
  a=1000;
  for(int i=0;i<s.size()-2;i++){
if(a>abs(753-((s.at(i)-'0')*100+(s.at(i+1)-'0')*10+s.at(i+2)-'0')))
   a=abs(753-((s.at(i)-'0')*100+(s.at(i+1)-'0')*10+s.at(i+2)-'0'));
}
cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,m,q,pa[55],pb[55],pc[55],pd[55],ans=0,cnt;
int a[24];
int main()
{
	cin>>n>>m>>q;
	rep(i,q) cin>>pa[i]>>pb[i]>>pc[i]>>pd[i];
	rep(i,m) a[i]=0;
	rep(i,n) a[m+i]=1;
	do
	{
		cnt=0;
		if(a[0]==1) break;
		int val[24],tp=0,tt=0;
		rep(i,m+n)
		{
			if(a[i]==0) tp++;
			else val[tt]=tp,tt++;
		}
		rep(i,q)
		{
			if(val[pb[i]-1]-val[pa[i]-1]==pc[i]) cnt+=pd[i];
		}
		ans=max(cnt,ans);
	} while(next_permutation(a,a+m+n));
	re(ans)
	return 0;}

Measured memory_bytes: 3600
W,H=map(int,input().split())
arr=[[0 for i in range(H)] for j in range(W)]
ans=[[0 for i in range(H)] for j in range(W)]

for i in range(W):
    gyou=input()
    for j in range(H):
        arr[i][j]=gyou[j:j+1]


for i in range(W):
    for j in range(H):
        if arr[i][j]=="#":
            ans[i][j]="#"
        else:    
            for k in range(-1,2):
                for l in range(-1,2):
                    if i+k>=0 and l+j>=0 and i+k<W and l+j <H:
                        
                        if arr[i+k][l+j]=="#":
                            
                            ans[i][j]+=1
                            
for i in range(W):
    ans1=map(str,ans[i])
    ans2="".join(ans1)
    
    print(ans2)

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

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


int main() {
    int N;
    int M = 1000000007;
    cin >> N;
    if(N == 1){
        cout << 3 << endl;
        return 0;
    }
    string S1,S2;
    cin >> S1;
    cin >> S2;
    long long res=1;
    int f = -1;
    for(int i=0;i<S1.length()-1;i++){
        if(S1[i] == S1[i+1]){
            if(f == 1){
                res *= 3;
            }else if(f == 0){
                res *= 2;
            }else{
                res *= 6;
            }
            f = 1;
            i++;
        }else{
            if(f == 1){
                res *= 1;
            }else if(f == 0){
                res *= 2;
            }else{
                res *= 3;
            }
            f = 0;
        }
        res %= M;
    }
    if(S1[S1.length()-2] != S1[S1.length()-1] && f == 0){
        res *= 2;
    }
    res %= M;
    cout << res << endl;

    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int dp[4010][4010];

signed main(){
    string s, t;
    while(cin >> s >> t){
        rep(i, 0, 4010) rep(j, 0, 4010) dp[i][j] = 0;
        int MAX = 0;
        rep(i, 0, s.size()){
            rep(j, 0, t.size()){
                if(s[i] == t[j]){
                    if(i != 0 && j != 0) dp[i][j] = dp[i - 1][j - 1] + 1;
                    else dp[i][j] = 1;
                    MAX = max(MAX, dp[i][j]); 
                }
            }
        }
        cout << MAX << endl;
    }
}

Measured memory_bytes: 126832
import itertools
from collections import deque,Counter
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

x,y = MAP()

c = (4*x - y)
t = ((-1)*2*x+y)

if c >= 0 and t >= 0:
  if c%2 == 0 and t%2 == 0:
    print('Yes')
    exit()
  
  
print('No')

Measured memory_bytes: 9472
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int a[200001];
int mapdata[200001];
int ans = 0;
vector<string> s;
int G[401][401];
bool visited[401][401];
int H, W;
int bnum, wnum;
void dfs(int x, int y) {
	visited[y][x] = true;
	if (s[y][x] == '#') bnum++;
	if (s[y][x] == '.') wnum++;
	for (int calc = 0; calc < 4; calc++) {
		int nx = x + dx[calc], ny = y + dy[calc];
		if (visited[ny][nx]) continue;
		//画面外ならおしまい
		if (nx < 0 || nx >= W) continue;
		if (ny < 0 || ny >= H) continue;
		//おなじ色には行けない
		if (s[y][x] == s[ny][nx]) continue;
		dfs(nx, ny);
		
	}

}

signed main() {

	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		string st;
		cin >> st;
		s.push_back(st);
	}



	//グラフごとにしろと黒の数を数える
	vector<pair<int, int>> bw;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			bnum = wnum = 0;
			dfs(j, i);
			bw.push_back(make_pair(bnum, wnum));
		}
	}

	int ans = 0;
	for (auto p : bw) {
		ans += p.first*p.second;
	}
	cout <<  ans << "\n";


	return 0;
}

Measured memory_bytes: 18160
k = int(input())
a = [i for i in range(1, 10)]
while True:
    if k <= len(a):
        print(a[k-1])
        exit()
    k -= len(a)
    old = []
    old, a = a, old
    for i in range(len(old)):
        for j in range(-1, 2):
            d = old[i]%10+j
            if d >= 0 and d <= 9:
                a.append(old[i]*10+d)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a, b, h;
int main() {
    cin >> a >> b >> h;
    int ans = h / 2 * (a + b);
    cout << ans << endl;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<pair<ll,ll>>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

vector<ll> dist; 
vector<bool> seen;  

void dfs(const Graph &G, int v, ll dis) {
    seen[v] = true;
    dist[v] = dis;

    for (auto next_v : G[v]) { 
        if (seen[next_v.first]) continue;
        dfs(G, next_v.first, dis+next_v.second); // 再帰的に値を追加していく
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);

    // グラフ
    Graph G(N);

    // firstに行き先の頂点番号、secondに辺コストを入れる
    pair<ll,ll> p;
    ll a, b, c;
    REP(i, N-1){
        cin >> a >> b >> c;
        a--; b--;
        
        p.first = b;
        p.second = c;
        G[a].push_back(p);
        
        p.first = a;
        p.second = c;
        G[b].push_back(p);
    }

    ll Q, K;
    cin >> Q >> K;

    vector<ll> X(Q);
    vector<ll> Y(Q);

    REP(i, Q){
        cin >> X[i] >> Y[i];
    }

    seen.assign(N, false);
    dist.assign(N, 0);
    
    dfs(G, K-1, 0);

    REP(i, Q){
        cout << dist[X[i]-1] + dist[Y[i]-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 18176
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<functional>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
using p = pair<ll,ll>;
const ll INF = (ll)1e9;

int main(){
    int n,m;
    cin >> n >> m;
    cout << (n==m?"Yes":"No");
    return 0;
}

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

using namespace std;

// 階乗を求める
int factorial(int num) {
    if (num == 1) return 1;
    return factorial(num - 1) * num;
}

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

    vector<int> x, y;
    vector<int> permutationPattern;  // 順列のパターン
    for (int i = 0; i < N; i++) {
        permutationPattern.push_back(i);
        int tmpX, tmpY;
        cin >> tmpX >> tmpY;
        x.push_back(tmpX);
        y.push_back(tmpY);
    }

    // 考え方メモ
    // (0, 1, 2) -> ((x0, y0), (x1, y1), (x2, y2)) -> (0 -> 1, 1 -> 2)
    // (0 -> 1) : sqrt((x0 - x1)^2 + (y0 - y1)^2) + sqrt((x1 - x2)^2 + (y1 - y2)^2)
    // (1, 2, 0) -> (1 -> 2, 2 -> 0)

    double allRouteLengthSum = 0;
    do {
        double routeLengthSum = 0;
        int counter = 0;
        for (int i = 0; i < N - 1; i++) {
            int num = permutationPattern.at(i);
            int next_num = permutationPattern.at(i + 1);
            routeLengthSum += pow(pow((x.at(num) - x.at(next_num)), 2) + pow((y.at(num) - y.at(next_num)), 2), 0.5);
        }
        allRouteLengthSum += routeLengthSum;
    } while (next_permutation(permutationPattern.begin(), permutationPattern.end()));

    cout << fixed << setprecision(10) << allRouteLengthSum / factorial(N) << endl;

    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> x(n,-1);
    for(int i=0;i<n;i++)cin>>x[i];
    vector<int> rx=x;
    sort(x.begin(),x.end());
    int med=x[n/2],med2=x[n/2-1];

    for(int i=0;i<n;i++){
        if(rx[i]<med2)cout<<med<<endl;
        else if(rx[i]>med)cout<<med2<<endl;
        else if(rx[i]==med)cout<<med2<<endl;
        else cout<<med<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;
const double PI = acos(-1);

const int MAX_N = 100010;
int par[MAX_N];  // 親
int Rank[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        Rank[i] = 0;
    }
}

// 木の根を求める
int find(int x){
    if (par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y)
        return;

    if (Rank[x] < Rank[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if (Rank[x] == Rank[y])
            Rank[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

struct edge{
    int cost, v, u;
};

bool comp(const edge &l, const edge &r){
    return l.cost < r.cost;
}

int main(){
    int N; 
    int ans = 0;
    cin >> N;
    vector<edge> E;
    vector<P> X(N), Y(N);
    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        X[i] = {x, i};
        Y[i] = {y, i};
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    for(int i = 1; i < N; i++){
        P v = X[i-1];
        P u = X[i];
        edge e = {u.first-v.first, v.second, u.second};
        E.push_back(e);
    }
    for (int i = 1; i < N; i++){
        P v = Y[i - 1];
        P u = Y[i];
        edge e = {u.first - v.first, v.second, u.second};
        E.push_back(e);
    }
    sort(E.begin(), E.end(), comp);
    int s = E.size();
    init(N);
    for(int i = 0; i < s; i++){
        edge now_e = E[i];
        if(same(now_e.v, now_e.u)) continue;
        unite(now_e.v, now_e.u);
        ans += now_e.cost;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8232
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n, m = 1, o = 0;
    string s;
    cin >> n;
    n--;
    while (1) {
        m *= 26;
        o++;
        if (n < m) {
            while (o--) s += n % 26 + 'a', n /= 26;
            reverse(s.begin(), s.end());
            cout << s;
            break;
        }
        n -= m;
    }
}


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


void solve(long long N){
    long long res = N;
    for(long long i=1;i*i<=N;++i){
        if(N%i==0){
            res = min(res, i + N/i -2);
        }
    }
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int[][] differences = new int[c][c];
        int[][] patterns = new int[3][c];
        for (int i = 0; i < c ; i++) {
            for (int j = 0 ; j < c ; j++) {
                differences[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                patterns[(i+j)%3][sc.nextInt()-1]++;
            }
        }

        long min = Long.MAX_VALUE;
        for (int i = 0 ; i < c ; i++) {
            for (int j = 0 ; j < c ; j++) {
                if (i != j) {
                    for (int k = 0 ; k < c ; k++) {
                        if (i != k && j != k) {
                            long tmp = 0;
                            for (int m = 0 ; m < c ; m++) {
                                tmp += patterns[0][m] * differences[m][i];
                                tmp += patterns[1][m] * differences[m][j];
                                tmp += patterns[2][m] * differences[m][k];
                            }
                            min = Math.min(tmp, min);
                        }
                    }
                }
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 76620
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readInt()
	// vec := make([]int, 0)
	// for i := 0; i < n; i++ {
	// 	vec = append(vec, readInt())
	// }
	vec := readIntLine(n)

	// copy
	cpVec := make([]int, len(vec))
	copy(cpVec, vec)
	sort.Ints(cpVec)

	left := cpVec[n/2-1]
	right := cpVec[n/2]

	for _, v := range vec {
		if v <= left {
			fmt.Println(right)
		} else if v >= right {
			fmt.Println(left)
		} else {
			fmt.Println("ERR")
		}
	}

	// fmt.Println(n)
	// fmt.Println(vec)
	// fmt.Println(cpVec)
}

func readInt() int {
	var a int
	fmt.Scan(&a)
	return a
}

func readIntLine(n int) []int {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	ret := make([]int, 0)

	for i := 0; i < n; i++ {
		sc.Scan()
		v, e := strconv.Atoi(sc.Text())
		if e != nil {
			panic(e)
		}
		ret = append(ret, v)
	}

	return ret
}


Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  
  int ans = (a + b);
  
  if(ans % 2 == 0){
      cout << ans / 2 << endl;
  }

 else{
     cout << (ans + 1) / 2 << endl;
 } 
    
}


Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
#define mp(x,y) make_pair(x,y)
#define for(i,a,b)  for(int i=a;i<b;i++)
#define rfor(i,a,b) for(int i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define forc(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define F first
#define S second
#define rev(v) reverse(all(v))
#define sort(arr, sz) sort(all(arr, sz))
typedef long long int ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int, int>  pi;
typedef pair<ll, ll>  pll;
typedef pair<ull,ull >  pull;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<vi> vii;
const int INF = 1000000005;
#define mod 1000000007
int main()
{ int n;
cin>>n;
int arr[n][3];
ll dp[n][3]={0};
 for(i,0,n)   scanf("%d%d%d",&arr[i][0],&arr[i][1],&arr[i][2]);
dp[0][0]=arr[0][0];
dp[0][1]=arr[0][1];
dp[0][2]=arr[0][2];
for(i,1,n)
{  for(j,0,3)
    {  for(k,0,3)
        { if(k!=j)
           {  if(dp[i-1][k]+arr[i][j]>dp[i][j])
                 dp[i][j]=dp[i-1][k]+arr[i][j];
           }
        }
    }
}
int mx=0;
for(j,0,3)
{  if(dp[n-1][j]>=mx)
      mx=dp[n-1][j];
}
cout<<mx;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int H,W; cin >> H >> W;
    int dx[] = {0,0,1,1,1,-1,-1,-1};
    int dy[] = {1,-1,0,-1,1,0,-1,1};
    char c[H][W];
    rep(i,H) rep(j,W) cin >> c[i][j];
    int d[H][W];
    rep(i,H) rep(j,W) d[i][j]=0;
    rep(i,H){
        rep(j,W){
            if(c[i][j]=='#') {d[i][j] = -1; continue;}
            rep(k,8){
                int a=i+dx[k],b=j+dy[k];
                if(a>=0 && b>=0 && a<H && b<W && c[a][b] == '#') d[i][j]++;
            }
        }
    }
    rep(i,H){
        rep(j,W){
            if(d[i][j]!=-1) cout << d[i][j];
            else cout << '#';
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,sum=0,a[200009],m,k;
	string s;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=1;i<=n-1;i++)
	{
		if(i==1)
			sum+=a[n-1];
		else
		{
			sum+=a[n-(i/2)-1];
			// cout<<a[n-(i/2)-1]<<" ";
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 5228
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	a = abs(n - a);
	b = abs(n - b);
	if (a == max(a, b))
		cout << "B";
	else
		cout << "A";
	cin.get();
	cin.get();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>

using namespace std;

inline int solution(istream &cin, ostream &cout) {
  int N;
  string S;
  int Q;
  cin >> N >> S >> Q;
  vector<int> K(Q);
  for (int i = 0; i < Q; ++i) cin >> K[i];
  for (auto k : K) {
    int64_t step1 = 0, step2 = 0, step3 = 0;
    int64_t m_count = 0;
    for (int i = 0; i < N; ++i) {
      if (i - k >= 0) {
        switch (S[i - k]) {
          case 'D':
            step2 -= m_count;
            --step1;
            break;
          case 'M':
            --m_count;
            break;
        }
      }
      switch (S[i]) {
        case 'D':
          step1++;
          break;
        case 'M':
          m_count++;
          step2 += step1;
          break;
        case 'C':
          step3 += step2;
          break;
      }
    }
    cout << step3 << endl;
  }
  return 0;
}

#if defined(LOCAL_TEST_RUN)

#include "gtest/gtest.h"
#include "gmock/gmock-matchers.h"
#include "gmock/gmock-more-matchers.h"
#include <sstream>

typedef pair<string, string> TestParam;
class ATest : public ::testing::TestWithParam<TestParam> {};

TEST_P(ATest, ExampleTest) {
  string input, expected_output;
  tie(input, expected_output) = GetParam();
  if (input == "" && expected_output == "") return;

  stringstream ss(input);
  stringstream out;
  solution(ss, out);
  EXPECT_THAT(out.str(), ::testing::StartsWith(expected_output));
}

INSTANTIATE_TEST_CASE_P(Case1, ATest, ::testing::Values(
  make_pair(
      /*input=*/R"(18
DWANGOMEDIACLUSTER
1
18)",
      /*output=*/R"(1)")
));

INSTANTIATE_TEST_CASE_P(Case2, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"(18
DDDDDDMMMMMCCCCCCC
1
18)",
        /*output=*/R"(210)")
));

INSTANTIATE_TEST_CASE_P(Case3, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"(54
DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED
3
20 30 40)",
        /*output=*/R"(0
1
2
)")
));

INSTANTIATE_TEST_CASE_P(Case4, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"(30
DMCDMCDMCDMCDMCDMCDMCDMCDMCDMC
4
5 10 15 20)",
        /*output=*/R"(10
52
110
140)")
));

INSTANTIATE_TEST_CASE_P(Case5, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

INSTANTIATE_TEST_CASE_P(Case6, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

#else

int main() {
  return solution(cin, cout);
}

#endif

Measured memory_bytes: 1412
#include<bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;
	int x;
	cin>>x;
	if(x>=30)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 3576
#include <cctype>
#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;
inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main () {
	string s;
	stack<int> st;
	while (cin >> s) {
		if (isdigit(s[0])) {
			st.push(toInt(s));
		}
		else {
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			switch(s[0]) {
			case '+':
				st.push(a + b);
				break;
			case '-':
				st.push(b - a);
				break;
			case '*':
				st.push(a * b);
				break;
			}
		}
	}
	cout << st.top() << endl;
	return 0;
}

Measured memory_bytes: 1228
//#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;

int h[100005];
int dp[100005];

int main(){
    int n,k;
    cin >> n>> k;
    rep(i,n+1){
        dp[i]=INF;
    }
    dp[1]=0;
    rep2(i,n){
        cin >> h[i];
        for(int j=i-k;j<n&&j<i;j++){
            if(0<j&&j<i){
                dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
    #define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
	#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    int n,a,b;
    vector<ld> vet;
    map<ld,ll> mapa1, mapa2;
     
    int main(){
		  ll C[55][55];
		
		  C[0][0] = 1;
		  FORN(i,1,50)
		  {
			C[i][0] = C[i][i] = 1;
			FOR(j,1,i) C[i][j] = C[i-1][j-1] + C[i-1][j];
		  }
				
    
    
    	cin >> n >> a >> b;
    	vet.resize(n);
    	for(int i = 0;i<n;i++){
    		cin >> vet[i];
    		mapa1[vet[i]] ++;
    	}
    	
    	sort(vet.begin(),vet.end(),greater<ld>());
    	
    	ld soma1 = 0;
    	
    	for(int i =0;i<a;i++)	soma1 += vet[i];
    	
    	ld maxi = soma1/a;
    	ll ans = 0;
    	for(int i = a;i<=b;i++){
    		ld soma = 0;
    		mapa2.clear();
    		for(int j = 0;j<i;j++){
    			soma += vet[j];
    			mapa2[vet[j]] ++;
    		}
    		ll tot = 1;
    		if(soma1*i == soma*a){
    			for(auto it: mapa2){
    				
    				tot*=C[mapa1[it.first]][it.second];
    			}
    			ans += tot;
    		}
    	}
    	printf("%.20Lf\n",maxi);
    	cout<<ans<<endl;
     
    }

Measured memory_bytes: 256
MODE = "stdio"

line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  2
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end



r = line[0].split(" ").map(&:to_f)

printf("%.10f %.10f\n",(-1.arg)*r[0]**2,2*(-1.arg)*r[0])

Measured memory_bytes: 8740
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.receipt", "r", stdin );
	int total, book;

	while (cin >> total && total ){
		for (int i = 0; i < 9; ++i){
			cin >> book;
			total -= book;
		} // end for
		cout << total << endl;

	} // end loop
	
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    ll n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    ll ans=0;
    for(ll i=0;i<k;i++){
        ll l=0;
        bool ok=0;
        while(i+l*k<n){
            ll u=i+l*k,v=i+(l-1)*k;
            if(l==0){
                if(t[u]=='r') ans+=p;
                if(t[u]=='s') ans+=r;
                if(t[u]=='p') ans+=s;
                ok=1;
            }else{
                if(t[u]!=t[v]){
                    ok=1;
                    if(t[u]=='r') ans+=p;
                    if(t[u]=='s') ans+=r;
                    if(t[u]=='p') ans+=s;
                }else{
                    if(ok) ok=0;
                    else{
                        ok=1;
                        if(t[u]=='r') ans+=p;
                        if(t[u]=='s') ans+=r;
                        if(t[u]=='p') ans+=s;
                    }
                }
            }
            l++;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
  int n;
  map<int,int> hash;
  for(int i=0;i<=1000;i++)
    for(int j=0;j<=1000;j++)
      hash[i+j]++;
  for(;cin>>n;)
    {
      int ans=0;
      for(int i=0;i<=n/2;i++)
          {
            ans+=hash[i]*hash[n-i];
            if(i!=n-i)
              ans+=hash[i]*hash[n-i];
          }
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;

using namespace std;

int n,m,le,x,y;
char s[25][25];
vector <int> vec[1000];
queue <int> level;
bool vis[1000];

void bfs(int src)
{
    level.push(src);le=0;vis[src]=true;
    while(!level.empty())
    {
        int sz=level.size();
        while(sz--)
        {
            int node=level.front();level.pop();
            for(int k=0;k<vec[node].size();k++)
            {
                int child=vec[node][k];
                if(!vis[child])
                {
                    vis[child]=true;
                    level.push(child);
                }
            }
        }
        le++;

    }
}

int main()
{
    sc(n);sc(m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
           x=(i-1)*m+j;
           if(j<m && s[i][j+1]!='#' && s[i][j]!='#')vec[x].pb((i-1)*m+j+1);
           if(j>1 && s[i][j-1]!='#' && s[i][j]!='#')vec[x].pb((i-1)*m+j-1);
           if(i<n && s[i+1][j]!='#' && s[i][j]!='#')vec[x].pb(i*m+j);
           if(i>1 && s[i-1][j]!='#' && s[i][j]!='#')vec[x].pb((i-2)*m+j);
        }
    }
    ///for(int i=1;i<=n*m;i++){for(int j=0;j<vec[i].size();j++)cout<<vec[i][j]<<" ";cout<<endl;}
    int mx=-1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            x=(i-1)*m+j;
            if(s[i][j]!='#'){
                bfs(x);
                mx=max(le-1,mx);
                ///cout<<le-1<<" ";
                memset(vis,0,sizeof vis);
            }
        }
    }
    cout<<mx;
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
/*string s;
int main(){
    cin>>s;
    if (s[0]==s[1] && s[1]==s[2]) return puts("Yes")*0;
    if (s[1]==s[2] && s[2]==s[3]) return puts("Yes")*0;
    puts("No");
    return 0;
}*/
/*ll a[87];
int main(){
    int n;
    a[0]=2,a[1]=1;
    for (int i=2;i<=86;i++) a[i]=a[i-1]+a[i-2];
    read(n);
    cout<<a[n]<<endl;
    return 0;
}*/
string s;
int main(){
    cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    int tmp=a;
    for (int i=0;i<2;i++){
        for (int j=0;j<2;j++){
            for (int k=0;k<2;k++){
                int ans=tmp;
                if (i==0) ans+=b;
                else ans-=b;
                if (j==0) ans+=c;
                else ans-=c;
                if (k==0) ans+=d;
                else ans-=d;
                if (ans==7){
                    printf("%d%c%d%c%d%c%d=7\n",a,i==0?'+':'-',b,j==0?'+':'-',c,k==0?'+':'-',d);
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

def bellmanford(G, s):
    n = len(G)
    inf = -float('inf')
    dist = [inf] * n
    dist[s] = 0
    for i in range(n):
        for v in range(n):
            for w, c in G[v]:
                if dist[w] < dist[v] + c:
                    dist[w] = dist[v] + c
                    if i >= n - 1 and w == n - 1:
                        return -1
    return dist

def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append((b, c))
    dist = bellmanford(graph, 0)
    if dist == -1:
        print("inf")
    else:
        print(dist[N-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
const int MAX = 510000;
const int MOD = 1000000007;
long long 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;
    }
}
// 二項係数計算
long long 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(){
    int n;
    cin>>n;
    vector<long long> a;
    map<long long,long long> nums;
    int firstdup=0;
    int seconddup=0;
    rep(i,n+1){
        long long tmp;
        cin>>tmp;
        a.push_back(tmp);
        if(nums.count(tmp)){
            firstdup=nums[tmp];
            seconddup=i;
        }else{
            nums[tmp]=i;
        }
    }
    COMinit();

//    cout << firstdup<<":"<<seconddup << endl;
    int x,z;
    x=firstdup;
    z=n-seconddup;
    long long ans=0;
    rep2(i,1,n+2){
        ans=(COM(n+1,i)-COM(x+z,i-1))%MOD;
        if(ans<0){
            ans=ans+MOD;
        }
//        cout << x << ":" << y << ":" << z<<endl;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 22180
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;

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

  int ans = 0;
  for(int i=1; i<=n; i+=2) {
    int sum = 0;
    for(int j=1; j<=i; j++) {
      if(i%j == 0) sum++;
    }
    if(sum == 8) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val a = sc.nextInt()
        val b = sc.nextInt()

        println(if((a*b)%2==1)"Yes" else "No")
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 29352
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
# https://matsu7874.hatenablog.com/entry/2019/12/01/230357

n = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 1

# 先頭はr/g/b
count = [3 if i == 0 else 0 for i in range(n + 1)]

for a in A:
    ans = ans * count[a] % MOD
    if ans == 0:
        break
    count[a] -= 1
    count[a + 1] += 1

print(ans)

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

long long gcd(long long x,long long y) {
	return y?gcd(y,x%y):x;
}

int main() {
	long long n,x; cin >> n >> x;
    cout << 3*(n-gcd(n,x)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int a, p;
  cin >> a >> p;

  cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 256