akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define FI first
#define SE second
using namespace std;
typedef long long LL;
int G[305][305];
int D[20][20],siro[20],cost[20];
int dp[17][1<<16],bit[1<<16];
bool done[17][1<<16];
struct node
{
    int u,st,dis;
    inline node(int _u=0,int _st=0,int _dis=0)
    {
        u=_u; st=_st; dis=_dis;
    }
    inline bool operator <(const node &a)const
    {
        return dis>a.dis;
    }
};
priority_queue <node> Q;

inline void Dijkstra(int n,int t)
{
    memset(dp,0x3f,sizeof(dp));
    memset(done,0,sizeof(done));
    dp[0][0]=0;
    Q.push(node(0,0,0));
    node u;
    while(!Q.empty())
    {
        u=Q.top(); Q.pop();
        if(done[u.u][u.st]) continue;
        done[u.u][u.st]=1;
        for(int i=1;i<=n;++i) if(D[u.u][i]!=INF)
        {
            if(u.st&(1<<(i-1))) continue;
            int v=u.dis+D[u.u][i]+cost[i];
            if(v+D[0][i]>t) continue;
            int nst=u.st|(1<<(i-1));
            if(dp[i][nst]>v)
            {
                dp[i][nst]=v;
                Q.push(node(i,nst,v));
            }
        }
    }
    int res=0;
    for(int i=1;i<=n;++i)
        for(int j=(1<<n)-1;j>=0;--j)
            if(dp[i][j]+D[0][i]<=t) res=max(res,bit[j]);
    printf("%d\n",res);
}

inline int bit_count(int st)
{
    int res=0;
    for(;st;st^=st&-st) ++res;
    return res;
}

int main()
{
    for(int i=(1<<16)-1;i>=0;--i) bit[i]=bit_count(i);
    int n,m,l,s,t;
    while(scanf("%d%d%d%d%d",&n,&m,&l,&s,&t)&&n)
    {
        for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) G[i][j]=INF;
        while(m--)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            G[u][v]=G[v][u]=w;
        }
        for(int k=1;k<=n;++k)
            for(int i=1;i<=n;++i)
                for(int j=1;j<=n;++j)
                {
                    if(k==i||k==j||i==j) continue;
                    G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
                }
        for(int i=1;i<=l;++i) scanf("%d%d",siro+i,cost+i);
        siro[0]=s;
        memset(D,0x3f,sizeof(D));
        for(int i=0;i<=l;++i)
            for(int j=i+1;j<=l;++j)
                D[i][j]=D[j][i]=G[siro[i]][siro[j]];
        Dijkstra(l,t);
    }
    return 0;
}

Measured memory_bytes: 14624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{




    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] m = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int first = m[0];
        for (int i = 1; i < m.Length; i++)
        {
            first = gcd(first, m[i]);
            if (first == 1) break;
        }
        Console.WriteLine(first);
    }

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



Measured memory_bytes: 19680
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
    public static void main(String ars[]){
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        System.out.println(a*b);
    }
}


Measured memory_bytes: 27012
"""
全探索
1からmin(a,b)の中でaとbを割り切るものの数をカウントする
"""
a, b, k = map(int, input().split())
counter = 0
for i in list(range(1,min(a,b)+1))[::-1] :
    if a%i == 0 and b%i == 0 :
        counter += 1
    if counter == k :
        print(i)
        break


Measured memory_bytes: 9064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
int upcmpii(const void *a, const void *b){
    return (*(int*)a == *(int*)b ? 0 : (*(int*)a > *(int*)b ? 1 : -1));
}
void sort_ui(int *a, int n){ qsort(a, n, sizeof(int), upcmpii);}

int main(){
    //input
    int n;
    scanf("%d", &n);
    int A[101010], B[101010], dif[101010];
    rep(i, n) scanf("%d", A+i);
    rep(i, n) scanf("%d", B+i);
    rep(i, n) dif[i] = A[i] - B[i];

    //solve
    sort_ui(dif, n);
    ll nsum = 0;
    int idx = n-1, ncnt = 0;
    rep(i, n){
        if(dif[i] < 0){
            ncnt++;
            nsum += dif[i];
        }else break;
    }
    while(nsum < 0 && idx >= 0){
        if(dif[idx] > 0){
            nsum += dif[idx];
            idx--;
        }else break;
    }
    
    //output
    if(nsum >= 0) printf("%d\n", n-1-idx+ncnt);
    else printf("-1\n");
}

Measured memory_bytes: 3096
import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
#input = sys.stdin.readline

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(lambda: collections.defaultdict(int))
G2 = collections.defaultdict(lambda: collections.defaultdict(int))

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b


def dijkstra(V, G, start):
    INF = float('inf')
    D = [INF for _ in range(V)]
    D[start] = 0
    H = [(0, start)]
    while H:
        du, u = heappop(H)
        if D[u] < du:
            continue
        for v, d in G[u].items():
            if D[v] > du + d:
                D[v] = du + d
                heappush(H, (D[v], v))
    return D


D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [10**15 - sum(_) for _ in zip(D1, D2)]
for i in range(N - 1, 0, -1):
    D[i - 1] = max(D[i - 1], D[i])
print(*D, sep='\n')


Measured memory_bytes: 127224
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 1010;

ll a[Maxn], b[Maxn], c[Maxn];

int x, y, z, k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> x >> y >> z >> k;
    for (int i = 0; i < x; ++i) cin >> a[i];
    for (int i = 0; i < y; ++i) cin >> b[i];
    for (int i = 0; i < z; ++i) cin >> c[i];
    vector<ll> ab;
    for (int i = 0; i < x; ++i) {
        for (int j = 0; j < y; ++j) {
            ab.emplace_back(a[i] + b[j]);
        }
    }

    sort(c, c + z, greater<ll>());
    sort(ab.begin(), ab.end(), greater<ll>());

    vector<ll> abc;
    for (int i = 0; i < min((int)ab.size(), k);
    ++i){
        for (int j = 0; j < min(k, z); ++j) {
            abc.emplace_back(ab[i] + c[j]);
        }
    }
    sort(abc.begin(), abc.end(), greater<ll>());
    for (int i = 0; i < k; ++i) {
        cout << abc[i] << "\n";
    }
}


Measured memory_bytes: 43236
#include<stdio.h>
int A[50];

int fibonatti(int);

int main(){
  int i,n;
  for(i=0;i<50;i++){
    A[i] = -1;
  }
  scanf("%d",&n);
  printf("%d\n",fibonatti(n));
  return 0;
}

int fibonatti(int a){
  if(A[a] != -1){
    return A[a];
  }

  if(a == 0 || a == 1){
    return A[a]=1;
  }
  return A[a] = fibonatti(a-2) + fibonatti(a-1);
}



Measured memory_bytes: 2112
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use std::cmp::{min, Reverse};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
        m: usize,
        s: usize,
        cs: [(Usize1, Usize1, usize, u64); m],
        exchanges: [(usize, u64); n],
    }

    let mut cities = vec![vec![]; n];
    for (u, v, a, b) in cs {
        cities[u].push((v, a, b));
        cities[v].push((u, a, b));
    }
    // n * a
    let max_money = 50 * 50;
    // dp[city][money] = time
    let mut dp = vec![vec![std::u64::MAX; max_money + 1]; n];
    // queue for (time, city, money) tuple
    let mut q = std::collections::BinaryHeap::new();

    dp[0][min(s, max_money)] = 0;
    q.push(Reverse((0, 0, min(s, max_money))));

    while let Some(Reverse((time, city, money))) = q.pop() {
        if dp[city][money] < time {
            continue;
        }

        // step forward to neighbor cities
        for &(another, cost_m, cost_t) in cities[city].iter() {
            // need more money!!
            if money < cost_m {
                continue;
            }

            let time = time + cost_t;
            let money = money - cost_m;

            if dp[another][money] > time {
                dp[another][money] = time;
                q.push(Reverse((time, another, money)));
            }
        }

        // step forward to money exchange
        let money = min(money + exchanges[city].0, max_money);
        let time = time + exchanges[city].1;
        if dp[city][money] > time {
            dp[city][money] = time;
            q.push(Reverse((time, city, money)));
        }
    }

    for i in dp.into_iter().skip(1) {
        let ans = i.into_iter().min().unwrap();
        echo!(ans);
    }
}


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

int main()
{
    long long int a,f=0;
    cin>>a;
    long long int l=sqrt(a);
    long long int aa[l];
    long long int ll=0;
    for(int i=1; i<=l; i++)
    {
        if(a%i==0)
        {
          long long  int d=a/i;
           aa[ll]=i+d;
           ll+=1;
        }

    }

     sort(aa,aa+ll);

    cout<<aa[0]-2<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
int LOG2(int a) {
	int cnt = 0;
	while (a % 2 == 0) {
		a /= 2;
		cnt++;
	}
	return cnt;
}
int main() {
	int n,a[10010];
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += LOG2(a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int c1=0,c2=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='A') c1++;
    else c2++;
  }
  if(c1==s.length() || c2==s.length())
    cout<<"No";
  else cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const lli mod = (lli)(998244353);

lli n, a, b, k, fac[N], ans;

lli fp(lli x, lli y) {
	if(y == 0)
		return 1;
	lli t = fp(x, y / 2);
	if(y % 2 == 0)
		return t * t % mod;
	else
		return (t * t % mod) * x % mod;
}

lli comb(lli x, lli y) {
	if(x < y)
		return 0;
	lli den = fac[y] * fac[x - y] % mod;
	return fp(den, mod - 2) * fac[x] % mod;
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);

	cin >> n >> a >> b >> k;

	if(k == 0) {
		cout << 1;
		return 0;
	}

	fac[0] = 1;
	for(lli i = 1; i < N; i++)
		fac[i] = fac[i - 1] * i % mod;
	for(lli x = 0; x <= n; x++) {
		if((k - x * a) % b == 0) {
			lli y = (k - x * a) / b;
			if(y >= 0 && y <= n) {
				ans += comb(n, x) * comb(n, y) % mod;
				ans %= mod;
				// d1("asd");
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
int main() {
	int  a, b, c,x,y;
	cin >> a >> b >> c >> x >> y;
	if (2 * c > a + b) {
		cout << a * x + b * y;
	}
	else {
		int d = min(x, y);
		int e = max(x, y);
		if (x > y) {
			cout << min(e*c*2,d * 2 * c + (e - d) * a);
		}
		else {
			cout << min(e*c*2,d * 2 * c + (e - d) * b);
		}
	}
}


Measured memory_bytes: 384
import Control.Applicative

-- | slove
-- >>> solve 3 4
-- 6
-- >>> solve 2 2
-- 1

main = do
    (n : m : _) <- (map read . words) <$> getLine -- input: 123 456 789
    print $ solve n m

solve n m = (n - 1) * (m - 1)


Measured memory_bytes: 508
import sys
S=input()
k=int(input())
ans=0
flag=0
left=0
right=0
if S[0]==S[-1]:
    left=1
    for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
    
now=""
for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        now=S[i]
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i]
ans*=k

if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2

print(ans)

Measured memory_bytes: 3064
N, Y = gets.split.map(&:to_i)

bills = [10000, 5000, 1000]

ans = '-1 -1 -1'
(N + 1).times do |i|
  (N - i + 1).times do |j|
    k = N - i - j
    sum = bills[0] * i + bills[1] * j + bills[2] * k
    if sum == Y then
      ans = "#{i} #{j} #{k}"
    end
  end
end

puts ans


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

using namespace std;

int X[100000];
int Y[100000];

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

    int i;
    for(i = 0; i < M; i++){
        cin >> X[i];
    }

    if(M <= N){
        cout << 0 << endl;
        return 0;
    }

    sort(X, X+M);

    for(i = 0; i < M-1; i++){
        Y[i] = X[i+1] - X[i];
    }

    sort(Y, Y+M-1);

    int sum = 0;
    for(i = 0; i < M-N; i++){
        sum += Y[i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, a, b] <- readIntegerList
  print $ a * (n `div` (a + b)) + min (n `mod` (a + b)) a


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int r, c, k;
  cin >> r >> c >> k;
  vector<vector<int>> v(r, vector<int>(c, 0));
  rep(i, k){
    int rr, cc, vv;
    cin >> rr >> cc >> vv;
    rr--; cc--;
    v.at(rr).at(cc) = vv;
  }
  
  vector<vector<vector<ll>>> dp(r, vector<vector<ll>>(c, vector<ll>(4, 0)));
  if(v.at(0).at(0) > 0){
    dp.at(0).at(0).at(1) = v.at(0).at(0);
  }
  rep(i, r)rep(j, c)rep(k, 4){
    ll now = dp.at(i).at(j).at(k);
    if(k > 0 && now == 0) continue;
    if(i < r-1){
      dp.at(i+1).at(j).at(0) = max(dp.at(i+1).at(j).at(0), now);
      if(v.at(i+1).at(j) > 0) dp.at(i+1).at(j).at(1) = max(dp.at(i+1).at(j).at(1), now+v.at(i+1).at(j));
    }
    if(j < c-1){
      dp.at(i).at(j+1).at(k) = max(dp.at(i).at(j+1).at(k), now);
      if(k < 3 && v.at(i).at(j+1) > 0) dp.at(i).at(j+1).at(k+1) =max(dp.at(i).at(j+1).at(k+1), now+v.at(i).at(j+1));
    }
  }
  ll ans = max({dp.at(r-1).at(c-1).at(0), dp.at(r-1).at(c-1).at(1), dp.at(r-1).at(c-1).at(2), dp.at(r-1).at(c-1).at(3)});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 671608
#include <stdio.h>

#define MAX 500000
#define SMAX 2000000000

int n,A[MAX],count=0;

void mergeSort(int*,int,int);
void merge(int*,int,int,int);

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",count);
  return 0;
}

void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k,L[MAX/2+2],R[MAX/2+2];
  n1 = mid-left;
  n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left+i];
  for(i=0;i<n2;i++) R[i] = A[mid+i];
  L[n1] = SMAX;
  R[n2] = SMAX;
  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i+1;
    }
    else {
      A[k] = R[j];
      j = j+1;
    }
  }
}

Measured memory_bytes: 4504
#include<stdio.h>
int main(void)
{	
	int count=0;
	int h,w;
	int i,j;
	scanf("%d%d",&h,&w);
	
	int s[h][w];
	for(i=0; i<h; i++)
	{
		for(j=0; j<w; j++)
			s[i][j]=0;
	}
	
	int a,b;
	scanf("%d%d",&a,&b);
	
	for(i=0; i<a; i++)
	{
		for(j=0; j<w; j++)
		{
			s[i][j]=-1;
		}
	}
	
	for(j=0; j<b; j++)
	{
		for( i=0; i<h; i++)
		{
			s[i][j]--;
		}
	}
	
		
	for(i=0; i<h; i++)
	{
		for(j=0; j<w; j++)
		{
			if(s[i][j]==0)
			count++;
		}
	}
	
	printf("%d",count);
	

	return 0;
}

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

int main()
{
	int a,b,c,d,sum=0;
	
    cin>>a;
    int v=a;
    vector<int> temp(v);
    for  (int i = 0; i < a; i++)
    {
        cin>>temp[i];
    }
    int cnt = a-1,lc=0,rc=0;
    int i=0,n=0;
    while(1)
    {
        if(a!=0)
        {
            if(lc<=rc)
            {
                lc+=temp[i];
                i++;
            }
            else
            {
                rc+=temp[cnt-n];
                n++;
            }

            a--;
 
        }
        else
            break;

    }

    cout<<abs(lc-rc);
    

    
	return 0;
}
	

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

#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end()); 
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));

//ffs = lsb, clz = l0's, ctz = r0's, popcount = 1's 
 //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
 //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
    fastio();
    int n; cin >> n;
    if(n>=1000){
        cout  << "ABD\n";
    }else{
        cout << "ABC\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A,B,C,D;
  cin >> A;
  
  B = A / 100; //100のくらい
  C = A % 2; //1の位
  D = A / 10 % 10; //10の位
  
  cout << B + C + D << endl;
  
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0) {
        c -= b;
        if(c <= 0) break;
        a -= d;
    }
    if(a > 0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int total = 0;
        int count = 0;
        while (count<2) {
            if (a > b) {
                total += a;
                a--;
                count++;
            } else if (a < b) {
                total += b;
                b--;
                count++;
            } else if (a == b) {
                total += a;
                a--;
                count++;
            }
        }
        System.out.println(total);
    }

}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

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

  int now = n;
  stack<int> stk;
  while(1){
    int bf = now;
    rrep2(i, 1, m+1){
      if(now - i >= 0 && s.at(now-i) == '0'){
        stk.push(i);
        now = now - i;
        break;
      }
    }
    if(bf == now){
      cout << -1 << endl;
      return 0;
    }
    if(now == 0) break;
  }
  bool f = false;
  while(!stk.empty()){
    if(f != false) cout << " ";
    cout << stk.top();
    stk.pop();
    if(f == false) f = true;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4032
package main

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

func main() {
	N, M := nextInt(), nextInt()
	ss := make([][]int, M)
	for i := 0; i < M; i++ {
		k := nextInt()
		ss[i] = make([]int, k)
		for j := 0; j < k; j++ {
			ss[i][j] = nextInt()
		}
	}

	ps := make([]int, M)
	for i := 0; i < M; i++ {
		ps[i] = nextInt()
	}

	allSw := map[int]bool{}
	var ans int
	for i := 0; ; i++ {
		if i != 0 {
			inc(allSw, 1)
		}
		isOK := true
		for j := 0; j < M; j++ {
			var onCnt int
			for _, s := range ss[j] {
				if allSw[s] {
					onCnt++
				}
			}
			if onCnt%2 != ps[j] {
				isOK = false
				break
			}
		}
		if isOK {
			ans++
		}

		isEnd := true
		for k := 1; k <= N; k++ {
			if !allSw[k] {
				isEnd = false
			}
		}
		if isEnd {
			break
		}
	}

	fmt.Println(ans)
}

func inc(m map[int]bool, i int) {
	if m[i] == true {
		m[i] = false
		inc(m, i+1)
		return
	}

	m[i] = true
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final long MOD =  1000000007L;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		long a = 1;
		for (i = 1; i <= n; i++) {
			a*=i;
			if(a>=MOD) {
				a%=MOD;
			}
		}
		out.println(a);
	}
}


Measured memory_bytes: 23636
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int h, w;
vector<int> ys[maxn];

bool read() {
  int n;
  if (scanf("%d%d%d", &h, &w, &n) < 3) {
    return false;
  }
  for (int i = 0; i < h; i++) {
    ys[i].clear();
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    ys[x].push_back(y);
  }
  return true;
}

void solve() {
  for (int i = 0; i < h; i++) {
    sort(ys[i].begin(), ys[i].end());
  }
  int r = 1;
  for (int i = 1; i < h; i++) {
    if (!ys[i].empty() && ys[i][0] < r) {
      printf("%d\n", i);
      return;
    }
    if (ys[i].empty() || ys[i][0] > r) {
      r++;
    }
  }
  printf("%d\n", h);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 11136
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int P[100010];

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

	cin >> N;
	int p;
	rep(i, 1, N + 1)
	{
		cin >> p;
		P[p] = i;
	}

	multiset<int> lset;
	multiset<int> rset;
	lset.insert(0);
	rset.insert(N + 1);

	int ans = 0;

	rrep(i, 1, N + 1)
	{
		int ll, lr, rl, rr;
		lr = -(*lset.upper_bound(-P[i]));
		if (lr == 0)ll = 0;
		else
			ll = -(*lset.upper_bound(-lr));
		rl = *rset.upper_bound(P[i]);
		if (rl == N + 1)rr = N + 1;
		else
			rr = *rset.upper_bound(rl);

		ans += i*((lr - ll)*(rl - P[i]) + (P[i] - lr)*(rr - rl));

		rset.insert(P[i]);
		lset.insert(-P[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10368
sx, sy, tx, ty = gets.split.map(&:to_i)
ret = []

a = ty - sy
b = tx - sx

ret << 'U' * a
ret << 'R' * b
ret << 'D' * a
ret << 'L' * b
ret << 'L'
ret << 'U' * (a + 1)
ret << 'R' * (b + 1)
ret << 'D'
ret << 'R'
ret << 'D' * (a + 1)
ret << 'L' * (b + 1)
ret << 'U'

puts ret.join

Measured memory_bytes: 1788
#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>;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	int t = n -1;
	rep(i,n) {
		int lim = 2;
		if (i == 0) lim = 1;
		rep(j, lim) {
			if (t > 0) {
				ans += a[i];
				t--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
ll m[6];
int32_t main() {
    IAMSPEED
  int n; cin >> n;
  FOR(i,1,n) {
    string str; cin >> str;
    if (str[0]=='M')m[0]++;
    if(str[0]=='A')m[1]++;
    if(str[0]=='R')m[2]++;
    if(str[0]=='C')m[3]++;
    if(str[0]=='H')m[4]++;
  }
  ll ans = 0;
  /*
  ans += m[0]*m[1]*m[2];
  ans += m[0]*m[1]*m[3];
  ans += m[0]*m[1]*m[4];
  ans += m[0]*m[2]*m[1];
  ans += m[0]*m[2]*m[3];
  ans += m[0]*m[2]*m[4];
  ans += m[0]*m[3]*m[1];
  ans += m[0]*m[3]*m[2];
  ans += m[0]*m[3]*m[4];
  ans += m[0]*m[4]*m[0];
  */
  FOR(i,0,5) {
      FOR(j,0,i-1) {
          FOR(k,0,j-1) {
              if (i!=j&&i!=k&&j!=k) ans += m[i]*m[j]*m[k];
          }
      }
  }
          
  cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    //食べた数
    cin >> N;
    //入力
    cout << 800 * N - 200 * (N / 15) << endl;
    //800円の食べ物をN回食べて、5回食べたら200円を引いて出力
}

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

ll nc2(ll n) { return n * (n - 1) / 2; }

int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  rep(i, n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  map<int, int> mp;
  int count = 1;
  rep(i, n - 1) {
    if (b[i] == b[i + 1]) {
      count++;
      if (i == n - 2) {
        mp.emplace(b[i], count);
      }
      continue;
    } else {
      mp.emplace(b[i], count);
      count = 1;
      if (i == n - 2) {
        mp.emplace(b[i + 1], 1);
      }
    }
  }
  ll all = 0;
  for (const auto &value : mp) {
    all += nc2(value.second);
  }
  ll ans = all;
  for (int k : a) {
    ans -= nc2(mp[k]);
    ans += nc2(mp[k] - 1);
    cout << ans << endl;
    ans = all;
  }
  return 0;
}

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

using namespace std;

string s, t;

int main()
{
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n,x; cin >> n >> x;
    int d = 0,count =0;
    vector<int> l;

    for(int i =0;i < n;i++){
        int a;
        cin >> a;
        l.push_back(a);
    }

    while(d <= x){
        if(count > n) break;
        d = d + l[count];
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int numV = scan.nextInt();
    ArrayList<ArrayList<Integer>> vlist = new ArrayList<>(numV);
    for(int i=0; i<numV; i++){
      vlist.add(new ArrayList<>());
    }
    for(int i=0, loop=scan.nextInt(); i<loop; i++){
      int u = scan.nextInt();
      int v = scan.nextInt();
      vlist.get(u).add(v);
      vlist.get(v).add(u);
    }
    int q = scan.nextInt();
    int[] start = new int[q];
    int[] target = new int[q];
    for(int i=0; i<q; i++) {
      start[i] = scan.nextInt();
      target[i] = scan.nextInt();
    }
    int[] color = new int[numV];
    assignColor(vlist,color);
    for(int i=0; i<q; i++) {
      if (color[start[i]]==color[target[i]]) {
        System.out.println("yes");
      }else {
        System.out.println("no");
      }
    }
  }

  static void assignColor(ArrayList<ArrayList<Integer>> vlist, int[] color){
    int[] status = new int[vlist.size()];
    ArrayDeque<Integer> stack = new ArrayDeque<>(vlist.size());

    int colorCount = 0;
    for(int i=0,len=vlist.size(); i<len; i++){
      if(color[i]!=0)
        continue;
      colorCount++;
      int current = i;
      status[current]++;
      stack.addLast(current);
      color[current] = colorCount;

      while(!stack.isEmpty()){
        current = stack.getLast();
        boolean hasNotBroken = true;
        for(int j=0; j<vlist.get(current).size(); j++){
          int adj = vlist.get(current).get(j);
          if(status[adj]==0){
            current = adj;
            status[current]++;
            stack.addLast(current);
            color[current] = colorCount;
            hasNotBroken = false;
            break;
          }
        }
        if(hasNotBroken){
          status[current]++;
          stack.removeLast();
        }
      }
    }
  }
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  assert(0<n and n <=1e5);
  int line[(int)(1e5+10)];
  for(auto&i:line)i=0;
  for(int i=0;i<n;++i){
    int x;
    cin >> x;
    assert(0<= x and x <= 1e5);
    ++line[x];
  }
  int ans = 0;
  for(int i=1;i<1e5;++i){
    ans = max(ans,line[i-1]+line[i]+line[i+1]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;


int solve(ll l, ll r) {
  
  int v = 2019;
  
  for (ll i = l; i <= r; ++i) {
    for (ll j = i+1; j <= r; ++j) {
      int mod = (i*j)%2019;
      v = min(v, mod);
    }
  }
  return v;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll l,r; cin>>l>>r;
  
  int res = 0;
  
  if(r-l+1>=2019) res = 0;
  else {
    res = solve(l, r);
  }
  
  cout<<res;
  
  return 0;
}

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

constexpr int INF = 1e9;

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> d(10, vector<int>(10, INF));
        for(int i=0; i<10; ++i) {
            d[i][i] = 0;
        }
        for(int i=0; i<n; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
        }
        for(int k=0; k<10; ++k) {
            for(int i=0; i<10; ++i) {
                for(int j=0; j<10; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        int cost = INF, town = -1;
        for(int i=0; i<10; ++i) {
            int c = 0;
            for(int j=0; j<10; ++j) {
                if(d[i][j] == INF) {
                    continue;
                }
                c += d[i][j];
            }
            if(c != 0 && cost > c) {
                cost = c;
                town = i;
            }
        }
        cout << town << ' ' << cost << endl;
    }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
	cin>>s;
	cout<<s.substr(0,3); 
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

vector<int> make753() {

	vector<int> vec753;
	int bit_used = 0;
	int tmp, ternary, n753;

	for (int digit = 3; digit <= 9; digit++) {

		for (int i = 0; i <= 19683; i++) {

			bit_used = 0;
			ternary = i;
			n753 = 0;

			for (int j = 0; j < digit; j++) {
				tmp = ternary % 3;
				ternary /= 3;
				n753 *= 10;
				if (tmp == 0) {
					n753 += 3;
					bit_used |= 1;
				}				
				if (tmp == 1) {
					n753 += 5;
					bit_used |= 2;
				}
				if (tmp == 2) {
					n753 += 7;
					bit_used |= 4;
				}
			}

			if (!(bit_used ^ 7)) vec753.push_back(n753);

		}

	}

	sort(vec753.begin(), vec753.end());
	vec753.erase(unique(vec753.begin(), vec753.end()), vec753.end());
	return vec753;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> vec = make753();
	int ans = upper_bound(vec.begin(), vec.end(), N) - vec.begin();

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <algorithm>

using namespace std;

#define chmin(a,b) a=min(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[100][100];

signed main()
{
	int N, K;
	
	while (scanf("%d %d", &N, &K), N || K) {
        fill(d[0], d[N], inf);
        rep(i, N) d[i][i] = 0;

		rep(i, K) {
			int t; scanf("%d", &t);
			if (t) {
				int a, b, c; scanf("%d %d %d", &a, &b, &c); a--; b--;
                d[a][b] = d[b][a] = min(d[a][b], c);
				rep(j, N) rep(k, N) {
					chmin(d[j][k], min(d[j][a] + d[a][b] + d[b][k], d[j][b] + d[b][a] + d[a][k]));
				}
			} else {
				int a, b; scanf("%d %d", &a, &b); a--; b--;
				printf("%d\n", d[a][b] == inf ? -1 : d[a][b]);
			}
		}
	}
}

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

using namespace std;

int main(void) {
  int c[4][4];
  for(int i = 1; i <= 3; i++) {
    for(int j = 1; j <= 3; j++) {
      cin >> c[i][j];
    }
  }

  int a[4], b[4];
  a[1] = 0;
  for(int i = 1; i <= 3; i++) {
    b[i] = c[1][i] - a[1];
  }
  for(int i = 2; i <= 3; i++) {
    a[i] = c[i][1] - b[1];
  }

  for(int i = 1; i <= 3; i++) {
    for(int j = 1; j <= 3; j++) {
      if(c[i][j] != a[i] + b[j]) {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int cnt = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if((500 * i + 100 * j + 50 * k) == x){
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a, a+n);
    long long sum = 0;
    int mid = a[n / 2];
    for (int i = 0; i < n; i++) {
        sum += abs(a[i] - mid);
    }
    cout << sum;
}

Measured memory_bytes: 1792
/*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

int main()  
{ 
    FAST_INP;
    // binary search 
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll l=1,r=0;
    for(int i=0;i<n;i++) {
    	cin >> a[i];
    	r=max(r,a[i]);
	}
    while(l!=r){
    	int m = l+(r-l)/2;
    	ll kk=0;
		for(int i=0;i<n;i++){
			kk+=(a[i]-1)/m;
		}
    	if(kk<=k) r=m;
    	else l=m+1;
	}
	cout << l << endl;
    return 0;
} 

Measured memory_bytes: 4748
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << '\n';
}


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

bool dfs(vector<vector<pair<int,int>>> &G, vector<int> &dis, int cur, int prv, int c) {
    if(dis[cur] != -1e9-1) return dis[cur] == c;
    dis[cur] = c;

    bool res = true;
    for(auto &v: G[cur]) {
        if(!res) return res;

        int w = v.first;
        int d = v.second;
        if(w == prv) continue;
        res &= dfs(G, dis, w, cur, c+d);
    }
    return res;
}

int main(void) {
    int n,m;
    cin >> n >> m;

    bool ok = true;

    vector<vector<pair<int, int>>> G(n);
    vector<int> dis(n, -1e9-1);

    for(int i=0; i<m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        G[l].push_back(pair<int,int>(r, d));
        G[r].push_back(pair<int,int>(l, -d));
    }

    bool res = true;
    for(int i=0; i<n; i++) {
        if(dis[i] != -1e9-1) continue;
        res &= dfs(G, dis, i, -1, 0);
    }
    cout << (res ? "Yes" : "No") << endl;

}


Measured memory_bytes: 13824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for (int i = 0; i < length; i++) {
                char ch = line.charAt(i);
                if (Character.isLowerCase(ch)) {
                    System.out.print(Character.toUpperCase(ch));
                } else {
                    System.out.print(Character.toLowerCase(ch));
                }
            }
            System.out.println(answer);
        }
    }
}



Measured memory_bytes: 27064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void Input(); void Prepare(); void Setup(); void Solve(); void Clean();

#ifdef DEBUG6500
double a = 2, b = 2, x = 4;
int main(){ Prepare(); Solve(); return 0; }
#else
double a, b, x;
int main(){ Input(); Prepare(); Solve(); Clean(); return 0; }
#endif

double S; // 横から見た時の水の面積

void Solve_mini(); void Solve_big();

void Solve()
{
	S = x / a;
	double podS = a * b;
	if (podS == S * 2) printf("%.8f\n", 45.0f);
	else if (podS > S * 2) Solve_mini();
	else Solve_big();
}
	
void Solve_mini()
{
	double c; // 傾けた時にできる直角三角形の底側の辺
	c = 2.0f * S / b;

	double tan_theta = b / c;
	double radian = atan(tan_theta);
	double degree = radian * 180 /M_PI;

	printf("%.8f\n", degree);
}

void Solve_big()
{
	double S2 = a * b - S; // 上に残る三角形の面積
	
	double c; // 傾けた時にできる直角三角形の壁側の辺
	c = 2.0f * S2 / a;

	double tan_theta = c / a;
	double radian = atan(tan_theta);
	double degree = radian * 180 /M_PI;

	printf("%.8f\n", degree);
}

void Prepare()
{
}

#ifndef DEBUG6500
void Clean()
{
}

void Input()
{
	cin >> a >> b >> x;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long H, W, A, B, fact[250000], inv[250000], factinv[250000];
long long nCr(int n, int r)
{
    if (n - r >= 0 && r >= 0)
    {
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }
    else
    {
        return 0;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fact[0] = 1;
    for (int i = 1; i < 250000; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }
    inv[1] = 1;
    for (int i = 2; i < 250000; i++)
    {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
    factinv[0] = 1;
    for (int i = 1; i < 250000; i++)
    {
        factinv[i] = factinv[i - 1] * inv[i] % MOD;
    }
    cin >> H >> W >> A >> B;
    long long sum = 0;
    int z = (H-A-1);
    for(int i = B; i < W; i++){
        long long first = nCr((z+i),i);
        long long second = nCr((A-1+W-1-i), (A-1));
        sum+=first*second;
        sum%=MOD;
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 6144