akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

void call(int n) {
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }

    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
  }
  cout << "\n";
}

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



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    if(x/d>=k){
        cout << x-k*d << endl;
        return 0;
    }

    k -= x/d;
    x -= (x/d)*d;

    if(k%2 == 0) cout << x << endl;
    else cout << d-x << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3652
N, C = map(int, input().split())
MAX_N = (10 ** 5 + 5)
X = [[0] * MAX_N for _ in range(C)]

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    X[c][s] += 1
    X[c][t + 1] -= 1
# print(X)
res = [[0] * MAX_N for _ in range(C)]
for c in range(C):
    for i in range(MAX_N - 1):
        res[c][i + 1] = res[c][i] + X[c][i]
# print(ans)
ans = 0
for i in range(MAX_N - 1):
    count = 0
    for c in range(C):
        if 0 < res[c][i]:
            count += 1
    ans = max(ans, count)
print(ans)


Measured memory_bytes: 52084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> j={"AC","WA","TLE","RE"};
  vector<int> c(j.size(),0);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int x=0;x<j.size();x++)
      if(s==j.at(x))
        c.at(x)++;
  }
  for(int x=0;x<j.size();x++)
    cout<<j.at(x)<<" x "<<c.at(x)<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if (N >= 10){
        cout << R << endl;
    }
    else{
        int ans;
        ans = R + 100 * (10-N);
        cout << ans << endl;
    }

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define fr(i, l, r) for(int i = l;i < r;i++)

using namespace std;

const int N = 200001;
const ll OO = 1e13;
ll tr[3][4 * N];
ll lz[3][4 * N];

void init(int in, int l, int r){
  if(l == r){
    fr(i, 0, 3)
      tr[i][in] = 1e13 + 1ll * (i - 1) * l;
    return;
  }
  int m = (l + r) / 2;
  init(in * 2, l, m);
  init(in * 2 + 1, m + 1, r);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}

void push(int in, int l, int r){
  fr(i, 0, 3)
    tr[i][in] += lz[i][in];
  if(l != r){
    fr(i, 0, 3)
      lz[i][2 * in] += lz[i][in], lz[i][2 * in + 1] += lz[i][in];
  }
  lz[0][in] = lz[1][in] = lz[2][in] = 0;
}

void ass(int in, int l, int r, int j, ll v){
  push(in, l, r);
  if(l > j || r < j)
    return;
  if(l == r){
    fr(i, 0, 3)
      tr[i][in] = v + 1ll * l * (i - 1);
    return;
  }
  int m = (l + r) / 2;
  ass(in * 2, l, m, j, v);
  ass(in * 2 + 1, m + 1, r, j, v);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}

struct MnRes{
  ll mn[3];
  MnRes(){
    mn[0] = mn[1] = mn[2] = OO;
  }
  MnRes(ll a, ll b, ll c){
    mn[0] = a, mn[1] = b, mn[2] = c;
  }
  void upd(const MnRes& ot){
    fr(i, 0, 3)
      mn[i] = min(mn[i], ot.mn[i]);
  }
};


MnRes get(int in, int l, int r, int s, int e){
  push(in ,l, r);
  if(l > e || r < s)
    return MnRes();

  if(l >= s && r <= e){
    return MnRes(tr[0][in], tr[1][in], tr[2][in]);
  }
  int m = (l + r) / 2;
  MnRes res = get(2 * in, l, m, s, e);
  res.upd(get(2 * in + 1, m + 1, r, s, e));
  return res;
}

void add(int in, int l, int r, int s, int e, ll v){
  push(in, l, r);
  if(l > e || r < s)
    return;
  if(l >= s && r <= e){
    fr(i, 0, 3)
      lz[i][in] += v;
    push(in, l, r);
    return;
  }
  int m = (l + r) / 2;
  add(2 * in, l , m, s, e, v);
  add(2 * in + 1, m + 1, r, s, e, v);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}
int n, q, a, b;

void print(int in = 1, int l = 0, int r = n -1){
  push(in, l, r);
  printf("l= %d, r= %d, tr[0]= %lld, tr[1]= %lld, tr[2]= %lld, lz[0]= %lld, lz[1]= %lld, lz[2]= %lld\n", l, r, tr[0][in], tr[1][in], tr[2][in], lz[0][in], lz[1][in], lz[2][in]);
  if(l == r){
    return;
  }
  int m = (l + r) / 2;
  print(2 * in, l, m);
  print(2 * in + 1, m + 1, r);
}

int x[N];

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n >> q >> a >> b;
  a--, b--;
  fr(i, 0, q){
    cin >> x[i];
    x[i]--;
  }
  init(1, 0, n - 1);
//  print();
  ass(1, 0, n - 1, a, abs(b - x[0]));
//  print();
  ass(1, 0, n - 1, b, abs(a - x[0]));
  for(int i = 1;i < q;i++){
    // calc dp[i][x[i]]
    MnRes r1 = get(1, 0, n - 1, 0, x[i]);
    MnRes r2 = get(1, 0, n - 1, x[i], n - 1);
    ll val = min(x[i] + r1.mn[0], r2.mn[2] - x[i]);
    add(1, 0, n - 1, 0, n - 1, abs(x[i] - x[i -1]));
    ass(1, 0, n - 1, x[i - 1], val);
//    print();
//    cout << endl;
  }
//  print();
  cout << get(1, 0, n - 1, 0, n - 1).mn[1] << endl;
//  cout << get(1, 0, n - 1, 0, n - 1).mn[1];
}


Measured memory_bytes: 28980
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	char s; cin >> s;
	s += 1;
	cout << s << endl;
}

Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            string a = Console.ReadLine();
            if (a[2] == a[3] && a[4] == a[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

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

int main() {
  int n,ans=0;
  cin >>n;
  vector<int> h(n,0);
  rep(i,n){
    cin >>h[i];
  }
  rep(i,n){
    bool f=true;
    for(int j=0;j<i;j++){
      if(h[j]>h[i]) f=false;
    }
    if(f==true) ans++;
  }
  cout << ans <<endl;
}



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

vector<int> to[200005];
vector<int> ans(200005);
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n,q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23552
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;

void go() {
	int a,b;
	cin >> a >> b;
	cout << b*2-a << endl;
}
 
int main() {
	go();
	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s[200010];
int l,cnt[30],i;
long long ans;
int main()
{
	scanf("%s",&s);
	l=strlen(s);
	for (i=0;i<l;i++) cnt[s[i]-'a']++;
	ans=0;
	for (i=0;i<l;i++)
	{
		ans+=l-i-cnt[s[i]-'a'];
		cnt[s[i]-'a']--;
	}
	printf("%lld\n",ans+1);
}















//reverse only if a[i]!=a[j]
//otherwise,if a[i]=a[j], reverse [i+1..j-1]
//result differently!

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int factorial(int n) 
{ 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
} 
  
int main()
{
	int n,c,d;
	long double sum=0.00;
	cin>>n;
	int x[n],y[n],p[n];
	for(int i=0;i<n;i++)
	{
	cin>>x[i]>>y[i];
	p[i]=i;
    }
	long long a=factorial(n);
	long double re[a];
	for(int i=0;i<a;i++)
	{
		re[i]=0;
		for(int j=0;j<n-1;j++)
		{
			c=p[j];
			d=p[j+1];
			re[i]+=sqrt(pow((x[c]-x[d]),2)+pow((y[c]-y[d]),2));
		}
		next_permutation(p, p + n);
	}
	for(int i=0;i<a;i++)
	sum=sum+re[i];
	cout << fixed << setprecision(10)<<sum/a;
	
} 

Measured memory_bytes: 1404
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;




int main(){
    int N;
    cin>>N;
    LL C[500],S[500],F[500];
    for(int i=0;i<N-1;++i){
        cin>>C[i]>>S[i]>>F[i];
    }
    for(int i=0;i<N;++i){
        LL t=0;
    for(int j=i;j<N-1;++j){
        if(t<S[j])t=S[j];
        else if(t%F[j]==0);
        else t=t+F[j]-(t%F[j]);
        t+=C[j];
    }
    cout<<t<<endl;
    }
    

}



Measured memory_bytes: 256
import collections

n = int(input())
s = []
for i in range(n):
	s.append(input())

m = int(input())
t = []
for i in range(m):
	t.append(input())

col = collections.Counter(s)

c = col.most_common()

ansl = []
for i in range(len(c)):
	ss = s.count(c[i][0])
	tt = t.count(c[i][0])
	ansl.append(ss - tt)
	
	
if max(ansl) < 0:
	ans = 0
else:
	ans = max(ansl)

print(ans)

Measured memory_bytes: 3316
from collections import defaultdict
import sys
sys.setrecursionlimit(100000000)
def DFS(u,G,H,A,visited,P):
    visited[u]=True
    for v in G[u]:
        if not (min(u,v),max(u,v)) in P:
            if H[u-1]>H[v-1]:
                    A[u]+=1
            elif H[v-1]>H[u-1]:
                    A[v]+=1
            P.add((min(u,v),max(u,v)))
        if not visited[v]:
            DFS(v,G,H,A,visited,P)

def DFSUtil(G,H,N):
    visited=[False]*(N+1)
    A=[0]*(N+1)
    P=set()
    for u in G:
        if (not visited[u]):
            DFS(u,G,H,A,visited,P)
    return A
N,M=map(int,input().strip().split())
H=list(map(int,input().strip().split()))
G=defaultdict(list)

for i in range(M):
    u,v=map(int,input().strip().split())
    G[u].append(v)
    G[v].append(u)
A=DFSUtil(G,H,N)
cnt=0
for i in range(1,N+1):
    neighbours=len(list(set(G[i])))
    if neighbours==A[i]:
        cnt+=1
print(cnt)

Measured memory_bytes: 68276
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  let
    m = 10 ^ 18 :: Int
    go :: Int -> [Int] -> Int
    go _ (0 : _)  = 0
    go 0 (_ : xs) = go 0 xs
    go y (x : xs) | m `div` x < y = go 0 xs
                  | otherwise     = go (y * x) xs
    go 0 _ = -1
    go y _ = y
  T.getLine
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print . go 1 $ as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int N, T;

signed main()
{
    cin >> N >> T;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    int minv = A[0], maxv = -INF, cnt = 0;
    for (int i = 1; i < N; ++i) {
        int cur = A[i];
        minv = min(minv, cur);
        if (cur - minv > maxv) {
            maxv = cur - minv;
            cnt = 1;
        } else if (cur - minv == maxv) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	count := 0
	fmt.Scan(&s, &t)
	sSlice := strings.Split(s, "")
	tSlice := strings.Split(t, "")

	for index, ss := range sSlice {
		if ss != tSlice[index] {
			count++
		}
	}
	fmt.Println(count)
}

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

int main() {
	int N, a;
	cin >> N;
	int sum = 0;
	for (int i = 0;i < N;++ i) {
		cin >> a;
		sum += a - 1;
	}
	cout << sum;
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

M = a_1 * a_2 * ... * a_N - 1とする
この時、mod a_1 はa_1 - 1になるし、……となっていくことを考えると、
答えはΣa - Nと分かる
*/

Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    a,b,c = map(int, sys.stdin.readline().split())
    if a >= b+c:
        print(0)
    else:
        print(c-(a-b))

Measured memory_bytes: 5712
from collections import deque
N,M=map(int,input().split())
s=input()
H=[[] for i in range(N)]
G=[[] for i in range(2*N)]
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    H[a].append(b)
    H[b].append(a)
    if s[a]=="A":
        if s[b]=="A":
            G[a].append(N+b)
            G[b].append(N+a)
        else:
            G[a+N].append(b+N)
            G[b].append(a)
    else:
        if s[b]=="A":
            G[a].append(b)
            G[N+b].append(N+a)
        else:
            G[N+a].append(b)
            G[N+b].append(a)
K=[0 for i in range(2*N)]
for i in range(2*N):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(2*N) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
if len(res)==2*N:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 93188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAX 105
#define MAXW 10005

int N, W;
int v[MAX], w[MAX];
int  dp[MAX][MAXW];

void solve() {
    for(int i=0; i<N; i++) {
        for(int j=0; j<=W; j++) {
            if(j < w[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

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

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

    solve();
}



Measured memory_bytes: 7024
H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
field=["."*(W+2)]+S+["."*(W+2)]

flag=0

for k in range(1,H+1):
    for j in range(1,W+1):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=1

if flag==1:
    print('No')
else:     
    print('Yes')

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys
import math
from decimal import Decimal, ROUND_DOWN
from collections import deque
from itertools import combinations
import copy

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (h, w, k) = [int(e) for e in lines[0].split(' ')]
    cs = []
    for i in range(1, h+1):
        l = [ c for c in lines[i]]
        cs.append(l)


    return (h, w, k, cs)


def solve(h, w, k, cs):


    def count_black(cs):
        return sum([len([ e for e in c if e == '#']) for c in cs])

    def gen_index(n):
        result = []
        for i in range(n+1):
            combs = combinations(range(n), i)
            for cb in combs:
                result.append(cb)
        return result

    cnt = 0
    for r in gen_index(h):
        for c in gen_index(w):
            ds = copy.deepcopy(cs)
            if debug:
                log("ds=%s" % ds)

            for i in range(h):
                for j in range(w):
                    if i in r or j in c:
                        ds[i][j] = 'R'

            
            cnt_black = count_black(ds)
            if cnt_black == k:
                if debug:
                    log("r=%s" % (r,))
                    log("c=%s" % (c,))
                    log("ds=%s" % ds)
                    log("cnt_black=%d" % cnt_black)
                cnt = cnt + 1


    return cnt
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long s = sc.NextLong();

        for (int h = 1; h <= 3500; h++)
        {
            for (int n = 1; n <= 3500; n++)
            {
                long right = s * n * h;
                long left = 4 * n * h - s * n - s * h;
                if (left >= right || left <= 0)
                {
                    continue;
                }
                if (right % left == 0)
                {
                    long w = right / left;
                    Console.WriteLine(h + " " + n + " " + w);
                    return;
                }
            }
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27224
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

typedef struct rangeVal{
  int l,r,a;
} node;

int cmp(const void *a,const void *b){
  return ((node *)a)->r-((node *)b)->r;
}

typedef struct RAQandRMQ{
  int64 *add;
  int64 *max;
  int size;
  int bit;
} seg;

seg* newRAQandRMQ(const int n){
  int bit=0;
  while((1<<bit)<n) bit++;
  int size=1<<bit;
  seg *s=(seg *)calloc(1,sizeof(seg));
  s->add=(int64 *)calloc(2*size,sizeof(int64));
  s->max=(int64 *)calloc(2*size,sizeof(int64));
  s->size=size;
  s->bit=bit;
  return s;
}

int64 max(int64 a,int64 b){
  return a>b?a:b;
}

int64 getMaxAt(seg *s,int k){
  return s->max[k]+s->add[k];
}

void down(seg *s,int k){
  k+=s->size;
  for(int i=s->bit;i>0;i--){
    int x=k>>i;
    s->add[2*x]+=s->add[x];
    s->add[2*x+1]+=s->add[x];
    s->add[x]=0;
    s->max[x]=max(getMaxAt(s,2*x),getMaxAt(s,2*x+1));
  }
}

void add(seg *s,int l,int r,int64 v){
  down(s,l);
  down(s,r-1);
  l+=s->size;
  r+=s->size;
  for(int x=l,y=r;x<y;x>>=1,y>>=1){
    if(x&1) s->add[x++]+=v;
    if(y&1) s->add[--y]+=v;
  }
  l>>=1;
  r=(r-1)>>1;
  while(l>0){
    s->max[l]=max(getMaxAt(s,2*l),getMaxAt(s,2*l+1));
    s->max[r]=max(getMaxAt(s,2*r),getMaxAt(s,2*r+1));
    l>>=1;
    r>>=1;
  }
}

int64 getMax(seg *s,int l,int r){
  down(s,l);
  down(s,r-1);
  int64 local=-1000000000000000000LL;
  for(l+=s->size,r+=s->size;l<r;l>>=1,r>>=1){
    if(l&1) local=max(local,getMaxAt(s,l++));
    if(r&1) local=max(local,getMaxAt(s,--r));
  }
  return local;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  node *p=(node *)calloc(m,sizeof(node));
  int i;
  for(i=0;i<m;i++){
    int l,r,a;
    scanf("%d%d%d",&l,&r,&a);
    p[i]=(node){l,r,a};
  }
  qsort(p,m,sizeof(node),cmp);
  seg *s=newRAQandRMQ(n+1);
  int j=0;
  for(i=1;i<=n;i++){
    int64 v=getMax(s,0,i);
    add(s,i,i+1,v);
    while(j<m && p[j].r<=i){
      add(s,p[j].l,p[j].r+1,p[j].a);
      j++;
    }
  }
  printf("%lld\n",getMax(s,0,n+1));
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

const ll INF = 100000000000000ll;
// CHT
// http://d.hatena.ne.jp/sune2/20140310/1394440369
struct CHT{
  struct L {
    ll a,b;
    L(ll a,ll b):a(a),b(b){}
    bool operator<(const L &that) const {
      return a!=that.a ? a>that.a : b<that.b;
    }
  };
  struct CP {
    ll n,d;
    L p;
    CP(ll _n,ll _d,const L &p):p(p){
      n=_n; d=_d;
      if(d<0){n*=-1; d*=-1;}
    }
    bool operator<(const CP &that) const {
      if(n==INF || that.n==-INF)return 0;
      if(n==-INF || that.n==INF)return 1;
      return n*that.d < that.n*d;
    }
  };
  CP cp(const L &p1, const L &p2){
    if(p1.a==INF)return CP(-INF,1,p2);
    if(p2.a==-INF)return CP(INF,1,p2);
    return CP(p1.b-p2.b,p2.a-p1.a,p2);
  }
  set<L> S;
  set<CP> C;
  CHT(){
    S.insert(L(INF,0)); S.insert(L(-INF,0));
    C.insert(cp(L(INF,0),L(-INF,0)));
  }
  typedef set<L>::iterator It;
  It itp1(It a){return ++a;}
  It itm1(It a){return --a;}
  void C_erase(It a, It b){
    for(It it=a;it!=b;it++)C.erase(cp(*it, *itp1(it)));
  }
  bool check(const L &p1, const L &p2, const L &p3){
    if(p1.a==p2.a && p1.b<=p2.b)return 1;
    if(p1.a==INF || p3.a==-INF)return 0;
    return (p2.a-p1.a)*(p3.b-p2.b)>=(p2.b-p1.b)*(p3.a-p2.a);
  }
  void add(ll a,ll b){
    const L p(a,b);
    It pos = S.insert(p).first;
    if(check(*itm1(pos),p,*itp1(pos))){
      S.erase(pos);return;
    }
    C.erase(cp(*itm1(pos),*itp1(pos)));
    {
      It it = itm1(pos);
      while(it!=S.begin()&&check(*itm1(it),*it,p))--it;
      C_erase(it,itm1(pos));
      S.erase(++it,pos);
      pos = S.find(p);
    }
    {
      It it = itp1(pos);
      while(itp1(it)!=S.end()&&check(p,*it,*itp1(it)))++it;
      C_erase(++pos,it);
      S.erase(pos,it);
      pos = S.find(p);
    }
    C.insert(cp(*itm1(pos),*pos));
    C.insert(cp(*pos,*itp1(pos)));
  }
  ll query(ll x){
    const L &p = (--C.lower_bound(CP(x,1,L(0,0))))->p;
    if(abs(p.a)==INF)return INF;
    return p.a*x + p.b;
  }
};

int n;
ll c;
ll h[252521];
ll dp[252521];

int main(){
  scanf("%d%lld",&n,&c);
  REP(i,n)scanf("%lld",h+i);
  dp[0] = 0;
  CHT cht;
  cht.add(-2ll*h[0], dp[0] + h[0]*h[0]);
  FOR(i,1,n){
    ll v = cht.query(h[i]) + c + h[i]*h[i];
    dp[i] = v;
    cht.add(-2ll*h[i], dp[i] + h[i]*h[i]);
  }
  printf("%lld\n",dp[n-1]);
  return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <cmath>
//#define ll long long
using namespace std;
int a[1001];
int main()
{
	long long n;
	cin >> n;
	long long a = sqrt(n);
	long long tmp1, tmp2;
	for (int i = a;i >= 1;i--)
	{
		if (n % i == 0)
		{
			tmp1 = i;
			tmp2 = n / i;
			break;
		}
	}
	cout << (tmp1 + tmp2 - 2) << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,w;
    cin>>n>>w;
    vi a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    vvi dp(n+1,vi(w+1));
    REP(i,1,n){
        REP(j,1,w){
            if(j>=a[i-1]){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1]]+b[i-1]);
            }
            else {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80384
import numpy as np

N, M = [int(i) for i in input().split()]
A = []
B = []
for n in range(0, N):
  a, b = [int(i) for i in input().split()]
  A.append(a)
  B.append(b)

A = np.array(A)
B = np.array(B)
B = B[np.argsort(A)]
A = A[np.argsort(A)]

m = 0
n = 0
cost = 0
while True:
  if m >= M:
    break
  m = m + B[n]
  cost = cost + A[n] * B[n]
  n = n + 1
if m != 0:
  cost = cost - A[n - 1] * (m - M)

print(cost)


Measured memory_bytes: 20760
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int r;
	cin >> r;
	if( r < 1200 ){
		cout << "ABC" << endl;
	} else if( r < 2800 ){
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long ans_even(int N, int A[])
{
	int i;
	long long odd[100001], even[100001], ans = -((long long)1 << 60);
	for (i = 1, odd[0] = 0; i <= N / 2; i++) odd[i] = odd[i-1] + A[i*2-1];
	for (i = 1, even[0] = 0; i <= N / 2; i++) even[i] = even[i-1] + A[i*2];
	for (i = 0; i <= N / 2; i++) if (odd[i] + even[N/2] - even[i] > ans) ans = odd[i] + even[N/2] - even[i];
	return ans;
}

long long ans_odd(int N, int A[])
{
	int i;
	long long odd[100001], dp[2], ans;
	for (i = 1, odd[0] = 0; i <= (N + 1) / 2; i++) odd[i] = odd[i-1] + A[i*2-1];
	ans = (odd[N/2] > odd[(N+1)/2] - A[1])? odd[N/2]: odd[(N+1)/2] - A[1];
	dp[0] = odd[1];
	dp[1] = A[2];
	if (dp[0] + odd[(N+1)/2] - odd[2] > ans) ans = dp[0] + odd[(N+1)/2] - odd[2];
	if (dp[1] + odd[(N+1)/2] - odd[2] > ans) ans = dp[1] + odd[(N+1)/2] - odd[2];
	for (i = 2; i <= N / 2; i++) {
		dp[1] = A[i*2] + ((dp[0] > dp[1])? dp[0]: dp[1]);
		dp[0] = odd[i];
		if (dp[0] + odd[(N+1)/2] - odd[i+1] > ans) ans = dp[0] + odd[(N+1)/2] - odd[i+1];
		if (dp[1] + odd[(N+1)/2] - odd[i+1] > ans) ans = dp[1] + odd[(N+1)/2] - odd[i+1];
	}
	return ans;
}

int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	if (N % 2 == 0) printf("%lld\n", ans_even(N, A));
	else printf("%lld\n", ans_odd(N, A));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
const ll MOD=1000000007;



int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    vector<pair<int,int>> ord(N);
    rep(i,N){cin>>A.at(i);ord.at(i).first=A.at(i);ord.at(i).second=i;}
    sort(ord.begin(),ord.end());
    reverse(ord.begin(),ord.end());
    vector<vector<ll>> dp(2001,vector<ll>(2001));
    
    rep(i,N){
        ll ac=ord.at(i).first;
        int ii=ord.at(i).second;
        rep(j,i+1){//左j人右i-j人
            ll new1=dp.at(j).at(i-j)+abs(ii-j)*ac,new2=dp.at(j).at(i-j)+abs(N-1-i+j-ii)*ac;
            dp.at(j+1).at(i-j)=max(dp.at(j+1).at(i-j),new1);
            dp.at(j).at(i-j+1)=max(dp.at(j).at(i-j+1),new2);
        }
    }
    ll ans=0;
    rep(i,N+1){
        ans=max(ans,dp.at(i).at(N-i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 34676
from sys import stdin
from math import inf
n,W = map(int,stdin.readline().split())
dp = [inf]*(1000*n)
for _ in range(n):
    w,v = map(int,stdin.readline().split())
    for i in range(1000*n-v-1,-1,-1):
        if dp[i] and dp[i]+w <= W:
            dp[i+v] = min(dp[i+v],dp[i]+w)
    dp[v-1] = min(dp[v-1],w)
for i in range(len(dp)-1,-1,-1):
    if dp[i] != inf:
        print(i+1)
        break

Measured memory_bytes: 72364
def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


def LCM(a, b):
    return (a // GCD(a, b)) * b


MOD = 1000000007

n = int(input())
a = list(map(int, input().split()))

l = 1
for i in range(n):
    l = LCM(l, a[i])

ans = 0
for i in range(n):
    num = l // a[i]
    ans += num
print(ans % MOD)


Measured memory_bytes: 4084
# D - Wizard in Maze
import sys
from collections import deque
from typing import List, Tuple


class WarpableMaze:
    __slots__ = ["height", "width", "unsearched", "dist"]

    def __init__(
        self,
        height: int,
        width: int,
        grid: List[bytes],
        road: str = ".",
    ) -> None:
        self.height = height + 4
        self.width = width + 4
        self.unsearched = 1 << 30
        self.dist = self._convert_grid_to_dist(grid, road)

    def _convert_grid_to_dist(self, grid: List[bytes], road: str) -> List[int]:
        dist = [-1] * self.height * self.width
        i = self.width * 2 + 1
        for row in grid:
            for c in row.decode():
                i += 1
                if c == road:
                    dist[i] = self.unsearched
            i += 4
        return dist

    def _flatten_coordinate(self, x: int, y: int) -> int:
        return self.width * (x + 2) + y + 2

    def bfs(self, start_2d: Tuple[int, int], goal_2d: Tuple[int, int]) -> int:
        start = self._flatten_coordinate(*start_2d)
        goal = self._flatten_coordinate(*goal_2d)

        w = self.width
        walk_to_warp = {
            -w: (-2 * w - 2, -2 * w - 1, -2 * w, -2 * w + 1, -w - 1),
            w: (w + 1, 2 * w - 1, 2 * w, 2 * w + 1, 2 * w + 2),
            -1: (-w - 2, -2, w - 2, w - 1, 2 * w - 2),
            1: (-w + 1, -2 * w + 2, -w + 2, 2, w + 2),
        }

        dist = self.dist[:]
        dist[start] = 0
        queue = deque([start])
        while queue:
            x = queue.popleft()
            cur_dist = dist[x]
            if x == goal:
                break

            for walk, warp in walk_to_warp.items():
                nx = x + walk
                if dist[nx] > cur_dist:
                    dist[nx] = cur_dist
                    queue.appendleft(nx)
                    continue
                if dist[nx] >= 0:
                    continue

                for dx in warp:
                    nx = x + dx
                    if dist[nx] > cur_dist + 1:
                        dist[nx] = cur_dist + 1
                        queue.append(nx)

        return dist[goal] if dist[goal] != self.unsearched else -1


def main():
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    H, W = map(int, readline().split())
    CH, CW = map(int, readline().split())
    DH, DW = map(int, readline().split())
    (*S,) = read().split()

    maze = WarpableMaze(H, W, S)
    start, goal = (CH - 1, CW - 1), (DH - 1, DW - 1)
    print(maze.bfs(start, goal))


if __name__ == "__main__":
    main()


Measured memory_bytes: 91912
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int a[n],b[m];
    int i;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<m;i++)cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    int c=a[n-1];
    int d=b[0];
    int flag=0;
    for(i=c+1;i<=d;i++)
    {
        if(i>x&&i<=y)flag=1;
    }
    if(flag)cout<<"No War";
    else cout<<"War";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int n; cin >> n;
	cout << "ABC" + to_string(n) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,k,v[300001],mars[300001],nrop;
bool allequal(ll v[300001])
{
    for(int j=1;j<n;j++)
        if(v[j]!=n)
            return 0;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    while(nrop<k&&allequal(v)==0)
    {
        nrop++;
        for(int i=1;i<=n;i++)
            mars[i]=0;
        for(int i=1;i<=n;i++)
        {
            mars[max(1LL,i-v[i])]++;
            mars[min(n+1,i+v[i]+1)]--;
        }
        for(int i=1;i<=n;i++)
        {
            mars[i]=mars[i-1]+mars[i];
            v[i]=mars[i];
        }
    }
    for(int i=1;i<=n;i++)
        cout<<v[i]<<" ";
    return 0;
}


Measured memory_bytes: 6708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    VL a(n);
    rep(i,n) cin >> a[i];
    VL sum(n);
    sum[0] = a[0];
    for(int i = 1; i < n; i++) sum[i] = sum[i-1] + a[i];
    ll ans = 0;
    rep(i,n){
        ll s = sum[n-1] - sum[i];
        s %= mod;
        ans += s * a[i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6356
use std::cmp::*;
use std::fmt::Debug;
use std::io::{stdin, Read};
use std::str::FromStr;

//mod lib;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    return token.parse().ok().expect("failed to parse token");
}

static MOD: i64 = 1_000_000_007;

fn read_vec1<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn read_vec2<T: FromStr>(n: usize, m: usize) -> Vec<Vec<T>> {
    return (0..n).map(|_| read_vec1(m)).collect();
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn add_by_mod(a: &i64, b: &i64) -> i64 {
    return (a % MOD + b % MOD) % MOD;
}

#[derive(Clone, Copy, Debug)]
pub struct Edge {
    cost: u64,
    from: usize,
    to: usize,
}

pub fn dijkstra(graph: &Vec<Vec<Edge>>, s: &usize) -> Vec<u64> {
    use std::collections::BinaryHeap;
    let inf = 1e18 as u64;
    let mut dp = vec![inf; graph.len()];
    let mut used = vec![false; graph.len()];
    let mut que: BinaryHeap<Rev<(u64, usize)>> = BinaryHeap::new();
    que.push(Rev((0, *s)));

    while que.len() > 0 {
        let Rev((now_cost, now_v)) = que.pop().unwrap();
        if used[now_v] {
            continue;
        }
        used[now_v] = true;
        dp[now_v] = now_cost;
        for e in graph[now_v].iter() {
            if e.cost + now_cost > dp[e.to] {
                continue;
            }
            que.push(Rev((e.cost + now_cost, e.to)));
        }
    }

    return dp;
}

fn main() {
    let (v, e, r): (usize, usize, usize) = (read(), read(), read());
    let mut graph = vec![Vec::new(); v];
    for _ in 0..e {
        let (s, t, d): (usize, usize, u64) = (read(), read(), read());
        graph[s].push(Edge {
            cost: d,
            from: s,
            to: t,
        });
    }

    let dist = dijkstra(&graph, &r);
    for d in dist.iter() {
        if *d == 1e18 as u64 {
            println!("{}", "INF");
        } else {
            println!("{}", *d);
        }
    }
}



Measured memory_bytes: 30552
#include<stdio.h>
int main(){
int a,b,c,d,e,f=0;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
if(c-e>=0 && c+e<=a){
f++;
}
if(d-e>=0 && d+e<=b){
f++;
}
if(f==2){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}


Measured memory_bytes: 2148
n,m = map(int,input().split())
if n > 1:
    ns = list('1' + '0'*(n-1))
else:
    ns = list('0')

ss, cc = -1, -1
for i in range(m):
    s, c = map(int, input().split())
    if s == ss and c != cc:
        ns[0] = '-1'
        break
    ns[s-1] = str(c)
    ss, cc = s, c
    
if (len(ns) > 1 and ns[0] == '0') or ns[0] == '-1':
    ans = -1
else:
    ans = ''.join(ns)
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	int m[][] = new int[h][w];
      	String sstack; 
      
      	for(int i = 0;i < h;i++){
          for(int j = 0;j < w;j++){
            m[i][j] = 0;
          }
        }
      	
      	for(int i = 0;i < h;i++){
          sstack = sc.next();
          for(int j = 0;j < w;j++){
          	if(sstack.charAt(j) == '#'){
              	m[i][j] = -1;
            	for(int k = -1;k < 2;k++){
                	for(int l = -1;l < 2;l++){
                    	if(i+k>=0 && j+l>=0 &&(k != 0||l != 0) && i+k< h && l+j< w){
                          if(m[i+k][j+l] != -1) m[i+k][j+l]++;
                        }
                    }
                }
            }
          }
        }
      
      for(int i = 0;i < h;i++){
          for(int j = 0;j < w;j++){
            if(m[i][j] != -1) System.out.print(m[i][j]);
            else  System.out.print('#');
          }
         System.out.println();
      }        
	}
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=303,mod=1e9+7;
int n;
int cnt[4];
double dp[N][N][N],ev[N][N][N];

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int a;cin>>a;++cnt[a];
	}
	dp[cnt[1]][cnt[2]][cnt[3]]=1;
	for(int k=n;k>=0;--k)
		for(int j=n;j>=0;--j)
			for(int i=n;i>=0;--i)
				if(i||j||k){
					double pwaste=double(n-(i+j+k))/n;
					double evwaste=pwaste/(1-pwaste)+1;
					ev[i][j][k]+=evwaste*dp[i][j][k];
					if(i)dp[i-1][j][k]+=dp[i][j][k]*i/(i+j+k);
					if(j)dp[i+1][j-1][k]+=dp[i][j][k]*j/(i+j+k);
					if(k)dp[i][j+1][k-1]+=dp[i][j][k]*k/(i+j+k);
					if(i)ev[i-1][j][k]+=ev[i][j][k]*i/(i+j+k);
					if(j)ev[i+1][j-1][k]+=ev[i][j][k]*j/(i+j+k);
					if(k)ev[i][j+1][k-1]+=ev[i][j][k]*k/(i+j+k);
				}
	cout<<setprecision(10)<<fixed<<ev[0][0][0]<<endl;
}


Measured memory_bytes: 436996
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
int A[100010];
int G[100010],G2[100010];

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	G[0]=A[0];
	for(int i=1;i<N;i++){
		G[i]=gcd(G[i-1],A[i]);
	}
	G2[N-1]=A[N-1];
	for(int i=N-2;0<=i;i--){
		G2[i]=gcd(G2[i+1],A[i]);
	}
	int ans=1;
	REP(i,N){
		int t=0;
		if(i==0){
			t=G2[1];
		}
		else if(i==N-1){
			t=G[N-2];
		}
		else{
			t=gcd(G2[i+1],G[i-1]);
		}
		ans=max(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
const int N = 123456;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, even = 0, odd = 0;
    cin >> n;
    for (int i =0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    if (odd % 2 == 0) {
        puts("YES");
    } else {
        puts("NO");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	n %= 500;
	int a; cin >> a;
	if(a >= n) cout << "Yes\n";
	else cout <<  "No\n";
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
const int mod = 1000000007;

vi fen(500001);

void add(int i) {
  for (; i < fen.size(); i |= i+1) {
    fen[i] += 1;
  }
}

int sum(int i) {
  int s = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1)
    s += fen[i];
  return s;
}

vl fac(fen.size(), 1);

int main() {
  for (int i = 2; i < fac.size(); ++i) fac[i] = fac[i-1] * i % mod;
  int n;
  cin >> n;
  vi p(n), was(n+1);
  int k = 0;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    was[p[i]] = 1;
    if (p[i] == 0) ++k;
  }
  vi up(n + 1), dw(n+1);
  for (int i = n-1; i > 0; --i) {
    up[i] = up[i + 1] + 1 - was[i + 1];
  }
  for (int i = 2; i <= n; ++i) {
    dw[i] = dw[i-1] + 1 - was[i-1];
  }
  ll res = 0, su = 0;
  int e = 0;
  int inv2 = (mod+1)/2;
  for (int i = n-1; i >= 0; --i) {
    if (p[i] == 0) {
      res = (res + fac[n-i-1] * (fac[k] * e % mod * inv2 % mod + fac[k-1] * su % mod)) % mod;
//      cerr << i << ' ' << e << ' ' << su << ' ' << res << endl;
      ++e;
    } else {
      int ls = sum(p[i]);
      res = (res + fac[n-i-1] * (fac[k] * ls % mod + fac[k-1] * e % mod * dw[p[i]] % mod)) % mod;
//      cerr << i << ' ' << ls << ' ' << res << endl;
      add(p[i]);
      su = (su + up[p[i]]) % mod;
    }
  }
  cout << (res + mod + fac[k]) % mod << endl;
  return 0;
}

Measured memory_bytes: 13952