akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;

int main(void){
   long long int n;
   cin>>n;
   long long int all=0;
   vector<long long int> hoge(n);
   for(long long int i=0; i<n; i++){
     cin>>hoge.at(i);
     all+=hoge.at(i);
   }

   long long int a=0;
   long long int b=all;
   long long int ans=pow(10,182);
   for(long long int i=0; i<n-1; i++){
     a+=hoge.at(i);
     b-=hoge.at(i);
     ans=min(ans, abs(a-b));
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 1792
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if b == A[i][j]:
        A[i][j] = 101
result = "No"
for i in range(3):
  if A[i].count(101) == 3:
    result = "Yes"
  elif A[0][i] == 101 and A[1][i] == 101 and A[2][i] == 101:
    result = "Yes"
if (A[0][0] == 101 and A[1][1] == 101 and A[2][2] == 101) or (A[0][2] == 101 and A[1][1] == 101 and A[2][0] == 101):
    result = "Yes"
print(result)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Apple Pie
            var line = ReadLine();
            int A = line[0];
            int P = line[1];

            Console.WriteLine((A * 3 + P) / 2);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int a[40000];
int b[40000];

int main() {
  int n;
  while(input(n), n) {
    inputs(a,n);
    inputs(b,n);
    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());
    // output(a,n);
    // output(b,n);

    int ans = -1;
    int idx = 0;

    int cnt = 0;
    for (int k=1; k<=n-1; ++k) {
      if (b[idx] >= a[k-1]) {
        idx++;
      } else {
        cnt++;
      }
      // cout << k << " " << idx << endl;
      if (cnt * 2 > k) {
        ans = k;
        break;
      }
    }
    if (ans == -1) puts("NA");
    else cout << ans << endl;
  }
}

Measured memory_bytes: 1452
def digit_sum(n):
    n_lst = list( str(n) )
    n_sum = 0
    for i in range( len(n_lst) ):
        n_sum += int( n_lst[i] )
    return n_sum

n1 = input()
if digit_sum(n1)%9==0 : print("Yes")
else: print("No")


Measured memory_bytes: 10496
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
int k = 0;

vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }
    
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    //cout << out.size() << " " << d << endl;
    //int p = min(int(out.size()+k), d);
    //int k = 13;
    //int p = min(int(out.size()+k), d);
    /*
    ll q = LLONG_MIN;
    for(int k = 0; k < 26; k++) {
        int p = min(int(out.size()+k), int(d));
        ll tmp = 0;
        for(int i = out.size(); i < p; i++) {
            for(int j = 0; j < 26; j++) {
                //score -= c[j]*((i)-last[j]);
                tmp -= c[j]*((i)-last[j]);
            }
        }
        if(tmp > q) {
            q = tmp;
        }
    }
    */

    //int k = 10;
    k = 3;
    int p = min(int(out.size()+k), int(d));
    for(int i = out.size(); i < p; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i)-last[j]);
            //tmp -= c[j]*((i)-last[j]);
        }
    }
    return score;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h> 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define mem(a,x) memset(a,x,sizeof(a));
using namespace std; 
typedef long long ll;

int main(){
	int x,n;
	int a[107],b[107];
	mem(b,0)
	scanf("%d %d",&x,&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[a[i]] = 1;
	} 
	if(n==0) {printf("%d\n",x); return 0;}
	int d = 200;
	int ans=0;
	for(int i=0;i<=101;i++){
		if(!b[i]){
			int tmp=abs(i-x);
			if(tmp<d) {
				d=tmp;
				ans = i;
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace atcoder;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, q;
    std::cin >> n >> q;
    
    dsu d(n);
    
    for (int i = 0; i < q; ++i) {
        int t, u, v;
        std::cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            std::cout << d.same(u, v) << "\n";
        }
    }
    
    return 0;
}

Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long a[300000],b[300000],n;
vector<pair<long long,long long> > vec;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){cin>>a[i];vec.push_back(make_pair(a[i],i));}
	for(int i=0;i<n;i++){cin>>b[i];vec.push_back(make_pair(b[i],i+n));}
	sort(vec.begin(),vec.end());
	long long v=1;long long cnt=0;
	for(int i=0;i<vec.size();i++){
		if(vec[i].second<n){
			if(cnt<0){v*=1LL*-cnt;}
			cnt++;
		}
		if(vec[i].second>=n){
			if(cnt>0){v*=1LL*cnt;}
			cnt--;
		}
		v%=1000000007LL;
	}
	cout<<v<<endl;
	return 0;
}

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

struct Card {char suit; int val; };

const int MAX = 100000, SENTINEL = 2100000000;
Card L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(Card A[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].val = R[n2].val = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i].val <= R[j].val) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void msort(Card A[], int n, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        msort(A, n, left, mid);
        msort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(Card A[], int p, int r) {
    Card x = A[r];
    int i = p - 1;
    for (int j  = p; j < r; j++) {
        if (A[j].val <= x.val) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

void qsort(Card A[], int n, int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        qsort(A, n, p, q - 1);
        qsort(A, n, q + 1, r);
    }
}

int main(void) {
    int n;
    Card A[MAX], B[MAX];
    cin >> n;
    string s;
    int v;
    for (int i = 0; i < n; i++) {
        cin >> s >> v;
        A[i].suit = B[i].suit = s[0];
        A[i].val = B[i].val = v;
    }

    msort(A, n, 0, n);
    qsort(B, n, 0, n - 1);

    int stable = 1;
    for (int i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) stable = 0;
    }

    cout << (stable ? "Stable" : "Not stable") << endl;
    for (int i = 0; i < n; i++) {
        cout << B[i].suit << " " << B[i].val << endl;
    }

    return 0;
}

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll n, k; 
ll a[200001];
ll adder[200001];

void change()
{
	f(i,0,n-1) adder[i] = 0;
	f(i,0,n-1) {
		ll l = max(0LL,i - a[i]);
		ll r = min(n-1,i + a[i]);
		adder[l]++; adder[r+1]--;
	}
	f(i,1,n-1) adder[i] += adder[i-1];
	f(i,0,n-1) a[i] = adder[i];
}

int main()
{
    // Fast_IO();
    cin >> n >> k;
    f(i,0,n-1) cin >> a[i];
    if(k < 100) {
    	f(i,1,k) change();
    }
    else f(i,0,n-1) a[i] = n;
    f(i,0,n-1) cout << a[i] << spc;
    return 0;
}

Measured memory_bytes: 6704
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<iomanip>
#include<vector>

using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;


int main(){
	ll n,x;
	cin>>n>>x;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0; i<n-1; i++){
		if(a[i] <= x) {
			x -= a[i];
			ans++;
		}
		else break;
	}
	if(x == a[n-1]) cout<<ans+1;
	else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n;
    cin >>n;
    ll t[n],sum=0;
    for(int i=0;i<n;i++){
        cin >>t[i];
        sum+=t[i];
    }
    ll m;
    cin>>m;
    for(int i=0;i<m;i++){
        ll p,x;
        cin >>p>>x;
        ans=sum-t[p-1]+x;
        cout <<ans<<endl;
    }


    return 0;

}

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

int main(){
    string z;
    cin >> z;
    if(z == "a"){cout << "vowel" << endl;}
    else if(z == "i"){cout << "vowel" << endl;}
    else if(z == "u"){cout << "vowel" << endl;}
    else if(z == "e"){cout << "vowel" << endl;}
    else if(z == "o"){cout << "vowel" << endl;}
    else cout << "consonant" << endl;

    return 0;
}

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

using namespace std;




int main(void)
{
    string tmp,ans="";
    vector<string> vec;
    int N,L;

    cin>>N>>L;

    for(int i=0;i<N;i++){
        cin>>tmp;
        vec.push_back(tmp);
    }

    sort(vec.begin(),vec.end());

    for(int i=0;i<vec.size();i++){
        ans+=vec[i];
    }

    cout<<ans<<endl;


	return 0;
}


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

using namespace std;

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

	if ((A == B && A != C && B != C) ||
	    (A != B && A == C && B != C) || (A != B && A != C && B == C)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
c = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    if a[i] != a[minj]:
        c += 1
    a[i],a[minj]=a[minj],a[i]
print(' '.join(map(str,a)))
print(c)


Measured memory_bytes: 5604
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
int main(){
    double n,m,d;
    cin>>n>>m>>d;
    double sad;
    if(d==0){
        sad=n;
    }else{
        sad+=n-(n-d);
        sad+=d;
        sad+=2*((n-d)-d);
    }
   
  cout<<setprecision(16);
    
    cout<<sad/(n*n)*(m-1)<<endl;

    
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

vector<vector<int>> c(10, vector<int>(10));
int V = 10; // 頂点数
void warshall_floyd() {
  for(int k = 0; k < V; ++k)
    for(int i = 0; i < V; ++i)
      for(int j = 0; j < V; ++j)  c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
}
int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, 10){
    rep(j, 10)  cin >> c[i][j];
  }
  rep(i, h)rep(j, w)  cin >> a[i][j];

  warshall_floyd();

  ll ans = 0;
  rep(i, h){
    rep(j, w){
      int num = a[i][j];
      if(num == -1 || num == 1) continue;
      ans += c[num][1];
    }
  }

  cout << ans  << endl;

  
}


Measured memory_bytes: 384
x = gets.chomp.to_i

if x <= 599
	puts 8
elsif x <= 799
	puts 7
elsif x <= 999
	puts 6
elsif x<= 1199
	puts 5
elsif x <= 1399
	puts 4
elsif x <= 1599 
	puts 3
elsif x<= 1799
	puts 2
else
	puts 1
end


Measured memory_bytes: 14432
N = int(input())

has8 = [0] * 201
for num in range(1,201):
    cnt = 0
    if num % 2 == 1:
        for m in range(1,num+1):
            if num % m == 0:
                cnt += 1
        if cnt == 8:
            has8[num] = 1

total = [0] * 201
for i in range(1,201):
    total[i] = total[i-1] + has8[i]

print(total[N])

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

struct Card { char suit, value; };

void trace(int N, struct Card cards[]) {
    if (N <= 0) return;
    cout << cards[0].suit << cards[0].value;
    for (int i = 1; i < N; i++) {
        cout << " " << cards[i].suit << cards[i].value;
    }
    cout << endl;
}

void bubbleSort(int N, struct Card cards[]) {
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j > i; j--) {
            if ( cards[j].value < cards[j - 1].value ) {
                std::swap(cards[j], cards[j - 1]);
            }
        }
    }
}

void selectionSort(int N, struct Card cards[]) {
    for (int i = 0; i < N; i++) {
        int min_i = i;
        for (int j = i; j < N; j++) {
            if (cards[j].value < cards[min_i].value) {
                min_i = j;
            }
        }
        if (i < min_i) {
            std::swap(cards[i], cards[min_i]);
        }
    }
}

bool isStable(int N, struct Card bCards[], struct Card sCards[]) {
    for (int i = 0; i < N; i++) {
        Card bc = bCards[i];
        Card sc = sCards[i];
        if (bc.suit != sc.suit) {
            return false;
        }
    }
    return true;
}

/* ALDS1_2_C: Stable Sort */
int main() {
    int N;
    cin >> N;

    char suit, value;
    Card C1[N], C2[N];

    for (int i = 0; i < N; i++) {
        cin >> suit >> value;
        C1[i].suit  = C2[i].suit  = suit;
        C1[i].value = C2[i].value = value;
    }

    bubbleSort(N, C1);
    selectionSort(N, C2);
    string bStatus = "Stable";
    string sStatus = isStable(N, C1, C2) ? "Stable" : "Not stable";

    trace(N, C1);
    cout << bStatus << endl;
    trace(N, C2);
    cout << sStatus << endl;

    return 0;
}

Measured memory_bytes: 1200
#!/usr/bin/perl -w

while(<>) {
    ($x, $y) = split /\s/, $_;
}

$ret = "No";
if($x == 4 || $x == 6 || $x == 9 || $x == 11) {
    if($y == 4 || $y == 6 || $y == 9 || $y == 11 ) {
        $ret = "Yes";
    }
} elsif($x == 2) {
    if($y == 2) {
        $ret = "Yes";
    }
} else {
    if($y == 1 || $y == 3 || $y == 5 || $y == 7 || $y == 8 || $y == 10 || $y == 12) {
        $ret = "Yes";
    }
}

print "$ret\n";


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

int main() {
	int H, W;
	cin >> H >> W;
	while (!(H == 0 && W == 0))
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
				cout << '#';
			cout << endl;
		}
		cin >> H >> W;
		cout << endl;
	}
}




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

using namespace std;
int a[100005];
bool used[100005]={};
vector<int>edge[100005];
vector<int>cost[100005];
vector<int>G[100005];
int cnt=0;
void dfs(int x){
	used[x]=1;
	G[cnt].push_back(x);
	for(int i=0;i<edge[x].size();i++){
		if(!used[edge[x][i]]){
			dfs(edge[x][i]);
		}
	}
	return;
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	for(int i=0;i<n;i++){
		if(!used[i]){
			dfs(i);
			cnt++;
		}
	}
	for(int i=0;i<cnt;i++){
		for(int j=0;j<G[i].size();j++){
			cost[i].push_back(a[G[i][j]]);
		}
	}
	if(cnt==1){
		cout<<"0"<<endl;
		return 0;
	}
	long long ans=0;
	vector<int>impossible;
	int ch=2*(cnt-1);
	for(int i=0;i<n;i++){
		if(cost[i].size()){
			sort(cost[i].begin(),cost[i].end());
			ans+=cost[i][0];
			ch--;
			for(int j=1;j<cost[i].size();j++){
				impossible.push_back(cost[i][j]);
			}
		}
	}
	if(ch>impossible.size()){
		cout<<"Impossible";
		return 0;
		
	}
	sort(impossible.begin(),impossible.end());
	for(int i=0;i<ch;i++)ans+=impossible[i];
	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 14080
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i;
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			List<Queue<Integer>> array = new ArrayList<>();
			for(i = 0; i < n; i++) {
				array.add(new PriorityQueue<Integer>(1 ,Comparator.reverseOrder()));
			}
			for(i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				int t = sc.nextInt();
				//命令1と2は配列が空なら処理しない
				if(array.get(t).isEmpty() && order_number != 0) {
					continue;
				}
				switch(order_number) {
				case 0 :
					array.get(t).add(sc.nextInt());
					break;
				case 1 :
					System.out.println(array.get(t).peek());
					break;
				case 2 :
					array.get(t).remove();
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 170104
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL N;
	cin >> N;

	string S;
	cin >> S;

	LL ans = 1;
	map<char, LL> selected_times;
	for (int i = 0; i < S.size(); i++) {
		selected_times[S[i]]++;
	}
	for (auto& kv : selected_times) {
		ans *= (kv.second + 1LL);
		ans %= MOD;
	}

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



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i, n)cin >> s.at(i) >> t.at(i);
    ll ans = 0;
    string  x;
    cin >> x;
    bool ok = false;
    rep(i, n){
        if(ok)ans += t.at(i);
        if(s.at(i) == x)ok = true;
    }
    cout << ans << endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int T[101010],X[101010],Y[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) {
		cin>>T[i]>>X[i]>>Y[i];
		x = abs(X[i]-X[i-1])+abs(Y[i]-Y[i-1]);
		if(x>T[i]-T[i-1] || (T[i]-T[i-1]-x)%2) return _P("No\n");
	}
	
	cout<<"Yes"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

using namespace std;

int main()
{
	vector <bool> vis(6, false);
	for (int i = 0; i < 5; i++) {
		int x;	cin >> x;
		vis[x] = true;
	}

	for (int i = 1; i <= 5; i++)
		if (!vis[i]) cout << i << '\n';

	return 0;
}


Measured memory_bytes: 3624
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10**9+7
    comb = [0] * (N+1)
    comb[K-1] = 1
    for i in range(K-1, N):
        comb[i+1] = comb[i] * (i+1) * pow(i-K+2, -1, mod) % mod
    # print(comb)
    A.sort()
    # mi = sum(a*comb[i]%mod for a, i in zip(reversed(A[:N-K+1]), range(K-1, N)))
    # ma = sum(a*comb[i]%mod for a, i in zip((A[K-1:]), range(K-1, N)))
    ans = sum((a-b)*comb[i]%mod for b, a, i in zip(reversed(A[:N-K+1]), A[K-1:], range(K-1, N)))
    # print(mi%mod, ma%mod)
    print(ans%mod)


if __name__ == '__main__':
    main()

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

#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;

#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937

const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;

#define MOD 1000000007

typedef long long ll;
const int mx=2e5+125;

ll pr[mx],ar[mx],br[mx];

#define PB push_back
#define endl '\n'
#define S second
#define F first

void solve()
{
    int n;
    cin>>n;
    int c=0;
    int mx=0;
    while(n--){
            int A,B;
            cin>>A>>B;
            if(A==B)c++;
            else mx=max(mx,c),c=0;

    }
    mx=max(mx,c);
    if(mx>=3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}
int main()
{
    faster();
    int tc;
    tc=1;
    while(tc--)
        solve();
    return 0;
}


Measured memory_bytes: 3580
import math

n, m = map(int, input().split(" "))

d = {}
for i in range(1, n + 1):
    d[i] = {"AC": False, "WA": 0}

acc, wac = 0, 0
for _ in range(m):
    q, m = input().split(" ")
    q = int(q)

    if not d[q]["AC"]:
        if m == "WA":
            d[q]["WA"] += 1
        elif m == "AC":
            d[q]["AC"] = True
            acc += 1
            wac += d[q]["WA"]

print(acc, wac)

Measured memory_bytes: 42144
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

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

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;

    int n = (int)s.size();

    int k;
    cin >> k;

    lint ans = 0;

    constexpr char c = '{';

    if(k & 1){
        s = s + s + s + s + s;
        rep(i, n - 1){
            if(s[i] == s[i + 1]){
                ++ans;
                s[i + 1] = c;
            }
        }
        REP(i, n - 1, (n << 1) - 1){
            if(s[i] == s[i + 1]){
                ans += (k - 1LL) / 2LL;
                s[i + 1] = c;
            }
        }
        REP(i, (n << 1) - 1, n * 3 - 1){
            if(s[i] == s[i + 1]){
                ans += (k - 2LL) / 2LL;
                s[i + 1] = c;
            }
        }
        REP(i, n * 3 - 1, (n << 2) - 1){
            if(s[i] == s[i + 1]){
                s[i + 1] = c;
            }
        }
        if(k > 1) REP(i, (n << 2) - 1, n * 5 - 1){
            if(s[i] == s[i + 1]){
                ++ans;
                s[i + 1] = c;
            }
        }
    }else{
        s = s + s + s + s;
        rep(i, n - 1){
            if(s[i] == s[i + 1]){
                ++ans;
                s[i + 1] = c;
            }
        }
        REP(i, n - 1, (n << 1) - 1){
            if(s[i] == s[i + 1]){
                ans += (k - 1LL) / 2LL;
                s[i + 1] = c;
            }
        }
        REP(i, (n << 1) - 1, n * 3 - 1){
            if(s[i] == s[i + 1]){
                ans += (k - 2LL) / 2LL;
                s[i + 1] = c;
            }
        }
        if(k > 1) REP(i, n * 3 - 1, (n << 2) - 1){
            if(s[i] == s[i + 1]){
                ++ans;
                s[i + 1] = c;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
const int MAXN = 200010;
const ll MOD = 1000000007;
int n, a[MAXN], b[MAXN];
int x0 = 2005, y0 = 2005;
ll g[4010][4010], fac[8010];
ll ifac[8010], ans;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x * f;
}

inline ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1LL) res = res * a % MOD;
		b >>= 1, a = a * a % MOD;
	}
	return res;
}

int main() {
	int i, j;
	n = read();
	for(i = 1; i <= n; i++) 
		a[i] = read(), b[i] = read();
	fac[0] = 1;
	for(i = 1; i <= 8000; i++) fac[i] = fac[i-1]*i%MOD;
	ifac[8000] = qpow(fac[8000], MOD-2);
	for(i = 8000; i >= 1; i--) ifac[i-1] = ifac[i]*i%MOD;
	for(i = 1; i <= n; i++) 
		ans = (ans-fac[2*a[i]+2*b[i]]*ifac[2*a[i]]%MOD*ifac[2*b[i]]%MOD+MOD)%MOD;
	for(i = 1; i <= n; i++) g[x0-a[i]][y0-b[i]]++;
	for(i = -2000; i <= 2000; i++) 
		for(j = -2000; j <= 2000; j++)
			g[i+x0][j+y0] = (g[i+x0][j+y0]+g[i+x0][j-1+y0]+g[i-1+x0][j+y0])%MOD;
	/*for(i = 3; i >= -3; i--) {
		for(j = -3; j <= 3; j++) 
			printf("%lld ", g[i+x0][j+y0]);
		printf("\n");
	}*/
	for(i = 1; i <= n; i++)
		ans = (ans+g[x0+a[i]][y0+b[i]])%MOD;
	printf("%lld\n", ans*qpow(2, MOD-2)%MOD);
	return 0;
}


Measured memory_bytes: 127360
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main() {
	ll H, W;
	vector<vector<char>> s;
    cin >> H >> W;

	for(ll i=0; i<H; i++) {
		vector<char> s_row;
		for(ll j=0; j<W; j++) {
			char ss;
			cin >> ss;
			s_row.push_back(ss);
		}
		s.push_back(s_row);
	}

	bool ans = true;
	for(ll i=0; i<H; i++) {
		for(ll j=0; j<W; j++) {
			if( (s[i][j] == '#') &&
				(i==0   || s[i-1][j] == '.' ) &&
				(i==H-1 || s[i+1][j] == '.' ) &&
				(j==0   || s[i][j-1] == '.' ) &&
				(j==W-1 || s[i][j+1] == '.' ) ) {
					ans = false;
				}
		}
	}

	cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	double a,b,c,d,e,f,x,y;
    	Scanner in = new Scanner(System.in);
    	while(true){
    		try{
    			a=in.nextDouble();
    			b=in.nextDouble();
    			c=in.nextDouble();
    			d=in.nextDouble();
    			e=in.nextDouble();
    			f=in.nextDouble();
    			y=(a*f-c*d)/(-b*d+e*a);
        		x=(c-b*y)/(a);
        		System.out.printf("%.3f %.3f\n",x,y);
    		}
    		catch (Exception g){
    			System.exit(0);
    		}
    	}
    }
}

Measured memory_bytes: 20576
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    A,B,C,N = map(int,input().split())
    ans = 0
    for i in range(N + 1):
        if i*A > N:
            break
        a = i*A
        for j in range(N + 1):
            if j*B + a > N:
                break
            b = j*B
            if (N - a - b)%C == 0:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if (A + B > C + D)
    cout << "Left" << endl;
  else if (A + B == C + D)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i()

n.times{|cnt|
	line =gets.chomp()
	num = 1
	m = 0
	c = 0
	x = 0
	i = 0
	
	line.each_char{|char|
		case char
		when "m"
			m += num
			num = 1
		when "c"
			c += num
			num = 1
		when "x"
			x += num
			num = 1
		when "i"
			i += num
			num = 1
		else
			num = char.to_i()
			if num == 0 then
				num = 1
			end
		end
	}
	
	if i >= 10 then
		i -= 10
		x += 1
	end
	if x >= 10 then
		x -= 10
		c += 1
	end
	if c >= 10 then
		c -= 10
		m += 1
	end
	
	if m > 1 then
		print m
		print "m"
	elsif m ==1 then
		print "m"
	end
	
	if c > 1 then
		print c
		print "c"
	elsif c ==1 then
		print "c"
	end
	
	if x > 1 then
		print x
		print "x"
	elsif x ==1 then
		print "x"
	end
	
	if i > 1 then
		print i
		print "i"
	elsif i ==1 then
		print "i"
	end
	print "\n"
	 
}

Measured memory_bytes: 6120
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**3
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
red = [LI() for _ in range(N)]
blue = [LI() for _ in range(N)]
red.sort(key=lambda x:x[1],reverse=True)
blue.sort()

ans = 0
for bx,by in blue:
    for i in range(N):
        if bx > red[i][0] and by > red[i][1]:
            ans += 1
            red[i][0] = INF
            break
print(ans)

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    if ( b - a <= 2 ) {
        cout << 1 + k << endl;
    }
    else if ( ( k - ( a - 1 ) ) % 2 == 0 ) {
        cout << a + ( k - ( a - 1 ) ) / 2 * ( b - a ) << endl;
    }
    else {
        cout << a + ( k - ( a - 1 ) ) / 2 * ( b - a ) + 1 << endl;
    }
    return 0;
}


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

int main(){
    int X, Y;
    int tsuru, kame;

    cin >> X >> Y;

    if((2*X > Y) || (4*X < Y)){
        cout << "No" << endl;
        return 0;
    }
    else if(Y % 2 != 0){
        cout << "No" << endl;
        return 0;
    }

    for(int kame=0; kame<=25; kame++){
        for(int tsuru=0; tsuru<=51; tsuru++){
            if((tsuru * 2 + kame * 4) == Y){
                cout << "Yes" << endl;
                return 0;
    }}}
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


def main():
    N, M = map(int, readline().split())
    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(int, readline().split())
        uf.union(a - 1, b - 1)
    print(-min(uf.parents))


if __name__ == '__main__':
    main()


Measured memory_bytes: 74320
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
//#include <tuple>
#include <cmath>
using namespace std;

int n, m, q;
vector<int> vec[500];
int l, r;

signed main() {
	int i, j;
	
	cin >> n >> m >> q;
	for (i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y; x--; y--;
		vec[x].push_back(y);
	}
	for (i = 0; i < n; i++) sort(vec[i].begin(), vec[i].end());
	
	for (i = 0; i < q; i++) {
		cin >> l >> r;
		l--; r--;
		int ans = 0;
		for (j = l; j <= r; j++) {
			ans += upper_bound(vec[j].begin(), vec[j].end(), r) - vec[j].begin();
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
/*input
200
*/
/*
***IT'S OUR LONG WAY TO THE OIILLLL***
 
 
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/
//010000000010
#include<bits/stdc++.h>
#define ll          long long
#define pb          emplace_back
#define endl        '\n'
#define pi         pair<ll int,ll int>
#define vi          vector<int>
#define vll          vector<ll int>
#define vpi          vector<pair<int,int>>
#define vpll          vector<pair<ll int,ll int>>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()
#define sz(x)       (ll int)x.size()
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define tr(x,t)      for(t=x.begin();t!=x.end();t++)
#define mp          make_pair
#define inf 1000000000
#define hell 1000000000
#define fi first
#define se second
using namespace std;
ll gc[201][201];
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
void inii(){
    for (int i = 0; i < 201; ++i)
    {
        /* code */
        for (int j = 0; j < 201; ++j)
        {
            /* code */
            gc[i][j]=gcd(i,j);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    ll t=1;
    //cin >> t;
    inii();
    while(t--)
    {
        ll n,ans=0;
        cin >> n;
        for (int i = 1; i < n+1; ++i)
        {
            /* code */
            for (int j = 1; j < n+1; ++j)
            {
                /* code */
                for (int k = 1; k < n+1; ++k)
                {
                    /* code */
                    ans+=gc[i][gc[j][k]];
                }
            }
        }
        cout << ans;
    }

    return 0;
}   

Measured memory_bytes: 3924
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    AIN(ll, A, N);
    for (ll i = K; i < N; ++i)
    {
        YES(A[i] > A[i - K]);
    }
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

ll a, b, k;

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

  if (a >= k) {
    cout << a - k << " " << b << endl;
  } else {
    cout << 0 << " " << max(0LL, b - (k - a)) << endl;
  }
  return 0;
}




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

int main()
{
    string s;
    cin >>s;
    int coa=0;
    int cob=0;
    for(int i=0;i<(int)s.size();i+=2){
        if(s[i]!='1')coa++;
        if(s[i]!='0')cob++;
    }
    for(int i=1;i<(int)s.size();i+=2){
        if(s[i]!='1')cob++;
        if(s[i]!='0')coa++;
    }
    cout << min(coa,cob)<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S, T;
	cin >> S >> T;
	sort(all(S));
	sort(rall(T));
	if (S < T)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



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

ll n,m;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1){}
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    // e = (x, y) を結んで良いかどうかも含めて判定
    bool merge(int x, int y) {
        x = root(x); y = root(y);

        // x と y が同じ連結成分
        if (x == y)  {
            return true;
        }

        
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;  
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
}; 
ll solve(){
   ll ans=0;
   vector<ll>p(n),x(m),y(m);
   rep(i,n)cin>>p[i];
   UnionFind uf(n+1);
   rep(i,m){
       cin>>x[i]>>y[i];
       uf.merge(x[i],y[i]);
   }
   rep(i,n){
       if(uf.issame(p[i],i+1))ans++;
   }

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

    cin>>n>>m;
    cout<<solve()<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

double expected_value(int n) {
  return (double)((1 + n) * n / 2) / (double)n;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> ps(n + 1);
  vector<double> comsum(n + 1, 0);
  int p;
  rep(i, n) {
    cin >> p;
    ps[i + 1] = expected_value(p);
    comsum[i + 1] = comsum[i] + ps[i + 1];
  }
  double mm = 0;
  for (int i = k; i <= n; i++) {
    mm = max(comsum[i] - comsum[i - k], mm);
  }
  printf("%.6f\n", mm);
  return 0;
}

Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);

int c[20], a[20][20], level[20];
int n, m, x;

int INF = 0x3f3f3f3f;

int solve(int k, int cost) {
    if (k > n) {
        for (int i = 0; i < m; i++) {
            if (level[i] < x) return INF;
        }
        return cost;
    } else {
        int c1 = solve(k + 1, cost);
        for (int i = 0; i < m; i++) {
            level[i] += a[k][i];
        }
        int c2 = solve(k + 1, cost + c[k]);
        for (int i = 0; i < m; i++) {
            level[i] -= a[k][i];
        }
        return min(c1, c2);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = solve(0, 0);

    if (ans == INF) {
        cout << -1 << "\n";
    } else {
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3196