akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 998244353
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N=200010;

int main()
{
	ll n;
	cin>>n;
	cout<<n*(n-1)/2;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int c0=0, c1=0;
    rep(i, s.size()){
        if(s[i]=='0'){
            c0++;
        }else{
            c1++;
        }
    }
    printf("%d\n", min(c0, c1)*2);
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;

    ll ans = 0;
    REP(i,0,SZ(S)/2-1) {
        if(S.substr(0,i+1) == S.substr(i+1,i+1)) ans = (i + 1) * 2;
    }
    PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 3636
#include<iostream>

int main(void)
{
	int A, B, C;	//ピザの値段
	int X, Y;

	int X_rest = 0;
	int Y_rest = 0;	// X 枚のAピザと Y 枚のBピザを用意する
	
	int result = 0;

	// 入力
	std::cin >> A >> B >> C >> X >> Y;

	int A_min = (A < C*2) ? A : C*2;
	int B_min = (B < C*2) ? B : C*2;

	//1. 同時買いの話
	if(X > Y){
		// AピザがBピザより多い

		//1. 同時買いの条件
		if(A+B >= 2*C){
			result += 2*C*Y;
		}else{
			//2. 同時買いはできません。
			result += (A+B)*Y;
		}
		// 残り
		X_rest = X - Y;

		result += X_rest * A_min;

	}else if(X < Y){
		// BピザがAピザより多い

		//1. 同時買いの条件
		if(A+B >= 2*C){
			result += 2*C*X;
		}else{
			//2. 同時買いはできません。
			result += (A+B)*X;
		}
		// 残り
		Y_rest = Y - X;

		result += Y_rest * B_min;

	}else{
	// AピザとBピザの枚数が同じとき

		//1. 同時買いの条件
		if(A+B >= 2*C){
			result = 2*C*X;
		}else{
			//2. 同時買いはできません。
			result = A*X + B*Y;
		}
		// 残りはありません
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
max_op = 0
1.upto(31).each do |x|
  d = 2 ** x
  result = 0.upto(n-1).each do |i|
    break false if (a[i] % d) != 0
    true
  end
  max_op = x if result
end
puts max_op

Measured memory_bytes: 1788
N, K = gets.split.map(&:to_i)
A = Hash.new {|h, k| h[k] = 0 }

gets.split.map(&:to_i).each do |i|
  A[i] += 1
end

puts A.size <= K ? 0 : A.values.sort.first(A.size - K).inject(:+)

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

int main()
{
	int A, B, C;

	cin >> A >> B >> C;

	if (C >= A && C <= B)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
s = input()

index = -1
current_index = -1
counter = 0
for i in range(n):
  if 'ABC' in s[i:]:
    current_index = s.index('ABC', i)
    # print(current_index, s[i:])
  if index != current_index:
    counter += 1
    index = current_index
print(counter)

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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

int main() {
    double R;
    cin >> R;
    printf("%.9f\n", 2 * M_PI * R);

    return 0;
}


Measured memory_bytes: 3788
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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(){
    long long L;
    long long R;
    cin >> L >> R;
    long long num=(int) pow(10,9);
    long long res=2019;
    if(R-L>3000) cout << 0 << endl;
    else{
        for(int i=L;i<R;++i){
            for(long long j=i+1;j<=R;++j){
                num=min(num,(i*j)%res);
            }
        }
        cout << num << endl;
    }
    }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int pos;
string s;
int n;
string f();
string expr(){
	//cout<<"-------"<<endl;
	string a=f();
	//cout<<a<<endl;
	while(isdigit(s[pos])||isalpha(s[pos])){
		if(a.size()>n)
		return a;
		a+=f();
	}
	return a;
}
string f(){
	if(isdigit(s[pos])){
		int ret=0;
		for(;isdigit(s[pos]);pos++){
			ret*=10;
			ret+=s[pos]-'0';
		}
		//cout<<ret<<endl;
		string t="";
		string p=f();
		for(int i=0;i<ret;i++){
			t+=p;
			if(t.size()>n)
				return t;
		
		}
		//cout<<t<<endl;
		return t;
	}else if(s[pos]=='('){
		pos++;
		string t=expr();
		pos++;
		return t;
	}else{
		string t="";
		for(;isalpha(s[pos]);pos++){
			t+=s[pos];
			if(t.size()>n)
				return t;
		
		}
		return t;
	}
}
int main(){
	
	while(cin>>s>>n,s!="0"||n){
		pos=0;
		s+="#";
		string t=expr();
		//cout<<t<<endl;
		if(t.size()-1<n)
		cout<<0<<endl;
		else
		cout<<t[n]<<endl;
		
	}
	return 0;
}

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

using namespace std;

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

    long long a, b, k;
    cin >> a >> b >> k;

    long long sub = min(a, k);
    a -= sub;
    b -= min(b, k-sub);
    cout << a << ' ' << b << '\n';

    return 0;
}

Measured memory_bytes: 256
/* Coached by rainboy */
#include <stdio.h>

#define N 500

int main() {
	static int dp[N][N];
	int n, m, t, i, j;

	scanf("%d%d%d", &n, &m, &t);
	while (m--) {
		int l, r;

		scanf("%d%d", &l, &r), l--, r--;
		dp[l][r]++;
	}
	for (i = n - 1; i >= 0; i--)
		for (j = i + 1; j < n; j++)
			dp[i][j] += dp[i + 1][j];
	for (i = n - 1; i >= 0; i--)
		for (j = i + 1; j < n; j++)
			dp[i][j] += dp[i][j - 1];
	while (t--) {
		int p, q;

		scanf("%d%d", &p, &q), p--, q--;
		printf("%d\n", dp[p][q]);
	}
	return 0;
}


Measured memory_bytes: 1792
/*
      H   H
       \ / 	
        C
       / \ 
      H   H
*/

#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include <cmath>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005
double sqrt_newton(double n) {
    const double eps = 1E-18;
    double x = 1;
    for (;;) {
        double nx = (x + n / x) / 2;
        if (abs(x - nx) < eps)
            break;
        x = nx;
    }
    return x;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		double a, b;
		cin >> a >> b;
		double h, m;
		cin >> h >> m;
		double t = ((5.0*h - ((11.0*m)/12.0))*M_PI)/30.0;
		if(t<0.0)
			t = 2.0*M_PI + t;
		if(t>M_PI)
			t = 2.0*M_PI - t;
		double ans = a*a + b*b - 2.0*a*b*cos(t);

		cout << fixed << setprecision(20) << sqrt_newton(ans);
	}
	return 0;
}

Measured memory_bytes: 4176
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a, b;
    cin >> a >> b;
    if(b == 1){
        cout << 0;
        return 0;
    }
    b -= a;
    int cnt = 1;
    int s = 0;
    while(s < b){
        cnt++;
        s += a-1;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	while(cin>>n,n){
		int sum=0;		
		double d=sqrt(n);
		loop(i,2,1e9){
			if(i>d)break;
			if(n%i==0){
				if(i!=n/i)sum+=i+n/i;
				else sum+=i;
			}
			if(n<sum)break;
		}
		if(n!=1)sum++;
		//cout<<n<<" "<<sum<<endl;
		if(sum==n)cout<<"perfect number"<<endl;
		else if(n<sum)cout<<"abundant number"<<endl;
		else cout<<"deficient number"<<endl;
	}
}

Measured memory_bytes: 1156
length = int(input())
eles = [int(l) for l in input().split()]
times = 0

for i in range(length-1):
    _min = i
    for j in range(i, length):
        if eles[j] < eles[_min]:
            _min = j
    if i != _min:
        eles[i], eles[_min] = eles[_min], eles[i]
        times += 1

print(*eles)
print(times)

Measured memory_bytes: 7720
#include<stdio.h>
int main(){
  int i, j;
  char s[1000];

  while( scanf("%s",s) != EOF ){

    for( i=0 ; s[i]!='\0' ; i++ ){
      if( s[i] == '@' ){
	for(j=0 ; j<s[i+1] - '0' ; j++){
	  printf("%c",s[i+2]);
	}
	i=i+2;
      }
      else{
	printf("%c",s[i]);
      }
    }
    printf("\n");
  }

  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v) cin >> i;

    map<int,ll> mp;
    for(auto i : v){
        mp[i]++;
    }

    ll total = 0;
    for(const auto& i : mp){
        total += i.second * (i.second - 1) / 2;
    }

    REP(i, n){
        cout << total - (mp[v[i]] - 1) << '\n';
    }
    return 0;
}


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


//選手のタイムを返す構造体
typedef struct struct_sensyu
{
	int number;
	double time;
}S_sensyu;



int main(void)
{
	//構造体の宣言
	S_sensyu s_sensyu[3][8];

	//tmp実体
	S_sensyu s_tmp , s_tmp2;

	//構造体ポインタ
	S_sensyu *ptr_sensyu = &s_tmp;
	S_sensyu *ptr_sensyu2 = &s_tmp2;

	//考えるのが面倒なので18個構造体を宣言
	S_sensyu s_output2[6];

	//入力
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			cin >> s_sensyu[i][j].number >> s_sensyu[i][j].time;
		}
	}

	//ソート
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 7; j++)
		{
			for (int k = j + 1; k < 8; k++)
			{
				//タイムが早い順に入れ替える
				if (s_sensyu[i][j].time > s_sensyu[i][k].time)
				{
					*ptr_sensyu = s_sensyu[i][j];
					*ptr_sensyu2 = s_sensyu[i][k];
					s_sensyu[i][j] = *ptr_sensyu2;
					s_sensyu[i][k] = *ptr_sensyu;
				}
			}
		}
	}

	//まず最初に出力
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			printf("%d %.2lf\n" , s_sensyu[i][j].number , s_sensyu[i][j].time);
		}
	}

	//カウント変数
	int count = 0;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 2; j <= 3; j++)
		{
			//ポインタを利用して高速化
			*ptr_sensyu = s_sensyu[i][j];
			s_output2[count++] = *ptr_sensyu;
		}
	}

	//再びソート
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 6; j++)
		{
			//タイムが早い順
			if (s_output2[i].time > s_output2[j].time)
			{
				*ptr_sensyu = s_output2[i];
				*ptr_sensyu2 = s_output2[j];
				s_output2[i] = *ptr_sensyu2;
				s_output2[j] = *ptr_sensyu;
			}
		}
	}

	//再び出力
	for (int i = 0; i < 2; i++)
	{
		printf("%d %.2lf\n" , s_output2[i].number , s_output2[i].time);
	}

	return 0;
}

Measured memory_bytes: 1240
#include "bits/stdc++.h"
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n,m;
    cin >> n >> m;
    map<int, int> mp;
    for(int i = 2; i <= m; i++){
        if(m%i == 0){
            mp[i]++;
            m /= i;
            i--;
        }
        if(m == 1) break;
    }
    
    long long ans = 1;
    COMinit();

    for(auto item : mp){
        int b = item.second;
        (ans *= COM(b + n - 1, b)) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  map<ll,ll>mp;
  mp[0]++;
  ll ans=0;
  ll sum=0;
  for(ll i=0;i<n;i++){
    sum+=a[i];
    ans+=mp[sum];
    mp[sum]++;
  }
  cout<<ans<<endl;
}

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

int n, q;
map<int, string> mp;

int main() {
  int i, x;
  string s;
  cin >> n >> q;
  mp[0] = "kogakubu10gokan";
  for(i = 0; i < n; ++i) {
    cin >> x >> s;
    mp[x] = s;
  }
  i = q;
  while(1) {
    if(mp.find(i) != mp.end()) {
      cout << mp[i] << endl;
      break;
    }
    --i;
  }
  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  
  int a,b,c;cin>>a>>b>>c;
  if(a-b==b-c)cout<<"YES"<<endl;
  else cout <<"NO"<<endl;
  
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;

vector<int> P(8);

bool solve(vector<vector<int>> table) {
    rep(i, 8) {
        // yoko
        rep(j, 8) {
            table[i][j]++;
        }
        // tate
        rep(j, 8) {
            table[j][P[i]]++;
        }
        // left naname
        rep(j, 8) {
            if (i - j < 0 || P[i] - j < 0) continue;
            table[i - j][P[i] - j]++;
        }
        rep(j, 8) {
            if (i + j > 7 || P[i] + j > 7) continue;
            table[i + j][P[i] + j]++;
        }
        // right naname
        rep(j, 8) {
            if (i + j > 7 || P[i] - j < 0) continue;
            table[i + j][P[i] - j]++;
        }
        rep(j, 8) {
            if (i - j < 0 || P[i] + j > 7) continue;
            table[i - j][P[i] + j]++;
        }
    }

    bool ans = true;
    rep(i, 8) {
        if (table[i][P[i]] != 6) ans = false;
    }

    return ans;
}

int main()
{
    int k;
    cin >> k;
    vector<int> r(k), c(k);
    rep(i, k) cin >> r[i] >> c[i];

    rep(i, 8) P[i] = i;

    do {
        bool ok = true;
        rep(i, k) {
            if (P[r[i]] != c[i]) ok = false;
        }
        if (!ok) continue;
        vector<vector<int>> table(8, vector<int>(8, 0));
        if (solve(table)) {
            rep(i, 8) {
                rep(j, 8) {
                    if (P[i] == j) {
                        cout << 'Q';
                    }
                    else cout << '.';
                }
                cout << endl;
            }
            return 0;
        }
    } while (next_permutation(all(P)));
    return 0;
}


Measured memory_bytes: 3152
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N, C = 0;
	scanf("%d", &N);
	char S[N];
	for (int i = 0; i < N; ++i) scanf(" %c", &S[i]);
	for (int i = 2; i < N; ++i) {
		if (S[i] == 'C' && S[i - 1] == 'B' && S[i - 2] ==  'A') ++C;
	}
	printf("%d", C);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n,t;
    cin>>n>>t;
    ll ans=t,mi=0;
    ll x;
    cin>>x;
    for(int i=1;i<n;i++)
    {
        cin>>x;
        if(x<=ans){
            ans=x+t;
        }else{
        mi=mi+(x-ans);
        ans=x+t;
        }

    }
    cout<<ans-mi<<endl;

}



Measured memory_bytes: 3600
unittest
{
	assert( [ "3", "3 1 2", "2 5 4", "3 6" ].parse.expand.solve == 14 );
	assert( [ "4", "2 3 4 1", "13 5 8 24", "45 9 15" ].parse.expand.solve == 74 );
	assert( [ "2", "1 2", "50 50", "50" ].parse.expand.solve == 150 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	return tuple( as, bs, cs );
}

auto solve( long[] as, long[] bs, long[] cs )
{
	auto ans = 0L;
	auto p = long.max;
	foreach( a; as )
	{
		ans += bs[ a ];
		if( p + 1 == a ) ans += cs[ p ];
		p = a;
	}
	return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        cin>>n;
        int arr[n+1];
        int xo=0;
        for(i=0;i<n;i++) {
            cin>>arr[i];
            xo^=arr[i];
        }
        if(n==2) {
            cout<<arr[1]<<" "<<arr[0];
        }
        else {
            int brr[n+1];
            for(i=0;i<n;i++) {
                cout<<(xo^arr[i])<<" ";
            }

        }
    }
    return 0;
}

Measured memory_bytes: 5172
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
LL n;
int x, y;
int main()
{
	scanf("%d %d",&x,&y);
	int flag = 0;
	for(int i = 1;i <= 100000000;i++)
	{
		n = i * x;
		if(n % x == 0 && n % y != 0)
		{
			printf("%d\n",n);
			flag = 1;
			return 0;
		}
	}
	if(flag == 0)
	{
		printf("-1\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int G, L;
  cin >> G;
  vector<string> vecG(G);
  rep(i, G) {
    cin >> vecG.at(i);
  }
  cin >> L;
  vector<string> vecL(L);
  rep(i, L) {
    cin >> vecL.at(i);
  }
  int MA = 0;
  int co = 0;
  rep(i, G) {
    rep(j, G) {
      if(vecG.at(i) == vecG.at(j)) {
        co++;
      }
    }
    rep(j, L) {
      if(vecL.at(j) == vecG.at(i)) {
        co--;
      }
    }
    MA = max(MA, co);
    co = 0;
  }
  cout << MA << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main()
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if(a!=b && a!=c) printf("%d", a);
  if(a!=b && b!=c) printf("%d", b);
  if(c!=b && c!=a) printf("%d", c);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

ll n;
vector<char> change={'a','b','c','d','e','f','g','h','i','j'};

void dfs(vector<ll> ans, ll al, ll nex) {
  ans.push_back(nex);
  al=max(al,nex);
  if(ans.size()==n) {
    for(ll i=0;i<n;i++) {
      cout << change[ans[i]];
    }
    cout << endl;
    return;
  }
  for(ll i=0;i<=al+1;i++) {
    dfs(ans,al,i);
  }
}

int main() {
  cin >> n;
  vector<ll> box;
  ll al=0;
  dfs(box,al, 0);
}

Measured memory_bytes: 1536
#include <stdio.h>
int gcd(long long a,long long b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
main(){
  int i,j;
  long long a,b,kb,ky;
  while(scanf("%lld%lld",&a,&b) !=EOF){
    ky=gcd(a,b);
    kb=a*b/gcd(a,b);
    printf("%lld %lld\n",ky,kb); 
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>

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

char str[105];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	for(int i=0;i<n;i++)
	{
		if(str[i]=='C')
		{
			bool up=false;
			for(int j=i+1;j<n;j++) if(str[j]=='F') up=true;
			if(up)
			{
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,y;
  scanf("%d %d",&x,&y);
  if(y<=4*x && y>=2*x)
  {
    if(y%2==0)
      printf("Yes");
    else
      printf("No");
  }
  else
    printf("No");
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < N; i++) ans ^= a[i];
    for (int i = 0; i < N; i++) { cout << (ans ^ a[i]) << (i == N-1 ? '\n' : ' ' ); }
}


Measured memory_bytes: 4028
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int coin=0;
    int day=0;
    while(7){
        if(coin>=c){
            break;
        }
        coin=coin+a;
        day=day+1;
        if(day%7==0){
            coin=coin+b;
        }
    }
    cout<<day<<endl;
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    int cnt = min(A, K);
    ans += cnt;
    K -= cnt;
    cnt = min(B, K);
    K -= cnt;
    cnt = min(C, K);
    ans -= cnt;
    cout << ans << endl;

    return 0;
}


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

int main() {
  long N,tmp;
  long count=0,five;
  cin >> N;
  if(N%2!=0) cout << 0 << endl;
  else{
    tmp = N;
    tmp/=2;
    while(tmp != 0){
      count += tmp/5;
      tmp /= 5; 
    }
    cout << count << endl;
  }
  
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
const int C = 16;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,c;
  while(cin >> n >> c && n && c){
    vector<bitset<C>> a(n),b(c);
    ll ans = 0;
    string s,s2;
    rep(i,n){
      s = "";
      rep(i,C){
        cin >> s2;
        s+= s2;
      }
      a[i] = bitset<C>(s);
    }
    rep(i,c){
      s = "";
      rep(i,C){
        cin >> s2;
        s+= s2;
      }
      b[i] = bitset<C>(s);
    }
    vector<vector<ll>> dp(1 << C,vector<ll>(n+1,0));
    vector<vector<bool>> f(1 << C,vector<bool>(n+1,false));
    f[0][0] = true;
    rep(i,n){
      rep(bfr,1 << C){
        if(f[bfr][i]){
          bitset<C> k(bfr);
          k |= a[i];
          rep(j,c){
            auto cnt = k & b[j];
            auto nxt = k & ~b[j];
            dp[(nxt).to_ulong()][i+1] = max(dp[(nxt).to_ulong()][i+1],dp[bfr][i] + (ll)cnt.count());
            f[(nxt).to_ulong()][i+1] = true;
          }
          if(i == 0) break;
        }
      }
    }
    ans = 0;
    rep(i,1 << C){
      ans = max(ans,dp[i][n]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 25504
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)

for i in range(n):
    cnt[a[i] - 1] += 1
    cnt[a[i] + 1] += 1
    cnt[a[i]] += 1

print(max(cnt.values()))


Measured memory_bytes: 20064
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w,d=LI()
  l=[LI() for _ in range(h)]

  q=I()
  ql=[LI() for _ in range(q)]

  dic={}
  for i in range(h):
    for j in range(w):
      x=l[i][j]
      dic[x]=(i+1,j+1)

  n=h*w
  to_last_distance=[0]*n
  for i in range(1,n+1)[::-1]:
    if i+d<=n:
      i_y,i_x=dic[i]
      ipd_y,ipd_x=dic[i+d]
      to_last_distance[i-1]=to_last_distance[i+d-1]
      to_last_distance[i-1]+=(abs(i_y-ipd_y)+abs(i_x-ipd_x))

  # print(to_last_distance)

  ans=[]
  for st,ed in ql:
    ans.append(to_last_distance[st-1]-to_last_distance[ed-1])

  for x in ans:
    print(x)

main()
# print(main())


Measured memory_bytes: 50556
#include <bits/stdc++.h>
   using namespace std;
   using pii = pair<int, int>;
   using ll = long long;
   #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
   const ll MOD = 1000000007;
   const ll INF = 1LL << 60;

   int main() {
     int N;
     cin >> N;
     vector<vector<int>> G(N);
     vector<pair<int,int>> vp;
     for(int i = 1; i < N; i++){
       int a,b;
       cin >> a >> b;
       a--;b--;
       G[a].emplace_back(b);
       G[b].emplace_back(a);
       vp.emplace_back(a,b);
     }

     int K = 0;
     map<pair<int,int>,int> I;
     vector<int> cs(N,0);

     vector<int> used(N,0);
     queue<int> que;
     used[0] = 1;
     que.emplace(0);
     while(!que.empty()){
       int v = que.front();
       que.pop();
       if (K < (int)G[v].size()) K = G[v].size();
       int cur = 1;
       for (int u : G[v]){
         if (used[u]) continue;
         if (cur == cs[v]) cur++;
         cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
         used[u] = 1;
         que.emplace(u);
       }
     }

     cout<< K << endl;
     for (auto p : vp) cout << I[p] << endl;
   }


Measured memory_bytes: 20084
#include <iostream>
using namespace std;
int main() {
    string s,p,ans="No";
    cin >> s >> p;
    int i,j,ss=s.size(),ps=p.size();
    for (i=0;i<ss;i++) {
        for (j=0;j<ps;j++) {
            if (s[(i+j)%ss] != p[j]) break;
        }
        if (j>=ps) {
            ans="Yes";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define maxN 100009
using namespace std;

int ad[maxN], bd[maxN], cd[maxN];
int main()
{
   int x, y, a, b, c;
   cin >> x >> y >> a >> b >> c;
   for(int i = 0; i < a; i++)
      cin >> ad[i];
   for(int i =0; i < b; i++)
      cin >> bd[i];
   for(int i = 0;i <c; i++)
      cin >> cd[i];
   sort(ad,ad+a);
   reverse(ad, ad+a);
   sort(bd, bd+b);
   reverse(bd,bd+b);
   vector<int> v;
   for(int i =0; i < x; i++)
      v.push_back(ad[i]);
   for(int i =0; i < y; i++)
      v.push_back(bd[i]);
   for(int i = 0; i < c; i++)
      v.push_back(cd[i]);
   sort(v.rbegin(), v.rend());
   long long sum = 0;
   for(int i = 0; i < x+y; i++)
      sum += v[i];

   cout << sum;


   return 0;
}



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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll t = (c-a-b) * (c-a-b);
  if(c -a-b <=0) cout << "No" << endl;
  else if(t > 4*a*b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

// SUB ID: UG02-53-20-001

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if ((n / 100 == 0 || n / 100 > 12) && (n % 100 == 0 || n % 100 > 12)) cout << "NA\n";
  else if (n / 100 == 0 || n / 100 > 12) cout << "YYMM\n";
  else if (n % 100 == 0 || n % 100 > 12) cout << "MMYY\n";
  else cout <<"AMBIGUOUS\n";
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
acc = 0
accs = a.map { |ai| acc += ai }.unshift(0)
old = accs.combination(2).map { |x, y| y - x }
# p old
42.downto(0) do |i|
  ne = old.select { |x| x[i] == 1 }
  old = ne if ne.size >= k
end
puts old.inject(&:&)


Measured memory_bytes: 13736
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		ArrayList<Integer> V = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			V.add(sc.nextInt());
		}
		ArrayList<Integer> C = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			C.add(sc.nextInt());
		}
		ArrayList<Integer> VC = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			VC.add(V.get(i)-C.get(i));
		}
		int total = 0;
		for(int j=0; j < VC.size(); j++) {
			if(VC.get(j) > 0) {
				total = total + VC.get(j);
			}
		}

		System.out.println(total);

	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 23124
def minimum_spanning_tree(adj_mat, cost, color, parent):
    N = len(cost)
    cost[0] = 0
    parent[0] = -1

    while True:
        mincost = 2000000

        for i in range(N):
            if color[i] != "B" and cost[i] < mincost:
                mincost = cost[i]
                cur = i

        if mincost == 2000000:
            break

        color[cur] = "B"

        for v in range(N):
            if color[v] != "B" and adj_mat[cur][v] >= 0:
                if adj_mat[cur][v] < cost[v]:
                    cost[v] = adj_mat[cur][v]
                    parent[v] = cur
                    color[v] = "G"

def Main():
    N = int(input())
    adj_mat = list()
    cost  = [ 2000000 for n in range(N)]
    color = ["W" for n in range(N)]
    parent = [None for n in range(N)]

    for n in range(N):
        adj_mat.append([int(a) for a in input().split()])

    minimum_spanning_tree(adj_mat, cost, color, parent)
    print(sum(cost))

Main()


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

signed main() {
	int n; cin >> n;
	rep(i, 10) {
		if (n <= 111 * i) {
			cout << 111*i << endl; return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans(ll x)
{
	if(x==1)
		return 1;
	return 1+2*ans(x/2);
}
int main()
{
	ll h;
	cin>>h;
	cout<<ans(h);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



////////////////////////////////////////////////////////////////////

template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

int n,m;matrix<int> g;vector<vector<int>> dist;
int ans;
template<typename T>
vector<vector<T>> warshall(matrix<T> &g){
  vector<vector<T>> dist(g.size());
  rep(i,g.size()){
    dist[i].resize(g.size());
    rep(j,g.size())dist[i][j] = (i == j ? 0 : g[i][j]);
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        if(dist[i][k] == INF || dist[k][j] == INF)continue;
        if(dist[i][j] >= dist[i][k] + dist[k][j]){
          dist[i][j] = dist[i][k] + dist[k][j];

        };
      }
    }
  }
  return dist;
}

#define warshall warshall<int>// matの初期化でINFを詰めておく


////////////////////////////////////////////////////////////////////i

signed main(){
  cin>>n>>m;
  g.resize(n, vector<int>(n, INF));
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;a--;b--;
    g[a][b] = g[b][a] = c;
  }
  dist = warshall(g);
  rep(i,n){
    repd(j,i+1,n){
      if(g[i][j] != INF && g[i][j] > dist[i][j]){
        ans++;
      }
    }
  }
  cout << ans << endl;
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

const int MOD = 1000000007;
int main() {
    ll x, k, d; cin >> x >> k >> d;

    if (x < 0) x = -x;
    ll ans = x;
    if (x/d < k)
    {
        ans = x%d;
        if ((x/d)%2 == 0)
        {
            ans = (k%2 == 0) ? ans : abs(ans-d);
        }
        else
        {
            ans = (k%2 == 1) ? ans : abs(ans-d);
        }
    }
    else
    {
        ans = x - k * d;
    }
    

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
using namespace std;

int N;
int main (){
    cin >> N;
    int ans;
    for(int i=1; i<N+1; i++){
        int x = i;
        int b,cnt = 0;
        while( x % 2 == 0){
        if(x <= 0) break;
            x /= 2;
            cnt++;
        }
        if ( cnt > b ) {
            b = cnt;
            ans = i;
        }
    }
    if(N == 1) cout << 1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M=map(int,input().split())
G=[set() for i in range(N)]
for i in range(M):
    x,y=map(int,input().split())
    G[x-1].add(y-1)
K=[0 for i in range(N)]
for i in range(N):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(N) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
dp=[0 for i in range(N)]
for i in range(N-1,-1,-1):
    v=res[i]
    for p in G[v]:
        dp[v]=max(dp[v],dp[p]+1)
print(max(dp))

Measured memory_bytes: 35180
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int h_l[2000][2000];
int h_r[2000][2000];
int h_lr[2000][2000];

int v_u[2000][2000];
int v_d[2000][2000];
int v_ud[2000][2000];
int main(){
  string s[2000];
  int h,w;
  cin >> h >> w;
  REP(i, h){
    cin >> s[i];
  }

  REP(i, h){
    int l = -1;
    REP(j, w){
      if(s[i][j] == '#') l = j;
      h_l[i][j] = l;
    }
  }

  REP(i, h){
    int r = w;
    for(int j = w - 1; j >= 0; j--){
      if(s[i][j] == '#') r = j;
      h_r[i][j] = r;
    }
  }

  REP(i, h){
    REP(j, w){
      h_lr[i][j] = (h_r[i][j] - h_l[i][j] - 1);
    }
  }

  REP(j, w){
    int u = -1;
    REP(i, h){
      if(s[i][j] == '#') u = i;
      v_u[i][j] = u;
    }
  }

  REP(j, w){
    int d = h;
    for(int i = h - 1; i >= 0; i--){
      if(s[i][j] == '#') d = i;
      v_d[i][j] = d;
    }
  }

  REP(j, w){
    REP(i, h){
      v_ud[i][j] = (v_d[i][j] - v_u[i][j] - 1);
    }
  }

  ll int nowmax = -1;

  // REP(i,h){
  //   REP(j,w){
  //     if(s[i][j] == '#') cout << '#';
  //     else cout << h_lr[i][j];
  //   }
  //   cout << endl;
  // }
  // cout << "------ " << endl;

  // REP(i,h){
  //   REP(j,w){
  //     if(s[i][j] == '#') cout << '#';
  //     else cout << v_ud[i][j];
  //   }
  //   cout << endl;
  // }

  REP(i, h){
    REP(j, w){
      if(s[i][j] == '#') continue;
      ll int amount = (v_ud[i][j] + h_lr[i][j] - 1);
      nowmax = max(nowmax, amount);
    }
  }
  cout << nowmax << endl;
}

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

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

typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long int> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvll;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int left = 0;
  int right = 0;
  rep(i, n) {
    if(s[i] == '(') right++;
    if(s[i] == ')') right--;

    if(right < 0) {
      left++;
      right = 0;
    }
  }

  rep(i, left) cout << '(';
  cout << s;
  rep(i, right) cout << ')';
  cout << endl;
}

Measured memory_bytes: 256