akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC170
{
    class B
    {
        static void Main(string[] args)
        {
            var XN = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var input = Console.ReadLine();

            if (input.Length == 0)
            {
                Console.WriteLine(XN[0]);
                return;
            }

            var p = input.Split().Select(long.Parse).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var AB = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var ans = long.MaxValue;
            var temp = long.MaxValue;
            for (int i = 210; i >= 0; i--)
            {
                if (!p.Contains(i))
                {
                    if (Math.Abs(XN[0] - i) <= temp) { temp = Math.Abs(XN[0] - i); ans = i; }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string x;
	cin >> x;
	
	int fx = 0;
	for(int i=0; i<(int)x.size(); i++){
		fx += (int)(x[i] - '0');
	}
	
	if(stoi(x) % fx == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

int main(){
   ll a = 0;
   string S;
   cin >> S;
   rep(i,S.size()) a += ll(S[i] - '0');
   if(a % 9 == 0) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
using Int = long long;
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N, K, X, Y; cin >> N >> K >> X >> Y;
    if (N >= K) {
        cout << K * X + (N - K) * Y << endl;
    } else {
        cout << N * X << endl;
    }
    return 0;
}

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

int main() {
  int k, n;
  cin >> n >> k;
  
  vector<double> exp(n);
  rep(i, n) {
    int p;
    cin >> p;
    exp[i] = (p + 1) / 2.0;
//    cout << exp[i] << endl;
  }
  
  double maxi = 0;
  rep(i, k) maxi += exp[i];
//  cout << maxi << endl;
  
  double now = maxi;
  for(int i = k; i < n ; ++i) {
//    cout << "maxi:" << maxi << ",exp[i-k]:" << exp[i-k] << ",exp[i-1]:" << exp[i] << endl;
    now = now - exp[i-k] + exp[i];
    maxi = max(maxi, now);
  }
  
  cout << fixed << maxi << endl;
    
  return 0;
}


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

int main(){

 int A, B, C, D;
 cin >> A  >> B >> C >> D;
  
 int left = A + B;
 int right = C + D;
  
 if(left > right){
  cout << "Left" << endl;
 }
  
 else if(left == right){
  cout << "Balanced" << endl;
 }
  
 else{
  cout << "Right" << endl;
 }

}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int X,Y;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> X >> Y;


	cout << X + Y/2<< endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		long long int n,k,z,i=0,q=0,count=0,c=0,d=0,sum=0,xor1=0;
      	cin >> n ;
      	vector<long long int> arr;
      	//memset(arr,0,sizeof(arr));
      	for(i=0;i<n;i++){
        	cin >> z;
          arr.push_back(z);
          //sum += z;
          xor1^=z;
        }
    	for(i=0;i<n;i++){
          c = arr[i];
        	cout << (c|xor1) - (c&xor1) <<" ";
        }
      
	}
}

Measured memory_bytes: 5304
#include <iostream>
#include <algorithm>
#define PI 3.14159265358979L
using namespace std;
long double r;
int main() {
	while(cin >> r, r != 0.0L) {
		for(int i = 1; ; i++) {
			long double x = (PI * i - (int)(PI * i)) / i;
			long double y = ((int)(PI * i) - PI * i + 1) / i;
			if(x <= r) {
				cout << (int)(PI * i) << '/' << i << endl; break;
			}
			if(y <= r) {
				cout << (int)(PI * i) + 1 << '/' << i << endl; break;
			}
		}
	}
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void A_task();

int main()
{
	A_task();
	
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int P, Q, R;
	scanf(" %d %d %d", &P, &Q, &R);

	int a = P + Q;
	int b = Q + R;
	int c = R + P;

	int ans = std::min(a, b);
	
	printf("%d\n", std::min(ans, c));
}


Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
street=[]
for i in range(m):
    street.append(list(map(int,input().split())))
not_taller=[]
for i in range(m):
    if h[street[i][0]-1]==h[street[i][1]-1]:
        not_taller.append(street[i][0])
        not_taller.append(street[i][1])
    elif h[street[i][0]-1]>h[street[i][1]-1]:
        not_taller.append(street[i][1])
    else:
        not_taller.append(street[i][0])
print(n-len(set(not_taller)))


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

int main(){
  int n; cin >> n;
  vector<int> a(n),v(100005); for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) v[a[i]]++;
  int count=0, even=0;
  for(int i=1;i<100005;i++){
  	if(v[i]>0){
      count++;
      if(v[i]%2==0) even++;
    }
  }
  cout << count - even%2 << endl;
  return 0;
}

Measured memory_bytes: 1152
import sys

input = sys.stdin.readline

S = input()
S = S.replace('\n','')
s_list = list(S)

K = "keyence"
k_list = list(K)

for start in range(len(s_list)):
    small_s_list = s_list[start:]
    if "".join(small_s_list)== K:
        print("YES")
        exit(0)

for end in reversed(range(len(s_list))):
    small_s_list = s_list[:end+1]
    if "".join(small_s_list)== K:
        print("YES")
        exit(0)
point = int(len(s_list)/2)
for delete_start in range(len(s_list)-point):
    if delete_start >= point:
        break
    for delete_end in reversed(range(len(s_list))):
        if delete_end < point:
            break
        small_s_list = s_list[:delete_start+1] + s_list[delete_end:]
        if "".join(small_s_list)== K:
            print("YES")
            exit(0)
print("NO")

Measured memory_bytes: 8936
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    vector<long long int> vec;
    for (long long int i = 0; i < n; i++)
    {
        long long int inp;
        cin >> inp;
        vec.push_back(inp);
    }
    long long int ans = 0;
    for (long long int i = 1; i < n; i++)
    {
        if (vec[i] < vec[i - 1])
        {
            ans = ans + (vec[i - 1] - vec[i]);
            vec[i] = vec[i - 1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5364
x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC = []
for x, a in enumerate(A):
    if x+1 > 3000:
        break
        
    for y, b in enumerate(B):
        if (x+1)*(y+1) > 3000:
            break
    
        for z, c in enumerate(C):
            if (x+1)*(y+1)*(z+1) > 3000:
                break
            
            ABC.append(a+b+c)
            
ABC.sort(reverse=True)
ABC = ABC[:k]

for abc in ABC:
    print(abc)

Measured memory_bytes: 8708
L = []
while True:
        a = list(map(int, input().split()))
        if a[0] == -1and a[1] == -1 and a[2]==-1:
            break

        L.append(a)

def f(m,f,r):

    s = m + f
    if m == -1 or f == -1:
        print("F")
    elif s >= 80:
        print("A")
    elif s >= 65 and s <80:
        print("B")
    elif s >= 50 and s <65:
        print("C")
    elif s >= 30 and s <50:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")

for i in range(len(L)):
    f(L[i][0],L[i][1],L[i][2])



Measured memory_bytes: 5600
T = list(input())
N = len(T)

for i in range(N):
  if T[i] == '?':
    if T == ['?']:
      print('D')
      exit()
    if i == 0:
      if T[1] == 'D':
        T[0] = 'P'
      elif T[1] == 'P':
        T[0] = 'D'
      else:
        T[0] = 'P'
    elif i == N - 1:
      T[i] = 'D'
    else:
      if T[i-1] == 'P':
        T[i] = 'D'
      else:
        if T[i+1] == '?':
          T[i] = 'P'
        else:
          if T[i+1] == 'D':
            T[i] = 'P'
          else:
            T[i] = 'D'
          
print("".join(T))
      

Measured memory_bytes: 10856
#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
#define oo (1e18)
using namespace std;
INT n, ans;
string s[330], a[660], b[660];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>s[i];
    for(int i = 0 ; i < 2*n ; i++ ) b[i] = a[i] = s[i%n]+s[i%n];
    for(int i = 0 ; i < 2*n ; i++ ) for(int j = 0 ; j < 2*n ; j++ )
        b[j][i] = a[i][j];
    for(int j = 0 ; j < n ; j++ )
    {
        bool same = true;
        for(int k = 0 ; same and k < n ; k++ )
            if( a[k].substr(j+k, n-k) != b[j+k].substr(k, n-k) )
                same = false;
        if( same ) ans+=n;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int64_t power(int64_t x, int64_t n) {
    int64_t ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x % MOD;
        }
        x = x * x % MOD;  //一周する度にx, x^2, x^4, x^8となる
        n >>= 1;          //桁をずらす n = n >> 1
    }
    return ans;
}

int main() {
    ll n, ans = 0, cnt = 1;
    string L;
    cin >> L;
    n = L.size();
    reverse(ALL(L));
    ans += power(3,n-1);
    for(ll i=n-2;i>=0;i--){
        if(L[i]=='1'){
            ans += power(3,i)*power(2,cnt)%MOD;
            ans %= MOD;
            //cout << ans << endl;
            cnt++;
        }
    }
    ans += power(2,cnt);
    //ans += 2;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int N, K;
int ans;
vector<vector<int>> rev;

int dfs(int v, int prev){
    int depth = 0;
    for(int to : rev[v]){
        if(to == prev) continue;
        depth = max(depth, dfs(to, v));
    }
    if(depth == K-1 && prev != 0){
        ans++;
        return 0;
    }
    return depth + 1;
}

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

    ans = 0;
    rev.assign(N, {});
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i == 0){
            ans += a != 1 ? 1 : 0;
        }else{
            rev[a-1].push_back(i);
        }
    }

    dfs(0, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    vector<int> a(3);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[0]>>a[1]>>a[2];
        sort(a.begin(),a.end());
        if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1])cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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

int main(){
  string n;
  cin >> n;
  
  int num = stoi(n);
  int sum = 0;
  rep(i,n.size()){
    sum += num%10;
    num /= 10;
  }
  
  if(stoi(n)%sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n,x,ans;
    cin >> n >> x;
    ans = 1;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int pre = 0;
    for(int i = 1; i<= n; i++){
        int d = pre + l[i-1];
        if(d <= x) ans++;
        pre = d;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	static int[] D = { 1, 0, -1, 0 };
	static int w, h, c;

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			h = sc.nextInt();
			w = sc.nextInt();
			c = sc.nextInt();
			if ((h|w|c)==0)break;

			int[] board = new int[w * h];
			for (int y = 0; y < h; y++)
			{
				for (int x = 0; x < w; x++)
				{
					board[y * w + x] = sc.nextInt();
				}
			}

			System.out.println(count(board, 5));
		}
	}

	static int count(int[] board, int t)
	{
		if (t == 0)
		{
			return countColor(board);
		}

		int max = 0;
		for (int i = 1; i <= 6; i++)
		{
			if (board[0] == i) continue;
			int[] cb = Arrays.copyOf(board, board.length);
			changeColor(cb, 0, 0, cb[0], i);
			max = Math.max(max, count(cb, t - 1));
		}
		return max;
	}

	static int countColor(int[] board)
	{
		return countColor(board, 0, 0);
	}

	static int countColor(int[] board, int x, int y)
	{
		int count = 0;
		if (0 <= x && x < w && 0 <= y && y < h && board[y * w + x] == c)
		{
			count++;
			board[y * w + x] = 0;
			for (int i = 0; i < 4; i++)
			{
				int x2 = x + D[i];
				int y2 = y + D[(i + 1) % 4];
				count += countColor(board, x2, y2);
			}
		}
		return count;
	}

	static void changeColor(int[] board, int x, int y, int c, int d)
	{
		if (0 <= x && x < w && 0 <= y && y < h && board[y * w + x] == c)
		{
			board[y * w + x] = d;
			for (int i = 0; i < 4; i++)
			{
				int x2 = x + D[i];
				int y2 = y + D[(i + 1) % 4];
				changeColor(board, x2, y2, c, d);
			}
		}
	}
}
/*
3 5 5
1 6 3 2 5
2 5 4 6 1
1 2 4 1 5
4 5 6
1 5 6 1 2
1 4 6 3 2
1 5 2 3 2
1 1 2 3 2
1 1 5
1
1 8 6
1 2 3 4 5 1 2 3
8 1 1
1
2
3
4
5
1
2
3
8 8 6
5 2 5 2 6 5 4 2
4 2 2 2 5 2 2 2
4 4 4 2 5 2 2 2
6 4 5 2 2 2 6 6
6 6 5 5 2 2 6 6
6 2 5 4 2 2 6 6
2 4 4 4 6 2 2 6
2 2 2 5 5 2 2 2
8 8 2
3 3 5 4 1 6 2 3
2 3 6 4 3 6 2 2
4 1 6 6 6 4 4 4
2 5 3 6 3 6 3 5
3 1 3 4 1 5 6 3
1 6 6 3 5 1 5 3
2 4 2 2 2 6 5 3
4 1 3 6 1 5 5 4
0 0 0
*/

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

int main()
{
  ll n;
  cin >> n;
  int res = 1e9;
  for(ll i = 1; i * i <= n; i++)
  {
    if(n % i != 0) continue;
    string a = to_string(i);
    string b = to_string(n / i);
    int score = max((int)a.size(), (int)b.size());
    res = min(res, score);
  }
  cout << res << endl;
  
  return 0;
}

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

n, m = map(int, input().split())
b = [False, True] + [False] * (n - 1)
c = [1] * (n + 1)
for i in range(m):
    x, y = map(int, input().split())
    c[x] -= 1
    c[y] += 1
    if b[x]:
        b[y] = True
    if c[x] == 0:
        b[x] = False
print(sum(b))

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#define ll long long
using namespace std;

int a;
ll b,n,k;

int main()
{
    cin>>a>>b>>n;
    if(n<b-1) k=n*a/b;
    else k=(b-1)*a/b;
    cout<<k<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(rrng(a));
  ll ans = 0 + a[0];
  int i = 1, cnt = 2;
  while (cnt < n) {
    ans += a[i];
    cnt++;
    if (cnt % 2 == 0) i++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<char> vec(W+2, '#');
  
  for(int i = 0; i < W+2; i++){
  cout << vec.at(i);
  }
  cout << endl;
  
  for(int j = 0; j < H; j++){ 
      
    string str;
    cin >> str;
  for(int i =0; i < W; i++){

    vec.at(i+1) = str.at(i);
  }
    for(int i = 0; i < W+2; i++){
  cout << vec.at(i);
  }
    cout << endl;
  }
  
  vector<char> ve(W+2, '#');
  
  for(int i = 0; i < W+2; i++){
  cout << ve.at(i);
  }
}


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

int n;
int sum;

int main(){

    cin>>n;

int degit_num=(int)log10(n);

sum=0;


for(int i=degit_num;i>=0;i--){
        sum+=n/(int)pow(10,i);
        n=n%(int)pow(10,i);
    }

if(sum==1){
    sum=10;
}


cout<<sum<<endl;
}

Measured memory_bytes: 640
n = int(input())
A = []
X = [[] for _ in range(n)]
Y = [[] for _ in range(n)]
for i in range(n):
    A.append(int(input()))
    for j in range(A[i]):
        x, y = map(int, input().split())
        X[i].append(x)
        Y[i].append(y)

ans = 0
for i in range(2 ** n):
    flg = True
    for j in range(n):
        for k in range(A[j]):
            if (i >> j) & 1:
                if ((i >> (X[j][k] - 1)) & 1) != Y[j][k]:
                    flg = False
                    break

    if flg == True:
        ans = max(ans, sum([int(b) for b in bin(i)[2:]]))

print(ans)

Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//ベクトル→↑←↓
int dx[12] ={2,2,2,-2,-2,-2,1,0,-1,1,0,-1};//ぴょん吉移動方向
int dy[12] ={0,-1,1,0,-1,1,-2,-2,-2,2,2,2};
int sdx[9] = {0,1,0,-1,0,1,1,-1,-1};
int sdy[9] = {0,0,1,0,-1,-1,1,1,-1};
int s;//現在のスクリンぷらーの数
int n;//スプリンクラーの数
typedef pair<int,int> P;
vector<P> S;//スプリンクラーの位置
bool dfs(int y,int x,int s){
  if(s ==n) 
    return true;
  for(int i = 0;i <12;i++){
    int px =x +dx[i];
    int py =y +dy[i];
    if(px <0||py<0||px>9||py>9)
      continue;
    for(int j = 0;j <9;j++){
      int sx =S[s].second+sdx[j];
      int sy =S[s].first+sdy[j];
      if(sx <0||sy<0||sx>9||sy>9)
	continue;
      if(px ==sx&&py ==sy)
	if(dfs(py,px,s+1))
	   return true;
    }
  }
  return false;
}
int main()
{
  int a,b;
  int x,y;
  while(cin >>x>>y,x!=0&&y!=0){//ぴょん吉の初期位置
    cin >>n;
    S.clear();
    for(int i = 0;i < n;i++){
      cin >>a>>b;
      S.push_back(P(b,a));
    }
    cout <<(dfs(y,x,0)?"OK" :"NA")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
  
int main(void) {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int jissoumendokusai(int a, int b)
{
	if ((0 == a) || (0 == b))return 0;
	while (a != b)
	{
		if (a > b) a -= b;
		else b -= a;
	}
	return a;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	cout << x + y + 1 - (jissoumendokusai(x, y)) << endl;
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n, m;
  cin >> n >> m;
  vector<set<int>> G(n + 1);
  vector<pair<int, int>> edges(m + 1);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].insert(v);
    edges[i] = {u, v};
  }
  for (int i = 1; i <= m; ++i) {
    int u = edges[i].first;
    int v = edges[i].second;
    G[u].erase(v);
    vector<int> par(n + 1, -1);
    debug(i);
    function<void(int, int)> dfs = [&](int u, int p) {
      debug(u, p);
      par[u] = p;
      for (auto v : G[u]) {
        if (par[v] == -1) {
          dfs(v, u);
        }
      }
    };
    dfs(v, 0);
    if (par[u] != -1) {
      set<int> nodes;
      int curr = u;
      while (curr != 0) {
        nodes.insert(curr);
        curr = par[curr];
      }
      vector<int> in_deg(n + 1), out_deg(n + 1);
      for (int i = 1; i <= m; ++i) {
        int _u = edges[i].first;
        int _v = edges[i].second;
        if (nodes.count(_u) && nodes.count(_v)) {
          ++in_deg[_v];
          ++out_deg[_u];
        }
      }
      bool ok = true;
      for (auto node : nodes) {
        if (in_deg[node] == 1 && out_deg[node] == 1) {
        } else {
          ok = false;
        }
      }
      if (ok) {
        cout << nodes.size() << "\n";
        for (auto node : nodes) {
          cout << node << "\n";
        }
        return;
      }
    }
    G[u].insert(v);
  }
  cout << "-1\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;
int dp[105][4][2];

int main(){
    string s; cin >> s;
    int k; cin >> k;
    int sl=s.length();
    dp[0][0][0]=1;

    rep(i,sl)rep(j,4)rep(p,2){
        int now=s[i]-'0';
        rep(d,10){
            int nj=j; int np=p;
            if(d!=0) nj++;
            if(nj>k) continue;
            if(d>now && p==0) continue;
            if(d<now) np=1;
            dp[i+1][nj][np]+=dp[i][j][p];
        }
    }
    cout << dp[sl][k][0]+dp[sl][k][1] << endl;
return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
int main(){
  int n,t;
  int a[200000];
  cin>>n>>t;
  rep(i,n)cin>>a[i];
  int sum=0;
  rep(i,n-1){
    if(a[i+1]-a[i]<=t){
      sum+=a[i+1]-a[i];
    }else{
      sum+=t;
    }
  }
  cout<<sum+t<<endl;
  
  return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, T):
    return len(list(filter(lambda x: x[0] == x[1], zip(S, T))))


def main():
    S = read_str()
    T = read_str()
    print(slv(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7612
#include <stdio.h>

int select(int array[], int N);
int main()
{
    int array[100], N, i, sw;
    scanf("%d", &N);
    for (i = 0; i < N; i++)
        scanf("%d", &array[i]);

    sw = select(array, N);
    for (i = 0; i < N; i++)
    {
        if (i > 0)
            printf(" ");
        printf("%d", array[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    return 0;
}
int select(int array[], int N)
{
    int i, j, k, temp, sw = 0;
    for (i = 0; i < N; i++)
    {
        k = i;
        for (j = i; j < N; j++)
        {
            if (array[j] < array[k])
                k = j;
        }
        temp = array[i];
        array[i] = array[k];
        array[k] = temp;
        if (i != k)
            sw++;
    }
    return sw;
}


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

LL gcd(LL a, LL b) {
    if (b > a) {
        swap(a, b);
    }

    if (b == 0) {
        return a;
    }

    return gcd(b, a % b);
}



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

    int N; cin >> N;
    vector<LL> A(N);
    REP(i, N) cin >> A[i];

    vector<LL> F(N + 1);
    vector<LL> B(N + 1);

    F[0] = 0;
    B[N] = 0;

    FOR(i, 1, N + 1) {
        F[i] = gcd(F[i - 1], A[i - 1]);
        B[N - i] = gcd(B[N - i + 1], A[N - i]);
    }

    LL res = 0;
    REP(i, N) {
        res = max(res, gcd(F[i], B[i + 1]));
    }

    cout << res << endl;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int n;
int a[24*60*60+1];

int tt(string s1)
{
    string ss;
    ss = s1.substr(0,2);
    int h = stoi(ss);
    ss = s1.substr(3,2);
    int m = stoi(ss);
    ss = s1.substr(6,2);
    int s = stoi(ss);
    return h*60*60 + m*60 + s;
}

int main()
{
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        rep(i,24*60*60+1){
            a[i] = 0;
        }
        rep(i,n){
            string s1,s2;
            cin >> s1 >> s2;
            a[tt(s1)]++,a[tt(s2)]--;
        }
        int res = 0;
        int nw = 0;
        rep(i,24*60*60+1){
            nw += a[i];
            res = max(res,nw);
        }
        cout << res << "\n";
    }
}

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

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

const int inf = 10000000;
int land[200][200];
int sea[200][200];
int dp[1000][200];

int main() {
    int N,M,R,x,y,i,j,k,t;
  string s;
  while(cin>>N>>M, N|M) {

    rep(i,200) {
      rep(j,200) land[i][j] = sea[i][j] = inf;
      land[i][i] = sea[i][i] = 0;
    }

    rep(i,M) {
      cin>>x>>y>>t>>s;
      x--,y--;
      if(s == "S") {
	sea[x][y] = min(t, sea[x][y]);
	sea[y][x] = sea[x][y];
      }else{
	land[x][y] = min(t, land[x][y]);
	land[y][x] = land[x][y];
      }
    }

    rep(k,N) {
      rep(i,N) {
	rep(j,N) {
	  sea[i][j] = min(sea[i][k]+sea[k][j], sea[i][j]);
	  land[i][j] = min(land[i][k]+land[k][j], land[i][j]);
	}
      }
    }

    cin>>R;
    vector<int> path;
    rep(i,1000) rep(j,200) dp[i][j] = inf;
    rep(i, R) {
      int kt;
      cin>>kt;
      kt--;
      path.push_back(kt);
    }

    dp[0][path[0]] = 0;
    for(i=1; i<R; ++i) {
      for(j=0; j<N; ++j) {
	dp[i][j] = min(dp[i-1][j]+land[path[i-1]][path[i]],dp[i][j]);

	for(k=0; k<N; ++k) {
	  int t = dp[i-1][j]+land[path[i-1]][j]+sea[j][k]+land[k][path[i]];
	  dp[i][k] = min(dp[i][k], t);
	}
	//cout<<i<<": "<<j<<" "<<dp[i][j]<<endl;
      }
    }

    int ans = inf;
    rep(i,N) {
      ans = min(ans, dp[R-1][i]);
      //cout<<i<<" : "<<dp[R-1][i]<<endl;
    }

    cout<<ans<<endl;


  }
}

Measured memory_bytes: 2024
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	breadth_first_search
# CreatedDate:  2020-04-14 23:40:14 +0900
# LastModified: 2020-04-15 00:14:09 +0900
#


import os
import sys
from collections import deque

def bfs(matrix,n):
    s=0
    color=[0]*n
    color[s]=1
    Q=deque()
    Q.append(s)
    distance = [-1]*n
    distance[0]=0
    while Q:
        u = Q.popleft()
        for v in matrix[u]:
            if color[v]==0:
#                print("{}->{}".format(u,v))
                distance[v]=distance[u]+1
                color[v]=1
                Q.append(v)
        color[u]=2
    
    return distance

def main():
    n=int(input())
    matrix = [[] for _ in range(n)]
    for i in range(n):
        lined = map(int,input().split())
#        print(lined)
        for j,pon in enumerate(lined):
            if j>=2:
                matrix[i].append(pon-1)
#    print(matrix)
    distance = bfs(matrix,n)
    for i,di in enumerate(distance):
        print("{} {}".format(i+1,di))

if __name__ == "__main__":
    main()



Measured memory_bytes: 6020
import math

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

x = [list(map(int, input().split())) for _ in range(n)]

answer = 0
for i in range(n):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (x[i][k] - x[j][k])**2
        ans = math.sqrt(ans)
        if ans.is_integer():
            answer += 1

print(answer)


Measured memory_bytes: 38384
from scipy.sparse import*
i=lambda:tuple(map(int,input().split()))
f=csgraph.dijkstra
n,m,l=i()
d=eval('[0]*-~n,'*-~n)
while m:a,b,c=i();d[a][b]=c;m-=1
d=f(f(d,0)<=l)
d[d>n]=0
for _ in'_'*i()[0]:print(d[i()]-1)

Measured memory_bytes: 19552
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    if(n >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
  int s;
  int m;
  int h;
  int tmp;
  scanf("%d\n",&s);
  tmp = s / 60;
  s = s % 60;
  m = tmp % 60;
  h = tmp / 60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

class Point{
public:
	ll x,y;
};

int main(){
	init();
	ll A,B;cin>>A>>B;
	cout<<B+(B-A)<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

string s;
string f;
int cnt;
int main(){
    cin>>s;
    f='a';
    REP(i,s.size()){
        if(f[0]!=s[i]){
            cnt++;
            f[0]=s[i];
        }
    }
    cout<<cnt-1;
    
    

    return 0;
}

Measured memory_bytes: 512
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let order_p l =
  let rec doit (x, y) = function
    | [] -> true
    | z::_ when x > z && y > z -> false
    | z::r when x < z && y > z -> doit (z, y) r
    | z::r when x > z && y < z -> doit (x, z) r
    | z::r when x < z && y < z -> doit (x, z) r || doit (z, y) r
    | _ -> false in
  doit (0, 0) l

let () =
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      let l = List.map int_of_string (split (read_line ()) ' ') in
      print_endline (if order_p l then "YES" else "NO");
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 1980
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        long a = sc.nextLong();
        long b = sc.nextLong();

        // 処理
        long out = -1;
        for(int i = 1; i <= 100 * 100; i++){
            if((long)(i * 0.08) == a && (long)(i * 0.1) == b){
                out = i;
                break;
            }
        }

        // 出力
        System.out.println(out);
    }

}

Measured memory_bytes: 23764
N = int(input())
marchd = {'M':set(), 'A':set(), 'R':set(), 'C':set(), 'H':set(),}
for _ in range(N):
  s = input().strip()
  if s[0] in marchd:
    marchd[s[0]].add(s)

print(len(marchd['M'])*len(marchd['A'])*len(marchd['R']) +
      len(marchd['M'])*len(marchd['A'])*len(marchd['C']) +
      len(marchd['M'])*len(marchd['A'])*len(marchd['H']) +
      len(marchd['M'])*len(marchd['R'])*len(marchd['C']) +
      len(marchd['M'])*len(marchd['R'])*len(marchd['H']) +
      len(marchd['M'])*len(marchd['C'])*len(marchd['H']) +
      len(marchd['A'])*len(marchd['R'])*len(marchd['C']) +
      len(marchd['A'])*len(marchd['R'])*len(marchd['H']) +
      len(marchd['A'])*len(marchd['C'])*len(marchd['H']) +
      len(marchd['R'])*len(marchd['C'])*len(marchd['H']))
  

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

int main(){
	int n;
	cin>>n;
	int a[16][16];
	for(int i=0;i<16;i++){
		for(int j=0;j<16;j++)
		 a[i][j]=-1;
	}
	 
	for(int i=1;i<=n;i++){
		int y;
		cin>>y;
		int a1,b1;
		for(int j=0;j<y;j++){
			cin>>a1>>b1;
			a[i][a1]=b1;
		}
	}
	int max=0;

	for(int i=0;i<(1<<n);i++){
		bool flag=true;
		int count=0;
		bool fg[n+1];
		for(int j=0;j<=n;j++)
		 fg[j]=false;
		for(int j=0;j<n;j++){
			
			if(i&(1<<j)){
				fg[j+1]=true;
			}
		}
		for(int j=1;j<=n;j++){
				
				if(fg[j]){
					count+=1;
				for(int k=1;k<=n;k++){
					if(a[j][k]==1){
						if(fg[k]==false){
							flag=false;
							break;
						}
					}
					else if(a[j][k]==0){
						if(fg[k]==true){
							flag=false;
							break;
						}
					}
				 }
				 //cout<<"1";
			}
			
	   }
	   if(flag){
	   
	  if(count>max)
	   max=count;
      }
   }
   cout<<max;
} 
			  
						
		


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

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

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;


    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
};


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

template<class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    int N;
    cin >> N;
    vector<int> B(N - 1);
    cin >> B;

    int ans = 0;
    ans += B[0];
    FOR(i, 1, N - 1) {
        ans += min(B[i - 1], B[i]);
    }
    ans += B[N - 2];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long int ll;

vector<int> g[100100];
int h[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		g[x].push_back(y);
		h[y]++;
	}
	stack<int> st;
	for(int i=0;i<n;i++){
		if(h[i]==0){
			st.push(i);
		}
	}
	vector<int> ans;
	while(st.size()){
		int i=st.top(); st.pop();
		ans.push_back(i);
		for(int j:g[i]){
			h[j]--;
			if(h[j]==0){
				st.push(j);
			}
		}
	}
	for(int i:ans){
		cout << i << endl;
	}
}


Measured memory_bytes: 6104
a,b,n=map(int, input().split())
cand1=(a*n)//b-a*(n//b)
x=n-n%b-1
cand2=0
if x>=0:
    cand2=(a*x)//b-a*(x//b)
cand1=max(cand2,cand1)
print(cand1)

Measured memory_bytes: 61892
using System;
using System.Linq;
using System.Collections.Generic;
namespace std
{
    class Test {
        static void Main(string[] args) {
           
         //   var input = Console.ReadLine().Split(' ');
            int n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split();
            var a = new List<KeyValuePair<char, char>>();
            var b = new List<KeyValuePair<char, char>>();
              
              
                foreach (var c in s) {//オブジェクト名、コレクション名
                    var t = new KeyValuePair<char, char>(c[0], c[1]);
                    a.Add(t);
                    b.Add(t);
                }
                a = a.OrderBy(x => x.Value).ToList();
                Print(a, n);
                Console.WriteLine("Stable");               
                SelectionSort(b, n);
                Print(b, n);
                Console.WriteLine(IsStable(a, b, n) ? "Stable" : "Not stable");
        }
        
         static void Print(List<KeyValuePair<char, char>> c, int n) {
             for (int i = 0; i < n; i++) {
                 Console.Write("{0}{1}",c[i].Key, c[i].Value);
                  if(i < n-1) Console.Write(" ");
             }
             Console.WriteLine("");
         }
         
         
        static void  SelectionSort(List<KeyValuePair<char, char>> a, int n) {
            int i, j, minj;
            for( i = 0; i < n; i++) {
                minj = i;
                for (j = i;  j < n; j++) {
                    if (a[j].Value < a[minj].Value) {
                        minj = j;
                    }
                }
                //swap
               if (i != minj) {
                    var tmp = a[i];
                    a[i] = a[minj];
                    a[minj] = tmp;
                }
            }
        }

        static bool IsStable(List<KeyValuePair<char, char>> a,
         List<KeyValuePair<char, char>> b, int n) {
        for (int i = 0; i < n; i++) {
          if (a[i].Key != b[i].Key) return false;
        }
        return true;
        }   
         


          
    }
}
 
    



Measured memory_bytes: 8292
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m,sum[100001],a[100000],b[100005]={},ans[100001];
int main(){
    scanf("%lld %lld",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i!=n-1){
            b[a[i]+2]--;
        }
        if(i!=0){
            b[a[i]+1]++;
            if(a[i]<a[i-1]){
                b[0]--;
            }
        }
    }
    sum[0]=b[0];
    for(int i=1;i<=m;i++){
        sum[i]=sum[i-1]+b[i];
    }
    for(int i=1;i<n;i++){
        sum[a[i]%m+1]+=(m+a[i]-a[i-1])%m-1;
    }
    ans[1]=0;
    for(int i=0;i<n-1;i++){
        ans[1]+=min(1+(a[i+1]+m-1)%m,(a[i+1]+m-a[i])%m);
    }
    for(int i=2;i<=m;i++){
        ans[i]=ans[i-1]+sum[i];
    }ans[0]=ans[1];
    for(int i=1;i<=m;i++){
        ans[0]=min(ans[0],ans[i]);
    }
    printf("%lld\n",ans[0]);
}

Measured memory_bytes: 3328
// #pragma GCC optimize ("O2")
// #pragma GCC target("avx2")
#include "bits/stdc++.h"
	
#define PI 3.141592653589793L
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// Use for file I/O;
#define FIN string _fname = "convention2"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define gsize(x) (int)((x).size())

using namespace std;

const char nl = '\n';

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
 
const ll inf = 1e9;
const ll inf2 = 1e18 + 99LL;
const ld inf3 = 1e14;
const ll mod = 1e9 + 7;
const ld eps = 1e-6;
 
const int logn = 19, maxn = 2e3+5, maxm = 1e5 + 5;

int main() {
	FAST;
	int n;
	cin >> n;
	vector<vector<ll>> dp(n, vector<ll>(4));
	dp[0][0] = 8;
	dp[0][1] = 1;
	dp[0][2] = 1;
	dp[0][3] = 0;
	for (int i = 1; i < n; i++) {
		dp[i][0] = (dp[i - 1][0] * 8ll) % mod;
		dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 9ll) % mod;
		dp[i][2] = (dp[i - 1][0] + dp[i - 1][2] * 9ll) % mod;
		dp[i][3] = (dp[i - 1][3] * 10ll + dp[i - 1][1] + dp[i - 1][2]) % mod;
	}
	cout << dp[n - 1][3];
}

Measured memory_bytes: 73268
from bisect import *
n = int(input())
dic = {}
dic2 = {}
box = []
for i in range(n):
    a, b, *c = input().split()
    if a == '0':
        insort_left(box, b)
        if b in dic:
            temp = dic[b]
            dic[b] = temp + [int(c[0])]
        else:
            dic[b] = [int(c[0])]
    elif a == '1':
        if b in dic:
            pri = []
            for i in dic[b]:
                pri.append(str(i))
            print("\n".join(pri))
    elif a == '2':
        if b in dic:
            del dic[b]
    else:
        L = bisect_left(box,b)
        R = bisect_right(box, c[0])
        while L<R:
            if box[L] in dic:
                for i in dic[box[L]]:
                    print(box[L], i)
            L = bisect_right(box, box[L])
        
        


Measured memory_bytes: 40140
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,b=0,n;
    string s,t;
    cin>>s;
    if(s[0]=='1') b++;
    if(s[1]=='1') b++;
    if(s[2]=='1') b++;
    cout<<b<<"\n";
    return(0);
}

Measured memory_bytes: 3596