akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int M,D;

    cin >> M >> D;


    int ans =0;

    REP(i,1,M+1){
       REP(j,1,D+1){
            int d1,d2;
            if(j>9){
                d1 = j/10;
                d2 = j%10;
                if(i == d1*d2 && d1>=2 && d2 >=2){
                    ans++;
                }
            }
       }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
ll a[200002], s[200002];
 
int main(void) {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        scanf("%lld", a+i);
        if(i == 0) s[i] = a[i];
        else s[i] = s[i-1] + a[i];
    }
 
    sort(s, s+n);
    ll ans = (s[0] == 0) ? 1 : 0, cnt = 1;
    for(int i=1; i<n; i++) {
        if(s[i] == 0) ans++;
        if(s[i] == s[i-1]) {
            cnt++;
        }
        if(s[i] != s[i-1] || (i == n-1 && cnt > 1)){
            ans += cnt * (cnt-1) / 2;
            cnt = 1;
        }
    }

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

Measured memory_bytes: 3328
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
S = list(input())
from collections import Counter

c = Counter(S)
ans = c['R']*c['G']*c['B']

for i in range(1, N):
    for j in range(N):
        first, second, third = j, j+i, j+i*2
        if third>=N:
            break
        if len(set((S[first], S[second], S[third])))==3:
            ans -= 1

print(ans)

Measured memory_bytes: 74544
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
int x[200010],v[200010],a[200010],b[200010],l[200010],r[200010],sum[200010],num[200010],n;
bool cmp1(int i,int j){return x[i]<x[j];}
bool cmp2(int i,int j){return v[a[i]]<v[a[j]];}
void update(int s,int w)
{
	while (s<=n)
	{
		sum[s]=(sum[s]+w)%mo;
		s+=s&(-s);
	}
}
int getsum(int s)
{
	int ans=0;
	while (s)
	{
		ans=(ans+sum[s])%mo;
		s-=s&(-s);
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&v[i]);
		a[i]=b[i]=i;
	}
	sort(a+1,a+n+1,cmp1);sort(b+1,b+n+1,cmp2);
	for (int i=1;i<=n;i++) num[b[i]]=i;
	l[n+1]=2100000000;r[0]=-2100000000;
	for (int i=n;i>=1;i--) l[i]=min(l[i+1],num[i]);
	for (int i=1;i<=n;i++) r[i]=max(r[i-1],num[i]);
	for (int i=1;i<=n;i++)
	{
		int p=(getsum(r[i])+((l[i]==1)?1:(mo-getsum(l[i]-2))))%mo;
		update(r[i],p);
	}
	printf("%d\n",(getsum(n)-getsum(n-1)+mo)%mo);
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c,x = 0,y = 0;
  while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
    if(a*a+b*b == c*c) x++;
    else if(a == b) y++;
  }
  cout <<x<<endl<<y<<endl;
  return 0;
}

Measured memory_bytes: 1208
n = gets.to_i
s = gets.chop.chars
w = Array.new(n, 0)
e = Array.new(n, 0)
for i in 1...n
  w[i] = w[i-1] + (s[i-1] == "E" ? 0 : 1)
  e[n-1-i] = e[n-i] + (s[n-i] == "W" ? 0 : 1)
end
p w.zip(e).map{|x, y| x + y}.min

Measured memory_bytes: 41180
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,a,count = 0;
	cin >> N;
	rep(i,N){
		cin >> a;
		while(a%2!=1){
			a=a/2;
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import sys

a,b,c,x,y=map(int,input().split())
ans=0
ans1=0

if a+b<=c*2:
  while x>0 and y>0:
    ans+=a+b
    x-=1
    y-=1

else:
  if (c*2>a and c*2>b) or (c>=a and x>=y) or (c>=b and y>x):
    while x>0 and y>0:
      ans+=c*2
      x-=1
      y-=1
  else:
    while x>0 or y>0:
      ans1+=c*2
      x-=1
      y-=1
    print(ans1)
    sys.exit()

if x==0:
  while y>0:
    ans+=b
    y-=1

else:
  while x>0:
    ans+=a
    x-=1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int n;
    cin>>n;
    vector<int> c(n,0),s(n,0),f(n,0);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n){
            int sum=0;
            FOR(j,i,n-1){
                if(sum<s[j]){
                    sum+=s[j]-sum;
                    sum+=c[j];
                }
                else if(sum>=s[j]){
                   sum=ceil(sum,f[j])*f[j];
                   sum+=c[j];
                } 
            }  
            cout<<sum<<endl;
    }        
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> t;
  // vlli d(n);
  a = t.size();
  if (t[a - 1] == '?')
  {
    t[a - 1] = 'D';
  }
  repe(i, 0, a - 1)
  {
    if (t[i] == '?' && t[i + 1] == 'P')
    {
      t[i] = 'D';
    }
    else if (t[i - 1] == 'P' && t[i] == '?' && i != 0)
    {
      t[i] = 'D';
    }
    else if (t[i] == '?' && t[i + 1] == 'D')
    {
      t[i] = 'P';
    }
    else if (t[i] == '?' && t[i + 1] == '?')
    {
      if (t[i - 1] == 'P' && i != 0)
      {
        t[i] = 'D';
      }
      else
      {
        t[i] = 'P';
        t[i + 1] = 'D';
      }
    }
  }

  cout << t << endl;
}

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

int main(){
  int n, a, b, sum, ans = 0;
  
  cin >> n >> a >> b;
  
  for ( int i = 1; i <= n; i++ ){
    int x = i;
    sum = 0;
    while ( x > 0){
      sum += x % 10;
      x /= 10;
    }
    
    if ( a <= sum && sum <= b ){
      ans += i;
    }
  }
  
  cout << ans << endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    if(b>c){
        tmp=c;
        c=b;
        b=tmp;
    }
    if(a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2036
#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

    vector<int> a(N);
    REP(i, N){
        cin >> a[i];
    }

    sort(a.rbegin(), a.rend());

    int A = 0, B = 0;
    
    REP(i, N){
        if (i % 2 == 0) 
            A += a[i];  
        else 
            B += a[i];
    }

    cout << A - B << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	final static int[][] serials = { { 18680908, 1868, 9, 8 },
			{ 19120730, 1912, 7, 30 }, { 19261225, 1926, 12, 25 },
			{ 19890108, 1989, 1, 8 } };

	final static String[] eras = { "pre-meiji", "meiji", "taisho", "showa",
			"heisei" };

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringBuilder sb = new StringBuilder();
		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int[] serial = toSerial(line.split(" "));
			String era = "";

			for (int i = 0; i < 5; ++i) {
				if (i < 4) {
					if (serial[0] < serials[i][0]) {
						era = eras[i];
					}
				} else {
					era = eras[i];
				}
				if (!era.isEmpty()) {
					if (i > 0) {
						serial[1] -= serials[i - 1][1] - 1;
						era += String.format(" %d %d %d", serial[1], serial[2],
								serial[3]);
					}
					break;
				}
			}
			sb.append(era + "\n");
		}
		System.out.print(sb.toString());
	}

	static int[] toSerial(String[] units) {
		int y, m, d;
		y = Integer.parseInt(units[0]);
		m = Integer.parseInt(units[1]);
		d = Integer.parseInt(units[2]);
		return new int[] { y * 10000 + m * 100 + d, y, m, d };
	}
}

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

typedef long long ll;

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

	ll l1 = 1;
	ll l0 = 2;
	ll ans = 1;
	for (int i = 2; i <= N; ++i) {
		ans = l1 + l0;
		l0 = l1;
		l1 = ans;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

	int N;

	scanf("%d", &N);

	if (N >= 0) {
		int c = 0;
		ll t = 1;
		ll prev = 1;
		while (prev <= N) {
			t <<= 2;
			prev += t;
			++c;
		}

		ll ans = prev;
		ll d = prev - N;
		ans ^= d & 0x55555555555555;
		ans |= d & 0xAAAAAAAAAAAAAA;

		rep(i, 63) {
			if ((ans >> (62 - i)) & 1) {
				for (; i < 63; ++i) {
					printf("%d", (ans >> (62 - i)) & 1);
				}
				printf("\n");
				return 0;
			}
		}
	}
	else {
		N = -N;
		int c = 0;
		ll t = 2;
		ll prev = 2;
		while (prev <= N) {
			t <<= 2;
			prev += t;
			++c;
		}

		ll ans = prev;
		ll d = prev - N;
		ans |= d & 0x55555555555555;
		ans ^= d & 0xAAAAAAAAAAAAAA;

		rep(i, 63) {
			if ((ans >> (62 - i)) & 1) {
				for (; i < 63; ++i) {
					printf("%d", (ans >> (62 - i)) & 1);
				}
				printf("\n");
				return 0;
			}
		}
	}
	printf("0\n");

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
public class Main{
    public static int calDim(int[][] array,int begX,int begY,int endX, int endY){
        int maxPoo = array[begX][begY];
        int minSur = array[begX-1][begY-1];
        int sum = 0;
        for (int i = begX; i <= endX; i++){
            for (int j = begY; j <= endY;j ++){
                if (array[i][j] > maxPoo) maxPoo = array[i][j];
            }
        }

        for (int i = begX-1; i <= endX+1;i++){
            for (int j = begY-1;j<=endY+1;j++){
                if ((i<=endX) && (i >= begX) && (j <= endY) && (j >= begY)){

                }else{
                    if(array[i][j] < minSur) minSur = array[i][j];
                }
            }
        }
        if (maxPoo >= minSur){
            return 0;
        }else{
            for (int i = begX; i <= endX; i++){
                for (int j = begY; j <= endY;j ++){
                    sum+= minSur - array[i][j];
                }
            }
            return sum;
        }
    }
    public static void main(String[] args){
        BufferedReader br = null;
        try{
            String curr;
            br = new BufferedReader(new InputStreamReader(System.in));
            while(!(curr = br.readLine()).equals("0 0")){
                String[] input = curr.split(" ");
                int d = Integer.parseInt(input[0]);
                int w = Integer.parseInt(input[1]);
                int[][] array = new int[d][w];
                for (int i = 0;i<d;i++){
                    curr = br.readLine();
                    input = curr.split(" ");
                    for (int j = 0; j<w; j++){
                        array[i][j] = Integer.parseInt(input[j]);
                    }
                }      
                int max = 0;
                for (int i = 1;i < d-1;i++){
                    for (int j = 1; j < w-1;j++){
                        for (int x = i; x < d-1;x++){
                            for (int y = j; y < w-1; y++){
                                int temp = calDim(array,i,j,x,y);
                                if (max < temp) max = temp;
                            }
                        }
                    }
                }    
                System.out.println(max); 
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 27212
#include "bits/stdc++.h"

using namespace std;

int N;
vector<int> d(110);

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

    sort(d.begin(), d.end());
    decltype(d)::iterator unique = std::unique(d.begin(), d.end());
    d.erase(unique, d.end());
    cout << d.size() - 1 << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 3e5 + 5;

bool st[N];
int WA[N];

int main() {
    int ac = 0;
    int wa = 0;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int t;
        string s;
        cin >> t >> s;
        if (!st[t]) {
            if (s == "AC") {
                st[t] = true;
                wa += WA[t];
                ac++;
            } else
                WA[t]++;
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <algorithm>
#include <cmath>
#define REP(i,N) for(int i=0;i<N;i++)
using namespace std;
using vi=vector<int>;

int main() {
	int N, M,root;
	cin >> N >> M;
	vi A(N - 1 + M), B(N - 1 + M), visited(N),sorted,sortedinv(N);
	vector<set<int>> from(N),to(N);
	REP(i, N-1+M) {
		cin >> A[i] >> B[i]; A[i]--; B[i]--;
		from[A[i]].insert(B[i]);
		to[B[i]].insert(A[i]);
	}
	REP(i, N) {
		if (to[i].empty()){
			root = i; break;
		}
	}

	function<void(int)> visit = [&](int n) {
		if (visited[n])return;
		visited[n] = 1;
		for (int x : from[n]) {
			visit(x);
		}
		sorted.push_back(n);
	};
	
	visit(root);

	REP(i, N) {
		sortedinv[sorted[i]] = i;
	}
	REP(i, N) {
		if (i == root) {
			cout << 0 << endl;
		}
		else {
			int par = N;
			for (int x : to[i]) {
				par = min(sortedinv[x], par);
			}
			cout << sorted[par]+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 26364
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(12)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

const int MOD=1e9+7;
ll mod_pow(ll a,ll b) {
    if(a==0) return 1;
    a%=MOD;
    ll product=1;
    while(b>0) {
        if(b&1) {
            product*=a;
            product%=MOD;
        }
        a*=a;
        a%=MOD;
        b>>=1;
    }
    return product%MOD;
}
signed main() {
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    map<int,int> c;
    REP(i,n) {
        if(c.find(a[i])==end(c)) c[a[i]]=1;
        else c[a[i]]++;
    }
    if(n%2==1 && c[0]!=1) {
        cout<<0<<endl;
        return 0;
    }
    for(int i=(n%2==0); i<n; i+=2) {
        if(c.find(i)==end(c) || c[i]!=2-(i==0)) {
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<mod_pow(2,n/2)<<endl;
    return 0;
}


Measured memory_bytes: 4992
import sys

n, m = list(map(int, input().split()))
swi = []
for _ in range(m):
    k, *sss = list(map(int, input().split()))
    t = 0
    for s in sss:
        t += 1 << (s - 1)
    swi.append(t)
ppp = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    for s, p in zip(swi, ppp):
        t = i & s
        c = bin(t).count('1') % 2
        if c != p:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		for (int i = 0; i < s.length(); i++) {
			if(i % 2 == 0)
				System.out.print(s.charAt(i));
		}
	}

}

Measured memory_bytes: 30928
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ll n, k;
	cin >> n >> k;
	double sum = 0;
	for (int i = 1; i<=n; i++) {
		double tmp = 1.0 / n;
		int now = i;
		while (now < k) {
			now *= 2;
			tmp /= 2;
		}
		sum += tmp;
	}
	printf("%.12f", sum);
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

int n, a, k, m, g;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> k >> g;

	m = g;

	for(int i = 2; i <= n; ++i)
	{
		cin >> a;
		m = max(m, a);
		g = __gcd(g, a);
	}

	if(k<=m && k%g==0)
		cout << "POSSIBLE";
	else
		cout << "IMPOSSIBLE";
}


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

using namespace std;

vector<int> pre(1000);
vector<int> in(1000);
vector<int> post;
int rootPoint = 0;

int getNext(){
    return pre[rootPoint++];
}

int findInin(int c){
    return distance(in.begin(), find(in.begin(), in.end(), c));
}

void print(){
    for(int i = 0; i < post.size(); i++){
        if(i){
            cout << " ";
        }
        cout << post[i];
    }
    cout << endl;
}

void reconstruction(int l, int r){
    if(l >= r){
        return;
    }
    int root = getNext(); // preorderの次の節店
    int m = findInin(root); // inorderにおけるrootの位置
    reconstruction(l,m);
    reconstruction(m + 1,r);

    post.push_back(root);
}

int main(void){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> pre[i];
    }
    for(int i = 0; i < n; i++){
        cin >> in[i];
    }
    reconstruction(0,n);
    print();
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;



int main() {
    ios_base::sync_with_stdio(false); 

   int a,b;
   cin >> a >> b;
   cout << a*b << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
	int sum = 0;
	int n;
	scanf("%d", &n);
	int i;
	int l, r;
	for ( i = 0; i < n; i++)
	{
		scanf("%d %d", &l, &r);
		sum += r - l + 1;
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N; cin >> N;
    long long int tmp_abs=1e9,ans = 0;
    int num_minus=0;
    for (int i=0;i<N;i++){
        long long int ai; cin >> ai;
        if (ai<0) num_minus++;
        ans+=abs(ai);
        tmp_abs = min(tmp_abs,abs(ai));
    }
    if (num_minus%2==1) ans -= 2*tmp_abs;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x,br = 0;
    cin >> x;
    string s;
    cin >> s;
    for (int i = 0;i < x;i++){
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            br++;
        }
    }
    cout << br << endl;
    return 0;
}


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

//     MLE,TLE魔
//↓↓↓↓↓↓↓↓↓↓↓↓
#define int long long
//↑↑↑↑↑↑↑↑↑↑↑↑
//     MLE,TLE魔
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n, m, x;
int a[105];
signed main() {
	cin >> n >> m >> x;
	rep(i, n) {
		cin >> a[i];
		x += (m - 1) / a[i] + 1;
	}
	cout << x << endl;
	endre;
}

Measured memory_bytes: 256
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

void solve(){
  int n;
  cin >> n;
  vector<vector<int>> g(n + 1);
  vector<vector<ll>> dp (n + 1 , vector<ll> (2 , 1ll));
  function<void(int , int)> Dfs = [&] (int a , int par){
    for (auto x : g[a]){
      if (x != par){
        Dfs (x , a);
        dp[a][0] *= dp[x][1];
        dp[a][0] %= mod;
        dp[a][1] *= (dp[x][0] + dp[x][1]) % mod;
        dp[a][1] %= mod;
      }
    }
  };
  for (int i = 0; i < n - 1; i++){
    int x , y;
    cin >> x >> y;
    g[x].push_back (y);
    g[y].push_back (x);
  }
  Dfs (1 , -1);
  ll ans = dp[1][1] + dp[1][0];
  ans %= mod;
  cout << ans << endl;
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



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

int main() {
    bool num[4] = {};
    for(int i=0; i<4; ++i) {
        int n; cin >> n;
        switch(n) {
            case 1: num[0] = true; break;
            case 9: num[1] = true; break;
            case 7: num[2] = true; break;
            case 4: num[3] = true; break;
        }
    }
    if(num[0] && num[1] && num[2] && num[3]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    for(int i=a; i<=b; i++){
        if(i < a+k && i > b-k){
            cout << i << endl;
        }
        else if(i < a+k){
            cout << i << endl;
        }
        else if(i > b-k){
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
void solve()
{
    long long i,j,a[n],ans=0;
    for (i=0;i<n;i++)
        cin>>a[i];
    for (i=0;i<=n-3;i++)
    {
        vector < long long > b(3);
        for (j=0;j<3;j++)
            b[j]=a[i+j];
        sort(b.begin(),b.end());
        if (b[1]==a[i+1]) ans++;
    }
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

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

int n;
int a[110];
int alice = 0;        
int bob = 0;
    int main() {
    //nを入力
    cin >> n;
    //aを配列に入れ込む作業をn回行なう
    rep(i, n){
        cin >> a[i];
    }
    sort(a, a+n, greater<int>());
    rep(i,n){
        if(i %2 ==0){
            alice += a[i];
        }else{
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Split(' ').Select(double.Parse).ToList();

            var x1 = oneLine[0];
            var y1 = oneLine[1];
            var x2 = oneLine[2];
            var y2 = oneLine[3];

            var xPow = (x1 - x2) * (x1 - x2);
            var yPow = (y1 - y2) * (y1 - y2);

            var distance = Math.Sqrt(xPow + yPow);

            Console.WriteLine(distance.ToString("F4"));

        }
    }
}



Measured memory_bytes: 18384
n = int(input())
arrayB = list(map(int, input().split()))

arrayA = [arrayB[0]]

for k in range(1,n-1):

    if arrayB[k] < arrayB[k-1]:
        arrayA.append(arrayB[k])

    else:
        arrayA.append(arrayB[k-1])

arrayA.append(arrayB[n-2])

print(sum(arrayA))


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

using namespace std;

typedef long long ll;



int main()
{
    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2){
        cout << "-1";
    } else {
        cout << n * (n - 1) / 2 - k << endl;
        for(int i = 2; i <= n; i++){
            cout << 1 << " " << i << endl;
        }
        int temp = (n - 1) * (n - 2) / 2 - k;
        for(int i = 2; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                if (temp){
                    cout << i << " " << j << endl;
                    temp--;
                } else {
                    break;
                }
            }
        }
    }
    return 0;
}


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

const int N = 1e5 + 1, K = 301;

ll dp[K][N];
int a[N];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, k; cin >> n >> m >> k;
  for(int i = 0; i < n; i++) cin >> a[i + 1];
  for(int i = 1; i <= n + 1 - k; i++) dp[1][i] = 1 * a[i];

  // slide minimum
  // 貰うDP
  for(int i = 2; i <= k; i++) {
    deque<int> deq;
    for(int j = max(1, i - m); j <= i - 1; j++) {
      // cerr << " j1 = " << j << endl;
      while(deq.size() && dp[i-1][deq.back()] <= dp[i-1][j]) deq.pop_back();
      deq.emplace_back(j);
    }
    cerr << " i = " << i << endl;
    for(int j = i; j <= n + i - k; j++) {
      if(deq.front() < j - m) deq.pop_front();
      dp[i][j] = dp[i-1][deq.front()] + (ll) i * a[j];
      //
      // cerr << "dp i j  = " << dp[i][j] << endl;
      while(deq.size() && dp[i-1][deq.back()] <= dp[i-1][j]) deq.pop_back();
      deq.emplace_back(j);
    }
  }
  ll ans = 0;
  for(int i = k; i <= n; i++) ans = max(ans, dp[k][i]);
  cout << ans << endl;
}



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

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> b(M);
  for(int i = 0; i < M; i++) cin >> b.at(i);
  vector<vector<int>> a(N,vector<int>(M));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      cin >> a.at(i).at(j);
    }
  }
  int ans=0, sum;
  for(int i = 0; i < N; i++){
    sum=0;
    for(int j = 0; j < M; j++){
      sum += a.at(i).at(j)*b.at(j);
    }
    if(sum+C>0) ans++;
  }
  cout << ans;
}

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

#define N 10000
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int d[N], color[N], p[N];
vector<pair<int, int> > adj[N];
priority_queue<pair<int, int> > PQ;

void dijkstra(int s){
  for(int i = 0 ; i < n ; i++){
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  d[s] = 0;
  PQ.push(make_pair(d[s], s));
  color[s] = GRAY;
  while(!PQ.empty()){
    pair<int, int> f = PQ.top(); PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if( d[u] < f.first * (-1) ) continue;

    for(int j = 0; j < adj[u].size() ; j++){
      int v = adj[u][j].first;
      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][j].second){
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
  for(int i = 0 ; i < n ; i++){
    cout << i <<" "<< (d[i] == INFTY ? -1 : d[i])<<"\n";
  }
}

int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    int u, k, v, c;
    cin >> u >> k;
    for(int j = 0; j < k ; j++){
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }
  dijkstra(0);
}



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

typedef long long ll;

int cnt[26 + 5];

ll C(int m, int n)
{
    ll re = 1;
    for (int i = m; i > m-n; i--) re *= i;
    for (int j = n; j > 1; j--) re /= j;
    return re;
}

int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0);
    
    string s; cin >> s;
    
    ll ans = C(s.length(), 2);
    for (int i = 0; i < s.length(); i++) cnt[ s[i]-'a' ]++;
    
    for (int i = 0; i < 26; i++) ans -= C(cnt[i], 2);
    printf("%lld\n", ++ans);
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];
  int ans = 0;
  rep(i,0,n){
    if(i%2==0&&a[i]%2==1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int h;
       cin>>h;

    priority_queue<long long int>p;

       long long int count = 0;
        p.push(h);

        long long int i=0;
      long long int value = pow(2,i);


       
       while(h!=1)
       {
           value = pow(2,i);
           count+= value;
            i++;
            h=h/2;
       }
        count = count + pow(2,i);
      cout<<count;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		int x = sc.nextInt();
		
		int min = x-k +1 ;
		int max = x+k -1;
		
		
		if (min < -1000000) {
			min  = -1000000 ;
		}
		if (max > 1000000) {
			max = 1000000;
		}
		
		for (int i = min ; i <= max ; i++ ) {
			
			System.out.print(i+" ");
		}
		
	}
}


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

int main(){
  int N;
  cin>>N;
  int T,A;
  cin>>T>>A;
  int H[N];
  REP(i,N){
    cin>>H[i];
  }
  double tmp[N];
  REP(i,N){
    tmp[i]=T-H[i]*0.006-A;
  }
  int ans;
  double alpha=100000;
  REP(i,N){
    if(alpha>abs(tmp[i])){
      alpha=abs(tmp[i]);
      ans=i+1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys

n = int(input())

nodes = [[-1, None, None] for _ in range(n)]

depths = [None for _ in range(n)]

for _ in range(n):
    nid, k, *children = list(map(int, sys.stdin.readline().split()))
    if k > 0:
        nodes[nid][1] = children[0]
    children.append(None)
    for i in range(k):
        cid = children[i]
        nodes[cid][0] = nid
        nodes[cid][2] = children[i+1]

def get_depth(nid):
    if depths[nid] is not None:
        return depths[nid]
    elif nodes[nid][0] == -1:
        depths[nid] = 0
        return 0
    else:
        depths[nid] = get_depth(nodes[nid][0]) + 1
        return depths[nid]
    

def get_children(nid):
    children = []
    cid = nodes[nid][1]
    while cid is not None:
        children.append(cid)
        cid = nodes[cid][2]
    return children

for nid in range(n):
    pid = nodes[nid][0]
    children = get_children(nid)
    depth = get_depth(nid)
    n_type = 'root' if pid == -1 else 'leaf' if len(children) == 0 else 'internal node'

    print('node {}: parent = {}, depth = {}, {}, {}'.format(nid, pid, depth, n_type, children))


Measured memory_bytes: 26508
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  long double l;
  cin >> l;
  l/=3;
  cout << fixed << setprecision(7) << l*l*l;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int abs=0;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      abs++;
    }
  }
  if(abs==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'R') a++;
        else a--;
    }
    puts(a > 0 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_array len read_func = Array.init len (fun _ -> read_func())
let print_int n = Printf.printf "%d\n" n

let () =
  let n = scan_int() in
  let h = scan_array n scan_int in
  let ans =
    let rec loop i curr ret =
      if i = n then ret
      else
        if h.(i-1) >= h.(i) then loop (i+1) (curr+1) (max ret (curr+1))
        else loop (i+1) 0 ret in
    loop 1 0 0 in
  print_int ans

Measured memory_bytes: 5376
#include <iostream>

int main(int argc, const char * argv[]) {
    
    long a, b ;
    
    std::cin >> a >> b ;
    long d = a/b ;
    long
    r = a%b ;
    double f = (double)a/(double)b ;
    printf("%ld %ld %f\n", d, r, f);
    
    return 0;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
inline char nchar() {
	static const int bufl=1<<20;
	static char buf[bufl],*a=NULL,*b=NULL;
	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
	int x=0,f=1;
	char c=nchar();
	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
	return x*f;
}
const int maxn=705;
const int maxx=1500;
int n,m,b[maxn],all=0;
bool f[maxn][maxx];
bool a[maxn][maxn];
namespace graph {
	vector<int> g[maxn];
	int col[maxn],sum;
	inline void add(int x,int y) {
		g[x].push_back(y);
		g[y].push_back(x);
	}
	void dfs(int x,int c) {
		if (col[x]) {
			if (col[x]!=c) puts("-1"),exit(0);
			return;
		}
		col[x]=c;
		sum+=c;
		for (const int &v:g[x]) dfs(v,-c);
	}
	void work() {
		for (int i=1;i<=n;++i) if (!col[i]) {
			sum=0;
			dfs(i,1);
			b[++all]=abs(sum);
		}
	}
}
int main() {
	n=read(),m=read();
	for (int i=1;i<=m;++i) {
		int x=read(),y=read();
		a[x][y]=true;
		a[y][x]=true;
	}
	for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j) if (i!=j && !a[i][j]) {
		graph::add(i,j);
	}
	graph::work();
	f[0][n]=true;
	for (int i=1;i<=all;++i) {
		int x=b[i];
		for (int j=0;j<=n*2;++j) if (j+x<=2*n) f[i][j+x]|=f[i-1][j];
		for (int j=0;j<=n*2;++j) if (j-x>=0) f[i][j-x]|=f[i-1][j];
	}
	int res=INT_MAX;
	for (int i=0;i<=n;++i) if (f[all][n-i] || f[all][n+i]) {
		res=i;
		break;
	}
	int lef=(n+res)/2,rig=n-lef;
	int ans=lef*(lef-1)/2+rig*(rig-1)/2;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <utility> // pairとか
#include <vector>
#include <array>
#include <list>
#include <deque>
#include <map>
#include <algorithm> // sortとか findとか
#include <functional> // algorithmに渡せる関数
#include <cmath>
#include <cstdio>
#include <numeric> // gcd,lcmとか

#define rep(iter, beg, end, step) for (long(iter) = (beg); (iter) < (end); (iter) += (step))

using namespace std;
int main() {
	int N;
	cin >> N;
	if( N < 1000 ) {
		cout << "ABC";
	}else{
		cout << "ABD";
	}
	cout << '\n';
	return 0;
}


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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1;
	// int t; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int inf = 1e16;
int arr[105];
void solve() {
	int mn = inf;
	int n;
	cin >> n;
	int suf = 0;
	for (int i = 1; i <= n; ++i)
		cin >> arr[i], suf += arr[i];
	int pre = 0;
	for (int i = 1; i < n; ++i) {
		pre += arr[i], suf -= arr[i];
		mn = min(mn, llabs(pre - suf));
	}
	cout << mn;
}	
 	

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


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

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

    for (int i = 0; i < N; ++i) cin >> A.at(i);
    for (int i = 0; i < N; ++i) cin >> B.at(i);
    for (int i = 0; i < N-1; ++i) cin >> C.at(i);

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += B.at(i);
    }

    for (int i = 0; i < N-1; ++i) {
        if (A.at(i+1) - A.at(i) == 1) {
            ans += C.at(A.at(i)-1);
        }
    }
    cout << ans << endl;
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

#include <boost/range/algorithm.hpp> // boost::sort(arr)


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

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> pref_year_city;
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    pref_year_city.emplace_back(p, y, i);
  }
  boost::sort(pref_year_city);
  map<int, pair<int, int>> city_pref_cnt;
  int cnt = 0;
  int prev_p = 0;
  for(auto & pyc : pref_year_city) {
    int p, y, c;
    tie(p, y, c) = pyc;
    if (p == prev_p) {
      ++cnt;
    } else {
      cnt = 1;
    }
    prev_p = p;
    city_pref_cnt[c] = make_pair(p, cnt);
  }
  rep(i, m) {
    int p;
    tie(p, cnt) = city_pref_cnt[i];
    cout << setfill('0') << setw(6) << p;
    cout << setfill('0') << setw(6) << cnt << endl;
  }
}


Measured memory_bytes: 8948
N = int(input())
D, X = map(int, input().split())
A = list()
for _ in range(N):
    A.append(int(input()))


def count_days(a,D):
    count = 1
    for d in range(2,D+1):
        if a*(d-1)+1 <= D:
            count+=1
    return count

print(sum([count_days(a,D) for a in A])+X)

Measured memory_bytes: 3060
package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 1000000)
	inn.Split(bufio.ScanWords)
	//prep
    n:=rdll();
    ans:=0;
    for f:=int64(2);int64(f)*int64(f)<=n;f++{
        if(n%f==0){
            cnt:=0;
            for n%f==0{
                cnt++;
                n/=f;
            }
            now:=1;
            for cnt>=now{
                cnt-=now;
                ans++;
                now++;
            }
        }
    }
    if n>1{
        ans++;
    }
    Fprint(out,ans);
}

//-------------------template------------------
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func maxll(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	x, _ = strconv.Atoi(string(inn.Bytes()))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	x, _ = strconv.ParseInt(string(inn.Bytes()), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}



Measured memory_bytes: 1768
main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      putStrLn $ solve n
      main

solve :: Int -> String
solve n = format (findTwin (reverse (getN n primeL)))
  where
    format :: (Int,Int) -> String
    format (a,b) = (show a) ++ " " ++ (show b)

    findTwin :: [Int] -> (Int,Int)
    findTwin (x:y:r)
      | x - y == 2 = (y,x)
      | otherwise = findTwin (y:r)
    getN :: Int -> [Int] -> [Int]
    getN _ [] = []
    getN n (x:xs)
      | x < n = x:(getN n xs)
      | x == n = [x]
      | x > n = []
prime :: Int -> [Int]
prime n = loop [2..n]
  where
    loop :: [Int] -> [Int]
    loop [] = []
    loop (x:xs) = x:(loop (filter (\y -> y `mod` x /= 0) xs))
primeL = prime 10000

Measured memory_bytes: 5552
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
a = list(map(int, input().split()))

#dp[i][j]はa[i]からa[j]が残ってる状態から取った時のX-Y
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]

#forは状態の配列の長さを増やしつつ回す
for gap in range(0, N):
    for left in range(N - gap):
        player = (N-gap-1) % 2
        right = left + gap

        if player == 0:
            if gap == 0:
                dp[left][right] = a[left]
                continue
            dp[left][right] = max(dp[left+1][right] + a[left], dp[left][right-1] + a[right])

        else:
            if gap == 0:
                dp[left][right] = -a[left]
                continue
            dp[left][right] = min(dp[left+1][right] - a[left], dp[left][right-1] - a[right])

print(dp[0][N-1])

Measured memory_bytes: 120028