akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int A[100005];
int tmp[100005];

int main() {

	int N;

	scanf("%d",&N);

	int i;

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

	int k = 0;

	for (i = 0; i < 100005; i++) {
		if (tmp[i] > 0) {
			k++;
		}
	}

	if (k % 2 == 0) { printf("%d\n",k-1); }
	else { printf("%d\n",k); }


	return 0;
}

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

using namespace std;


int main()
{
    int n,j=0,b=0;
    double tem,ans=0;
    char s[4];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>tem>>s;
        if(s[0]=='J')
            ans+=tem;
        else ans+=(tem*380000.0);

    }
    printf("%.7lf",ans);
    return 0;
}





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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    string s,u="";
    cin >> s;
    int ss=s.size();
    string t="ACGT";

    int count=0;
    int max_=0;
    bool flag=false;
    rep(i,ss){
        rep(j,4){
            if(s[i]==t[j]){
                flag=true;
                break;
            }
            if(j==3){
                flag=false;
                count=0;
            }
        }
        if(flag){
            count++;
            max_=max(max_,count);
        }
    }

    cout << max_;



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  int n,m; cin>>n>>m;
  vector<int> l(n,0);
  rep(i,m){
    int a,b; cin>>a>>b;
    a--;b--;
    l[a]++;l[b]++;
  }
  rep(i,n){
    cout<<l[i]<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    int x=0;
    int ans=x;
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I')x++;
        else x--;
        ans=max(ans,x);
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

// 163
/* c
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        a[i] = 0;
    }
    for(int i = 0; i < n - 1; i++){
        int x;
        cin >> x;
        a[x - 1]++;
    }
    for(int i = 0; i < n; i++){
        cout << a[i] << endl;
    }
}
*/
/* d */
int main(){
    ll mod = pow(10, 9) + 7;
    ll n, k;
    cin >> n >> k;

    ll max = 0;
    ll min = 0;
    ll ans = 0;

    for(ll i = k; i <= n; i++){
        min = static_cast<long long>(i) * (0 + i - 1) / 2;
        max = i * (n + (n - i + 1)) / 2;
        ans += (max - min + 1);
        ans %= mod;
    }
    cout << ans + 1 << endl;
}




Measured memory_bytes: 3624
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=[]
heapq.heapify(ans)
for i in range(x):
    _p=heapq.heappop(p)
    heapq.heappush(ans,-_p)
for i in range(y):
    _q=heapq.heappop(q)
    heapq.heappush(ans,-_q)
#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==0:break
    _ans=heapq.heappop(ans)
    _r=-heapq.heappop(r)
    if _r>=_ans:
        heapq.heappush(ans,_r)
    else:
        heapq.heappush(ans,_ans)
        break
print(sum(ans))

Measured memory_bytes: 23456
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> s(N);
	int sum = 0;
	
	for(int i=0;i<N;i++){
		cin>>s[i];
		sum += s[i];
	}
	
	sort(s.begin(),s.end());
	
	if(sum%10!=0){
		cout<<sum<<endl;
		return 0;
	}
	
	for(int i=0;i<N;i++){
		if(s[i]%10!=0){
			cout<<sum-s[i]<<endl;
			return 0;
		}
	}
	
	cout<<0<<endl;
	
	
	
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

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

  double x = (n % 2 == 0) ? n/2 : (n+1)/2;

  cout << x / n << endl;
  
  return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  double ans=0;
  vector<double> v(N);
  for(int i=1;i<=N;i++){
    int count=0;
    int x=i;
    while(x<K){
      x*=2;
      count++;
    }
    v.at(i-1)=1/(N*pow(2,count));
  }
  for(int i=0;i<N;i++){
    ans+=v.at(i);
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
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; }
using LP  = pair<ll, int>;
int main()
{
    int N;
    cin >> N;
    vl A(N);
    vector<LP> B;
    rep(i, N) {
        cin >> A[i];
        B.eb(LP(A[i] +i, i));
    }
    map<ll, int> m;
    ll ans = 0;
    rep(i, N)
    {
        ll a = A[i] + i;
        ll b = i - A[i];
        m[a]++;
        ans += m[b];
        
    }
    //  sort(ALL(B));
    // vl C(N);
    // rep(i, N) C[i] = B[i].first;
    // // |j-i| = ai + aj
    // // j = (ai+i) + aj 
    // ll ans = 0;
    // rep2(j, 2, N)
    // {
    //     ll x = j-A[j];
    //     if(x < 2) continue;
    //     auto p = lower_bound(ALL(C), x);
    //     while(p != C.end()){
    //        //if(B[p-C.begin()].second != j ) {
    //             if(*p == x) ++ans;
    //             else break;
    //         //}
    //         ++p;
    //     }
    // }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

string s;

const int N = 1e6;
int dp[2][N + 5];

int calc(int st, int pos) {
  if(pos == -1) return st;
  int &res = dp[st][pos];
  if(res != -1) return res;
  res = 1e9;
  int val = s[pos] - '0';
  if(st == 0) {
    res = min(calc(0, pos - 1) + val, calc(1, pos - 1) + 10 - val);
  } else {
    int nval = val + 1;
    if(nval != 10) res = min(calc(0, pos - 1) + nval, calc(1, pos - 1) + 10 - nval);
    else res = calc(1, pos - 1) + 10 - nval;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin>>s;
  memset(dp, -1, sizeof dp);
  cout<<calc(0, s.size() - 1)<<endl;
  return 0;
}


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

int main() {
    int N;
    while (cin >> N, N) {
        int sum = 0;
        if (N > 1) sum = 1;
        for (int i = 2; i <= sqrt(N); i++) {
            if (N % i == 0) {
                if (i != (N/i))
                    sum += i + (N/i);
                else
                    sum += i;
            }
        }

        if (sum < N) cout << "deficient number" << endl;
        else if (sum == N) cout << "perfect number" << endl;
        else cout << "abundant number" << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >> n;
vector<int>box(n,1);
vector<bool>che(n,false);
che.at(0)=true;
int m;
cin >> m;
for(int i=0;i<m;i++){
    int x,y;
    cin >> x >> y;x--;y--;
    box.at(x)--;
    box.at(y)++;
    if(che.at(x))che.at(y)=true;
        if(box.at(x)==0)che.at(x)=false;
}
ll ans = 0;
for(int i=0;i<n;i++){
    if(che.at(i))ans++;
}
cout << ans << endl;
}



Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()

	a := make([]int, n+1)
	count := make([]int, n+1)
	for i := 2; i <= n; i++ {
		a[i] = readInt()
		count[a[i]]++
	}
	for i := 1; i <= n; i++ {
		fmt.Println(count[i])
	}
}


Measured memory_bytes: 7296
n,ma,mb = map(int, input().split())
abcl = []
for _ in range(n):
    a,b,c = map(int, input().split())
    abcl.append((a,b,c))

dp = [ [ [10**9]*401  for _ in range(401) ] for _ in range(n+1) ]
dp[0][0][0] = 0
for i in range(n):
    ai,bi,ci = abcl[i]
    for a in range(401):
        for b in range(401):
            if a+ai < 401 and b+bi < 401:
                dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b])
                dp[i+1][a+ai][b+bi] = min(dp[i][a][b] + ci, dp[i+1][a+ai][b+bi])


ans = 10**9
dp_row = dp[n]
for a in range(1,401):
    for b in range(1,401):
        if ma*b == mb*a:
            v = dp[n][a][b]
            ans = min(ans,v)

if ans == 10**9: ans = -1
print(ans)

Measured memory_bytes: 127856
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
const int mod = 998244353 ;
const int inf = 1e9 + 5;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 3e3 + 5 ;
int n ;
double dp[maxn][maxn] ;
double p[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1)
    cin >> p[i] ;
    rep(i,0,n-1)
    rep(j,0,n)
    dp[i][j] = 0.0 ;
    dp[0][1] = p[0] ;
    dp[0][0] = 1-p[0] ;
    rep(i,1,n-1)
    {
        rep(j,0,n)
        {
            if(j-1 >= 0)
            dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])*dp[i-1][j] ;
            else dp[i][j] = (1-p[i])*dp[i-1][j];
        }
    }
    cout << fixed << setprecision(10) ;
    double res ;
    rep(i,(n+1)/2,n)
    res += dp[n-1][i] ;
    cout << res << "\n" ;
    return 0 ;
}


Measured memory_bytes: 70656
/*
 * Copyright (c) 2019 ... All rights reserved.
 * ...
 */
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    // source code
    int a = inputValue();
    int b = inputValue();
    int c = inputValue();

    if (a <= c and c <= b){
        cout << "Yes" << endl;
    }else if(b <= c and c <= a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    cout<<"100 100"<<endl;
    int A,B;
    cin >> A >> B;
    
    char grid[100][100];
    for(int i=0; i<50; i++){
        for(int j=0; j<100; j++){
            grid[i][j]='.';
        }
    }
    for(int i=50; i<100; i++){
        for(int j=0; j<100; j++){
            grid[i][j]='#';
        }
    }
    
    A--;
    B--;
    
    
    for(int i=0; i<50; i+=2){
        for(int j=0; j<100; j+=2){
            if(B>0){
                grid[i][j]='#';
                B--;
            }
        }
    }
    
    for(int i=51; i<100; i+=2){
        for(int j=0; j<100; j+=2){
            if(A>0){
                grid[i][j]='.';
                A--;
            }
        }
    }
    
    
    
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            cout<<grid[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
const ll MOD = 1000000007;
const int N = 100000 + 7;
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int main()
{
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif*/
	ll n, p;
	scanf("%lld%lld", &n, &p);
	ll i = 2, ans = 1;
	int cnt;
	for (i = 2; i*i <= p; i++)
	{
		cnt = 0;
		while (p%i == 0)
		{
			cnt++;
			p /= i;
		}
		cnt /= n;
		while (cnt--)
			ans *= i;
	}
	if (n == 1)
		ans *= p;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import math

n,d = map(int,input().split())
ans = 0
li=[list(map(int,input().split())) for i in range(n)]

for i in range(n-1):
    for j in range(i+1,n):
        cnt = 0
        for k in range(d):
            cnt += (li[i][k] - li[j][k])**2
        if math.sqrt(cnt).is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 9200
(let ((str (read-line)))
  (loop for end downfrom (- (length str) 2) to 0 by 2
     until (or (string= str str
			 :start1 0 :end1 (/ end 2)
			 :start2 (/ end 2) :end2 end)
	       (zerop end))
     finally (princ end)))

Measured memory_bytes: 11748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args)
	{
		FastReader in = new FastReader();
		boolean exist = false;
		int num = in.nextInt();
		int max = in.nextInt();
		int cost = Integer.MAX_VALUE;
		for(int i = 0; i < num; i++)
		{
			int c = in.nextInt();
			int t = in.nextInt();
			if(c < cost && t <= max)
			{
				cost = c;
				exist = true;
			}
		}
		if(exist)
			System.out.println(cost);
		else
			System.out.println("TLE");
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 

	
}


Measured memory_bytes: 21076
# C - たくさんの数式 / Many Formulas
s = input()
n = len(s)-1
o = []

if n==0:
    print(int(s))
    exit()

for i in range(2**n):
    op = [0]*n
    for j in range(n):
        if ((i>>j)&1):
            op[n-1-j]=1
    o.append(op)

ans = 0

for i,oo in enumerate(o):
    t = ''
    for j,ss in enumerate(s):
        if j==0:
            t += ss
            continue
        if o[i][j-1]:
            ans += int(t)
            t = ''
            t += ss
        else:
            t += ss
        if j==n:
            ans += int(t)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,road[200005],rail[200005],connect[200005];
pair<pair<int,int>,int> total[200005];

int root (int ind) {
	if (road[ind] == ind) return ind; else 
	return road[ind] = root(road[ind]);
}

void onion(int l, int r) {
	if (root(l) != root(r)) road[root(l)] = root(r);
}

int root2(int ind) {
	if (rail[ind] == ind) return ind; else 
	return rail[ind] = root2(rail[ind]);
}

void onion2(int l, int r) {
	if (root2(l) != root2(r)) rail[root2(l)] = root2(r);
}

int main() {
	cin >> x >> y >> z;
	for (int i = 0; i <= x; i++) {
		rail[i] = i;
		road[i] = i;
	}
	for (int i = 0; i < y; i++) {
		cin >> n >> m;
		onion(n,m);
	}
	for (int i = 0; i < z; i++) {
		cin >> n >> m;
		onion2(n,m);
	}
	for (int i = 1; i <= x; i++) {
		total[i] = make_pair(make_pair(root(i),root2(i)),i);
	}
	sort(total+1,total+1+x);
	total[x+1].f.f = total[x+1].f.s = -31415;
	stack<int> st; while (!st.empty()) st.pop();
	int a1 = 0,a2 = 0,b1 = 0,b2 = 0;
	for (int i = 1; i <= x+1; i++) {
		a1 = total[i].f.f, a2 = total[i].f.s;
		if (!(st.empty() || (a1 == b1 && a2 == b2))) {
			int tmp = st.size();
			while (!st.empty()) {
				connect[st.top()] += tmp-1;
				st.pop(); 
			}
		} 
		b1 = a1, b2 = a2;
		st.push(total[i].second);
	}
	for (int i = 1; i <= x; i++) {
		cout << connect[i]+1 << " ";
	}
}

Measured memory_bytes: 8216
from collections import defaultdict
import sys
sys.setrecursionlimit(1 << 25)

G = defaultdict(lambda: [])
n, m = map(int, input().split())
color = {key: None for key in range(n)}

for _ in range(m):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)

# 離接リストをもとに、たどり着ける友達関係をグループ化する #(union findが使える気もするけどここではDFSで領域を探索していく)


def dfs(node: int, co: int):
    if color[node] is not None:
        return
    color[node] = co

    for no in G[node]:
        dfs(no, co)
    return


# すべてのnodeを開始点としてdfsで領域わけしてみる
c = 1
for node in G.keys():
    dfs(node, c)
    c += 1

Q = int(input())
for _ in range(Q):
    s, t = list(map(int, input().split()))
    if color[s] and color[t] and color[s] == color[t]:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 143920
n,a = map(int,input().split())
x = list(map(int,input().split()))
dp = [[[0]*(n*max(max(x),a)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(1,n+1):
    for j in range(n+1):
        for k in range(n*max(max(x),a)+1):
            dp[i][j][k] = dp[i-1][j][k]
            if x[i-1] <= k and j>0:
                dp[i][j][k] += dp[i-1][j-1][k-x[i-1]]
ans = 0
for j in range(1,n+1):
    ans += dp[n][j][j*a]
print(ans)

Measured memory_bytes: 93404
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c;cin>>a>>b>>c;
  if(a==5 && b==5 && c==7){
    P("YES");
  }else if(a==5 && b==7 && c==5){
    P("YES");
  }else if(a==7 && b==5 && c==5){
    P("YES");
  }else{
    P("NO");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x0 = 0, y0 = 0;
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int n = sc.nextInt();

        for(int i = 0; i < n; i++) {
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int a = sc.nextInt();
        	if(a == 1) {
        		x0 = Math.max(x0, x);
        	} else if (a == 2) {
        		x1 = Math.min(x1, x);
        	} else if (a == 3) {
        	    y0 = Math.max(y0, y);
        	} else {
        		y1 = Math.min(y1, y);
        	}
        }
        int area = 0;
        if(x0 < x1 && y0 < y1)
        	area = (x1 - x0) * (y1 - y0);
        System.out.println(area);
    }
}


Measured memory_bytes: 21716
N=int(input())
H=list(map(int,input().split()))
#C=[[] for i in range(N)]
C=[0]*N
C[0]=0
C[1]=abs(H[1]-H[0])
for i in range(2,N):
    C[i]=min(C[i-1]+abs(H[i]-H[i-1]),C[i-2]+abs(H[i]-H[i-2]))
print(C[N-1])


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


int main() {
  int N, D, result;
  int i;
  scanf ("%d %d", &N, &D);
  
  if (N%(D*2+1)==0) result = N/(D*2+1);
  else              result = N/(D*2+1)+1;
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    ll a, b1, b2;
    scanf("%lld %lld.%lld", &a, &b1, &b2);
    ll b = b1 * 100 + b2;
    cout << a * b / 100 << endl;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,m; cin>>n>>m;
    vector<ll> a(m);
    rep(i,n){
        ll k; cin>>k;
        rep(j,k){
            ll b; cin>>b;
            a[b-1]++;
        }
    }
    ll ans=0;
    rep(i,m){
        if(a[i]==n) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
 int W,H,x,y,r;
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if(x+r<=W && H>=y+r && r<=y && r<=x && x>=0 && y>=0)
    printf("Yes\n");
 else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 2128
def main():
    import sys
    input = sys.stdin.readline

    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 998244353

    dp = [[0] * (S+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(S+1):
            dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod
            if j+a <= S:
                tmp = 1
                if j == 0:
                    tmp *= (i+1)
                if j+a == S:
                    tmp *= (N-i)
                dp[i+1][j+a] = (dp[i+1][j+a] + (dp[i][j] * tmp)%mod)%mod
    print(dp[-1][S])


if __name__ == '__main__':
    main()


Measured memory_bytes: 111836
n = int(input())
cities = list(map(int,input().split()))
heroes = list(map(int,input().split()))
ans = 0
for i in range(n):
	if cities[i] < heroes[i]:
		ans += cities[i]
		heroes[i] -= cities[i]
		cities[i] = 0
	else:
		ans += heroes[i]
		cities[i] -= heroes[i]
		heroes[i] = 0
	
	if cities[i+1] < heroes[i]:
		ans += cities[i+1]
		heroes[i] -= cities[i+1]
		cities[i+1] = 0
	else:
		ans += heroes[i]
		cities[i+1] -= heroes[i]
		heroes[i] = 0
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string o,e;
  cin>>o>>e;
  REP(i,o.size()){
    cout<<o[i];
    if(i<e.size())cout<<e[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 105, mod = (int) 1e9 + 7;
int dp[N * N], odp[N * N];
void sadd(int &x, int y) {
	x += y;
	while (x >= mod) x -= mod;
}
int main() {
	int n, k;
	cin >> n >> k;
	int sum_all = n * (k + 1) * k / 2;
	for (int x = 0; x < n - 1; ++x) sum_all = sum_all * (LL) (k + 1) % mod;
	dp[0] = 1;
	for (int pl = n - 1; pl >= 0; --pl) {
		memcpy(odp, dp, sizeof dp);
		memset(dp, 0, sizeof dp);
		for (int val = 0; val <= k; ++val) {
			if (val > pl + 1) {
				for (int j = 0; j < N * N; ++j) if (odp[j]) sadd(dp[j], odp[j]);	
			} else {
				for (int j = 0; j < N * N; ++j)	if (odp[j]) {
					int fin_val = j + val;
					int add = fin_val / (pl + 1);
					sadd(dp[j + add], odp[j]);
				}
			}
		}
	}
	for (int j = 0; j < N * N; ++j) if (dp[j]) {
		sum_all = (sum_all - dp[j] * (LL) j % mod + mod) % mod;
	}
	cout << sum_all << endl;
}






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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second

using namespace std;

struct day {
    int a_i, b_i, c_i;
};

void holidayPlan(){
    int n;
    cin >> n;
    vector<day> days;
    lp(i, 0, n){
        int a, b, c;
        cin >> a >> b >> c;
        days.push_back({a, b, c});
    }
    int maxLuv[n + 5][3];
    maxLuv[0][0] = days.at(0).a_i;
    maxLuv[0][1] = days.at(0).b_i;
    maxLuv[0][2] = days.at(0).c_i;
    lp(i, 1, n){
        lp(j, 0, 3){
            if (j == 0) maxLuv[i][j] = days.at(i).a_i + max(maxLuv[i - 1][1], maxLuv[i - 1][2]);
            else if (j == 1) maxLuv[i][j] = days.at(i).b_i + max(maxLuv[i - 1][0], maxLuv[i - 1][2]);
            else maxLuv[i][j] = days.at(i).c_i + max(maxLuv[i - 1][0], maxLuv[i - 1][1]);
        }
    }
    cout << max(maxLuv[n - 1][0], max(maxLuv[n - 1][1], maxLuv[n - 1][2])) << endl;
}

int main() {
    holidayPlan();
}




Measured memory_bytes: 2676
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String baseStr = sc.next();
		String resultStr = sc.next();

		int result = 0;
		for(int i=0;i<baseStr.length();i++) {
			if(baseStr.charAt(i) != resultStr.charAt(i)) {
				result++;
			}

		}
		sc.close();

		System.out.println(result);

	}


}

Measured memory_bytes: 32020
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;


int main() {
    ll n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    ll inf = 1e10;
    vector<vector<ll>> dp(n, vector<ll>(n, inf));
    for (ll i = 0; i < n; ++i) {
        dp[i][i] = 0;
        for (ll j = 1; i + j < n; ++j) {
            dp[i][i+j] = j;
            dp[i+j][i] = j;
        }
    }
    dp[x][y] = 1;
    dp[y][x] = 1;
    for (ll i = 0; i < n; ++i) {
        for (ll j = 1; i + j < n; ++ j) {
            dp[i][i+j] = min(dp[i][i+j], dp[i][x] + dp[x][y] + dp[y][i+j]);
            dp[i][i+j] = min(dp[i][i+j], dp[i][y] + dp[y][x] + dp[x][i+j]);
            dp[i+j][i] = dp[i][i+j];
            // cerr << i << "," << j << ":" << dp[i][i+j] << endl;
        }
    }
    vector<ll> res(n, 0);
    for (ll i = 0; i < n; ++i) {
        for (ll j = i+1; j < n; ++j) {
            res[dp[i][j]]++;
        }
    }
    for (ll i = 1; i < n; ++i) {
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 31744
h, w = map(int, input().split())
mat = []
idx = []
mat2 = []
for i in range(h):
    tmp = input()
    if tmp.count('.') != w:
        mat.append(tmp)

###行と列を入れ替える
for i in range(w):
    tmp2 = ''
    for j in range(len(mat)):
        tmp2 += mat[j][i]
    mat2.append(tmp2)

mat.clear()
for i in range(len(mat2)):
    if mat2[i].count('.') != len(mat2[i]):
        mat.append(mat2[i])

for i in range(len(mat[0])):
    ans = ''
    for j in range(len(mat)):
        ans += mat[j][i]
    
    print(ans)

Measured memory_bytes: 3064
N = int(input())
C = []
count_AC = 0
count_WA = 0
count_TLE = 0
count_RE = 0
for i in range(0, N):
    c = input()
    C.append(c)

for i in range(0, N):
    if C[i] == 'AC':
        count_AC += 1
    elif C[i] == 'WA':
        count_WA += 1
    elif C[i] == 'TLE':
        count_TLE += 1
    elif C[i] == 'RE':
        count_RE += 1


print("AC x " + str(count_AC))
print("WA x " + str(count_WA))
print("TLE x " + str(count_TLE))
print("RE x " + str(count_RE))


Measured memory_bytes: 16324
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(30).
01 A          PIC 9(10).
01 B          PIC 9(10).
01 ans        PIC 9(10) VALUE ZERO COMP.
01 cur        PIC 9(10) VALUE 1 COMP.
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B.
  PERFORM UNTIL B <= cur
    ADD 1 TO ans
    COMPUTE cur = cur + A - 1
  END-PERFORM.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

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

    cout << (N-1)/(K-1) + ((N-1)%(K-1) == 0 ? 0 : 1) << endl;
    return 0;
}

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

#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<int,pi>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define debug cout<<"debugging"<<endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int I_LIMIT = 999999999;
ll L_LIMIT = 19999999999999999;
ll mod = 998244353;

void solve()
{
    ll n,k,i,l,r,j,bb=0;
    cin>>n>>k;
    ll A[k][2];
    for(i=0;i<k;i++)
        cin>>A[i][0]>>A[i][1];
    
    ll dp[n+1],pre[n+1];

    pre[0] = 0;
    dp[0] = 0;
    dp[1] = 1;
    pre[1] = 1;
    for(i=2;i<=n;i++)
    {
        dp[i] = 0;
        for(j=0;j<k;j++)
        {
            l = A[j][0];
            r = A[j][1];
            
            if(i-l>0)
                dp[i] = (dp[i]+pre[i-l]-pre[max(i-r-1,bb)]+mod*10000000)%mod;
        }
        pre[i] = (dp[i]+pre[i-1])%mod;
    }
    
    cout<<dp[n]<<"\n";
    return;
}
int main()
{
    IOS;
    solve();
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e11;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    ll h,n,a,c =0;
    cin >> h >> n;
    rep(i,n){
        cin >> a;
        c += a;
    }
    if (h <= c) PRINT("Yes");
    else PRINT("No");
}

Measured memory_bytes: 256
# パスカルの三角形
N, K = map(int, input().split())

m = 1000000007

n = max(K, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    c[i][0] = 1
    for j in range(1, i + 1):
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % m)
#print('\n'.join(str(i) for i in result))
print(*result, sep='\n')


Measured memory_bytes: 103852
#include<bits/stdc++.h>
 
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  int ans=0;
  vector<bool> a(n);
  for(int i=0;i<n;i++)if(i+1==v[v[i]-1] && !a[i] && i+1!=v[i])ans++,a[i]=true,a[v[i]-1]=true;
  cout << ans << endl;
  return 0;
}

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


int main () {
    int r ;
    cin >> r;
    cout << r*r << endl;    
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

ll MAX_V = 2e5 + 5;
vector<vector<ll>> G(MAX_V);//隣接リスト(添え字は始点、値は終点)
vector<ll>t(MAX_V);//訪問したかどうか
void dfs(ll k,ll x){
  t[k]=x;
  for(ll i=0;i<G[k].size();i++){
    if(t[G[k][i]]==0){
      dfs(G[k][i],x); 
    }
  }
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  multiset<ll>st;
  vector<ll>a(n);
  rep(i,0,n){
    ll x;cin>>x;
    st.insert(x);
    a[i]=x;
  }
  for(ll i=0;i<m;i++){
    ll p,q;
    cin>>p>>q;
    G[p].push_back(q);
    G[q].push_back(p);
  }
  ll cnt=0;
  rep(i,0,n){
    if(t[i]==0){
      cnt++;
      dfs(i,cnt);
    }
  }
  if(n/2<cnt-1)cout<<"Impossible"<<endl;
  else if(cnt==1)cout<<0<<endl;
  else{
    vector<ll>b(cnt,INF);
    rep(i,0,n){
      chmin(b[t[i]-1],a[i]);
    }
    ll ret=0;
    rep(i,0,cnt){
      st.erase(st.find(b[i]));
      ret+=b[i];
    }
    ll x=cnt-2;
    for(auto z:st){
      if(x<=0){
        break;
      }
      else{
        ret+=z;
        x--;
      }
    }
    cout<<ret<<endl;
  }
  return 0;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
int n, q;
const int N = 500001;
int a[N], ainv[N]; // ainv : 이 크기를 가진 원소가 마지막으로(왼쪽부터 볼떄)나온 위치
int seg[2 * N]; //새그트리
vector<pi> lq[N];// 오른쪽 끝이 i인 쿼리
int ans[N];// i번째 쿼리의 정답을 저장

// 새그먼트 트리
// 새그 트리가 나타내는 정보 : 수열의 i번째 자리에 서로다른 원소가 있냐 없냐 (1 or 0)
// 이 들어있으므로, 이를 구간합으로 처리하면 [l,r]들어있는 서로 다른 원소의 개수를 알 수 있다.
void update(int p, int val) {// 업데이트
    for (seg[p += N] += val; p > 1; p >>= 1)seg[p >> 1] = seg[p] + seg[p ^ 1];
}
int query(int l, int r) { //[l,r] 구간의 서로 다른 원소의 개수 (구간합으로 처리)
    r++;
    int ret = 0;
    for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
        if (l & 1)ret += seg[l++];
        if (r & 1)ret += seg[--r];
    }
    return ret;
}


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    memset(ainv, -1, sizeof(ainv));
    for (int i = 1; i <= n; i++)cin >> a[i];

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        lq[r].push_back({ l,i }); // 오른쪽 끝이 r인 쿼리의 시작점이 l이고, 이 쿼리를 나타내는 인덱스는 i이다.
    }

    for (int i = 1; i <= n; i++) {
        if (ainv[a[i]] > 0)update(ainv[a[i]], -1);
        update(i, +1);
        ainv[a[i]] = i;
        for (auto k : lq[i]) {
            int l = k.first, qn = k.second;
            ans[qn] = query(l, i);
        }
    }
    for (int i = 0; i < q; i++)cout << ans[i] << "\n";
}

Measured memory_bytes: 35116
rooms = Array.new(4).map! do |n|
  n = Array.new(3).map! do |m|
    m = Array.new(10, 0)
  end
end

gets.to_i.times do
  b, f, r, v = gets.split.map(&:to_i)
  rooms[b - 1][f - 1][r - 1] += v
end

rooms.each_with_index do |i, index|
  i.each do |j|
    puts " " + j.join(" ")
  end
  puts "####################" if index != 3
end

Measured memory_bytes: 6108
using System;
using System.Linq;
namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Trim().ToCharArray();
            var countR = S.Where(x=>x=='R').Count();
            if(countR == 2){
                Console.Write(S[1]=='S' ? 1 : 2);
            }else{
                Console.Write(countR);
            }
        }
    }
}


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

using namespace std;


int main(){
	int N, R;
	scanf("%d %d", &N, &R);
	if (N >= 10) {
		printf("%d\n", R);
	} else {
		printf("%d\n", R + 100 * (10 - N));
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import*

n,m,o=map(int,input().split())
*R,=map(int,input().split())
INF=float("inf")
d=[[INF]*n for _ in range(n)]
r=range
for i in r(n):
	d[i][i]=0
for _ in r(m):
	a,b,c=map(int,input().split())
	d[a-1][b-1]=d[b-1][a-1]=c
for k in r(n):
	for i in r(n):
		for j in r(n):
			d[i][j]=min(d[i][j],d[i][k]+d[k][j])
v=[[d[i-1][j-1]for j in R]for i in R]
m=INF
for t in permutations(r(o)):
	a=0;f=1
	for i,j in zip(t,t[1:]):
		if v[i][j]==INF:
			f=0
			break
		else:
			a+=v[i][j]
	if f:
		m=min(m,a)
print(m)

Measured memory_bytes: 72408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,d,x; 
  cin >>r>>d>>x;
  int tmp=r*x-d;
  cout<<tmp<<endl;
  for(int i=0;i<9;i++){
    int kotae=r*tmp-d;
    cout<<kotae<<endl;
    tmp=kotae;
  }
  return 0;
}

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

int main(){
  string str1, str2;
  int n,a=0,b=0,i;
  cin>>n;
  for (i=0;i<n;i++){
    cin >> str1 >> str2;
    if ( str1 == str2 ) {
      a++;
      b++;
    }
    else if ( str1 < str2 ) b+=3;
    else if ( str1 > str2 ) a+=3;
  }
  cout<<a<<' '<<b<<endl;
}



Measured memory_bytes: 3188
N = int(input())
A = list(map(int, input().split()))
INF = 10**18

dp0 = [-INF] * (N + 2)
dp1 = [-INF] * (N + 2)
dp2 = [-INF] * (N + 2)
dp0[0] = 0
dp0[1] = 0
dp1[0] = 0
dp1[1] = 0

for i, a in enumerate(A, start=2):
    dp0[i] = dp0[i - 2] + a
    dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])
    dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2])

if N % 2 == 1:
    print(dp2[-1])
else:
    print(max(dp1[-1], dp0[-1]))


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

int main() {
	int i, j, n, tmp, a[100];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (i = 0; i < n; i++) {
		tmp = a[i];
		for (j = i - 1; j >= 0; j--) {
			if (a[j] > tmp)a[j + 1] = a[j];
			else break;
		}
		a[j + 1] = tmp;
		for (j = 0; j < n; j++) {
			cout << a[j];
			if (j != n - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
#define MAX 1000

int main(){
    int n;
    int i, j=0, sum;
    int score[MAX];
    double ave, tmp;
    double dev[MAX];

    while(1){
        scanf("%d", &n);
        if(n==0)break;
        sum=0;
        for(i=0;i<n;i++){
            scanf("%d", &score[i]);
            sum+=score[i];
        }
        ave=(double)sum/(double)n;
        tmp=0.0;
        for(i=0;i<n;i++){
            tmp+=pow(score[i]-ave, 2);
        }
        dev[j++]=sqrt(tmp/(double)n);
    }
    for(i=0;i<j;i++){
        printf("%f\n", dev[i]);
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <map>
#include <string>
#define f first
#define s second
using namespace std;
int main(){

  string x; int y;
  int n,q,i,cnt=0;
  queue<pair <string,int> > a;

  cin>>n>>q;
  for(i=0;i<n;i++){
    cin>>x>>y;
    a.push(make_pair(x,y));
  }
  while(!a.empty()){
    cnt+=q;
    a.front().s-=q;
    if(a.front().s>0){
      a.push(a.front());      
      a.pop();
    } else {
      cnt+=a.front().s;
      cout<<a.front().f<<" "<<cnt<<endl;
      a.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 6312
'''
    [bellman_ford]
'''
def bellman_ford(s, n, g): # s: start, n: |V|, g; glaph 
    INF = 10**18
    d = [INF]*n
    d[s] = 0
    for i in range(n-1): # max n-1 loops. if update d[] in n-th loop -> negative cycle
        update = False
        for v_from, v_to, cost in g:
            if d[v_to] > d[v_from] + cost:
                d[v_to] = d[v_from] + cost
                update = True
        if not update:
            return d
    return d
    # else: # if not break until n-th loop -> detect negative cycle
    #     # may do something for negatice cycle
    #     return None


def bellman_ford2(s, n, g, d): # s: start, n: |V|, g; glaph 
    INF = 10**18
    # d = [INF]*n
    # d[s] = 0
    for i in range(n-1): # max n-1 loops. if update d[] in n-th loop -> negative cycle
        update = False
        for v_from, v_to, cost in g:
            if d[v_to] > d[v_from] + cost:
                d[v_to] = -INF
    return d


n,m = map(int, input().split())
g = []
for _ in range(m):
    a,b,c = map(int, input().split())
    g.append((a-1,b-1,-c))

d = bellman_ford(0,n,g)
d2 = bellman_ford2(0,n,g,d[:])

INF = 10**18
if d2[n-1] <= -INF:
    print('inf')
else:
    print(-d[n-1])

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    int res = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x >= k) {
            res++;
        }
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
ll a, b;
int main() { ios::sync_with_stdio(false);cin.tie(0);
	cin >> a >> b;
	cout << max((ll)0, a - b - b);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int N, A, B, C, X, Y[109];
int main() {
	while(scanf("%d%d%d%d%d", &N, &A, &B, &C, &X), N) {
		for(int i = 0; i < N; i++) scanf("%d", &Y[i]);
		int P = 0, ret = -1;
		for(int i = 0; i < 10001; i++) {
			if(X == Y[P]) {
				if(++P == N) {
					ret = i; break;
				}
			}
			X = (A * X + B) % C;
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 2688