akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

vector<vector<int>> p(202020, vector<int>());
vector<int> ans(202020, 0);
vector<bool> seen(202020, false); 

void ki_plus(int i){
    seen[i] = true;
    if(p[i].size()){
        for(int j : p[i]){
            if(!seen[j]){
                ans[j] += ans[i];
                ki_plus(j);
            }
        }
    }
}

int main(){
    int n, q;
    
    cin >> n >> q;

    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        p[a].push_back(b);
        p[b].push_back(a);
    }

    rep(i, q){
        int j, x;
        cin >> j >> x;
        ans[j] += x;
    }

    ki_plus(1);

    rep(i, n){
        cout << ans[i+1] << endl;
    }

    return 0;
}

Measured memory_bytes: 23552
N,M=gets.chomp.split(' ').map{|n| n.to_i}
L=Array.new(M) { |i|  }
R=Array.new(M) { |i|  }
for i in 0..(M-1)
	L[i],R[i]=gets.chomp.split(' ').map{|n| n.to_i}
end
puts "#{[R.min - L.max + 1, 0].max}"


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  vector<int> b(N);
  rep(i, 0, N) { cin >> b[i]; }
  vector<pair<int, int>> v;
  rep(i, 0, N) { v.push_back(make_pair(a[i], 0)); }
  rep(i, 0, N) { v.push_back(make_pair(b[i], 1)); }
  sort(all(v));
  dump(v);

  int cnta = 0, cntb = 0, ans = 1;
  rep(i, 0, 2*N) {
    if (v[i].second == 0) {
      if (cntb > 0) {
        (ans *= cntb) %= MOD;
        cntb--;
      } else
        cnta++;
    } else {
      if (cnta > 0) {
        (ans *= cnta) %= MOD;
        cnta--;
      } else
        cntb++;
    }
    dump(ans,cnta,cntb);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8048
import java.util.*;


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

        List num = new ArrayList();
        for (int i = 0; i < 9; i++) {
            num.add(s.nextInt());
        }
        int n = s.nextInt();
        List called = new ArrayList();
        for (int i = 0; i < n; i++) {
            called.add(s.nextInt());
        }
        List<List<Integer>> hoge = Arrays.asList(
                Arrays.asList(1, 4, 7),
                Arrays.asList(2, 4),
                Arrays.asList(4, 3, 8),
                Arrays.asList(5, 1),
                Arrays.asList(5, 2, 7, 8),
                Arrays.asList(5, 3),
                Arrays.asList(6, 1, 8),
                Arrays.asList(6, 2),
                Arrays.asList(6, 3,7)
        );
        int[] result=new int[9];
        for (int i = 0; i <called.size() ; i++) {
            if(num.indexOf(called.get(i))!=-1){
                int id=num.indexOf(called.get(i));
                hoge.get(id).forEach((nn)->{
                   result[nn-1]++;
                });
            }
        }
        for (int i = 0; i <9 ; i++) {
            if(result[i]>=3){
                System.out.println("Yes");
                return;
            }

        }
        System.out.println("No");


    }
}


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

using namespace std;

#define forn(i, n) for(int i=0;i<int(n);i++)

int main(){
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<int> t (n+1, 0);
	for(int i=1;i<=n;i++){
		int check;
		if(s[i-1] == 'A' && s[i] == 'C') check = 1;
		else check = 0;
		t[i] = t[i-1]+check; 
	}
	forn(i, q){
		int a, b; cin >> a >> b;
		a--; b--;
		cout << t[b]-t[a] << endl;
	}
}


Measured memory_bytes: 1408
#include<stdio.h>

#define N 106
#define INF 100000000

int P[N];
int m[N][N];


int matrixchainorder(int*,int);

int main(){
  int i;
  int num;

  scanf("%d",&num);
  

  for(i=1;i<=num;i++){
    //printf("%d\n",i);
    scanf("%d%d",&P[i-1],&P[i]);
  }
  
  printf("%d\n",matrixchainorder(P,num));

  return 0;
}


int matrixchainorder(int *P,int length){
  int n,i,j,k;
  int q;
  int l;

  n = length;

  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }

  for(l = 2;l <= n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<=j-1;k++){
	q = m[i][k] + m[k+1][j] + P[i-1]*P[k]*P[j];
	if(m[i][j] > q){
	  m[i][j] = q;
	  //printf("q = %d\n",q);
	}
      }
    }
  }

  /*printf("DEBUG\n");
  for(int a = 7; a >= 1; a--){
    for(int b = 0; b <= 6; b++){
      printf("%d ", m[b][a]);

    }
    printf("\n");
  }
  */

  return m[1][n];
}
   
	
    





Measured memory_bytes: 2752
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n,m;
    cin>>n>>m;
    int ans=0;
    ans+=min(n,m/2);
    m-=ans*2;
    ans+=m/4;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int a[m] = {};
  int sum = 0;

  for(int i=0; i<m; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  if(n-sum>=0) cout << n-sum << endl;
  else cout << -1 << endl; 
}


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

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

  int x;
  int roboa=0, robob=0;
  int distance[N];
  int total=0;
  for(int i=0; i<N; i++) {
    cin >> x;
    roboa = (x - 0) * 2;
    robob = (K - x) * 2;
    total += (roboa < robob) ? roboa : robob;;
  }

  cout << total << endl;
}

Measured memory_bytes: 256
fn chmax<T: PartialOrd>(x: &mut T, a: T) {
    if *x < a {
        *x = a;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        w: usize,
        item: [(usize, u64); n],
    }
    let mut dp = vec![0; w + 1];
    for (w, v) in item {
        let mut next = dp.clone();
        for (next, dp) in next.iter_mut().skip(w).zip(dp.iter()) {
            chmax(next, *dp + v);
        }
        dp = next;
    }
    let ans = dp[w];
    println!("{}", ans);
}

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

int main(){
    long n,a,b;cin>>n>>a>>b;
    string s;cin>>s;
    long na=0;
    long nb=0;
    for(int i=0;i<n;i++){
        char k=s.at(i);
        if(k=='a'){
            if(na+nb<a+b){
                cout<<"Yes"<<endl;
                na++;
            }else cout<<"No"<<endl;
        }
        if(k=='b'){
            if(na+nb<a+b && nb<b){
                cout<<"Yes"<<endl;
                nb++;
            }else cout<<"No"<<endl;
        }
        if(k=='c'){
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 3764
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define toupper(S) transform(S.begin(),S.end(),S.begin(),toupper)
#define tolower(S) transform(S.begin(),S.end(),S.begin(),tolower)

int main() {
	int N;
	string S;
	cin >> N >> S;
	vector<int>SA(N);
	vector<int>SB(N);
	int cnta = 0;
	int cntb = 0;
	rep(i, N) {
		if (S[i] == '.') {
			cnta++;
		}
		SA[i] = cnta;
		if (S[i] == '#') {
			cntb++;
		}
		SB[i] = cntb;
	}
	int ans = min(cnta, cntb);
	rep(i, N) {
		ans = min(ans, SB[i]+ cnta - SA[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2180
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
num = [i for i in range(1,n+1)]
lst = list(itertools.permutations(num))
pos_p = 0
pos_q = 0
for i in range(len(lst)):
    temp = list(lst[i])
    if temp == p:
        pos_p = i
    if temp == q:
        pos_q = i
print(abs(pos_p - pos_q))



Measured memory_bytes: 13836
max = 0
a = [0]
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
while True:
  if N == 1:
    print("0")
    break
  for i in range(N):
    if V[i] > C[i]:
      a.append(V[i]-C[i])
  for i in a:
    max += i
  print(max)
  break

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

using namespace std;

const int N = 4e5 + 5;
const int mod = 1e9 + 7;

int n, a[N], pw[N];

void add (int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    
    pw[0] = 1;
    for (int i = 1; i < N; i++) {
        pw[i] = pw[i - 1] + pw[i - 1];
        if (pw[i] >= mod) pw[i] -= mod;
    }
    
    int ans = 0;
    sort(a + 1, a + n + 1);
    
    int u = pw[2 * n - 1];
    int d = pw[2 * n - 2];
    for (int i = n; i >= 1; i--) {
        add(ans, 1LL * u * a[i] % mod);
        add(u, d);
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  long long multi = 1;
  vector<long long> a;
  for(int i = 0; i < n; i++){
    long long x; cin >> x;
    a.push_back(x);
    if(x == 0){
      cout << 0;
      return 0;
    }
  }
  for(int i = 0; i < n; i++){
    if(a.at(i) <=1000000000000000000/multi)
      multi *=a.at(i);
    else{
      cout << -1;
      return 0;
    }
  }
  cout << multi;
}
  

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
long long pw2[60];
vector<long long>G[60];
long long edgenum[60][60];
vector<long long> pth[60][60];
long long vnode[60], vedge[60];
long long Mlist[60][2];
bool findpth(long long node,long long s,long long e){
	bool tmp;
	vnode[node]=1;
	if(node==e) return true;
	for(long long i=0;i<G[node].size();i++){
		if(vnode[G[node][i]]==0){
			tmp=findpth(G[node][i],s,e);
			if(tmp==true){
				pth[s][e].push_back(edgenum[node][G[node][i]]);
				return true;
			}
		}
	}
	return false;
}

int main(){
	long long a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,tmp,cnt;
	long long ans,e;
	scanf("%lld",&n);
	pw2[0]=1;
	for(i=1;i<60;i++) pw2[i]=pw2[i-1]*2;
	
	for(i=1;i<n;i++){
		scanf("%lld %lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
		edgenum[a][b]=i;
		edgenum[b][a]=i;
	}
	
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=0;k<60;k++) vnode[k]=0;
			findpth(i,i,j);
		}
	}
	scanf("%lld",&m);
	for(i=0;i<m;i++){
		scanf("%lld %lld",&Mlist[i][0],&Mlist[i][1]);
	}
	tmp=pw2[m];
	ans=0;
	for(i=0;i<tmp;i++){
		j=i;
		for(x=0;x<60;x++) vedge[x]=0;
		e=1;
		for(k=0;k<m;k++){
			if(j%2==1){
				for(l=0;l<pth[Mlist[k][0]][Mlist[k][1]].size();l++) vedge[pth[Mlist[k][0]][Mlist[k][1]][l]]=1;
				e=-e;
			}
			j/=2;
		}
		cnt=n-1;
		for(x=0;x<60;x++) if(vedge[x]==1) cnt--;
		ans+=(e*pw2[cnt]);
		//prlong longf("%lld\n",(e*pw2[cnt]));
	}
	printf("%lld",ans);
}

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

string s, t;

int main() {
	cin >> s >> t;
	bool flag = true;
	int memo;
	if (s.size() >= t.size()) {
		for (int j = 0; j <= s.size() - t.size();j++) {
			bool temp = true;
			for (int i = 0; i < t.size(); i++) {
				if (s[j + i] != t[i] && s[j + i] != '?') {
					temp = false;
				}
			}
			if (temp) {
				flag = false;
				memo = j;
			}
		}
	}
	if (flag) { cout << "UNRESTORABLE" << endl; }
	else {
		for (int i = 0; i < t.size(); i++) {
			s[memo + i] = t[i];
		}
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '?') { cout << 'a'; }
			else { cout << s[i]; }
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int max_k=-INF;

string make_id(string s){
  string ret="";
  ret+=s[0];
  rep(i,s.size()-1){
    if(s[i]=='a'||s[i]=='i'||s[i]=='u'||s[i]=='e'||s[i]=='o')ret+=s[i+1];
  }
  max_k=max(max_k,(int)ret.size());
  return ret;
}

int calc_k(int n,vector<string>v){
  int ret=1;
  while(ret!=max_k+1){
    set<string>se;
    rep(i,n){
      //cout<<ret<<": "<<v[i].substr(0,ret)<<endl;
      se.insert(v[i].substr(0,ret));
    }
    if(se.size()==n)return ret;
    ret++;
  }
  return -1;
}

int main(){
  int n;
  while(cin>>n,n){
    max_k=-INF;
    string s;
    vector<string> v;
    rep(i,n){
      cin>>s;
      v.pb(make_id(s));
    }
    cout<<calc_k(n,v)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;

    cout << min({P+Q, Q+R, P+R}) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 1e5 + 5;
int dp [N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n, m;
  cin >> n >> m;
  F0R (i, m) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    dp[l]++;
    dp[r + 1]--;
  }
  int cur = 0;
  int cnt = 0;
  F0R (i, n) {
    cur += dp[i];
    cnt += cur == m;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 640
N = int(input())
#1~50の素数を見つける
a=[i for i in range(2,51)]
sosu = [2]
while(True):
    a = [i for i in a if i%sosu[-1]!=0]
    if a == []:
        break
    sosu.append(a[0])
nsosu = [0]*len(sosu)
for n in range(2,N+1):
    for ind,s in enumerate(sosu):
        if n%s == 0:
            count = 0
            while(n%s == 0):
                count += 1
                n = n/s
            nsosu[ind] += count
        elif int(n/s) == 0:
            if n != 1:
                nsosu.append(1)
            break
        if ind == len(sosu)-1:
            if n != 1:
                nsosu.append(1)
nsosu = [i for i in nsosu if i !=0]
#8*5*2*2=160個の約数
#75 = (1,75) (3,25),(5,15),(3,5,5)
#(3,25)を探す
count = 0
count5 = 0
for i,ns in enumerate(nsosu):
    if ns >= 24:
        for j,nso in enumerate(nsosu):
            if i != j:
                if nso>=2:
                    count += 1
                    
    #(5,15)を探す
    if ns >= 14:
        for j,nso in enumerate(nsosu):
            if i != j:
                if nso >= 4:
                    count += 1
    #(3,5,5)
    if ns >= 4:
        for j,nso in enumerate(nsosu):
            if i != j:
                if nso >= 4:
                    for k,nsos in enumerate(nsosu):
                        if i != k and j != k:
                            if nsos >= 2:
                                count5 += 1
    #(1,75)
    if ns >= 74:
        count += 1
count += int(count5/2)                  
print(count)

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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int n,m;cin>>n>>m;
    int once=1900*m+100*(n-m);
    int times=1;
    REP(i,m){
        times*=2;
    }
    cout<<once*times<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
  
#define MAX 1000
#define MAXWEIGHTIJ 20000
  
struct MCS {
    int cost;
    int order;
};
  
void exchange( struct MCS *pa, struct MCS *pb )
{
    struct MCS t;
       
    t=*pa;
    *pa=*pb;
    *pb=t;
       
     return;
}
   
int Partition( struct MCS A[], int p, int r )
{
    struct MCS x;
    int i,j;
   
    x=A[r];
    i=p-1;
    for( j=p; j<r; j++ ) {
        if( A[j].cost < x.cost ) {
            i++;
            exchange( &A[i], &A[j] );
         }
    }
    exchange( &A[i+1], &A[r] );
  
    return i+1;
}
void QuickSort( struct MCS A[], int p, int r )
{
    int q;
       
    if( p < r ) {
        q=Partition( A, p, r );
        QuickSort( A, p, q-1 );
        QuickSort( A, q+1, r );
    }
    return;
}
  
int tryChange( int n, struct MCS W[] )
{
    int cnt;
    int fixedcost,profit;
    int from, to, togoal;
      
    int cost,lowestCost;
    int i,j;
    int lowW,lowestW;
    int low,high,lowest;
  
    lowestW=lowW=lowestCost=cost=MAXWEIGHTIJ;
    lowest=high=low=-1;
    for( i=0; i<n; i++ ) {
        if( i != W[i].order && W[i].cost < lowW ) {
            lowW=W[i].cost;
            low=i;
            for( j=0; j<n; j++ ) {
                if( low == W[j].order ) {
                    high=j;
                    break;
                }
            }
        }
        if( W[i].cost < lowestW ) {
            lowestW=W[i].cost;
            lowest=i;  
        }      
    }
  
    if( W[high].order == low && W[low].order == high ) {
        lowestCost = W[low].cost + W[high].cost;
    } else if( low != lowest ) {   
        fixedcost = W[low].cost + W[lowest].cost;
        profit = W[low].cost - W[lowest].cost;
        from=high;
        to=low;
        togoal = W[low].order;
        cnt=0;
        while( 1 ) {
            if( W[from].order == to ) {
                if( togoal == to ) { break; }
                to=from;
                cnt++;
            } else {
                break;
            }
            for( i=0; i<n; i++ ) {
                if( i != W[i].order ) {
                    if( to == W[i].order ) {
                        from=i;
                        break;
                    }
                }
            }
        }
        profit = ( profit * cnt ) - ( 2 * fixedcost );
        if( 0 < profit ) {
            high=low;
            low=lowest;
            lowestCost = fixedcost;
        }
    }
    if( W[high].order == low ) {
        lowestCost = W[low].cost + W[high].cost;
    }
  
    if( MAXWEIGHTIJ != lowestCost ) {
        exchange( &W[low], &W[high] );
    } else {
        lowestCost=0;
    }
    return lowestCost;
}
  
int main( void )
{  
    int n,i;
    struct MCS W[MAX+1];
    int cost;
          
    scanf( "%d", &n );
    for( i=0; i<n; i++ ) {
        scanf( "%d", &W[i].cost );
        W[i].order=i;
    }
  
    QuickSort( W, 0, n-1 );
    cost=i=0;
    while( (i = tryChange( n, W ) ) ) {
        cost+=i;
    }
    printf( "%d\n", cost );
  
    return 0;
}

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

int main()
{
    string s; cin >> s;
    int i, j;
    for(i = 0;i < s.length();i++){// break at A
        if(s[i] == 'A'){
            break;
        }
    }
    for(j = s.length()-1;j >= 0;j--){// break at Z
        if(s[j] == 'Z'){
            break;
        }
    }
    cout << j - i + 1 << endl;// print the length between A and Z
}

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

using namespace std;

const int NMAX = 1000;
const int SIGMA = 26;

string s;
int N, pre[NMAX+2][SIGMA], mx[NMAX+2][SIGMA];
int Ans = NMAX;
int main()
{
    cin >> s;
    N = s.size();
    for( int i = 1;  i <= N;  ++i ) {
        for( int j = 0;  j < SIGMA;  ++j )
            pre[i][j] = pre[i - 1][j] + 1;
        pre[i][ s[i - 1] - 'a' ] = 0;
        for( int j = 0;  j < SIGMA;  ++j )
            mx[i][j] = max(mx[i - 1][j], pre[i][j]);
        Ans = min( Ans, max(mx[i][s[i - 1] - 'a'], N - i) );
    }
    cout << Ans << '\n';
    return 0;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
cnt=0

for i in range(n):
    if p[i]==i+1:
        j=i+1
        if j>=n:
            j=i-1
        p[i],p[j]=p[j],p[i]
        cnt+=1

print(cnt)

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "

int D;
int c[26];
int s[365][26];

int main(){
    cin >> D; //D = 365
    int max_[30][365];
    int lastd[26];
    //vector<int> high_c;
    //vector<int> midl_c;
    //vector<int> low_c;
    vector<pair<int,int>> high_pr(26);
    Rep(i,26){
        cin >> c[i];
        lastd[i] = 0;
        //if(c[i] > 70)high_c.push_back(i);
        //else if(c[i] > 40)midl_c.push_back(i);
        //else low_c.push_back(i);
    }
    Rep(i,365){
        Rep(j,26){
            cin >> s[i][j];
        }
    }
    int M_score = 0;
    int score;
    int L = 6;
    For(lange,6,25){
        score = 0;
        Rep(i,365){
            max_[lange][i] = 0;
            int max = 0;
            Rep(j,26){
                Rep(k,lange){
                  if(max < s[i][high_pr[25-k].second] + high_pr[25-k].first){
                        max = s[i][high_pr[25-k].second] + high_pr[25-k].first;
                        max_[lange][i] = high_pr[25-k].second;
                    }
                }
            }
            Rep(j,26){
                if(j == max_[lange][i])lastd[j] = 0;
                else lastd[j]++;
            }
            Rep(j,26){
                high_pr[j] = make_pair(c[j]*lastd[j],j);
            }
            sort(high_pr.begin(),high_pr.end());
            score += max;
        }
        //cout << score << endl;
        if(score > M_score){
            M_score = score;
            L = lange;
        }
    }
    Rep(i,365){
        cout << max_[L][i]+1 << endl;
    }
    //int x;
    //cin >> x;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> a, b, ans;
vector<vector<pair<int, int>>> g;
vector<bool> homon;
int medge = 0;

void dfs(int c, int bcolor){
  homon[c] = true;
  int color = 1;
  REP(i, g[c].size()){
    int nx = g[c][i].first;
    if(homon[nx]) continue;
    if(color == bcolor) color++;
    ans[g[c][i].second] =  color;
    dfs(nx, color);
    color++;
  }
}

int main(){
  cin >> N;
  a.resize(N-1), b.resize(N-1);
  g.resize(N);
  REP(i, N-1){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]].push_back({b[i], i});
    g[b[i]].push_back({a[i], i});
    medge = max(medge, max((int) g[a[i]].size(), (int)g[b[i]].size()));
  }
  homon.resize(N, false), ans.resize(N-1);
  dfs(0, -1);
  cout << medge << endl;
  REP(i, N-1){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 7680
#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
#include <cassert>
#include <cstdlib>
using namespace std;

istringstream iss;

int m;

void consume(char expect) {
  char ch; iss>>ch;
  if(expect!=ch) {
    cerr<<"Error: expect '"<<expect<<"' but got '"<<ch<<"'"<<endl;
    cerr<<"Rest string is ";
    string rest;
    while(!iss.eof()) { iss>>rest; cerr<<rest; }
    cerr<<endl;
    exit(EXIT_FAILURE);
  }
}

bool formula() {
  char ch; iss>>ch;
  
  if(isalpha(ch)) {
    if(ch=='T') return true;
    if(ch=='F') return false;
    else {
      return m >> (ch-'a') & 1;
    }
  }

  if(ch=='-') return !formula();

  assert(ch=='(');
  bool f1 = formula();
  iss >> ch;
  if(ch=='-') consume('>');
  bool f2 = formula();
  consume(')');
  if(ch=='*') return f1&&f2;
  if(ch=='+') return f1||f2;
  return f1<=f2;
}

bool solve(const string &input) {
  for(m = 0; m < (1<<11); m++) {
    iss.clear(); iss.str(input);
    bool left=formula();
    consume('=');
    bool right=formula();
    if(left!=right) { return false; }
  }
  return true;
}

int main() {
  string str;
  
  while(getline(cin,str), str!="#") {
    cout << (solve(str) ? "YES" : "NO") << endl;
  }

  return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<std::string> s;
  tools::read(s, N);

  std::unordered_map<std::string, i64> map;
  for (std::string& s_i : s) {
    std::sort(s_i.begin(), s_i.end());
    ++map[s_i];
  }

  i64 answer = 0;
  for (const auto& pair : map) {
    answer += pair.second * (pair.second - 1) / 2;
  }
  std::cout << answer << std::endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int main(){
    int N;
    cin >> N;
    map<ll, int> ma;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
        ma[a] = i;
    }
    sort(A, A+N);

    ll high = A[N-1];
    double diff = 1e10;
    int idx;
    REP(i,N){
        ll a = A[i];
        double d = abs(high/2.0 - a);
        if(d < diff){
            diff = d;
            idx = i;
        }
    }

    ll low = A[idx];

    printf("%lld %lld\n", high, low);
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define maxn 300100
#define ll long long
bool cmp1(int x,int y)
{
    return x<y;
}
bool cmp2(int x,int y)
{
    return x>y;
}
int n,m;
int a[maxn];
struct node1
{
    int x;
    bool operator <(const node1& nn) const
    {
        return x>nn.x;
    }
};
struct node2
{
    int x;
    bool operator <(const node2& nn) const
    {
        return x<nn.x;
    }
};
ll ans1[maxn],ans2[maxn];
int main()
{
    scanf("%d",&n);
    m=n*3;
    for(int i=1;i<=m;++i) scanf("%d",&a[i]);
    ll ans=0;
    priority_queue<node1>q1;
    priority_queue<node2>q2;
    while(!q1.empty()) q1.pop();
    while(!q2.empty()) q2.pop();
    for(int i=1;i<=n;++i)
    {
        node1 tmp1;
        node2 tmp2;
        tmp1.x=a[i];
        tmp2.x=a[m+1-i];
        q1.push(tmp1);
        q2.push(tmp2);
        ans+=a[i]; ans-=a[m+1-i];
    }
    ans1[n]=0;
    for(int i=n+1;i<=n*2;++i)
    {
        ans1[i]=ans1[i-1];
        node1 tmp=q1.top();
        if(tmp.x>=a[i]) continue;
        q1.pop();
        ans1[i]+=a[i]-tmp.x;
        tmp.x=a[i];
        q1.push(tmp);
    }
    ans2[n*2+1]=0;
    for(int i=n*2;i>=n+1;--i)
    {
        ans2[i]=ans2[i+1];
        node2 tmp=q2.top();
        if(tmp.x<=a[i]) continue;
        q2.pop();
        ans2[i]+=tmp.x-a[i];
        tmp.x=a[i];
        q2.push(tmp);
    }
    ll ff=ans;
    for(int i=n;i<=2*n;++i)
        ff=max(ff,ans+ans1[i]+ans2[i+1]);
    cout<<ff<<"\n";
    return 0;
}


Measured memory_bytes: 5236
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {

    input!{
        n: i32,
        a: i32,
        b: i32,
        p: [i32; n],
    }
    let mut t_list = vec![0; 3];

    for task in p.iter() {
        if task <= &a {
            t_list[0] += 1;
        } else if task <= &b {
            t_list[1] += 1;
        } else {
            t_list[2] += 1;
        }
    }
    println!("{}", t_list.iter().min().unwrap_or(&0));
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define pb push_back
using namespace std;

const ll mod = 1e9+7;

ll n, m, k, a[200001], b[200001], ans, x, c, d;
bool ok = 1;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("A.txt", "r", stdin);
    #endif
    cin >> n >> m >> k;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(ok&&x+a[i]<=k){
            x += a[i];
            c++;
        }
        else ok=0;
    }
    ok=1;
    for(int i=0; i<m; i++){
        cin >> b[i];
        if(ok&&x+b[i]<=k){
            x += b[i];
            d++;
        }
        else ok=0;
    }
    ans = c+d;
    for(int i=c-1; i>=0; i--){
        x -= a[i];
        while(d<m&&x+b[d]<=k){
            x += b[d];
            d++;
        }
        ans = max(ans, i+d);
    }
    cout << ans;
}


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

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

int main(){
  int n;
  cin>>n;
  rep(i,n){
    int y, m, d;
    cin>>y>>m>>d;
    ll ans=0;
    while(!(y==1000 && m==1 && d==1)){
      if(y%3==0){ //3????????°?????´
        if(d==20){
          if(m==10){y++; m=1; d=1;}
          else{m++; d=1;}
        }
        else{
          d++;
        }
      }
      else{ //not3????????°?????´
        if(m%2==1){
          if(d==20){
            m++; d=1;
          }
          else{
            d++;
          }
        }
        else{
          if(d==19){
            if(m==10){y++; m=1; d=1;}
            else{m++; d=1;}
          }
          else{d++;}
        }
      }
      ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#n = int(input())
from collections import deque
n, m = map(int, input().split())
# n=200000
# m=200000
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
adjl = [[] for _ in range(n+1)]
NIL = -1
appear = {}
isalone = {}
for i in range(m):
    a, b = map(int, input().split())
    if appear.get((a, b), False) or appear.get((a, b), False):
        continue
    appear[(a, b)] = True
    appear[(b, a)] = True
    isalone[a] = False
    isalone[b] = False
    adjl[a].append(b)
    adjl[b].append(a)

NIL = -1  # 未発見を示す値
d = [-1 for i in range(n+1)]  # 頂点1からの距離を格納するリスト
color = [NIL for i in range(n+1)]  # 未到達かを示すリスト


def bfs(start_node, color_id):  # uは探索の開始点
    global color, d
    q = deque([start_node])
    d[start_node] = 0
    color[start_node] = color_id
    while len(q) != 0:
        u = q.popleft()
        for v in adjl[u]:
            if color[v] == NIL:
                d[v] = d[u]+1
                color[v] = color_id
                q.append(v)


color_id = 0
for u in range(1, n+1):
    if color[u] == NIL:
        color_id += 1
        bfs(u, color_id)

group = {}
for i in range(1, n+1):
    if isalone.get(i, True):
        continue
    group[color[i]] = group.get(color[i], 0)+1

mx = 1
for k, v in group.items():
    mx = max(mx, v)

print(mx)


Measured memory_bytes: 107964
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
  int h, n, x;
  int damage = 0;
  scanf("%d %d", &h, &n);
  REP(i, n){
    scanf("%d", &x);
    damage += x;
  }  
  if (damage >= h) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
S=input()
ch="abcdefghijklmnopqrstuvwxyz"
ans=True

if S[0]!="A":
  ans=False
cnt=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cnt+=1

if cnt!=1:
  ans=False
  
cnt=0
for i in range(1,len(S)):
  if not(S[i] in ch):
    cnt+=1
if cnt!=1:
  ans=False
  
if ans:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3064
import java.util.*;


public class Main{
    
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int grab = input.nextInt();
        int [] arr = new int[grab+ 1];
        
        for(int i = 1; i <= grab ; i++){
            arr[i] = input.nextInt();
        }//for
        
        for(int i = 1; i <= grab; i++){
            System.out.print("node " + i + ": key = " + arr[i] + ", ");
            if(i/2 > 0){
                 System.out.print("parent key = " + arr[i/2] + ", ");
            }//if
            if(2*i <= grab){
            	System.out.print("left key = " + arr[2*i] + ", ");
            }//if
            if((2*i + 1) <= grab){
                System.out.print("right key = " + arr[2*i + 1] + ", ");
            }
            
            
            System.out.println();
        }//for
    }//main
}


Measured memory_bytes: 27408
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 1010;
const int MOD = 1e9+7;

int H, W;
ll dp[MAX][MAX];

int main () {
  cin >> H >> W;
  REP (h, H) {
    string s;
    cin >> s;
    REP (w, W) dp[h][w] = -1 * (s[w] == '#');
  }
  dp[0][0] = 1;
  REP (h, H-1) if (dp[h][0] >= 0 && dp[h+1][0] >= 0) dp[h+1][0] = dp[h][0];
  REP (w, W-1) if (dp[0][w] >= 0 && dp[0][w+1] >= 0) dp[0][w+1] = dp[0][w];
  FOR (h, 1, H) FOR (w, 1, W) if (dp[h][w] >= 0)
    dp[h][w] = (max(dp[h-1][w], 0ll) + max(dp[h][w-1], 0ll)) % MOD;
  cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s, t;
    cin >> s >> t;
    REP(i,s.size()) {
        if (s[i] != t[t.size()-1-i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())

submit = dict()
WA = 0
AC = 0

for i in range(M):
  p,S = map(str, input().split())
  
  if p not in submit:
    if S == "AC":
      submit[p] = -1
      AC += 1
    elif S =="WA":
      submit[p] = 1
  else:
    if S == "AC":
      if submit[p] != -1:
        AC += 1
        WA += submit[p]
        submit[p] = -1
    elif S =="WA":
      if submit[p] != -1:
        submit[p] += 1    	

print(AC,WA)

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
const ll mod = 1e9+7;
#define INF 200100
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)



ll fac[INF];
ll inv[INF];
ll facinv[INF];
void C_init(){
    fac[0] = 1;
    for(int i = 1;i < INF;i++)fac[i] = (fac[i-1] * i)%mod;
    inv[1] = 1;
    for(int i = 2;i < INF;i++)inv[i] = ((-(mod/i)*inv[mod%i])%mod+mod)%mod;
    facinv[0] = 1;
    for(int i = 1;i < INF;i++)facinv[i] = (facinv[i-1] * inv[i])%mod;
    return;
}
ll nCr(ll n, ll r){
    return ((fac[n] * facinv[n-r])%mod * facinv[r])%mod;
}
/*--------------------------------------------*/

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(ALL(a));
  
  
  ll b = a[n-1];
  
  ll Max = 1e9,num = 0;
  
  
  double center = b/2.0;
  
  rep(i,n-1){
    
    if(abs(a[i] - center) < Max){
		Max = abs(a[i] - center);
        num = a[i];
    }
  }
 
	
  
  cout << b << ' ' << num << endl;
   
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 2e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
bool vis[N];int n,m,ans;
vi v[N];
int dfs(int now)
{
	int res=1;
	vis[now]=true;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		if(!vis[to])res+=dfs(to);
	}
	return res;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	for(int i=0;i<n;i++)
		if(!vis[i])
			ans=max(dfs(i),ans);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 24104
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=[0]*n
num=[]
if k>41:
    ans=[n]*n
    print(*ans)
else:
    def c(num1,num2,num3):
        num[max(0,num1-num2)]+=1
        num[min(num3,num1+num2+1)]-=1
    for i in range(k):
        num=[0]*(n+1)
        for j in range(n):
            c(j,a[j],n)
        num5=0
        for j in range(n):
            num5+=num[j]
            a[j]=num5
        if sum(a)==n*n:
            break
    print(*a)


Measured memory_bytes: 152256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int N,A[100],sum=0;
	priority_queue<int,vector<int>,greater<int>> q;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		sum+=A[i];
		q.push(A[i]);
	}
	if(sum%10!=0){
		cout<<sum<<endl;
		return 0;
	}else{
		while(!q.empty()){
			if(q.top()%10!=0){
				cout<<sum-q.top()<<endl;
				return 0;
			}
			q.pop();
		}
	}
	cout<<"0"<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()

	f := make([]int, N+1)

	for x := 1; x < 100; x++ {
		for y := x; y < 100; y++ {
			for z := y; z < 100; z++ {
				n := x*x + y*y + z*z + x*y + y*z + z*x
				if n > N {
					continue
				}
				if x == y && y == z {
					f[n] += 1
				} else if x == y || y == z {
					f[n] += 3
				} else {
					f[n] += 6
				}
			}
		}
	}
	for i := 1; i <= N; i++ {
		fmt.Fprintf(out, "%d\n", f[i])
	}
}


Measured memory_bytes: 1956
#include<iostream>

using std::cin;
using std::cout;

inline int dis( int x , int y )
{
	return x + y;
}

int main( void )
{
	int T;
	cin >> T;
	int buf1 , buf2 , buf3;
	while( T-- )
	{
		cin >> buf1 >> buf2 >> buf3;
		if( buf1 < dis( buf2 , buf3 ) )
		{
			cout << "No\n";
			return 0;
		}
		if( ( buf1 - dis( buf2 , buf3 ) ) & 1 )
		{
			cout << "No\n";
			return 0;
		}
	} 
	cout << "Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    string o, e;
    cin >> o >> e;

    rep(i, o.size()+e.size()){
        if(i%2==0){cout<<o[i/2];}
        else{
            cout << e[(i-1)/2];
        }
    }
    cout << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,A,B,bigsum=0;
    cin >> N >> A >> B;
    for(int i=0;i<=N;i++){
        int a=i;
        int sum=0;
        while(a>0){
            sum+=a%10;
            a/=10;
        }
        if(sum>=A && B>=sum){
            bigsum+=i;
        }
    }
    cout << bigsum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  while(1){
    C-=B;
    if(C<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    A-=D;
    if(A<=0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {

		Scanner sc = new Scanner(System.in);
		int N = 0;
		boolean j = false;

		N = sc.nextInt();

		for(int x = 1;x <= 9;x++) {
			for(int y = 1;y <=9;y++) {
				if(N == x*y) {
					j = true;
				}
			}
		}
		if(j == true) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
   int n,k;
   cin>>n>>k;
   vector<int> p(n);
   rep(i,n) cin>>p[i];

   sort(all(p));
   ll ans=0;
   rep(i,k){
       ans+=p[i];
   }

   cout<<ans<<endl;
}


Measured memory_bytes: 3580
#include<stdio.h>
 
int main(void){
       int a , b, c;
       for(a=1;a<10;a++){
        for(b=1;b<10;b++){
           c = a * b;
                printf("%dx%d=%d\n", a, b, c);
        }
     }
     return 0;
}

Measured memory_bytes: 524
n,m = map(int,input().split())
judge = [True for i in range(n+5)]
for i in range(m):
    judge[int(input())] = False
dp = [0]*(n+5)
dp[0] = 1
for i in range(n):
    if i + 1 > n:continue
    if judge[i + 1]:dp[i+1] = (dp[i] +dp[i+1]) %1000000007
    if i + 2 > n:continue
    if judge[i + 2]:dp[i+2] = (dp[i] + dp[i+2]) %1000000007
print(dp[n]%1000000007)

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

int main()
{
	int N = 0;
	cin >> N;

	vector<int64_t> A(N);
	unordered_map<int64_t, int> map(0);
	for (int64_t i = 0; i < N; ++i)
	{
		cin >> A[i];
		++map[i+A[i]];
	}
	
	int64_t count = 0;
	for (int64_t i = 0; i < N; ++i)
	{
		count += map[i-A[i]];
	}

	cout << count << endl;

	return 0;
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

int s[(int)1e4], t[500];
int n, q;
void solve() {
	cin >> n;
	rep(i, 0, n) {
		cin >> s[i];
	}
	cin >> q;
	rep(i, 0, q) {
		cin >> t[i];
	}
	int ans = 0;
	rep(i, 0, q) {
		rep(j, 0, n) {
			if (t[i] == s[j]) {
				++ans;
				break;
			}
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3072
#include<stdio.h>


int main(void) {
    int a,b,c,no1,no2,no3;

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

    no3 = a>=b && a>=c ? a : (b>=c ? b : c);
    no2 = (a>=b && a<=c) || (a<=b && a>=c) ? a : ((a>=b && b>=c) || (a<=b && b<=c) ? b : c);
    no1 = a<=b && a<=c ? a : (b<=c ? b : c);

    printf("%d %d %d\n",no1,no2,no3);

    return 0;
}

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

int main(){
    while(1){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if (op == '?') break;
        else if (op == '+') cout << a + b << endl;
        else if (op == '-') cout << a - b << endl;
        else if (op == '*') cout << a * b << endl;
        else if (op == '/') cout << a / b << endl;
    
    }

    return 0;
    
}


Measured memory_bytes: 3100