akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
  int n;
   cin >> n;
   vector<ll> a(n);
   for(int i = 0; i < n; i++){
     cin >> a[i];
   }

   map<ll,int> p;
   for(int i = 0; i < n; i++){
     p[a[i]]++;
   }
   ll ans = 0;
   for(auto itr = p.begin(); itr != p.end(); ++itr){
      if(itr->second < itr->first) ans += itr->second;
      else ans += itr->second - itr->first;
   }
   cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,a;
  int p[50];
  cin >> N;
  a = 0;
  for (int i; i < N; i++) {
    cin >> p[i];
  }
  for (int i; i < N-1; i++) {
    if( p[i] != i+1 ) a++;
  }
  if ( a <= 2 ) {
  	cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
def bubble_sort(a, n):

    swap_count = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
                swap_count += 1
        i += 1

    print(' '.join(map(str, a)))
    print(swap_count)


def main():
    n = int(input())
    a = list(map(int, input().split(' ')))
    bubble_sort(a, n)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,ans;
    cin>>n;
    ans=n/2;
    if(n%2==0) ans--;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define DB(x){if(DEBUG)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(LL i=(0);i<(b);++i)
#define FOR(i,a,b)for(LL i=(a);i<=(b);++i)
#define FORD(i,a,b)for(LL i=(a);i>=(b);--i)
#define ALL(x) (x).begin(),(x).end()
#define VV vector
template<typename X,typename Y>void MAX(X&a,Y b){a=(a>=b?a:b);}
template<typename X,typename Y>void MIN(X&a,Y b){a=(a<=b?a:b);}
typedef long long LL;typedef long double LD;
int DEBUG=0,MULTI=0,GCJ=0;

struct solver_t;solver_t *solver;
struct solver_t {


  void solve() {
    int N; cin >> N;
    VV <LL> A(N), B(N);
    REP (i, N) cin >> A[i];
    REP (i, N) cin >> B[i];

    LL addL = 0, addR = 0;
    REP (i, N) {
      LL diff = A[i] - B[i];
      if (diff > 0) {
        int useB = min(diff, addR);
        diff -= useB;
        B[i] += useB;
        addR -= useB;

        addL += 2 * diff;
        addR += 0;
        B[i] += diff;

        DB(addL<<" "<<addR);
      }
      else if (diff < 0) {
        diff = -diff;
        diff = (diff + 1) / 2 * 2;
        int useA = min(diff, addL);
        diff -= useA;
        A[i] += useA;
        addL -= useA;

        addL += 0;
        addR += diff / 2;
        A[i] += diff;
        assert(diff % 2 == 0);

        i--;
        DB(addL<<" "<<addR);
        continue;
      }
    }
    REP (i, N) DB(A[i]<<" "<<B[i]);
    DB(addL<<" "<<addR);
    if (addL <= addR) {
      cout << "Yes\n";
    }
    else {
      cout << "No\n";
    }
  }
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  FOR(i,1,argc-1)for(int j=0;argv[i][j];j++)if(argv[i][j]=='.')freopen(argv[i],"r",stdin);
  FOR(i,1,argc-1)if(argv[i]==string("q"))DEBUG=1<<30;
  FOR(i,1,argc-1)if(argv[i]==string("gen")){(solver=new solver_t())->gen();exit(0);}
  FOR(i,1,argc-1)if(argv[i]==string("brute")){(solver=new solver_t())->brute();exit(0);}
  ios::sync_with_stdio(false),cin.tie(0);
  cout.setf(ios::fixed),cout.precision(10);int t;if(MULTI||GCJ)cin>>t;else t=1;
  FOR(i,1,t){if(DEBUG)cerr<<__LINE__<<" "<<i<<endl;if(GCJ)cout<<"Case #"<<i<<": ";
    solver = new solver_t();
    solver->solve();
  }return 0;
}



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

int main() {
  int s;
  cin >> s;
  vector<int> a(1);
  a.push_back(s);
  
  int flag = 0;
  while (flag < 2) {
    if (a[a.size() - 1] % 2 == 0) a.push_back(a[a.size() - 1] / 2);
    else a.push_back(3 * a[a.size() - 1] + 1);
    if (a[a.size() - 1] == 1) flag++;
  }

  int ans = 0;
  for (int n = 1; n < a.size(); n++) {
    for (int m = n + 1; m < a.size(); m++) {
      if (a[m] == a[n]) {
        ans = m;
        break;
      }
    }

    if (ans) break;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import math

n=int(input())
mod = 10**9+7

def get_sieve_of_eratosthenes(n):
    if n==1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

# エラトステネスの篩を使い、素数のリストを作る
E=get_sieve_of_eratosthenes(n)
# 素数の数を数える
l=len(E)
#print("len(e): ",l)

# カウンタ
co=1
# 0から素数までの値で、nを何回割れるかを数える
for e in E:
    co_sub=1
    # 対数。n=25,e=5の時,2を返す(5**"2"==25)
    l_sub=int(math.log(n,e))
    # 対数の数だけ繰り返す
    for j in range(1,l_sub+1):
        # 割れる回数をカウンタに追加
        co_sub+=n//(e**j)
    co*=co_sub
    # 大きすぎるのでmodのあまりにする
    co%=mod
    #print(co_sub)
print(co)


Measured memory_bytes: 38640
N =  int(input())
A =  [list(map(int, (input().split(' ')))) for i in range(N)]

hoge = [sum(a) for a in A]
fuga = [a[0] - a[1] for a in A]
print(max(max(hoge) - min(hoge), max(fuga) - min(fuga)))


Measured memory_bytes: 61260
#include <bits/stdc++.h> 
using namespace std;
 
typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	int A, B;
	cin >> A >> B;
	if((A + B) == 3) printf("3\n");
	else if((A + B) == 4) printf("2\n");
	else printf("1\n");
    return 0;
}

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


void solve(std::string S){
  vector<int> ans(S.size());
  vector<int> flip;
  vector<int> flipL;

  char current = S[0];
  for (int i=1, len=S.size(); i<len; ++i) {
    if (current != S[i]) {
      flip.push_back(i);
      if (i > 0)
        flipL.push_back(i-1);
    }
    current = S[i];
  }

  for (int i=0, len=S.size(); i<len; ++i) {
    if (S[i] == 'R') {
      //auto start_itr = lower_bound(flip.begin(), flip.end(), i);
      auto start_itr = upper_bound(flip.begin(), flip.end(), i);
      if (start_itr != flip.begin()) start_itr--;
      auto flip_itr = lower_bound(start_itr, flip.end(), i+1);

      if (flip_itr >= flip.end()) continue;

      int j = *flip_itr - i;

      //std::cout << i << " th loop: process R, j = " << j << std::endl;

      if (j % 2 == 0) { // stay in 'L' after 10^n transition
        ans.at(i+j)++;
      } else {
        ans.at(i+j-1)++;
      }
    } else { // S[i] == 'L'
      auto flip_itr = lower_bound(flipL.begin(), flipL.end(), i);
      flip_itr--;

      if (flip_itr < flipL.begin()) continue;

      int j = i - *(flip_itr);

      //std::cout << i << " th loop: process L, j = " << j << std::endl;

      if (j % 2 == 0) {
        ans.at(i-j)++;
      } else {
        ans.at(i-j+1)++;
      }
    }
  }

  for (int i=0, len=ans.size(); i<len; ++i) {
    std::cout << ans.at(i);
    if (i != len-1)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,t;cin >> k >> t;
	vector<int> a(t);
	rep(i,t) cin >> a.at(i);
	if(t==1){
		cout << k-1 << endl;
		return 0;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	int ans=a[0]-a[1];
	for(int i=2;i<t;++i){
		ans=abs(ans-a[i]);
	}
	cout << max(ans-1,0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashSet;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n,flag;
        flag=0;
        n= scan.nextInt();
        HashSet<String>hs = new HashSet<String>();
        for(int i=0;i<n;i++){
            hs.add(scan.next());
        }
        if(n==hs.size()) System.out.printf("YES");
        else System.out.printf("NO");
    }
}

Measured memory_bytes: 77684
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a+b>c+d)
{
    cout<<"Left"<<endl;
}
else if(a+b<c+d)
    {
        cout<<"Right"<<endl;
    }
else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
vector<vector<vector<double> > >dp;
double dfs(int a,int b,int c) {
	if(dp[a][b][c]>-1) return dp[a][b][c];
	if(a==0&&b==0&&c==0) return 0;
	dp[a][b][c]=(double)N/(a+b+c);
	if(a>0) dp[a][b][c]+=(double)a/(a+b+c)*dfs(a-1,b,c);
	if(b>0) dp[a][b][c]+=(double)b/(a+b+c)*dfs(a+1,b-1,c);
	if(c>0) dp[a][b][c]+=(double)c/(a+b+c)*dfs(a,b+1,c-1);
	return dp[a][b][c];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	vector<int>cnt(3);
	for(int i=0,a;i<N;i++) {
		cin>>a;
		cnt[a-1]++;
	}
	dp.resize(N+1,vector<vector<double> >(N+1,vector<double>(N+1,-1)));
	dp[0][0][0]=0;
	cout<<setprecision(15)<<dfs(cnt[0],cnt[1],cnt[2])<<'\n';
	return 0;
}


Measured memory_bytes: 219956
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    string str;
    while(cin>>str){
    if(str=="0") break;
    int size=str.size();
    int a[1000];
    int ans=0;
    for(int k=0;k<size;k++){
        a[k]=str[k]-'0';
    }
    for(int i=0;i<size;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

Measured memory_bytes: 3196
import numpy as np
N = int(input())
SList = []
PList = []
dic = {}
Slist = []
aa = []
for _ in range(N):
    S, P = input().split()
    dic[S] = int(P)
    Slist.append(S)
    aa.append((int(P), S))
dic = sorted(dic.items())

sortedS = list(sorted(set(Slist)))

for i in range(len(sortedS)):
    tempV = []
    tempI = []
    for j in range(N):
        if aa[j][1] == sortedS[i]:
            tempV.append(aa[j][0])
            tempI.append(j)
    indexList = np.argsort(tempV)
    for k in reversed(indexList):
        print(tempI[k] + 1)

Measured memory_bytes: 12504
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // ***  問題のpathを記載 ***
    // https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1/ITP1_1_D

    // 標準入力から値を取得
    // 入力数がN個の場合
    int array[9];
    for (int i = 0; i < 9; i++)
    {
        cin >> array[i];
    }
    int n;
    cin >> n;
    int values[n];
    for (int i = 0; i < n; i++)
    {
        cin >> values[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            if (values[i] == array[j])
            {
                // 値がありました
                array[j] = 0;
            }
        }
    }

    // 判定
    // 横
    if (array[0] == 0 && array[3] == 0 && array[6] == 0)
    {
        puts("Yes");
    }
    else if (array[1] == 0 && array[4] == 0 && array[7] == 0)
    {
        puts("Yes");
    }
    else if (array[2] == 0 && array[5] == 0 && array[8] == 0)
    {
        puts("Yes");
    }

    // 縦
    else if (array[0] == 0 && array[1] == 0 && array[2] == 0)
    {
        puts("Yes");
    }
    else if (array[3] == 0 && array[4] == 0 && array[5] == 0)
    {
        puts("Yes");
    }
    else if (array[6] == 0 && array[7] == 0 && array[8] == 0)
    {
        puts("Yes");
    }

    // 斜め
    else if (array[0] == 0 && array[4] == 0 && array[8] == 0)
    {
        puts("Yes");
    }
    else if (array[2] == 0 && array[4] == 0 && array[6] == 0)
    {
        puts("Yes");
    }
    else{
        puts("No");
    }

    // 成功時は必ず0を返す
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

vector<int> board( 9 );
set< vector<int> > reachedState;

void PrintBoard() {
    for ( int row=0; row<3; ++row ) {
	for ( int col=0; col<3; ++col ) cout << board[row*3+col];
	cout << endl;
    }
}

bool IsReachedState( const vector<int>& b ) {
    return reachedState.find( b ) != reachedState.end();
}

void RegisterState( const vector<int>& b ) {
    reachedState.insert( b );
}

bool IsCompleted( const vector<int>& b ) {
    for ( int i=0; i<8; ++i ) {
	if ( b[i] != i+1 ) return false;
    }
    return b[8] == 0;
}

int main() {

    const int dx[4] = { -1, 0, 1,  0 };
    const int dy[4] = {  0, 1, 0, -1 };
    
    int x, y;
    for ( int i=0; i<3; ++i ) {
	for ( int j=0; j<3; ++j ) {
	    cin >> board[i*3+j];
	    if ( board[i*3+j] == 0 ) {
		y = i;
		x = j;
	    }
	}
    }

    //    PrintBoard();

    queue< pair<vector<int>,int> > stateQue;
    stateQue.push( make_pair(board, 0) );

    while ( !stateQue.empty() ) {

	vector<int> state = stateQue.front().first;
	int step = stateQue.front().second;
	stateQue.pop();

	if ( IsCompleted( state ) ) {
	    cout << step << endl;
	    board = state;
	    //	    PrintBoard();
	    break;
	}

	if ( IsReachedState( state ) ) continue;
	RegisterState( state );

	int x, y;
	for ( int i=0; i<9; ++i ) {
	    if ( state[i] == 0 ) {
		x = i%3;
		y = i/3;
		break;
	    }
	}
	
	for ( int i=0; i<4; ++i ) {

	    int nx = x + dx[i];
	    int ny = y + dy[i];

	    if ( nx < 0 || nx > 2 || ny < 0 || ny > 2 ) continue;

	    vector<int> next = state;
	    swap( next[3*y+x], next[3*ny+nx] );
	    stateQue.push( make_pair( next, step+1 ) );
	    
	}
	
    }
    
    return 0;
}



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

ll simulate(int n, vector<ll> v) {
    int ans = 0;
    while (*max_element(v.begin(), v.end()) >= n) {
        ans++;
        rep(i, n) v[i]++;
        *max_element(v.begin(), v.end()) -= (n + 1);
    }
    return ans;
}

class Q {
    priority_queue<ll> q;
    ll up_count = 0;
public:
    void push(ll l) {
        q.push(l - up_count);
    }

    void pop() {
        q.pop();
    }

    ll top() {
        return q.top() + up_count;
    }

    void up(ll k) {
        up_count += k;
    }
};


int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    Q q;
    rep(i, n) q.push(v[i]);

    ll ans = 0;
    while (q.top() >= n) {
        ll top = q.top();
        ll c = top / n;
        ans += c;
        q.pop();
        top -= n * c;
        q.up(c);
        q.push(top);
    }
    cout << ans << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, t; cin >> n >> t;
        vector<int> a(n); cin >> a;
        a.emplace_back(2e9 + 1);
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
                ans += min(t, a[i] - a[i - 1]);
        }

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 4584
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;

int main() {
	int A, B; cin >> A >> B;
	string s; cin >> s;
	bool flag = true;
	for (int i = 0; i < s.size(); i ++) {
		if (i == A) {
			if (s[i] != '-') flag = false;
		} else if (!isdigit(s[i])) flag = false;
	}
	if (flag) cout << "Yes\n";
	else cout << "No\n";
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Possible":"Impossible")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int a,b;
	bool ans=false;
	cin >>a>>b;

	cout<<solve(a%3==0 or b%3==0 or (a+b)%3==0)<<endl;
}

Measured memory_bytes: 256
def comb(n, max_k, mod):
    """
    (n,k) := n個からk個選ぶ組み合わせ
    k = 0~max_Kまでを計算して返す
    """
    res = [1]*(max_k+1)
    t = 1
    for i in range(max_k+1):
        res[i] *= t
        t *= n-i
        t %= mod

    n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
    n = modinv(n, mod)

    for i in reversed(range(max_k+1)):
        res[i] *= n
        res[i] %= mod
        n *= i
        n %= mod
    return res

N,P = map(int,input().split())

A = map(int,input().split())

evens = 0
odds = 0

for a in A:
    if a%2:
        odds += 1
    else:
        evens += 1


cnt = 0
if P == 0:
    comb = 1
    cnt = 1
    for n in range(2,odds+1,2):
        comb *= (odds+2-n)*(odds+1-n)
        comb //= n*(n-1)
        cnt += comb
else:
    comb = odds
    cnt = odds
    for n in range(3,odds+1,2):
        comb *= (odds+2-n)*(odds+1-n)
        comb //= n*(n-1)
        cnt += comb

print(2**evens * cnt)

Measured memory_bytes: 9176
class TreeNode:
  def __init__(self, val):
    self.val = val
    self.left = None
    self.right = None

class Bst:
  def __init__(self):
    self.root = None

  def insert(self, val):
    node = TreeNode(val)
    if self.root is None: 
      self.root = node
      return

    cur_parent = None
    cur_root = self.root

    while cur_root is not None:
      cur_parent = cur_root
      if val > cur_root.val:
        cur_root = cur_root.right
      else:
        cur_root = cur_root.left

    if val > cur_parent.val:
      cur_parent.right = node
    else:
      cur_parent.left = node

  def find(self, val):
    cur_node = self.root

    while cur_node is not None:
      if cur_node.val == val:
        return cur_node
      elif cur_node.val > val:
        cur_node = cur_node.left
      else:
        cur_node = cur_node.right

    return False

  def minValueNode(self, node): 
    current = node 
  
    # loop down to find the leftmost leaf 
    while(current.left is not None): 
        current = current.left  
  
    return current

  def delete(self, root, val):
    if root is None: 
      return root
    elif val < root.val:
      root.left = self.delete(root.left, val)
    elif val > root.val:
      root.right = self.delete(root.right, val)
    else:
      # Node with only one child or no child 
      if root.left is None: 
        temp = root.right  
        root = None 
        return temp  

      elif root.right is None: 
          temp = root.left  
          root = None
          return temp 

      # Node with two children: Get the inorder successor 
      # (smallest in the right subtree) 
      temp = self.minValueNode(root.right) 

      # Copy the inorder successor's content to this node 
      root.val = temp.val 

      # Delete the inorder successor 
      root.right = self.delete(root.right, temp.val) 

    return root  

  def print(self):
    self.inorder = []
    self.preorder = []
    self.inorder_dfs(self.root)
    self.preorder_dfs(self.root)

    print(" " + " ".join([ str(i) for i in self.inorder ]))
    print(" " + " ".join([ str(i) for i in self.preorder ]))

  def inorder_dfs(self, root):
    if not root: return

    self.inorder_dfs(root.left)
    self.inorder.append(root.val)
    self.inorder_dfs(root.right)

  def preorder_dfs(self, root):
    if not root: return

    self.preorder.append(root.val)
    self.preorder_dfs(root.left)
    self.preorder_dfs(root.right)


n = int(input())
bst = Bst()
for _ in range(n):
  ins = list(map(str, input().split()))
  order = ins[0]
  if order == "insert":
    val = int(ins[1])
    bst.insert(val)
  elif order == "find":
    val = int(ins[1])
    if not bst.find(val):
      print("no")
    else:
      print("yes")
  elif order == "delete":
    val = int(ins[1])
    bst.delete(bst.root, val)
  elif order == "print":
    bst.print()





Measured memory_bytes: 121632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n;
  cin >> n;
  ll ans=inf;
  for(ll i=1;i*i<=n;i++){
    if(n%i!=0)continue;
    ll digit=0;
    ll temp=n/i;
    while(temp>0){
      digit++;
      temp/=10;
    }
    ans=min(ans,digit);
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int x,y,z,a;
    scanf("%d %d %d", &x, &y, &z);
    
    a = x;
    x = z;
    z = y;
    y = a;

    printf("%d %d %d", x,y,z);

    
    return 0;
}






Measured memory_bytes: 1680
#include<iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;

    if (a==b){
      cout << "a == b" << endl;
      return 0;
    } else if (a>b){
      cout << "a > b" << endl;
      return 0;
    } else if (a<b){
      cout << "a < b" << endl;
      return 0;
    }
    
    return 0;
}   


Measured memory_bytes: 3096
#include<stdio.h>

int main() {
    int n, i, j, l, a;
    
    int points[7][5];
    for(i=0;i<7;i++)for(j=0;j<5;j++) points[i][j] = 5*i + (j+1);
    
    scanf("%d", &n);
    
    for(i=0;i<n;i++) {
        scanf("%d %d", &l, &a);
        
        printf("%d", points[a/30][l/100-1]);
        if(l%100>0) printf(" %d", points[a/30][l/100]);
        if(a%30>0) printf(" %d", points[a/30+1][l/100-1]);
        if(l%100>0 && a%30>0) printf(" %d", points[a/30+1][l/100]);
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
int main(void)
{
    int a,b,c,d,h1,h2,h3,k1,k2,k3;
	scanf("%d %d",&h1,&h2);
	scanf("%d %d",&k1,&k2);
	scanf("%d %d %d %d",&a,&b,&c,&d);
	h1=h1*a;
	k1=k1*a;
	h2=h2*b;
	k2=k2*b;
	if(h1>=a*10){
	    h3=h1/(a*10);
		h1=h1+h3*c;
	}
	if(k1>=a*10){
	    k3=k1/(a*10);

		k1=k1+k3*c;
	}
	if(h2>=b*20){
	    h3=h2/(b*20);
		h2=h2+h3*d;
	}
	if(k2>=b*20){
	    k3=k2/(b*20);
		k2=k2+k3*d;
	}

	h3=h1+h2;
	k3=k1+k2;
	if(h3>k3){
		printf("hiroshi\n");
	}
	else if(h3<k3){
	    printf("kenjiro\n");
	}
	else{
	    printf("even\n");
	}
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int H, W;
int a[500][500];

P getXY(int xy) {
  int y;
  if((xy / W) % 2 == 0) y = xy % W;
  else y = W - (xy % W + 1);
  return P(xy / W, y);
}

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

  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> a[i][j];

  vector<int> ans;
  REP(i, H * W - 1) {
    P xy = getXY(i);
    if(a[xy.first][xy.second] % 2 != 0) {
      a[xy.first][xy.second] -= 1;
      P nxy = getXY(i + 1);
      a[nxy.first][nxy.second] += 1;
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;
  REP(i, ans.size()) {
    P xy = getXY(ans[i]);
    P nxy = getXY(ans[i] + 1);
    cout << xy.first + 1 << " " << xy.second + 1 << " ";
    cout << nxy.first + 1 << " " << nxy.second + 1 << endl;
  }
}


Measured memory_bytes: 3704
/* Reversing Numbers */
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);

    int w[n], i;
    for(i=0; i<n; i++){
        scanf("%d",&w[i]);
    }
    for(i=n-1; i>=1; i--){
        printf("%d ", w[i]);
    }
    printf("%d\n", w[i]);
    return 0;
}


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

int main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif // LC
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) {
        cout << "Zero";
    } else {
        int neg = 0;
        if (a < 0) {
            assert(b < 0);
            neg = b - a + 1;
        }
        if (neg % 2) {
            cout << "Negative";
        } else {
            cout << "Positive";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	int n; cin >> n;
	double x; string str;
	double ans = 0;
	rep(i, n) {
		cin >> x >> str;
		if (str == "JPY")ans += x;
		else ans += 380000 * x;
	}
	cout << ans << endl;
	return 0;
}

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

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

    auto appearances = vector<int>(N);
    for (auto i = 0; i < M; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;

        appearances[a]++;
        appearances[b]++;
    }

    auto all_even = true;
    for (const auto x : appearances)
        all_even &= x % 2 == 0;

    cout << (all_even ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);

int main(){
  int n;ll k;cin>>n>>k;
  vector<int> s(n), t(n), a(n);
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  for(int i=0;i<n;i++){
  	for(int j=0;j<n;j++){
      if(a[i]<=a[j])continue;
      if(i<j){
      	s[i]++;t[i]++;
      }else if(i>j){
      	s[i]++;
      }
    }
  }
  ll ans=(ll)0;
  for(int i=0;i<n;i++){
    ll si = (ll)s[i];
    ll ti = (ll)t[i];
    ll num = k*ti;
    num += ((k*(k-(ll)1)/(ll)2)%ll(1e9+7))*si;
  	ans += num % ll(1e9+7);
    ans %= ll(1e9+7);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	k := getNextInt64(scanner)
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	if b-a <= 2 || k <= a {
		fmt.Fprintln(writer, k+1)
		return
	}

	k -= a - 1
	ans := (k>>1)*(b-a) + a
	if k%2 == 1 {
		ans++
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
 
int main(){
  ll N;
  string A,B,C;
  cin>>N>>A>>B>>C;
  ll num=0;
  for(int i=0;i<N;++i){
    if(A[i]==B[i]){
      if(A[i]==C[i]){
        
      }else{//A==B!=C
        num++; 
      }
    }else{
      if(A[i]==C[i]){//A==C!=B
        num++;
      }else{//C!=A!=B
        if(B[i]==C[i]){
          num++;
        }else{
          num+=2;
        }
      }
    }
  }
  cout<<num<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();

		if(num < 1200) {
			System.out.println("ABC");
		}else if(num < 2800) {
			System.out.println("ARC");
		}else {
			System.out.println("AGC");
		}
	}

}


Measured memory_bytes: 21204
N, M = gets.strip.split(/\s+/).map(&:to_i)
if N >= M then puts 0; exit end
i = gets.strip.split(/\s+/).map(&:to_i).sort
d = i.each_cons(2).map{|a,b| b-a }
di = d.length.times.sort_by{|i| d[i] }
puts di.take(di.length-N+1).inject(0){|sum,i| sum+d[i] }


Measured memory_bytes: 16224
n,m = map(int,input().split())
h = list(map(int,input().split()))

noset = set([])
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] == h[b-1]:
        noset.add(a)
        noset.add(b)
    elif h[a-1] > h[b-1]:
        noset.add(b)
    elif h[a-1] < h[b-1]:
        noset.add(a)

print(n-len(noset))

Measured memory_bytes: 85264
/* 
   AOJ 1188
   Hierarchical Democaracy
*/


#include<stdio.h>
#include<stdlib.h>

#define MAX_STR 10001

typedef struct block
{
  int majority, child_num;
  struct block *children[MAX_STR];
}block;


char str[MAX_STR];
int p;



block* new(void)
{
  block* ret = malloc(sizeof(block));
  ret->majority = 0;
  ret->child_num = 0;
  return ret;
}

int parse_num(void)
{
  int ret = 0, n;
  while('0' <= str[p] && str[p] <= '9')
    {
      n = str[p] - '0';
      ret = ret * 10 + n;
      p++;
    }
  return ret;
}

block* parse_block(void)
{
  block* ret = new();
  p++;
  if(str[p] == '[')
    {
      while(str[p] == '[')
	{
	  ret->children[ret->child_num] = parse_block();
	  ret->child_num++;
	  p++;
	}
    }
  else if('0' <= str[p] && str[p] <= '9')
    {
      ret->majority = (parse_num() / 2) + 1;
    }
  return ret;
}

int comp(const void *a, const void *b)
{
  int x = *(int *)a;
  int y = *(int *)b;

  if(x < y)
    return -1;
  else
    return 1;
}

int solve(block* b)
{
  int i;
  int majority_arr[MAX_STR];

  if(b->majority == 0)
    {
      for(i = 0; i < b->child_num; i++)
	majority_arr[i] = solve(b->children[i]);
      qsort(majority_arr, b->child_num, sizeof(int), comp);
      for(i = 0; i < (b->child_num / 2) + 1; i++)
	b->majority += majority_arr[i];
    }

  return b->majority;
}


void free_blocks(block* b)
{
  int i;
  if(b->child_num != 0)
      for(i = 0; i < b->child_num; i++)
	free_blocks(b->children[i]);
  free(b);
  return ;
}

void init(block* head)
{
  free_blocks(head);
  p = 0;
}

int main(void)
{
  int n, i;
  block *head;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%s", str);
      head = parse_block();
      printf("%d\n", solve(head));
      init(head);
    }
  return 0;
}

Measured memory_bytes: 14024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,i;cin>>a;
  for(i=1;i<=a/2;i=i*2);   //iは1以上、a以下で最大の2^xを求める、i→2,4,8,16,,,i<=a/2と2で割らないと、一段階前のiについて調べてしまい、結果としてaより大きい答えを出してしまう
  cout<<i<<endl;}


Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
Ans = 0
for b in B:
    Ans += bisect.bisect_left(A,b) * (N - bisect.bisect_right(C,b))
print(Ans)

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

/* function */
//  - none - 


/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int N;       // input
  int ans;     // output

  int i, j, k; // subscript
  int count;
  int comp; // comparison
  int max_data;


  /* Input, Array_Proclamation */
  cin >> N;
  vector<int> A(N);
  vector<int> X;

  for(i=0; i<N; i++)
  {
    cin >> A.at(i);
  }


  /* Initialize */
  ans = 0;
  count = 0;



  /* Calculation */
  for(i=0; i<N; i++)
  {
    for( j = A.at(i) -1; j <= A.at(i) +1; j++)
    {
      X.push_back(j);
    }
  }

  sort( all(X) );

  max_data = X.at( X.size()-1 );
  vector<int> X_cnt( (max_data +1), 0 ); // X==A.at(i) となる数字の数

  comp = X.at(0);
  for(i=1; i<N*3; i++)
  {

    if( comp >= 0 )
    {
      if( comp < X.at(i) )
      {
        X_cnt.at( X.at(i) ) = 1;
      }
      else if( comp == X.at(i) )
      {
        X_cnt.at( X.at(i) )++;
      }
    }

    comp = X.at(i);
    
  }
  

  sort( all(X_cnt) );
  ans = X_cnt.at( X_cnt.size() -1 );

  /* Output */
  cout << ans << endl;


  return 0;

}


/* entity */
//  - none -




Measured memory_bytes: 2804
#include<stdio.h>

int main(void){
	int a[4],b[4],hit,blow,i,l;
	
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		hit=blow=0;
		
		for(i=0;i<4;i++){
			for(l=0;l<4;l++){
				if(a[i]==b[l]){
					if(i==l)hit++;
					if(i!=l)blow++;
				}
			}
		}
		
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 0
<>;
@a=glob<>;
$l=$a[0];
$l=&f($l,$_) for @a;
print $l;
sub f{
    my ($a, $b) = @_;
    ($a,$b)=($b,$a) if ($a>$b);
    until($a==0){
        ($a,$b)=($b%$a,$a);
    }
    return $b;
}

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

int N, M, X[100000], A[100000], B[100000], Y[100000];

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    vector<int64_t> wt;
    vector<int> es;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        wt.resize(n);
        es.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
            wt[i] = X[i];
            es[i] = 0;
        }
    }

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

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]){
            par[x] = y;
            sz[y] += sz[x];
            wt[y] += wt[x];
            es[y] += es[x];
        }else{
            par[y] = x;
            sz[x] += sz[y];
            wt[x] += wt[y];
            es[x] += es[y];
        }
    }

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

    int64_t weight(int x){
        return wt[find(x)];
    }

    void add_edge(int x){
        x = find(x);
        es[x]++;
    }

    int result_edge(int x){
        x = find(x);
        int ret = es[x];
        es[x] = 0;
        return ret;
    }
};

int main(){
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> X[i];
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i] >> Y[i];
        A[i]--; B[i]--;
    }

    vector<int> order;
    for(int i=0; i<M; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int a, int b){ return Y[a] < Y[b];});

    int use = 0;
    UnionFind uf(N);
    for(int i : order){
        uf.unite(A[i], B[i]);
        int64_t weight = uf.weight(A[i]);
        uf.add_edge(A[i]);

        if(weight >= Y[i]){
            use += uf.result_edge(A[i]);
        }
    }

    int ans = M - use;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4344
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[100001];
int b[100001];
int cmp(const void *x,const void *y)
{
  return (*(int*)x) - (*(int*)y);
}
int main()
{
  int d,n,m,i,j,k,l;
  for(;;){
    scanf("%d",&d);
    if(d==0) break;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    scanf("%d\n%d",&n,&m);
    for(i=1;i<n;i++){
      scanf("%d",&a[i]);
    }
    a[n] = d;
    for(i=0;i<m;i++){
      scanf("%d",&b[i]);
    }
    qsort(a,n+1,sizeof(int),cmp);
    qsort(b,m,sizeof(int),cmp);
    l = 0;
    k = 0;
    for(i=0;i<m;i++){
      while(b[i] > a[k]) {
	k++;
      }
      if(b[i] == a[k]) continue;
      if(a[k] - b[i] < b[i] - a[k-1]) l += a[k] - b[i];
      else l += b[i] - a[k-1];
    }
    printf("%d\n",l);
  }
  return 0;
}

Measured memory_bytes: 1548
#include<iostream>
using namespace std;
typedef long long ll;
ll n;

void solve(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			cout << " " << i;
			solve(n / i);
			return;
		}
	}
	cout << " " << n;
	return;
}
int main() {
	cin >> n;
	cout << n << ":";
	solve(n);
	cout << endl;
}


Measured memory_bytes: 3112
<?php
define('WALL', '#');
define('ROAD', '.');
fscanf(STDIN, '%d %d', $h, $w);
for ($i  = 0; $i < $h; $i++) {
    $s[] = str_split(trim(fgets(STDIN)));
}
for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
        $cnt_down = $cnt[$i - 1][$j] ?? 0;
        $cnt_right = $cnt[$i][$j - 1] ?? 0;
        if ($s[$i][$j] === WALL && $s[$i - 1][$j] !== WALL) $cnt_down++;
        if ($s[$i][$j] === WALL && $s[$i][$j - 1] !== WALL) $cnt_right++;

        if ($i === 0) {
            $cnt[$i][$j] = $cnt_right;
        } elseif ($j === 0) {
            $cnt[$i][$j] = $cnt_down;
        } else {
            $cnt[$i][$j] = min($cnt_down, $cnt_right);
        }
    }
}
echo $cnt[$h - 1][$w - 1];

Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,A,B;
    cin >> N >> A >> B;
    long long sum=A+B;
    long long ans=N/sum;
    if(N%sum<=A){
        cout << N-B*ans << endl;
    }else{
        cout << A*(ans+1) << endl;
    }
}

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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

double arr[200005] ;

int main()
{
    ll n, k, x, temp, j = 0 ;
    double ans = 0, sum = 0 ;
    cin >> n >> k ;

    for (int i = 0; i < n; i++) {
        scanf("%lld", &x) ;
        temp = (x * (x + 1) ) / 2 ;
        arr[i] = double(temp) / double(x) ;
    }

    for (int i = 0; i < n; i++) {
        if (i < k) {
            sum += arr[i] ;
        }
        else {
            sum -= arr[j++] ;
            sum += arr[i] ;
        }
        ans = max(ans, sum) ;
    }

    cout << fixed << setprecision(12) << ans << endl ;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
using namespace std;

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

int gcd(vector<int> a) {
    int ans = a[0];
    FOR(i, 1, a.size()) { ans = gcd(ans, a[i]); }

    return ans;
}

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

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

    int ans = gcd(A);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

static const int N = 1000;

int lcs(string X, string Y)
{
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;

    X = ' ' + X;    // X[0] に空白を挿入
    Y = ' ' + Y;    // Y[0] に空白を挿入
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main()
{
    string s1, s2;
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }

    return 0;
}


Measured memory_bytes: 7060
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int a, b, c, d;
  string s;
  cin >> s;
  a = s[0]-'0';
  b = s[1]-'0';
  c = s[2]-'0';
  d = s[3]-'0';

  vi vb, vc, vd;
  
  vb.pb(b);
  vb.pb(-b);
  vc.pb(c);
  vc.pb(-c);
  vd.pb(d);
  vd.pb(-d);
  
  for (int ib : vb) {
    for (int ic: vc) {
      for (int id : vd) {
        if (a+ib+ic+id == 7) {
          cout << a;
          if (ib >= 0) {
            cout << "+";
          }
          cout << ib;
          if (ic >= 0) {
            cout << "+";
          }
          cout << ic;
          if (id >= 0) {
            cout << "+";
          }
          cout << id;
          
          cout << "=7";
          return 0;
        }
      }
    }
  }
  
  return 0;
}

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

using namespace std;

int main()
{
	int l,n;
	string s[100];

	cin >> n >> l;
	for(int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	sort(s, s+n);
	for(int i = 0; i < n; i++)
	{
		cout << s[i];
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int  maxn = 100010;
long long  town[maxn],hero[maxn];

int main()
{
	int n;
	cin >> n;
	long long sum=0;
	
	for(int i=0;i < n+1;i++){
		scanf("%lld",&town[i]);
	}
	for(int i=0 ;i < n;i++){
		scanf("%lld",&hero[i]);
	}
	for(int i=0 ; i < n;i++){
		for(int j=i;j<=i+1;j++){
			int num=min(hero[i],town[j]);
			sum+=num;
			town[j]-=num;
			hero[i]-=num;
		}
		//printf("%d ",sum);
	}
	
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		//int[] a = new int[k + k - 1];
		for(int i=0; i<k + k - 1; i++){
			//a[i] = x - k + 1 + i;
			System.out.print(x - k + 1 + i + " ");
		}
	}
}


Measured memory_bytes: 38444