akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  int a,d=0,c,e,f;
  cin>>a;
  vector<int> b(a);
for(int i=0;i<a;i++){
  cin>>b.at(i);
}
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  for(int x=0;x<a-2;x++){
    for(int y=x+1;y<a-1;y++){
      for(int z=y+1;z<a;z++){
        if(b.at(x)<b.at(y)+b.at(z))d++;
           else break;
      }
    }
  }
  cout<<d;
}

Measured memory_bytes: 384
#!/usr/bin/env python
# coding: utf-8

def readInt():
    return int(input())

def readList():
    return list(input().split())

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

def main():
    s = input()

    # BC->dに置き換え
    s2 = ""
    i = 0
    while i < len(s)-1:
        if s[i] == 'B' and s[i+1] == 'C':
            s2 += 'd'
            i += 1
        elif s[i] == 'A':
            s2 += 'a'
        else:
            s2 += s[i]
        i += 1
    ans = 0
    na = 0
    for c in s2:
        if c != 'a' and c != 'd':
            na = 0
            continue
        if c == 'a':
            na += 1
            continue
        ans += na
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3500
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_NTL_1_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadInt();

            var ans = ModPow(nm[0], nm[1], 1000000007);

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }

        /// <summary>
        /// a^n (mod p)
        /// nが非常に大きい時に有効
        /// </summary>
        /// <param name="a"></param>
        /// <param name="n"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static long ModPow(long a, long n, long p)
        {
            if (n == 1) return a % p;
            if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p;

            long t = ModPow(a, n / 2, p);
            return (t * t) % p;
        }
    }
}



Measured memory_bytes: 18452
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    print("".join(["x" for _ in range(len(_S()))]))

main()



Measured memory_bytes: 27172
from collections import deque
H,W=map(int,input().split())
c=list(map(int,input().split()))
d=list(map(int,input().split()))
s=[list(input()) for _ in range(H)]
INF=10000000
dp=[[INF for _ in range(W)] for _ in range(H)]

def walk_bfs(y,x,v):
  # 歩ける範囲で歩き潰す
  dp[y][x] = v
  path = deque()
  path.append([y,x])
  ret = deque()
  while path:
    y,x = path.popleft()
    ret.append([y,x])
    for i,j in ((0,1),(0,-1),(1,0),(-1,0)):
      if not (0 <= y+i < H and 0 <= x+j < W):
        continue
      if s[y+i][x+j] == '#':
        dp[y+i][x+j] = -1
      elif dp[y+i][x+j] == INF:
        dp[y+i][x+j] = v
        path.append([y+i,x+j])
  return ret

def warp_bfs():
  # ワープ回数でbfsとる
  deq = walk_bfs(c[0]-1,c[1]-1,0)
  while deq:
    y,x = deq.popleft()
    for yi in range(max(0,y-2),min(H,y+3)):
      for xi in range(max(0,x-2),min(W,x+3)):
        if s[yi][xi]=='#':
          dp[yi][xi] = -1
          continue
        if dp[yi][xi]==INF:
          deq.extend(walk_bfs(yi,xi,dp[y][x]+1))

warp_bfs()
ans = dp[d[0]-1][d[1]-1]
if 0<= ans < INF:
  print(ans)
else:
  print(-1)
#print(dp)

Measured memory_bytes: 148068
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;
typedef long long ll;

int c[10][10];
int a[202][202];

int main()
{
 	ios_base::sync_with_stdio(0);
 	int h, w;
 	cin >> h >> w;
 	for(int i=0; i<10; i++) {
 		for(int j=0; j<10; j++) {
 			cin >> c[i][j];
 		}
 	}
 	
 	for(int i=0; i<10; i++) {
 		for(int j=0; j<10; j++) {
 			for(int k=0; k<10; k++) {
 				for(int l=0; l<10; l++) {
 					c[j][k] = min(c[j][k], c[j][l] + c[l][k]);
 				}
 			}
 		}
 	}
	
	ll res = 0;
	
 	for(int i=0; i<h; i++) {
 		for(int j=0; j<w; j++) {
 			cin >> a[i][j];
 			if(a[i][j] != -1) {
 				res += c[a[i][j]][1];
 			}
 		}
 	}
 	cout << res;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
#define fs(i, x, y) for(int i = x;i >= y;i--)
using namespace std;
typedef long long ll;
ll n, d[100010], v[100010], mod = 998244353, ans;
int main() {
    scanf("%lld", &n);
    ff(i, 1, n)
    scanf("%lld", &d[i]);
    int pan = 1, num = 0;
    if(d[1] != 0)
        pan = 0;
    sort(d + 1, d + 1 + n);
    ff(i, 1, n) {
        v[d[i]]++;
        if(d[i] < num);
        else if(d[i] == num)
        num++;
        else {
            pan = 0;
            break;
        }
    }
    if(d[2] == 0 && n >= 2) pan = 0;
    if(pan == 0);
    else {
        ans = 1;
        ff(i, 2, n) {
            ans = ans * v[d[i] - 1] % mod;
        }
    }
    printf("%lld", ans);
    return  0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  string s;
  cin >> s;
  ll k;
  cin >> k;

  int n = s.length();

  int i = 0;
  while(i < n && i < k - 1 && s[i] == '1'){
    ++i;
  }

  if(i == n) cout << 1 << endl;
  else cout << s[i] << endl;

  return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,m,ans=0; cin>>n>>m;
    vector <int> sw[m],p(m);
    for (int i=0;i<m;i++){
        int k; cin>>k;
        sw[i].resize(k); 
        for (int l=0;l<k;l++) cin>>sw[i][l],sw[i][l]--;
    }
    for (int &i: p) cin>>i; 
    for (int i=0;i<(1<<n);i++){
        bool ok=true;
        for (int j=0;j<m;j++){
            int c=0;
            for (int &k: sw[j]){
                if ((i>>k)&1) c++;
            }
            if (c%2 != p[j]) ok=false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3584
import math

a, b, h, m = map(int, input().split())
tansin = h * 30 + m * 0.5
# tansin = min(tansin, 360 - tansin)
tyousin = m * 6

if tansin > 360:
    tansin = tansin - 360
if tyousin > 360:
    tyousin = tyousin - 360
# print(tansin)
# print(abs(tansin - tyousin))
rad = math.radians(abs(tansin - tyousin))
c = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(math.sqrt(c))


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

int main()
{
  int N,M,L,R,min_counter,max_counter,x;
  cin >> N >> M;

  min_counter = 0;
  max_counter = N;
  for(int i = 0;i < M;i++)
  {
    cin >> L >> R;
    if (min_counter <= L)
      min_counter = L;
    if (max_counter >= R)
      max_counter = R;
  }
  x = max_counter - min_counter + 1;
  if (x > 0)
    cout << x << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    if (s.substr(5, 2) == "01" || s.substr(5, 2) == "02"|| s.substr(5, 2) == "03" || s.substr(5, 2) == "04") cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

Measured memory_bytes: 256
import math
#import time
def gcd(a,b,c):
    return math.gcd(a,math.gcd(b,c))
#time1=time.time()
K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                ans+=gcd(i,j,k)
            elif i==j or i==k or j==k:
                ans+=3*gcd(i,j,k)
            else:
                ans+=6*gcd(i,j,k)
#time2=time.time()
print(ans)
#print(time2-time1)

Measured memory_bytes: 9152
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

//ここから編集する

int main() {
    ll k;
    ll m;
    cin >> k;
    ll amari = k % 50;
    if (amari == 0) {
        m = k / 50;
    } else {
        m = k / 50 + 1;
    }

    if (k == 0) {
        cout << 4 << endl;
        cout << "3 3 3 3" << endl;
        return 0;
    }
    cout << 50 << endl;
    cout << (50 - 1) + m << " ";
    for (int i = 1; i < 50; i++) {
        if (i != amari)cout << (50 - i - 1) + m;
        else cout << (50 - i - 1) + m - 1;
        if (i - 1 != 49) cout << " ";
    }

//    cout << 50 << endl;
//    cout << (50 - 0) + m << " ";
//    for (int i = 1; i < 50; i++) {
//        if (i != amari)cout << (50 - i) + m;
//        else cout << (50 - i) + m - 1;
//        if (i - 1 != 49) cout << " ";
//    }

    return 0;
}

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


int main(){
	int a,b;
	cin >> a >> b;
	if(a==1) a+=15;
	if(b==1) b+=15;
	if(a>b) cout << "Alice" << endl;
	else if(a<b) cout << "Bob" << endl;
	else cout << "Draw" << endl;


	return 0;
}

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

template<typename T>
T get_value(std::istream& is);

int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  auto first {s.find('A')};
  auto end {s.rfind('Z')};
  cout << end - first + 1 << '\n';

  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int N = sc.nextInt();

			String S = sc.next();
			String T = sc.next();

			char[] s = S.toCharArray();
			char[] t = T.toCharArray();

			char[] c = new char[2 * N];
			for (int i = 0; i < N; i++) {
				c[2 * i] = s[i];
				c[2 * i + 1] = t[i];
			}

			System.out.println(new String(c));

		}
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;

char d[51][51];

int main() {
    string s;
    cin >> s;
    set<char>st;
    rep(i,s.size()) st.insert(s[i]);
    if(st.size()==26){
        cout <<"None" <<endl;
        return 0;
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    string t;
    for(char c = 'a';c<='z';++c){
        t.push_back(c);
    }
    rep(i,s.size()){
        if(s[i]!=t[i]){
            cout << t[i]<<endl;
            return 0;
        }       
    }
    cout << t[s.size()] <<endl;
}

Measured memory_bytes: 512
import sys
read = sys.stdin.read
from collections import Counter
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ac = Counter(a)
    com_base = {}
    for i in ac:
        com_base[i] = ac[i] * (ac[i] - 1) / 2
    sum_combase = sum(com_base.values())
    for ae in a:
        r = sum_combase - com_base[ae] + ((ac[ae] - 1) * (ac[ae] - 2) / 2)
        print(int(r))

if __name__ == '__main__':
    main()

Measured memory_bytes: 36500
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long a = 0;
	long long b = 0;
	while(cin >> a >> b)
	{
		long long GCD = 0;
		long long LCM = 0;
		if(a < b)
			swap(a,b);
		long long temp = a * b;
		while(a % b != 0)
		{
			long long t = a % b;
			a = b;
			b = t;
		}
		LCM = b;
		GCD = temp / LCM;
		cout << LCM << " " << GCD <<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n;
    cin>>n;
    map<int,int> mp;
    vector<int> ar(n);
    int sum=0;
    for(auto &i:ar)
    {
        cin>>i;
        sum+=i;
        mp[i]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int a,b;
        cin>>a>>b;
        if(!mp.count(a))
        {
            cout<<sum<<"\n";
            continue;
        }
        int old=mp[a]*a;
        mp[b]+=mp[a];
        sum=sum-old+mp[a]*b;
        mp.erase(a);
        cout<<sum<<"\n";
    }
}
int32_t main()
{
    //_READ
    _FAST
    int t;
    t=1;
    while(t--)
        solve();
    
    
    return 0;
}

Measured memory_bytes: 7948
fun main(args: Array<String>) {
        val s = readLine()!!.toString()

        val a = s.substring(0, (s.length - 1) / 2)
        val b = s.substring(((s.length + 3) / 2) - 1, s.length)

        if (s == s.reversed() && a == a.reversed() && b == b.reversed()) {
            println("Yes")
            return
        }
        println("No")
    }


Measured memory_bytes: 33712
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <complex>

using namespace std;
typedef long long ll;


typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define re(i,a,b) for(i=a;i<=b;i++);
#define end return 0;

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans=0;
ll a,b,c,d,e,h,w;
ll x[100005],y[100005],z[100005];
ll dp[1005][1005];
ll ban[1005][1005];

int main(){
    cin>>n>>a>>b;
    for(i=0;i<n;i++){
        cin>>x[i];
    }
    for(i=0;i<n-1;i++){
        if((x[i+1]-x[i])*a>b){
            ans+=b;
        }else{
            ans += (x[i+1]-x[i])*a;
        }
    }
    
    p(ans);
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>

using namespace std;

int main(void){

  int X, Y;
  int XX, YY, a, b;

  cin >> X >> Y;

  XX = X * 2;
  YY = Y / 2;

  a = XX - YY;
  b = YY - X;

  if(a>=0 && b>=0 && X==a+b && Y==2*a+4*b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
 
int main(){
  ll n,x;
  cin >> n >> x;
  ll a[100100];
  memset(a,0,sizeof(a));
  ll sum;ll result=0;
  for ( int i = 0 ; i < n ;i++){
  cin >> a[i];
  }
  if ( a[0] > x ) {
		result += a[0] - x;
		a[0] = x;
	}
	sum = a[0];
	for ( int i = 1 ; i < n ; i++){
		sum += a[i];
		if (sum > x){
			result += sum-x;
			a[i] -= sum-x;
			sum = x;
		}
		sum -= a[i-1];
	}
	cout << result;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		long d;
		n = scan.nextInt();
		d = scan.nextLong();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			long x,y;
			x = scan.nextLong();
			y = scan.nextLong();
			if (x*x+y*y <= d*d) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 59760
import heapq

N = int(input())
a = [int(i) for i in input().split()]

hq = a[0: N]
left_max = [sum(hq)]
heapq.heapify(hq)
for i in range(N):
    left_max.append(left_max[i] + a[N + i] - heapq.heappushpop(hq, a[N + i]))

hq = [-i for i in a[2 * N: 3 * N]]
right_min = [-sum(hq)]
heapq.heapify(hq)
for i in range(N):
    right_min.append(right_min[i] + a[2 * N - i - 1] + heapq.heappushpop(hq, -a[2 * N - i - 1]))

ans = -100000000000000
for i in range(N + 1):
    ans = max(ans, left_max[i] - right_min[N - i])

print(ans)

Measured memory_bytes: 123408
n, m = map(int, input().split())

x = 10**9+7

if abs(n-m) >= 2:
  print(0)
  exit()
  
import math
if n == m:
  print((2*math.factorial(n)*math.factorial(m))%x)
else:
  print((math.factorial(n)*math.factorial(m))%x)





Measured memory_bytes: 54768
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
	cin>>n;
	int c=0;
	for(int i=0;i<n;++i){
		int a,b;
		cin>>a>>b;
		if(a==b){
			++c;
			if(c>2){
				cout<<"Yes"<<endl;
				return 0;
			}
		}else{
			c=0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;
template <typename T> void print(T vec) {for(auto d: vec) cout<<d<<' ';cout<<'\n';}
template<typename T> void print2D(T mat) {for(auto vec:mat) print(vec);}



void dfs(vector<vector<int>> & Graph, vector<bool> &visited, vector<int> &dp, int node) {
    visited[node] = 1;
    for(int d : Graph[node]) {
        if(!visited[d]) {
            dfs(Graph, visited, dp, d);
        }
        dp[node] = max(dp[node], 1 + dp[d]);
    }
}



int main() {
    int n, m;
    cin>>n>>m;
    vector<vector<int>> A(n + 1);
    int x, y;
    for(int i = 0; i< m;i++) {
        cin>>x>>y;
        A[x].push_back(y);
    }
    vector<int> dp(n+1, 0);
    vector<bool> visited(n+ 1, 0);
    for(int i = 1; i <= n; i++) {
        dfs(A, visited, dp, i);
    }
    cout<<*max_element(dp.begin(), dp.end())<<"\n";
    // print(dp);
    return 0;
}

Measured memory_bytes: 9472
#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

int main(){
    int N;
    int K;
    int i;
    ULL *H;
    ULL sum = 0;
    cin >> N >> K;
    H = new ULL[N];
    for(i=0;i<N;i++){
        cin >> H[i];
    }
    sort(H,H+N, std::greater<ULL>());
    for(i=K;i<N;i++){
        sum += H[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
n = int(input())

list1 = [[0 for k in range(10)] for l in range(3)]
list2 = [[0 for k in range(10)] for l in range(3)]
list3 = [[0 for k in range(10)] for l in range(3)]
list4 = [[0 for k in range(10)] for l in range(3)]


for i in range(n):
    b,f,r,v = map(int,input().split())
    if b == 1:
        list1[f-1][r-1] += v
    elif b == 2:
        list2[f-1][r-1] += v        
    elif b == 3:
        list3[f-1][r-1] += v        
    elif b == 4:
        list4[f-1][r-1] += v

for i in range(3):
    for j in range(10):
        print(' {0}'.format(list1[i][j]),end='')
    print()

print('####################')
for i in range(3):
    for j in range(10):
        print(' {0}'.format(list2[i][j]),end='')
    print()    

print('####################')
for i in range(3):
    for j in range(10):
        print(' {0}'.format(list3[i][j]),end='')
    print()

print('####################')
for i in range(3):
    for j in range(10):
        print(' {0}'.format(list4[i][j]),end='')
    print()











Measured memory_bytes: 5632
num_mountain = int(input())
mountains = list(map(int, input().split()))
ans = 1

for my_index in range(num_mountain):
    for opp_index in range(my_index):
        if mountains[opp_index] > mountains[my_index]:
            break
        if my_index - opp_index == 1:
            ans += 1
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

bool ch[100010];
ll w[100010];
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<k;i++){
		ll x;string s;
		cin>>x>>s;
		x--;
		if(ch[x]){
			continue;
		}
		else{
			if(s=="AC"){
				ch[x]=true;
			}
			else{
				w[x]++;
			}
		}
	}
	ll cnt1,cnt2;
	cnt1=cnt2=0;
	for(ll i=0;i<n;i++){
		if(ch[i]){
			cnt1++;
			cnt2+=w[i];
		}
	}
	cout << cnt1<<" "<<cnt2;
	// your code goes here
	return 0;
}

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

int x = 0;
int y = 0;
int a = 0;
int xx =0;
int yy = 0;
cin >> x >> y;

if (x == 1 && y == 1) {
  a = 400000;
}
if (x == 1){
  xx = 300000;
}
if (x == 2){
  xx = 200000;
}if (x == 3){
  xx = 100000;
}if (y == 1){
  yy = 300000;
}if (y == 2){
  yy = 200000;
}if (y == 3){
  yy = 100000;
}

cout << xx + yy + a << endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;
int main()
{
 hs;
 ll a,b;
 cin>>a>>b;
 ll sum=a+b;
 if(sum%2==0)
    cout<<sum/2<<endl;
 else
    cout<<"IMPOSSIBLE"<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int i;
  int len,b;
  char aa[100],bb[100],cc[100];
  int ia,ib,ic;
//  scanf("%s %s",&aa,&bb);
//    printf("aa:%s bb:%s\n",aa,bb);
  scanf("%d %d %d",&ia,&ib);
//    printf("aa:%d bb:%d\n",ia,ib);
	if(ia > 10){
		printf("%d\n",ib);
      
    }
  	else{
		printf("%d\n",ib+100*(10-ia));
    }

  return 0;

}

Measured memory_bytes: 128
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {
    // static final long MOD = 1000000007;

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

        int a, b, c, d;
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();
        d = scanner.nextInt();

        int ans = Math.max(a * b, c * d);

        System.out.println(ans);


    }





}




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

typedef long long ll;
const int maxn = 100010;
int n; ll a[maxn];
vector<int> G[maxn];

ll dfs(int v, int f) {
    if (G[v].size() == 1) return a[v];
    ll sum = 0;
    vector<ll> V;
    for (int u : G[v]) if (u ^ f) {
        ll t = dfs(u, v);
        sum += t, V.push_back(t);
    }
    ll ub = sum - a[v];
    if (ub < 0) printf("NO\n"), exit(0);
    for (ll x : V) {
        ll t = min(x, sum - x);
        if (t + (sum - x - t) / 2 < ub) printf("NO\n"), exit(0);
    }
    a[v] -= ub, sum -= ub * 2;
    if (a[v] < 0) printf("NO\n"), exit(0);
    if (!f && sum) printf("NO\n"), exit(0);
    return sum;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    if (n == 2) {
        printf("%s\n", a[1] == a[2] ? "YES" : "NO"), exit(0);
    }
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        if (G[i].size() > 1) { dfs(i, 0); break; }
    }
    printf("YES\n");
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) {
    par = vector<int>(n);
    siz = vector<int>(n, 1);
    rep(i, n) {
      par[i] = i;
    }
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
  }

int size(int x) {
    return siz[root(x)];
  }
};

int main() {
  int n,k,l;
  cin>>n>>k>>l;
  UnionFind road(n), rail(n);
  rep(i, k) {
    int a,b;
    cin>>a>>b;
    a--; b--;
    road.unite(a,b);
  }
  rep(i, l) {
    int a,b;
    cin>>a>>b;
    a--; b--;
    rail.unite(a,b);
  }
  // Aのroadかrailでの根とBのroadかrailでの根が一致していれば繋がっている
  map<pair<int, int>, int> v;
  rep(i, n) {
    v[{road.root(i), rail.root(i)}]++;
  }
  rep(i, n) {
    cout << v[{road.root(i), rail.root(i)}] << " ";
  }
}


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

using namespace std;  

const int maxn = 1e5 + 10;

int n;
vector<int> e[maxn];
long long a[maxn];
bool dfs(int x, int fa) {
	if(e[x].size() == 1) return true;
	long long sum = 0, mx = 0;
	for(auto &it : e[x]) {
		int v = it;
		if(v == fa) continue;
		if(!dfs(v, x)) return false;
		sum += a[v];
		mx = max(mx, a[v]);
	}
	mx = min(sum - mx, sum / 2);
	long long tmp = sum - a[x];
	if(tmp < 0 || tmp > mx) return false;
	a[x] -= tmp;
	if(x == fa) return a[x] == 0;
	return true;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	for(int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	if(n == 2) {
		a[1] == a[2] ? printf("YES\n") : printf("NO\n");
		return 0;
	}
	int pos = -1;
	for(int i = 1; i <= n; i++) {
		if(e[i].size() != 1) {
			pos = i;
			break;
		}
	}
	dfs(pos, pos) ? printf("YES\n") : printf("NO\n");
	return 0;
}

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

using namespace std;

int main() {

	int l, r, d;
	cin >> l >> r >> d;

	int res=0;
	for (int i = l; i <= r; i++) {
		if (i%d == 0) { res++; }
	}

	cout << res << endl;



	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++)
        cin >> s.at(i);
    bool tf = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') {
                bool ijnotpaint = true;
                if(i - 1 >= 0) {
                    if (s.at(i - 1).at(j) == '#') continue;
                }
                if (i + 1 < h) {
                    if (s.at(i + 1).at(j) == '#') continue;
                }
                if(j - 1 >= 0) {
                    if (s.at(i).at(j - 1) == '#') continue;
                }
                if (j + 1 < w) {
                    if (s.at(i).at(j + 1) == '#') continue;
                }
                if (ijnotpaint){
                    tf = false;
                    break;
                }
            }
        }
        if (!tf) break;
    }
    if (tf) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << max({a + a - 1, a + b, b + b - 1}) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=20;
int n;
int a[N],c[N];
int b[N][N];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		for(int j=1;j<=a[i];j++) {
			int t;cin>>t;
			cin>>b[i][t];b[i][t]++;
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		int flag=0,res=0;
		for(int j=0;j<n;j++) {
			c[j+1]=(i>>j)&1;
			if(c[j+1]==1) res++;
		}
		for(int j=1;j<=n;j++){
			if(c[j]==0) continue;
			for(int k=1;k<=n;k++) {
				if(b[j][k]==0) continue;
				if(b[j][k]-1!=c[k]) {
					flag=1;break;
				}
			}
		}
		if(!flag) {
			ans=max(ans,res);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
int main()
{
    string s;
    cin>>s;
    stack<bool>sta;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='C')sta.push(1);
        if(s[i]=='F'&&(!sta.empty()))
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

int main(){
  string s;	cin >> s;
  
  if(s=="SSS")	cout << 0;
  else if(s=="SSR"||s=="SRS"||s=="RSS"||s=="RSR")	cout << 1;
  else if(s=="SRR"||s=="RRS")	cout << 2;
  else if(s=="RRR")	cout << 3;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

#define INF 1000000000

using namespace std;

int n, m;
vi adj[1010];

set<int> ans;
bool visited[1010];
int from[1010];

void dfs(int i) {
    if(ans.find(i) != ans.end()) return;
    ans.insert(i);
    dfs(from[i]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].PB(b);
    }

    for(int i = 1; i <= n; i++) {
        int dist[n+1];
        for(int j = 1; j <= n; j++) dist[j] = INF;
        queue<pair<int, int>> q; // {atual, last}
        q.push(MP(i, i));
        dist[i] = 0;
        from[i] = i;
        while(!q.empty()) {
            pair<int,int> top = q.front(); q.pop();
            if(top.F == i && top.S != i) {
                dfs(top.S);
                cout << ans.size() << endl;
                for(int v : ans) {
                    cout << v << "\n";
                }
                exit(0);
            }
            bool can = true;
            for(int c : adj[top.F]) {
                if(dist[c] < dist[top.F] && c != i) can = false;
            }
            if(!can) continue;
            for(int c : adj[top.F]) {
                if(dist[c] > dist[top.F] + 1 || dist[c] == 0) {
                    from[c] = top.F;
                    dist[c] = dist[top.F] + 1;
                    q.push(MP(c, top.F));
                }
            }
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;
using namespace chrono;

//  https://ja.wikipedia.org/wiki/Xorshift
int xor64(void) {
    static unsigned long long x = 88172645463325252ULL;
    x ^= x<<13;
    x ^= x>> 7;
    x ^= x<<17;
    return int(x&0x7fffffff);
}

int main()
{
    //  入力
    int D;
    cin>>D;
    vector<int> C(26);
    for (int &c: C)
        cin>>c;
    vector<vector<int>> S(D, vector<int>(26));
    for (auto &s: S)
        for (auto &x: s)
            cin>>x;

    auto start = system_clock::now();

    //  選んだコンテスト
    vector<int> T(D, -1);
    int score = 0;

    //  d日目にコンテストtを開く
    auto add = [&](int d, int t)
    {
        int d0 = d;
        while (d0>=0 && T[d0]!=t)
            d0--;
        int d1 = d;
        while (d1<D && T[d1]!=t)
            d1++;
        score += C[t]*(d-d0)*(d1-d);
        score += S[d][t];
        T[d] = t;
    };

    //  d日目のコンテストを止める
    auto remove = [&](int d)
    {
        int t = T[d];
        T[d] = -1;
        int d0 = d;
        while (d0>=0 && T[d0]!=t)
            d0--;
        int d1 = d;
        while (d1<D && T[d1]!=t)
            d1++;
        score -= C[t]*(d-d0)*(d1-d);
        score -= S[d][t];
    };

    for (int d=0; d<D; d++)
        add(d, d%26);

    double time = 0.0;
    double limit = 1.8;

    int step;
    for (step=0; time<limit; step++)
    {
        if (step%10000==0)
            time = duration_cast<microseconds>(system_clock::now()-start).count() * 1e-6;

        if (step%2==0)
        {
            //  1日のコンテストの種類を変えてみる
            int d = xor64()%D;
            int t = xor64()%26;
            int old_score = score;
            int old_t = T[d];            
            remove(d);            
            add(d, t);

            //  悪くなったら戻す
            if (score < old_score)
            {
                remove(d);
                add(d, old_t);
            }
        }
        else
        {
            //  1週間以内のコンテストを交換してみる
            int d0 = xor64()%D;
            int d1 = d0 + xor64()%15 - 7;
            if (d1!=d0 && 0<=d1 && d1<D)
            {
                int old_score = score;
                int t0 = T[d0];
                int t1 = T[d1];
                remove(d0);
                remove(d1);
                add(d0, t1);
                add(d1, t0);

                //  悪くなったら戻す
                //  ただし、ある程度までは許容する
                //  許容範囲は時間とともに狭める（焼きなまし）
                if (score < old_score + int(10000*(limit-time)/limit))
                {
                    remove(d0);
                    remove(d1);
                    add(d0, t0);
                    add(d1, t1);
                }
            }
        }
    }

    for (int t: T)
        cout<<t+1<<endl;

    cerr<<"score: "<<max(0, score+1000000)<<endl;
    cerr<<"step: "<<step<<endl;
}


Measured memory_bytes: 3212
import math
import numpy as np

N = int(input())
A_list = list(map(int, input().split()))
np_A = np.array(A_list)
tmp_cou = 0
x = 1
while x==1:
    for i in np_A:
        if i % 2 == 0:
            tmp_cou += 1
        else:
            x = 2
    np_A = np_A/2

cou = math.floor(tmp_cou/N)
print(cou)


Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int a[maxn];
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int pos=0,cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[pos]<a[i])
		{
			pos=i;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[pos])
		{
			cnt++;
		}
	}
	if(cnt==1)
	{
		for(int i=0;i<n;i++)
		{
			if(i==pos)
			{
				int y=0;
				for(int j=0;j<n;j++)
				{
					if(j!=pos)
					{
						y=max(a[j],y);
					}
				}
				cout<<y<<endl;
			}
			else
			{
				cout<<a[pos]<<endl;
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			cout<<a[pos]<<endl;
		}
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    cin.tie(0);ios::sync_with_stdio(false);
    
    ll p10[11];
    p10[0]=1;
    for(int i=1; i<11; ++i) p10[i]=p10[i-1]*10;

    ll n;
    int k;
    while(cin >>n >>k,n)
    {
        --n;

        ll d=1;
        while(n - 9*p10[d-1]*d >=0)
        {
            n-=9*p10[d-1]*d;
            ++d;
        }

        ll b=p10[d-1];

        b+=n/d;
        n-=(n/d)*d;

        string s="";
        for(ll i=b; i<b+100; ++i) s+=to_string(i);

        cout << s.substr(n,k) << '\n';
    }
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
      cin >> vec.at(i);
    }
       
    
    sort(vec.begin(), vec.end()); // {1, 2, 2, 5}
  
    int sum = 0;

    for (int i = 0; i < K; i++) {
        sum += vec.at(i);
    }
  cout << sum;
}


Measured memory_bytes: 3584
import sys
lis =list()
lis.append([0, 0, 0])
sys.stdin.readline()
for e in sys.stdin:
  lis.append(list(map(int, e.split())))
for i in range(len(lis) - 1):
  d_t = lis[i + 1][0] - lis[i][0]
  man_dis = abs(lis[i + 1][1] - lis[i][1]) + abs(lis[i + 1][2] - lis[i][2])
  if d_t < man_dis or d_t % 2 - man_dis % 2 != 0:
    print("No")
    sys.exit()
print("Yes")

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int flag = 0;
    sort(a.begin(), a.end());
    for(int i = 0; i< n-1; i++){
        if(a[i]==a[i+1]){
            flag = 1;
            break;
        }
    }
    if(flag) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();
		double r2 = 1.0*r;
		
		double ensyu = r2 * 2 * 3.141592653589;
		double menseki = r2 * r2 * 3.141592653589;

		String ee =String.format("%.8f",ensyu);
		String mm =String.format("%.8f",menseki);
		System.out.println(mm+" "+ee);
	}
}

Measured memory_bytes: 28336
using System;

class Program
{
    static void Main(string[] args)
    {
        int numNumbers = int.Parse(Console.ReadLine());
        string[] numbersString = Console.ReadLine().Split(' ');
        int[] numbers = new int[numNumbers];

        for (int i = 0; i < numNumbers; ++i)
        {
            numbers[i] = int.Parse(numbersString[i]);
        }

        int divideTwoCount = 0;
        while (true)
        {
            bool successed = true;

            for (int i = 0; i < numNumbers; ++i)
            {
                if (numbers[i] % 2 != 0)
                {
                    successed = false;
                    break;
                }
                else
                {
                    numbers[i] /= 2;
                }
            }

            if (successed)
            {
                divideTwoCount++;
            }
            else
            {
                break;
            }
        }

        Console.WriteLine(divideTwoCount);
    }
}


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

const int inf=-1;
typedef pair<int,int> P;

int h,w,n;
char a[1001][1001];
int d[1001][1001];

int bfs(P st,P go){
    int dx[4]={0,1,0,-1};
    int dy[4]={-1,0,1,0};
    queue<P> que;
    que.push(st);
    d[st.first][st.second]=0;
    while(que.size()){
        P ck=que.front();
        que.pop();
        if(ck.first==go.first&&ck.second==go.second)break;
        for(int i=0;i<4;i++){
            int nx=ck.first+dx[i];
            int ny=ck.second+dy[i];
            if(nx>0&&nx<=h&&ny>0&&ny<=w&&a[nx][ny]!='X'&&d[nx][ny]==inf){
                que.push(P(nx,ny));
                d[nx][ny]=d[ck.first][ck.second]+1;
            }
        }
        /*for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cout<<setw(2)<<d[i][j]<<' ';
            }
            cout<<endl;
        }
        cout<<endl;*/
    }
    return d[go.first][go.second];
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    P st;
    P go;
    P memo[10];
    char direct[10]={'S','1','2','3','4','5','6','7','8','9'};
    cin>>h>>w>>n;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
            d[i][j]=inf;
            for(int k=0;k<=n;k++){
               if(a[i][j]==direct[k]){
                   memo[k].first=i;
                   memo[k].second=j;
               }
            } 
        }
    }
    st.first=memo[0].first;
    st.second=memo[0].second;
   
    int cnt=0;
    for(int i=1;i<=n;i++){
        go.first=memo[i].first;
        go.second=memo[i].second;
       // cout<<'#'<<cnt<<endl;
        cnt+=bfs(st,go);
        for(int j=1;j<=h;j++){
            for(int k=1;k<=w;k++){
                d[j][k]=inf;
            }
        }
        st.first=memo[i].first;
        st.second=memo[i].second;
    }
    cout<<cnt<<endl;
    return 0;
}



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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int  N;
    cin>> N;
    vi A(N, 0);
    vi Table(100001, 0);
    long sum = 0;

    REP(i, 0, N){
        cin >> A[i];
        Table[A[i]]++;
        sum += A[i];
    }

    int Q;
    cin >> Q;
    REP(i, 0, Q){
        int b, c;
        cin >> b >> c;
        int b_quant = Table[b];
        int c_quant = Table[c];
        Table[b] = 0;
        Table[c] += b_quant;
        sum += b_quant * (c-b);
        cout << sum << endl;
    }
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)
 
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define fi first
#define se second
#define pb push_back
 
vector<pii> adj[15];
 
 
int djikstra(int num)
{
    int dis[15],b,i;
    fill(dis,dis+15,2*mod);
    
    dis[1]=0;
    
    priority_queue< pii , vector< pii > , greater<pii > > pq;  // careful about '>' spacing
    
    pq.push({0,1});
    
    while(!pq.empty())
    {
        b=pq.top().second;
        pq.pop();
        
        for(i=0;i<adj[b].size();i++)
        {
            if(dis[ adj[b][i].first ] >  dis[b]+ adj[b][i].second )
            {
                dis[adj[b][i].first ]=dis[b]+adj[b][i].second ;
                pq.push(make_pair(dis[ adj[b][i].first ],adj[b][i].first));
            }
        }
    }
    return dis[num];
}
 
int main() 
{
    boost;
    
    int i,j,h,w,num ;
    
    
    cin>>h>>w;
    
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            cin>>num;
            adj[j].push_back({i,num});
        }
    }    
    
    int dp[10];
    
    for(i=0;i<10;i++)
    dp[i]=djikstra(i);
    
//    cout<<dp[8]<<endl;
    
    int ans=0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>num;
            if(num!=-1)
            {
                ans+=dp[num];
            }
        }
    }
    
    cout<<ans<<endl;
    
       
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  ll ans=0;
  rep(i,1000000){
    ll u=i+1;
    if(n-u<=0)continue;
    if((n-u)%u==0&&(n-u)/u>u)ans+=(n-u)/u;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;//外
using System.Linq;//Linq
public class ABC{

    public static void Main(){
        int cnt = 0;
        int n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine();
        var p = line.Split(' ').Select(s => int.Parse(s)).ToArray();//Select,λ型
        for ( int i = 0; i<n; i++){
            if (p[i]!=i+1){
                cnt += 1;
            }
        }
        if (cnt >2) {
            Console.WriteLine("NO");
        }
        else{
            Console.WriteLine("YES");
        }
       
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int a[5],ans,f,mina=10,c,t;
main(){
    for(int i=0;i<5;i++){
        cin>>a[i];
        f=a[i]%10;
        if(f!=0)ans+=a[i]+10-f;
      	else ans+=a[i];
        if(f==0){
          t++;
          continue;
        }
        else if(mina>f)mina=f,c=i;
    }
    cout<<(t==5?ans:ans-10+a[c]%10)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
int main(void){
  int n, i, max;
  cin >> n;
  int a[100001] = {}, cnt[100001] = {};
  REP(i, n){
    cin >> a[i];
    cnt[a[i]-1]++;
    cnt[a[i]  ]++;
    cnt[a[i]+1]++;
  }
  max = *max_element(cnt,cnt+100001);
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 
  int i,j;
  int fmoney,lmoney;
  int r;
  int year;
  int b,cost;
  double per;
  int m,n;
  int *a;
 
  scanf("%d",&m);
  while(1)
    {
      if(m==0)break;
      scanf("%d",&fmoney);
      scanf("%d",&year);
      scanf("%d",&n);
      a=(int *)malloc(sizeof(int)*n);
 
      for(i=0;i<n;i++)
    {
      scanf("%d %lf %d",&b,&per,&cost);
      lmoney=fmoney;
           r=0;
      if(b==0)
        {
          for(j=0;j<year;j++)
        {
          r+=(int)(lmoney*per);
          lmoney-=cost;
        }
          a[i]=r+lmoney;
        }
 
      if(b==1)
        {
          for(j=0;j<year;j++)
        {
          r = (int)(lmoney*per);
                  lmoney=lmoney+r-cost;
        }
          a[i]=lmoney;
        }
    }
      for(i=1;i<n;i++)
    {
      if(a[0]<a[i]){a[0]=a[i];}
    }
      printf("%d\n",a[0]);
      m--;
    }
 
  return 0;
}


Measured memory_bytes: 2044
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

int n, m;
int vis[maxN] = {};

void solve()
{
    cin >> n >> m;
    vector<vector<int>> graph(maxN);
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vis[1] = 1;
    //
    queue<int> q;
    q.push(1);
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        for (auto i:graph[now])
        {
            if (!vis[i])
            {
                vis[i] = now;
                q.push(i);
            }
        }
    }
    bool check = true;
    for (int i = 1; i <= n; i++)
    {
        if (vis[i] == 0)
        {
            check = false;
            break;
        }
    }
    if (check)
    {
        cout << "Yes\n";
        for (int i = 2; i <= n; i++)
        {
            cout << vis[i] << endl;
        }
    }
    else
    {
        cout << "No\n";
    }
}

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

Measured memory_bytes: 12560