akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  long long n,x=1e9,y=1e9,i,a,s=0,c=0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    if(a<0){
      x=MIN(x,-a);
      s-=a;
      c++;
    }
    else{
      y=MIN(y, a);
      s+=a;
    }
  }
  if(c%2)s-=2*MIN(y,x);
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;


#define FOR(i, n) for (int i = 0; i < (n); ++i)


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto s = next<string>(in);
  int cs = 0;
  int toRemove = 0;
  FOR(i, s.length()) {
    if (s[i] == 'S') {
      ++cs;
    } else {
      if (cs) {
        toRemove += 2;
        --cs;
      }
    }
  }
  out << s.length() - toRemove << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

int main()
{
    ll A, B; cin >> A >> B;
    ll a = A + B;
    ll b = A - B;
    ll c = A * B;
    ll maxv = max(a, b);
    maxv = max(maxv, c);
    cout << maxv << endl;
    




}


Measured memory_bytes: 3624
#include <bits//stdc++.h>
using namespace std;
long long int gcd(long long int m,long long int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}
long long int lcm(long long int m,long long int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}
int main() {
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long int ccan=b/c-(a-1)/c;
	long long int dcan=b/d-(a-1)/d;
	long long int cdcan=b/lcm(c,d)-(a-1)/lcm(c,d);
	cout<<(b-a+1)-(ccan+dcan-cdcan);
	return 0;
}



Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,K = (int(_) for _ in input().split())
    S = list(int(_) for _ in input())
    now = 1
    cnt = 0
    Nums = []
    ans = 0
    left = 0
    right = 0
    tmp = 0
    for i in range(N):
        if(S[i]==now):
            cnt+=1
        else:
            Nums.append(cnt)
            now = 1 - now
            cnt=1
    if(cnt!=0):
        Nums.append(cnt)
    if(len(Nums)%2 == 0):
        Nums.append(0)
    Add = 2 * K +1
    for i in range(0,len(Nums),2):
        Nextleft = i
        Nextright = min(i+Add,len(Nums))
        
        while(Nextleft>left):
            tmp -= Nums[left]
            left +=1
        while(Nextright>right):
            tmp += Nums[right]
            right +=1        
        ans = max(tmp,ans)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 5264
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

//Operations with Finite Sets
public class Main{

	boolean[][] set;
	boolean[] u;
	Map<Integer, Integer> ref;
	int n;
	
	char[] s;
	int id;
	char get(){
		return s[id++];
	}
	
	boolean[] exp(){
		boolean[] res = new boolean[n];
		res = fact();
		for(;;){
			char ch = get();
			boolean[] x;
			if(ch=='u'){
				x = fact();
				for(int i=0;i<n;i++)res[i]=res[i]|x[i];
			}
			else if(ch=='i'){
				x = fact();
				for(int i=0;i<n;i++)res[i]=res[i]&x[i];
			}
			else if(ch=='d'){
				x = fact();
				for(int i=0;i<n;i++)res[i]=res[i]&&!x[i];
			}
			else if(ch=='s'){
				x = fact();
				for(int i=0;i<n;i++)res[i]=res[i]^x[i];
			}
			else break;
		}
		return res;
	}
	
	boolean[] fact(){
		boolean[] res = new boolean[n];
		char ch = get();
		if(Character.isUpperCase(ch)){
			if(ch=='U'){
				Arrays.fill(res, true);
				return res;
			}
			for(int i=0;i<n;i++)res[i] = set[ch-'A'][i];
			return res;
		}
		if(ch=='('){
			return exp();
		}
		ch = s[id];
		boolean[] x;
		if(ch=='('){
			get();
			x = exp();
		}
		else x = fact();
		for(int i=0;i<n;i++)res[i]=!x[i];
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			set = new boolean[5][500];
			u = new boolean[500];
			ref = new HashMap<Integer, Integer>();
			n = 0;
			int[] rev = new int[500];
			for(;;){
				char ch = sc.next().charAt(0);
				int k = sc.nextInt();
				if(ch=='R')break;
				while(k--!=0){
					int x = sc.nextInt();
					if(!ref.containsKey(x)){
						rev[n] = x;
						ref.put(x, n++);
					}
					set[ch-'A'][ref.get(x)] = true;
				}
			}
			s = (sc.next()+"$").toCharArray();
			id = 0;
			Arrays.fill(u, true);
			boolean[] res = exp();
			PriorityQueue<Integer> q = new PriorityQueue<Integer>();
			for(int i=0;i<n;i++)if(res[i])q.add(rev[i]);
			if(q.isEmpty())System.out.println("NULL");
			else {
				System.out.print(q.poll());
				while(!q.isEmpty())System.out.print(" "+q.poll());
				System.out.println();
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int a = 0; a < N; a++){
    vec[a] = a + 1;
  }
  int b = N;
  
  for(int i = 0; i < K; i++){
    int x;
    cin >> x;
    for(int j = 0; j < x; j++){
      int y;
      cin >> y;
      for(int k = 0; k < b; k++){
        if(vec[k] == y){
          b -= 1;
          vec.erase(vec.begin() + k);
        }
      }
    }
  }
  cout << b << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {

	ll n;
	cin >> n;
	vector<ll> t(n);
	ll ans = 1;
	rep(i, n) {
		cin >> t.at(i);
		ans = lcm(ans, t.at(i));
	}
	cout << ans << endl;
	
	
	return 0;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    VI a(3); cin >> a;
    SORT(a);
    a.erase(unique(all(a)), a.end());
    cout << (a.size() == 2 ? "Yes\n" : "No\n");
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    char c;
    cin >> c;
    if(c <= 'Z')
        cout << 'A';
    else
        cout << 'a';

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

int main(){
	char str[32];
	char MostS[32];
	char dict[1000][32];
	int  count[1000];
	int MSC=0;
	int A,B,C;
	for(A=0;A<1000;A++)
		count[A]=0;
	while(scanf("%s",str)!=EOF){
		for(A=0;A<1000 && (B=strcmp(dict[A],str)) && count[A];A++);
		if(B)
			strcpy(dict[A],str);
		count[A]++;
		A=strlen(str);
		if(MSC<A){
			strcpy(MostS,str);
			MSC=A;
		}
	}
	B=0;C=0;
	for(A=0;A<1000 && count[A];A++)
		if(B<count[A]){
			B=count[A];
			C=A;
		}
	printf("%s %s\n",dict[C],MostS);
 	return 0;
}

Measured memory_bytes: 568
import Data.Char

main :: IO()
main = do
  [n, a, b] <- map read . words <$> getLine
  let digitList = map (sum . map digitToInt) (map show [0..n])
  let isMatch x = fst x >= a && fst x <= b
  let filteredList = filter isMatch $ zip digitList [0..n]
  print $ sum $ map snd filteredList

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 2*1e5+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
	cin>> n;
	vi a(n);
	vi freq(n+1, 0LL);

	for(int &i: a){
		cin>> i;
		freq[i]++;
	}

	int tot = 0LL;

	for(int i = 1; i<=n; ++i) tot+= ((freq[i]*(freq[i]-1)) >> 1);


	for(int i: a) cout<< tot - freq[i] + 1LL << endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}

Measured memory_bytes: 6288
n=int(input())
A=list(map(int,input().split()))
A.sort()
t=0
e=[True]*1000001
for i in range(n-1):
    a=A[i]
    if e[a]==False:
        continue
    b=a*2
    while b < 1000001:
        e[b]=False
        b+=a
    if A[i+1]==a:
        e[a]=False
for a in A:
    if e[a]:
        t+=1
print(t)

Measured memory_bytes: 121864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int char2int(char c) {
  return int(c-'a');
}
int main() {
  int N, Q;
  string S;
  cin >> N >> S >> Q;
  vector<set<int> > A(26, set<int>());
  rep(i, N) A[char2int(S[i])].insert(i);
  rep(q, Q) {
    int type;
    cin >> type;
    if(type == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      A[char2int(S[i])].erase(i);
      A[char2int(c)].insert(i);
      S[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      l--; r--;
      int cnt = 0;
      rep(alpha, 26) {
        auto litr = A[alpha].lower_bound(l);
        if(litr == A[alpha].end()) continue;
        if(*litr <= r) cnt++;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 24196
def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    total_price = 0

    for i in range(1,N+1):
        if i <= K:
            total_price += X
        else:
            total_price += Y
    
    print(total_price)

main()

Measured memory_bytes: 2940
from operator import itemgetter
from scipy.sparse import lil_matrix, csr_matrix, coo_matrix
from scipy.sparse.csgraph import minimum_spanning_tree

def main():
    N = int(input())
    M = 10**10
    XY = [tuple(map(int, input().split())) for _ in range(N)]
    xy = [(x, i) for i, (x, _) in enumerate(XY)]
    yx = [(y, i) for i, (_, y) in enumerate(XY)]
    xy.sort()
    yx.sort()
    d = {}
    x1, i1 = xy[0]
    for x, i in xy[1:]:
        t = (i1, i) if i1 < i else (i, i1)
        d[t] = min(abs(x1 - x), d.get(t, M))
        x1, i1 = x, i
    x1, i1 = yx[0]
    for x, i in yx[1:]:
        t = (i1, i) if i1 < i else (i, i1)
        d[t] = min(abs(x1 - x), d.get(t, M))
        x1, i1 = x, i
    row = list(map(itemgetter(0), d.keys()))
    col = list(map(itemgetter(1), d.keys()))
    c = coo_matrix((list(d.values()), (row, col)), shape=(N, N))
    a = minimum_spanning_tree(c, overwrite=True)
    return int(a.sum())

print(main())


Measured memory_bytes: 91776
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int a,b;
  int ans=0,mi,tmp=0;

  cin>>a;
  mi=a%10;
  tmp=a;

  rep(i,4)
  {
    cin>>a;
    if(a%10==0) ans+=a;
    else if(a%10<=mi)
    {
      mi=a%10;
      if(tmp%10==0) ans+=tmp;
      else ans+=(tmp/10*10+10);

      tmp=a;
    }

    else
    {
      ans+=(a/10*10+10);
    }

    if(i==3) ans+=(tmp);
  }

  cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;

const int MAX_N = pow(10,5);
vector<ll> v(MAX_N,0);
vector<ll> A1(MAX_N,0);
vector<ll> A2(MAX_N,0);
int n;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  for(int k=0;k<n/2;k++){
    A1[v[2*k]]+=1;
    A2[v[2*k+1]]+=1;
  }
  int answer =0;
  int max1 = *max_element(A1.begin(), A1.end());
  int max2 = *max_element(A2.begin(), A2.end());
  answer = n - max1 - max2;
  if( max_element(A1.begin(), A1.end())-A1.begin()== max_element(A2.begin(), A2.end())-A2.begin()){
    int pre_max1 = max1;
    int pre_max2 = max2;
    A1[max_element(A1.begin(), A1.end())-A1.begin()] = 0;
    A2[max_element(A2.begin(), A2.end())-A2.begin()] = 0;
    max1 = *max_element(A1.begin(), A1.end());
    max2 = *max_element(A2.begin(), A2.end());
    if(max1>=max2){
      answer = n - max1 - pre_max2;
    }else{
      answer = n - pre_max1 - max2;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
const int MOD = 1e9+7;
ll dp[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, T;
    cin >> N >> T;
    vector<int> D(N);
    for (int i = 0; i < N; i++)
        cin >> D[i];
    sort(D.begin(), D.end());
    dp[0] = 1;
    for (int i = 1; i < N; i++) {
        int j = lower_bound(D.begin(), D.end(), D[i]-T) - D.begin();
        dp[i] = (dp[i-1]*(i-j+1))%MOD;
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 4136
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    //答えansを仮置きする。
    //これが十分に大きくないと不正解となるので、
    //この値なら絶対に正しい答えが出る、という値を仮置きすること
    int ans = T.size();
 
    //Sの何文字目から調べるかを全探索する
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3628
puts ({
  0 => "pon",
  1 => "pon",
  2 => "hon",
  3 => "bon",
  4 => "hon",
  5 => "hon",
  6 => "pon",
  7 => "hon",
  8 => "pon",
  9 => "hon",
}[gets.chomp[-1].to_i])

Measured memory_bytes: 14268
N = int(input())
F = [int(x) for x in input().split()]

flag = True
for i in range(N-1):
    if F[i] < F[i+1]:
        F[i+1] -= 1
    elif F[i] > F[i+1]:
        flag = False
        break
    
if flag == True:
    print("Yes")
else:print("No")

Measured memory_bytes: 20608
#include <stdio.h>
#include <math.h>
int main(void) {
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf\n",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    return 0;
}

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

using namespace std;
stack<char> q, q2;
int main()
{
    int len, i=1;
    string s;
    cin >> len >> s;
    q.push(s[0]);
    while(1)
    {
        if(i==len) break;
        if(q.empty()) q.push(s[i]);
        else
        {
            if(q.top()=='(' && s[i]==')') q.pop();
            else q.push(s[i]);
        }
        i++;
    }
    while(!q.empty())
    {
        q2.push(q.top());
        q.pop();
    }
    while(!q2.empty())
    {
        if(q2.top()!=')') break;
        putchar('(');
        q2.pop();
    }
    cout<<s;
    while(!q2.empty()) putchar(')'), q2.pop();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll INF=1000000000;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int n,m;
int c[20],x[20010];
ll dp[20010][256];
ll dfs(int now,int pre){
    if(dp[now][pre]!=-1)return dp[now][pre];
    ll res=LINF;
    for(int i=0;i<m;i++){
        int to=min(255,max(0,pre+c[i]));
        ll s=(to-x[now])*(to-x[now]);
        if(now+1<n)s+=dfs(now+1,to);
        res=min(res,s);
    }
    return dp[now][pre]=res;
}
int main(){
    while(cin>>n>>m,n+m){
        for(int i=0;i<m;i++)cin>>c[i];
        for(int i=0;i<n;i++)cin>>x[i];
        memset(dp,-1,sizeof(dp));
        cout<<dfs(0,128)<<endl;
    }
}


Measured memory_bytes: 45040
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(){
  int a[5],b[5];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  sort(a, a+5); 
  for(int i=0;i<5;i++){
  	b[i] = ((a[i]+(9))/10)*10;
  }
  int res[5];
  res[0] = b[0]+b[1]+b[2]+b[3]+a[4];
  res[1] = b[0]+b[1]+b[2]+a[3]+b[4];
  res[2] = b[0]+b[1]+a[2]+b[3]+b[4];
  res[3] = b[0]+a[1]+b[2]+b[3]+b[4];
  res[4] = a[0]+b[1]+b[2]+b[3]+b[4];
  sort(res,res+5);
  cout << res[0] << endl;
 
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    set<string> se;
    for(int i=0; i<N; i++){
        string S;
        cin >> S;
        se.insert(S);
    }
    int M;
    cin >> M;
    bool lock = true;
    for(int i=0; i<M; i++){
        string S;
        cin >> S;
        if(se.count(S)){
            if(lock){
                cout << "Opened by " << S << "\n";
                lock = false;
            }else{
                cout << "Closed by " << S << "\n";
                lock = true;
            }
        }else{
            cout << "Unknown " << S << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt(), k = sc.nextInt();
		char[][] a = new char[h][w];
		for(int i = 0; i < h; i++) {
			char[] s = sc.next().toCharArray();
			a[i] = s;
		}
		int[][] s = set(h, w);
		int ans = 0;
		for(int i = 0; i < (int)Math.pow(2, h+w); i++) {
			int[] c =  s[i];
			int num = 0;
			for(int j = 0; j < h; j++) {
				if(c[j] == 0) {
					for(int l = 0; l < w; l++) {
						if(a[j][l] == '#' && c[h+l] == 0) {
							num++;
						}
					}
				}
			}
			if(num == k) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	static int[][] set(int h, int w) {
		int all = (int)Math.pow(2, h+w);
		int[][] list = new int[all][h+w];
		for(int i = 0; i < all; i++) {
			Arrays.fill(list[i], 0);
			int x = i;
			int n = 0;
			while(x >= 2) {
				list[i][n] = x % 2;
				n++;
				x /= 2;
			}
			list[i][n] = x;
		}
		return list;
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 33712
// Problem : B - String Palindrome
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*
 * author :Sadik Hassan
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
	string s,k,ss,kk;
	cin>>s;
	k=s;
	VREV(k);
	if(k!=s)
	{
		cout<<"No";return 0;
	}
	else
	{
		int l=SZ(s)-1;
		string sap,pap;
		rep(i,l/2)
		sap+=s[i];
		pap=sap;
		VREV(pap);
		if(pap!=sap)
		{
			cout<<"No";return 0;
		}
		
		l+=4;
		l/=2;
		for(int i=l-1;i<SZ(s);i++)
		{
			ss+=s[i];
		}
		kk=ss;
		VREV(kk);
		if(kk!=ss)
		{
			cout<<"No";return 0;
		}
		cout<<"Yes";
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin>>n>>k;
    int h[n];
    for(int i=0; i<n; i++)
        cin>>h[i];
    int z = INT_MAX;
    int ans[n];
    for(int i=0; i<n; i++)
    {
        ans[i] = z;
    }
    ans[0] = 0;
    for(int i=1; i<n; i++)
    {
        for(int j=i-1; j>=i-k && j>=0; j--)
        {
            ans[i] = min((ans[j]+abs(h[i]-h[j])), (ans[i]));
        }
    }
    cout<<ans[n-1];

    return 0;
}



Measured memory_bytes: 1024
// ACLBC-D.cpp

#include <iostream>
#include <vector>
#include <atcoder/segtree> // 無向グラフ DSU  Union-Find
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

const int MAX_A = 300005;

int f(int a,int b) {
    return max(a, b);
}
int e() {
    return 0;
}
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

    segtree<int, f, e> dp(MAX_A);
    rep(i, n) {
        int x = a[i];
        int l = x - k;
        int r = x + k + 1;
        l = max(l, 0);
        r = min(r, MAX_A);
        int now = dp.prod(l,r)+1;
        dp.set(x,now);
    }
    int ans = dp.prod(0, MAX_A);
    cout << ans << endl;
}


Measured memory_bytes: 9248
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long lli;
lli n,a,b;
vector<lli> v;
vector<long double> dv;
long double ans;
lli num;
vector<vector<lli> > dp(51,vector<lli>(51));
lli combination(lli n,lli k){
    if(dp[n][k]) return dp[n][k];
    if(n == k) return 1;
    if(k == 0) return 1;
    if(k == 1) return n;
    return dp[n][k] = combination(n-1,k-1) + combination(n-1,k);
}
 
int main(){
    cin >> n >> a >> b;
    v = vector<lli> (n);
    dv = vector<long double> (n);
    for(lli i = 0;i < n;i++) cin >> v[i];
    sort(v.begin(),v.end(),greater<lli>());
    for(lli i = 0;i < n;i++) dv[i] = (long double)v[i];
    for(lli i = 1;i < n;i++){
        dv[i] += dv[i-1];
    }
    ans = 0;
    for(lli i = a-1;i < b;i++){
        ans = max(ans,dv[i]/(long double)(i+1));
    }
    num = 0;
    for(lli i = a-1;i < b;i++){
        if(dv[i]/(long double)(i+1) == ans){
            lli j = i;
            while(j >= 0 && v[j] == v[i]) j--;
            lli s = i-j;
            j++;
            lli k = 0;
            while(j < n && v[j] == v[i]) j++,k++;
            num += combination(k,s);
        }
    }
    printf("%.18Lf\n",ans);
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int s = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = 0;
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++) {
                int sum = i + j;
                if (sum <= s && s - sum <= k) {
                    result++;
                }
            }
        }

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


Measured memory_bytes: 35532
#include <stdio.h>

int main(void) {
	int H1, M1, H2, M2, K;
	int asumi, iguti;
	int tomatu;
	if (scanf("%d%d%d%d%d", &H1, &M1, &H2, &M2, &K) != 5) return 1;
	asumi = H1 * 60 + M1;
	iguti = H2 * 60 + M2;

	tomatu = iguti - asumi - K;
	printf("%d\n", tomatu >= 0 ? tomatu : 0);
	return 0;
}


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

int main(){
    char s[55][55];
    int h,w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '#' && s[i+1][j] !='#' && s[i-1][j] !='#' && s[i][j+1] !='#' && s[i][j-1] !='#'){
                goto fail;
            }
        }
    }
    cout << "Yes" << endl;
    goto end;
    fail:
    cout << "No" << endl;
    end:
    return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    #define mp make_pair
    #define pb push_back
    #define M_PI           3.14159265358979323846  /* pi */
    typedef long double ld;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<ll> vi;
    const int maxN = 100224;

    ll fa[maxN], cnt[maxN];

    ll find(ll x){
      return fa[x] == x ? x : fa[x] = find(fa[x]);
    }

    void solve(){
      ll n,m;
      cin>>n>>m;
      ll x[m+1],y[m+1],ans[m+1];
      rep(i,m) cin>>x[i]>>y[i];
      ans[m] = n*(n-1)/2;
      repA(i,1,n) fa[i] = i, cnt[i] = 1;
      repD(i,m-1,1){
        ll a = find(x[i]), b = find(y[i]);
        if(a==b) ans[i] = ans[i+1];
        else {
          ans[i] = ans[i+1] - cnt[a]*cnt[b];
          fa[a] = b;
          cnt[b]+=cnt[a]; 
        }
      }
      repA(i,1,m) cout<<ans[i]<<endl;
    }
    
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      solve();
      return 0;
    }   

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    string S;
    cin >> S;
    ll N, K;
    cin >> K;
    N = S.size();
    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(2, vector<ll>(K + 2, 0)));
    dp[0][0][0] = 1;
    rep(i, N) {
        ll d = S[i] - '0';
        rep(j, 2) {
            if (j == 1) {
                d = 9;
            }
            rep(k, K + 1) {
                rep(m, d + 1) {
                    dp[i + 1][j == 1 || m < d][(m != 0 ? k + 1: k)] += dp[i][j][k];
                }
            }
        }
    }
    ll ans = dp[N][0][K] + dp[N][1][K];
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())

if 2*x <= a*a*b:
  y = 2 * x / (a*b)
  print(math.degrees(math.atan(b/y)))
else:
  y = 2 * (a*a*b - x) / (a*a)
  print(math.degrees(math.atan(y/a)))


Measured memory_bytes: 3188
<?php 
     $n = trim(fgets(STDIN));
     $s = str_split(trim(fgets(STDIN)));
     $ans = 0;
     for($i = 0; $i < $n; $i++){
       if($s[$i] == "A"){
           if($s[$i+1] == "B" && $s[$i+2] == "C"){
             $ans++;
           }
       }else{
         continue;
       }
     }
     echo $ans;
    ?>

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int h,w;
	cin>>h>>w;
	string s[h];
	loop(i,0,h) cin>>s[i];
	int dp[h][w];
	init(dp,0);
	dp[0][0] = 1;
	loop(i,1,w) if(s[0][i]=='.' && s[0][i-1]=='.') dp[0][i] = dp[0][i-1];
	loop(i,1,h) if(s[i][0]=='.' && s[i-1][0]=='.') dp[i][0] = dp[i-1][0];
	loop(i,1,h)
		loop(j,1,w)
		{
			if(s[i][j]=='.' && s[i-1][j]=='.') dp[i][j] = (dp[i][j] + dp[i-1][j])%mod; 
			if(s[i][j]=='.' && s[i][j-1]=='.') dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
		}
	cout<<dp[h-1][w-1]<<endl;
	return 0;		
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int n;
    cin >> n;
    vector<int>ans(4);
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC"){
            ans[0]++;
        }
        else if(s=="WA"){
            ans[1]++;
        }
        else if(s=="TLE"){
            ans[2]++;
        }
        else ans[3]++;
    }
    cout << "AC x " <<ans[0] <<endl;
    cout << "WA x " <<ans[1] <<endl;
    cout << "TLE x " <<ans[2] <<endl;
    cout << "RE x " <<ans[3] <<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  int a = x%2;
  int y = (x-a)/10;
  int b = y%2;
  int z = (y-b)/10;
  int c = z%2;
  cout << a+b+c <<endl;
}

Measured memory_bytes: 256
n = int(input())
A = map(int, input().split())
sum_b = 0
cnt_b = 0
sum_c = 0
cnt_c = 0
for i,a in enumerate(A):
  sum_b += a
  if not sum_b or ((sum_b > 0) != ((i % 2) > 0)):
    cnt_b += abs(sum_b) + 1
    sum_b = 1 if ((i % 2) > 0) else -1
  sum_c += a
  if not sum_c or ((sum_c > 0) == ((i % 2) > 0)):
    cnt_c += abs(sum_c) + 1
    sum_c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

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

  vector<set<int>> friends(N);
  vector<set<int>> blocks(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    friends[a].insert(b);
    friends[b].insert(a);
  }
  REP(i, K) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    blocks[a].insert(b);
    blocks[b].insert(a);
  }

  map<int, int> color;
  map<int, int> num_color;
  REP(i, N) if (color.count(i) == 0) {
    queue<int> que;
    que.push(i);

    int c = color.size() + 1;
    color[i] = c;
    num_color[c]++;

    DBG(i, c);

    while (!que.empty()) {
      int j = que.front();
      que.pop();
      DBG(j);
      FOR(k, friends[j]) {
        DBG(k);
        if (color.count(k) != 0) continue;
        color[k] = c;
        num_color[c]++;
        que.push(k);
      }
    }

    DBG(c, num_color[c]);
  }

  DBG(N);
  REP(i, N) {
    int cnt = num_color[color[i]] - 1 - friends[i].size();
    FOR(b, blocks[i]) if (color[b] == color[i]) --cnt;
    if (i) cout << " ";
    cout << cnt;
  }
  cout << endl;
}


Measured memory_bytes: 37888
#define DEB
#include <map>
#include <set>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>

#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<lint,lint> pi;

namespace std{
    template<class S,class T>
    ostream &operator <<(ostream& out,const pair<S,T>& a){
        out<<'('<<a.fr<<','<<a.sc<<')';
        return out;
    }
}

//const int INF=5e8;


int n;
lint d[200005];
lint c[200005];
int main(){
    cin>>n;
    lint tot=0;
    lint dig=0;
    REP(i,n){
        cin>>d[i]>>c[i];
        tot+=d[i]*(lint)c[i];
        dig+=c[i];
    }
    lint res=(tot-1)/9+dig-1;
    cout<<res<<endl;


    return 0;
}





Measured memory_bytes: 3328
typedef long long L;L G(L X, L Y){return Y?G(Y,X%Y):X;}n,v[10],d[10];L t,g;main(i){for(;scanf("%d",&n)*n;){for(i=n;i--;d[i]/=t,v[i]/=t)scanf("%d%d",d+i,v+i),t=G(d[i],v[i]);t=1;for(i=n;i--;)t*=d[i]/G(t,d[i]);g=t/ *d**v;for(i=n;--i;)g=G(g,t/d[i]*v[i]);for(;n--;)printf("%lld\n",t/d[n]*v[n]/g);}}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n,max=0,second=0;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(max<=a[i]){
    	second=max;
    	max=a[i];
    }else if(second<=a[i]&&a[i]<max){
    	second=a[i];
    }
  }
  for(int i=0;i<n;i++){
    if(a[i]==max)	cout<<second<<endl;
    else cout<<max<<endl;
  }
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll light[1000];//i番目のライトがどのスイッチで変わるか
ll no[1000];
//bitを探索する
char hen(int i)
{
	if(i==-1)
		return '?';
	if(i<10)
		return (char)('0'+i);
	else{
		i-=10;
		return (char)('A'+i);
	}
}
char chin(int ind,int n)
{
	int cnt=0;
	int ret=-1;
	for(ll i=0;i<n;i++)
	{
		if(light[ind]&(1LL<<i))
		{
			cnt++;
			ret=i;
		}
	}
	if(cnt!=1)
		ret=-1;
	return hen(ret);
}
ll s[100001];
string b[100001];
int main()
{
	int n,m,q;
	while(1)
	{
		cin>>n>>m>>q;
		string tmp="";
		for(int i=0;i<m;i++)
			tmp+='0';
		b[0]=tmp;
		s[0]=0;
		for(int i=1;i<q+1;i++)
		{
			cin>>tmp>>b[i];
			reverse(tmp.begin(),tmp.end());
			s[i]=stoll(tmp,nullptr,2);
		}
		if(n==0)
			break;
		if(q==0)
		{
			if(n==1)
			{
				for(int i=0;i<m;i++)
					cout<<0;
				cout<<endl;
			}else{
				for(int i=0;i<m;i++)
					cout<<'?';
				cout<<endl;
			}
			continue;
		}
		fill(light,light+1000,(1LL<<(ll)n)-1LL);
		fill(no,no+1000,0);
		for(int i=1;i<q+1;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(b[i-1][j]!=b[i][j])
					light[j]&=s[i];
				else
					no[j]|=s[i];
			}
		}
		string ans;
		for(int i=0;i<m;i++)
		{
			//cerr<<bitset<36>(light[i])<<" "<<bitset<36>(no[i])<<endl;
			light[i]&=(~no[i]);
			//cerr<<i<<" "<<bitset<36>(light[i])<<endl;
			ans+=chin(i,n);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 4840
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;

//参考：https://pyteyon.hatenablog.com/entry/2019/03/11/200000
//参考：https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396

class UnionFind {
public:
  vector<ll> parent; //parent[i]はiの親
  vector<ll> siz; //素集合のサイズを表す配列(1で初期化)

  //コンストラクタの:の後ろはメンバ変数を初期化している
  UnionFind(ll n):parent(n),siz(n,1){ //最初は全てが根であるとして初期化する
    for(ll i=0;i<n;i++){parent[i]=i;}
  }

  ll root(ll x){ //データxの属する木の根を再帰で得る
    if(parent[x]==x) return x;
    //代入式の値は代入した変数の値になる！
    //経路圧縮をしている
    return parent[x]=root(parent[x]);
    //再帰で得る際に親の更新を行っておく
  }

  void unite(ll x,ll y){ //xとyの木を併合する
    ll rx=root(x);//xの根をrx
    ll ry=root(y);//yの根をry
    if(rx==ry) return; //同じ木にある時
    //小さい集合を大きい集合へと併合させる(ry→rxへ併合)
    if(siz[rx]<siz[ry]) swap(rx,ry);
    siz[rx]+=siz[ry];
    parent[ry]=rx; //xとyが同じ木にない時はyの根ryをxの根rxにつける
  }

  bool same(ll x,ll y){//xとyが属する木が同じかを返す
    ll rx=root(x);
    ll ry=root(y);
    return rx==ry;
  }

  ll size(ll x){ //素集合のサイズ
    return siz[root(x)];
  }
};

signed main(){
  ll n,m;cin >> n >> m;
  vector< pair<ll,ll> > ab(m);
  for(ll i=m-1;i>=0;i--){cin >> ab[i].first >> ab[i].second;}
  UnionFind uf(n);
  vector<ll> ans(m);ans[0]=(n*(n-1))/2;//cout << ans[0] << endl;
  for(ll i=0;i<m-1;i++){
    //ここで更新も同時に起こってる
    ll a,b;a=ab[i].first-1;b=ab[i].second-1;
    if(uf.same(a,b)){
      ans[i+1]=ans[i];
    }else{
      ll sa,sb;sa=uf.size(a);sb=uf.size(b);
      ans[i+1]=ans[i]+(sa*(sa-1))/2+(sb*(sb-1))/2;
      uf.unite(a,b);sa=uf.size(a);
      ans[i+1]-=(sa*(sa-1))/2;
    }
  }
  for(ll i=m-1;i>=0;i--){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;
signed main(){
  ll n,m,xsum=0,ysum=0,ans=0;
  cin >> n >> m;
  ll tx[n],ty[m],x[n],y[m];
  for(ll i=0;i<n;i++){
    cin >> tx[i];
  }
  for(ll i=0;i<m;i++){
    cin >> ty[i];
  }
  sort(tx,tx+n);
  sort(ty,ty+m);
  n--; m--;
  for(ll i=0;i<n;i++){
    x[i]=tx[i+1]-tx[i];
    x[i]%=MOD;
  }
  for(ll i=0;i<m;i++){
    y[i]=ty[i+1]-ty[i];
    y[i]%=MOD;
  }
  for(ll i=0;i<n;i++){
    if(i==0||i==n-1){
      xsum+=x[i]*n;
    }else{
      xsum+=((((i+1)*(n-i))%MOD)*x[i])%MOD;
    }
    xsum%=MOD;
  }
  for(ll i=0;i<m;i++){
    if(i==0||i==m-1){
      ysum+=y[i]*m;
    }else{
      ysum+=((((i+1)*(m-i))%MOD)*y[i])%MOD;
    }
    ysum%=MOD;
  }
  ans = xsum*ysum;
  ans%=MOD;
  cout << ans<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w;
int dp[20][20];

vector<string> s;

int dfs(int ih, int iw, int dist) {
  if (dp[ih][iw] == -1 || dp[ih][iw] > dist) {
    dp[ih][iw] = dist;
  } else {
    return dp[ih][iw];
  }

  int maxx = 0;
  if (ih + 1 < h && s[ih + 1][iw] != '#') {
    maxx = max(dfs(ih + 1, iw, dist + 1), maxx);
  }
  if (ih - 1 >= 0 && s[ih - 1][iw] != '#') {
    maxx = max(dfs(ih - 1, iw, dist + 1), maxx);
  }
  if (iw + 1 < w && s[ih][iw + 1] != '#') {
    maxx = max(dfs(ih, iw + 1, dist + 1), maxx);
  }
  if (iw - 1 >= 0 && s[ih][iw - 1] != '#') {
    maxx = max(dfs(ih, iw - 1, dist + 1), maxx);
  }

  return maxx;
}

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

  cin >> h >> w;
  memset(dp, -1, sizeof dp);
  s.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      // cをスタートしたときの各点への最短経路を求める
      char c = s[i][j];
      if (c == '.') {
        memset(dp, -1, sizeof dp);

        dfs(i, j, 0);
        int dist = 0;
        for (int ih = 0; ih < h; ih++) {
          for (int iw = 0; iw < w; iw++) {
            dist = max(dp[ih][iw], dist);
          }
        }

        ans = max(ans, dist);
      } else {
        continue;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265

#define MAX 501


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

    string str;
    cin >> str;
    ll k;
    cin >> k;
    int n = str.size();

    for (int i = 0; i < n; i++) {
        if (str[i] != '1') {
            cout << str[i] << endl;
            return 0;
        }
        else if (str[i] == '1' && k <= i + 1) {
            cout << "1" << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}


Measured memory_bytes: 384