akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc053/tasks/abc053_b

int main() {

    string s; cin >> s;

    int start = 0;
    REP(i, s.length()) {
        if (s[i] == 'A') {
            start = i;
            break;
        }
    }

    int end = 0;
    for (int i = s.length(); i >= 0; --i) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }

    cout << end - start + 1 << "\n";

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int m = Integer.parseInt(scan.next());
        int x = Integer.parseInt(scan.next());
        int[] c = new int[n];
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = Integer.parseInt(scan.next());
            for (int j = 0; j < m; j++) {
                a[i][j] = Integer.parseInt(scan.next());
            }
        }
        scan.close();

        int ans = Integer.MAX_VALUE;
        for (int bit = 0; bit < (1 << n); bit++) {
            int[] rikaido = new int[m];
            int money = 0;
            for (int i = 0; i < n; i++) {
                if ((bit & (1 << i)) != 0) {
                    for (int j = 0; j < m; j++) {
                        rikaido[j] += a[i][j];
                    }
                    money += c[i];
                }
            }

            boolean isSatisfied = true;
            for (int j = 0; j < m; j++) {
                if (rikaido[j] < x) {
                    isSatisfied = false;
                    break;
                }
            }

            if (isSatisfied) {
                ans = Math.min(ans, money);
            }
        }

        if (ans == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }

    }
}


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

int main() {
  int n;
  cin>>n;
  pair<int, int> a[n];
  for (int i=0; i<n; i++) {
    int l, r;
    cin>>l>>r;
    a[i].first = l;
    a[i].second = r + 1;
  }
  int l_max = 0;
  int r_min = 1e9;
  for (int i=0; i<n; i++) {
    l_max = max(a[i].first, l_max);
    r_min = min(a[i].second, r_min);
  }
  long ans1 = 0;
  for (int i=0; i<n; i++) {
    long n1 = max(r_min - l_max, 0);
    long n2 = a[i].second - a[i].first;
    ans1 = max(n1 + n2, ans1);
  }
  pair<long, long> c[n];
  for (int i=0; i<n; i++) {
    c[i] = make_pair(r_min - a[i].first, a[i].second - l_max);
  }
  sort(c, c + n);
  long ans2 = 0;
  long min_sec = 1e9;
  for (int i=0; i<n-1; i++) {
    min_sec = min(c[i].second, min_sec);
    ans2 = max(c[i+1].first + min_sec, ans2);
  }
  cout<<max(ans1, ans2)<<endl;
}

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

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

  int mi = min(a, b) * 2;
  int ma = max(a, b);

  int result = (16 - mi) / 2; 
  

  if (result >= max(a, b) - min(a, b))
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}
void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  string s="";
  int n;
  cin>>n;
  rep(i,0,n) s+="ACL";
  cout<<s<<endl;
}

int main(){
    optimizeIO();
    {solve();}
}


Measured memory_bytes: 7016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

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

using namespace std;

typedef long long ll;

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

  int m;
  cin >> m;

  vector<ll> d(m);
  vector<ll> c(m);

  rep(i, m) {
    cin >> d[i] >> c[i];
  }

  ll ans = 0;
  ll dd = 0, s = 0;
  rep(i, m) {
    dd += c[i];
    s += d[i]*c[i];
  }
  cout << (dd-1) + (s-1)/9 << endl;

  return 0;
}

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

int main()
{
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)
			break;

		for (int i = 0; i < H ; i++) {
			for (int j = 0; j < W; j++) {
				if (0 < i&&i < H - 1 && 0 < j&&j < W-1) {
					cout << '.';
				}
				else {
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#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,M;
vector<int> E[2020];

int EE[2020][2],TE[2020][2];
set<int> VE[2020];
vector<int> EL[2020];
int dir[2020];
int cnt[2020][2020];

void shrink(int cur) {
	FORR(c,EL[cur]) dir[c%M] = c/M;
}

int dfs(int cur,int pre,int tar) {
	if(cur==tar) {
		cnt[pre][cur]++;
		return 1;
	}
	else {
		int ok=0;
		FORR(e,E[cur]) if(e!=pre) ok+=dfs(e,cur,tar);
		if(ok&&pre) cnt[pre][cur]++;
		return ok>=1;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	
	dfs(1,1,0);
	FOR(i,M) {
		cin>>EE[i][0]>>EE[i][1];
		dfs(EE[i][0],0,EE[i][1]);
		TE[i][0]=EE[i][0];
		TE[i][1]=EE[i][1];
		VE[EE[i][0]].insert(i);
		VE[EE[i][1]].insert(i+M);
		EL[i].push_back(i);
	}
	
	
	int ret=0;
	for(y=1;y<=N;y++) for(x=1;x<y;x++) ret+=min(2,cnt[x][y]+cnt[y][x]);
	cout<<ret<<endl;
	
	while(true) {
		for(i=1;i<=N;i++) if(E[i].size()==1) break;
		if(i>N) break;
		int cur=i;
		vector<int> delcand;
		FORR(v,VE[cur]) if(v<M && VE[cur].count(v+M)) {
			delcand.push_back(v);
			shrink(v);
		}
		FORR(d,delcand) VE[cur].erase(d),VE[cur].erase(d+M);
		
		
		int p=E[cur][0];
		if(VE[cur].size()>=2) {
			int a=*VE[cur].begin()%M;
			
			VE[TE[a][0]].erase(a);
			VE[TE[a][1]].erase(a+M);
			int b=*VE[cur].begin()%M;
			VE[TE[b][0]].erase(b);
			VE[TE[b][1]].erase(b+M);
			
			if(TE[a][0]==cur) {
				FORR(e,EL[a]) {
					if(e>=M) e-=M;
					else e+=M;
				}
				swap(TE[a][0],TE[a][1]);
			}
			if(TE[b][1]==cur) {
				FORR(e,EL[b]) {
					if(e>=M) e-=M;
					else e+=M;
				}
				swap(TE[b][0],TE[b][1]);
			}
			TE[a][1]=TE[b][1];
			FORR(e,EL[b]) EL[a].push_back(e);
			EL[b].clear();
			VE[TE[a][0]].insert(a);
			VE[TE[a][1]].insert(a+M);
		}
		FORR(v,VE[cur]) {
			TE[v%M][v/M]=p;
			VE[p].insert(v);
		}
		VE[cur].clear();
		E[p].erase(remove(ALL(E[p]),cur),E[p].end());
		E[cur].clear();
	}
	
	for(i=1;i<=N;i++) FORR(v,VE[i]) shrink(v);
	FOR(i,M) {
		if(dir[i]) cout<<EE[i][1]<<" "<<EE[i][0]<<endl;
		else cout<<EE[i][0]<<" "<<EE[i][1]<<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: 15616
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 100005;
vector<int> g[NMAX];
bool check[NMAX];

deque<int> d;

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i ++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    d.push_back(1);
    check[1] = 1;
    bool flag = 0;
    while(flag == 0) {
        flag = 1;
        for(auto it : g[d.front()]) {
            if(check[it] == 0) {
                flag = 0;
                d.push_front(it);
                check[it] = 1;
                break;
            }
        }
        for(auto it : g[d.back()]) {
            if(check[it] == 0) {
                flag = 0;
                d.push_back(it);
                check[it] = 1;
                break;
            }
        }
    }
    cout << d.size() << "\n";
    while(d.size()) {
        cout << d.front() << " ";
        d.pop_front();
    }
    return 0;
}


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(0),cin.tie(0);
int main(void)
{
	AC;
	int T,a,n,i,b,k,t,sum=0;
	cin>>n>>a>>b;
	for(i=1;i<=n;i++){
		k=i;
		t=0;
		while(k!=0){
			t+=k%10;
			k/=10;
		}
		if(t>=a && b>=t) sum+=i;
	}
	cout<<sum<<"\n";
}



Measured memory_bytes: 384
import java.util.Scanner;

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

		int r = sc.nextInt();
		int c = sc.nextInt();

        int array[][] = new int[r][c];

        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
            }
        }
        int ar[] = new int[c];
        int allsum = 0;

        for(int i = 0; i < r; i++){
            int sum = 0;
            for(int j = 0; j < c; j++){
                ar[j] += array[i][j];
                sum += array[i][j];

                System.out.print(array[i][j] + " ");
            }
            allsum += sum;
            System.out.print(sum);
            System.out.println();
        }
        for(int i = 0; i < c; i++){
            System.out.print(ar[i] + " ");
        }
        System.out.print(allsum);
        System.out.println();
    }
}


Measured memory_bytes: 42216
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N+1];
  int b[N+1];
  int ans[N+1];
  for(int i=1; i<=N; i++){
    cin >> a[i];
  }
  for(int i=N; i>=1; i--){
    int cnt = 0;
    for(int j=i+i; j<=N; j+=i){
      if(j % i == 0){
        if(b[j] == 1) cnt++;
      }
    }
    if(a[i] == 1){
      if(cnt % 2 == 0){
        b[i] = 1;
      }else{
        b[i] = 0;
      }
    }else{
      if(cnt % 2 == 1){
        b[i] = 1;
      }else{
        b[i] = 0;
      }
    }
  }

  int m = 0;
  for(int i=1; i<=N; i++){
    if(b[i] == 1){
      m++;
    }
  }
  cout << m << endl;
  for(int i=1; i<=N; i++){
    if(b[i] == 1){
      cout << i << ' ';
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
function main()
  local input = string.gmatch(io.read(), "[^ ]+")
  local n = tonumber(input())
  local m = tonumber(input())

  local ans
  if n < math.floor(m/2) then
    ans = n
  else
    ans = math.floor(m/2)
  end

  m = m - 2*ans

  ans = ans + math.floor(m/4)

  print(ans)
end

main()


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define    PI                  3.14159265358979323846
 
int main()
{
    ll r;
    cin>>r;
 
    double ans = 2*PI*r;
    cout<<fixed<<setprecision(20)<<ans<<endl;
}

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

const int MAXN=1e5+5;

int n;
int a[MAXN];

int gcd(int x,int y){return !y?x:gcd(y,x%y);}

bool solve(){
    int cnt0=0,cnt1=0;
    for(int i=1;i<=n;i++) (a[i]&1)?cnt1++:cnt0++;
    if(cnt0&1) return 1;
    else if(cnt1>1) return 0;
    else {
        for(int i=1;i<=n;i++)
            if(a[i]&1) {
                if(a[i]==1) return 0;
                else a[i]--;
            }
        int gg=0;
        for(int i=1;i<=n;i++) gg=gcd(gg,a[i]);
        for(int i=1;i<=n;i++) a[i]/=gg;
        return !solve();
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    printf("%s",solve()?"First":"Second");
}


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

int main(){
  int N;
  cin >> N;
  if ( N == 100000) cout << 90909 << endl;
  else if (N >= 10000) cout << ( N - 9999) + 909 << endl;
  else if (N >= 1000) cout <<  909 << endl;
  else if (N >= 100) cout << ( N - 99) + 9 << endl;
  else if (N >= 10) cout << 9 << endl;
  else cout << N << endl;  
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = LI()
    S = S[:-1]
    ans = 0
    for C in range(1, N):
        tmp = 0
        L = 0
        lim = (N - 1 - C) if (N - 1) % C else (N // 2)
        while L < lim:
            tmp += S[L] + S[-L]
            ans = max(ans, tmp)
            L += C
    return ans

print(main())

Measured memory_bytes: 14388
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;
#define PI 3.14159265358979323846

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> h(10);
  h[2] = h[4] = h[5] = h[7] = h[9] = "hon";
  h[0] = h[1] = h[6] = h[8] = "pon";
  h[3] = "bon";
  n = n % 10;
  cout << h[n] << endl;
  return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;
  int h[105];
  rep(i, n) cin >> h[i];

  f = 0;
  int count=0;
  rep(i, n){
    for(j=0;j<i;j++){
      if(h[i] < h[j]){
        f = 1;
        break;
      }
    }
    if(f==0) count++;
    f = 0;
  }

  out(count);
}

Measured memory_bytes: 256
// Problem : D - String Formation
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,1,1,-1,-1,-1,0,0};
int dy[8]={1,0,-1,1,-1,0,1,-1};
//#define int long long
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
string s;
cin>>s;
int q;
cin>>q;
int rev=0;
string front="",back="";
while(q--){
	int x;
	cin>>x;
	if(x==1)
	rev++;
	else {
		int f;char c;
		cin>>f>>c;
		if(f==1){
			if(rev%2){
				back+=c;
			}
			else {
				front+=c;				
			}
		}
		else {
			if(rev%2){
				front+=c;
			}
			else back+=c;
		}
	}

}
reverse(front.begin(),front.end());
s=front+s;
s=s+back;
	if(rev%2)
	reverse(s.begin(),s.end());
	cout<<s;

}









Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N;
  cin >> N;
  vector<int> Ap, Am;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    if (a < 0) Am.push_back(a);
    else Ap.push_back(a);
  }
  
  sort(Am.begin(), Am.end());
  sort(Ap.begin(), Ap.end());
  
  vector<int> x(N - 1), y(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    int xx;
    if (Ap.size() > 0)
    {
      xx = Ap.at(Ap.size() - 1);
      Ap.erase(Ap.end() - 1);
    }
    else
    {
      xx = Am.at(Am.size() - 1);
      Am.erase(Am.end() - 1);
    }
    int yy;
    if (Am.size() > 0)
    {
      yy = Am.at(0);
      Am.erase(Am.begin());
    }
    else
    {
      yy = Ap.at(0);
      Ap.erase(Ap.begin());
    }
    if (Ap.size() > Am.size()) swap(xx, yy);
    if (xx - yy >= 0)
    {
      auto it = lower_bound(Ap.begin(), Ap.end(), xx - yy);
      Ap.insert(it, xx - yy);
    }
    else
    {
      auto it = lower_bound(Am.begin(), Am.end(), xx - yy);
      Am.insert(it, xx - yy);
    }
    x.at(i) = xx;
    y.at(i) = yy;
    //cerr << xx << " " << yy << endl;
    //for (int i = 0; i < Ap.size(); i++) cerr << Ap.at(i) << endl;
    //for (int i = 0; i < Am.size(); i++) cerr << Am.at(i) << endl;
  }
  
  cout << x.at(x.size() - 1) - y.at(y.size() - 1) << endl;
  for (int i = 0; i < N - 1; i++)
  {
    cout << x.at(i) << " " << y.at(i) << endl;
  }
  
}

Measured memory_bytes: 4340
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
int iLL(Pt a, Pt b, Pt c, Pt d) {
	if (sig((b - a).det(d - c))) return 1; // intersect
	if (sig((b - a).det(c - a))) return 0; // parallel
	return -1; // correspond
}
bool iLS(Pt a, Pt b, Pt c, Pt d) {
	return (sig(tri(a, b, c)) * sig(tri(a, b, d)) <= 0);
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
	return (iSP(a, b, c) * iSP(a, b, d) <= 0 && iSP(c, d, a) * iSP(c, d, b) <= 0);
}
bool iSSstrict(Pt a, Pt b, Pt c, Pt d) {
	return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0);
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
	b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}
double dLP(Pt a, Pt b, Pt c) {
	return ABS(tri(a, b, c)) / (b - a).ABS();
}
double dSP(Pt a, Pt b, Pt c) {
	if (sig((b - a).dot(c - a)) <= 0) return (c - a).ABS();
	if (sig((a - b).dot(c - b)) <= 0) return (c - b).ABS();
	return ABS(tri(a, b, c)) / (b - a).ABS();
}
double dLL(Pt a, Pt b, Pt c, Pt d) {
	return iLL(a, b, c, d) ? 0 : dLP(a, b, c);
}
double dLS(Pt a, Pt b, Pt c, Pt d) {
	return iLS(a, b, c, d) ? 0 : min(dLP(a, b, c), dLP(a, b, d));
}
double dSS(Pt a, Pt b, Pt c, Pt d) {
	return iSS(a, b, c, d) ? 0 : min(min(dSP(a, b, c), dSP(a, b, d)), min(dSP(c, d, a), dSP(c, d, b)));
}
Pt p[5300];
Pt q[5300];
int main(){
	int a;
	scanf("%d",&a);
	if(a>5300){
		printf("0\n");return 0;
	}
	for(int i=0;i<a;i++){
		int X1,Y1,X2,Y2;
		scanf("%d%d%d%d",&X1,&Y1,&X2,&Y2);
		p[i]=Pt(X1,Y1);
		q[i]=Pt(X2,Y2);
	}
	double ret=9999999;
	for(int i=0;i<a;i++){
		for(int j=i+1;j<a;j++){
			ret=min(ret,dSS(p[i],q[i],p[j],q[j]));
		}
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 1228
#include <iostream>
#include<cmath>
#include<vector>
using namespace std;
long dp[100][100001];

int main()
{
    long n,w;
    cin>>n>>w;
    long a[n][2];
    //int dp[n][w+1]={0};
    /*for(long i=0;i<n;i++){
        for(long j=0;j<w;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(long i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    
    for(long i=0;i<n;i++){
        for(long j=1;j<=w;j++){
            if(i==0){
                if(j>=a[i][0]){
                    dp[i][j]=a[i][1];
                }
            }
            
            else if(j>=a[i][0]){
                dp[i][j]=max(dp[i-1][j],a[i][1]+dp[i-1][j-a[i][0]]);
            }
            
            else {
                dp[i][j]=dp[i-1][j];
            }
            
        }
    }
    /*for(long i=0;i<n;i++){
        for(long j=0;j<=w;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[n-1][w];
    
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int n,k;
vector<int> b[10];
int d[2001];

int main(){
    cin >> n >> k;
    memset(d,0,sizeof(d));
    REP(i,10){
	b[i].PB(0);
    }
    REP(i,n){
	int c,g;
	cin >> c >> g;
	b[g-1].PB(c);
    }
    REP(i,10){
	sort(b[i].begin()+1,b[i].end(),greater<int>());
	if(b[i].size() <= 0) continue;
	REP(j,b[i].size()-1){
	    b[i][j+1] += b[i][j];
	}
	REP(j,b[i].size()){
	    b[i][j] += (j-1)*j;
	}
    }

    d[0] = 0;
    REP(i,10){
	RREP(j,n+1){
	    if(d[j] < 0) continue;
	    int s = min(n-j,(int)b[i].size() - 1);
            for(int l=s;l >= 0;l--){
		d[j+l] = max(d[j+l],d[j]+b[i][l]);
	    }
	}
    }
    int ans = 0;
    cout << d[k] << endl;
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for(int i = k+1; i <= n; i++){
		ans += (n/i)*(i-k) + (n%i-k+1>0?n%i-k+1:0);
	}
    if(k==0) ans -= n;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int MAXN =(int) 3e3+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int R;
void work(){
    scanf("%d",&R);
    printf("%.12lf\n",R*2*pi);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}





Measured memory_bytes: 3788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int mx=0;
	int mn=0;
	int mxid=-1;
	int mnid=-1;
	bool flag=true;
	int befo=-100000000;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(a[i]<befo)flag=false;
		befo=a[i];
		if(a[i]<mn)
		{
			mn=a[i];
			mnid=i;
		}
		if(a[i]>mx)
		{
			mx=a[i];
			mxid=i;
		}
	}
	if(flag)
	{
		cout << 0 << endl;
		return 0;
	}
	int dir=(abs(mx)-abs(mn)>=0 ? 0:1);
	vector<pair<int,int>> ans;
	if(dir==0)
	{
		ans.push_back(make_pair(mxid,0));
		ans.push_back(make_pair(mxid,0));
		a[0]+=a[mxid];
		a[0]+=a[mxid];
		for(int i=0;i<n-1;i++)
		{
			ans.push_back(make_pair(i,i+1));
			ans.push_back(make_pair(i,i+1));
			a[i+1]+=a[i];
			a[i+1]+=a[i];
		}
	}
	if(dir==1)
	{
		ans.push_back(make_pair(mnid,n-1));
		ans.push_back(make_pair(mnid,n-1));
		a[0]+=a[mnid];
		a[0]+=a[mnid];
		for(int i=n-1;i>0;i--)
		{
			ans.push_back(make_pair(i,i-1));
			ans.push_back(make_pair(i,i-1));
			a[i-1]+=a[i];
			a[i-1]+=a[i];
		}
	}

	cout << ans.size() << endl;
	for(int i=0;i<ans.size();i++)
		cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
	for(int i=0;i<n;i++)
		cerr << a[i] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    string x;
    cin >> x;
    int s = 0, t = 0, cnt = 0;
    for (int i = 0; i < x.length(); i++)
    {
        if (x[i] == 'S')
        {
            s++;
        }
        else
        {
            t++;
        }
        if (s > 0 && t > 0)
        {
            s--;
            t--;
        }
        else if (s < t)
        {
            cnt++;
            t = 0;
        }
    }
    cnt += s;
    cout << cnt << endl;
}


Measured memory_bytes: 640
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    s = input()
    K = int(input())
    dict = set()
    for i in range(len(s)):
        for j in range(K):
            if i+j+1 <= len(s):
                dict.add(s[i:i+j+1])
    di = list(dict)
    di.sort()
    print(di[K-1])
    
if __name__ == '__main__':
    main()


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    ll n, y;
    cin >> n >> y;

    int a = 0, b = 0, c = 0;

    for (ll i = 0; i <= y / 5000LL; i++) {
        for (ll j = 0; j <= (y - 5000LL * i) / 10000LL; j++) {
            ll k = n - i - j;

            if (y == (10000 * j + 5000 * i + 1000 * k)) {
                b = true;
                cout << j << " " << i << " " << k << endl;
                break;
            }
        }
        if (b)
            break;
    }

    if (!b) {
        cout << "-1 -1 -1" << endl;
    }
}

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

using namespace std;

int w, h;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

struct Pazzle {
    char glid[10][10];
};

void draw(char glid[][10], int x, int y, char base, char color, int *count) {
    glid[y][x] = color;
    for (int i = 0; i < 4; i++) {
        int nposx = x + dx[i];
        int nposy = y + dy[i];
        if (nposx < 0 || nposx >= w || nposy < 0 || nposy >= h) {
            continue;
        }
        if (glid[nposy][nposx] == base) {
            (*count)++;
            draw(glid, nposx, nposy, base, color, count);
        }
    }
}

int main() {
    while (1) {
    Pazzle p;
    cin >> w >> h;
    if (w == 0) {
        break;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> p.glid[i][j];
        }
    }

    queue<Pazzle> que;
    int depth = 0;
    bool success = false;
    que.push(p);
    while (!que.empty()) {
        int size = que.size();
        for (int i = 0; i < size; i++) {
            p = que.front();
            que.pop();
            int ret1 = 1, ret2 = 1;
            Pazzle temp1, temp2;
            temp1 = temp2 = p;
            if (p.glid[0][0] == 'R') {
                draw(temp1.glid, 0, 0, p.glid[0][0], 'G', &ret1);
                draw(temp2.glid, 0, 0, p.glid[0][0], 'B', &ret2);
            }
            else if (p.glid[0][0] == 'G') {
                draw(temp1.glid, 0, 0, p.glid[0][0], 'R', &ret1);
                draw(temp2.glid, 0, 0, p.glid[0][0], 'B', &ret2);
            }
            else {
                draw(temp1.glid, 0, 0, p.glid[0][0], 'R', &ret1);
                draw(temp2.glid, 0, 0, p.glid[0][0], 'G', &ret2);
            }
            
            if (ret1 == h * w || ret2 == h * w) {;
                success = true;
                break;
            }
            que.push(temp1);
            que.push(temp2);
        }
        if (success == true) {
            cout << depth << endl;
            break;
        }
        depth++;
    }
    }

    return 0;
}

Measured memory_bytes: 25708
N = int(input())
A = list(map(int, input().split()))

ans = 0
plus = 0
minus = 0
zero = 0
min = 10**9

for i in range(N):
    if A[i] == 0:
        zero += 1
    elif A[i] > 0:
        plus += 1
    else:
        minus += 1
    ans += abs(A[i])
    if min > abs(A[i]):
        min = abs(A[i])

if zero > 0 or minus%2==0:
    print(ans)
else:
    print(ans - min*2)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}
 
/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
 
//#define int ll
//#define int long long
 
signed main()
{
 int a, b, k; cin >> a >> b >> k;
  int cnt = 0;
  vi v1(0);
  int whi = max(a,b);
  for(int i =1; i <= whi; ++i){
    if(a%i == 0&&b%i == 0){
     v1.PB(i);
      ++cnt;
    }
  }
/*for(int i = 1; i <= whi; ++i){
  cout << a%i;
  cout << b%i << endl;
}*/
  

  reverse(v1.begin(),v1.end());
//    REP(i, cnt){cout << v1[i] << endl;}
  
  cout << v1[k-1];
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int maxn = 503;
const int maxm = 200035;

struct Edge
{
	int v,w;
	Edge(int a=0, int b=0):v(a),w(b) {}
}edges[maxm];
int n,m;
int fa[maxn],mp[maxn][maxn],ans,lim[maxn],bck[maxn];
int edgeTot,head[maxn],nxt[maxm];
std::vector<int> cam[maxn];

int read()
{
	char ch = getchar();
	int num = 0, fl = 1;
	for (; !isdigit(ch); ch=getchar())
		if (ch=='-') fl = -1;
	for (; isdigit(ch); ch=getchar())
		num = (num<<1)+(num<<3)+ch-48;
	return num*fl;
}
void addedge(int u, int v, int w)
{
	edges[++edgeTot] = Edge(v, w), nxt[edgeTot] = head[u], head[u] = edgeTot;
	edges[++edgeTot] = Edge(u, w), nxt[edgeTot] = head[v], head[v] = edgeTot;
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void deal(int S)
{
	std::queue<int> q;
	while (q.size()) q.pop();
	for (int i=1; i<=n; i++) fa[i] = i, bck[i] = lim[i] = 0;
	lim[S] = 2e9, q.push(S);
	for (int now; q.size(); )
	{
		now = q.front(), q.pop();
		for (int i=head[now]; i!=-1; i=nxt[i])
		{
			int v = edges[i].v, w = edges[i].w;
			if (w > lim[now]||v==bck[now]) continue;
			if (find(now)==find(v)){
				for (int i=1; i<=n; i++) mp[S][i] = mp[i][S] = false;
				return;
			}
			fa[fa[now]] = fa[v], lim[v] = w;
			bck[v] = now, q.push(v);
		}
	}
	for (int i=1; i<=n; i++)
		if (find(i)==find(S)){
			mp[i][S] = mp[S][i] = false;
			cam[i].push_back(S);
		}
}
int main()
{
	memset(head, -1, sizeof head);
	n = read(), m = read();
	for (int i=1; i<=m; i++)
		addedge(read(), read(), i);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			mp[i][j] = true;
	for (int i=1; i<=n; i++) deal(i);
	for (int i=1; i<=n; i++)
		for (int j=0,mx=cam[i].size(); j<mx; j++)
			for (int k=j+1; k<mx; k++)
				mp[cam[i][j]][cam[i][k]] = mp[cam[i][k]][cam[i][j]] = false;
	for (int i=1; i<=n; i++)
		for (int j=i+1; j<=n; j++)
			if (mp[i][j]){
				++ans;
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    priority_queue <int> pq;
    for(int i=0,x;i<n;i++)
    {
        cin>>x;
        pq.push(x);
    }
    while(m)
    {
        int t = pq.top();
        pq.pop();
        t>>=1;
        m--;
        pq.push(t);
    }
    long long int ans = 0;
    while(!pq.empty())
    {
        int t = pq.top();
        pq.pop();
        ans += 1LL*t;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    string s;
    s=to_string(n);
    rep(i,3){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int n;
typedef pair<int,int> pii;
pii x[11];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>x[i].fi>>x[i].se;
	sort(x+1,x+n+1);
	double ans=0;
	do{
		for(int i=2;i<=n;i++){
			ans+=sqrt(1.0*(x[i].fi-x[i-1].fi)*(x[i].fi-x[i-1].fi)+1.0*(x[i].se-x[i-1].se)*(x[i].se-x[i-1].se));
		}
	}while(next_permutation(x+1,x+n+1));
	for(int i=1;i<=n;i++) ans/=i;
	printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}

		int count = 0;
		for(int i = 0; i < n; i++){
			int minj = i;
			for(int j = i; j < n; j++){
				if(arr[j] < arr[minj]){
					minj = j;
				}
			}
			if(i != minj){
				int small = arr[minj];
				arr[minj] = arr[i];
				arr[i] = small;
				count++;
			}
		}

		for(int i = 0; i < n; i++){
			System.out.printf(i != n-1? "%d ": "%d\n", arr[i]);
		}
		System.out.printf("%d\n", count);
	}
}

Measured memory_bytes: 26392
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<string> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll l ; cin >> l ;
	vector<string> ans(n) ;
	for(int i=0;i<n;i++){
		cin >> ans.at(i) ;
	}
	mysort(ans) ;
	for(auto i:ans) cout << i ;
	cout << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s[1000],c='a';
    int i;
    cin>>s;
    for(i=0;i<1000;i++){
        if (s[i]=='\0') break;
        c=s[i];
    }
    if (c=='s'){
        cout<<s<<"es";
    }else{
        cout<<s<<"s";
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INFI = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 3e3+2;
int N;
ll a[MAXN], dp[MAXN][MAXN];
bool vis[MAXN][MAXN];
ll solve(int l, int r){
	if(vis[l][r])return dp[l][r];
	vis[l][r] = true;
	if(l==r)return dp[l][r] = a[l];
	return dp[l][r] = max(a[l]-solve(l+1, r), a[r]-solve(l, r-1));
}
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N;
	for(int i = 1;i<=N;i++)cin >> a[i];
	cout << solve(1, N) << nl;
}

Measured memory_bytes: 78592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, k;
  cin >> n >> k;
  cout << (n-1+k-2)/(k-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N];
int b[N];

int cmp(int a,int b)
{
    return a>b;
}

map <int,int> mp;
string s;
string t;

int parent[N],n,m,sum;
int num[N];

void Init()
{
    for(int i = 1;i <= n;i++)
        parent[i] = i;
    return;
}

int get_boss(int v)
{
    if(parent[v] == v)
        return v;
    else
    {
        parent[v] = get_boss(parent[v]);
        return parent[v];
    }
}

void Merge(int v,int u)
{
    int t1 = get_boss(v);
    int t2 = get_boss(u);
    parent[t2] = t1;
    return;
}

int main()
{
    cin>>n>>m;
    Init();
    while(m--){
        int a,b;
        cin>>a>>b;
        Merge(a,b);

    }
    int ans=0;
    for(int i=1;i<=n;i++){
        parent[i]=get_boss(parent[i]);
        num[parent[i]]++;
        //cout<<parent[i]<<endl;
    }
    for(int i=1;i<=n;i++) ans=max(ans,num[i]);
    cout<<ans<<endl;
}






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

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


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int k, c, s; s = 0, cin >> k, k; cout << s / (k - 1) << endl)
        rep(i, k * (k - 1) / 2) cin >> c, s += c;

    return 0;
}

Measured memory_bytes: 1160