akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  ll N, K;
  cin >> N >> K;
  vector<Pll> box(0);
  bool flag = false;
  for(int i = 0; i < N; i++){
    ll A;
    cin >> A;
    if(A >= 0) flag = true;
    box.push_back(Pll(abs(A), A));
  }
  sort(ALL(box), greater<Pll>());

  if(N == K){
    ll ans;
    for(int i = 0; i < K; i++){
      if(i == 0) ans = box.at(i).second;
      else ans *= box.at(i).second;
      ans = (ans + MOD) % MOD;
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
    return 0;
  }

  if(!flag && K%2!=0){
    ll ans;
    for(int i = 0; i < K; i++){
      if(i == 0) ans = box.at(N-1-i).second;
      else ans *= box.at(N-1-i).second;
      ans = (ans + MOD) % MOD;
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
    return 0;
  }
  ll ans;
  ll counter = 0;
  for(int i = 0; i < K; i++){
    if(box.at(i).second < 0) counter++;
  }
  if(counter%2==0){
    ll ans;
    for(int i = 0; i < K; i++){
      if(i == 0) ans = box.at(i).second;
      else ans *= box.at(i).second;
      ans = (ans + MOD) % MOD;
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
  }
  else{
    vll plus(0), minus(0);
    for(int i = K; i < N; i++){
      if(box.at(i).second < 0) minus.push_back(box.at(i).second);
      else plus.push_back(box.at(i).second);
    }
    sort(ALL(plus), greater<ll>()); sort(ALL(minus));
    ll erase1 = -1, erase2 = -1;
    ll ans1, ans2;
    for(int i = K-1; i >= 0; i--){
      if(box.at(i).second > 0 && sz(minus) > 0 && erase1 == -1){
        ans1 = minus.at(0);
        erase1 = i;
      }
      if(box.at(i).second < 0 && sz(plus) > 0 && erase2 == -1){
        ans2 = plus.at(0);
        erase2 = i;
      }
    }
    for(int i = 0; i < K; i++){
      if(i != erase1){
        ans1 *= box.at(i).second;
        ans1 = (ans1 + MOD) % MOD;
      }
      if(i != erase2){
        ans2 *= box.at(i).second;
        ans2 = (ans2 + MOD) % MOD;
      }
    }
    ll ans;
    if(erase1 == -1) ans = ans2;
    else if(erase2 == -1) ans = ans1;
    else{
      if(minus.at(0) * box.at(erase2).second > plus.at(0) * box.at(erase1).second) ans = ans1;
      else ans = ans2;
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
  }
}


Measured memory_bytes: 7432
#include <stdio.h>

int main() {
	int i, j, n, m, c, count = 0;
	int b[20], a[21][21];

	scanf("%d %d %d", &n, &m, &c);

	for (i = 0; i < m; i++) scanf("%d", &b[i]);

	for (j = 0; j < n; j++) {
		for (i = 0; i < m; i++) {
			scanf("%d", &a[j][i]);
		}
		a[j][20] = 0;
	}

	for (j = 0; j < n; j++) {
		for (i = 0; i < m; i++) {
			a[j][20] = a[j][20] + b[i] * a[j][i];
		}
		a[j][20] += c;
		if (a[j][20] > 0) count++;
	}

	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;


int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> point(N);
    set<pair<int, int>> points;
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        point[i] = {x, y};
        points.insert(point[i]);
    }

    sort(point.begin(), point.end(), [](auto &left, auto &right) {
            if(left.first == right.first)
                return left.second > right.second;
             return left.first > right.first;
    });

    map<pair<int, int>, int> m;
    for(int i=0; i< point.size() - 1; ++i) {
        int xa = point[i].first;
        int ya = point[i].second;
        for(int j=i+1; j < point.size(); ++j) {
            int xb = point[j].first;
            int yb = point[j].second;
            pair<int, int> pp = {xa-xb, ya-yb};
            m[pp]++;
        }
    }

    auto max_m = 0;
    auto max_p = 0;
    auto max_q = 0;
    for(auto itr: m) {
        if(max_m < itr.second) {
            max_m = itr.second;
            max_p = itr.first.first;
            max_q = itr.first.second;
        }
    }
    int ret = 0;
    for(int i=0; i<point.size(); ++i) {
        auto p = point[i];
        if(points.count(p) == 0) {
            continue;
        }
        ret++;
        while(points.count(p)) {
            points.erase(p);
            p.first  -= max_p;
            p.second -= max_q;
        }
    }

//    cout << max_p << " " << max_q << endl;
    cout << ret << endl;

    return 0;
}



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


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

using namespace std;

int main(void){
	
	int n;

	while(scanf("%d", &n), n){
		ll p[60]={0};
		bool ans = false;
		vector<int> x[50];
		
		rep(i,60)
			p[i] = (ll)(1)<<i;
		
		rep(i,n){
			int m;
			scanf("%d", &m);
			rep(j,m){
				int t;
				scanf("%d", &t);
				x[t].push_back(i);
			}
		}
		
		reps(i,1,31){
			ll b = 0;
			rep(j,x[i].size())
				b |= p[x[i][j]];
			rep(j, x[i].size())
				p[x[i][j]] = b;
				
			if(b == ((ll)1<<n)-1){
				ans = true;
				printf("%d\n", i);
				break;
			}
		}
		if(!ans){
			puts("-1");
		}
	}
	return 0;
}

Measured memory_bytes: 1224
import math
A,B,H,M = map(int,input().split())
chousinnkakudo = M * 6
tannsinnkakudo = 0.5 * (H * 60 + M)
kakudo = chousinnkakudo - tannsinnkakudo
if kakudo < 0:
    kakudo -= 2 * kakudo
if kakudo > 180:
    kakudo = 360 - kakudo
if kakudo == 180:
    print(A+B)
    exit(0)
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(kakudo))))


Measured memory_bytes: 62260
def main():
    while True:
        n,x = map(int,input().split())
        if n==x==0:
            break
        ans = 0
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        ans+=1
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5596
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


int main(){
    
    ll a,b;cin>>a>>b;
    cout<<a+b/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int a[21212], b[21212];
int main() {
	int n, x, i, j; scanf("%d", &n);
	for (i = 1, j = 1; i <= n; i++, j += (n + 1))a[i] = j;
	for (i = n, j = 1; i >= 1; i--, j += (n + 1))b[i] = j;
	for (i = 1; i <= n; i++) scanf("%d", &x),b[x] += i;
	for (i = 1; i <= n; i++)printf("%d ", a[i]);
	puts("");
	for (i = 1; i <= n; i++)printf("%d ", b[i]);
	return 0;
}

Measured memory_bytes: 640
#include "iostream"
#include "vector"

using namespace std;

int main() {
    long long k, a, b;
    cin >> k >> a >> b;
    long long res = 1;
    if (b - a < 3) return !printf("%lld\n", res + k);
    long long x = min(k, a - 1);
    k -= x;
    res += x;
    res += k / 2 * (b - a);
    if (k & 1) res ++;
    printf("%lld\n", res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int m1,m2,d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1+1==m2 && d2==1) cout << "1" << endl;
  else cout << "0" << endl;
  return 0;
}


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

typedef long long ll;
const int INF = 1e12;

ll f(ll a, ll b, ll m)
{
    ll res = m - a;
    if (res == b) --res;
    return res;
}

bool check(ll m, ll a, ll b)
{
    ll mx = 0;
    if (m == a) return false;

    if (m <= b)
    {
        mx = max((a + 1) * (m - a), (a - 1) * (m - a + 1));
        for (ll x = (m + 1) / 2 - 2; x <= (m + 1) / 2 + 2; ++x)
        {
            mx = max(mx, (m - x) * (x + (x >= a)));
        }

        return mx < a * b;
    }
    else
    {
        //mx = max((a - 1) * f(a - 1, b, m), (a + 1) * f(a + 1, b, m));
        //mx = max(max((b - 1) * f(b - 1, a, m), (b + 1) * f(b + 1, a, m)), mx);
        for (ll x = (m + 1) / 2 - 2; x <= (m + 1) / 2 + 2; ++x)
        {
            if (x <= 0 || x >= m) continue;
            mx = max(mx, (m + 1 - x - (x >= (m - b))) * (x + (x >= a)));
        }

        return mx < a * b;
    }
}

int main()
{

    //freopen("input.txt", "r", stdin);

    int q;
    cin >> q;

    ll a, b, l, r, m;
    ll ans;
    while(q--)
    {
        cin >> a >> b;
        if (a > b) swap(a, b);

        l = a, r = INF;
        ans = 1;
        while(r - l > 1)
        {
            m = (r + l) / 2;
            if (check(m, a, b))
            {
                ans = max(ans, m);
                //cout << ans << '\n';
                l = m;
            }
            else
                r = m;
        }

        cout << ans - 1 << '\n';
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> a = new ArrayList<Integer>(3);
        for(int i = 0; i < 3; i++) {
            a.add(sc.nextInt());
        }
        Collections.sort(a);
        System.out.printf("%d %d %d\n", a.get(0), a.get(1), a.get(2));
        sc.close();
    }
}


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

int main(){
  string w;
  cin>>w;
  map<char,int> A;
  for(char c:w)
    A[c]++;
  for(pair<char,int> i:A)
    if(i.second%2==1){
      cout<<"No"<<endl;
      return 0;
    }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n;
signed main()
{
	scanf("%d",&n);long double ans(((floor(sqrt(n)))*(floor(sqrt(n)))));
	printf("%.0Lf",ans);
	return putchar(10),0;
}

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

#define fr(i, a, b) for (i = a; i < b; i++)
#define fr2(i, b, a) for (i = b; i >= a; i--)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<pair<int, int>>

#define set0(a) memset(a, 0, sizeof(a))
#define setneg(a) memset(a, -1, sizeof(a))
#define setinf(a) memset(a, 126, sizeof(a))

#define N 1000000007
#define PI acos(-1.0)

typedef long long int ll;
typedef unsigned long long ull;

ll Npow(ll x, ll n, ll M = 1000000007)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return Npow((x * x) % M, n / 2, M);
	return (x * Npow((x * x) % M, (n - 1) / 2, M)) % M;
}

template <typename T>
void Nswap(T *a, T *b)
{
	T temp;
	temp = *a;
	*a = *b;
	*b = temp;
	;
}

template <typename T>
void show(T *a, int size)
{
	int i;
	cout << endl;
	fr(i, 0, size)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}

template <typename T>
void show_vector(vector<T> v)
{
	cout << endl;
	int i;
	fr(i, 0, v.size())
	{
		cout << v[i] << " ";
	}
	cout << endl;
}

//GLOBAL

//FUNCTIONS

int main()
{
	ll i, count, j, l, k, ans[600000];
	char curr;
	string s;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> s;
	curr = s[0];
	i = 0;
	ans[0] = 0;
	while (i < s.size())
	{
		curr = s[i];
		i++;
		j = i;
		count = 1;
		while (i < s.size() && s[i] == curr)
		{
			i++;
			count++;
		}
		cerr<<count<<" ";
		if (curr == '<')
		{
			l = 1;
			k=j;
			fr(j, j, k + count)
			{
				ans[j] = l;
				l++;
			}
		}
		else
		{
			if (count > ans[j - 1])
			{
				ans[j - 1] = count;
			}
			l = count - 1;
			k=j;
			fr(j, j, k + count)
			{
				ans[j] = l;
				l--;
			}
		}
	}
	ll rv = 0;
	fr(i, 0, s.size() + 1)
	{
		rv += ans[i];
	}
	cout << rv;
	return 0;
}


Measured memory_bytes: 5404
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp(),reverse=True)
a.append(0)
i=0
ans=[]
while i<n:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Measured memory_bytes: 94428
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main() {
    int s;
    cin >> s;
    int m = 1000010;
    for (int i = 1; i < m; i++) {
        if (s==1||s==2||s==4) {
            cout << i+3 << endl;
            return 0;
        } else if (s % 2 == 1) {
            s = 3*s + 1;
        } else if (s % 2 == 0) {
            s /= 2;
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <vector>
using namespace std;

int main() {
	int r, c;
	(void)scanf("%d %d", &r, &c);
	vector<vector<int> > sp(r, vector<int>(c, 0));
	vector<int> r_sum(r,0);
	vector<int> c_sum(c+1,0);
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			(void)scanf("%d", &sp[i][j]);
		}
	}
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			printf("%d ", sp[i][j]);
			r_sum[i] += sp[i][j];
		}
		printf("%d\n", r_sum[i]);
	}
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < r; j++) {
			c_sum[i] += sp[j][i];
		}
		printf("%d ", c_sum[i]);
	}
	for (int j = 0; j < c; j++) {
		c_sum[c] += c_sum[j];
	}
	printf("%d\n", c_sum[c]);
	return 0;
}


Measured memory_bytes: 2788
#include <bits/stdc++.h>
using namespace std;
long long  n,a,cnt;
int main ()
{
   cin>>a>>n;
if(a>=n)
   return cout<<n/2 , 0;
else
{
    long long b= (n-(a*2))/4;
    cnt=a+b;

}




    return cout<<cnt ,0;
}


Measured memory_bytes: 256
def next(c,y,x):
    ans = []
    if c[y][x+1] == '.':
        ans.append([y,x+1])
    if c[y][x-1] == '.':
        ans.append([y,x-1])
    if c[y+1][x] == '.':
        ans.append([y+1,x])
    if c[y-1][x] == '.':
        ans.append([y-1,x])
    return ans

def bfs(maze,sy,sx,w,h):
    arrival = [[0 for i in range(w+2)]for k in range(h+2)]
    q = [[sy,sx]]
    arrival[q[0][0]][q[0][1]] = 1
	

    while len(q)>0:
        nextcell = next(maze,q[0][0],q[0][1])
        for i in range(len(nextcell)):
            if arrival[nextcell[i][0]][nextcell[i][1]] == 0:
                q.append([nextcell[i][0],nextcell[i][1]])
                arrival[nextcell[i][0]][nextcell[i][1]] = arrival[q[0][0]][q[0][1]] + 1
        q.pop(0)
    return arrival


h,w = map(int,input().split())
s = []
add = ["#" for i in range(w+2)]
s.append(add)
counter = 0
for i in range(h):
    stemp = list(input())
    for k in range(w):
        if stemp[k] == "#":
            counter += 1
    stemp.append("#")
    stemp.insert(0,"#")
    s.append(stemp)
s.append(add)


arrival = bfs(s,1,1,w,h)

if arrival[h][w] == 0:
    print('-1')
else:
    print(h*w-counter-arrival[h][w])

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define PI acos(-1)
using namespace std;
int main()
{
  long long n,m,i,a[10005],sum=0;
  cin>>n>>m;
  for(i=1;i<=m;i++)
  {
      cin>>a[i];
      sum+=a[i];
  }

  if(n>=sum)
    cout<<n-sum<<endl;
  else
    cout<<-1<<endl;

    return 0;




}


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

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.rbegin(), v.rend());

  vector<ll> h;
  for (int i = 0; i < n; i++) {
    if (v[i] == v[i + 1]) {
      h.push_back(v[i]);
      i++;
    }
  }

  if (h.size() < 2) {
    cout << 0 << endl;
    return 0;
  }
  cout << (ll)h[0] * h[1] << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    //const int INF = 1e9;
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> dp(n,0);
    dp[0]=1000;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        rep(j,i){
            chmax(dp[i],dp[j]);
            ll x=dp[j]/a[j];
            ll res=dp[j]+(a[i]-a[j])*x;
            chmax(dp[i],res);
        }
    }
    cout << dp[n-1] << endl;
}




Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] arg){

        Scanner scan =new Scanner(System.in);

        int n=scan.nextInt();
        int x=scan.nextInt();

        int count=1;
        int D=0;
        int l;

        for(int i=0;i<n;i++){

            l=scan.nextInt();
            D=D+l;

            if(D<=x) count=count+1;
        }

        System.out.print(count);

    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
using namespace std;

const long long inf = 1e10;
const long long mod = 1e9+7;

typedef vector<vector<int> > G;
G graph;

int color[100050];

bool dfs(int u, int c){
    color[u] = c;
    for(int i=0; i<graph[u].size(); i++){
        int v = graph[u][i];
        if(color[v] == c){
            return false;
        }
        if(color[v] == 0 && !dfs(v, -c) ){
            return false;
        }
    }   
    return true;
}

int main(void){
    long long n, m;
    cin >> n >> m;
    graph = G(n);
    for(int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long B=0, W=0;
    if(dfs(0, 1)){
        for(int i=0; i<n; i++){
            if(color[i] == 1){
                B++;
            }else if(color[i] == -1){
                W++;
            }
        }
        cout << B*W - m << endl;
    }else{
        cout << ( (n*(n-1)) /2) - m << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9300
from fractions import gcd
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
min_A, max_A = min(A), max(A)
g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])
if max_A < K:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE" if K % g == 0 else "IMPOSSIBLE")


Measured memory_bytes: 16284
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const int MAX = 200002;

int N = 0,n = 0;
char a;

int main()
{
    cin>>n;
    cout<<n/3<<endl;;

    return 0;
}


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

DP = [[(0, float('inf'))] * (N+1) for _ in range(N)]

for num in range(1, N+1):
    for start in range(N):
        end = start + num
        if end > N:
            break
        if num == 1:
            DP[start][end] = (A[start], 0) # （大きさ、コスト）
            continue
        for i in range(start + 1, end):
            tmp = DP[start][i][0] + DP[start][i][1] + DP[i][end][0] + DP[i][end][1]
            large = DP[start][i][0] + DP[i][end][0]
            if DP[start][end][1] > tmp:
                DP[start][end] = (large, tmp)
print(DP[0][N][1])


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

using namespace std;
#define int long long
int MOD = 1000000007;

int wa(int a){
    if(a<10) return a;
    else return wa(a/10)+a%10;
}

signed main(){
    int N;
    cin >> N;
    
    int tmp = 0,ans = MOD;
    for(int i=1;i<N;i++){
        tmp = wa(i)+wa(N-i);
        ans = min(ans,tmp);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,s,g,wa=0;
  cin>>a>>b;
  s=b;
  g=a+b-1;
  wa=(a*(2*s+a-1))/2;
  if(s*g<=0){
    cout<<wa;
  }else if(s>0){
    cout<<wa-s;
  }else{
    cout<<wa-g;
  }
}
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi data(n-1);
    bool one = false;
    rep(i,s.size()-1){
        data.at(i) = abs((s.at(i)-'0') - (s.at(i+1)-'0'));
        if(data.at(i) == 1) one = true;
    }
    int m = data.size();
    vi cnt(m,0);
    for(int i=1;i<30;i++){
        for(int j=1;j*pow(2,i)<m;j++){
            cnt.at(j*pow(2,i))++;
        }
    }
    vi sum(m,0);
    for(int i=1;i<m;i++){
        sum.at(i) = sum.at(i-1) + cnt.at(i);
    }
    int tmp = 0;
    rep(i,m){

        tmp += data.at(i) * (sum.at(m-1) - sum.at(m-1-i) - sum.at(i) == 0) % 2;
        tmp %= 2;
    }
    if(tmp == 1){
        cout << 1 << endl;
        return 0;
    }
    if(one){
        cout << 0 << endl;
        return 0;
    }
    tmp = 0;
    rep(i,m){
        tmp += (data.at(i)/2) * (sum.at(m-1) - sum.at(m-1-i) - sum.at(i) == 0) % 2;
        tmp %= 2;
    }
    if(tmp == 1){
        cout << 2 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 13060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n; cin >> n;
  vector<ll> res(n, 0);
  for(ll i=0; i<n-1; ++i){
    ll x; cin >> x;
    ++res[x-1];
  }
  for(ll x : res) cout << x << endl;
  return 0;
}

Measured memory_bytes: 4852
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
    ll n,k,x,i,j;
    cin>>n>>k;
    list<ll>q;
    q.push_back(k);
    n--;
    j=n;
    i=k;
    while(n--){
        k--;
        q.push_front(k);
    }
    while(j--){
        i++;
        q.push_back(i);
    }
    for(auto it :q)cout<<it<<spc;
}


Measured memory_bytes: 4992
import std;

void calc(long x) {
    foreach (i; -200L..200L) {
        foreach (j; -200L..200L) {
            long y = i^^5 - j^^5;
            if (x == y) {
                writeln(i, " ", j);
                return;
            }
        }
    }
}

void main() {
    long x; scan(x);
    calc(x);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

int n;
int d[3][MAX];
long long dp[3][MAX];
long long m;

int main(){
    cin>>n;
    for(int i=1; i<=n; i++){
        for(int j=0; j<3; j++)
            cin>>d[j][i];
    }
    for(int i=1; i<=n; i++){
        for(int j=0; j<3; j++)
            for(int k=0; k<3; k++){
                if(k!=j)dp[j][i] = max(dp[k][i-1]+d[j][i], dp[j][i]);
                m = max(dp[j][i], m);
            }
    }
    cout<<m<<"\n";
    return 0;
}
/*
3
10 40 70
20 50 80
30 60 90
*/


Measured memory_bytes: 6972
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	l := make([]int, n)
	for i := range l {
		fmt.Scan(&l[i])
	}
	fmt.Println(sunuke(k, l))
}

func sunuke(k int, l []int) int {
	var s int
	sort.Sort(sort.Reverse(sort.IntSlice(l)))
	for i := 0; i < k; i++ {
		s += l[i]
	}
	return s
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 




int n, x; 


 
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin >> n >> x;

    vector<int> dis(n + 1);
    dis[0] = 0;
    int tmp = 0;
    loop(i , n) {
        cin >> tmp;
        dis[i + 1] = dis[i] + tmp;
    }
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        if (dis[i] <= x) {
            ans++;
        }
    }
    cout << ans << endl;

    


    

 
    
    return 0;
}


Measured memory_bytes: 256
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  for(d<-stdin.getLines.map(_.toInt)) {
    var (j,s) = (0,0)

    while((j-1)*d < 600-d) {
      s += j*j
      j += 1
    }
    b.append(s*d*d*d+"\n")
  }

  print(b.result)
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<int>> vec(n, vector<int>(3, 0));

  rep(i, n-1) {
    rep(j, 3) vec[i+1][j] = vec[i][j];
    *lower_bound(ALL(vec[i+1]), a[i]) += 1;
    sort(ALL(vec[i+1]));
  }
  mint ans = 1;
  rep(i, n) {
    int c = 0;
    rep(j, 3) if(vec[i][j] == a[i]) ++c;
    ans *= c;
  }
  cout << ans.x << endl;
}

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

int main () {
  int N, A, x;
  cin >> N >> A;
  x = N / 500;
  if (N % 500 == 0){
    cout << "Yes" << endl;
  }
  else if (N - (500 * x) <= A){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(X: int, N: int, p: "List[int]"):
    kouho = list((set(v + 1 for v in p) | set(v - 1 for v in p)) - set(p))
    kouho.sort()
    diff = INF
    ans = X
    for v in kouho:
        cdiff = abs(v - X)
        if diff > cdiff:
            diff = cdiff
            ans = v
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	REP(i, n){cin >> h[i];}
	sort(h.begin(), h.end());
	vector<ll> diff(n-k+1);
	REP(i, n-k+1){diff[i] = (h[i+k-1]-h[i]);}
	cout << *min_element(diff.begin(), diff.end()) << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        int n = sc.nextInt();
        int l = sc.nextInt();
        int ans = 0, min = l;
        
        for (int i = 1; i <= n; i ++) {
            int m = l + i - 1;
            ans += m;
            if (Math.abs(m) < Math.abs(min)) {
                min = m;
            }
        }
        ans -= min;

        System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21716
#include <iostream>

int main(){
    int t;
    std::cin >> t;
    if(t == 1){
        std::cout << "Hello World" << std::endl;
    }else{
        int t1, t2;
        std::cin >> t1 >> t2;
        std::cout << t1+t2 << std::endl;
    }
}

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

ll dp[101010][4];
int n;
vector<int> a;
vector<int> b;
vector<int> c;
int x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		a.push_back(x);
		cin >> x;
		b.push_back(x);
		cin >> x;
		c.push_back(x);
	}

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i < n; i++){
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << "\n";
}


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

using LL = long long;

constexpr int MOD = 1e9+7;
constexpr int N = 200005;

LL powmod (LL a, LL b, LL MOD) {
        LL ans = 1;
        while (b) {
                if (a % 2) ans = ans * a % MOD;
                b /= 2;
                a = a * a % MOD;
        }
        return ans % MOD;
}

LL fac[N], inv[N], fnv[N];

LL comb (LL a, LL b) {
        if (a < b) return 0;
        if (b == 0 || b == a) return 1;
        return fac[a] * fnv[b] % MOD * fnv[a-b] % MOD;
}

int main () {
        fac[0] = inv[0] = fnv[0] = 1;
        fac[1] = inv[1] = fnv[1] = 1;
        for (int i = 2; i < N; ++i) {
                fac[i] = fac[i-1] * i % MOD;
                inv[i] = inv[MOD%i] * (MOD-MOD/i) % MOD;
                fnv[i] = fnv[i-1] * inv[i] % MOD;
        }
        int h, w, a, b; cin >> h >> w >> a >> b;
        LL sum = comb (h+w-2, h-1);
        cerr << "sum = " << sum << endl;
        for (int i = 1; i <= min(100000,a); ++i) {
                // (1,1) -> (b,h-i+1)
                LL cur = comb (b-1+h-i, b-1);
                // (b+1,h-i+1) -> (w,h)
                LL lft = comb (w-b-1+h-h+i-1, w-b-1); 
               // cerr << "(" << b << "," << h-i+1 << ")  ->  (" << w << "," << h << ")" << endl;
               // cerr << "i = " << i << ", cur = " << cur << ", lft = " << lft << endl;
                sum = (sum - cur * lft % MOD) % MOD;
                sum = (sum + MOD) % MOD;
        }
        cout << sum << endl;
        return 0;
}

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

using LL = long long;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

	string s; cin >> s;
	int n = s.size(), ans = 0;
	for (int i = 0; i < n / 2; ++i) {
		if (s[i] != s[n - i - 1]) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define HashMap std::unordered_map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm ( A x, B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        String s;
        read s;
        if ( s <= "2019/04/30" ) echo "Heisei" fin;
        else echo "TBD" fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int r, g, b, num;

    cin >> r >> g >> b;

    num = 100*r + 10*g + b;

    if( num%4 == 0 )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
string target="keyence";
int main(void){
    string s;cin>>s;
    rep(i,8){
        string f=s.substr(0,i),l=s.substr(s.size()-(7-i),(7-i));
        //cout<<f<<" "<<l<<endl;
        if(f+l==target){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  vector<int> v;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
  {
    v.push_back(s[i]-48);
  }
  accumulate(v.begin(),v.end(),0) % 9 == 0 ? cout << "Yes" : cout << "No";
  return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> G(N+1);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> ans;
    vector<bool> visited(N+1,false);
    visited[1]=true;
    ans.push_back(1);
    int now=1;
    bool ok=false,once=true;
    while(!ok){
        bool changed=true;
        for (auto v:G[now]){
            if (!visited[v]){
                changed=false;
                visited[v]=true;
                ans.push_back(v);
                now=v;
                break;
            }
        }
        if (once&&changed){
            reverse(ans.begin(),ans.end());
            once=false;
            now=1;
            for (auto v:G[now]){
                if (!visited[v]){
                    changed=false;
                    visited[v]=true;
                    ans.push_back(v);
                    now=v;
                    break;
                }
            }
        }
        if (changed){
            ok=true;
        }
    }
    int s=ans.size();
    cout << s << endl;
    rep(i,s){
        cout << ans[i];
        if (i!=s-1){
            cout << ' ';
        }
        else {
            cout << endl;
        }
    }
}

Measured memory_bytes: 6776
<?php

fscanf(STDIN, "%d %d", $a, $b);

function gcd($a, $b) {
    if ($b === 0) {
        return $a;
    }
    return gcd($b, $a % $b);
}

$gcd = gcd($a, $b);

$cd = [];
for ($i = 1; $i <= sqrt($gcd); ++$i) {
    if ($gcd % $i === 0) {
        $cd[] = $i;
        $cd[] = $gcd / $i;
    }
}

$cd = array_unique($cd);
sort($cd);

$cnt = 0;
foreach ($cd as $val) {
    $flg = true;
    for ($j = 2; $j <= sqrt($val); ++$j) {
        if ($val % $j === 0) {
            $flg = false;
            break;
        }
    }
    $cnt += $flg ? 1 : 0;
}

echo $cnt;


Measured memory_bytes: 4728
// #define _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define reps(i, s, n) for (i64 i = s; i < (i64)(n); ++i)

void solve() {
    string s, t;
    cin >> s >> t;
    i64 ans = 1e9;
    rep(i, s.size() - t.size() + 1) {
        i64 cur = 0;
        rep(j, t.size()) {
            if (s[i + j] != t[j]) {
                cur++;
            }
        }
        ans = min(ans, cur);
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3672
#include<stdio.h>
#include<algorithm>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

ll d[1000][1000];
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n)rep(j,n){
		if(i==j)d[i][j]=0;
		else d[i][j]=-1e18;
	}
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		d[a][b]=c;
	}
	rep(k,n)rep(i,n)rep(j,n)d[i][j]=max(d[i][j],d[i][k]+d[k][j]);
	if(d[0][0]>0)puts("inf");
	else printf("%lld\n",d[0][n-1]);
}


Measured memory_bytes: 8064
N = io.read("*n")
B = {}
for i = 1, N-1 do
    B[i] = io.read("*n")
end

A = {}
for i = 1, N do
    if i == 1 then
        A[i] = B[i]
    elseif i == N then
        A[i] = B[i-1]
    else
        A[i] = math.min(B[i-1], B[i])
    end
end

sum = 0
for i = 1, N do
    sum = sum + A[i]
end
print(sum)

Measured memory_bytes: 376
#include<bits/stdc++.h>
using namespace std;
int main()
{int a[3];int c;
 cin>>a[0]>>a[1]>>a[2];
 c=accumulate(a,a+3,0);
 
if(c>=22)
  cout<<"bust";
else
   cout<<"win";
 
 
 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define pb push_back
#define ll long long
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() 
{
    fast_io();
    int x; cin >> x;
    int dp[x+1] = {0}; dp[0] = 1;
    for (int i = 0; i < x; ++i)
    {
    	if (!dp[i]) continue;

    	for (int j = 100; j <= 105; ++j) 
    	{
    		if (i+j <= x)
    			dp[i+j] = 1;
    	}
    }
    if (dp[x])
    	cout << 1 << endl;
    else
    	cout << 0 << endl;
    return 0;
}

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

int main() {
    int i;
    int a, b, c;
    int n = 0;
    std::cin >> a >> b >> c;
    for (i = 1; n < c; i++) {
        n += a;
        if (i % 7 == 0) {
            n+=b;
        }
    }
    std::cout << i-1 << std::endl;
}



Measured memory_bytes: 3112
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) \
cerr << #v << ": " << (v) << endl

long long dp[2501][51][51];
int a[50], N, A;

long long f(int s, int n, int i) {
    if (i == N)
        return 0;
    if (dp[s][n][i] >= 0)
        return dp[s][n][i];
    int s2 = s + a[i];
    int n2 = n + 1;
    return dp[s][n][i] = f(s, n, i + 1) + f(s2, n2, i + 1) + (s2 % n2 == 0 && s2 / n2 == A);
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> N >> A;
    for (int i = 0; i < N; ++i)
        cin >> a[i];
    cout << f(0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 51072
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    int m;
    vector<int> a;
    int tmp_a;
    int total=0;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        a.push_back(tmp_a);
        total+= tmp_a;
    }

    sort(a.begin(), a.end(), greater<int>());

    if(a[m-1]*(4*m)>=total){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, X, Y; cin >> N >> X >> Y;
  ll c = Y - X + 1;
  ll a = X - 1;
  ll b = N - Y;
  vector<ll> cnt(N);

  for (ll i = 1; i < (c+1) / 2; i++) {
    cnt.at(i) += c;
  }
  if (c % 2 == 0) cnt.at(c/2) += c/2;

  for (ll i = 1; i < a; i++) cnt.at(i) += a - i;
  for (ll i = 1; i < b; i++) cnt.at(i) += b - i;
  // a-c
  for (ll i = 1; i <= a; i++) {
    cnt.at(i) += 1;
    for (ll j = 1; j < (c+1)/2; j++) {
      cnt.at(i+j) += 2;
    }
    if (c % 2 == 0) cnt.at(i + c/2) += 1;
  }
  // b-c
  for (ll i = 1; i <= b; i++) {
    cnt.at(i) += 1;
    for (ll j = 1; j < (c+1)/2; j++) {
      cnt.at(i+j) += 2;
    }
    if (c % 2 == 0) cnt.at(i + c/2) += 1;
  }
  // a-b
  for (ll i = 1; i <= a; i++) {
    for (ll j = 1; j <= b; j++) {
      cnt.at(i+j+1)++;
    }
  }
  for (ll i = 1; i <= N-1; i++) {
    cout << cnt.at(i) << "\n";
  }


  return 0;
}



Measured memory_bytes: 256