akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int a[80][80],b[80][80];
int dp[80][80][80*159*2+1];

int main(){
    int h,w,da=80*159; cin>>h>>w;
    rep(i,h)rep(j,w) cin>>a[i][j];
    rep(i,h)rep(j,w) cin>>b[i][j];
    rep(i,80)rep(j,80)rep(k,80*159*2+1) dp[i][j][k]=0;
    dp[0][0][a[0][0]-b[0][0]+da]=1;
    dp[0][0][-a[0][0]+b[0][0]+da]=1;
    rep(i,h)rep(j,w){
        if(i<h-1){
            rep(k,80*159*2+1){
                if(dp[i][j][k]){
                    dp[i+1][j][k+a[i+1][j]-b[i+1][j]]=1;
                    dp[i+1][j][k-a[i+1][j]+b[i+1][j]]=1;
                }
            }
        }
        if(j<w-1){
            rep(k,80*159*2+1){
                if(dp[i][j][k]){
                    dp[i][j+1][k+a[i][j+1]-b[i][j+1]]=1;
                    dp[i][j+1][k-a[i][j+1]+b[i][j+1]]=1;
                }
            }
        }
    }
    int ans=inf;
    rep(i,80*159*2+1)if(dp[h-1][w-1][i]) ans=min(ans,abs(i-da));
    cout<<ans<<endl;
}


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

namespace Combinatorics {

using lint = long long;

lint MOD;
vector<lint> factorial, inv;

lint power(lint n, lint x) {
  if (x == 0) {
    return 1;
  }
  lint res = power(n, x / 2);
  res *= res;
  res %= MOD;
  if (x & 1) {
    res *= n;
    res %= MOD;
  }
  return res;
}

void init(int n, int MOD_) {
  MOD = MOD_;
  factorial.resize(n);
  factorial[0] = 1;
  for (int i = 1; i < n; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
  }
  inv.resize(n);
  inv[n - 1] = power(factorial[n - 1], MOD - 2);
  for (int i = n - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % MOD;
  }
}

lint Choose(int n, int k) {
  return factorial[n] * inv[k] % MOD * inv[n - k] % MOD;
}

}

int main() {
  int N, M, A, B, MOD = 1e9 + 7;
  cin >> N >> M >> A >> B;

  Combinatorics::init(2 * (N + M), 1e9 + 7);
  long long ans = 0;
  for (int i = 1; i <= N - A; i++) {
    pair<int, int> part1(i - 1, B - 1);
    pair<int, int> part2(N - i, M - B - 1);
    ans += 1ll * Combinatorics::Choose(part1.first + part1.second, part1.first) * Combinatorics::Choose(part2.first + part2.second, part2.first) % MOD;
    ans %= MOD;
  }

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

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,x; cin >> n >> x;
    VI m(n); REP(i,n) cin >> m[i];
    out(n+(x-SUM(m,0LL))/MIN(m));

    return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
e = [[] for _ in range(N)]
# 隣接リスト

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

# BFS*2で直径を求める
dist = [-1 for _ in range(N)]
dist[0] = 0

q = deque()
q.append(0)

while q:
    v = q.popleft()
    d = dist[v]
    for nv in filter(lambda x: dist[x] == -1, e[v]):
        dist[nv] = d + 1
        q.append(nv)
# 探索終了後
# (v,d)=頂点0から最遠点の頂点番号v,頂点0からの距離d

dist = [-1 for _ in range(N)]
dist[v] = 0

q = deque()
q.append(v)

while q:
    w = q.popleft()
    d = dist[w]
    for nw in filter(lambda x: dist[x] == -1, e[w]):
        dist[nw] = d + 1
        q.append(nw)
# 探索終了後
# (w,d)=頂点vから最遠点の頂点番号w,頂点vからの距離d

print('Second' if d % 3 == 1 else 'First')

Measured memory_bytes: 49212
#include<stdio.h>
int main(void)
{
	int a[4];
	int b[4];
	int i,j;
	int hit,blow;
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
	    scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		hit=0;
		blow=0;
		for(i=0;i<4;i++){
			if(a[i]==b[i]){
				hit++;
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(a[i]==b[j]){
					blow++;
				}
			}
		}
		blow=blow-hit;
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int main(void) {
    int n, x;
    int i, j, k, ans;
     
    while (scanf("%d %d", &n, &x), n || x) {
        ans = 0;
        for (i = 1; i <= n; i++) {
            for (j = i + 1; j <= n; j++) {
                for (k = j + 1; k <= n; k++) {
                    if (i + j + k == x) ans++;
                }
            }
        }
         
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2104
from collections import deque

n, q = map(int, input().split())

g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    c[p-1] += x

q = deque([0])
flag = [False] * n
while q:
    v = q.pop()
    flag[v] = True
    for e in g[v]:
        if flag[e]:
            continue
        c[e] += c[v]
        q.append(e)

print(*c)

Measured memory_bytes: 105236
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

ll sum(ll num) {
	ll res = 0;
	while (num) {
		res += num % 10;
		num /= 10;
	}
	return res;
}
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int i, k;
	cin >> k;
	cout << 1 << endl;

	ll n = 1, d = 1;
	for (i = 1; i < k; i++) {
		if (sum(n + d) * (n + 10 * d) < sum(n + 10 * d) * (n + d)) d *= 10;
		n += d;
		cout << n << endl;
	}
}

Measured memory_bytes: 256
#![allow(non_snake_case, dead_code)]
use proconio::fastout;
use proconio::input;
use rand::Rng;

#[fastout]
fn main() {
    input! {
        D:usize,
        C:[i32;26],
        S:[[i32;26];D]
    }
    let start = std::time::Instant::now();
    let mut rng = rand::thread_rng();
    // コスト計算(初回)
    let score = |T: &Vec<usize>| {
        let mut last = vec![0; 26];
        let mut x = 0i32;
        for d in 0..D {
            last[T[d]] = d + 1;
            for i in 0..26 {
                x -= C[i] * (d + 1 - last[i]) as i32;
            }
            x += S[d][T[d]];
        }
        x
    };
    // -------------
    let mut T = vec![0; D];
    let mut Tmax = vec![0; D];
    //let mut cnt = 0;

    for i in 0..D {
        let mut saidai = 0;
        for j in 1..26 {
            if S[i][saidai] < S[i][j] {
                saidai = j;
            }
        }
        T[i] = saidai;
        Tmax[i] = saidai;
    }
    let mut ans = score(&T);
    loop {
        let r_day = rng.gen::<usize>() % D;
        let r_con = rng.gen::<usize>() % 26;
        T[r_day] = r_con;
        //cnt += 1;
        let x = score(&T);

        // 最大値を更新できたら値を更新するが、そうでなければ元に戻す。
        if ans < x {
            ans = x;
            Tmax[r_day] = T[r_day];
        } else {
            T[r_day] = Tmax[r_day];
        }
        let duration = start.elapsed();
        if duration > std::time::Duration::from_millis(1900) {
            break;
        }
    }
    for i in 0..D {
        println!("{}", Tmax[i] + 1);
    }
    //println!("cnt:{}, point:{}", cnt, ans);
}
fn score(D: usize, C: &Vec<i32>, S: &Vec<Vec<i32>>, T: &Vec<usize>) -> i32 {
    let mut dlast = vec![vec![1i32; 26]; D];
    dlast[0][T[0]] = 0;
    for d in 1..D {
        for i in 0..26 {
            dlast[d][i] = dlast[d - 1][i] + 1;
        }
        dlast[d][T[d]] = 0;
    }
    let mut x = 0;
    for d in 0..D {
        let i = T[d];
        x += S[d][i];
        //println!("ss{}", x);
        for j in 0..26 {
            x -= C[j] * (dlast[d][j]);
            //println!("C[{}]={} -> {}", j, C[j], x);
        }
    }
    x
}


Measured memory_bytes: 2732
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, m, s, t;
VI e[300010];

void solve() {
  cin >> n >> m;
  REP(i, m) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u*3].push_back(v*3+1);
    e[u*3+1].push_back(v*3+2);
    e[u*3+2].push_back(v*3);
  }
  cin >> s >> t;
  s--;
  t--;
  s *= 3;
  t *= 3;

  set<int> vis;
  vis.insert(s);
  queue<pair <int, int> > q;
  q.push({s, 0});
  while(q.size() > 0) {
    pair <int, int> node = q.front();
    q.pop();
    int v = node.first;
    int cost = node.second;
    if (v == t) {
      cout << cost/3 << endl;
      return;
    }

    for (auto a: e[v]) {
      if (vis.count(a) == 0) {
        q.push({a, cost+1});
        vis.insert(a);
      }
    }

  }
  cout << -1 << endl;

}

int main() {
	solve();
	return 0;
}


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

using namespace std;

void solve();

int main()
{
#ifdef OFFLINE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

typedef pair<int, int> pii;
#define fst first
#define snd second

const int N = 111;

int a[N];

void solve() {
    int n; cin >> n;
    int xlo = n, xhi = 0;
    for (int i=0; i<n; i++) {
        int x; cin >> x;
        a[x]++;
        xlo = min(xlo, x);
        xhi = max(xhi, x);
    }

    bool ok = true;
    if (xlo != (xhi + 1) / 2)
        ok = false;
    else {
        if (!(xhi & 1) && (a[xlo] > 1 || a[xlo + 1] < 2))
            ok = false;
        if ((xhi & 1) && a[xlo] != 2)
            ok = false;
        for (int x=xlo + 1; ok && x<=xhi; x++)
            if (a[x] < 2)
                ok = false;
    }
    if (ok)
        cout << "Possible\n";
    else
        cout << "Impossible\n";
}


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


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

    int h,w,k;  cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h){
        cin >> c[i];
    }

    int ans=0;

    rep(ix,1<<h)rep(jx,1<<w){
        int cnt=0;

        rep(i,h)rep(j,w){
            if(ix>>i & 1)   continue;
            if(jx>>j & 1)   continue;
            if(c[i][j] == '#')  cnt++;
        }

        if(cnt==k)  ans++;
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N,M;
  cin >> N >> M;
  ll X[M];
  ll be[M - 1];
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }
  sort(X,X+M);
  ll sum = X[M - 1] - X[0];
  for (int i = 1; i < M; i++) {
    be[i - 1] = X[i] - X[i - 1];
  }
  sort(be,be+M-1);
  reverse(be,be+M-1);
  ll ans = sum;
  if (N >= M) {
    cout << 0 << endl;
  }
  else {
    for (int i = 0; i < N - 1; i++) {
      ans -= be[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void swap_int(int *x, int *y) {int temp;temp = *x;*x = *y;*y = temp;}
void swap_char(char *x, char *y) {char temp;temp = *x;*x = *y;*y = temp;}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x > y ? y : x; }

int main(){
    int x,a;

    scanf("%d %d",&x,&a);
    if(x<a){
        printf("0\n");
    }else{
        printf("10\n");
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
if n%2 == 0:
  print(n*(n-2)//2)
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      if i+j != n+1:
        print(i,j)
else:
  print((n*(n-2)+1)//2)
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      if i+j != n:
        print(i,j)

Measured memory_bytes: 3612
#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;


ll a[16][16];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

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

    vector<ll> dp(1<<n);
    int k;
    for(k=0; k<(1<<n); k++) {
        vector<int> z;
        for(i=0; i<n; i++) {
            if(k & (1<<i)) z.push_back(i); 
        }
        int siz=(int)z.size();

        dp[k]=0;
        for(i=0; i<siz; i++) {
            for(j=i+1; j<siz; j++) {
                dp[k] += a[z[i]][z[j]];
            }
        }

        ll max=0;
        for(i=0; i<(1<<siz); i++) {
            int tmp0=0, tmp1=0;
            for(j=0; j<siz; j++) {
                if(i & (1<<j)) tmp0 |= (1<<z[j]);
                else           tmp1 |= (1<<z[j]);
            }
            ll val = dp[tmp0]+dp[tmp1];
            max = MAX(max, val);
        }
        dp[k] = max;
    }
    printf("%lld\n", dp[(1<<n)-1]);

    return 0;
}


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

int main() {
   int a, b, d, r;
   double f;
   
   cin >> a >> b;
  d = a/b;
  r = a%b;
  f = (double)a / b;
   
   cout << d << " " << r << " " << fixed << setprecision(5) << f <<endl;
}


Measured memory_bytes: 3244
#include<iostream>
#include<algorithm>
#define f first
#define s second
using namespace std;
int main(){
  int n,m;
  pair<int,int>d[10000];
  while(cin>>n>>m&&n!=0){
    int an=0,k=0;
    for(int i=0;i<n;i++)cin>>d[i].s>>d[i].f,k+=d[i].s;
    sort(d,d+n);
    for(int i=0;m<k;i++){
      if(k-m<d[i].s)an+=d[i].f*(k-m);
      else an+=d[i].f*d[i].s;
      k-=d[i].s;
    }
    cout<<an<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int x, y; cin >> x >> y;

    cout << x+y/2 << endl;
    return 0;
}


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

int main() {
  int x, n;
  cin >> x >> n;
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  set<int> a;
  rep(i, n){
    int tmp;
    cin >> tmp;
    a.insert(tmp);
  }
  auto c = a.find(x);
  if(c== a.end()){
    cout << x << endl;
    return 0;
  }
  int minus = 1;
  int plus = 1;
  while (true){
    auto it = a.find(x-minus);
    auto ic = a.find(x + plus);
      if(it == a.end()){
        cout << x - minus << endl;
        return 0;
      }
      if(ic == a.end()){
        cout << x  + plus << endl;
        return 0;
      }
    minus++;
    plus++;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct xyz{
    ll x,y,z;
};
ll ans=-1,n;
vector<xyz> v;
bool cs(xyz a,xyz b){
    return a.x<b.x;
}
int main(){
cin>>n;
v.resize(n);
for(ll k=0;k<n;k++)
    cin>>v[k].x;
for(ll k=0;k<n;k++)
    cin>>v[k].y;
for(ll k=0;k<n;k++)
    v[k].z=k;
ll N=1<<n;

for(ll k=0;k<N;k++){
        ll t=k;
    vector<xyz> p;
    p=v;
    vector<xyz> d;
    d=p;
    for(ll i=0;i<n;i++){
        ll val=k&(1<<i);
        if(val!=0)
            swap(d[i].x,d[i].y);
    }


    ll pas=0;
    sort(d.begin(),d.end(),cs);
    ll j=n-1;
    while(j>=0){
        ll ind=0,val=d[j].x;
        for(ll i=j;i>=0;i--){
            if(((k&(1<<p[i].z))==0 && (j-i)%2==0 && val==p[i].x) || ((k&(1<<p[i].z))!=0 && (j-i)%2==1 && val==p[i].y)){
                ind=1;
                for(ll q=i;q<j;q++){
                    swap(p[q].x,p[q].y);
                    swap(p[q+1].x,p[q+1].y);
                    k=(k ^ (1 << (p[q].z)));
                    k=(k ^ (1 << (p[q+1].z)));
                    swap(p[q],p[q+1]);
                    pas++;
                }
                break;
            }
        }
        if(ind==0){
            pas=-1;
            break;
        }
        j--;
    }
if(pas!=-1){
    if(ans==-1)
        ans=pas;
    else ans=min(ans,pas);
}
k=t;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
//        string[] read = ReadLine().Split(' ');
//        int read_leng = read.Length;
//        int[] readR = new int[mochinum];
        string word = ReadLine();
        char[] a = word.ToCharArray();
        Array.Reverse(a);
        string wordR = new string(a);

        string[] wR = new string[4]{"maerd","remaerd","esare","resare"};
        while(wordR.Length > 0){
            int c1 = wordR.Length;
            for(int i=0;i<wR.Length;i++){
                if(wordR.IndexOf(wR[i]) == 0){
                    if(wordR.Length == wR[i].Length){
                        wordR = "";
                    }else{
                        wordR = wordR.Substring(wR[i].Length);
                    }
                }
            }
            int c2 = wordR.Length;
            if(c1 == c2 || c2 ==0){
                if(c2 > 0){
                    WriteLine("NO");
                }else{
                    WriteLine("YES");
                }
                break;
            }
        }
    }
}


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

int main() {
    int w, a, b, ans;
    cin >> w >> a >> b;
    ans = max(max(b - (a + w), a - (b + w)), 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
lis=[]
for i in range(N):  
  lis.append(int(input()))
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)

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

constexpr double eps = 1e-8;

int main() {
    int n, k, t, u, v, l;
    cin >> n >> k >> t >> u >> v >> l;
    vector<double> D(n);
    for(int i=0; i<n; ++i) {
        cin >> D[i];
    }
    double pos = 0;
    double res = 0;
    int cnt = 0;
    double rest = 0;
    for(int i=0; i<n; ++i) {
        if(rest == 0 && cnt == 0) {
            res += (D[i] - pos) / u;
            pos = D[i];
            rest = v*t;
        } else if(rest + pos >= D[i]) {
            if(cnt == k) {
                res += (D[i] - pos) / v;
                pos = D[i];
                rest = v*t;
            } else {
                cnt++;
            }
        } else {
            while(cnt > 0 && rest + eps < D[i] - pos) {
                res += t;
                pos += v*t;
                cnt--;
            }
            if(D[i] - pos > rest + eps) {
                res += rest / v + (D[i] - pos - rest) / u;
                pos = D[i];
                rest = v*t;
            } else {
                rest -= D[i] - pos;
                res += (D[i] - pos) / v;
                pos = D[i];
                cnt++;
            }
        }
    }
    if(rest + (double)cnt*v*t >= l - pos) {
        res += (l - pos) / v;
    } else {
        res += rest / v + cnt * t + (l - (pos + rest + cnt*v*t)) / u;
    }
    cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 3304
s=list(input())
c=0
while len(s)>0:
    p="1"
    q="1"
    r="1"
    if len(s)<5:
        break
    if len(s)<=7:
        if len(s)==5:
            if s==list("dream") or s==list("erase"):
                c=1
                break
        elif len(s)==6:
            if s==list("eraser"):
                c=1
                break
        elif len(s)==7:
            if s==list("dreamer"):
                c=1
                break
    else:
        p=s[len(s)-5:len(s)]
        q=s[len(s)-6:len(s)]
        r=s[len(s)-7:len(s)]
        if p==list("dream") or p==list("erase"):
            del s[len(s)-5:len(s)]
        elif q==list("eraser"):
            del s[len(s)-6:len(s)]
        elif r==list("dreamer"):
            del s[len(s)-7:len(s)]
        else:
            break
print("YES" if c==1 else"NO")

Measured memory_bytes: 4084
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            MyDebugger.Test(process, "../TextFile1.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);
      
        int ones = ary.Count(x=>x==1);
        if (ones > 0){
            if(ones > 1) return 0;
            return 1;
        }

        int max = ary.Max();

        var hash = new DefaultDectionary<int, int>(0);
        foreach(var x in ary) {
            hash[x] += 1;
        }

        var keys = hash.Keys.ToArray();
        foreach (var v in keys) {
            var x = hash[v];
            if(x == 0) continue;

            if(hash[v] > 1) {
                hash[v] = 0;
            }
            var y = v * 2;
            int i = 3;
            while(y <= max) {
                if (hash.ContainsKey(y)) {
                    hash[y] = 0;
                }
                y = v*i;
                i++;
            }
        }

        long sum = 0;
        foreach(var x in hash) {
            sum += x.Value;
        }

        return sum;
    }

    class DefaultDectionary<Tkey, TValue> : Dictionary<Tkey, TValue>
    {
        TValue DefaultValue;
        public DefaultDectionary(TValue defaultvalue) {
            this.DefaultValue = defaultvalue;
        }
        public new TValue this[Tkey key] {
            get {
                if (this.ContainsKey(key)) return base[key];
                else return DefaultValue;
            }
            set {
                base[key] = value;
            }
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if(n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 53652
from math import cos
a,b,h,m = map(int, input().split())
p = 3.14159265358979323846264338327950

rad = h/12.0 + m/(60*12) - m/60.0
rad = 2*p * rad

ans = a**2 + b**2 -2*a*b*cos(rad)
 

print(ans**(0.5))

Measured memory_bytes: 62552
#import numpy as np

n,m=map(int,input().split())
a=[]
k=[]
for _ in range(n):
    b=list(map(int,input().split()))
    k.append(b[0])
    a.append(b[1:])
#print(k)
#print(a[1][0])

#c=np.zeros(m)
c=[0]*m
for i in range(n):
    for j in range(k[i]):
        d=a[i][j]
#        print(d)
        c[d-1]+=1

ans=0
for i in range(m):
    if c[i]==n:
        ans+=1
print(ans)


Measured memory_bytes: 62708
s = input().rstrip()
n = len(s)
count_a = 0
count_bc = 0
res = 0
i = 0
while i < n:
    if s[i] == 'A':
        count_a += 1
        i += 1
    elif s[i] == 'B':
        if count_a == 0:
            i += 1
            continue
        if i + 1 == n:
            break
        if i + 1 < n and s[i + 1] != 'C':
            count_a = 0
            i += 1
            continue
        while i + 1 < n and s[i:i + 2] == 'BC':
            count_bc += 1
            i += 2
        res += count_a * count_bc
        count_bc = 0
    else:
        count_a = 0
        i += 1
print(res)

Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

const long long int INF=1e16;

int main() {
    int N;
    cin >> N;
    vector<vector<long long int> > og(N, vector<long long int>(N));
    priority_queue<pair<long long int, pair<int, int> > > que;
    for(int n=0; n<N; n++) {
        for(int m=0; m<N; m++) {
            cin >> og[n][m];
            if(n>=m) continue;
            que.push(make_pair(-og[n][m], make_pair(n, m)));
        }
    }
    vector<vector<long long int> > field(N, vector<long long int>(N, INF));
    long long int ans=0;
    while(!que.empty()) {
        pair<long long int, pair<int, int> > t=que.top(); que.pop();
        long long int cost=-t.first;
        int n=t.second.first, m=t.second.second;
        if(field[n][m]>cost) {
            field[n][m] = cost;
            field[m][n] = cost;
            ans += cost;
            
            int k=n;
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    field[i][j] = min(field[i][j], field[i][k]+field[k][j]);
                    if(og[i][j]>field[i][j]) {
                        ans = -1;
                        break;
                    }
                }
            }
            k=m;
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    field[i][j] = min(field[i][j], field[i][k]+field[k][j]);
                    if(og[i][j]>field[i][j]) {
                        ans = -1;
                        break;
                    }
                }
            }
        }
        if(ans==-1) {
            break;
        }
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 5276
#include <stdio.h>

int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

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

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>

int main(){
    int r, c;
    scanf("%d %d", &r, &c);
    int ss[101][101]={0};
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            scanf("%d", &ss[i][j]);
            ss[i][c]+=ss[i][j];
            ss[r][j]+=ss[i][j];
            ss[r][c]+=ss[i][j];
        }
    }
    for(int i=0; i<=r; i++){
        for(int j=0; j<c; j++){
            printf("%d ",ss[i][j]);
        }
        printf("%d\n",ss[i][c]);
    }
}


Measured memory_bytes: 2044
import java.math.*

fun main(args: Array<String>) {
    val (a, b, k) = readInputLine().split(" ").map { it.toInt() }
    
    for (i in a until a + k) {
        if (i > b) {
            break
        }
        println(i)
    }
    
    for (i in Math.max(a + k, b - k + 1)..b) {
        println(i)
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}

Measured memory_bytes: 38116
from collections import deque

N = int(input())
graph = [deque([]) for _ in range((N + 1))]
for _ in range(N):
    u, k, *v = [int(x) for x in input().split()]
    v.sort()
    for i in v:
        graph[u].append(i)
        
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)

def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()
    return [arrive_time, finish_time]
    
for i in range(N):
    if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)
        
for j in range(N):
    temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
    print(*temp)


Measured memory_bytes: 6088
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, M = LI()

print(int((1900 * M + 100 * (N-M))* (1/2)**(-M)))


Measured memory_bytes: 67308
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed;
    cout << setprecision(8) << sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) << endl;

    return 0;
}


Measured memory_bytes: 3288
/*
 * @Author: Kaizyn
 * @Date: 2020-03-22 19:57:48
 * @LastEditTime: 2020-03-22 20:02:56
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1e2+7;
const int MOD = 1e9+7;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

int n, m;

inline void solve()
{
    cin >> n >> m;
    int res = 0;
    res += n*(n-1)/2;
    res += m*(m-1)/2;
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

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

int main()
{
  int n, a, b, c, d;
  int x_price, y_price;
  std::cin >> n >> a >> b >> c >> d;

  x_price = (n + a - 1) / a * b;
  y_price = (n + c - 1) / c * d;

  std::cout << std::min(x_price, y_price) << std::endl;

  return (0);
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

int n, m, a[200001], b[200001];
bool ab[200000] = {0}, aa[200000] = {0};

int main(){
	bool ans = 0;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		if(a[i] == 1)
			aa[b[i]] = 1;
		if(b[i] == n)
			ab[a[i]] = 1;
	}
	
	for(int i = 0; i < n; i++){
		if(aa[i] && ab[i])
			ans = 1;
	}
	
	if(ans)
		cout << "POSSIBLE" << endl;
	else
		cout << "IMPOSSIBLE" << endl;
	
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

ll calc(const vl& a, ll k) {
    const int n = a.size();
    ll sum = accumulate(all(a), 0LL);
    vl b(2*n);
    rep(i, n) {
        b[i] = a[i];
        b[i+n] = a[i];
    }
    ll ans = -INF;
    rep(i, n) {
        ll x = b[i];
        int d = 1;
        chmax(ans, x + max(0LL, sum * ((k - d) / n)));
        REP(j, i+1, b.size()) {
            ++d;
            if(d > k) break;
            x += b[j];
            chmax(ans, x + max(0LL, sum * ((k - d) / n)));
        }
    }
    return ans;
}

int main(){
    ll n, k;
    cin >> n >> k;
    vl p(n), c(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> c[i];
    rep(i, n) p[i]--;

    ll ans = -INF;
    
    vi used(n);
    rep(i, n) if(!used[i]) {
        int cur = i;
        vl a;
        while(!used[cur]) {
            used[cur] = true;
            a.emplace_back(c[cur]);
            cur = p[cur];
        }
        chmax(ans, calc(a, k));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3804
N = gets.to_i
s = Hash.new(0)
N.times do |i|
    cs = Hash.new(0)
    gets.chomp.chars.each do |char|
        cs[char] += 1
    end
    s[cs] += 1
end
ans = 0
s.values.each do |num|
    if num >= 2
        ans += (num * (num - 1)) / 2
    end
end
puts ans

Measured memory_bytes: 139388
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

// int main(){
//     long long N;
//     scanf("%lld",&N);
//     for (long long i = 1; i <= N; i++) {
//         ll cnt=0;
//         for (long long x = 1; x <= 100 ; x++) {
//             if(x*x>i) break;
//             for (long long y = 1; y <= 100 ; y++) {
//                 if(x*x+y*y+x*y>i) break;
//                 for (long long z = 1; z <= 100 ; z++) {
//                     if(x*x+y*y+z*z+x*y+y*z+z*x>i) break;
//                     if(x*x+y*y+z*z+x*y+y*z+z*x==i) cnt++;
//                 }
//             }
//         }
//         cout << cnt << endl;
//     }
//     return 0;
// }

int main(){
    long long N;
    scanf("%lld",&N);
    vector<int> v(10001);
    for (long long x = 1; x <= 100 ; x++) {
        for (long long y = 1; y <= 100 ; y++) {
            for (long long z = 1; z <= 100 ; z++) {
                int r = x*x+y*y+z*z+x*y+y*z+z*x;
                if(r<=10000) v[r]++;
            }
        }
    }
    for (long long i = 1; i <= N; i++) {
        cout << v[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	int a;
	cin>>a;
	rep(i,100)rep(j,100)if(i*4+j*7==a){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}






Measured memory_bytes: 256
<?php
// 入力
$s = trim(fgets(STDIN));

$n = strlen($s);
// 答え出力用配列に0格納
$result = array_fill(0, $n, 0);

$r_top = 0;
// 'R...RL...L'ごとに処理
while($r_top < $n) {
    $l_top = strpos($s, 'L', $r_top);
    $r_last = $l_top - 1;
    $r_next = strpos($s, 'R', $l_top);
    if ($r_next) { // 次の'R'が見つかった場合
        $l_last = $r_next - 1;
    } else { // 次の'R'が見つからない場合
        $l_last = $n - 1;
    }
    $r_cnt = $r_last - $r_top + 1; // 'R'の個数
    $l_cnt = $l_last - $l_top + 1; // 'L'の個数

    // 'RL'の'R'に移動するのは'R'までの距離が偶数の'R'と'L'
    $result[$r_last] = ceil($r_cnt / 2) + floor($l_cnt / 2);
    // 'RL'の'L'に移動するのは'L'までの距離が偶数の'R'と'L'
    $result[$l_top] = floor($r_cnt / 2) + ceil($l_cnt / 2);

    $r_top = $l_last + 1;
}
echo implode(' ', $result).PHP_EOL;

Measured memory_bytes: 35576
N = int(input())

edge = [ [] for _ in range(N) ]
for _ in range(N-1):
  U, V, W = map(int, input().split())
  edge[U-1].append([V-1, W])
  edge[V-1].append([U-1, W])

dist = [-1] * N
dist[0] = 0
q = [0]
while q:
  temp = q.pop()
  for u, v in edge[temp]:
    if dist[u] != -1:
      continue
    dist[u] = dist[temp] + v
    q.append(u)
  
for ans in dist:
  if ans % 2 == 0:
    print(1)
  else:
    print(0)

Measured memory_bytes: 48976
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
int a,b;
  cin >> a >>b;
  int d = a +b;
  if (d >=10) cout <<"error" << endl;
  else cout << d << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

bool solve(int N) {
  for(int i = 0; i * 4 <= N; i++) {
    int	rem = N	- (i * 4);
    if(rem % 7 == 0) return true;
  }
  return false;
}

int main() {
  int N; cin>>N;
  bool ans = solve(N);
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 256
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

S = inputs[0]
ff = S[0..1].to_s.to_i
ll = S[2..3].to_s.to_i

is_yymm = false
is_mmyy = false

# check ll
if ll > 0 && ll <= 12 && ff > 0 && ff <= 12
  is_yymm = true
  is_mmyy = true
elsif (ff > 0 && ff <= 12) && (ll > 12 || ll == 0)
  is_yymm = false
  is_mmyy = true
elsif (ff > 12 || ff == 0) && (ll > 0 && ll <= 12)
  is_yymm = true
  is_mmyy = false
else
  is_yymm = false
  is_mmyy = false
end

if is_yymm && is_mmyy
  puts "AMBIGUOUS"
elsif !is_yymm && !is_mmyy
  puts "NA"
elsif is_yymm && !is_mmyy
  puts "YYMM"
elsif !is_yymm && is_mmyy
  puts "MMYY"
end

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int H = ni();
        int N = ni();
        ArrayList<ArrayList<Integer>> ab = new ArrayList<>();
        int maxa = 0;
        for (int i = 0; i < N; i++) {
            int a = ni();
            int b = ni();
            var abi = new ArrayList<Integer>();
            abi.add(a);
            abi.add(b);
            ab.add(abi);
            if(maxa < a) maxa = a;
        }
        int[] dp = new int[H+maxa+1];
        for (int i = 1; i < dp.length; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        for (int i = 1; i < dp.length; i++) {
            for (var a_b : ab) {
                int from = Math.max(0,i-a_b.get(0));
                dp[i] = Math.min(dp[i],dp[from]+a_b.get(1));
            }
        }
        int ans = Integer.MAX_VALUE;
        for (int i = H; i < dp.length; i++) {
            ans = Math.min(ans, dp[i]);
        }
        
        out.println(ans);
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 35212
n = int(input())
res = 1
ls = input().split(' ')
list.sort(ls)
if int(ls[0]) == 0:
    print(0)
    exit()
for a in ls:
    res = res * int(a)
    if res > 1000000000000000000:
        print(-1)
        exit()
print(res)


Measured memory_bytes: 19212