akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


bool in_array(const char &word, const vector< char > &data)
{
    int max=data.size(); 
    if (max==0) return false;
 
    for(int i=0; i<max; i++){
        if (data.at(i)==word) return true;
    }
    return false;
} 

int main() {
  
  int n, m; 
  cin >> n >> m;
  
  vector<vector<char>> data(n, vector<char>(m));
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      char x;
      cin >> x;
      data.at(i).at(j) = x;
    }
  }
  
  for(int i=0; i<n; i++){    
    for(int j=0; j<m; j++){
      
      //横一列に # が存在する
      if(in_array('#', data.at(i))){

        //縦一列に # が存在する
        int c = 0; 
        for(int k=0; k<n; k++){
          if (data.at(k).at(j) == '#') {
            c = 1;
            break;
          }
        }

        if (c == 1) cout << data.at(i).at(j);

      }
      
    }
    if(in_array('#', data.at(i))) cout << endl;
  }
   
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int N;
    cin>>N;
    vector<ll> a;
    FOR(i, 0, 3*N){
        ll in;
        cin >> in;
        a.push_back(in);
    }
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    FOR(i, 0, 2*N){
        if(i%2==1) ans+=a[i];
    }
    cout << ans << endl;
}


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

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

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

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

struct Solver {
    int N;
    vector<vector<int>> table;
    vector<vector<int>> dp;

    Solver(int n, vector<vector<int>> v) : N(n),
                                           table(n, vector<int>(n)),
                                           dp(60, vector<int>(1 << n, -1)) {
        REP(i, n){
            REP(j, n){
                table[i][j] = v[j][abs(i-j)%2];
            }
        }
        REP(i, 60) dp[i][0] = 0;
    }

    int solve(int mi, int bit) {
        if(dp[mi][bit] != -1) return dp[mi][bit];
        int res = inf;

        REP(i, N){
            int k = table[__builtin_popcount(bit) - 1][i];
            if(!((bit >> i) & 1) || mi < k) continue;

            int cnt = __builtin_popcount(bit & ~((1 << (i + 1)) - 1));
            cnt += solve(k, bit & ~(1 << i));
            chmin(res, cnt);
        }
        return dp[mi][bit] = min(res, inf);
    }
};

signed main(){
    int n;
    cin >> n;

    vector<vector<int>> v(n, vector<int>(2));
    REP(i, n) cin >> v[i][0];
    REP(i, n) cin >> v[i][1];

    Solver S(n, v);
    int ans = S.solve(50, (1 << n) - 1);

    cout << (ans < inf ? ans : -1) << endl;

    return 0;
}


Measured memory_bytes: 62976
#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(){
    cout << setprecision(20);
    int n,k;
    cin >> n >> k;
    long double p[n];
    rep(i,n){
        double a;
        cin >> a;
        p[i] = 1+a;
        p[i] /= 2;
    }
    rep(i,n-1)p[i+1] = p[i] + p[i+1];
    long double ans = p[k-1];
    
    rep(i,n-k){
        ans = max(ans,p[i+k]-p[i]);
    }
    cout << ans << endl;
    //rep(i,n)cout << p[i] << endl;
    return 0;
}

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

int main() {
    int N, A[110];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    double ans = 0.0;
    for (int i = 0; i < N; i++) {
        ans += 1.0 / A[i];
    }
    ans = 1.0 / ans;

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll K,A,B; cin >> K >> A >> B;
    if (A+1LL >= B) {
        cout << K+1 << endl;
        return 0;
    }
    ll cnt = min(K+1LL,A);
    K = max(0LL,K-A+1LL);
    if (K%2==1) {
        K--;
        cnt++;
    }
    cnt = cnt + (B-A)*(K/2LL);

    cout << cnt << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	const [A, B, C, K] = input[0].split(' ').map(n => parseInt(n))
	if (A >= K) {
		ans = K
	} else {
		ans = A
		if ((A + B) >= K) {
			ans = A
		} else {
			ans = ans - (K - A - B)
		}
	}

	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vtp abc(n);
  rep(i,n){
    ll a,b,c; cin>>a>>b>>c;
    abc[i]=tie(a,b,c);
  }
  ll ans=0;
  rep(i,2){
    rep(j,2){
      rep(k,2){
        vpll v;
        rep(ki,n){
          ll a,b,c;
          tie(a,b,c)=abc[ki];
          ll sum=0;
          sum+=i?-a:a;
          sum+=j?-b:b;
          sum+=k?-c:c;
          v.emplace_back(sum,ki);
        }
        sort(v.rbegin(),v.rend());
        ll x=0,y=0,z=0;
        rep(ki,m){
          ll idx=v[ki].second;
          ll a,b,c;
          tie(a,b,c)=abc[idx];
          x+=a;
          y+=b;
          z+=c;
        }
        chmax(ans,abs(x)+abs(y)+abs(z));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
	c = []
	for j in range(l):
		c.append(sum(a[i][k]*b[k][j] for k in range(m)))
	print(*c)

Measured memory_bytes: 8596
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

x, y, r = map(float, raw_input().split())

q = input()

for loop in range(q):
    x1, y1, x2, y2 = map(float, raw_input().split())
    vx = x2 - x1
    vy = y2 - y1
    norm = vx * vx + vy * vy
    inn = vx * (x - x1) + vy * (y - y1)
    xc = x1 + vx * inn / norm
    yc = y1 + vy * inn / norm
    rem = math.sqrt(max(0, r ** 2 - (xc - x) ** 2 - (yc - y) ** 2))
    dx = vx / math.sqrt(norm) * rem
    dy = vy / math.sqrt(norm) * rem

    ans = sorted([(xc + dx, yc + dy), (xc - dx, yc - dy)])
    print "%.10f %.10f %.10f %.10f" % (ans[0][0], ans[0][1], ans[1][0], ans[1][1])



Measured memory_bytes: 5108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    pair<long long int,long long int> p[n];
    long long int t[n];
    for(int i = 0;i < n;i++)
    {
        int a,b;
        cin >> a >> b;
        p[n - 1 - i] = make_pair(a,b);
    }
    t[0] = ceil((double)p[0].first / p[0].second) * p[0].second - p[0].first;
    for(int i = 0;i < n - 1;i++)
    {
        p[i + 1].first += t[i];
        t[i + 1] = t[i] + ceil((double)p[i + 1].first / p[i + 1].second) * p[i + 1].second - p[i + 1].first;
    }
    cout << t[n - 1] << "\n";

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int N;

	cin >> N;

	map<string, int> Ss;

	string s;
	for (int ni = 0; ni < N; ni++) {
		cin >> s;
		sort(s.begin(), s.end());
		Ss[s]++;
	}

	long long sum = 0;
	for (auto ps : Ss) {
		for (int c = ps.second - 1; c > 0; c--) {
			sum += c;
		}
	}


	//printf("%.9f", ans);
	std::cout << sum;

	return 0;
}



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

int main() {
  string S;
  int64_t x;
  cin >> S;
  const int N=S.size();
  vector<int> vec(N);
  int64_t A=stoll(S);
  for(int i=0;i<N;i++){
    x=A/10;
    vec.at(N-i-1)=A-x*10;
    A=x;
  }
 int64_t sum;
  for(int tmp=0;tmp<(1<<N-1);tmp++){
    bitset<20> s(tmp);
    int64_t ans=0;
    int64_t num=0;
    for(int i=0;i<N-1;i++){
      if(s.test(i)){
        ans+=10*num+vec.at(i);
        num=0;
      }
      else{
        num=10*num+vec.at(i);
      }
    }
      ans+=10*num+vec.at(N-1);
      sum+=ans;
  }
   cout << sum << endl;
}
    


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

int main() {  
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int M;
  cin >> M;
  vector<string> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }  
  int ans = 0;
    
  for (int i = 0; i < N; i++) {
    int b = 0;
    for (int j = 0; j < N; j++) {
      if (A.at(i) == A.at(j)) {
      b++;
    }
    }
    for (int j = 0; j < M; j++) {
      if (A.at(i) == B.at(j)) {
      b--;
    }
    }
     ans = max(ans,b);
  }    
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 15:11:59 2020

@author: Kanaru Sato
"""

n = int(input())
v = list(map(int, input().split()))

v.sort()
valuesum = (v[0]+v[1])/2

for i in range(2,n):
    valuesum = (valuesum+v[i])/2

print(valuesum)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){
	char s[100000];
	int num[26]={};
	int last = 0;
	scanf("%s",s);

	for(int i=0;i<strlen(s);i++){
		for(int n=0;n<26;n++){
			if(s[i]=='a'+n) num[n] = 1;
		}
	}

	for(int m=0;m<26;m++){
		if(num[m]==0){
			printf("%c\n",'a'+m);
			last = 1;
			break;
		}
	}
	if(last==0) printf("None\n");
	return 0;
}


Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
    fast();
    ll i,j,l,r,x=INT_MAX;
    cin>>l>>r;
    for(i=l;i<=min(l+2019,r);i++)
        for(j=i+1;j<=min(l+2019,r);j++)
            x=min(x,(i*j)%2019);
    cout<<x;
    exit(0);
}

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

int main(void){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    static int Alice,Bob;
    sort(a, a+N, greater<int>());
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            Alice += a[i];
        }else{
            Bob += a[i];
        }
    }

    cout << Alice - Bob <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double z,f[500][50],t;
int n,c,a[10];
int main(){
    scanf("%d%d",&n,&c);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    do{
        memset(f,0,sizeof(f));
		f[n*a[n-1]][0]=1;
		for(int i=0;i<n*c;i++){
			for(int j=i;j<=n*c;j++){
				for(int k=0;k<(1<<(n-1));k++){
					if (i%n&&(k>>(i%n-1)&1)==0){
						f[min(max(j,i+n*a[i%n-1]),n*c)][k|(1<<(i%n-1))]+=f[j][k];
					}
				}
			}
		}
        z+=f[n*c][(1<<(n-1))-1];
		t++;
    }while(next_permutation(a,a+n-1));
    printf("%.15f\n",z/t/pow(c,n-1));
}


Measured memory_bytes: 384
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll f(ll a, ll b);

string s,t;

ll ls,lt;

vector<vector<ll>> dp(3010, vector<ll>(3010,-1));

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

    cin>>s;
    cin>>t;

    ls = s.length();
    lt = t.length();

    DEBUG(f(0,0));

    string ans = "";

    ll i=0, j=0;
    while(i<ls && j<lt)
    {
        
        ll maxi = 0;
        
        ll addone = 0;    
        string c = "";
        if(s[i] == t[j])
        {       
            addone++;
            c = s[i];
        }   

        maxi = max( f(i+1,j), max(f(i,j+1) , addone+f(i+1,j+1)) );
        if(maxi == f(i+1,j))
        {
            i++;   
        }
        else if(maxi == f(i,j+1))
        {
            j++;   
        }
        else
        {
            i++;
            j++;   
            ans += c;
        }
    
    }

    cout<<ans<<endl;

    return 0;
}

ll f(ll a, ll b)
{
    if(dp[a][b] != -1)
    {
        return dp[a][b];
    }

    if(a >= ls || b>= lt)
    {
        return 0;
    }

    ll addone = 0;

    if(s[a] == t[b])
    {       
        addone++;
    }   
    return dp[a][b]  = max( f(a+1,b), max(f(a,b+1) , addone+f(a+1,b+1)) );

}

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


int main() {


	int n;

	int a, b;

	cin >> n;

	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else if (n == 2) {
		cin >> a >> b;
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
  int N; cin >> N;
  string S1,S2;
  cin >> S1 >> S2;
  ll ans = 0;
  if(S1[0] == S2[0]) ans += 3;
  else ans += 6;
  rep(i,N-1){
     if(S1[i+1] != S1[i] && S1[i+1] != S2[i+1] && S1[i] == S2[i]){
        ans *= 2;
        ans %= MOD;
     }
     else if(S1[i+1] != S1[i] && S1[i+1] != S2[i+1] && S1[i] != S2[i]){
        ans *= 3;
        ans %= MOD;
     }
     else if(S1[i+1] == S2[i+1] && S1[i] == S2[i]){
        ans *= 2;
        ans %= MOD;
     }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def check(P):
    t = 0
    for p in P:
        if t > p:
            return False
        t = p
    return True

def main():
    N = i2n()
    P = i2nn()
    if check(P):
        print('YES')
        return
    for i in range(N):
        for j in range(i+1, N):
            P[i], P[j] = P[j], P[i]
            if check(P):
                print('YES')
                return
            P[i], P[j] = P[j], P[i]
    print('NO')

main()


Measured memory_bytes: 39280
import numpy as np

raw = input()
a, b, h, m = [int(f) for f in raw.split(" ")]

hour = np.array(
    [a * np.sin(h * np.pi / 6 + m * np.pi / 360), a * np.cos(h * np.pi / 6 + m * np.pi / 360)]
)
mins = np.array([b * np.sin(m * np.pi / 30), b * np.cos(m * np.pi / 30)])

r = np.linalg.norm(hour - mins)

print(r)

Measured memory_bytes: 27260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll calcLucas(ll i_min_2, ll i_min_1, int stopIdx, int idx){
    ll sum = i_min_1 + i_min_2;
    if (stopIdx+1 == idx) {
        return sum;
    }
    return calcLucas(i_min_1, sum, stopIdx, idx + 1);
}

int main(){
    int n;cin >> n;
    if (n == 1){
        cout << 1 << endl;
        return 0;
    } else if (n == 2){
        cout << 3 << endl;
        return 0;
    }
    cout << calcLucas(2,1, n, 3) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;
int N, K;
int l[100] = {};

void solve() {
	cin >> N >> K;
	for(int i = 0; i<N; i++){
		cin >> l[i];
	}

	// nameをキーに昇順でソート
	sort(l, l+N, greater<int>());

	int ans=0;
	for(int i=0; i<K; i++){
		ans += l[i];
	}

	printf("%d\n", ans);
}




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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "
#define F           first
#define S           second
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,i;
    cin>>n;
    ll a[n-1];
    for(i=0;i<(n-1);i++)
        cin>>a[i];
    ll ans=0;
    ans+=a[0]+a[n-2];
    for(i=1;i<(n-1);i++)
        ans+=min(a[i],a[i-1]);
    cout<<ans;
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>

const int V = 500000000;
const int MN = 20005;

int N, A[MN];

int main() {
	scanf("%d", &N);
	for (int i = 1, x; i <= N; ++i) scanf("%d", &x), A[x] = i;
	for (int i = 1; i <= N; ++i) printf("%d%c", N * i, " \n"[i == N]);
	for (int i = 1; i <= N; ++i) printf("%d%c", V + A[i] - N * i, " \n"[i == N]);
	return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<string, map<string, int> > Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

int h[2000];

int main(){
	int T;
	cin >> T;
	for(int t = 0; t < T; t++){
		int n;
		cin >> n;
		int rmax = 0, rmin = 0;
		for(int i = 0; i < n; i++){
			cin >> h[i];
			if(i != 0){
				rmax = max(rmax, h[i] - h[i-1]);
				rmin = min(rmin, h[i] - h[i-1]);
			}
		}
		cout << rmax << " " << -rmin << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<limits>
#include<cmath>
using namespace std;
int n,k,minn,sum,aa[2500],bb[2500];vector<int>a[2500];
void dfs(int qian, int x,int z)
{
	if(z<k)
	for(int i=0;i<a[x].size();++i)
	{
		if(a[x][i]!=qian)
		{
		++sum;
		dfs(x,a[x][i],z+1);
	    }
	}
	
}
int main()
{	
	cin>>n>>k;minn=n;
	for(int i=0;i<n-1;++i)
	{
		scanf("%d%d",&aa[i],&bb[i]);
		a[bb[i]].push_back(aa[i]);
		a[aa[i]].push_back(bb[i]);
	}
	
	if(k%2)
	{
		k/=2;
		for(int i=0;i<n-1;++i)
		{
			sum=2;
			dfs(aa[i],bb[i],0);
			dfs(bb[i],aa[i],0);
			minn=min(minn,n-sum);
		}
		
	}
	else
	{
		k/=2;
		for(int i=1;i<=n;++i)
		{
			sum=1;
			dfs(0,i,0);
			minn=min(minn,n-sum);
		}
		
	}
	
	
	cout<<minn;
    
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N;
    cin >> N;

    vector<string> s(N);
    rep(i, N) cin >> s[i];

    rep(i, N) { sort(ALL(s[i])); }

    map<string, ll> dic;
    ll ans = 0;
    rep(i, N) {
        if (dic.find(s[i]) == dic.end()) {
            dic.insert(make_pair(s[i], 0));
        } else {
            dic[s[i]]++;
            ans += dic[s[i]];
        }
    }

    // repv(dic) { cout << (*it).first << ", " << (*it).second << endl; }
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;

 
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> G[n];
  vector<int> d(n, -1);
  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);
  }
  queue<int> que;
  d[0] = 0;
  que.push(0);
  while(!que.empty()){
    int x = que.front();
    que.pop();
    for(int next : G[x]){
      if(d[next] != -1) continue;
      d[next] = x;
      que.push(next);
    }
  }
  for(int i=1; i<n; i++){
    if(d[i] == -1){
      cout << "No" << endl;
      return 0;
    }
    d[i]++;
  }
  cout << "Yes" << endl;
  for(int i=1; i<n; i++){
    cout << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 10196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n, m;
    cin >> n >> m;
    int ma[n];
    rep(i, n){
        ma[i]=INF;
    }
    rep(i, m){
        int s, c;
        cin >> s >> c;
        --s;
        if(ma[s]==INF){
            ma[s]=c;
        }else if(ma[s]==c){
            continue;
        } else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(n>=2 && ma[0]==0){
        cout << -1 << endl;
        return 0;
    }

    rep(i, n){
        if(ma[i]!=INF){
            cout << ma[i];
        }else{
            if(i==0){
                if(n!=1){
                    cout << 1;
                }else{
                    cout << 0;
                }
            }else{
                cout << 0;
            }
        }
    }
    
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,a,b=MI()
l=b-a
if l%2==0:
    ans=l//2
    print(ans)
else:
    edge=min(n-b,a-1)
    #print(edge)
    ans=edge
    ans+=1
    l-=1
    ans+=l//2
    print(ans)

Measured memory_bytes: 38384
# pythonっぽい書き方
N = int(input())
A = list(map(int, input().split()))
#tmp = sorted([(a, n) for n, a in enumerate(A, start=1)])
#print(*[x[1] for x in tmp])


# まつり縫いみたいなやり方
# aの要素でアクセスできる形式で、何番目の要素だったのかを保持しておけば良い
tmp = [None] * (N + 1)
for i, a in enumerate(A, start=1):
    tmp[a] = i
A.sort()
print(*[tmp[a] for a in A])



Measured memory_bytes: 63532
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 1000005;
int a[N];
int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[x]++;
        ans = __gcd(ans, x);
    }
    int ok = 1;
    for (int i = 2; i <= 1000000; i++) {
        int cnt = 0;
        for (int j = i; j <= 1000000; j += i) {
            cnt += a[j];
        }
        if (cnt > 1) ok = 0;
    }

    if (ok)
        puts("pairwise coprime");
    else if (ans == 1)
        puts("setwise coprime");
    else
        puts("not coprime");
    return 0;
}


Measured memory_bytes: 7564
// LCS

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

class Main {
	public static void LCS(String s1, String s2) {
		int m = s1.length();
		int n = s2.length();
		int[][] dp = new int[m+1][n+1];

		for(int i = 0; i <= n; i++)
			dp[0][i] = 0;
		for(int i = 0; i <= m; i++)
			dp[i][0] = 0;

		for(int i = 1; i <= m; i++) {
			for(int j = 1; j <= n; j++) {
				if(s1.charAt(i-1) == s2.charAt(j-1))
					dp[i][j] = 1+dp[i-1][j-1];
				else
					dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
		

		String result = "";
		int i, j;
		i = m;
		j = n;
		while(i > 0 && j > 0) {
			if(s1.charAt(i-1) == s2.charAt(j-1)) {
				result = s1.charAt(i-1) + result;
				i -= 1;
				j -= 1;
			}
			else {
				if(dp[i-1][j] > dp[i][j-1])
					i -= 1;
				else
					j -= 1;
			}
		}
		System.out.println(result);
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s1 = br.readLine();
		String s2 = br.readLine();

		LCS(s1, s2);

	}

	public static int max(int...arr) {
		int max = Integer.MIN_VALUE;
		for(int i: arr) {
			if(i > max)
				max = i;
		}
		return max;
	}
}


Measured memory_bytes: 82236
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n = 0;
    scanf("%d", &n);
    int ppp[101][101];

    int g, vv;
    for(g = 0; g<101; g++){
        for(vv = 0; vv<101; vv++){
            ppp[g][vv] = 0;
        }
    }

    int a1, a2, a3;
    int i, j;
    for(i=0; i<n; i++){
        scanf("%d %d", &a1, &a2);
        for(j=0; j<a2; j++){
            scanf("%d", &a3);
            ppp[a1-1][a3-1] = 1;
        }
    }

    int k, l;
    for(k=0; k<n; k++){
        for(l=0; l<n; l++){
            printf("%d", ppp[k][l]);
            if(l != n-1) printf(" ");
        }
        printf("\n");
    }


    return 0;
}



Measured memory_bytes: 2056
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;

	cin >> n;
	string	s;
	map<string, int> kei;

	for (i=0;i<n;i++) {
		cin >> s;
		kei[s] = 1;
	}

	cout << kei.size() << endl;

}


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

int main() {

    string S;
    cin >> S;
    
    if (S == "ABC") {
        cout << "ARC" << endl;
    }
    
    else { cout << "ABC" << endl;
         }
    
    
}

Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

signed main(){
    string T;
    string ans="";

    cin>>T;

    for(int i=0;i<T.size();i++){
        if(T[i]=='P') ans+='P';
        else if(T[i]=='D') ans+='D';
        else ans+='D';
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 3472
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
int P[200][200], L[200];
signed main() {
  int N;
  while (cin >> N, N) {
    for (int i = 0; i < 200; i++) {
      for (int j = 0; j < 200; j++) {
        P[i][j]=0;
      }
    }

    for (int i = 0; i < N; i++) {
      int M; cin >> M;
      for (int j = 0; j < M; j++) {
        int p; cin >> p;
        P[i][p] = 1;
      }
    }
    int K; cin >> K;
    for (int i = 0; i < K; i++) {
      cin >> L[i];
    }
    
    int ans = -1, cnt = 0;
    for (int i = 0; i < N; i++) {
      int flag = 1;
      for (int j = 0; j < K; j++) {
        if (P[i][L[j]] == 0) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        cnt++;
        ans = i+1;
      }
    }
    
    if (cnt > 1) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
}




Measured memory_bytes: 3416
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long



int main(void) {

	int N,a[100],i,j,target,powtemp;
	long ans,temp;

	ans = 0x7FFFFFFF;
	scanf("%d", &N);

	for(i=0;i<N;i++){
		scanf("%d", &a[i]);
	}

	for(i=-100;i<101;i++){
		temp = 0;
		target = i;
		for(j=0;j<N;j++){
			powtemp = a[j]-target;
			temp += powtemp * powtemp;
		}
		if(ans > temp){
			ans = temp;
		}

	}

	printf("%ld", ans);

	return 0;
}

/* 最後の改行忘れるな！！ */


Measured memory_bytes: 128
#include <iostream>

constexpr int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {
	bool all_visited = true;

	for (int i = 0; i < N; ++i) {
		if (visited[i] == false)
			all_visited = false;
	}

	if (all_visited)
		return 1;

	int ret = 0;

	for (int i = 0; i < N; ++i) {
		if (graph[v][i] == false)
			continue;
		if (visited[i])
			continue;

		visited[i] = true;
		ret += dfs(i, N, visited);
		visited[i] = false;
	}

	return ret;
}

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

	for (int i = 0; i < M; ++i) {
		int A, B;
		std::cin >> A >> B;
		graph[A - 1][B - 1] = graph[B - 1][A - 1] = true;
	}

	bool visited[nmax];

	for (int i = 0; i < N; ++i) {
		visited[i] = false;
	}

	visited[0] = true;
	std::cout << dfs(0, N, visited) << '\n';

	return 0;
}




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

const int Max = 510000;
const int primary = 1000000007;
long long fac[Max], finv[Max], inv[Max];

void make_cmb()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	int i;
	for (i = 2; i < Max; i++)
	{
		fac[i] = fac[i - 1] * i % primary;
		inv[i] = primary - inv[primary % i] * (primary / i) % primary;
		finv[i] = finv[i - 1] * inv[i] % primary;
	}
}
long long nCr(int n, int r)
{
	if (n < r || n < 0 || r < 0)
		return 0;
	return fac[n] * (finv[r] * finv[n - r] % primary) % primary;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	make_cmb();
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	long long result = 0;
	int i;
	for (i = 0; i < H - A; i++)
	{
		int tmp = i + 1 + B;
		result += (nCr(tmp - 2, B - 1) * nCr(H + W + 1 - tmp - 2, W - B - 1)) % 1000000007;
		result = result % 1000000007;
	}
	cout << result;
	return 0;
}


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

signed main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if( A == B ){
    cout << 0 << endl;
  }else if( A > B ){
    if( K % 2  == 1 ){
      cout << B-A << endl;
    }else{
      cout << A-B << endl;
    }
  }else if( A < B ){
    if( K % 2 == 1 ){
      cout << B-A << endl;
    }else{
      cout << A-B << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

class union_find {
public:
	union_find(int n)
	: par_(n, -1)
	{}
	void init(int n) {
		par_.assign(n, -1);
	}

	int root(int x) {
		return par_[x] < 0 ? x : par_[x] = root(par_[x]);
	}

	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if(x == y) {
			return false;
		} else {
			if(par_[x] < par_[y]) {
				par_[x] += par_[y];
				par_[y] = x;
			} else {
				par_[y] += par_[x];
				par_[x] = y;
			}
			return true;
		}
	}

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

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

private:
	std::vector<int> par_;
};

ll n,m;

ll solve() {
	union_find uf(n);
	ll cnct=n;
	vector<pair<ll,P>> edg;
	REP(i,m) {
		ll s,t,c;
		cin>>s>>t>>c;
		s--; t--;
		edg.pb(make_pair(c,P(s,t)));
	}
	sort(ALL(edg));
	REP(i,m) {
		if(!uf.same(edg[i].second.first,edg[i].second.second)) cnct--;
		if(cnct==n/2) return edg[i].first;
		uf.unite(edg[i].second.first,edg[i].second.second);
	}
	return 3939;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>n>>m;
		if(n==0&&m==0) break;
		cout<<solve()<<endl;
	}
	return 0;
}



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

int main(){
  int N;
  string S;
  cin>>N>>S;
  vector<int> a(N),b(N);
  int j=0;
  for(int i=0;i<N;i++){
    int k=0;
    if(S.at(i)=='E')
      k=1;
    j+=k;
    a.at(i)=j;
    b.at(i)=i+1-j;
  }
  j=a.at(N-1)-a.at(0);
  for(int i=1;i<N;i++){
    int k=b.at(i-1)+a.at(N-1)-a.at(i);
    j=min(j,k);
  }
  cout<<j<<endl;
}

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

int main()
{
int N;
  cin>>N;
  int A;
  if(N%2==0)
  {
    A=(N/2)-1;
  }
  else
  {
    A = (N-1)/2;
  }
  cout<<A<<endl;
}


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

int main(){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e-a <= k) cout << "Yay!" << endl;
  else cout  << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
struct unionfind{
	int par[1000],sz[1000];
	void init(int N){rep(i,N) par[i]=i,sz[i]=1;}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		par[y]=x;
		sz[x]+=sz[y];
	}
}UF;
int main(){
	int N,M;
	cin>>N>>M;
	UF.init(N);
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		UF.unite(a,b);
	}
	int x=0;
	rep(i,N) if(UF.find(i)==i){
		if(UF.sz[i]==1) x++;
		else x--;
	}
	cout<<abs(x)<<endl;
}

Measured memory_bytes: 3120
from collections import deque
n,q = map(int,input().split())
g = [[] for _ in range(n+1)]
v = [0]*(n+1)
ans = [0]*(n+1)
for _ in range(n-1):
	a,b = map(int,input().split())
	g[a].append(b)
	g[b].append(a)
for _ in range(q):
	p,x = map(int,input().split())
	v[p] += x
alr = [False]*(n+1)
ans[1] = v[1]
stk = deque()
stk.append(1)
while stk:
	cur = stk.pop()
	alr[cur] = True
	for nxt in g[cur]:
		if not alr[nxt]:
			ans[nxt] = ans[cur] + v[nxt]
			stk.append(nxt)
print(*ans[1:])	

Measured memory_bytes: 63596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    ll n,m,x,ans = INF;
    cin>>n>>m>>x;

    vector<int>c(n),sum(m,0);
    vector<vector<int>>a(n,vector<int>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }

    rep(i,(1LL << n)){
        ll cost = 0;
        rep(j,m)sum[j] = 0;
        rep(j,n){
            if(i & (1LL << j)){
                cost += c[j];
                rep(k,m){
                    sum[k] += a[j][k];
                }
            }
        }
        bool flag = true;
        rep(j,m)if(sum[j] < x)flag = false;
        if(flag)ans = min(ans,cost);
    }
    if(ans != INF)cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  int x,y,m,n,l;

  scanf("%d %d",&x,&y);

  if(x >= y){
    m = x;
    n = y;
  }
  else {
    m = y;
    n = x;
  }

  while(n !=0){
    l = n;
    n = m % n;
    m = l;
  }
  printf("%d\n",m);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef pair<int,P> PP;
typedef pair<ll,LP> LPP;


int main(){
    string s;
    cin >> s;
    string a[3]={"Sunny","Cloudy","Rainy"};
    rep(i,3){
        if(s==a[i])cout << a[(i+1)%3] << endl;
    }

    return 0;
}

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


int main() {
    int N;
    cin>>N;
    int count=0;
    while(N>=3){
        count++;
        N-=3;
        if(N-3>=3)continue;
        else{
            count++;
            break;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
program speedrun
implicit none
integer(16)::N
integer(16),allocatable,dimension(:)::C
integer(16)::ANS=0,mo=10**9+7,mm=1
integer(16)::i
read*,N
allocate(C(N))
read*,C
call heapsort(N,C)
do i=1,N
    ANS=mod(ANS+C(i)*(N-i+2),mo)
end do
do i=1,N-1
    mm=mod(mm*4,mo)
end do
print"(i0)",mod(ANS*mm,mo)

contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end program speedrun

Measured memory_bytes: 3968
#!/usr/bin/env python3


if __name__ == '__main__':
    n, k = list(map(int, input().split()))

    ans = []
    for i in range(1, n+1):
        tmp = i
        j = 0
        while tmp < k:
            j += 1
            tmp *= 2
        ans.append((1 / n) * ((1 / 2) ** j))

    print('{:.12f}'.format(sum(ans)))

Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    ll N,K;
    cin>>N>>K;
    vll A(N+1);
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    vi step(N+1);
    vi check(N+1,-1);
    int pos=1,count=0;
    step[0]=1;
    check[1]=0;

    while(1){
        count++;
        pos=A[pos];
        if(check[pos]>=0){
            break;
        }else{
            check[pos]=count;
            step[count]=pos;
        }
    }
    int tail=check[pos];
    int loop=count-tail;
    //cout<<tail<<" "<<loop<<endl;
    if(K<=tail){
        cout<<step[K]<<endl;
    }else{
        cout<<step[tail+((K-tail)%loop)]<<endl;
    }
}


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

int n;
int C, B, A;

int l[1005];

int dfs(int k, int a, int b, int c){
	if(k == n){
		if(a == 0 || b == 0 || c == 0) return 1e9;
		return abs(A-a) + abs(B-b) + abs(C-c);
	}
	int ans = 1e9;
	ans = min(ans,dfs(k+1,a+l[k],b,c)+(a>0 ? 10:0));
	ans = min(ans,dfs(k+1,a,b+l[k],c)+(b>0 ? 10:0));
	ans = min(ans,dfs(k+1,a,b,c+l[k])+(c>0 ? 10:0));
	ans = min(ans,dfs(k+1,a,b,c));
	return ans;
}

int main(){
	cin >> n >> A >> B >> C;
	for(int i = 0; i < n; ++i) cin >> l[i];
	cout << dfs(0,0,0,0) <<endl;
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
G = [[] for _ in range(n)]
for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)

lis = [float('inf')] * n
ans = [0] * n

def dp(v, prev):
    i = bisect_left(lis, a[v])
    tmp = lis[i]
    lis[i] = a[v]
    ans[v] = bisect_left(lis, float('inf'))
    for u in G[v]:
        if u != prev:
            dp(u, v)
    lis[i] = tmp

dp(0, -1)
for l in ans:
    print(l)


Measured memory_bytes: 224884