akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<pair<int, int>> a(1e5 + 1), b(1e5 + 1);
    unordered_set<int> v;
    for (int i = 0; i < 1e5 + 1; i++) {
        a[i].first = 0;
        a[i].second = i;
        b[i].first = 0;
        b[i].second = i;
    }

    for (int i = 0; i < n; i++) {
        int vi;
        cin >> vi;
        v.insert(vi);
        if (i % 2) {
            a[vi].first += 1;
        } else {
            b[vi].first += 1;
        }
    }

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


    if (a[0].second == b[0].second) {
        if (a[1].first < b[1].first) {
            cout << n - a[0].first - b[1].first << endl;
        } else {
            cout << n - a[1].first - b[0].first << endl;
        }
    } else {
        cout << n - a[0].first - b[0].first << endl;
    }

    return 0;
}


Measured memory_bytes: 5924
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long read();
void Add(int &x, int y) { (x += y) > mod ? x -= mod : x; }
int fsp(long long bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = bs * rt % mod;
        bs = bs * bs % mod, p >>= 1;
    }
    return rt;
}
int n, m, res;
long long x, ans;
struct E {
    int u, v, w;
    void init() { u = read(), v = read(), w = read(); }
} e[2003];

bool cmp(E a, E b) { return a.w < b.w; }

int fa[1003];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void init_fa() {
    for (int i = 1; i <= n; ++i) fa[i] = i;
}

long long get_ans(int c) {
    long long rt = 0;
    for (int i = 1; i <= m; ++i) {
        if (find(e[i].u) != find(e[i].v))
            rt += e[i].w, ++c, fa[find(e[i].u)] = find(e[i].v);
        if (c == n - 1) return rt;
    }
    return rt;
}

long long tans[2003];

int main() {
    n = read(), m = read(), x = read();
    for (int i = 1; i <= m; ++i) e[i].init();
    sort(e + 1, e + 1 + m, cmp), init_fa(), ans = get_ans(0);
    if (ans > x) return puts("0"), 0;
    if (ans == x) Add(res, 1ll * (fsp(2, n - 1) - 2) * fsp(2, m - n + 1) % mod);
    int used = n - 1;
    for (int i = 1; i <= m; ++i)
        init_fa(), fa[e[i].u] = fa[e[i].v], tans[i] = get_ans(1) + e[i].w;
    sort(tans + 1, tans + 1 + m);
    for (int i = n; i <= m; ++i)
        if (tans[i] == x) Add(res, fsp(2, m - i + 1));

    printf("%d\n", res);
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
long long read() {
    long long x = 0;
    char c = gc;
    while (!isdigit(c)) c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x;
}

Measured memory_bytes: 256
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

def ibis(H, A, B):
    dp = [max(B) * H] * (H + 1)
    dp[0] = 0
    for h in range(H):
        for n in range(N):
            hp = min(h + A[n], H)
            dp[hp] = min(dp[hp], dp[h] + B[n])
    return dp[H]

print(ibis(H, A, B))

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

struct Pair
{
    int pos;
    int dis;
};

int main() {
    int n, m;
    while(cin >> n >> m && n != 0)
    {
        int last_p = 0;
        Pair set[n];
        for(int i = 0;i<n;i++)
            cin >> set[i].dis >> set[i].pos;
        for(int i = 0; i< n; i++)
            for(int j = i+1; j < n; j++)
            {
                if(set[i].pos < set[j].pos)
                {
                    Pair rem = set[i];
                    set[i] = set[j];
                    set[j] = rem;
                }
            }
        
        for(int i = 0; i<n;i++)
        {
            if(m >= set[i].dis)
                m -= set[i].dis;
            else if(m < set[i].dis)
            {
                set[i].dis -= m;
                m = 0;
                last_p += set[i].dis * set[i].pos;
            }
        }
        cout << last_p << endl;
    }
        
    return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    ll n , a , b ;
    cin >> n >> a >> b ;

    ll s = a + b ;

    ll t = n / s ;
    ll rem = n % s ;

    rem = min ( rem , a ) ;

    ll ans = rem + t*a ;
    cout << ans ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


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

using namespace std;

#define pb push_back

const int maxn = 2e3 + 10;
int n, k, cnt[maxn], l, t, ans;
vector <int> adj[maxn];

void dfs(int v, int par, int he) {
	cnt[he]++;
	if (he == l)
		++t;
	for (auto u: adj[v])
		if (u != par)
			dfs(u, v, he + 1);
	return;
}

int main(){
	cin >> n >> k;
	for (int i = 1, v, u; i < n; ++i) {
		cin >> v >> u;
		adj[--v].pb(--u);
		adj[u].pb(v);
	}
	l = (k + 1) / 2;
	ans = maxn;
	for (int i = 0, mx, sum; i < n; ++i) {
		memset(cnt, 0, sizeof(cnt));
		mx = 0;
		for (auto j: adj[i]) {
			t = 0;
			dfs(j, i, 1);
			mx = max(t, mx);
		}
		sum = 0;
		for (int f = k / 2 + 1; f <= n; ++f)
			sum += cnt[f];
		if (k & 1)
			sum -= mx;
		ans = min(ans, sum);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 2018/8/12
 
 23:05-23:17 anslysis
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N,M;
VI L[MAX_N];

int G;
int uf[MAX_N];
int find(int x) { return x==uf[x]?x:uf[x]=find(uf[x]); }
void unite(int x, int y) {
  int xx=find(x),yy=find(y);
  if(xx!=yy) {
    uf[xx]=yy;
    --G;
  }
}
bool solve() {
  G=N;
  REP(i,N) uf[i]=i;
  REP(i,M) REP(j,SZ(L[i])-1) unite(L[i][j],L[i][j+1]);
//  dump(G);
//  REP(i,N)dump2(i,find(i));
  return G==1;
}

const string yes="YES",no="NO";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>M;
  REP(i,N) {
    int K; cin>>K;
    REP(j,K) {
      int l; cin>>l;
      L[l-1].push_back(i);
    }
  }
  cout<<(solve()?yes:no)<<endl;
  return 0;
}


Measured memory_bytes: 4608
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()
T = S[:N//2]

if T*2 == S:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 5192
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, b, c, d, ans;
  cin >> a >> b >> c >> d;
  cout << max(0, min(b, d) - max(a, c)) << endl;
}


Measured memory_bytes: 256
n = int(input())
p = []
p = list(map(int, input().split()))
cnt = 0
for i in range(1,len(p)-1):
  if p[i] > p[i-1] and p[i] <= p[i+1]:
    cnt += 1
  elif p[i] > p[i+1] and p[i] <= p[i-1]:
    cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, g;
  cin >> n >> g;
  g /= 100;

  vll ps(n), cs(n);
  rep(i,n) {
    cin >> ps[i] >> cs[i];
    cs[i] /= 100;
  }

  ll ans = INF;
  rep(s, 1 << n){
    ll tmp = 0;
    ll scr = 0;
    rep(j, n){
      if((s >> j) & 1) {
        tmp += ps[j];
        scr += (j+1)*ps[j]+cs[j];
      }
    }
    ll cur = n - 1;
    ll curn = 0;
    bool ok = true;
    while(g > scr){
      if(cur < 0){
        ok = false;
        break;
      }
      if((s >> cur) & 1){
        cur--;
        curn = 0;
        continue;
      }
      if(curn == ps[cur]-1){
        cur--;
        tmp += curn-1;
        curn = 0;
      }
      scr += cur + 1;
      curn++;
    }
    tmp += curn;
    if(ok) chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

//K
int main(void) {
	ll N, K;
	cin >> N >> K;
	vector<ll> dp = vector<ll>(K + 1, 1); // 1なら自分が勝つ
	vector<ll> A = vector<ll>(N);
	rep(i, 0, N) cin >> A[i];
	dp[0] = 0;
	rep(i, 1, K + 1) {
		bool isFalse = true;
		rep(j, 0, N) {
			if (i >= A[j] && dp[i - A[j]] == 0) {
				dp[i] = 1;
				isFalse = false;
			}
		}
		if (isFalse)dp[i] = 0;
	}
	cout << (dp[K] ? "First" : "Second") << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
 struct node{
    struct node *r;
    struct node *l;
    struct node *p;
    int key;
};
typedef struct node * Node;
 
Node root;
 
Node TreeM(Node x){
 }
 
Node TreeS(Node udemy, int kee){
    if(udemy == NULL || udemy->key == kee)
        return udemy;
    else if(udemy->key > kee)
        return TreeS(udemy->l, kee);
    else if(udemy->key < kee)
        return TreeS(udemy->r, kee);
}
 
Node TreeSu(Node x){
 }
 
void TreeDe(Node z){
    Node y; 
    Node x;
 }
 
void Inse(int k){
    Node y = NULL;
    Node x = root;
    Node zet;
 
    zet = (Node)malloc(sizeof(struct node));
    zet->key = k;
    zet->l = NULL;
    zet->r = NULL;
 
    while(x != NULL){
        y = x;
        if(zet->key < x->key)
            x = x->l;
        else
            x = x->r;
    }
    zet->p = y;
    if(y == NULL)
        root = zet;
    else if(zet->key < y->key)
        y->l = zet;
    else
        y->r = zet;
 }
 
void ino(Node u){
    if(u->l != NULL)
        ino(u->l);
    printf(" %d",u->key);
    if(u->r != NULL)
        ino(u->r);
}
void pre(Node u){
    printf(" %d",u->key);
    if(u->l != NULL)
        pre(u->l);
    if(u->r != NULL)
        pre(u->r);
}
 
 
int main(){
    int num,j, x;
    char com[20];
    Node t;
    scanf("%d", &num);
    for (j=0;j<num;j++){
        scanf("%s", com);
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            t = TreeS(root, x);
            if ( t != NULL ) printf("yes\n");
            else printf("no\n");
        } else if ( com[0] == 'i' ){
            scanf("%d", &x);
            Inse(x);
        } else if ( com[0] == 'p' ){
            ino(root);
            printf("\n");
            pre(root);
            printf("\n");
        } 
    }
 
    return 0;
}

Measured memory_bytes: 19364
def resolve():
    INF = 1<<60
    H, N = map(int, input().split())
    A, B = [], []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    dp = [[INF]*(H+1) for _ in range(N+1)]
    for i in range(N):
        dp[i][0] = 0
    
    for i in range(N):
        for j in range(H+1):
            if j < A[i]:
                # 体力がマイナスなっても魔法は使用できる
                dp[i + 1][j] = min(dp[i][j], B[i])
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i])

    print(dp[N][H])


if __name__ == "__main__":
    resolve()


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

int n;
map<ll, ll> m;
ll ans, pre;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    m.insert({0, 1});

    for (int i = 0; i < n; i++) {
        int A; cin >> A;
        pre += A;
        ans += m[pre];
        m[pre]++;
    }
    cout << ans;
}


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


const ll INF = 1e15;
int H, N;
vector<int> A, B;


void input() {
    cin >> H >> N;
    A = B = vector<int>(N);
    rep(i, N) cin >> A[i] >> B[i];
}


int main() {
    input();
    vector<ll> dp(H+1, INF);
    dp[0] = 0;
    for (int i = 1; i <= H; i++) {
        rep(j, N) {
            dp[i] = min(dp[i], B[j] + dp[max(0, i-A[j])]);
        }
    }
    cout << dp[H] << endl;
}


Measured memory_bytes: 384
n_list = list(input())
n_len_o = len(n_list)
a = 0
while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(a,n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      if i != 0:
        a = i - 1
      else:
        a = 0
      flag = "ok"
      break
  if flag == "ng":
    break
print(n_len_o-len(n_list))

Measured memory_bytes: 3956
def countwhen(n, a, b)
  count = 0
  (n / a + 1).times do |i|
    count += 1 if (n - i * a) % b == 0
  end
  return count
end

r, g, b, n = gets.chomp.split.map(&:to_i)
count = 0
(n / r + 1).times do |i|
  count += countwhen(n - i * r, g, b)
end

puts count


Measured memory_bytes: 1788
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<"square1001"<<endl;
	return 0;
}


Measured memory_bytes: 2928
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <regex>

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

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

using namespace std;

//#define LOCAL_DEBUG

vector<int> graph[100];

int main() {
#ifdef LOCAL_DEBUG
	freopen("input1.txt","r", stdin);
#endif
	int N, M;
	cin >> N >> M;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	stack<set<int>> stk1;
	stack<int> stk2;
	stk1.push(set<int>());
	stk2.push(1);
	int ans = 0;
	while (stk1.size() != 0) {
		set<int> s = stk1.top(); stk1.pop();
		int ss = s.size();
		int i = stk2.top(); stk2.pop();
		s.insert(i);
		if ((int)s.size() == N) {
			ans++;
			continue;
		}
		int size = graph[i].size();
		REP(i1, size) {
			int j = graph[i][i1];
			if (s.count(j) == 0) {
				set<int> new_s;
				for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
					new_s.insert(*it);
				}
				stk1.push(new_s);
				stk2.push(j);
			}
		}
	}

	cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 256
n,W = map(int,input().split())
w,v = [],[]
for i in range(n):
    wi,vi = map(int,input().split())
    w.append(wi)
    v.append(vi)
mv = sum(v)
INF = float("INF")
dp = [[INF]*(mv+100) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for sv in range(mv+100):
        if sv-v[i] >= 0:
            dp[i+1][sv] = min(dp[i+1][sv],dp[i][sv-v[i]]+w[i])
        dp[i+1][sv] = min(dp[i+1][sv],dp[i][sv])
    #print(dp)
ans = 0
for i in range(mv+100):
    #print(dp[n][i])
    if dp[n][i] <= W:
        ans = max(ans,i)
print(ans)


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

int prime(int n){
	if(n <= 1) return 0;
	for(int i = 2; i < n; i++)
	    if(n % i == 0) return 0;
	return 1;
}     

int main() {
	int X;
	cin >> X;
	if(prime(X)){
		 cout << X;
	}
	else{
		
	   while(!prime(X))
	        X++;
      cout << X;
   }
   return 0; 
}


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

using namespace std;

#define ll long long int 
#define F first
#define S second
#define pb push_back

const ll N = 1e6 + 5;
const ll LOG = 40;
const ll MOD = 1e9 + 7;
const ll OO = 1e9;
ll n, m, a[N], all,  _add[N], cnt[N];
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (i == 1) continue; 
        if (a[i - 1] < a[i]){
            all += a[i] - a[i - 1];
            cnt[a[i - 1] + 1]++, cnt[a[i] + 1]--;
            _add[a[i - 1] + 1] += a[i - 1] + 1ll;
            _add[a[i] + 1] += - a[i - 1] - 1ll;
        }
        if (a[i] < a[i - 1]){
            all += m - a[i - 1] + a[i];
            cnt[1]++, cnt[a[i] + 1]--;
            cnt[a[i - 1] + 1]++;
            _add[1] += -m + a[i - 1] + 1ll;
            _add[a[i] + 1] += m - a[i - 1] - 1ll;
            _add[a[i - 1] + 1] += a[i - 1] + 1ll;
        }
    }
    ll ans = all;
    for (ll i = 1; i <= m; i++){
        cnt[i] += cnt[i - 1];
        _add[i] += _add[i - 1];
        ans = min(ans, all + _add[i] - cnt[i] * i);
    }
    cout << ans << '\n';
    return 0;
}

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

int main()
{
	string		line;
	getline(cin, line);

	for (auto &it : line)
	{
		if (('a' <= it) && (it <= 'z'))
		{
			it = toupper(it);
		}
		else if (('A' <= it) && (it <= 'Z'))
		{
			it = tolower(it);
		}
	}

	cout << line << "\n";

	return 0;
}

Measured memory_bytes: 3144
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL n, a, b;

LL inv[200001], com[200001];

int main() {
    cin >> n >> a >> b;
    
    LL aaa = 2, nnn = n, p = 1;
    while (nnn > 0) {
        if (nnn % 2) {
            p = (p * aaa) % MOD;
        }
        aaa = (aaa * aaa) % MOD;
        nnn >>= 1;
    }

    inv[1] = 1;
    com[1] = n;
    FOR (i, 2, b + 1) {
        inv[i] = MOD - (inv[MOD % i] * (MOD / i) % MOD);
        com[i] = (((com[i - 1] * (n - i + 1)) % MOD) * inv[i]) % MOD;
    }

    LL ans = (p - ((com[a] + com[b]) % MOD + 1) % MOD) % MOD;
    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;
    return 0;
}


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

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

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (10 <= i && i < 100) continue;
        else if (1000 <= i && i < 10000) continue;
        else if (i == 100000) continue;
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	//N T
	int[] ntArray = Arrays.stream(sc.nextLine().split(" ")) //" "で区切ってString配列へ
    .mapToInt(Integer::parseInt) //数値にして
	.toArray(); //配列へ
	int N = ntArray[0];
	int T = ntArray[1];

	int[] ctArray;

	int minc = 10000;
	// c t　格納
	for(int i=1;i<=N;i++){
		ctArray = Arrays.stream(sc.nextLine().split(" ")) //" "で区切ってString配列へ
		.mapToInt(Integer::parseInt) //数値にして
		.toArray(); //配列へ

		//コスト最小？ 時間内？
		if(minc > ctArray[0]){
			if(T >= ctArray[1]){
				minc = ctArray[0];
			}
		}
	}

	if(minc == 10000){
		System.out.println("TLE");
	}else{
		System.out.println(minc);
	}
  }
}

Measured memory_bytes: 28372
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    ll a[n] = {};
    inrep(n,a);

    ll ans = 1;
    rep(i,0,n)ans = lcm(ans,a[i]);
    P(ans);
	return  0;
}

Measured memory_bytes: 256
import collections

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

cnt1=collections.Counter(L[0::2]).most_common(2)
cnt2=collections.Counter(L[1::2]).most_common(2)

if len(cnt1)==1:
    cnt1.append((0,0))
if len(cnt2)==1:
    cnt2.append((0,0))

if cnt1[0][0]!=cnt2[0][0]:
    print(N-cnt1[0][1]-cnt2[0][1])
else:
    print(min(N-cnt1[0][1]-cnt2[1][1],N-cnt1[1][1]-cnt2[0][1]))

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

void solve(long long N, vector<long long> A, vector<long long> B, vector<long long> C){
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	vector<long long> btoc(N), btocsum(N+1);
	for(int i = 0 ; i <= N-1 ; i++){
		btoc[i] = C.end() - upper_bound(C.begin(), C.end(), B[i]);
	}
	btocsum[N] = 0;
	for(int i = N-1 ; i >= 0 ; i--){
		btocsum[i] = btocsum[i+1]+btoc[i];
	}
	for(int i = 0 ; i <= N-1 ; i++){
		// cout << btocsum[i] << "\n";
	}
	long long res = 0;
	for(int i = 0 ; i <= N-1 ; i++){
		res += btocsum[upper_bound(B.begin(), B.end(), A[i])-B.begin()];
	}
	cout << res << "\n";
}

int main(){
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	vector<long long> C(N-1+1);
	vector<long long> B(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&B[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&C[i]);
	}
	solve(N, A, B, C);
	return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    a.at(i) -= i + 1;
  }
  
  sort(a.begin(), a.end());
  
  ll b;
  if(n % 2 == 1) b = a.at(n / 2);
  else b = (a.at(n / 2 - 1) + a.at(n / 2) + 1) / 2;
  
  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans += abs(a.at(i) - b);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
def main(N, A):
    num = 1
    ans = 1
    for i in range(N+1):
        num -= A[i]
        if i < N:
            num *= 2
            ans += num
        if num == 0 and i < N:
            return -1
        if num < 0:
            return -1
    eda = 0
    for i in range(N+1):
        ans -= num
        eda += A[N-i]
        num -= eda
        num = num//2
        if num <= 0:
            break
    return ans


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

print(main(N, A))


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

int N, Q;
int const INF = INT_MAX;

struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> a) {
        int sz = (int)a.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1, INF);

        for(int i=0; i<sz; i++) node[n-1+i] = a[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int k, int val) {
        k += n - 1;
        node[k] = val;
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;     // ?????????
        if(a <= l && r <= b) return node[k]; // ?????¨????¢????

        int vl = getmin(a, b, 2*k+1, l      , (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r      );
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    SegmentTree seg( vector<int>(N, INF) );
    for(int i=0; i<Q; i++) {
        int c, x, y; cin >> c >> x >> y;
        if(c == 0) seg.update(x, y);
        else cout << seg.getmin(x, y+1) << endl;
    }    
}

Measured memory_bytes: 4064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,x;
    scanf("%d%d", &n,&x);
    int i;
    ll sum=0;
    int cnt=1;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        sum += tmp;
        if(sum<=x) cnt++;
    }
    printf("%d\n", cnt);







    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define N 300010
using namespace std;
int n,a,b,now,t1,t2,k1,k2,d[N];
int main(){
	bool flag=0;
	scanf("%d%d%d",&n,&a,&b);
	//a上升,b下降
	per (i,b,1) d[b-i+1]=i;
	a--; now=b;
	if (a){
		t1=(n-b)/a+1; k1=(n-b)%a;// printf("t1=%d,k1=%d\n",t1,k1);
		t2=(n-b)/a; k2=a-(n-b)%a;// printf("t1=%d,k1=%d\n",t1,k1);
		if (k1 && t1>b || k2 && t2>b){ puts("-1"); return 0; }
		if (((bool)t1)*k1+((bool)t2)*k2<a){ puts("-1"); return 0; }
		rep (t,1,k1){//now+t1--->now+1
			rep (i,1,t1) d[now+i]=now+t1-i+1;
			now+=t1;
		}
		rep (t,1,k2){
			rep (i,1,t2) d[now+i]=now+t2-i+1;
			now+=t2;
		}
	}
	rep (i,1,n) printf("%d ",d[i]);
	return 0;
}

Measured memory_bytes: 3328
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  if (s.size() == 3) reverse(all(s));
  cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3616
n = int(input())
l = list(map(int, input().split()))

scores = [0, 0, 0, 0, 0, 0, 0, 0]
x = [0]

def evaluation(list):
    for i in list:
        if 0 <= i <= 399:
            scores[0] = 1
        elif 400 <= i <= 799:
            scores[1] = 1
        elif 800 <= i <= 1199:
            scores[2] = 1
        elif 1200 <= i <= 1599:
            scores[3] = 1
        elif 1600 <= i <= 1999:
            scores[4] = 1
        elif 2000 <= i <= 2399:
            scores[5] = 1
        elif 2400 <= i <= 2799:
            scores[6] = 1
        elif 2800 <= i <= 3199:
            scores[7] = 1
        else:
            x.append(1)

evaluation(l)

y = sum(scores)
z = sum(x)

print(max(1, y), y + z)

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

int main(){
    int N; cin>>N;
    int A, ans[N]={0};

    for(int i=1; i<N; i++){
        cin>>A;
        ans[A-1]++;
    }
    for(int i=0; i<N; i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 4400
from collections import deque

h,w=map(int,input().split())

maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



def bfs(maze,visited,sy,sx):#,gy,gx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=0
  while queue:
    [y,x]=queue.popleft()
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  visited=[[-INF]*(w+2) for i in range(h+2)]
  bfs(maze,visited,i,j)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)



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

#define INF 1e9

typedef vector <int> vi;

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

    int v[n];
    for (int i = 0; i < n; i++) cin >> v[i];

    vi dp(n, INF);
	dp[0] = 0;

    for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= i + k && j < n; j++) {
			dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));
		}
    }

	// for (int i = 0; i < n; i++) cout << dp[i] << " ";
	// cout << endl;

    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		if (input.equals("AAA") || input.equals("BBB")) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 35476
#include<stdio.h>

int henkann(int x, int y, int z);

int main()
{
int a, b, c, k;
int kake;
int i = 0;
int cp;
int kotae;

scanf("%d %d %d", &a, &b, &c);
scanf("%d", &k);
kake = henkann(a, b, c);
cp = henkann(a, b, c);
for (i = 0; i < k; i++)
{
kake *= 2;
}

printf("%d\n", a+b+c+kake-cp);
return 0;
}

int henkann(int x, int y, int z)
{
int max = x;
if (y > max) max = y;
if (z > max) max = z;
return max;
}

Measured memory_bytes: 128
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))

A=[]
A.append(A1)
A.append(A2)
A.append(A3)
N=int(input())

ans='No'

for _ in range(N):
    b=int(input())
    if b in A1:
        A1[A1.index(b)]=0
    if b in A2:
        A2[A2.index(b)]=0
    if b in A3:
        A3[A3.index(b)]=0

if not any(A1) or not any(A2) or not any(A3) :#全てFalse
    ans='Yes'

A1c=[A1[0],A2[0],A3[0]]
A2c=[A1[1],A2[1],A3[1]]
A3c=[A1[2],A2[2],A3[2]]

if not any(A1c) or not any(A2c) or not any(A3c) :#全てFalse
    ans='Yes'

A1n=[A1[0],A2[1],A3[2]]
A2n=[A1[2],A2[1],A3[0]]

if not any(A1n) or not any(A2n):#全てFalse
    ans='Yes'

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct Edge
{
	int to;
	int nxt;
}e[200005];
int n,m,edgenum,head[100005],num,d[100005];
bool flag[100005];
void add(int u,int v)
{
	e[++edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
		d[u]++,d[v]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i]&1)
		{
			printf("No\n");
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i]==2)continue;
		if(d[i]>=6)
		{
			printf("Yes\n");
			return 0;
		}
		if(d[i]==4)num++;
	}
	if(num>=3)
	{
		printf("Yes\n");
		return 0;
	}
	if(num<=1)
	{
		printf("No\n");
		return 0;
	}
	int node=0;
	for(int i=1;i<=n;i++)
	  if(d[i]==4)node=i;
	flag[node]=1;
	for(int hd=head[node];hd;hd=e[hd].nxt)
	{
		int to=e[hd].to;
		if(flag[to])
		{
			printf("Yes\n");
			return 0;
		}
		int u=to;
		while(d[u]==2&&flag[u]==0)
		{
			flag[u]=1;
			if(flag[e[head[u]].to]==0)u=e[head[u]].to;
			else if(flag[e[e[head[u]].nxt].to]==0)u=e[e[head[u]].nxt].to;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 2560
import queue
h,w=map(int,input().split())
s=[input() for _ in range(h)]
INF=10**18
dx=[-1,0,1,0]
dy=[0,-1,0,1]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':continue
    d=[[INF]*w for _ in range(h)]
    d[i][j]=0
    q=queue.Queue()
    q.put((i,j))
    while not q.empty():
      x,y=q.get()
      for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=nx<h and 0<=ny<w:
          if s[nx][ny]=='.' and d[nx][ny]==INF:
            q.put((nx,ny))
            d[nx][ny]=d[x][y]+1
            ans=max(ans,d[nx][ny])
print(ans)


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int n, x; scanf("%d%d", &n, &x);
    int m = 1001;
    for (int i = 0; i < n; ++i) {
        int t; scanf("%d", &t);
        m = min(m, t);
        x -= t;
    }
    printf("%d", n+x/m);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double l = sc.nextDouble();
        double la = (l/3)*(l/3)*(l/3);
        System.out.println(BigDecimal.valueOf(la).toPlainString());
    }
}

Measured memory_bytes: 25172
from collections import deque
n, q = map(int, input().split())
lst = deque([])
for i in range(n):
    name, time = input().split()
    lst.append({'name': name, 'time': int(time)})
now = 0
while len(lst) > 0:
    task = lst.popleft()
    now += min(q, task['time'])
    task['time'] -= q
    if task['time'] > 0:
        lst.append(task)
    else:
        print(task['name'], now)



Measured memory_bytes: 21408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,ans,sum,a[100005];
int main(){
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	for(int i=1;i<n;i++)
		sum=a[i]<=a[i-1]?sum+1:0,ans=max(ans,sum);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    vector<ll> s(N,0),ans(N,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
    
    ll tmp = sum;
    for(int i=1;i<N;i+=2){
        tmp -= (2 * A[i]);
    }
    ans[0] = tmp;
    cout << ans[0] << endl;
    for(int i=0;i<N-1;i++){
        ans[i+1] =  2 * A[i] - ans[i];
        cout << ans[i+1] << endl;
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,W;
  cin>>N>>W;
  ll dp[N+1][W+1];
  ll weight[N+1],value[N+1];
  for(ll i=0;i<N;i++)cin>>weight[i]>>value[i];
  //初期化
  for(ll i=0;i<=W;i++)dp[0][i]=0;
  //DP
  for(ll i=0;i<N;i++){
    for(ll w=0;w<=W;w++){
      if(w>=weight[i])
      dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+value[i]);
      else dp[i+1][w]=dp[i][w];
    }
  }
  cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 79104
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(void){
    int a[3];
    for (int i=0;i<3;i++){
    cin >> a[i];
    }
    sort(a,a+3);
    if (a[0]+a[1]==a[2]){
        puts("Yes");
    }else{
        puts("No");
    }
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++){ cin >> A[i]; }
    
    int count = 0;
    bool odd_flag = false;
    
    while(true){
        for(int i=0;i<N;i++){
            if(A[i] % 2 == 1){ odd_flag = true; break; }
            else{ A[i] /= 2; }
        }
        if(odd_flag == true){ break; }
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    vector<ll>a(n),b(n);
    vector<pair<ll,ll>>p(n);
    ll max1=0,sum=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        p[i]=make_pair(b[i],a[i]);
    }
    sort(p.begin(),p.end());
    rep(i,n){
        sum+=p[i].second;
        max1=max(max1,p[i].first);
        if(max1<sum){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 6528
#include<cstdio>
#define fo(i, x, y) for(int i = x; i <= y; i ++)
using namespace std;

const int N = 5e5 + 5;

int T,n,m,x,y;
int fi[N],to[N * 2],nt[N * 2],tot,bz[N];
int fa[N],ans[N],siz[N];

void link(int x,int y){
	nt[++tot] = fi[x],to[tot] = y,fi[x] = tot;
}

void cl(){
	fo(i,1,n)	bz[i] = fi[i] = ans[i] = siz[i] = 0;
	tot = 1;
}

void dg(int x,int la){
	bz[x] = 1;
	for(int i = fi[x]; i; i = nt[i]) if(!bz[to[i]]){
		ans[i / 2] = (i & 1);
		siz[to[i]] ^= 1;
		dg(to[i],i);
		siz[x] ^= siz[to[i]];
	} else if(i != (la ^ 1)){
		ans[i / 2] = !(i & 1);
		siz[to[i]] ^= 1;
	}
	if(siz[x]) ans[la / 2] ^= 1;
}

#include <vector>
using namespace std;

int main(){
	//for(scanf("%d",&T); T; T--){
		cl();
		scanf("%d %d",&n,&m);
		vector<pair<int,int>>ed;
		fo(i,1,m){
			scanf("%d %d",&x,&y);
			ed.push_back({x,y});
			link(x,y); link(y,x);
		}
		if(m & 1){
			printf("-1\n"); return 0;
		}
		dg(1,0);
		fo(i,1,m){
			printf("%d %d\n",(ans[i]?ed[i-1].first:ed[i-1].second)
				   ,(ans[i]?ed[i-1].second:ed[i-1].first));
		}
	//}
}

//sub-EOF


Measured memory_bytes: 21748
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    double p[n];
    double f[n]={1};
    for(int i=0;i<n;i++){
        cin>>p[i];
        f[i]=1-p[i];
    }
    
    double dp[n+1][n+1];
    
    for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++)
        dp[i][j]=0;
    }

   

    dp[0][0]=1;

    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j!=0){
                dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*f[i-1];
            }
            else{
                dp[i][j]=dp[i-1][j]*f[i-1];
            }
        }
    }

 


    double ans=0;
    for(int i=(n+1)/2;i<=n;i++)
        ans+=dp[n][i];
    printf("%0.9f", ans);  
}

Measured memory_bytes: 70656