akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

int Q;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
    cin >> Q;

    // エラトステネスの篩
    Sieve sieve = Sieve(100100);
    map<ll, ll> sum;
    ll tmp = 0; 
    for (int i = 1; i <= 100100; i++) {
        if (i % 2 == 0) {
            sum[i] = tmp;
            continue;
        }

        if (sieve.isPrime(i) && sieve.isPrime((i + 1) / 2)) {
            tmp++;
            sum[i] = tmp;
        } else {
            sum[i] = tmp;
        }
    }
    // ll cnt = 0;
    // for (auto mp : sum) {
    //     cout << mp.first << " " << mp.second << endl;
    //     cnt++;
    //     if (cnt > 20) {
    //         return 0;
    //     }
    // }

    rep(i, Q) {
        ll l, r;
        cin >> l >> r;
        ll ans = sum[r] - sum[l - 1];
        // cout << sum[r] << " " << sum[l] << endl;
        cout << ans << endl;
    }
}

Measured memory_bytes: 9216
#include<stdio.h>


int main()
{

    int a,b,c,i,sum=0,max;

    scanf("%d",&a);

    int A[a];


    for(i=0;i<a;i++){

        scanf("%d",&A[i]);

        sum=sum+A[i];

    }

    max=A[0];

    for(i=1;i<a;i++){

        if(max<A[i]) max=A[i];

    }

    b=sum-max;

    if(b>max) printf("Yes\n");

        else printf("No\n");









    return 0;

}


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

        Scanner sc = new Scanner(System.in);
        int n,m = 0;
        n = sc.nextInt();
        m = sc.nextInt();
        if(n==m){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
using namespace std;
int main(){
    int N;cin >> N;
    int max=0,mai,x,ans=0;
    vector<int> vec(N);

    REP(i,N){
        cin >> x;
        vec[i] = x;

        if(max<x){
            max = x;
            mai = i;
        }
        
    }

    vec[mai] = 0;

    REP(i,N){
        ans += vec[i];
    }

    if(max < ans){
        cout << "Yes" <<endl;
    }else{
        cout << "No"<<endl;
    }

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

type IOTp struct {
	iBuffer []byte
	iPos int
}
func (this *IOTp) GetChar() byte {
	res:=this.iBuffer[this.iPos]
	this.iPos++
	return res
}
func (this *IOTp) ReadInt() int {
	res:=0
	k:=1
	for ch:=this.iBuffer[this.iPos]; !(ch>='0' && ch<='9'); ch=this.iBuffer[this.iPos]{
		if ch=='-' {
			k=-1
		}
		this.iPos++
	}
	for ch:=this.iBuffer[this.iPos]; ch>='0' && ch<='9'; ch=this.iBuffer[this.iPos]{
		res=res*10+int(ch-'0')
		this.iPos++
	}
	res*=k
	return res
}
func NewIOTp() *IOTp {
	now:=new(IOTp)
	//inputFile,_:=os.Open("in.txt")
	inputFile:=os.Stdin
	now.iBuffer,_=ioutil.ReadAll(inputFile)
	now.iBuffer=append(now.iBuffer, '\n')
	now.iPos=0
	return now
}
func max(x,y int) int {
	if x>y {
		return x
	} else {
		return y
	}
}
func min(x,y int) int {
	if x<y {
		return x
	} else {
		return y
	}
}
var cin *bufio.Reader
var cout *bufio.Writer
const MAXN=500
var n int
func get(i,j int) (x,y int) {
	x=(i-j+n)/2
	y=(i+j)/2
	return
}
func main() {
	IO:=NewIOTp()
	cout=bufio.NewWriter(os.Stdout)
	n=IO.ReadInt()
	var prime []int
	for i:=2; len(prime)<=1000; i++ {
		flag:=true
		for j:=2; j*j<=i; j++ {
			if i%j==0 {
				flag=false
				break
			}
		}
		if flag {
			prime=append(prime, i)
		}
	}
	var a[MAXN+5][MAXN+5]int
	for i:=1; i<=n; i++ {
		for j:=1; j<=n; j++ {
			if (i+j)%2==1 {
				x,y:=get(i,j)
				//fmt.Println(i,j,x,n+y)
				a[i][j]=prime[x]*prime[n+y]
			} else {
				x1,y1:=get(i,j-1)
				x2,y2:=get(i,j+1)
				//fmt.Println(prime[x1],prime[y1+n-1],prime[x2],prime[y2+n-1])
				a[i][j]=prime[x1]*prime[n+y1]*prime[x2]*prime[n+y2]+1
			}
			fmt.Fprint(cout,a[i][j]," ")
		}
		fmt.Fprintln(cout)
	}
	cout.Flush()
}


Measured memory_bytes: 9600
import Control.Monad
import Control.Applicative
import Data.List

isEven :: [Int] -> Int -> Bool
isEven lst idx = ((lst !! idx) `mod` 2) == 0

main :: IO ()
main = do
  ss <- (map read . words) <$> getLine
  if (isEven ss 0) || (isEven ss 1)
  then putStrLn "Even"
  else putStrLn "Odd"

Measured memory_bytes: 508
a, b = map(int, input().split())
if a * b <= 0:
    print("Zero")
else:
    assert(a > 0 or b < 0)
    if a > 0:
        print("Positive")
    else:
        print("Positive" if abs(a-b+1) % 2 == 0 else "Negative")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,k; cin>>n>>k;
    vector<pair<ll,ll>> coo(n);
    rep(i,n){
        ll x,y; cin>>x>>y;
        coo[i]={x,y};
    }
    sort(coo.begin(),coo.end());
    ll res=-1;
    rep(i,n){
        rep(j,n){
            if(j-i+1<k) continue;
            vector<ll> ys={};
            for(ll l=i; l<=j; l++){
                ys.push_back(coo[l].second);
            }
            sort(ys.begin(),ys.end());
            ll tmp=1e10;
            ll len=ys.size();
            for(ll l=0; l+k-1<len; l++){
                chmin(tmp,ys[l+k-1]-ys[l]);
            }
            if(res==-1) res=(coo[j].first-coo[i].first)*tmp;
            else chmin(res, (coo[j].first-coo[i].first)*tmp);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=305,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        double pw;cin>>pw;
        double a=pw,b=0;
        
        vector<pair<double,pair<double,double>>> S;
        
        S.push_back(mp(0,mp(0,0)));
        
        for(int i=0;i<N;i++){
            double vw,pf,vf,th;cin>>vw>>pf>>vf>>th;
            
            double aa,bb;
            aa=-vw*(pf/vf);
            bb=th/vf*pf;
            
            b+=max(bb,0.0);
            
            if(bb<0){
                if(aa>0) S.push_back(mp(abs(bb)/aa,mp(aa,bb)));
            }else{
                a+=aa;
                if(aa<0) S.push_back(mp(abs(bb)/abs(aa),mp(-aa,-bb)));
            }
        }
        
        sort(all(S));
        
        double ans=1e15;
        
        int i=0;
        
        //cout<<setprecision(25)<<a<<" "<<b<<endl;
        
        while(i<si(S)){
            int j=i;
            while(j<si(S)&&S[i].fi==S[j].fi){
                a+=S[j].se.fi;
                b+=S[j].se.se;
                j++;
            }
            
            chmin(ans,S[i].fi*a+b);
            
            i=j;
        }
        
        //cout<<setprecision(25)<<a<<" "<<b<<endl;
        
        cout<<setprecision(25)<<ans<<endl;
    }
}



Measured memory_bytes: 8536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        String line = readLine(System.in);
        int sec = Integer.parseInt(line);
        int h = sec / 3600;
        int m = (sec / 60) % 60;
        int s = sec % 60;
        System.out.println(h + ":" + m + ":" + s);
    }

    private static String readLine(InputStream in) {
        String line = null;
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new InputStreamReader(in));
            line = reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        return line;
    }
}

Measured memory_bytes: 17060
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair <int, ll> pil;
#define x first
#define y second
#define mp make_pair

struct node{
	ll mval, upd;
};

node t[(1 << 19) + 5];
vector <pil> seg[200005];
int n, m;

void update(int root, int l, int r, int s, int e, ll val){
	if(l > r || l > e || r < s)
		return;
	if(l >= s && r <= e){
		t[root].mval += val;
		t[root].upd += val;
		return;
	}
	int mid = (l + r) / 2;
	update(root * 2, l, mid, s, e, val);
	update(root * 2 + 1, mid + 1, r, s, e, val);
	t[root].mval = max(t[root * 2].mval, t[root * 2 + 1].mval) + t[root].upd;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1 ; i <= m ; ++i){
	int l, r;
	ll w;
	cin >> l >> r >> w;
	seg[r].push_back(mp(l, w));
}
for(int i = 1 ; i <= n ; ++i){
	update(1, 1, n, i, i, t[1].mval);
	for(vector <pil>::iterator j = seg[i].begin() ; j != seg[i].end() ; ++j){
		pil o = *j;
		update(1, 1, n, o.x, i, o.y);
	}
}
cout << max(0LL, t[1].mval) << endl;

return 0;
}



Measured memory_bytes: 19456
#include <iostream>
#include <stdint.h>
#include <utility>
#include <limits.h>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

using Year = int;
using Line = int;
using PrefId = int;
using CityNumber = int;
using CityId = pair<PrefId,CityNumber>;
using CityMap = map<Year,Line>;
using PrefCityMap = map<PrefId,CityMap*>;
using CityIdMap = map<Line,CityId>;

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

  PrefCityMap pref_city_map; // Npref : MAPcities
  for (int n=1; n<=N; ++n) {
    pref_city_map.emplace(n,new map<int,int>());
  }

  for (int m=0; m<M; ++m) {
    int p, y;
    cin >> p >> y;

    pref_city_map[p]->emplace(y,m);
  }

  vector<CityIdMap*> city_id_maps;
  for (auto& x : pref_city_map) {
    PrefId pref_id = x.first;
    CityMap* city_map = x.second;
    CityIdMap* city_id_map = new CityIdMap;
    CityNumber city_number = 1;
    for (auto& city_info : *city_map) {
      Year year = city_info.first;
      Line line = city_info.second;
      city_id_map->emplace(line,make_pair(pref_id,city_number++));
    }
    city_id_maps.push_back(city_id_map);
  }

  CityIdMap city_id_map;
  for (auto x: city_id_maps)
    city_id_map.insert(x->begin(),x->end());

  for (auto x: city_id_map) {
    cout << setw(6) << setfill('0') << x.second.first;
    cout << setw(6) << setfill('0') << x.second.second << endl;
  }
  
  return 0;
}

Measured memory_bytes: 38260
#include <stdio.h>
#define MAX 1000000
int A[MAX];

int partition(int A[],int p,int r){
    int t,i,j;
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j] <= A[r]){
            i++;
            t=A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t=A[r];A[r]=A[i+1];A[i+1]=t;
    return i+1;
}

void quicksort(int 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);
    }
}

int main(void){
    int num,kazu,map[1000],sum,i;
    while(1){
        sum=0;
        scanf("%d %d",&num,&kazu);
        if(num == 0)
            break;
        for(i=0;i<num;i++){
            scanf("%d",&map[i]);
        }
        quicksort(map,0,num-1);
        for(i=num-kazu;i>=0;i-=kazu)
            map[i]=0;
        for(i=0;i<num;i++)
            sum+=map[i];
        printf("%d\n",sum);
    }
    return 0;
}

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

int main(int argc, char const *argv[]) {
    string n;
    cin >> n;

    string out = "No";
    for (size_t i = 0; i < 3; i++) {
        if (n[i] == '7') {
            out = "Yes";
        }
    }

    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3584
// original submission at https://atcoder.jp/contests/agc032/submissions/4676204
// authored by abc050
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef struct {
	int N;
	int *u;
	int *u_size;
}union_find;

union_find *make_union_find(int N){
	int i;
	union_find *uf = (union_find *)malloc(sizeof(union_find));
	uf->N = N;
	uf->u = (int *)malloc(sizeof(int) * N);
	uf->u_size = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		uf->u[i] = i;
		uf->u_size[i] = 1;
	}
	return uf;
}

int root_uf(int x, union_find *uf){
	int *u = uf->u;
	if(u[x] == x){
		return x;
	}
	else{
		u[x] = root_uf(u[x], uf);
		return u[x];
	}
}

void combine_uf(int x, int y, union_find *uf){
	int x_root = root_uf(x, uf);
	int y_root = root_uf(y, uf);
	int *u = uf->u;
	int *u_size = uf->u_size;
	if(x_root == y_root){
		return;
	}
	else if(u_size[x_root] < u_size[y_root]){
		u[x_root] = y_root;
		u_size[y_root] += u_size[x_root];
		u_size[x_root] = 0;
	}
	else{
		u[y_root] = x_root;
		u_size[x_root] += u_size[y_root];
		u_size[y_root] = 0;
	}
}

//xとyが同じ集合に属していれば1を,そうでなければ0を返す
int is_same_union_uf(int x, int y, union_find *uf){
	if(root_uf(x, uf) == root_uf(y, uf)){
		return 1;
	}
	else{
		return 0;
	}
}

//xが属する集合の要素数を返す
int size_uf(int x, union_find *uf){
	return uf->u_size[root_uf(x, uf)];
}

int main(){
	int N, M, i, j, k;
	scanf("%d%d", &N, &M);
	int *num = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		num[i] = 0;
	}
	int *a = (int *)malloc(sizeof(int) * M);
	int *b = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		num[a[i]]++;
		num[b[i]]++;
	}
	int count = 0;
	for(i = 0; i < N; i++){
		if(num[i] % 2 == 1){
			printf("No\n");
			return 0;
		}
		if(num[i] == 4){
			count++;
		}
	}
	for(i = 0; i < N; i++){
		if(num[i] >= 6){
			printf("Yes\n");
			return 0;
		}
	}
	if(count >= 3){
		printf("Yes\n");
		return 0;
	}
	if(count != 2){
		printf("No\n");
		return 0;
	}
	int **es = (int **)malloc(sizeof(int *) * N);
	int *now = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		es[i] = (int *)malloc(sizeof(int) * 4);
		now[i] = 0;
	}
	for(i = 0; i < M; i++){
		es[a[i]][now[a[i]]] = b[i];
		now[a[i]]++;
		es[b[i]][now[b[i]]] = a[i];
		now[b[i]]++;
	}

	union_find *uf = make_union_find(N);
	for(i = 0; i < M; i++){
		if(num[a[i]] < 4 && num[b[i]] < 4){
			combine_uf(a[i], b[i], uf);
		}
	}
	for(i = 0; i < N; i++){
		if(num[i] == 4){
			for(j = 0; j < 4; j++){
				for(k = j + 1; k < 4; k++){
					if(is_same_union_uf(es[i][j], es[i][k], uf) == 1){
						printf("Yes\n");
						return 0;
					}
				}
			}
		}
	}
	printf("No\n");

/*	srand(time(NULL));
	if(rand() % 2 == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
*/	return 0;
}


Measured memory_bytes: 6400
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(now, ContestType):
  res = c[ContestType] * (now - LastDay[ContestType])
  return res

def nasu(now, x, y, z):
  res = 0
  res += s[now-1][x]
  res += s[now][y]
  res += s[now+1][z]
  if x == y == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == y:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * ((D - LastDay[z]) * c[z])
  elif y == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (2 * c[z])
  else:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * ((D - LastDay[z]) * c[z])
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]

LastDay = [0]*26
for i in range(1,D+1-3):
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(i, x, y, z)
        if tmp[1] < score:
          tmp = [x, score]
  LastDay[x] = i
  print(tmp[0]+1)
else:
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(i, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  for i in tmp[0]:
    print(i+1)

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

const int MAX = 1e5 + 5;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

using ll = long long;

bool check (vector<int> &a, vector<int> &b, ll k, ll x) {
    for (int i = 0; i < (int) a.size(); i++) {
        ll u = a[i], v = b[i];
        if (u * v > x) {
            k -= u - x / v;
        }
    }
    return k >= 0;
}

int main() {
    int n;
    ll k;
    scanf("%d %lld", &n, &k);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }
    sort(a.rbegin(), a.rend());
    sort(b.begin(), b.end());

    ll lo = 0, hi = 1e15, ans = 0;
    while (lo <= hi) {
        ll mid = (lo + hi) / 2;
        if (check(a, b, k, mid)) {
            ans = mid;
            hi = mid - 1;
        }
        else {
            lo = mid + 1;
        }
    }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long int a[10000005]={0};
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);
    // long double ans=0;   
	ll n,ans=0;
	string s;
	cin>>n;
	for(int i=0;i<10000002;i++)
		a[i]=0;
	for(int i=1;i<=sqrt(n);i++)
	{
		for(int j=i;j<=n;j+=i)
		{
			if(i!=1 && i!=j && i*sqrt(n)<j)
			{
				a[j]+=2;
			}
			else
				a[j]++;
		}
	}
	for(int i=sqrt(n)+1;i<=n;i++)
		a[i]++;
	for(int i=1;i<=n;i++)
	{
		// cout<<a[i]<<" ";
		ans+=i*a[i];
	}
	cout<<ll(ans)<<endl;
	return 0;
}

Measured memory_bytes: 81700
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T> inline T gcd(T&a,T&b){return b==0?a:gcd(b,a%b);}
template<typename T> inline T lcm(T&a,T&b){return a/gcd(a,b)*b;}
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
char s[100000];
string T="";
int main(){
    scanf("%s",s+1);
    int len=strlen(s+1);
    for (int i=1;i<=len;i++){
        if (i&1) T=T+s[i];
    }
    cout<<T<<endl;
    return 0;
}


Measured memory_bytes: 576
if __name__ == '__main__':
    n, k = map(int, input().split())
    if k % 2 == 1:
        base = n // k
        if base == 0:
            print(0)
        else:
            print(base ** 3)
    else:
        ans = 0
        base = n // k
        if base != 0:
            ans += base ** 3

        base = n // (k // 2)
        if base % 2 == 0:
            base = base // 2
        else:
            base = (base + 1) // 2

        ans += base ** 3

        print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	ll n;
	cin >> n;
	int t;
	int maxi = -9999999;
	int mini = 9999999;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		cin >> t;
		maxi = max(maxi,t);
		mini = min(mini,t);
		sum += t;
	}
	cout << mini << " " << maxi << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3108
s = input()
n = len(s)


def dfs(i, s_str, sum):
    if i == n - 1:
        if sum == 7:
            print(s_str + '=7')
            exit()

    else:
        dfs(i+1, s_str + '+' + s[i+1], sum + int(s[i+1]))
        dfs(i+1, s_str + '-' + s[i+1], sum - int(s[i+1]))


dfs(0, s[0], int(s[0]))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int A[4][4];
int B[4][4];
int N;

bool Bingo()
{
	int Sum = 0;
	for(int i=1; i<=3; i++)
	{
		Sum = 0;
		for(int j=1; j<=3; j++)
		{
			if(B[i][j] == 1)
			{
				Sum++;
			}
		}
		if(Sum == 3)
		{
			return true;
		}
	}
	for(int i=1; i<=3; i++)
	{
		Sum = 0;
		for(int j=1; j<=3; j++)
		{
			if(B[j][i] == 1)
			{
				Sum++;
			}
		}
		if(Sum == 3)
		{
			return true;
		}
	}
	Sum = B[1][1] + B[2][2] + B[3][3];
	if(Sum == 3)
	{
		return true;
	}
	Sum = B[1][3] + B[2][2] + B[3][1];
	if(Sum == 3)
	{
		return true;
	}
	return false;
} 

void TF(int Temp)
{
	for(int i=1; i<=3; i++)
	{
		for(int j=1; j<=3; j++)
		{
			if(A[i][j] == Temp)
			{
				B[i][j] = 1;
			}
		}
	}
}

int main()
{
	for(int i=1; i<=3; i++)
	{
		for(int j=1; j<=3; j++)
		{
			scanf("%d", &A[i][j]);
		}
	}
	scanf("%d", &N);
	int Temp;
	for(int i=1; i<=N; i++)
	{
		scanf("%d", &Temp);
		TF(Temp);
	}
	if(Bingo())
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

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

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var N = long.Parse(Read());
            Console.WriteLine(N % DigitsSum(N) == 0 ? "Yes" : "No");
        }

        public static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0)
                throw new Exception("0未満");

            if (start > stop || (start == 0 && stop == 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        public static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        public static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        public static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IList<int> ReadIntInputs()
        {
            return Read().Split(' ').Select(int.Parse).ToList();
        }

        public static int ReadInt()
        {
            return int.Parse(Read());
        }

        public static IList<string> ReadInputs()
        {
            return Read().Split(' ').ToList();
        }
    }
}

Measured memory_bytes: 11348
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());
    let n = scan.next::<i32>();
    for i in 1..n+1 {
        let mut x = i;
        if x % 3 == 0 {
            write!(out, " {}", i).ok();
            continue;
        }
        while x > 0 {
            if x % 10 == 3 {
                write!(out, " {}", i).ok();
                break;
            }
            x /= 10;
        }
    }
    writeln!(out).ok();
}



Measured memory_bytes: 5036
import Control.Monad
import Data.List
import Data.Char

main = do
    s <- getLine
    solve $ map length (group s)

solve [] = putStrLn ""
solve (r : l : rls) = do
    when (r >= 1) $ replicateM_ (r - 1) (putStr "0 ")
    putStr . show $ ((r + 1) `div` 2) + (l `div` 2)
    putChar ' '
    putStr . show $ (r `div` 2) + ((l + 1) `div` 2)
    when (l >= 1) $ replicateM_ (l - 1) (putStr " 0")
    unless (null rls) $ putChar ' '
    solve rls

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

class UnionFind
{
  public:
    vector<int> root;
    vector<int> rank;

    UnionFind() {}

    UnionFind(int n)
    {
        for (auto i = 0; i < n; i++)
        {
            root.push_back(i);
            rank.push_back(1);
        }
    }

    int find(int a)
    {
        if (root[a] == a)
        {
            return a;
        }
        else
        {
            return root[a] = find(root[a]);
        }
    }

    bool same(int a, int b)
    {
        if (find(a) == find(b))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    void unite(int a, int b)
    {
        int ra, rb, raa, rab;
        ra = find(a);
        rb = find(b);
        raa = rank[ra];
        rab = rank[rb];

        if (same(a, b))
        {
            return;
        }
        else
        {
            if (raa < rab)
            {
                root[ra] = root[rb];
            }
            else if (raa > rab)
            {
                root[rb] = root[ra];
            }
            else
            {
                root[rb] = root[ra];
                rank[ra] = rank[a] + 1;
            }
        }
    }
};

int main()
{
    int n, m, num = 0;
    cin >> n >> m;
    int p[n];

    for (auto i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    UnionFind uf(n);

    for (auto i = 0; i < m; i++)
    {
        int x1, x2;
        cin >> x1 >> x2;
        uf.unite(x1 - 1, x2 - 1);
    }

    for (auto i = 0; i < n; i++)
    {
        if (uf.same(p[i] - 1, i))
        {
            num++;
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 1660
using System;
using System.Linq;
class Program
{
    public static void Main()
    {
        var acgt = new char[] { 'A', 'C', 'G', 'T' };
        var str = Console.ReadLine();
        var len = 0;
        for (int i = 0; i < str.Length; i++)
        {
            var begin = str.IndexOfAny(acgt, i);
            if(begin == -1)
            {
                break;
            }
            i = begin;
            while(i < str.Length)
            {
                if(!acgt.Any(c => c == str[i]))
                {
                    len = Math.Max(len, i - begin);
                    break;
                }
                i++;
            }
            if(i == str.Length)
            {
                len = Math.Max(len, i - begin);
            }
        }
        Console.WriteLine("{0}", len);
    }
}


Measured memory_bytes: 13268
n = int(input())
s = str(n)
len_s = len(s)

dp = [[0]*(len_s+1) for i in range(2)]

dp[0][1] = int(s[0])
dp[1][1] = int(s[0]) - 1

for i in range(1, len_s):
    for num in range(int(s[i]) + 1):
        dp[0][i+1] = max(dp[0][i+1], dp[0][i] + num)
        
    for num in range(int(s[i])):
        dp[1][i+1] = max(dp[1][i+1], dp[0][i] + num)
    
    for num in range(10):
        dp[1][i+1] = max(dp[1][i+1], dp[1][i] + num)

print(max(dp[0][len_s], dp[1][len_s]))

Measured memory_bytes: 38384
package main

import  "fmt"

func main() {
    var n, m, x, y int
    fmt.Scan(&n)
    fmt.Scan(&m)
    fmt.Scan(&x)
    fmt.Scan(&y)
    xMax := x
    yMin := y
    var tmp int
    for i := 0; i < n; i++ {
        fmt.Scan(&tmp)
        if xMax < tmp {
            xMax = tmp
        }
    }

    for i := 0; i < m; i++ {
        fmt.Scan(&tmp)
        if yMin > tmp {
            yMin =tmp
        }
    }
    if xMax < yMin {
        fmt.Println("No War")
    } else {
        fmt.Println("War")
    }
}

Measured memory_bytes: 512
k=gets.to_i

a=Array.new(k)
a[0]=7%k

1.upto(k-1) do |i|
    a[i]=(a[i-1]*10+7)%k
end

k.times do |i|
    if a[i]==0
        puts i+1
        return
    end
end

puts "-1"


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
    i64 sum = 0;
    rep(i, N) sum += A[i];
    i64 cnt = 0;
    rep(i, N) if(A[i] * 4 * M >= sum) cnt++;
    if(cnt >= M) cout << YES << endl;
    else cout << NO << endl;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	int num[100];
	int key;
	
	int count = 0;
	
	int i,j;
	//Input N
	scanf("%d",&N);
	
	//Input Numbers
	for(i = 0;i < N;i++){
		scanf("%d",&num[i]);
	}
	
	//Bubble Sort
	for(i = 0;i < N-1;i++){
		for(j = N-1;j > i;j--){
			if(num[j] < num[j-1]){
				key = num[j];
				num[j] = num[j-1];
				num[j-1] = key;
				count++;
			}
		}
	}
	
	//Display Numbers
	for(i = 0;i < N;i++){
		printf("%d",num[i]);
		if(i < N-1){
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n",count);
return 0;
}

Measured memory_bytes: 604
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = ~~arg[0].split(" ")[0];
    const B = ~~arg[0].split(" ")[1];
    const C = ~~arg[0].split(" ")[2];
    const D = ~~arg[0].split(" ")[3];
    
    const X = C - A;
    const Y = D - B;

    console.log((C - Y) + " " + (D + X) + " " + (A - Y) + " " + (B + X));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
N=int(input())
A=[]
for i in range(N):
  x,y=map(int,input().split())
  A.append((x,y))
if N==1:
  print(1)
  exit()
ans=10000000
for k in range(N):
  for j in range(k):
    p=A[k][0]-A[j][0]
    q=A[k][1]-A[j][1]
    c=0
    for s in range(N):
      flag=False
      for t in range(N):
        if A[s][0]-p==A[t][0] and A[s][1]-q==A[t][1]:
          flag=True 
          break
      if not flag:
        c+=1
    ans=min(c,ans)
print(ans)

Measured memory_bytes: 43116
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    w, h,n = map(int, input().split())
    ans = []

    for i in range(h):
        s = [1]*w
        ans.append(s)
    for i in range(n):
        a, b, c = map(int, input().split())
        if c == 1:
           for j in range(0,h):
               for k in range(0,a):
                   ans[j][k] =0
        if c == 2:
           for j in range(0,h):
               for k in range(a,w):
                   ans[j][k] =0
        if c == 3:
           for j in range(0,b):
               for k in range(0,w):
                   ans[j][k] =0
        if c == 4:
           for j in range(b,h):
               for k in range(0,w):
                   ans[j][k] =0

    s = 0
    for  i in ans:
        for j in i:
            s += j

    print(s)


Measured memory_bytes: 5144
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 2 == 0) {
            System.out.println(n);
        } else {
            System.out.println(n*2);
        }
    }
}


Measured memory_bytes: 23892
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof i);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) (x&-x)
#define siz(v) (long long)v.size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

int main() {
    EmiliaMyWife

    ll a, b, ans=0;
    cin >> a >> b;
    for(ll i = a; i<=b; i*=2) {
        ans++;
    }
    cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
	char S[6];
	int cnt;
	int Accepted = 0;

	for (cnt = 0;cnt <= 5;cnt++)
	{
		scanf("%c",&S[cnt]);
	}

	for (cnt = 0;cnt <= 5;cnt++)
	{
		if (S[cnt] == '1')
		{
			Accepted++;
		}
	}

	printf("%d",Accepted);
}

Measured memory_bytes: 128
package main
 
import (
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"os"
)
 
func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}
 
func readInt(sc *bufio.Scanner) (res int) {
	res, _ =strconv.Atoi(readLine(sc))
	return
}
 
func readInts(sc *bufio.Scanner, n int) []int {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int, n)
 
	for i, n := range ns {
		res[i], _ = strconv.Atoi(n)
	}
	return res
}
 
func readInt64s(sc *bufio.Scanner, n int) []int64 {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int64, n)
 
	for i, n := range ns {
		res[i], _ = strconv.ParseInt(n, 10, 64)
	}
	return res
}
 
func readMatrix(sc *bufio.Scanner, rows, cols int) [][]int {
	res := make([][]int, rows)
	for i := 0; i < rows; i ++ {
		res[i] = readInts(sc, cols)
	}
	return res
}
 
func abs(i int) int {
	if i < 0 {
		return -i
	} else {
		return i
	}
}
 
func main() {
	sc := bufio.NewScanner(os.Stdin)
 
	xs := readInts(sc, 2)
	n := xs[0]
	m := xs[1]
 
	students := readMatrix(sc, n, 2)
	points := readMatrix(sc, m, 2)
 
	for _, s := range students {
		x := s[0]
		y := s[1]
 
		min_i := -1
		min := 1000000000
		for j := len(points) - 1; j >= 0; j-- {
			u := points[j][0]
			v := points[j][1]
 
			d := abs(u - x) + abs(v - y)
			if d <= min {
				min_i = j
				min = d
			}
		}
 
		fmt.Println(min_i + 1)
	}
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main(void){
  struct place{
    char x,y,dir;
  } now;
  unsigned int m,n;
  int k;
  char input[32],command[16];

  while(scanf("%u%u%*c",&m,&n) && m && n){
    now=(struct place){1,1,0};
    
    while(scanf("%31[^\n]%*c",input) && strcmp(input,"STOP")){
      if(!strcmp(input,"RIGHT")){
	now.dir+=1;
	now.dir%=4;
	continue;
      }else if(!strcmp(input,"LEFT")){
	now.dir+=3;
	now.dir%=4;
	continue;
      }
      sscanf(input,"%15s%d",command,&k);
      if(!strcmp(command,"BACKWARD")) k*=-1;
      if(now.dir%2){
	k*=(now.dir==3)?-1:1;
	now.x+=k;
	if(now.x<1) now.x=1;
	else if(now.x>m) now.x=m;
      }else{
	k*=(now.dir==2)?-1:1;
	now.y+=k;
	if(now.y<1) now.y=1;
	else if(now.y>n) now.y=n;
      }
    }
    printf("%d %d\n",now.x,now.y);
  }
  return 0;
}

Measured memory_bytes: 612
// In The Namw Of Allah
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;
typedef pair <int, int> pii;
typedef long long ll;

set <int> s[N];
int n, m;
vector <pii> e;
bool ok[N];

void solve (int t) {
	s[t].insert(t);
	for (int i = m - 1; ~i; i--) {
		int v = e[i].first, u = e[i].second;
		if(s[t].find(v) != s[t].end()) {
			if(s[t].find(u) != s[t].end()) {
				ok[t] = false;
				return;
			}
			else {
				s[t].insert(u);
			}
		}
		else {
			if(s[t].find(u) != s[t].end()) {
				s[t].insert(v);	
			}
		}
	}
	ok[t] = true;
}

bool find_ans(int i, int j) {
	for (auto v : s[i]) {
		if(s[j].find(v) != s[j].end())
			return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		e.push_back({u, v});
	}
	for (int i = 0; i < n; i++)
		solve(i);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if(ok[i] & ok[j]) {
				ans += find_ans(i, j);
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 11124
N = int(input())
H = list(map(int, input().split()))
dp = [0]*N
for i in range(1, N):
    if i > 1:
        dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]))
    else:
        dp[i] = dp[i-1] + abs(H[i]-H[i-1])
print(dp[N-1])


Measured memory_bytes: 20684
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;

inline void make_top3(vector<int> &top3, int height) {
    for (auto it = top3.begin(); it != top3.end(); it++) {
        if (height > *it) {
            it = top3.insert(it, height);
            if (top3.size() > 3)
                top3.pop_back();
            return;
        }
    }
    if (top3.size() < 3)
        top3.push_back(height);
    return;
}

int main()
{
    int height;
    vector<int> top3;

    while (cin >> height)
        make_top3(top3, height);

    for (auto h: top3)
        cout << h << endl;

    return 0;
}

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

using ll = long long;

ll n, m, vis[100005], a, b, c;

bool flag;

vector<ll> adj[100005];
 
void dfs (ll cur) {
	for(auto nxt : adj[cur]) {
		if(!vis[nxt]) {vis[nxt] = 3-vis[cur]; dfs(nxt);}
		else if(vis[nxt] == vis[cur]) flag = true;
	}
}
 
int main()
{
    
    cin >> n >> m;
    
	for(int i=1;i<=m;i++) {
		ll A, B;
		cin >> A >> B;
		
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	
	for(int i=1;i<=n;i++) {
	    
		if(vis[i]) continue;
		
		if(adj[i].size() == 0) c++;
		
		else {
			flag = false;
			vis[i] = 1;
			dfs(i);
			flag ? b++ : a++;
		}
		
	}
	cout << c*c + c*(n-c)*2 + a*a*2 + a*b*2 + b*b << endl;
	
}

Measured memory_bytes: 12416
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
string in[9]={
	"\',.!?",
	"abcABC",
	"defDEF",
	"ghiGHI",
	"jklJKL",
	"mnoMNO",
	"pqrsPQRS",
	"tuvTUV",
	"wxyzWXYZ",
};
int main(){
	string s;
	while(cin>>s){
		rep(i,s.size()-1){if(s[i]!=s[i+1]&&s[i]!='0'&&s[i+1]!='0')s=s.substr(0,i+1)+"0"+s.substr(i+1);}
		if(s[s.size()-1]!='0')s+="0";
		s="0"+s;
		rep(i,s.size()){
			if(i+1==s.size())break;
			if(s[i+1]=='0'){cout<<" ";continue;}
			i++;
			int co=0;
			char tmp=s[i];
			while(s[i]==tmp){co++;i++;}
			int d=tmp-'1';
			co--;
			cout<<in[d][co%in[d].size()];
			i--;
		}
		cout<<endl;
	}
}

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

using namespace std;

typedef long long ll;

const int MX = 303;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n, k;
ll mod;
ll f[MX][MX], g[MX][MX], c[MX][MX];

int main()
{
	read(n), read(k), read(mod);
	n++, k++;
	for(int i=0; i<=n; i++)
	{
		c[i][0] = 1;
		for(int j=1; j<=i; j++) c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
	}
	for(int i=1; i<=k; i++) f[1][i] = 1;
	for(int i=1; i<=k; i++) g[1][i] = k-i;
	for(int s=2; s<=n; s++)
	{
		for(int i=k; i>=1; i--)
		{
			for(int t=1; t<s; t++)
				f[s][i] = (f[s][i] + g[s-t][i]*f[t][i]%mod*c[s-2][t-1]) % mod;
			g[s][i] = (g[s][i+1] + f[s][i+1]) % mod;
		}
	}
	printf("%lld\n", f[n][1]);
	return 0;
}


Measured memory_bytes: 2432
s = str(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
if len(s) < 26:
    toappend = ""
    for i in alpha:
        if i not in s:
            toappend = i
            break
    s += toappend
    print(s)
else:
    if s == alpha[::-1]:
        print(-1)
    else:
        s = s[::-1]
        ckd = []
        for i in range(26):
            for j, it in enumerate(ckd):
                if s[i] < it:
                    temp = ckd[j] + s[i+1:]
                    print(temp[::-1])
                    exit()
            ckd.append(s[i])





Measured memory_bytes: 3064
# Wrote in Mar 27, 2020 15:27 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------
loop do
  n,x = inp
  i = 0
  res = []
  if [n,x]==[0,0]
    break
  end
  (1..n).to_a.combination(3).to_a.each{|a,b,c|res.push(a+b+c)}
  puts res.count(x)
end  



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

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

    char a, b;
    cin >> a >> b;
    if (a == 'H') {
        cout << b << endl;
    } else {
        cout << (b == 'H' ? 'D' : 'H') << endl;
    }
}


Measured memory_bytes: 3584
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *
from random import *					# alpha = ascii_lowercase
from sys import stdin
from itertools import *
from collections import Counter			# z = dict(Counter(l))

def jump(l,i,end):
	dp = [0]*len(l)
	if(len(l) == 2):
		return abs(l[0] - l[1])
	dp[1] = abs(l[0] - l[1])
	for i in range(2,len(l)):
		dp[i] = min(abs(l[i] - l[i-2]) + dp[i-2], abs(l[i] - l[i-1]) + dp[i-1])
	return dp[-1]


N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = jump(l,N-1,N-1)
print(ans)

Measured memory_bytes: 15380
#include <iostream>

#include <stdio.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 100;

double calc(const int i, const int n, const int *a) {
    double acc = 1;
    for (int j = 0; j < n; j++) {
        if (j == i) continue;
        acc *= a[j];
    }
    return acc;
}

int main(void) {
    int N;
    int a[MAX_N];
    cin >> N;

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

    double acc = 0;
    for (int i = 0; i < N; i++) {
        acc += calc(i, N, a);
    }

    printf("%9.6f\n", calc(-1, N, a) / acc);
    
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
     cin>>a>>b;
     if(a<=8&&b<=8)Cout("Yay!");
     else Cout(":(");
    
       
return 0;
}


Measured memory_bytes: 256