akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

const int N = 3e3;
const int MOD = 1e9 + 7;
int dp[N + 10][N + 10];
int pref[N + 10][N + 10];

int main()
{
    turbo

    int n; cin >> n;

    string s; cin >> s;

    dp[1][1] = 1;
    pref[1][1] = 1;
    for(int i = 2; i <= s.size() + 1; i++)
    {
        for(int j = 1; j <= i; j++)
            (dp[i][j] += (s[i - 2] == '<' ? pref[i - 1][j - 1] : pref[i - 1][i - 1] - pref[i - 1][j - 1] + MOD)) %= MOD;

        for(int j = 1; j <= i; j++)
            pref[i][j] = (pref[i][j - 1] + dp[i][j]) % MOD;
    }

    int ans = 0;

    for(int i = 1; i <= s.size() + 1; i++)
        (ans += dp[s.size() + 1][i]) %= MOD;

    return cout << ans, 0;
}

Measured memory_bytes: 69632
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", Q: int, B: "List[int]", C: "List[int]"):
    bucket = [0] * (10 ** 5 + 1)
    sum = 0
    for i in A:
        bucket[i] += 1
        sum += i
    # print(bucket[0], bucket[1], bucket[2], bucket[3], bucket[4], bucket[5])
    
    for i in range(Q):  # B[i] -> C[i]
        b, c = B[i], C[i]
        num = bucket[b]
        sum += (c - b) * num
        bucket[b] = 0
        bucket[c] += num
        print(sum)
        # print(bucket[0], bucket[1], bucket[2], bucket[3], bucket[4], bucket[5])
    


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = int(next(tokens))  # type: int
    B = [int()] * (Q)  # type: "List[int]"
    C = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, A, Q, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81224
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int a,b;
  cin>>a;
  vector<int>v1(a);
 for(int i=0;i<a;i++)
 cin>>v1[i];
 cin>>b;
 vector<int>v2(b);
 for(int j=0;j<b;j++)
 cin>>v2[j];
 cout<<lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end())<<endl;

  return  0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for(char& c : s) c -= '0';
    int ans = -1;
    for(int i = 0; i + 2 < s.size(); i++) {
        int curr = abs(s[i] * 100 + s[i + 1] * 10 + s[i + 2] - 753);
        if(ans == -1 or curr < ans) {
            ans = curr;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

int dfs(const V<V<int>>& G, V<bool>& used, V<int>& prev, int v) {
   used[v] = true;
   int to = -1;
   for (int i = 0; i < G[v].size() && to == -1; i++) {
      int u = G[v][i];
      if (used[u]) continue;
      prev[u] = v;
      to = dfs(G, used, prev, u);
   }
   return (to == -1 ? v : to);
}

signed main()
{
   int n, m; cin >> n >> m;
   V<V<int>> G(n);
   for (int i = 0; i < m; i++) {
      int a, b; cin >> a >> b; a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   V<bool> used(n, false);
   V<int> prev(n, -1);
   V<int> ans;
   if (G[0].size() == 1) {
      int s = dfs(G, used, prev, 0);
      for (int v = s; v != -1; v = prev[v]) {
         ans.push_back(v);
      }
   } else {
      int s = dfs(G, used, prev, 0);
      int t = dfs(G, used, prev, 0);
      for (int v = s; v != -1; v = prev[v]) {
         ans.push_back(v);
      }
      V<int> tmp;
      for (int v = t; v != 0; v = prev[v]) {
         tmp.push_back(v);
      }
      for (int i = tmp.size()-1; i >= 0; i--) {
         ans.push_back(tmp[i]);
      }
   }

   cout << ans.size() << endl;
   for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] + 1 << " ";
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 15220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long start = 100;
		long goal = Long.parseLong(sc.next());
		int year = 0;
		while (true) {
			start *= 1.01;
			year++;
			if (start >= goal) {
				System.out.println(year);
				break;
			}

		}

	}

}


Measured memory_bytes: 35716
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
	int i, a, b, c;
	while (cin >> a >> b) {
		c = a + b;
		for (i = 1; c >= 10; i++) {
			c /= 10;
		}
		printf("%d\n", i);
	}	
		return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<LL> s(A);
    REP0 (i, A)
    {
        cin >> s[i];
    }
    s.push_back(LLINF);
    s.push_back(-LLINF);
    sort(s.begin(), s.end());

    vector<LL> t(B);
    REP0 (i, B)
    {
        cin >> t[i];
    }
    t.push_back(LLINF);
    t.push_back(-LLINF);
    sort(t.begin(), t.end());

    REP0 (i, Q)
    {
        LL x;
        cin >> x;

        // s を探索
        int ok = -1;
        int ng = A + 2;
        while (abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;
            if (s[mid] <= x)
                ok = mid;
            else
                ng = mid;
        }  // s[mid] : x 以下になる最大の s
        LL dsl = abs(s[ok] - x);
        LL dsr = abs(s[ng] - x);

        // t を探索
        ok = -1;
        ng = B + 2;
        while (abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;
            if (t[mid] <= x)
                ok = mid;
            else
                ng = mid;
        }  // t[mid] : x 以下になる最大の t
        LL dtl = abs(t[ok] - x);
        LL dtr = abs(t[ng] - x);

        LL ans = min(max(dtl, dsl), max(dtr, dsr));
        ans = min(ans, 2LL * min(dsl, dtr) + max(dsl, dtr));
        ans = min(ans, 2LL * min(dtl, dsr) + max(dtl, dsr));
        cout << ans << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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

int main() {
    bool card[4][14];
    char ch, mark;
    int x, n;
    
    for (int s = 0; s < 4; s++)
        for (int r = 1; r <= 13; r++)
            card[s][r] = 0;
            
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> ch >> x;
        if (ch == 'S') { card[0][x] = 1;}
        else if (ch == 'H') { card[1][x] = 1;} 
        else if (ch == 'C') { card[2][x] = 1;} 
        else if (ch == 'D') { card[3][x] = 1;}
    }
    for (int s = 0; s < 4; s++){
        for (int r = 1; r <= 13; r++){
            if (!card[s][r]) {
            if (s == 0)  mark = 'S';
            else if (s == 1) mark = 'H';
            else if (s == 2) mark = 'C';
            else if (s == 3) mark = 'D';
            cout << mark << " " << r << endl;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3096
#include <stdio.h>

#define INFTY 2000000000;
#define MAX 500000

int count=0;
int S[MAX], L[MAX], R[MAX];

void merge(int *, int, int, int, int);
void mergeSort(int *, int, int, int);

int main()
{
  int i, n;

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ) scanf("%d", &S[i]);

  mergeSort(S, n, 0, n);

  for( i = 0 ; i < n ; i++ ){
    if( i >= 1 ) printf(" ");
    printf("%d", S[i]);
  }
  printf("\n");

  printf("%d\n", count);

  return 0;
}

void merge(int S[], int n, int left, int mid, int right)
{
  int n1, n2, i, j, k;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for( i = 0 ; i < n1 ; i++ ) L[i] = S[left+i];
  for( i = 0 ; i < n2 ; i++ ) R[i] = S[mid+i];

  L[n1] = R[n2] = INFTY;

  i = j = 0;
  
  for( k = left ; k < right ; k++ ){
    count++;
    if( L[i] <= R[j] ){
      S[k] = L[i];
      i++;
    }
    else {
      S[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int S[], int n, int left, int right)
{
  int mid;

  if( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(S, n, left, mid);
    mergeSort(S, n, mid, right);
    merge(S, n, left, mid, right);
  }
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n]={0};
	int i,num;
	for(i=1;i<n;i++)
	{
		cin>>num;
		arr[num-1]++;
		// for(int j=0;j<n;j++)
		// cout<<arr[j]<<" ";
		// cout<<endl;
	}
	for(i=0;i<n;i++)
	cout<<arr[i]<<endl;
	return 0;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    string S;
    cin >> S;
    auto a = S.find( "A" );
    auto z = S.rfind( "Z" );
    
    cout << z - a + 1  << endl;
    return 0;
}

Measured memory_bytes: 720
<?php
  $n = intval(fgets(STDIN));

  $data = [];
  for($i=0; $i<$n; $i++){
    $str = trim(fgets(STDIN));
    
    if(isset($data[$str])){
      $data[$str]++;
    }else{
      $data[$str] = 1;
    }
  }

  arsort($data);

  $resultArray = [];
  $max = -1;
  foreach($data as $key=>$val){
    if($max==-1){
      $max = $val;
    }
    
    if($val==$max){
      $resultArray[] = $key;
    }else{
      break;
    }
  }

  sort($resultArray);

  foreach($resultArray as $str){
    echo $str."\n";
  }


Measured memory_bytes: 29176
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  int cur = 0;
  rep(i, n){
    cin >> a[i];
    if(i & 1) cur -= a[i];
    else cur += a[i];
  }
  cout << cur << " ";
  for(int i = 0; i < n - 1; i++){
    cur = 2 * a[i] - cur;
    if(i != n - 2) cout << cur << " ";
    else cout << cur << endl;
  }
}

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

 int main() {
     int offset = 'a' - 'A';
     int n;
     cin >> n;
     int k;
     cin >> k;
     char s[n];
     for(int i = 0; i < n; i++) {
         cin >> s[i];
     }
     s[k-1] += offset;
     for(int i = 0; i < n; i++) {
         cout << s[i];
     }
     cout << endl;
     return 0;
 }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

int main() {
	for (int i = 0; i < 5; i++) {
		string s;
		cin >> s;
		if (s.length() == 1 && s[0] == '0') {
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long

string s;
int n, ans;

signed main()
{
    cin >> s;
    n = s.size();
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            if(s[i] == 'p'){
                ans--;
            }
        }
        else{
            if(s[i] == 'g'){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
int dp[2][100010];
vector <int> g[100010];
const int inf = 100000000;

int dfs(int x, int par) {
	dp[0][x] = dp[1][x] = 0;
	int mx = -inf;
	for(auto i : g[x]) {
		if(i == par) continue;
		dfs(i, x);
		dp[1][x] += dp[0][i];
		mx = max(mx, dp[1][i] - dp[0][i]);
	}
	dp[0][x] = max(dp[1][x], 1 + (dp[1][x] + mx)); 
}

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		g[p].push_back(q);
		g[q].push_back(p);
	}
	dfs(1, 0);
	int matching = dp[0][1];
	if((matching << 1) == n) printf("Second\n");
	else printf("First\n");
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <ctime>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
#define MS(x) memset(x, 0, sizeof(x))
using namespace std;

long long f[100];

int main() {
	f[1] = 1;
	f[2] = 26;
	rep(i,3,80) f[i] = f[i-1] * 26;
	rep(i,2,80) f[i] += f[i-1];
	long long a;
	string s;
	cin >> a;
	int b = 0;
	rep(i,1,50) {
		//cout << a << " " << f[i] << endl;
        if (a < f[i]) {
        a -= f[i-1], b= i-1;;
       
        break;
        }
	}
	rep(i,1,b) {
		s.push_back(a % 26 + 'a');
		a /= 26;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}

Measured memory_bytes: 3628
while line = gets
    next if line.to_s.strip == ""
    left_char = ""
    right_char = ""
    line.strip!
    length = line.size
    line.size.times do |i|
        current_char = line[i]
        if current_char == "?"
            if i == (length - 1)
                right_char = ""
            else
                right_char = line[i + 1]
            end
            if left_char == "P"
                # 左がPの場合はDにする
                line[i] = "D"
            else
                # 左がDの場合
                if right_char == ""
                    # 最後の文字ならDにする
                    line[i] = "D"
                elsif right_char == "?"
                    # 次が?の場合はPにする
                    line[i] = "P"
                elsif right_char == "D"
                    # 次がDの場合はPにする
                    line[i] = "P"
                else
                    # それ以外はDにする
                    line[i] = "D"
                end
            end
        end
        left_char = line[i]
    end
    puts line
end


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

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	int q;
	scanf("%d", &q);
	vector<int> b(q);
	for(int i = 0; i < q; i++)
		scanf("%d", &b[i]);
	sort(b.begin(), b.end());
	vector<int> d;
	set_difference(a.begin(), a.end(), b.begin(), b.end(), back_inserter(d));
	for(auto x: d)
		printf("%d\n", x);
}



Measured memory_bytes: 5496
/*author:anshumanc007
   created on:12/01/2019
            */
//:P
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
#define MAX 100005
long long int MOD=998244353;
long long int INF=1e18;
//long long int dp[MAX];
//sushi-#expectation!
long double dp[301][301][301];
long long int jj=0;
void initialise()
{
    long long int j,i,k;
    for(j=0;j<=300;j++)
    {
        for(i=0;i<=300;i++)
        {
            for(k=0;k<=300;k++)
            {
                dp[j][i][k]=-1;
            }
        }
    }
}
long double fun(long long int a,long long int  b,long long int  c)
{
    if(a==0 && b==0 && c==0)
    {
        return 0;
    }
    else if(dp[a][b][c]!=-1)
    {
        return dp[a][b][c];
    }
    else
    {
        long double k=(jj*1.00);
        long double p=(a+b+c);
        if(a>0)
        {
            k=k+(((a*fun(a-1,b,c))));
        }
        if(b>0)
        {
            k=k+1.00*(b*fun(a+1,b-1,c));
        }
        if(c>0)
        {
           k=k+1.00*(c*fun(a,b+1,c-1));
        }
                 dp[a][b][c]=(k*1.00)/(p);
                                  return dp[a][b][c];
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,maxi=0,w,mini=INF,cnt=0,ans=0,sum=0,a,b,c;
    long long int  A[4]={0};
    
    initialise();
    cin>>n;
    jj=n;
    for(i=0;i<n;i++)
    {
        cin>>k;
        A[k]++;
    }
    cout<<setprecision(10);
    a=A[1];
    b=A[2];
    c=A[3];
  
        dp[a][b][c]=fun(a,b,c);
                              
    cout<<dp[A[1]][A[2]][A[3]]<<endl;
  
}
    

Measured memory_bytes: 426496
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll LNF = 1LL<<60;

ll v[110];
ll w[110];
ll dp[110][100010];

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ma=-1;
    for(int i=1;i<N;i++){
        string a = "";
        string b = "";
        vector<int> x(26,0);
        vector<int> y(26,0);
        for(int j=0;j<i;j++){
            a += S[j];
            x[S[j]-'a']++;
        }
        for(int j=i;j<N;j++){
            b += S[j];
            y[S[j]-'a']++;
        }
        int cnt=0;
        for(int j=0;j<26;j++){
            if(x[j]>0 && y[j]>0){
                cnt++;
            }
        }
        if(cnt>ma) ma=cnt;
    }
    cout << ma << endl;
    return 0;
}


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

vector<int> G[200000];
vector<int> cnt;
vector<bool> visited(200000);

void dfs(int u) {
    visited[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (visited[v]) continue;
        cnt[v] += cnt[u];
        dfs(v);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cnt.resize(N);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    dfs(0);

    for (int i = 0; i < N; i++) {
        cout << cnt[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	vector<int> v, ans;
	cin >> n;
	v.resize(n);
	ans = v;
	for(int i=0; i<n; i++) {
		cin >> v[i];
		ans[i] = i;
	}
	sort(ans.begin(), ans.end(), [&](int a, int b) {
		return v[a]<v[b];
	});
	for(int a: ans)
		cout << a+1<<' ';
}

Measured memory_bytes: 1664
#include<iostream>

using namespace std;

int main(){
	int N;
	cin>>N;
	
	int x=0;
	int y=0;
	for(int i=1 ; i<=N ; i++){
		x+=800;
		if(i%15==0)y+=200;
	}
	cout<<x-y<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#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 SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int n;
	cin >> n;
	vector<int> S(n);
	REP(i, n) { cin >> S[i]; }
	int q;
	cin >> q;
	int C = 0;
	REP(i, q) {
		int t;
		cin >> t;
		C += binary_search(S.begin(), S.end(), t);
	}
	cout << C << endl;

	return 0;
}



Measured memory_bytes: 3232
N = int(input())
if N == 1:
    st = 0
    S = input()
    for x in S:
        if x == '(':
            st += 1
        else:
            if st > 0:
                st -= 1
            else:
                print('No')
                exit()
    if st == 0:
        print('Yes')
    else:
        print('No')
    exit()
lst1, lst2 = [], []
flg, mr = 0, 10**9
for i in range(N):
    S = input()
    st, r, rall = 0, 0, 0
    for c in S:
        if c == '(':
            st += 1
        else:
            rall += 1
            if st > 0:
                st -= 1
            else:
                r += 1
    pls = max(0, len(S)-rall-(rall-r))
    if pls >= r:
        lst1.append((r, -pls))
    else:
        lst2.append((-pls, r))
lst1.sort()
lst2.sort()
if lst1[0][0] != 0:
    print('No')
    exit()
lcnt = -lst1[0][1]
for (r, pls) in lst1[1:]:
    lcnt -= r
    if lcnt < 0:
        print('No')
        exit()
    lcnt -= pls
for (pls, r) in lst2:
    lcnt -= r
    if lcnt < 0:
        print('No')
        exit()
    lcnt -= pls
if lcnt == 0:
    print('Yes')
else:
    print('No')

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    string s;
    cin >> s;

    vector<int> v(26);
    for (char i = 'a'; i <= 'z'; ++i) {
        int cnt = 0, ans = 0;
        rep(j, s.size()){
            if(s[j] == i){
                ans = max(ans, cnt);
                cnt = 0;
            }else{
                cnt++;
            }
        }
        ans = max(ans, cnt);
        v[i-'a'] = ans;
    }

    sort(all(v));
    cout << v[0] << endl;



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
	string s;
	cin >> s;

	int count = 0;

	for (int i = 0; i < s.length() / 2; i++)
	{
		if (s[i] != s[s.length()-(1+i)])
		{
			count++;
		}
	}
	
	cout << count << endl;
    
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 10
using namespace std;
int main()
{
	char a[N];
	int i;
	int n;
	cin >> n;
	int cnt[5] = {0};
	for (i = 0;i < n;i ++)
	{
		cin >> a;
		switch(a[0])
		{
			case 'A':
				cnt[0] ++;
				break;
			case 'W':
				cnt[1] ++;
				break;
			case 'T':
				cnt[2] ++;
				break;
			case 'R':
				cnt[3] ++;
				break;
		}
	}
	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

int main() 
{
	long long n,m;
	while(cin >> n >> m , !(n==0 && m==0))
	{
		pair<long long,long long> a[100000];
		for(int i=0;i<n;i++)
		{
			cin >> a[i].second >> a[i].first;
		}
		
		sort(a,a+n);
		reverse(a,a+n);
		
		long long risk = 0;
		
		for(int i=0;i<n;i++)
		{
			if(m==0){	risk += a[i].first * a[i].second;	}
			else if(a[i].second <= m){	m-=	a[i].second;	}
			else {	risk += (a[i].second - m)*a[i].first;m=0;}
		}
		cout << risk << endl;
		}	
	return 0 ;
}

Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
double f(vector<double> v, int p) {
  double s = 0;
  for (int i = 0; i < v.size(); i++) s += pow(v[i], p);
  return pow(s, 1.0 / p);
}
int main() {
  int n;
  cin >> n;
  vector<double> x(n, 0);
  vector<double> y(n, 0);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) cin >> y[i];
  vector<double> z(n);
  for (int i = 0; i < n; i++) z[i] = abs(x[i] - y[i]);
  cout << fixed << setprecision(6) << f(z, 1) << endl;
  cout << fixed << setprecision(6) << f(z, 2) << endl;
  cout << fixed << setprecision(6) << f(z, 3) << endl;
  cout << fixed << setprecision(6) << *max_element(z.begin(), z.end()) << endl;
  return 0;
}


Measured memory_bytes: 3500
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n=int(input())
ans=0
if n>1:
    array=factorization(n)
    # print(array)
    ans=0
    for a in array:
        ans+=(-1+math.sqrt(1+8*a[1]))//2
        # print(ans)

print(int(ans))


Measured memory_bytes: 63504
#include<stdio.h>
int main(void)
{
	int n,m,si,ai,x[100001],sum,s,i;
	scanf("%d%d",&n,&m);
	x[0]=0;
	for(i=1;i<n;i++){
		scanf("%d",&si);
		x[i]=si+x[i-1];
	}
	//for(i=0;i<n;i++)printf("x[%d]=%d\n",i,x[i]);
	s=0; sum=0;
	for(i=1;i<=m;i++){
		//printf("sum=%d\n",sum);
		scanf("%d",&ai);
		if(ai>=0){
			sum+=x[s+ai]-x[s];
			s+=ai;
		}
		else{
			sum+=x[s]-x[s+ai];
			s+=ai;
		}
		sum%=100000;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 2192
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
const int MOD = 1e9+7;

//xのn乗
ll mod_pow(ll x, ll n) {// O(log(n))
    ll res = 1;
    while (n > 0) {//繰り返し二乗法
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}
 
int main() {
  ll n, ans=0;
  cin>>n;
  ans=(mod_pow(10,n)-2*mod_pow(9,n)%MOD+mod_pow(8,n))%MOD;
  if(ans<0){
    ans+=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-

#ボタン1→いろいろあってボタン2で終わるならボタンを押す回数、無理なら-1を出力

N = int(input())

Bo = []

for i in range(N):
    A = int(input())
    Bo.append(A)


S = Bo[0]

if S == 2:
    print(1)

else:
    
    ans = []
    
    for i in range(N):
        S = Bo[S - 1]
        
        if S == 2:
            C = i + 2
            ans.append(C)
        
    if len(ans) != 0:
        print(ans[0])
    
    else:
        print(-1)

  
    

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

int main(){
  int k;
  cin>>k;
  int par = 0, imp = 0;
  for(int i = 1; i<=k; ++i){
    if(i&1) imp++;
    else par++;
  }
cout<<par*imp<<"\n";
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
const int INF = 1001001001;
int main(){
    int n; cin >> n;
    vector<P> red;
    rep(i,n){
        int a,b; cin >> a >> b;
        red.push_back({a,b});
    }
    vector<P> blue;
    rep(i,n){
        int c,d; cin >> c >> d;
        blue.push_back({c,d});
    }
    sort(blue.begin(),blue.end());
    bool use[n];
    rep(i,n) use[i]=0;
    int ans=0;
    //blueをfi下から見て、取れるredのうちyの最大をとる。
    rep(i,n){
        int c=blue[i].fi;
        int d=blue[i].se;
        int y=-1; int now=-1;
        rep(j,n){
            if(red[j].fi < c && red[j].se < d && y<red[j].se && use[j]==0){
                now=j;
                y=red[j].se;
            }
        }
        if(now>=0){
            ans++;
            use[now]=1;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  auto X = scan!long;
  auto K = scan!long;
  auto D = scan!long;

  long solve() {
    if (X < 0) X = -X;

    auto times = X / D;
    if (K < times) {
      return X - D*K;
    }

    auto loopTimes = K - times;

    if (loopTimes % 2 == 0) {
      return X - D*times;
    } else {
      return (X - D*times - D).abs;
    }
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2752
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <sstream>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << os.str();                            \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

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



signed main()
{
    string S;
    
    cin >> S;
    if (S.find("AC") != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    map<string,int>data;
    rep(i,n){
        string s;
        cin >> s;
        if(data.count(s)){}
        else {
            data[s] = 1;
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 19180
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
int n, a[10101];
void solve() {
	for1(i, n)a[i] = input();
	if (n < 4) { cout << n << "\n"; return; }
	int p = n, l, r;
	a[n + 1] = 0;
	r = 2; while (a[2] == a[r + 1])r++; if (r >= 4)p = n - r;
	l = n - 1; while (a[l - 1] == a[n - 1])l--; if (l <= n - 3)p = min(p, l - 1);
	for (int i = 2; i < n; i++) {
		int c = a[i];
		if (a[i] != a[i - 1]) {
			a[i] = a[i - 1];
			l = i - 1, r = i;
			while (a[l] == a[r]) {
				int cnt = 2;
				while (a[l - 1] == a[l]) { l--; cnt++; }
				while (a[r + 1] == a[r]) { r++; cnt++; }
				if (cnt >= 4) { p = min(p, n - (r++ - --l)); if (l < 1 || n < r)break; }
				else break;
			}
		}
		if (a[i] != a[i + 1] && a[i - 1] != a[i + 1]) {
			a[i] = a[i + 1];
			l = i, r = i + 1;
			while (a[l] == a[r]) {
				int cnt = 2;
				while (a[l - 1] == a[l]) { l--; cnt++; }
				while (a[r + 1] == a[r]) { r++; cnt++; }
				if (cnt >= 4) { p = min(p, n - (r++ - --l)); if (l < 1 || n < r)break; }
				else break;
			}
		}
		a[i] = c;
	}
	cout << p << "\n"; return;
}
signed main() {
	while (n = input())solve();
}


Measured memory_bytes: 3112
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	long long n,k,s;
	cin >> n >> k >> s;
	long long replace=s-1;
	if(replace<=0)replace=s+1;
	vector<long long> result(n,replace);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(cnt!=k){
			result[i]=s;
			cnt++;
		}
	}
	
	for(int i=0;i<n;i++){
		cout << result[i] << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,ans=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    while(a[i]%2==0){
      ans++;
      a[i]=a[i]/2;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
//#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	FAST_IO ;
	int tt = 1;
//	cin >> tt ;
	while(tt--){
		int a ;
		cin >> a ;
		int ans = a+(a*a)+(a*a*a) ;
		cout << ans << endl ;
	}
	return 0 ;
}


Measured memory_bytes: 3636
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);
    REP(i,n) cin >> x[i] >> y[i] >> h[i];
    int able_h = 0;
    REP(i,n) if (h[i] > 0) able_h = i;
    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            int H = h[able_h] + abs(x[able_h]-cx) + abs(y[able_h]-cy);
            bool f = true;
            REP(j,n) if (h[j] != max(H - abs(x[j]-cx) - abs(y[j]-cy), 0)) f = false;
            if (f) {
                cout << cx << " " << cy << " " << H << std::endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <set>
using namespace std;

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};


int main(){
  int N, M = 1e5+1;
  cin >> N;
  vector<pair<int,int>> P;

  set<int> XX, YY;
  UnionFind uf(2*M);
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    P.emplace_back(x,y);
    uf.unite(x,y+M);
    XX.insert(x);
    YY.insert(y);
  }

  vector<int> X(2*M,0), Y(2*M,0);

  for(auto x : XX)
    ++X[uf.find(x)];

  for(auto y : YY)
    ++Y[uf.find(y+M)];

  long long ans = -N;
  for(int i = 0; i < 2*M; ++i){
    ans += (long long)X[i]*Y[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 8056
x = int(input())
a = [0]*1000
for i in range(1000):
    tmp = i**5
    a[i] = tmp
for i in range(1000):
    for j in range(1000):
        if((a[i]-x) == (a[j])):
            print(i,j)
            exit()
        elif(x-a[i]==a[j]):
            print(i,-j)
            exit()


Measured memory_bytes: 9064
from heapq import heappop, heappush

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N)]
for a, b, c in X:
    graph[a - 1].append((b - 1, c))
    graph[b - 1].append((a - 1, c))


def dijkstra(s):
    inf = 10 ** 9 + 7
    d = [inf] * N
    d[s] = 0
    pq = []
    heappush(pq, (0, s))
    while pq:
        _, u = heappop(pq)
        for v, c in graph[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                heappush(pq, (d[v], v))

    return d


dist = [dijkstra(s) for s in range(N)]
ans = [False] * M
for n, (a, b, c) in enumerate(X):
    for i in range(N):
        for j in range(N):
            ans[n] |= dist[i][j] == dist[i][a - 1] + c + dist[j][b - 1]

print(M - sum(ans))


Measured memory_bytes: 54108
#include<stdio.h>
int main(void){
    int x,a,b;

    scanf("%d %d %d",&x,&a,&b);

    a=x-a;
    a= (a>0)? a:-a;
    b=x-b;
    b= (b>0)? b:-b;

    if( a < b ){
        printf("A\n");
    }
    else{
        printf("B\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int stu[501];
	int ls[2][10001];
	int c,n,m,i,j;
	
	for(;;){
		c=0;
		for(i=0;i<501;i++)stu[i]=0;
		scanf("%d",&n);
		scanf("%d",&m);
		if(n==0)break;
		
		for(i=0;i<m;i++){
			scanf("%d%d", &ls[0][i], &ls[1][i]);
			if(ls[0][i]==1)stu[ls[1][i]]=2;
			if(ls[1][i]==1)stu[ls[0][i]]=2;
		}
		
		for(i=1;i<n+1;i++){
			if(stu[i]==2){
				for(j=0;j<m;j++){
					if(ls[0][j]==i){
						if(stu[ls[1][j]]==2){}
						else stu[ls[1][j]]=1;
					}
					if(ls[1][j]==i){
						if(stu[ls[0][j]]==2){}
						else stu[ls[0][j]]=1;
					}
				}
			}
		}
		stu[1]=0;
		for(i=1;i<n+1;i++)if(stu[i]==1 || stu[i]==2)c++;
		printf("%d\n",c);
	}
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N; 
    cin >> N;

    vector<ll> A(N);
    
    REP(i, N){
        cin >> A[i];
    }

    ll money = 1000;
    ll updown = 0;
    ll mink;
    ll maxk;

    if(A[1] > A[0]){
        updown = 1;
        mink = A[0];

        if(N==2){
            money = money%A[0] + (money/A[0]) * A[1];
        }
    }
    else{
        updown = -1;
        maxk = A[0];
        mink = A[1];
    }

    for(ll i=2; i<N; i++){
        // 今まで上昇トレンドのとき
        if(updown  == 1){
            // 更に上昇するとき
            if(A[i] >= A[i-1]){
                maxk = A[i];
                updown = 1;

                if(i == N-1){
                    money = money%mink + (money/mink) * A[i];
                }
            }   
            // 下降するとき
            // 上昇が止まる前の時点ですべて売り払う
            else{
                money = money%mink + (money/mink) * A[i-1];
                mink = A[i];
                updown = -1;
            }
        }

        //　今まで下降トレンドのとき
        else{
            // さらに下降するとき
            if(A[i] <= A[i-1]){
                mink = A[i];
                updown= -1;
            }
            // 下降から上昇に転じるとき
            else{
                updown = 1;
                if(i == N-1){
                    money = money%mink + (money/mink) * A[i];
                }
            }
        }
        // cout << "mink:" << mink << " " << A[i] << " " << money << endl;
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

int n;
int in[5100];
unordered_set<int> vs;

int Solve(int x, int y) {
  int d = y - x;
  if (vs.count(x-d) > 0) return 0;
  int r = 1;
  for (int x = y; vs.count(x) > 0; x += d) {
    r++;
  }
  return r;
}

int main() {
  while (cin >> n) {
    vs.clear();
    for (int i = 0; i < n; ++i) {
      cin >> in[i];
      vs.insert(in[i]);
    }
    sort(in, in+n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i+1; j < n; ++j) {
        int r = Solve(in[i], in[j]);
        // cout << iter.first << " / " << r << endl;
        ans = max(ans, r);
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
int ctoi(const char c){
    switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
  }
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,pow=1;
	cin >> N;
	repr(i,1,1+N){
		pow = pow*i%MOD;
	}
	cout << pow << endl;
}


Measured memory_bytes: 256
/*		  m 
组合数：Cn 	 （从n个中取m个） 
	
*/ 
#include<cstdio>
#include<algorithm>
using namespace std;

int n,a,b;
long long c[55][55],ans2,v[55],sum;
double ans1;

bool cmp(long long  x,long long  y)
{
	return x>y;
}

void pre()
{
	for(int i=0;i<=n;i++)
	{
		c[i][0]=1;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
} 

int main()
{
	int num=0,num1=0,tot=0;

	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&v[i]);
	}
	pre();	
	sort(v+1,v+n+1,cmp);
	for(int i=1;i<=a;i++)
	{
		sum+=v[i];
		if(v[i]==v[a])
		{
			num1++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(v[i]==v[a])
		{
			num++;
		}
		if(v[i]==v[1])
		{
			tot++;
		}
	}	
	
	if(v[a]==v[1])
	{
		for(int i=a;i<=min(b,tot);i++)
		{

			ans2+=c[tot][i];
		}
	}
	else 
	{
	
		ans2=c[num][num-num1];	
	}
	ans1=(double)sum/a;
	printf("%.6lf\n%lld",ans1,ans2);
	return 0;
}

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

vector<int> a, b;
vector<vector<int>> ed;
map<P,int> mp;
int n;

void dfs(int x, int c=-1, int p=-1) {
    int cnt = 0;
    rep(j, ed[x].size()) {
        int now = ed[x][j];
        if (cnt == c) cnt++;
        if (now == p) continue;
        mp[{x, ed[x][j]}] = cnt;
        mp[{ed[x][j], x}] = cnt;
        dfs(now, cnt, x);
        cnt++;
    }
}

void solve() {
    cin >> n;
    a.resize(n-1), b.resize(n-1);
    ed.resize(n);
    rep(i,n-1) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        ed[a[i]].push_back(b[i]);
        ed[b[i]].push_back(a[i]);
    }

    dfs(0);

    int m = 0;
    rep(i,n-1) m = max(m, (int)ed[i].size());
    cout << m << endl;
    rep(i,n-1) cout << mp[{a[i], b[i]}] + 1 << endl;

}

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


Measured memory_bytes: 20352
N = int(input())
S = input()

wcnt = [(S[0]=='W')*1]+[0]*(N-1)
for i in range(1, N):
    wcnt[i] = wcnt[i-1]+(S[i]=='W')*1

w = wcnt[N-1]
e = N-w
ans = 10**9
for j in range(N):
    tmp = wcnt[j]
    ans = min(e+2*wcnt[j]-(S[j]=='W')*1-1-j, ans)
    
print(ans)

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

  
     
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(51, 0);
  int ans = 0;
  for(int i = 0; i < N; i++) cin >> vec[i];
  
  sort(vec.begin(), vec.end(), greater<int>());
  for(int i = 0;i < K; i++) ans += vec[i];
  
  cout << ans;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int, input().split()))
    n2 = sum([a % 2 == 0 for a in A])
    n4 = sum([a % 4 == 0 for a in A])
    nodd = n - n2
    n2 -= n4
    if nodd == n4 + 1:
        if n2 == 0:
            print('Yes')
        else:
            print('No')
    elif nodd <= n4:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 64664