akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int x; scan(x);
      Int total = 0;
      Int y = x;
      while( y != 0 ) {
         total += y % 10;
         y = y / 10;
      }
      puts((x % total == 0) ? "Yes" : "No");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int dp[n + 1][3];
    int a[n + 1], b[n + 1], c[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        dp[i][0] = dp[i][1] = dp[i][2] = 0;
    }
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for(int i = 2; i <= n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    return 0;
}


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

const int MOD = 1000000007;
int N, M;
int a[100010];
bool f[100010];
int dp[100010];

void _main() {
    cin >> N >> M;
    REP (i, M) {
        cin >> a[i];
        f[a[i]] = true;
    }
    dp[0] = 1;
    FOR (i, 1, N + 1) if (!f[i]) {
        if (!f[i - 1]) (dp[i] += dp[i - 1]) %= MOD;
        if (i - 2 >= 0 && !f[i - 2]) (dp[i] += dp[i - 2]) %= MOD;
    }
    cout << dp[N] << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int N,K;
	int l[51];
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++){
	    scanf("%d",&l[i]);
	}
	sort(l,l+N);
	int ans=0;
	for(int i=N-1;i>N-1-K;i--){
	    ans += l[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
s = input()
p = input()
len_s = len(s)
len_p = len(p)
ans = "No"
for i in range(len_s):
    match_count = 0
    for j in range(len_p):
        k = (i + j) % len_s
        if s[k] == p[j]:
            match_count += 1
        else:
            break
    if match_count == len_p:
        ans = "Yes"
        break
print(ans)



Measured memory_bytes: 5560
def show(A, n):
    for i in range(n):
        if i != n-1:
            print(A[i], end=' ')
        else:
            print(A[i])


def selection_sort(A, n):
    count = 0
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if A[min_j] > A[j]:
                min_j = j
        if min_j != i:
            A[i], A[min_j] = A[min_j], A[i]
            count += 1
    show(A, n)
    print(count)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    selection_sort(A, n)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, long>;

ll solve() {
    ll N, a, b, c, Q, K, x, y;
    cin >> N;
    vector<vector<pii>> G(N);
    for ( int i = 0; i < N-1; i++ ) {
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back(pii(b, c));
        G[b].push_back(pii(a, c));
    }
    cin >> Q >> K;
    vector<ll> dst(N, -1);
    function<void(int,int,ll)> dfs = [&](int v, int p, ll d) {
        dst[v] = d;
        for ( auto x : G[v] ) {
            if ( x.first == p ) continue;
            dfs(x.first, v, d + x.second);
        }
    };
    dst[K-1] = 0;
    dfs(K-1, -1, 0);

    vector<ll> X(Q), Y(Q);
    for ( int i = 0; i < Q; i++ ) {
        cin >> X[i] >> Y[i];
    }
    for ( int i = 0; i < Q; i++ ) {
        ll ans = dst[X[i]-1] + dst[Y[i]-1];
        cout << ans << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 18944
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var K = arr[0];
        var N = arr[1];
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var x = A[0] + K - A[^1];
        var y = Enumerable.Range(0, N - 1).Max(i => A[i + 1] - A[i]);
        var longest = x < y ? y : x;
        var answer = K - longest;
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 43720
import java.util.Scanner;

class Main {

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

        int S = sc.nextInt();

        int h = S/3600;
        int m = S%3600/60;
        int s =S%60;

        System.out.println(h+":"+m+":"+s);

        sc.close();

    }

}


Measured memory_bytes: 26288
import math
def ModFact(N,Mod):
    Num = 1
    for T in range(2,N+1):
        Num = (Num*T)%Mod
    return Num
  
N,M = (int(T) for T in input().split())
Mod = 10**9+7
if N==M:
    print((2*ModFact(N,Mod)*ModFact(M,Mod))%Mod)
elif N==M+1 or M==N+1:
    print((ModFact(N,Mod)*ModFact(M,Mod))%Mod)
else:
    print(0)

Measured memory_bytes: 9108
N = int(input())
A = [int(i) for i in input().split()]

left = 0
total = 0
xor = 0
ans = 0
for right in range(N):
    total += A[right]
    xor ^= A[right]
    while total != xor:
        total -= A[left]
        xor ^= A[left]
        left += 1
    ans += right - left + 1
    
print(ans)

Measured memory_bytes: 24584
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    // N　品物の数
    // M 割引券の枚数
    int N, M;
    cin >> N >> M;
    priority_queue<ll> A;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        A.push(tmp);
    }
    REP(i, M) {
        ll t = A.top();
        t = t / 2;
        A.pop();
        A.push(t);
    }
    ll res = 0;
    while(!A.empty()) {
        res += A.top();
        A.pop();
    }
    cout << res << endl;
    return 0;
}

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

int main() {

	int R;
	cin >> R;

	if (R < 1200) {
		cout << "ABC";
	}
	else if (R < 2800) {
		cout << "ARC";
	}
	else {
		cout << "AGC";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, m, h, k;

	while(cin >> n >> m >> h >> k) {
		if(n == 0 && m == 0 && h == 0 && k == 0) break;

		vector<int> cost(n);
		rep(i, n) cin >> cost[i];

		vector<P> p(m);
		rep(i, m) cin >> p[i].second >> p[i].first;
		sort(p.begin(), p.end());

		vector<int> id(n);
		rep(i, n) id[i] = i;

		rep(i, m) {
			swap(id[ p[i].second-1 ], id[ p[i].second]);
		}

		int ans = 0;
		vector<int> v(n);
		rep(i, n) {
			v[id[i]] = cost[i];
			if(id[i] < k) ans += cost[i];
		}

		int res = 0;
		for(int i = m-1; i >= 0; i--) {
			int a = id[ p[i].second-1];
			int b = id[ p[i].second];

			if(a < k && k <= b) {
				if(v[a] > v[b]) {
					res = max(res, v[a] - v[b]);
				}
			} else if(b < k && k <= a) {
				if(v[b] > v[a]) {
					res = max(res, v[b] - v[a]);
				}
			}

			swap(id[ p[i].second-1], id[p[i].second]);
		}

		cout << ans - res << endl;
	}

	return 0;
}

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

using std::begin;
using std::end;

int main() {
  int n;
  std::vector<int> v;
  std::cin >> n;
  for(int i{0}; i < n; ++i) {
    int t;
    std::cin >> t;
    v.push_back(t);
  }

  int cnt{0};
  for(int i{0}; i < n; ++i) {
    int min{i};
    for(int j{i}; j < n; ++j) {
      if(v[j] < v[min]) {
        min = j;
      }
    }
    if(i != min) {
      ++cnt;
      int t{v[i]};
      v[i] = v[min];
      v[min] = t;
    }
  }


  bool f{true};
  for(int e: v) {
    if(f) {
      f = false;
    } else {
      std::cout << ' ';
    }
    std::cout << e;
  }

  std::cout << std::endl << cnt << std::endl;

  return 0;
}



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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

    lli n;
    cin>>n;

    lli ans = INF;

    for(lli i=1;i*i<=n;i++){
        if(n%i==0){
            lli a = n/i;
            lli b = i;
            ans = min(a+b-2,ans);
        }
    }
    cout<<ans<<endl;

	return 0;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
//
const int N = 1e5+5; 

ll diff[N];

int main(){

	int n , q ;
	ll k ; 
	cin >> n >> k >> q ; 
	for(int i = 0 ; i < q ; i++ ){
		int a ; 
		cin >> a ; 
		diff[a+1]--; 
		diff[a]++; 
		diff[1]--;
	}
	for(int i = 1 ; i <= n ; i++ ){
		diff[i]+=diff[i-1]; 
	}
	for(int i = 1 ; i <= n ; i++ )
		cout << ((bool)(diff[i]+k>0)?"Yes":"No") << endl; 
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){


    FAST
//	PRECISE

ll x;
cin>>x;
x=(x-400)/200;

x=8-x;
cout<<x;


return 0;
 }
 

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

map<string, int> x;

ll f(int x){
  ll ans = x;
  return (ans * (ans-1)) / 2;
}

int main(void){
  int n;
  ll ans = 0;
  cin >> n;
  rep(i,n){
    string tmp;
    cin >> tmp;
    sort(all(tmp));
    x[tmp]++;
  }


  for(auto y: x){
    if(y.second != 1){
      ans += f(y.second);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11136
from collections import deque
from itertools import product
h, w = map(int, input().split())
si, sj = map(lambda x: int(x)-1, input().split())
gi, gj = map(lambda x: int(x)-1, input().split())
fld = ''.join([input()for _ in range(h)])
INF = 10**18


def to_v(i, j):
    return i*w+j


n = h*w
start = to_v(si, sj)
goal = to_v(gi, gj)


def generate_v2(v):
    i, j = divmod(v, w)
    it = [-2, -1, 0, 1, 2]
    for di, dj in product(it, repeat=2):
        x, y = i+di, j+dj
        if x < 0 or h <= x or y < 0 or w <= y:
            continue
        if (di, dj) in [(-1, 0), (1, 0), (0, -1), (0, 1), (0, 0)]:
            d = 0
        else:
            d = 1
        yield d, x*w+y


def bfs(init_v):
    next_v = deque([init_v])
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        for d, v2 in generate_v2(v):
            if fld[v2] == '#':
                continue
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            if d:
                next_v.append(v2)
            else:
                next_v.appendleft(v2)
    return dist


ans = bfs(start)[goal]
print(-1 if ans == INF else ans)


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

int main(){
  long long a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  long long p = abs(a - b);
  long long q = (v - w) * t;
  cout << (p <= q ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3520
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int h,w;
	int i,j,k;
	int q[53][53] = { 0 };
	char p[53][53];

	scanf("%d%d",&h,&w);
	for(i = 0; i < h; i++)	scanf("%s",&p[i + 1][1]);
	for(i = 1; i <= h; ++i){
		for(j = 1; j <= w; ++j){
			if(p[i][j] == '#'){
				for(k = -1; k <= 1; ++k){
					++q[i - 1][j + k];
					++q[i + 1][j + k];
				}
				++q[i][j - 1];
				++q[i][j + 1];
			}
		}
	}
	for(i = 1; i <= h; ++i){
		for(j = 1; j <= w; ++j){
			if(p[i][j] == '#')	printf("#");
			else	printf("%d", q[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
 
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
 
 
int main(){
	int d,n;
	cin>>d>>n;
	if(n==100)n=101;
	if(d==0){
		cout<<n<<endl;
	}else if(d==1){
		cout<<n*100<<endl;
	}else{
		cout<<n*10000<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;


int main(int argc, char* argv[]){
	int X;
	scanf("%d",&X);
	int Y = (X-400)/200;
	int kyu = 8-Y;
	printf("%d\n", kyu);
}


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

int main(){
int n,a,b;
 	cin >> n;
  a = n;
  if (n ==0) cout << "Yes" << endl;
  else{
  	for (int i=0; i<8; i++){
 	b += a%10;
  	a /= 10 ; 
  }
  if (n%b==0)
  cout << "Yes" << endl;
  else cout << "No" << endl;}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int A, B;
  cin >> A >> B;

  int ans = 0;
  if(A >= 13) ans = B;
  else if(A >= 6) ans = B/2;

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int c1, c5 ,c10, c50, c100, c500;
    cin>>c1 >>c5 >>c10>> c50>> c100>> c500;
    if(c1+ (c5*5) +(c10*10) +(c50*50)+ (c100*100) +(c500*500)>=1000)
        cout<<1<<endl;
    else
        cout<<0<<endl;
}

Measured memory_bytes: 1164
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{ n: usize,
            k: i32,
            x: [i32; n],
    }
    let ans: i32 = x.iter().map(|&x| 2 * std::cmp::min(x, (k - x))).sum();
    println!("{}", ans);
}


Measured memory_bytes: 4352
import static java.lang.System.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		out.println(Math.min(b / a, c));
		
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{   
    
    string str;
  
    //空白も含めて1行まるごとを文字列として受け取るためにはgetline関数を使う
    getline(cin,str);

    REP(i,(int)str.size()){
            
        if(islower(str[i])) printf("%c",toupper(str[i]));
        else if(isupper(str[i])) printf("%c",tolower(str[i]));
        else printf("%c",str[i]);  
        if(str[i]==EOF)break;
    }
    printf("\n");
}


Measured memory_bytes: 3108
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
min_costs = [float("inf") for n in range(loop)]
for i in range(loop):
    for j in range(loop):
        min_costs[j] = min(min_costs[j], cost[(i - j) % loop])
    answer = min(answer, sum(min_costs) + (magic_cost * (i) ) )
print(answer)

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

typedef struct{
  int parent;
  int right;
  int left;
  int sibling;
  int degree;
}BT;

BT bt[26];
int n;



int CH(int g){
  int a = 0,b = 0;
  if(bt[g].degree == 0)return 0;

  if(bt[g].right != -1) a = CH(bt[g].right)+1;

  if(bt[g].left != -1) b = CH(bt[g].left)+1;

  if(a>b)return a;

  else return b;

  
 }

int main(){
  int i,j,num,depth = 0;
 

  
  scanf("%d",&n);

  for(i=0;i<n;++i){
    bt[i].parent = -1;
    bt[i].sibling = -1;
    bt[i].degree = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d",&num);
    scanf("%d%d",&(bt[num].left),&(bt[num].right));

    if(bt[num].left != -1 &&bt[num].right != -1){
      bt[bt[num].left].parent = num;
      bt[bt[num].right].parent = num;
      bt[bt[num].left].sibling = bt[num].right;
      bt[bt[num].right].sibling = bt[num].left;
      bt[num].degree = 2;
    }
    else if(bt[num].left != -1){
      bt[bt[num].left].parent = num;
      bt[num].degree = 1;
    }
    else if(bt[num].right != -1){
      bt[bt[num].right].parent = num;
      bt[num].degree = 1;
    }
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, "
	   ,i,bt[i].parent,bt[i].sibling,bt[i].degree);

    num = i;
    while(bt[num].parent != -1){
      depth++;
      num = bt[num].parent;
    }
    printf("depth = %d, height = %d, ",depth,CH(i));
    depth = 0;
    
    if(bt[i].parent == -1) printf("root\n");
    else if(bt[i].left == -1 && bt[i].right == -1) printf("leaf\n");
    else printf("internal node\n");
  }
}



Measured memory_bytes: 2148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str L;
ll dp[100010][2];
int main(){
  cin>>L;
  int N=L.size();
  vi n;
  rep(i,N){
    n.pb(L[i]-'0');
  }
  fill(dp,0);
  dp[0][0]=1;
  rep(i,N){
    rep(j,2){
      rep(k,(j?2:n[i]+1)){
	dp[i+1][j||k<n[i]]=(dp[i][j]*(k+1)+dp[i+1][j||k<n[i]])%MOD;
      }
    }
  }
  ll res=(dp[N][0]+dp[N][1])%MOD;
  prin(res);
  return 0;
}


Measured memory_bytes: 2424
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const int mod = 1000000007;


int main(){
    string S;
    cin>>S;
    ll sz = S.size();
    ll right=0;
    ll left=0;
    ll num[sz]={0};
    for(ll i=0;i<sz;i++){
        if(S[i]=='R'){
            right++;
        }else if(S[i]=='L'){
            num[i-1]+=(right+1)/2;
            num[i]+=(right)/2;
            right=0;
        }
    }
    // for(ll i=0;i<sz;i++){
    //     cout<<num[i]<<" ";
    // }
    // cout<<endl;
    for(ll i=sz-1;i>=0;i--){
        if(S[i]=='L'){
            left++;
        }else if(S[i]=='R'){
            num[i+1]+=(left+1)/2;
            num[i]+=(left)/2;
            left=0;
        }
    }
    for(ll i=0;i<sz;i++){
        cout<<num[i]<<" ";
    }
    cout<<endl;
    
}


Measured memory_bytes: 1408
package main
import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
 
func nextInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

type Item struct {
  Price int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int {
  return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
  return pq[j].Price < pq[i].Price
}

func (pq PriorityQueue) Swap(i, j int) {
  pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n-1]
  *pq = old[0:n-1]
  return item
}

func (pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq, item)
}

func main() {
  sc.Buffer(make([]byte, 500000), 500000)
  sc.Split(bufio.ScanWords)
 
  n := nextInt()
  m := nextInt()
  
  as := make([]int, n)
  for i := 0; i < n; i++ {
    as[i] = nextInt()
  }
  priorityQueue := make(PriorityQueue, n, 1000*n)
  result := 0
  for i, a := range as {
    item := Item{}
    item.Price = a
    priorityQueue[i] = &item 
    result += a
  }
  heap.Init(&priorityQueue)
  
  for i := 0; i < m; i++ {
    item := heap.Pop(&priorityQueue).(*Item)
    newPrice := item.Price/2
    discountedPrice := item.Price - newPrice
    result -= discountedPrice
    newItem := Item{}
    newItem.Price = newPrice
    heap.Push(&priorityQueue, &newItem)
  }
  fmt.Println(result)
  
  
}

Measured memory_bytes: 32000
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

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

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

	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> b(m), c(m);
	vector<pair<ll, ll>> cb(m);
	rep(i, m) {
		cin >> b[i] >> c[i];
		cb[i].first = c[i];
		cb[i].second = b[i];
	}

	// 合計値
	// 小さいやつを消したい
	sort(allof(a));
	sort(allof(cb), greater<pair<ll, ll>>());

	int index = 0;
	bool end = false;
	rep(i, m) {
		rep(j, cb[i].second) {
			if (a[index] < cb[i].first) {
				a[index++] = cb[i].first;
			}
			else {
				end = true;
				break;
			}
			if (index >= n) {
				end = true;
				break;
			}
		}
		if (end) break;
	}

	ll sum = 0;
	rep(i, n) {
		sum += a[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 4224
include Math
EPS = 1e-2

loop do
  n = gets.to_i
  break if n == 0
  jewels = (1..n).map { gets.split.map(&:to_i) }

  max_num = 1
  (0..n-1).to_a.combination(2) do |i, j|
    x1, y1, r1, m1 = jewels[i]
    x2, y2, _, _ = jewels[j]
    t = atan2(y2 - y1, x2 - x1)
    shifted = jewels.map {|x, y, r, m| [x - x1, y - y1, r, m] }
    transformed = shifted.map {|x, y, r, m| [cos(-t) * x - sin(-t) * y, sin(-t) * x + cos(-t) * y, r, m] }
    x2, _, r2, m2 = transformed[j]

    [r1, r1 + m1].product([r2, r2 + m2]).each do |ar1, ar2|
      [1, -1].repeated_permutation(2) do |sign1, sign2|
        s = (ar1**2 + sign1 * ar1 * ar2) / x2.to_f
        next if ar1.abs < s.abs - EPS
        t = sign2 * sqrt([ar1 ** 2 - s ** 2, 0].max)

        num = transformed.count do |x, y, r, m|
          d = (s * x + t * y - ar1 ** 2).abs / ar1
          r - EPS <= d && d <= r + m + EPS
        end
        max_num = num if num > max_num
      end
    end
  end
  p max_num
end


Measured memory_bytes: 7492
import java.util.Scanner;

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

    double a = reader.nextDouble();
    double b = reader.nextDouble();
    double digC = Math.toRadians(reader.nextDouble());

    double S = a * b * Math.sin(digC) / 2;
    double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(digC));
    double L = a + b + c;
    double h = S * 2 / a;
    System.out.println(S + "\n" + L + "\n" + h);
  }
}

Measured memory_bytes: 28120
import heapq

N, M = map(int, input().split())
nums = list(map(int, input().split()))

nums = list(map(lambda x: -1*x, nums))

heapq.heapify(nums)

for _ in range(M):
    tmp = heapq.heappop(nums)
    heapq.heappush(nums, (-1)*(-tmp//2))

print(sum(list(map(lambda x: -1*x, nums))))

Measured memory_bytes: 14184
using System;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();

            // 金額nを取得
            int n = int.Parse(input);

            // 標準入力から1行取得
            input = Console.ReadLine();

            // 1円玉の枚数を取得
            int a = int.Parse(input);

            // nを500で割った余りがa以下である場合、支払うことができる
            if(n % 500 <= a)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>

int a[200000];
int g[200000];
int c[200000];

int gcd(int x, int y) {
    if(y == 0) return x;
    if(x < y) return gcd(y, x);
    return gcd(y, x % y);
}

int main(void) {
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);

    g[0] = a[0];
    for(int i=0; i<n-1; i++)
        g[i+1] = gcd(g[i], a[i+1]);

    c[n-1] = a[n-1];
    for(int i=n-1; i>0; i--)
        c[i-1] = gcd(c[i], a[i-1]);

    int m=0;
    for(int i=1; i<n-1; i++) {
        int k = gcd(g[i-1], c[i+1]);
        if(m < k) m = k;
    }
    if(m < c[1]) m = c[1];
    if(m < g[n-2]) m = g[n-2];

    printf("%d\n", m);
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
inline int nextInt(void){
	int res=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch<='9'&&ch>='0')(res*=10)+=ch-'0',ch=getchar();
	return res;
}
short stk[20],tail=0;
inline void putInt(int x){
	if(x==0){puts("0");return;}
	while(x)stk[++tail]=x%10,x/=10;
	while(tail)putchar('0'+stk[tail--]);
	puts("");
}
const int N=15,M=1005,INF=0x3f3f3f3f;
#define bitAt(x,y) ((x>>y)&1)
#define bitFill(x) ((1<<x)-1)
#define bitChg(x,y,z) (x&(~((1<<y)|(1<<z))))
int n,m,dis[N][N],dp[1<<16],cnt[N],que[N],tot=0,ans=0;
inline int DP(int bit){
	if(~dp[bit])return dp[bit];
	if(bit==0)return dp[bit]=0;
	dp[bit]=INF;
	for(int i=0;i<tot;i++)for(int j=0;j<tot;j++)
	if(i!=j&&bitAt(bit,i)&&bitAt(bit,j))
	dp[bit]=min(dp[bit],dis[que[i]][que[j]]+DP(bitChg(bit,i,j)));
	return dp[bit];
}
signed main(void){
	memset(dp,-1,sizeof(dp));
	memset(dis,0x3f,sizeof(dis));
	n=nextInt();m=nextInt();
	for(int i=1,x,y,w;i<=m;i++){
		cnt[x=nextInt()]++,cnt[y=nextInt()]++,ans+=(w=nextInt());
		dis[x][y]=dis[y][x]=min(dis[x][y],w);
	}
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
	dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for(int i=0;i<n;i++)if(cnt[i]&1)que[tot++]=i;
	putInt(ans+DP(bitFill(tot)));
}

Measured memory_bytes: 1348
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

#define mp(x, y) make_pair(x, y)
#define X first
#define Y second

using namespace std;

typedef pair<double, double> pdd;

/* 外積 */
template <typename T>
T cross_product ( T x1, T y1, T x2, T y2 )
{
	return ((x1 * y2) - (x2 * y1));
}

int main ( void )
{
	vector<pdd> v;
	pdd p;
	
	while (~scanf("%lf,%lf", &p.X, &p.Y))
	{
		v.push_back(p);
	}
	
	double sum = 0;
	
	for (int i = 1, size = v.size()-1; i < size; ++i)
	{
		int j = i+1;
		pdd a, b;
		a = mp(v[i].X - v[0].X, v[i].Y - v[0].Y);
		b = mp(v[j].X - v[0].X, v[j].Y - v[0].Y);
		sum += fabs(cross_product<double>(a.X, a.Y, b.X, b.Y));
	}
	
	printf("%.6lf\n", sum/2.0);
	
	return 0;
}

Measured memory_bytes: 1240
#include<iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    int cnt = 0;
    int ans = 0;
    if (s.length() == 1) { //1文字なら何もしない
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i < s.length(); i++) { //全て同じ文字なら何もしない
        if (s[i] != s[i - 1]) {
            break;
        }
        if (i == s.length() - 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < 26; ++i) { //全文字でそれに揃えるcostを計算
        string tmp = s;
        bool flg = false;
        int ss = (int)tmp.length(); //最後の文字を捨てていく
        while (1) {
            ss--; //下のforの前 最後の文字消してから全部同じか判定 caaab
            for (int j = 0; j < ss; ++j) { //全ての文字を1つ先の文字に
                if (tmp[j + 1] == 'a' + i) {
                    tmp[j] = 'a' + i;
                }
            }
            for (int k = 1; k < ss; ++k) { //全部同じ文字になったか
                if (tmp[k] != tmp[k - 1]) {
                    break;
                }
                if (k == ss - 1) {
                    flg = true;
                    break;
                }
            }
            cnt++;
            if (ss == 0) {
                flg = true;
                break;
            }
            if (flg) { //全ての文字が同じ or 文字列長0
                break;
            }
        } //while end
        if (i == 0) { //initialize
            ans = cnt;
        }
        if (cnt < ans) {
            ans = cnt;
        }
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}


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

int x, a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> x >> a;
	if(x < a) cout << 0 << "\n";
	else cout << 10 << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

int main(){
	string x;
	cin>>x;
	x[3] = '8';
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<string.h>

int main(void){
    int card[4][13] = {0} ;
    int i=0 ,j=0 ;
    int n=0 ,mem=0 ;

    char mark[100] ;
    int num ;

    scanf("%d",&n);
    for (i=0 ;i<n ;i++){
        scanf(" %s%d",mark,&num);

        if (strcmp(mark,"S")==0){
            mem=0;
        } else if (strcmp(mark,"H")==0){
            mem=1;
        } else if (strcmp(mark,"C")==0){
            mem=2;
        } else if (strcmp(mark,"D")==0){
            mem=3;
        }

        card[mem][num-1]=1;
    }

    for (i=0 ;i<4 ;i++){
        for (j=0 ;j<13 ;j++){
            if (card[i][j]==0){
                if (i==0){
                    printf("S ""%d\n",j+1);
                } else if (i==1){
                    printf("H ""%d\n",j+1);
                } else if (i==2){
                    printf("C ""%d\n",j+1);
                } else if (i==3){
                    printf("D ""%d\n",j+1);
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int x, y;
	cin >> x >> y;

	if (y >= x) {
		if ((x >= 0 && y >= 0) || (x <= 0 && y <= 0)) {
			cout << y - x << "\n";
		} 
		else if (x < 0 && y >= 0) {
			if (abs(x) > y) {
				cout << - y - x + 1 << "\n";
			} else {
				cout << 1 + y - abs(x) << "\n";
			}
		}
	} else {
		if (x < 0 && y < 0) {
			cout << min(1 + abs(y) - x, 2 + abs(y) - abs(x)) << "\n";
		}
		else if (x >= 0 && y >= 0) {
			cout << min(1 + y + x, 2 - y + x) << "\n";
		} else {
			if (y >= -x) {
				cout << 1 + y + x << "\n";
			} else {
				cout << 1 + abs(y) - x << "\n";
			}
		}
	}

	return 0;

}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int H, W;
vector<string> S;
vector<vector<int>> dist;
int gx, gy, sx, sy;
int ans = 0;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void bfs(){
  REP(i, H){
    REP(j, W){
      dist[i][j] = -1;
    }
  }
  queue<pair<int, int>> que;
  que.push({sy, sx});
  dist[sy][sx] = 0;
  while(!que.empty()){
    int x, y;
    tie(y, x) = que.front();
    if(y == gy && x == gx){
      ans = max(ans, dist[y][x]);
      return;
    }
    que.pop();
    REP(i, 4){
      int nx = x + dx[i], ny = y+dy[i];
      if(nx < 0 || W <= nx || ny < 0 || H <= ny || dist[ny][nx] != -1 || S[ny][nx] == '#') continue;
      dist[ny][nx] = dist[y][x] + 1;
      que.push({ny, nx});
    }
  }
}

int main(){
  cin >> H >> W;
  S.resize(H);
  REP(i, H){
    cin >> S[i];
  }
  dist.resize(H, vector<int>(W, 0));
  REP(i, H){
    REP(j, W){
      if(S[i][j] == '#') continue;
      REP(k, H){
        REP(l, W){
          if(S[k][l] == '#') continue;
          gx = l, gy = k, sx = j, sy = i;
          bfs();
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int N;
    cin >> N;
    set<string> items;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        items.insert(s);
    }
    cout << items.size() << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 19140
s = list(input())
a = 0; z = 0
for i in range(len(s)):
    if s[i] == "A":
        a = i
        break

for i in range(len(s)):
    if s[len(s)-i-1] == "Z":
        z = len(s)-i-1
        break

print(z-a+1)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

struct drink {
  i64 money, total;
};

bool comp(drink &a, drink &b) {
  if (a.money == b.money) {
    return a.total > b.total;
  } else {
    return a.money < b.money;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i32 n, m;
  cin >> n >> m;
  vi64 a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<drink> drinks(n);
  rep(i, n) {
    drinks[i].money = a[i];
    drinks[i].total = b[i];
  }
  sort(all(drinks), comp);
  i64 ans = 0;
  i32 i = 0;
  while (m > 0) {
    if (drinks[i].total <= m) {
      ans += drinks[i].money * drinks[i].total;
      m -= drinks[i].total;
    } else {
      ans += drinks[i].money * m;
      m = 0;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
n = int(input())
a = list(map(int, input().split()))

from heapq import heappush, heappop,heappushpop,heapify
hq1 = a[:n]
now=sum(hq1)
heapify(hq1)
lis1=[now]
for k in range(n,2*n):
    now+=a[k]
    p=heappushpop(hq1,a[k])
    now-=p
    lis1.append(now)

a.reverse()
hq2=[]
for i in range(n):
    hq2.append(-a[i])
now=sum(hq2)
heapify(hq2)
lis2=[now]
for k in range(n,2*n):
    now-=a[k]
    p=heappushpop(hq2,-a[k])
    now-=p
    lis2.append(now)
lis2.reverse()

ans=-float("inf")
for i in range(len(lis1)):
    num = lis1[i]+lis2[i]
    ans=max(ans,num)
print(ans)

Measured memory_bytes: 123280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  int tar=1;
  for(int i=0;i<N;i++){
    if(A[i]==tar) tar++;
  }

  if(tar==1) cout<<-1<<endl;
  else cout<<N-tar+1<<endl;

  return 0;
}


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

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  bool exist = false;
  for(int i=0; i<= 100; i++){
    if((a*i % b)==c){
    	 exist = true;
    } 
  }
  
  if(exist) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	int N, P, A;
	unsigned long long ans = 0;
	bool isAllEven = true;
	cin >> N >> P;

	for (int i = 0; i < N; i++)
	{
		cin >> A;
		if (A % 2 == 1)
			isAllEven = false;
	}

	cout << setprecision(30) << endl;
	if (isAllEven)
	{
		if (P)
			cout << 0 << endl;
		else
			cout << pow(2, N) << endl;
	}
	else
		cout << pow(2, N - 1) << endl;
	
	return 0;
}


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

int main()
{
    std::vector<int> array_mount;

    for ( int i = 0; i < 10; i++ )
    {
        int tmp = 0;
        std::cin >> tmp;
        array_mount.push_back(tmp);
    }

    std::sort( array_mount.begin(), array_mount.end(), std::greater<int>() );

    for ( int i = 0; i < 3; i++ )
    {
        std::cout << array_mount[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3140
def main():
    n = int(input())
    lr = []
    for i in range(n):
        l, r = map(int, input().split())
        lr.append((l, r))

    ans = 0
    for s in lr:
        l, r = s
        ans += (r - l) + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import math

N,D=map(int,input().split())
Z=[[int(x) for x in input().split()] for y in range(N)]

ans=0
for i in range(N):
  for j in range(i+1,N):
    cnt=0
    for k in range(D):
      cnt += (Z[i][k]-Z[j][k])**2
    cnt=math.sqrt(cnt)
    if cnt.is_integer():
      ans+=1
      
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a, b, c, d;
  a = N / 1000;
  b = (N - 1000 * a) / 100;
  c = (N - 1000 * a - 100 * b) / 10;
  d = N - 1000 * a - 100 * b - 10 * c;
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    string st[n];
    for(int i=0;i<n;i++)
        cin >> st[i];
    vector <pair <int,int> > v;
    for(int i=0;i<n;i++){
        string x="";
        for(auto ch:st[i]){
            if(ch=='(')x+=ch;
            else{
                if(x.size() and x.back()=='(')
                    x.pop_back();
                else x+=ch;
            }
        }
        int a=0,b=0;
        for(auto ch:x){
            if(ch=='(')b++;
            else a--;
        }
        if(a or b)v.push_back({a,b});
    }
    sort(v.begin(),v.end(),[&](auto x,auto y){
        int a=x.f+x.s,b=y.f+y.s;
        if(a*b>0){
            if(a>0)return x.f>y.f;
            else return x.s>y.s;
        }
        else return a>b;
    });
    int sum=0,ok=1;
    for(auto &i:v){
        for(auto j:{i.f,i.s}){
            sum+=j;
            if(sum<0)ok=0;
        }
    }
    if(sum==0 and ok)cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 50968
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
using namespace std;

template <class T>
class _Point{
public:
	T x;
	T y;
	_Point(){}
	_Point(T _x, T _y) :x(_x), y(_y){}
	_Point(const _Point & v) :x(v.x), y(v.y){}

	const _Point operator + (const _Point & v)
	{
		return _Point(x+v.x,y+v.y);
	}
	const _Point operator - (const _Point & v)
	{
		return _Point(x - v.x, y - v.y);
	}
	T abs() const {
		return sqrt(x*x + y*y);
	}
	_Point unit() const{
		T len = abs();
		return _Point(x / len, y / len);
	}
	T operator*(const _Point &v) const
	{
		return x * v.x + y * v.y;
	}
	const _Point operator*(const T &len) const
	{
		return _Point(len * x, len * y);
	}
};
typedef double R;
typedef _Point<R> Point;
typedef Point Vector;

int main(){
	std::istream & c_in = cin;

	Point p, p1, p2;
	c_in >> p1.x >> p1.y >> p2.x >> p2.y;
	Vector P12(p2 - p1);
	Vector e12(P12.unit());

	int q;
	c_in >> q;
	for (int i = 0; i < q; ++i)
	{
		Point p;
		c_in >> p.x >> p.y;
		p = p - p1;
		R projection = p*e12;
		Vector b(projection*(e12.x), projection*(e12.y));
		Point X(p1 + b);
		cout << fixed << setprecision(10) << X.x << " " << X.y << endl;
	}
}

Measured memory_bytes: 1296