akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  double a;
  string s;
  P(string s, double a):a(a),s(s) {}
};

bool operator<(const P &a, const P &b) {
  return a.a!=b.a ? a.a>b.a : a.s<b.s;
}
  
int main() {
  int n;
  while(cin>>n,n) {
    vector<P> v;
    REP(i,n) {
      string ss;
      cin >> ss;
      double p,a,b,c,d,e,f,s,m;
      cin >> p>>a>>b>>c>>d>>e>>f>>s>>m;
      double hoge = (m*s*f-p)/(a+b+c+(d+e)*m);
      v.push_back(P(ss,hoge));
    }
    sort(ALL(v));
    FOR(it, v)
      cout << it->s << endl;
    cout << "#"<<endl;
  }
}

Measured memory_bytes: 0
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    int n, k; cin >> n >> k;
    double ans = 0;
    repi(i,1,n+1){
        int now = i;
        double cnt = 1;
        while(now<k){
            now <<= 1;
            cnt /= 2;
        }
        ans += cnt;
    }
    ans /= n;
    cout << ans << '\n';
    
}


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

int d[100000], x[100000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++)
    cin >> x[i];
  sort(x, x+m);

  for (int i = 1; i < m; i++)
    d[i-1] = x[i]-x[i-1];
  sort(d, d+m-1);
  ll ans = 0;
  for (int i = 0; i < max(0,m-n); i++) {
    ans += d[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define For(i, a, b)       for(int i = a; i <= b; ++i)
#define Ford(i, a, b)      for(int i = a; i >= b; --i)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define FileName           "test"
#define ll                 long long
#define ld                 long double
#define ull                unsigned long
#define Print(x)           cerr << #x << "is " << x << '\n';
#define pb                 push_back
#define ep                 emplace_back
#define X                  first
#define Y                  second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template<typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template<typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template<typename T, typename... Args> inline void Cin(T& a, Args&... args){Cin(a);Cin(args...);}
template<typename T, typename... Args> inline void Cout(T x, char c, Args... args){Cout(x, c);Cout(args...); }

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 207;
const int M = 1e5 + 7;
const ll oo = 1e18 + 7;

struct TVal{ll w, v;} t[N];
ll n, m, cnt = 0, f[M], g[M], w, v, k;

void Enter()
{
     Cin(n, m);
     For(i, 1, n) Cin(t[i].w, t[i].v);
}

void Solve()
{
     fill_n(f, M, oo);
     fill_n(g, M, oo);
     f[0] = g[0] = 0;
     For(i, 1, n)
     {
         For(j, 0, int(1e5))
         {
             if(g[j] == oo) continue;
             if(t[i].v + j < M) f[j + t[i].v] = min(f[j + t[i].v], g[j] + t[i].w);
         }
         For(j, 0, int(1e5)) g[j] = min(g[j], f[j]), f[j] = g[j];
     }
     Ford(i, int(1e5), 0)
     {
         if(g[i] <= m) {cout << i; exit(0);}
     }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-1)a[i+1]+=a[i];
    ll ans = longinf;
    rep(i,n-1){
        ans = min(ans,abs(2*a[i]-a[n-1]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

a,b,c = list(map(int, sys.stdin.buffer.readline().split()))
k = int(sys.stdin.buffer.readline())

cnt = 0
while a >= b:
    b *= 2
    cnt += 1
while b >= c:
    c *= 2
    cnt += 1
if cnt <=k:
    print('Yes')
else:
    print('No')


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

int main(){
    int n;
    cin>>n;
    int a[200010];
    a[1]=1;
    int ans[200010]={0};
    for(int i=1;i<n;i++){
        cin>>a[i+1];
        ans[a[i+1]]++;
    }
    rep(i, n){
        cout<<ans[i+1]<<endl;
    }
}

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


int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;

int x = c-a, y = d-b ;
cout << c-y << " " << d+x <<" " << a-y<<" "<<b+x<<endl;

}

Measured memory_bytes: 256
import sys

# %%

n, m = list(map(int, sys.stdin.readline().split()))
ary = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
bry = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
mod = 10 ** 9 + 7

# %%

if len(set(ary)) != len(ary) or len(set(bry)) != len(bry):
    print(0)

else:
    ary.append(0)
    bry.append(0)

    cnt = 1
    i = 0
    j = 0
    for num in range(n * m, 0, -1):

        if (num == ary[i]) & (num == bry[j]):
            i += 1
            j += 1

        elif (num == ary[i]) ^ (num == bry[j]):
            if num == ary[i]:
                cnt *= len(bry[:j])
                i += 1
            else:
                cnt *= len(ary[:i])
                j += 1

        else:
            cnt *= (i * j - (n * m - num))

        cnt = cnt % mod

    print(cnt)


Measured memory_bytes: 3188
#include<iostream>

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);

    int a[3];
    std::cin >> a[0] >> a[1] >> a[2];

    int k;
    std::cin >> k;

    int max_n;
    int exclude;
    if(a[0] >= a[1] && a[0] >= a[2]){
        max_n = a[0];
        exclude = 0;
    }
    else if(a[1] >= a[0] && a[1] >= a[2]){
        max_n = a[1];
        exclude = 1;
    }
    else if(a[2] >= a[0] && a[2] >= a[1]){
        max_n = a[2];
        exclude = 2;
    }

    for(int i = 0 ; i < k ; ++i){
        max_n *= 2;
    }

    int sum = 0;
    for(int i = 0 ; i < 3 ; ++i){
        if(i == exclude) sum += max_n;
        else sum += a[i];
    }

    std::cout << sum;

    return 0;

}

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

const int maxn = 1<<18;
int n, a[maxn], sa[maxn], b[maxn];

struct segt {
	int t[maxn*2];
	void update(int s, int e, int x, int p, int v) {
		if (s==e) t[x] += v;
		else {
			int m = (s+e)/2;
			if (p<=m) update(s, m, 2*x, p, v);
			else update(m+1, e, 2*x+1, p, v);
			t[x] = t[2*x] + t[2*x+1];
		}
	} void update(int p, int v) { update(0, maxn-1, 1, p, v); }
	int query(int s, int e, int x, int l, int r) {
		if (l<=s and e<=r) return t[x];
		else if (l<=e and s<=r) {
			int m = (s+e)/2;
			return query(s, m, 2*x, l, r) + query(m+1, e, 2*x+1, l, r);
		} else return 0;
	} int query(int l, int r) { return query(0, maxn-1, 1, l, r); }
} t;

bool able(int k) { b[0] = 0;
	for (int i=1; i<=n; i++) b[i] = a[i] >= k;
	for (int i=2; i<=n; i++) b[i] += b[i-1];
	for (int i=1; i<=n; i++) b[i] *= 2;
	for (int i=1; i<=n; i++) b[i] -= i;
	for (int i=0; i<=n; i++) b[i] += maxn/2;
	for (int i=0; i<maxn*2; i++) t.t[i] = 0;
	for (int i=0; i<=n; i++) t.update(b[i], 1);
	long long ans = 0;
	for (int i=0; i<n; i++) {
		t.update(b[i], -1);
		ans += t.query(b[i], maxn-1);
	}
	return 2*ans >= n*(long long)(n+1)/2;
}

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

	cin >> n;
	for (int i=1; i<=n; i++) cin >> a[i], sa[i] = a[i];

	sort(sa+1, sa+n+1);

	int l = 1, r = n+1;
	while (l+1<r) {
		int m = (l+r)/2;
		if (able(sa[m])) l = m;
		else r = m;
	}

	cout << sa[l];
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

    ll d = 0;
    ll s = 0;
    rep(i, m){
        ll x, c;
        cin >> x >> c;
        d += c;
        s += x*c;
    }
    
    ll ans = (d-1) + (s-1)/9;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int N,T;
    cin>>N>>T;
    int c[N],t[N];
    rep(i,0,N-1){
        cin>>c[i]>>t[i];
    }
    int min=10000;
    bool flag=false;
    rep(i,0,N-1){
        if(t[i]<=T){
            if(min>c[i]){
                min = c[i];
                flag = true;
            }
        }
    }
    if(flag) cout<<min<<endl;
    else cout<<"TLE"<<endl;
    return 0;
}

Measured memory_bytes: 380
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
int main(){
    ll N;
    ll A,B;
	cin >> N >> A >> B;
    ll ans = (N/(A+B))*A;
    ll res = N%(A+B);
    ans += min(res,A);
	cout << ans << endl;
	return 0; 
}

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

int main()
{
  string s;
  string a[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  cin>>s;
  for(int i=0;i<7;i++)
  {
	if(s==a[i])
      cout<<(7-i);
  }
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 string S; cin >> S;
 
  if( S == "Sunny"){ cout << "Cloudy" << endl;}
  if( S == "Cloudy"){ cout << "Rainy" << endl;}
  if( S == "Rainy"){ cout << "Sunny" << endl;}
  return 0;}

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


int main(){
  int n,m;cin>>n>>m;
  int k;
  int a[m+1]={};
  int b;
  fol(i,n){
    cin>>k;
    fol(j,k){
      cin>>b;
      a[b]++;
    }
  }
  int ans = 0;
  fol(i,m+1){
    if(a[i]==n)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
x = [int(i) for i in input().split()]

def gcd(a, b) :
    while b != 0 :
        a, b = b, a % b
    return a

diff = [abs(x[i] - X) for i in range(N)]
ret = diff[0]
for i in range(1, N) :
    ret = gcd(ret, diff[i])
print(ret)

Measured memory_bytes: 63640
#coding: utf-8
import math

def yis(z):
    y = int(math.floor(math.sqrt(e - z * z * z)))
    return y

while True:
    e = int(raw_input())
    y = 0
    z = 0
    if e == 0:
        break
    for i in range(102):
        if i * i * i > e:
            z = i - 1
            break
    n = z
    m = e
    for i in range(n + 1):
        y = yis(z)
        m = min(m,e - y * y - z * z * z + y + z)
        z = z - 1
    print m

    

Measured memory_bytes: 6360
# -*- coding: utf-8 -*-


def main():
    d = int(input())

    if d == 25:
        print('Christmas')
    elif d == 24:
        print('Christmas Eve')
    elif d == 23:
        print('Christmas Eve Eve')
    elif d == 22:
        print('Christmas Eve Eve Eve')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import sys
from collections import deque
from itertools import *

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

x = LS()

for i,xx in enumerate(x):
    if xx == '0':
        print(i+1)
        exit() 

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    long N, ans = 1;
    cin >> N;
    vl A(N);
    REP(i, 0, N){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    REP(i, 0, N){
        ans *= A[i];
        if(i != N-1 && ans > 1000000000000000000/ A[i+1]){
            cout << -1 << endl;
            return 0;
        };
    }

    cout << ans << endl;
}

Measured memory_bytes: 3976
#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> d(N);rep(i,N) cin>>d[i];
  
  sort(d.begin(),d.end());
  ll ans=d[N/2]-d[N/2-1];
  
  cout << ans << endl;
}


Measured memory_bytes: 4040
A = int(input())
B = int(input())
if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)
elif (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)
elif (A == 2 and B == 3) or (A == 3 and B == 2):
    print(1)

Measured memory_bytes: 3064
def main():
	wordCount = {}
	W = input()
	while True:
		line = input()
		if line == 'END_OF_TEXT':
			break
		line = line.lower()
		for word in line.split():
			if word in wordCount:
				wordCount[word] += 1
			else:
				wordCount[word] = 1
	print(wordCount[W])
	
main()



Measured memory_bytes: 5564
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X, Y := ReadInt(), ReadInt()
	c := 0
	for X <= Y {
		c++
		X <<= 1
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
vec = []
loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?

  vec << [h, w]
end

vec.each do |v|
  h = v[0]
  w = v[1]

  h.times do |i|
    w.times do |j|
      x = i + j
      if x.even?
        print '#'
      else
        print '.'
      end
    end
    puts ''
  end
  puts ''
end



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m; 
  cin>>n>>m;
  vector< pair<int64_t, int64_t> > vec(n);
  int64_t money=0;
  int64_t cnt=0;

  for (int i = 0; i < n; i++) {
    int64_t a,b;
    cin>>a>>b;
    vec.at(i) = make_pair(a,b);
  }

  sort(vec.begin(), vec.end());

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

    if (cnt >= m) break;
    int64_t tmp = vec.at(i).second;
    if (tmp+cnt > m) tmp = m-cnt;
    money += vec.at(i).first * tmp;
    cnt += tmp;
  }
  cout<<money<<endl;
}


Measured memory_bytes: 1792
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    int v=count(ALL(s),'A');
    if(v==3||v==0)W("No");
    else W("Yes");
    return 0;
}


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

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;
    cout << t2 - k - t1 << endl;
    return 0;
}

Measured memory_bytes: 3644
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

answer = 0
for i in range(1, N):
    if (X[i] - X[i-1]) * A > B:
        answer += B
    else:
        answer += (X[i] - X[i-1]) * A
print(answer)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << setprecision(30) << (ld) w / 2.0 * (ld) h << " ";
    cout << (x * 2 == w && y * 2 == h) << endl;

    return 0;
}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

antenas=[a,b,c,d,e]
teste = 1

for i in range(len(antenas)):
    for j in range(len(antenas)):
        if antenas[j]-antenas[i] > k:
            teste = 0
            break
if teste:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   int ans = 0;
   if (s[0] == '1') ans++;
   if (s[1] == '1') ans++;
   if (s[2] == '1') ans++;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.5
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 2)

    i = 1
    for t, v in zip(T, V):
        # error_print(vs)
        if vs[i-1] > v:
            j = 0
            while abs(vs[i-1-j] - vs[i-1-j+1]) > 0.001:
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
                j += 1

        for _ in range(t*int(1/df)):
            vs[i] = min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2

    # print('\t'.join(map(lambda x: str(x[1]),
    #                     filter(lambda x: x[0] % 2 == 0, zip(range(len(vs)), vs))))
    #       )
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()

    print(slv(N, T, V))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63340
#include<bits/stdc++.h>
#define ll long long
#define pub push_back 
#define pob pop_back 
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
using namespace std ;
int main()
{
	int a  ;
	cin >> a ;
	int arr[a] ;
	fo(i, a)
		cin >> arr[i] ;
	int flag = 1 ;
	for(int i = a-2 ; i >= 0 ; i--)
	{
	    if(arr[i] > arr[i+1])
	        arr[i] -- ;
	}
	for(int i = 1 ; i < a ; i++)
	    if(arr[i] < arr[i-1])
	        flag = 0 ;
	if(flag)
		cout << "Yes" << endl; 
	else
		cout << "No" << endl;
	
	return 0 ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int a,b;
    cin>>a>>b;
    int sum=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]){
            sum++;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

table = {i: [0]*(W+1) for i in range(N+1)}
def dp(N, W):
  for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
      if w <= j:
        table[i][j] = max(table[i-1][j-w]+v, table[i-1][j])
      else:
        table[i][j] = table[i-1][j]
  return table[N][W]

print(dp(N, W))

Measured memory_bytes: 118256
#include<cstdio>

int main(int argc, char const *argv[])
{
    int a, b;
    while(scanf("%d %d", &a, &b) != EOF){
        int c = a+b;
        int cnt = 0;
        while(c!=0){
            c /= 10;
            cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}



Measured memory_bytes: 2564
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  bool ans = true;
  REP(0, N, i) {
    i64 A;
    cin >> A;
    if(A % 2 == 0 && (A % 3 != 0 && A % 5 != 0))
      ans = false;
  }
  cout << (ans ? "APPROVED" : "DENIED") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int n;
	cin>>n;
	int ma=1000000000000;
	int ans=0;
	for (int i=0;i<n;i++){
		int y;
		cin>>y;
		if (y<=ma){
			ans++;
			ma=y;
		}
	}
	cout<<ans;
	re 0;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

template <class T>
struct SegTree {
    int n;
    T identity;
    std::vector<T> values;
    std::function<T(T, T)> operateF;
    std::function<T(T, T)> updateF;

    SegTree(
        int n,
        T identity,
        std::function<T(T, T)> operateF,
        std::function<T(T, T)> updateF
    ) {
        this->identity = identity;
        this->operateF = operateF;
        this->updateF = updateF;

        int node = 1;
        while (node < n) node *= 2;
        this->n = node;
        this->values = std::vector<T>(2*node-1, identity);
    }

    void update(int i, T x) {
        i += n - 1;
        values[i] = updateF(values[i], x);
        while (i > 0) {
            i = (i-1) / 2;
            values[i] = operateF(values[i*2+1], values[i*2+2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i) {
        return values[i+n-1];
    }

private:
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return identity;
        if (a <= l && r <= b) return values[k];

        T childL = _query(a, b, 2*k+1, l, (l+r)/2);
        T childR = _query(a, b, 2*k+2, (l+r)/2, r);
        return operateF(childL, childR);
    }
};

int n, q;

int main() {
    cin >> n >> q;
    SegTree<ll> t = SegTree<ll>(
        n, INT_MAX,
        [](const ll& a, const ll& b) {
            return min(a, b);
        },
        [](const ll& a, const ll& b) {
            return b;
        }
    );

    REP(i, q) {
        int c, x, y; cin >> c >> x >> y;
        if (c == 0) {
            t.update(x, y);
        } else {
            cout << t.query(x, y+1) << '\n';
        }
    }

    return 0;
}



Measured memory_bytes: 4908
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

const vector<int> dx4 = {-1,  0,  1,  0};
const vector<int> dy4 = { 0,  1,  0, -1};
const vector<int> dx8 = {-1, -1, -1,  0,  1,  1,  1,  0};
const vector<int> dy8 = {-1,  0,  1,  1,  1,  0, -1, -1};

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

    long long ans = 1;

    for(int i = 1; i <= n; i++){
        ans *= i;
        ans %= (1000000007);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;


int main() {
  int k, t;
  cin >> k >> t;
  int ma = 0;
  for (int i = 0; i < t; ++i) {
    int a;
    cin >> a;
    ma = max(a, ma);
  }
  if (t == 1) {
    cout << ma - 1 << '\n';
  } else {
    int ans = max(0, ma - 1 - (k - ma));
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d);
}


Measured memory_bytes: 256
//
//  main.cpp
//  uecontest2
//
//  Created on 2020/04/29.
//  Copyright © 2020 エロやん. All rights reserved.
//

#include <iostream>
using namespace std;
int main(){
    int N,A,B;
    cin>>N>>A>>B;
    if(N*A<=B)
        cout<<N*A;
    else
        cout<<B;
    
    
    return 0;
}


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

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

int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll>a(n),b(m);
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    
    ll A[n+1];ll B[m+1];
    A[0]=0;B[0]=0;
    for(ll i=1;i<=n;i++)
    A[i] = A[i-1]+ a[i-1];
    
    for(ll i=1;i<=m;i++)
    B[i] = B[i-1]+ b[i-1];
    
 int j=m;
 int ans=0;
 rep(i,n+1)
 {
     if(A[i] > k)
     break;
     while(B[j] > k-A[i])j--;
     ans = max(ans,i+j);
 }
    cout<<ans<<endl;
}

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

int main(void)
{
        int n,d;
        std::cin >> n;
        std::cin >> d;

        auto one_man = d*2+1;
        auto ans = n / one_man + (n % one_man != 0? 1 : 0);
        std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
a = []
for i in range(n):
    a.append(inn())
accl = [0] * (n+1)
accr = [0] * (n+1)
for i in range(n):
    accl[i] = max(accl[i-1], a[i])
for i in range(n-1,-1,-1):
    accr[i] = max(accr[i+1], a[i])
for i in range(n):
    print(max(accl[i-1], accr[i+1]))


Measured memory_bytes: 16056
S = input()
N = len(S)
res = False
P = []
L = []
K = []
for s in range(N):
    P.append(S[s])
L = P[:(N-1)//2]
K = P[(N+3)//2-1:N]
if L == K:
    res = True
if res:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9116
A, B, H, M = gets.split.map(&:to_i)

hdig = 2 * Math::PI * (H / 12.0 + M / 12.0 / 60.0)
mdig = 2 * Math::PI * M / 60.0
theta = hdig - mdig

a = A * Math.sin(theta)
b = B - A * Math.cos(theta)
puts Math.sqrt(a ** 2 + b ** 2)


Measured memory_bytes: 14780
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14


using namespace std;


struct Edge {
    int from;
    int to;
    int cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const Edge& edge) const {
        return this->cost < edge.cost;
    }
    bool operator>(const Edge& edge) const {
        return this->cost > edge.cost;
    }
};

class UnionFind {
public:
    vector<int> parent;
    vector<int> setSize;

    UnionFind(unsigned int size) {
        parent.resize(size + 1);
        iota(parent.begin(), parent.end(), 0);
        setSize.resize(size + 1, 1);
    }

    // x??¨y???????????????????±??????????
    bool isSameSet(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    // x??¨y????±??????????????????????
    void unionSet(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) { return; }

        parent[x] = y;
        setSize[y] += setSize[x];
    }

private:
    // ??¨??????????±???????
    int findRoot(int x) {
        if (parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = findRoot(parent[x]);
        }
    }
};


int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    UnionFind uf(n);
    FOR(i, 0, q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            uf.unionSet(x, y);
        }
        else {
            cout << uf.isSameSet(x, y) << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3292
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll, int> Node;

ll cost[100005], ans;
int p[100005];

priority_queue<Node, vector<Node>, greater<Node>> st[100005], q;

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

bool merge(int a, int b) {
	a = find(a), b = find(b);
	if (a == b) return 0;
	if (st[a].size() < st[b].size()) swap(a, b);
	while (!st[b].empty()) {
		st[a].push(st[b].top()); st[b].pop();
	}
	p[b] = a;
	return 1;
}

int main() {
	int N, M; scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%lld", cost + i);
		p[i] = i;
		st[i].push({cost[i], i});
	}
	int remain = N - 2 - M;
	if (remain < 0) return !printf("0");
	while (M--) {
		int a, b; scanf("%d %d", &a, &b);
		if (!merge(a, b)) return !printf("Impossible");
	}

	for (int i = 0; i < N; i++) if (i == find(i)) {
		ans += st[i].top().first; st[i].pop();
		while (!st[i].empty()) {
			q.push(st[i].top());
			st[i].pop();
		}
	}
	while (remain && !q.empty()) {
		ans += q.top().first; q.pop();
		remain--;
	}
	if (remain) puts("Impossible");
	else printf("%lld", ans);
}

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

using namespace std;

const int N = 1299709;

vector<int> prime;
bool is_prime[N + 1];

void sieve(){
  fill(is_prime, is_prime+N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=N;i++){
    if(is_prime[i]){
      prime.push_back(i);
      for(int j=2*i;j<=N;j+=i) is_prime[j] = false;
    }
  }
}

int solve(int n){
  if(is_prime[n]) return 0;
  vector<int>::iterator it = upper_bound(prime.begin(), prime.end(), n);
  int r = *it;
  *it--;
  int l = *it;
  return r-l;
}

main(){
  int n;
  sieve();
  while(cin >> n && n){
    cout << solve(n) << endl;
  }
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N,M;
string S;
ll dp [3001] [3001];
const ll MOD = 1e9 + 7;

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

	cin >> N >> M >> S;
	vector< pair<int,int> > A(M);
	FOR(i,0,M){
		cin >> A [i].first >> A [i].second;
		A [i].first--;
	}

	dp [0] [0] = 1;
	int idx = 0,r = 0;
	FOR(i,0,N){
		int cnt = 0;
		if(r == i){
			cnt += S [i] == '0';
			r++;
		}
		while(A [idx].first <= i){
			FOR(j,r,A [idx].second){
				cnt += S [j] == '0';
			}
			chmax(r,A [idx].second);
			idx++;
		}
		for(int j = 0;j <= N;j++) if(dp [i] [j]){
			if(j + cnt > 0){
				(dp [i + 1] [j + cnt - 1] += dp [i] [j]) %= MOD;
			}
			if((r - i) - (j + cnt) > 0){
				(dp [i + 1] [j + cnt] += dp [i] [j]) %= MOD;
			}
		}
	}

	printf("%lld\n",dp [N] [0]);


	return 0;
}


Measured memory_bytes: 12672
N, M = map(int, input().split())
cnt = [0] * N
for i in range(M):
	a, b = map(lambda x: int(x) - 1, input().split())
	cnt[a] += 1
	cnt[b] += 1

for i in range(N):
	if cnt[i] % 2 != 0:
		print("NO")
		exit()
print("YES")

Measured memory_bytes: 9676
// AOJ 1338: Clock Hands
// 2017.12.7 bal4u@uu

#include <stdio.h>

long long gcd(long long a, long long b)
{
	long long r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int main()
{
    int H, h, m, s;
	long long c3600, ha, ma, sa, a1, a2, g, d, n;

    while (scanf("%d%d%d%d", &H, &h, &m, &s) && H > 0) {
        d = 119*H - 1;
		c3600 = 3600*H*d;
        n = s * d;
        while (1) {
            ha = (60 * h + m) * 60*d + n;
            ma = 60 * H * m * d + n * H;
            sa = 60 * H * n;
            ma = (ma - ha) % c3600;
            sa = (sa - ha) % c3600;
            if (ma < 0) ma += c3600;
            if (sa < 0) sa += c3600;
            if (ma != 0) {
                if (ma < sa) a1 = c3600 - sa, a2 = sa - ma;
                else         a1 = sa, a2 = ma - sa;
                if (a1 == a2) break;
            }
            n++;
            if (n == 60 * d) m++, n = 0;
            if (m == 60) m = 0, h++;
            if (h == H) h = 0;
        }
        g = gcd(n, d);
        printf("%d %d %d %d\n", h, m, (int)(n/g), (int)(d/g));
    }
}

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

int main() {
	int N;
	string s, t;
	cin >> N >> s >> t;

	int len = s.size() + t.size();
	for (int i = 1; i <= min(s.size(), t.size()); ++i) {
		bool ok = true;
		for (int j = 0; j < i; ++j) {
			if (s[s.size() - i + j] != t[j]) { ok = false; }
		}

		if (ok) { len = len - i; }
	}

	if (len < N) { len = N; }

	cout << len << endl;

	return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String{ let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!(N:i32,T:i32,A:i32,H:[i32;N]);
    let mut HandI = Vec::new();
    for i in 0..H.len() as i32{HandI.push((H[i as usize],i+1));}
    print!("{}",HandI.into_iter().min_by_key(|&(x,_)| (T*1000-x*6-A*1000).abs()).unwrap().1);
}

Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define mid (l+r>>1)
#define M 1020
using namespace std;
int read(){
	int nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
void fail(){puts("IMPOSSIBLE");exit(0);}
int n,F[M],fa[M],fs[M],sz[M],c[M][M],G[M];
bool tg[M<<4];
void DP(int x){
	F[x]=0;
	int minn=0,tot=0,maxn=0,top=0;
	for(int i=1;i<=sz[x];i++){
	    DP(c[x][i]),tot+=G[c[x][i]]+F[c[x][i]];
	    minn+=min(G[c[x][i]],F[c[x][i]]);
	}
	if(minn>G[x]) fail();
	for(int i=1;i<=G[x]-minn;i++) tg[i]=false;
	for(int i=1;i<=sz[x];i++){
		int dt=abs(G[c[x][i]]-F[c[x][i]]);
		for(int pos=maxn;pos>=0;pos--){
			if(!tg[pos]) continue;
			maxn=max(maxn,min(G[x]-minn,pos+dt));
			tg[pos+dt]=true;
		}
	}
	for(int i=maxn;i>=0;i--) if(tg[i]){F[x]=tot-(minn+i);return;}
}
int main(){
	n=read(),tg[0]=true;
	for(int i=2;i<=n;i++) fa[i]=read(),c[fa[i]][++sz[fa[i]]]=i;
	for(int i=1;i<=n;i++) G[i]=read();
	DP(1),puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int cnt = 0;
void go(int a, int b, int c, int prev_a, int prev_b, int prev_c) {
    if (a % 2 == 1 or b % 2 == 1 or c % 2 == 1) return;
    if (a == prev_a and b == prev_b and c == prev_c) {
        cnt = -1;
        return;
    }
    cnt++;
    go(b/2 + c/2, a/2 + c/2, a/2 + b/2, a, b, c);
}
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    go(a, b, c, -1, -1, -1);
    cout << cnt << '\n';
   
    return 0;
}

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

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.assign(n, -1);
    treerank.assign(n, 0);
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[y];
    par[y] -= size(x);
    par[x] = y;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

int n, q;

int main() {
  cin >> n >> q;
  Unionfind uf(n);
  for(int i = 0; i < q; ++i) {
    int c, x, y;
    cin >> c >> x >> y;
    if(c)
      cout << uf.issame(x, y) << endl;
    else
      uf.uni(x, y);
  }
  return 0;
}



Measured memory_bytes: 3172