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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] i = new int[N];
        
        for(int j = 0; j < N; j++){
            i[j] = sc.nextInt();
        }
        long answer = gcd(i[0],i[1]);
        
        for(int j = 2; j < N; j++){
            answer = gcd(answer,i[j]);
        }
        
        System.out.println(answer);
    }
    
    public static long gcd(long div, long div2){
        if(div2 == 0) {
        	return div;
        }
        return gcd(div2,div%div2);
        
        
    }
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < M; i++) {
    int A;
    cin >> A;
    if (A < X)
      ans1++;
    else
      ans2++;
  }
  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

ll N;

int main() {
    cin >> N;
    string res = "";
    while(N) {
        int z = N%26;
        if (z == 0) {
            res += (char)('z');
            --N;
        }
        else {
            res += (char)('a' + (z - 1));
        }
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

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

typedef long long ll;
#define INF 1LL << 60
ll H, W;

ll f(ll a, ll b, ll c) {
    ll ma = max(a, max(b, c));
    ll mi = min(a, min(b, c));
    return ma - mi;
}
ll solA() {
    ll res = INF;
    if (2 < H) {
        ll h = H / 3;
        if (H % 3 == 0) return 0;
        res = min(res, W);
    }
    if (2 < W) {
        ll w = W / 3;
        if (W % 3 == 0) return 0;
        res = min(res, H);
    }
    return res;
}
ll solB() {
    ll res = INF;
    rep(x, 1, W) {
        ll xx = x;
        ll b = H / 2;
        res = min(res, f(xx * b, xx * (H - b), (W - xx) * H));
    }

    rep(y, 1, H) {
        ll yy = y;
        ll b = W / 2;
        res = min(res, f(yy * b, yy * (W - b), (H - yy) * W));
    }
    return res;
}
int main() {
    cin >> H >> W;
    ll ans = min(solA(), solB());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int N, M; char S[15][15],T[15][15];
vector<pair<int, int> > pick;
int chk[15];
 
void go(int r)
{
	if (r <= 1) {
		int x = -1;
		for (int i = 0; i < N; i++) if (chk[i] == 2) x = i;
		int v = 0;
		for (int i = 0; i < pick.size(); i++) {
			for (int j = 0; j < M; j++) T[v][j] = S[pick[i].first][j];
			v++;
		}
		if (x >= 0) {
			for (int j = 0; j < M; j++) T[v][j] = S[x][j];
			v++;
		}
		for (int i = (int)pick.size() - 1; i >= 0; i--) {
			for (int j = 0; j < M; j++) T[v][j] = S[pick[i].second][j];
			v++;
		}
 
		vector<string> p;
		for (int j = 0; j < M; j++) {
			string u;
			for (int i = 0; i < N; i++) u += T[i][j];
			p.push_back(u);
		}
 
		for (int i = 0; i < p.size(); i++) {
			string v = p[i];
			reverse(v.begin(), v.end());
			for (int j = i + 1; j < p.size(); j++) {
				if (v == p[j]) {
					p.erase(p.begin() + j);
					p.erase(p.begin() + i);
					i--;
					break;
				}
			}
		}
 
		if (p.size() == 1) {
			string v = p[0];
			reverse(v.begin(), v.end());
			if (p[0] != v) return;
		}
 
		if (p.size() <= 1) {
			puts("YES");
			exit(0);
		}
	}
	else {
		int s;
		for (int i = 0; i < N; i++) if (!chk[i]) { s = i; break; }
		chk[s] = 1;
		for (int i = s + 1; i < N; i++) if (!chk[i]) {
			chk[i] = 1;
			pick.push_back({ s,i });
			go(r - 2);
			pick.pop_back();
			chk[i] = 0;
		}
		chk[s] = 0;
	}
}
 
void proc()
{
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%s", S[i]);
	if (N % 2) {
		for (int i = 0; i < N; i++) {
			chk[i] = 2;
			go(N - 1);
			chk[i] = 0;
		}
	}
	else go(N);
	puts("NO");
}
 
int main()
{
	proc();
	return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll n, a, b, count, t;
  string s;
  cin >> n >> a >> b;
  
  forll(i, 1, n+1){
	s = to_string(i);
	t = 0;
	forll(j, 0, s.size()){
	  t += stoll(string{s[j]});
	}
	if (a <= t && t <= b)
	  count += i;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

void DebugGrid(int row, int column, auto table){
  cout << endl;
  rep(i,row){
    rep(j,column) cout << table[i][j] << " ";
    cout << endl;
  }
}

int main(){

  // Define
  // num_items : n, total_weight : w
  // items(value, weight)
  int n, w;
  cin >> n >> w;
  // items[pair< value, weight >]
  vector<pair<int,int>> items(n);
  rep(i,n){
    cin >> items[i].first >> items[i].second;
  }
  // dp[contain item [idx<i], min total weight] = total value .
  vector<vector<int>> dp(n+1, vector<int>(w+1, 0));

  for(int i = 1; i <= n; i++){
    for (int j = 1; j <= w; j++) {
      if (j - items[i - 1].second >= 0) {
        dp[i][j] = max(dp[i-1][j], dp[i-1][j - items[i - 1].second] + items[i - 1].first);
      } else {
        dp[i][j] = dp[i-1][j];
      }
    }
  }


  cout << dp[n][w] << endl;
  return 0;
}


Measured memory_bytes: 6772
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 100000007
typedef long long ll;
using namespace std;
ll G(ll x,ll k){
    if(x%k==0)return x/k;
    ll s=x/k+1,m=x-x%k;
    ll d=((x-m)/s+!!((x-m)%s));
    ll p=x-s*d;
    return G(p,k);
}
int main(){
    int n;cin>>n;
    ll ans=0;
    lol(i,n){
	ll a,k;cin>>a>>k;
	ans^=G(a,k);
    }
    cout<<(ans?"Takahashi":"Aoki")<<endl;
    return 0;
}


Measured memory_bytes: 256
N = input().split()
X = int(N[0])
Y = int(N[1])

flag = False

for i in range(X):
    if flag:
        break

    if (X-i)*2 + i*4 == Y:
        flag = True
    
    if (X-i)*4 + i*2 == Y:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>num(N + 2,0);
  
  for(int i=1;i<=N;i++){
    cin >> num[i];
  }
  
  int sum = 0;
  
  for(int i=1;i<=N + 1;i++){
    sum += abs(num[i] - num[i - 1]);
  }
  
  for(int i=1;i<=N;i++){
    cout << sum + abs(num[i + 1] - num[i - 1]) - abs(num[i] - num[i - 1]) - abs(num[i] - num[i + 1]) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1664
import numpy as np
N=int(input())
A=[np.array(list(map(int,input().split()))) for i in range(N)]
ans=sum([sum(A[i]) for i in range(N)])
ans//=2
for i in range(N):
    A[i][i]=10**10
def main(ans):
    for i in range(N):
        for j in range(i+1,N):
            Min=min(A[i]+A[j])
            if Min<A[i][j]:
                return -1
            if Min==A[i][j]:
                ans-=A[i][j]
    return ans
print(main(ans))

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define MOD 1000000007
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n; cin>>n;

	ll h[n+1];
	f(i,1,n) cin>>h[i];

	for(int j=n-1;j>=1;j--){
		if(h[j]>h[j+1]) h[j]--;
	}

	f(i,1,n-1){
		if(h[i+1]<h[i]){
			cout<<"No";
			exit(0);
		}
	}

	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
use proconio::{input,fastout};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input!{
        h: usize,
        w: usize,
        k: usize,

        c: [Chars; h],
    }

    let mut ans = 0;

    for i in 0..(1<<h) {
        for j in 0..(1 << w){
            let mut cnt = 0;

            for k in 0..h{
                for l in 0..w{
                    if ((i >> k) & 1) == 1 || ((j >> l) & 1) == 1 || c[k][l] == '.'{
                        continue;
                    }
                    cnt += 1;
                }
            }
            if cnt == k {
                ans += 1;
            }

        }
    }

    println!("{}",ans);
}


Measured memory_bytes: 2172
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    String s = sc.next();
    int k = Integer.parseInt(sc.next());
    
    String target = s.substring(k-1,k);
    String check = "";
    String ans = "";
    
    for (int i=0; i<n; i++) {
      check = s.substring(i,i+1);
      if (check.equals(target)) {
        ans += check;
      } else {
        ans += "*";
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
<?php
$s = trim(fgets(STDIN));

$first = (int)($s[0].$s[1]);
$second = (int)($s[2].$s[3]);

$first_m_able = false;
if ($first > 0 && $first < 13) {
	$first_m_able = true;
}
$second_m_able = false;
if ($second > 0 && $second < 13) {
	$second_m_able = true;
}

$result = 'NA';
if ($first_m_able && $second_m_able) {
	$result = 'AMBIGUOUS';
}elseif ($first_m_able && !$second_m_able) {
	$result = 'MMYY';
}elseif (!$first_m_able && $second_m_able) {
	$result = 'YYMM';
}
echo $result;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define dbug printf("I am here\n");
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
    static const long double pi = 3.141592653589793;
    using namespace std;

    int main() {

    ll int a,b,c,s,n,k;
    char ch;
    cin >> ch;
    if(ch>='A' && ch<='Z')cout<<"A"<<endl;
    else cout<<"a"<<endl;

        return 0;
    }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


int main(){
    int n;
    cin >> n;
    vector<vector<int>> hxy(n,vector<int>(3,0));

    for(int i = 0; i < n; i++){
        int tx, ty, th;
        cin >> tx >> ty >> th;
        hxy[i][0] = th;
        hxy[i][1] = tx;
        hxy[i][2] = ty;

    }
    sort(hxy.begin(),hxy.end());
    reverse(hxy.begin(),hxy.end());

    int m = 101;
    bool isOK = false;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            int dist = abs(hxy[0][1]-i) + abs(hxy[0][2]-j);
            int height = hxy[0][0] + dist;
            isOK = true;
            for(int k = 1; k < hxy.size(); k++){
                int t_dist = abs(hxy[k][1]-i) + abs(hxy[k][2]-j);
                if(max(height - t_dist, 0)  != hxy[k][0]){
                    isOK = false;
                }
            }

            if(isOK){
                cout << i << " " << j << " " << height << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << ((n / x) + (n % x != 0)) * t << endl;
}

Measured memory_bytes: 3592
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)




function check(table, K, H, W)
    ans = 0
    for i in 1:H
        for j in 1:W
            if table[i][j] == '#'
                ans += 1
            end
        end
    end
    return (ans == K)
end




function main()
H, W, K = parseMap(split(readline()))

table = []

for idx1 in 1:H
    C = collect(chomp(readline()))
    push!(table, C)
end
old_table = deepcopy(table)

ans = 0
for i in 0:2^H - 1
    for j in 0:2^W - 1 
        y_p = digits(i, base=2, pad=H)
        t_p = digits(j, base=2, pad=W)
        for k in 1:H
            y = y_p[k]
            if y == 1
                for kk in 1:W
                    table[k][kk] = 'r'
                end
            end
        end

        for k in 1:W
            t = t_p[k]
            if t == 1
                for kk in 1:H
                    table[kk][k] = 'r'
                end
            end
        end
        if check(table, K, H, W)
            ans += 1
        end
        table = deepcopy(old_table)
    end
end


println(ans)


end


main()

Measured memory_bytes: 192312
N = int(input())
A = list(map(int, input().split()))
B = [[a, i] for i, a in enumerate(A, 1)]
B.sort(reverse=True)

dp = [[0] * (N+1) for i in range(N+1)]
s, i = B[0]
dp[1][0] = s*(i - 1)
dp[0][1] = s*(N - i)
for n in range(2, N+1):
  a, i = B[n-1]
  for l in range(n+1):
    r = n - l
    if l == 0:
      dp[l][r] = dp[l][r-1] + abs(N-r+1 - i)*a
    elif r == 0:
      dp[l][r] = dp[l-1][r] + abs(l - i)*a
    else:
      dp[l][r] = max(dp[l-1][r]+abs(l-i)*a, dp[l][r-1]+abs(N-r+1-i)*a)

ans = 0
for l in range(N+1):
  r = N - l
  ans = max(ans, dp[l][r])

print(ans)

Measured memory_bytes: 136060
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >>n ;
    int temp=0;
    while(n>=4)
    {
        if(n%7==0||n%4==0)
        {
            temp=1;
            break;
        }
        n=n-4;
    }
    if(temp==1)
        cout<< "Yes" <<endl;
    else
        cout<< "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    int x, y;
    cin >> x >> y;
    cout << ((y >= 2*x and y <= 4*x and !(y&1)) ? "Yes" : "No");
}


Measured memory_bytes: 3128
R,G,B,N = map(int,input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N-r*R-g*G)//B
        # print(r,g,b,r*R+g*G+b*B )
        if b>=0 and r*R+g*G+b*B == N:
            ans +=1
print(ans)

Measured memory_bytes: 40940
#ABC141.C
N,K,Q = map(int,input().split())
A = [int(input())for i in range(Q)]
La = [(K-Q) for i in range(N)]
for m in range(Q):
    La[A[m]-1]+=1
for j in range(N):
    if La[j] <= 0:
        print('No')
    elif La[j] >0:
        print('Yes')

Measured memory_bytes: 11780
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (int)
K = int(input().rstrip())

# 1 ✕ 1 (str)
S = input().rstrip()

if len(S) > K:
    print(S[:K] + "...")
else:
    print(S)


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    string s;
    cin>>s;
    ll n = s.length();
    ll ans=0;
    ll white=0;
    for (int i = n-1; i>=0; i--)
    {
        if(s[i]=='W'){
            white++;
        }
        else{
            ans+=white;
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3756
a=list(map(int,input().split()))
cnt=0
for i in range(3):
  if a[i]%2==1:
    cnt+=1
if cnt==0 or cnt==3:
  print((3*max(a)-sum(a))//2)
elif cnt==1 and max(a)%2==1 or cnt==2 and max(a)%2==0:
  print((max(a)-a[0])//2+(max(a)-a[1])//2+(max(a)-a[2])//2+1)
else:  
  print((max(a)+1-a[0])//2+(max(a)+1-a[1])//2+(max(a)+1-a[2])//2+1)


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int rl = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] == 'R' && s[i + 1] == 'L')
            ++rl;
    }
    if (rl > k)
        cout << n - (rl - k) * 2 - (s.front() == 'L') - (s.back() == 'R') << endl;
    else if (rl == k)
        cout << n - (s.front() == 'L') - (s.back() == 'R') << endl;
    else
        cout << n - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    ll A, B, C;

    cin >> A >> B >> C;

    ll ans = C - (A - B);
    if(ans < 0){
        cout << 0 << endl;
        return 0;
    }

    cout << ans << endl;
    

}

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

using ll = long long;

const int N = 100005, sz = 131072;
const ll INF = ll(1e18);

struct Seg{
    ll d[2 * sz];
    void ini(){ fill(d, d + 2 * sz, INF); }
    void upd(int x, ll v){
        x += sz;
        d[x] = min(d[x], v);
        for(x >>= 1; x; x >>= 1) d[x] = min(d[2 * x], d[2 * x + 1]);
    }
    ll get(int s, int e){
        ll r = INF;
        for(s += sz, e += sz; s <= e; s >>= 1, e >>= 1){
            if( s & 1) r = min(r, d[s++]);
            if(~e & 1) r = min(r, d[e--]);
        }
        return r;
    }
} S, T;

int n, l, t, x[N];

int main(){
    scanf("%d%d%d", &n, &l, &t);
    for(int i = 1; i <= n; i++) scanf("%d", x + i);
    S.ini();
    T.ini();
    S.upd(0, 0);
    T.upd(0, -2 * x[1]);
    for(int i = 1, j = 0; i <= n; i++){
        while(j < i - 1 && 2 * (x[i] - x[j + 1]) > t) j++;
        ll v = min(S.get(j, i - 1) + t + x[i], T.get(0, j - 1) + 3LL * x[i]);
        S.upd(i, v - x[i]);
        T.upd(i, v - x[i] - 2 * x[i + 1]);
    }
    printf("%lld\n", S.get(n, n) + l);
}

Measured memory_bytes: 4736
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, a, b;
        cin >> n >> a >> b;
        if (n == 1 && a == b) cout << 1 << endl;
        else if (b >= a && n > 1) cout << b * (n - 1) + a - (a * (n - 1) + b) + 1 << endl;
        else cout << 0 << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N;
	cin >> N;
	double otoshidama = 0;
	for (int i = 0; i < N; i++) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") otoshidama += x;
		if (u == "BTC") otoshidama += x * 380000;
	}
	cout << fixed << setprecision(5) << otoshidama << endl;
	return 0;
}

Measured memory_bytes: 3744
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int rad(int a);
int main(void)
{
    int n;
    scanf("%d", &n);
    int p[n], q[n];
    int i, ans;
    for (i = 0; i < n; i++) {
        scanf("%d", &p[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &q[i]);
    }
    int pn = 0, qn = 0;
    for (i = 0; i < n; i++) {
        pn += (p[i] - 1) * rad(n - i  - 1);
        qn += (q[i] - 1) * rad(n - i - 1);

        for (int j = i + 1; j < n; j++) {
            if (p[j] > p[i]) {
                --p[j];
            }
            if (q[j] > q[i]) {
                --q[j];
            }
        }
    }


    printf("%d\n", abs(pn - qn));
    return 0;
}

int rad(int a)
{
    if (a == 1 || a == 0) {
        return 1;
    } else {
        return a * rad(a - 1);
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  long long k;
  cin >> s >> k;
  int n = min((long long)s.size(), k);
  for (int i = 0; i < n; i++) {
    if (s[i] != '1') {
      cout << s[i] << '\n';
      return 0;
    }
  }
  cout << 1 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int s, t, u, v;

  while(cin>>s&&s){
    cin >> t >> u >> v;

    s += (t+u+v);

    t = s%60;
    u = (s-t)/60;

    cout << u << endl;
    cout << t << endl;
  }

  return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,M;
    cin >> N >> M;

    vector<i64> A(N+M-1),B(N+M-1);
    vector<vector<i64>> to(N),from(N);
    vector<i64> in(N);
    rep(i,0,N+M-1){
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
        to[A[i]].emplace_back(B[i]);
        from[B[i]].emplace_back(A[i]);
        ++in[B[i]];
    }

    i64 root;
    rep(i,0,N){
        if(in[i]==0){
            root=i;
            break;
        }
    }

    vector<i64> depth(N,-inf64),parent(N);
    function<void(i64,i64,i64)> rec=[&](i64 u,i64 p,i64 d){
        if(d<=depth[u]) return;
        for(auto v:from[u]){
            if(depth[v]==-inf64) return;
        }
        depth[u]=d;
        parent[u]=p;
        for(auto v:to[u]){
            rec(v,u,d+1);
        }
    };

    rec(root,-1,0);

    rep(i,0,N){
        cout << parent[i]+1 << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

from collections import deque


n, m = map(int, input().split())

GRAPH = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    GRAPH[a].append(b); GRAPH[b].append(a)

ANS = [0] * (n + 1)
SEARCHED = [False] * (n + 1)

SEARCHED[1] = True
QUEUE = deque([1])
while QUEUE:
    v = QUEUE.popleft()
    for w in GRAPH[v]:
        if SEARCHED[w]:
            continue
        ANS[w] = v
        SEARCHED[w] = True
        QUEUE.append(w)

print("Yes")
for ans in ANS[2:]:
    print(ans)


Measured memory_bytes: 35832
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	m := map[byte]int{}

	for i := 0; i < len(s); i++ {
		if _, ok := m[s[i]]; ok {
			m[s[i]]++
		} else {
			m[s[i]] = 1
		}
	}

	flag := true

	for _, i := range m {
		if i != 2 {
			flag = false
		}
	}

	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=*pos+val;}
//const long double EPS=1E-8;
////////////////////////////////////////



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ans=a[n-1]-a[0];
    ll p=0,q=n-1;
    while(p+2<q){
        ans+=a[q-1]-a[p];
        ans+=a[q]-a[p+1];
        p++;q--;
    }
    if(p+2==q){
        ans+=max(a[q]-a[q-1],a[p+1]-a[p]);
    }
    cout<<ans<<endl;
    
    return 0;
}
//ios::sync_with_stdio(false);cin.tie(0);


Measured memory_bytes: 1024
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    RMQ　の実装
    '''

    def __init__(self, n, inf=float('inf')):
        '''
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        for k in reversed(range(self.n-1)):
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のminを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = gcd(ret, self.data[R-1])
            if L & 1:
                ret = gcd(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
L = list(map(int, input().split()))
T = SegmentTree(N, 0)
for i, l in enumerate(L):
    T.set(i, l)
T.build()

ans = 0
for i in range(N):
    l = i
    r = i+1
    ans = max(ans, gcd(T.query(0, l), T.query(r, N)))
print(ans)


Measured memory_bytes: 61164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;}
ll x1,y1,gcd=gcdEx(b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)      {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}

typedef pair<ll, ll>      pii;
typedef vector<ll>         vi;
typedef vector<pii>         vii;
typedef set<ll>            si;
typedef map<string, ll>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(ll i=b;i<n;i++)
#define loopv(b,n,a)         for(ll i=b;i<n;i+=a)
#define loopr(b,n)           for(ll i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(int)(MOD+((a%MOD)-(b%MOD))%MOD):(int)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)

#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)               cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)            cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)      cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<end
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;}
y=y>>1; x=(x*x)%MOD;} return r;}
ll min(ll a,ll b ) {     if(a<b)     return a;     else    return b;  }
ll max(ll a,ll b ) {     if(a>b)     return a;     else    return b;  }

int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
 //  freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE
ll t;
 t=1;
// cin>>t;

 while(t--)
{
ll ans=0,n,a,b;
cin>>n>>a>>b;
if(a==b)
{

    cout<<0;
    continue;
}
if(a<b)
{

    ll temp=a;
    a=b;
    b=temp;
}
ll x=a-b;

if(x==1)
{
  if(a==n||b==1)
        ans=1;
        else
        ans=min(n-b,a-1);

}
else
{
    if(x&1)
    {
ans=min(b-1,n-a)+1;
ans+=(x/2);
    }
    else
        ans=x/2;

}
cout<<ans;
}
cout<<"\n";
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[16];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll ans = ll(1e18);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<(1<<n);i++)
	{
		if(__builtin_popcount(i)==k)
		{
			ll las = -ll(1e18);
			ll cnt = 0;
			for(int j = 0; j < n; j++)
			{
				if(i&(1<<j))
				{
					if(a[j]>las)
					{
						las=a[j];
						continue;
					}
					cnt+=las+1-a[j];
					las++;
				}
				las=max(las,a[j]);
			}
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-1 15:54:30
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int N;
  cin >> N;
  vector<int> V;
  for (auto i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    V.push_back(a);
  }
  int maxi = *max_element(V.begin(), V.end());
  int mini = *min_element(V.begin(), V.end());
  cout << maxi - mini << endl;
}

Measured memory_bytes: 256
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int MAX = 1000000;
    vector<int> cnt(MAX+1, 0);
    int g;
    rep(i, N){
        int A; cin >> A;
        if(i == 0) g = A;
        g = gcd(g, A);
        cnt[A]++;
    }
    if(g > 1) {cout << "not coprime" << endl; return 0;}
    bool flag = true;
    rep2(i, 2, MAX+1){
        int res = 0;
        for(int j = 1; i*j <= MAX; j++){
            res += cnt[i*j];
        }
        if(res >= 2) flag = false;
    }
    cout << (flag? "pairwise " : "setwise ") << "coprime" << endl;
}

Measured memory_bytes: 7216
(* O(k^2) *)
Scanf.scanf "%d %d" @@ fun k s ->
  let ans = ref 0 in
  for x = 0 to k do
    for y = 0 to k do
      let z = s - x - y in
      if 0 <= z && z <= k then incr ans
    done
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=LLONG_MAX,mod=1000000007,BS,k;
ll par[200005],rn[200005];
ll fin(ll num){
    if(par[num]!=num)
    par[num]=fin(par[num]);
    return par[num];
}
ll uni(ll a,ll b){
    ll par1,par2;
    par1=fin(a);
    par2=fin(b);
    if(par1==par2)return 0;
    if(rn[par1]<rn[par2]){
        par[par1]=par2;
    }
    else if(rn[par1]>rn[par2]){
        par[par2]=par1;
    }
    else{
        par[par2]=par1;
        rn[par1]++;
    }
    return 0;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n,m,a,b;cin>>n>>m;
        ll freq[n]={0};
        for(ll i=0;i<n;i++)rn[i]=0,par[i]=i;
        for(ll i=0;i<m;i++){
            cin>>a>>b;a--;b--;
            uni(a,b);
        }
        for(ll i=0;i<n;i++)
        freq[fin(i)]++;
        cout<<*max_element(freq,freq+n);

}


Measured memory_bytes: 8336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n;
    vector<ll> up, mid, bottom;
    rep(i, n){
        cin >> a;
        up.push_back(a);
    }
    rep(i, n){
        cin >> a;
        mid.push_back(a);
    }
    rep(i, n){
        cin >> a;
        bottom.push_back(a);
    }
    sort(all(up));
    sort(all(bottom));
    rep(i, n){
        ans += (lower_bound(all(up), mid[i]) - up.begin()) * (bottom.end() - upper_bound(all(bottom), mid[i]));
    }
    cout << ans << endl;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1 << 20;
const ll MOD = 1000000007;

struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

int d[110];

int main()
{
    int N, M;
    cin >> N >> M;
    Graph G(N);
    int dist[100][100], a[1010], b[1010], c[1010];
    rep(i, M)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }

    rep(i, N)
    {
        rep(j, N)
        {
            if (i == j)
                dist[i][j] = 0;
            else
                dist[i][j] = INF;
        }
    }
    rep(i, M)
    {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    rep(k, N)
    {
        rep(i, N)
        {
            rep(j, N)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = M;
    rep(i, M)
    {
        int flg = false;
        rep(j, N)
        {
            if (dist[j][a[i]] + c[i] == dist[j][b[i]])
                flg = true;
        }
        if (flg)
        {
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int A[N+1];
    int one;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        if(A[i]==1){
            one=i;
        }
    }
    int ans=(N-1)/(K-1);
    if((N-1)%(K-1)!=0){
        ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int n,y,m,d,count;
  scanf("%d",&n);
  while(n--){
    count=0;
    scanf("%d%d%d",&y,&m,&d);
    count=(y-1)*39*5;
    count+=((y-1)/3)*1*5;
    if(y%3==0){
      count+=(m-1)*20;
    }
    else{
      count+=(m-1)*20-(m-1)/2*1;
    }
    count+=d-1;
    printf("%d\n",196470-count);
  }
  return 0;
}

Measured memory_bytes: 596
N, M = map(int, input().split())
c = [1] * N
r = [True] + [False] * (N-1)
for i in range(M):
    x, y = map(int, input().split())
    if r[x-1] == True:
        r[y-1] = True
    if c[x-1] == 1:
        r[x-1] = False
    c[x-1] -= 1
    c[y-1] += 1
print(sum(r))


Measured memory_bytes: 76396
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

int main()
{
    fastio;
    lli n,k;
    cin >> n >> k;
    n=n%k;
    cout << min(n,k-n) << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<int> d(n);

	rep(i, 0, n) cin >> d[i];

	int ans = 0;

	rep(i, 0, n - 1) {
		rep(j, i + 1, n) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String s = stdR.readLine();
        int n = 0;
        for(int i = 0 ; i < s.length(); i++) {
            if(s.charAt(i) == '1')n++;
        }
        System.out.println(n);
    }
}

Measured memory_bytes: 22612
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N=sys.stdin.readline().strip()
N=N[::-1]
#Lの先頭の0を入れるのは、何も数を選択しない状態はmod2019がゼロになるの意味
#19行目でx=0の際に、ans+=C[x]で1足されることになるので都合が良い
L=[0] 
val=0
for i,x in enumerate(N):
    val+=pow(10,i,2019)*int(x)
    L.append(val%2019)

C=defaultdict(lambda: 0)    #mod2019の出現個数を記録
ans=0
for x in L:
    ans+=C[x]   #自分とmod2019の結果が同じ値となる個数をansに足す
    C[x]+=1     #自分のmod2019の値を出現回数に+1カウント
print ans



Measured memory_bytes: 85708
import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        input >>= return . solve >>= output
        main

input :: IO ([Int],[Int])
input = do
    as <- (map read . words) `fmap` getLine
    bs <- (map read . words) `fmap` getLine
    return (as,bs)

output :: (Int,Int) -> IO ()
output (h,b) = putStrLn $ unwords $ [show h, show b]

solve :: ([Int],[Int]) -> (Int,Int)
solve (as,bs) = (hit, blow)
    where
    hit  = length $ filter id $ [as!!i == bs!!j |i<-[0..3], j<-[0..3], i==j]
    blow = length $ filter id $ [as!!i == bs!!j |i<-[0..3], j<-[0..3], i/=j]

Measured memory_bytes: 4136
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

int n, m, q;
vector<int> a(100), b(100), c(100), d(100);
ll ans = 0;

void dfs(vector<int> _v, int _dep, int _init){
    if(_dep == n){
        int res = 0;
        rep(i, q){
            if(_v[b[i]] - _v[a[i]] == c[i]) res += d[i];
        }
        chmax(ans, res);
    }
    else{
        for(int i = _init; i <= m; ++i){
            vector<int> _nv = _v; _nv.pb(i);
            dfs(_nv, _dep + 1, i);
        }
    }
}

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    cin >> n >> m >> q;
    rep(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    vector<int> v;

    dfs(v, 0, 1);

    cout << ans << endl;

return 0;
}

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

int main(){
  int n,T; cin >>n >>T;
  vector<int> t(n);
  rep(i,n) cin >>t[i];
  ll ans = 0;
  rep(i,n){
    if(i==n-1) {
      ans+=T;
      break;
    }
    else if(t[i+1]-t[i]<=T) {
      ans+=t[i+1]-t[i];
    }
    else ans+=T;
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 4048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;


int main(void){
    map<string,ll> pitsu;
    ll n;
    cin>>n;
    rep(i,n){
        string suz;
        cin>>suz;
        pitsu[suz]++;
    }
    ll yotsu = 0;
    for(pair<string,ll> ken:pitsu){
        yotsu++;
    }
    cout<<yotsu<<endl;
}

Measured memory_bytes: 19228