akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N, D, X;
  ci(N, D, X);
  int a = 0;
  ve<int> A(N);
  rep(i, N){
    int c = 0;
    ci(A.at(i));
    wh(c < D){
      c += A.at(i);
      a ++;
    }
  }
  co(a + X);
}


Measured memory_bytes: 256
n,w = map(int,input().split())
weighta = []
weightb = []
weightc = []
weightd = []
for i in range(n):
	wtemp,vtemp = map(int,input().split())
	if i == 0:
		weighta.append(vtemp)
		first = wtemp
	elif wtemp == first:
		weighta.append(vtemp)
	elif wtemp == first+1:
		weightb.append(vtemp)
	elif wtemp == first+2:
		weightc.append(vtemp)
	elif wtemp == first+3:
		weightd.append(vtemp)

weighta.sort()
weighta.reverse()
weightb.sort()
weightb.reverse()
weightc.sort()
weightc.reverse()
weightd.sort()
weightd.reverse()

cuma = [0]
for i in range(len(weighta)):
	cuma.append(weighta[i]+cuma[i])
cumb = [0]
for i in range(len(weightb)):
	cumb.append(weightb[i]+cumb[i])
cumc = [0]
for i in range(len(weightc)):
	cumc.append(weightc[i]+cumc[i])
cumd = [0]
for i in range(len(weightd)):
	cumd.append(weightd[i]+cumd[i])

wa = first
wb = first+1
wc = first+2
wd = first+3

max = 0
for a in range(len(weighta)+1):
	for b in range(len(weightb)+1):
		for c in range(len(weightc)+1):
			for d in range(len(weightd)+1):
				if wa*a + wb*b + wc*c + wd*d <= w:
					t = cuma[a]-cuma[0] + cumb[b]-cumb[0] + cumc[c]-cumc[0] + cumd[d]-cumd[0]
					if t > max:
						max = t
print(max)

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

int main(){
  string S,T;
  cin>>S>>T;
  bool A=true;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)!=T.at(i)){
      A=false;
    }
  }
  if(A){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main(int argc, char *argv[]) {
  int N;
  cin >> N;
  N += 2;
  int A[N];
  for(int i = 1; i < N - 1; i++) {
    cin >> A[i];
  }
  A[0] = 0;
  A[N - 1] = 0;
  int sum = 0;
  for(int i = 0; i < N - 1; i++) {
    sum += abs(A[i + 1] - A[i]);
  }
  for(int i = 1; i < N - 1; i++) {
    if(A[i - 1] <= A[i] && A[i] <= A[i + 1]) {
      cout << sum << endl;
    } else {
      int ans = sum - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1]);
      cout << ans << endl;
    }
  }
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, L;
    cin >> n >> L;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += L + i - 1;
    }
    int ans = 0;
    int hoge = 1145141919;
    for (int i = 1; i <= n;i++) {
        int foo = 0;
        for (int j = 1; j <= n; j++) {
            if (j == i) continue;
            foo += L + j - 1;
        }
        int bar = abs(foo - sum);
        if (hoge > bar) {
            hoge = bar;
            ans = foo;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n,pd[100002];
vector<int> A;
int dp(int id){
    if(id==n-1) return 0;
    if(pd[id]!=-1) return pd[id];
    if(id+2<=n-1){
        return pd[id] = min(dp(id+1)+abs(A[id]-A[id+1]),dp(id+2)+abs(A[id]-A[id+2]));
    }
    return pd[id] = dp(id+1)+abs(A[id]-A[id+1]);
}
int main(){
    memset(pd,-1,sizeof pd);
    cin >> n;
    A = vector<int> (n);
    for(auto &a:A) cin >> a;
    cout << dp(0) << '\n';
    
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if(i==0||j==0||i==h-1||j==w-1)
        cout<<"#";
        else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

using Graph = vector<vector<int>>;

//深さ優先探索
vector<bool> seen;
map<P, int> mp;
int ans = 0;
void dfs(const Graph &G, int v, int color){
  seen[v] = true; // v を訪問済みにすru
  int cou = 1;

  // vから行ける各頂点 next_v について
  for(auto nv : G[v]){
    if (seen[nv]) continue; // next_v が探索済みだったらスルー
    if(cou == color) cou++;
    mp[P(v, nv)] = cou;
    dfs(G, nv, cou); // 再帰的に探索
    cou++;
  } 
  ans = max(ans, cou-1);
}

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

  int N; cin >> N;
  P P1[N-1];
  
  Graph G(N);
  for(int i=0;i<N-1;i++){
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
    P1[i] = P(A, B);
  }

  seen.assign(N, false); // 全頂点を「未訪問」にして初期化
  dfs(G, 0, 0);

  cout << ans << endl;

  rep(i,N-1){
      cout << mp[P1[i]] << endl;
  }

}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;
int N, M;
vector<vector<int>> g;
vector<bool> visited;

int dfs(int u){
    bool visited_all = true;
    for (int i=0;i<N;i++){
        if (!visited[i]) visited_all = false;
    }
    if (visited_all){
        return 1;
    }
    int res = 0;
    for (int v: g[u]){
        if (visited[v]) continue;
        visited[v] = true;
        res += dfs(v);
        visited[v] = false;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    g = vector<vector<int>>(N);
    visited = vector<bool>(N,false);
    for (int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    visited[0] = true;
    int ans = dfs(0);
    cout << ans << "\n";
}

Measured memory_bytes: 3632
n = int(input())
s = input()
ans = []
for i in range(1, n):
  x = set()
  y = set()
  for e in s[:i]:
    x.add(e)
  for e in s[i:]:
    y.add(e)
  ans.append(len(list(x & y)))
print(max(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int N = 5001, MOD = 1e9 + 7;
int dp[N][N][2] = {}, ok[N][N][2] = {};
inline void add (int &val, int x) {
    val += x;
    if (val >= MOD) val -= MOD;
    if (val < 0) val += MOD;
}
inline int mul (int a, int b) {
    return ((ll)a * b) % MOD;
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    ok[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k < 2; k++) {
                if (!ok[i][j][k]) continue;
                add(ok[i + 1][j + 1][k], mul(ok[i][j][k], 2));
                add(ok[i + 1][max(0, j - 1)][k | (j == 0)], ok[i][j][k]);
            }
        }
    }
    int k = (int)s.length();
    int ans = (ok[n][k][0] + ok[n][k][1]) % MOD;
    for (int i = 0; i < k; i++) ans = mul(ans, 500000004);
    cout << ans << '\n';
}


Measured memory_bytes: 195072
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
lli dp[N],n,k,a[105];
//lli calc(int i,int sum){
//	if(sum>k) return 0;
//	if(i==n&&sum==k) return 1;
//	else if(i==n) return 0;
//	if(dp[i][sum]!=-1) return dp[i][sum];
//	lli add=0;
//	for(int j=0;j<=a[i];j++){
//		add=(add+calc(i+1,sum+j))%mod;
//	}
//	return dp[i][sum]=add;
//}
int main(){
	fast
	cin>>n>>k;
	mem(dp,0);
	dp[0]=1LL;
	FOR0(n) cin>>a[i];
	for(int i=0;i<n;i++){
		lli pr[k+1];
		mem(pr,0);
		for(int us=k;us>=0;us--){
			lli add=dp[us];
			int l=us+1;
			int r=us+min(a[i],k-us);
			if(l<=r){
				pr[l]=(pr[l]+add)%mod;
				if(r+1<=k){
					pr[r+1]=(pr[r+1]-add+mod)%mod;
				}
			}
		}
		lli sm=0;
		for(int i=0;i<=k;i++){
			sm=(sm+pr[i])%mod;
			dp[i]=(dp[i]+sm)%mod;
		}
	}
//	FOR0(k+1) cout<<dp[i]<<" ";cout<<endl;
	cout<<dp[k];
}



Measured memory_bytes: 1792
import sys

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    return fac, ifac

fac, ifac = make_table(5*10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

def nHr(n, r):
    return comb(n-1+r, r)

n, k = map(int, sys.stdin.readline().split())
if k >= n:
        k = n - 1

def main():
    res = nHr(n, n)
    for i in range(1, n-k):
        res -= comb(n, i) * nHr(i, n-i) % MOD
        res %= MOD
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(){
  int N;
  cin >> N;
  map<string, vector<pair<int, int>>> book;
  for(int i = 0; i < N; i++){
    string ts;
    vector<pair<int, int>> tp;
    tp.push_back(make_pair(0, i+1));
    cin >> ts >> tp.at(0).first;
    if(book.count(ts)) book[ts].push_back(tp.at(0));
    else book.insert(make_pair(ts, tp));
  }
  for(auto itr: book){
    sort(itr.second.begin(), itr.second.end());
    reverse(itr.second.begin(), itr.second.end());
    for(int i = 0; i < itr.second.size(); i++){
      cout << itr.second.at(i).second << endl;
    }
  }
}

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

int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    int sum = 0;
    int r = 0;

    for(int l = -1; l < N; l++){
        if(l != -1) sum -= A[l];
        //printf("%d %d %d\n", l, r, sum);
        while((A[r] & sum) == 0 && r < N){
            sum += A[r];
            r++;
        }
        ans += r - l - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import numpy as np

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

ruisekiwa = []

for i in range(0, N-1):
    ruisekiwa.append(Hs[i] - Hs[i+1])

checkList = []

for i in ruisekiwa:
    x = 1 if i >= 0 else 0
    checkList.append(x)
checkList.append(0)
checkList.insert(0,0)

checkArray = np.array(checkList)
ans = np.diff(np.nonzero(checkArray == 0)[0]) - 1

print(max(ans))

Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  ll n;cin>>n;
  vector<ll> a;
  ll ans = 100000000000000;
  {
    
    for(ll i = 1;n >= i*i;i++){
      if(n%i == 0)ans = min(i+n/i,ans);
    }

  }
  print(ans-2);
  return 0;
} 


Measured memory_bytes: 256
import bisect
a, b, q = map(int, input().split())
INF = 10**18
shrines = [-INF]+[int(input())for _ in range(a)]
temples = [-INF]+[int(input())for _ in range(b)]

for _ in range(q):
    x = int(input())

    ans = INF
    # 神社→寺
    Ri = bisect.bisect_left(shrines, x)
    Li = Ri-1
    if Ri != a+1:
        R = shrines[Ri]
        Rj = bisect.bisect_left(temples, R)
        Lj = Rj-1
        d = INF
        if Rj != b+1:
            d = min(d, temples[Rj]-x)
        if Lj != 0:
            d = min(d, R-temples[Lj]+R-x)
        if d < ans:
            ans = d
    if Li != 0:
        L = shrines[Li]
        Rj = bisect.bisect_left(temples, L)
        Lj = Rj-1
        d = INF
        if Rj != b+1:
            d = min(d, temples[Rj]-L+x-L)
        if Lj != 0:
            d = min(d, x-temples[Lj])
        if d < ans:
            ans = d

    # 寺→神社
    Ri = bisect.bisect_left(temples, x)
    Li = Ri-1
    if Ri != b+1:
        R = temples[Ri]
        Rj = bisect.bisect_left(shrines, R)
        Lj = Rj-1
        d = INF
        if Rj != a+1:
            d = min(d, shrines[Rj]-x)
        if Lj != 0:
            d = min(d, R-shrines[Lj]+R-x)
        if d < ans:
            ans = d
    if Li != 0:
        L = temples[Li]
        Rj = bisect.bisect_left(shrines, L)
        Lj = Rj-1
        d = INF
        if Rj != a+1:
            d = min(d, shrines[Rj]-L+x-L)
        if Lj != 0:
            d = min(d, x-shrines[Lj])
        if d < ans:
            ans = d

    print(ans)


Measured memory_bytes: 17652
S = list(input())
num_first = 0
num_last = 0
for i in range(len(S)):
    if S[i] == 'A':
        num_first = i
        break
S.reverse()
for j in range(len(S)):
    if S[j] == 'Z':
        num_last = len(S) - j
        break
print(num_last - num_first)


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

#define int long long

int V;
int E;
int r;

struct edge {
    int to;
    int cost;
    edge(int to, int cost)
        : to(to), cost(cost) { }
};

vector<edge> G[100001];
int d[100001];

using p = pair<int, int>;

void dijkstra(int s) {
    priority_queue<p, vector<p>, greater<p> > que;
    fill(d, d+V, 1e+9);
    d[s] = 0;
    que.push(p(0,s));
    while(!que.empty()) {
        p pi = que.top();
        que.pop();
        int v = pi.second;
        if(d[v]<pi.first) continue;
        for(int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(p(d[e.to], e.to));
            }
        }
    }
}

auto main() -> signed {
    cin >> V >> E >> r;
    int s, t, w;
    for(int i=0; i<E; ++i) {
        cin >> s >> t >> w;
        G[s].push_back(edge(t,w));
    }
    dijkstra(r);
    for(int i=0; i<V; ++i) {
        if(d[i]==1e+9) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19472
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;

	while (n > 0)
	{
		n /= 10;

		count++;
	}
	return count;
}
int digit(int n)
{

	int ans = 0;
	while (n > 0)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n;
	cin >> n;
	map<int,int>plan;
	rep(i,n){
		int p;
		cin>>p;
		plan[p]++;
	}
	int d;
	cin>>d;
	bool ans=true;
	rep(i,d){
		int pt;
		cin>>pt;
		if(plan[pt]>0){
			plan[pt]--;
		}else{
			ans=false;
		}
	}
	if(ans){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}

}


Measured memory_bytes: 9600
from itertools import permutations
n,m=map(int,input().split())
e=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  e[a-1]+=[b-1]
  e[b-1]+=[a-1]
num=list(permutations([0]+list(range(1,n))))
ans=0
for i in range(len(num)):
  if num[i][0]!=0:continue
  s=1
  now=0
  while s<n:
    if num[i][s] in e[now]:
      now=num[i][s]
      s+=1
    else:break
  if s==n:ans+=1
print(ans)

Measured memory_bytes: 79436
import scala.math._

// longでrangeの作り方

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val x = sc.nextInt
//  val list = List.fill(3)(sc.next)

  val ans = if (x < 1200) "ABC" else "ARC"

  println(ans)


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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 25416
L, R = map(int, input().split())

if R - L > 2018:
  print(0)
else:
  min_mod = 2019
  for i in range(L, R+1):
    for j in range(i+1, R+1):
      if min_mod > i*j%2019:
        min_mod = i*j%2019
        
  print(min_mod)

Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
int main(void){
    double x1, y1, x2, y2, z;
    scanf("%lf" "%lf" "%lf" "%lf", &x1, &y1, &x2, &y2);
    z = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    printf("%f\n", z);
    return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>

int main(void)
{
    int A, B;
    char c;
    
    scanf("%d %c %d", &A, &c, &B);
    
    if(c== '+'){
        printf("%d\n", A+B);
    }else if(c== '-'){
        printf("%d\n", A-B);
    }


    return 0;
}


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

int main()
{
    ll N,M;
    cin >> N >> M;

    if(N == M)
    {
        ll tmp = 1;
        for(ll i = 1; i <= N; i++)
        {
            tmp = (tmp * i) % 1000000007;
        }
        ll tmp2 = 1;
        for(ll i = 1; i <= M; i++)
        {
            tmp2 = (tmp2 * i) % 1000000007;
        }

        cout << (2 * tmp * tmp2) % 1000000007 << endl;
    }
    else if(N == M-1 || M == N-1)
    {
        ll tmp = 1;
        for(ll i = 1; i <= N; i++)
        {
            tmp = (tmp * i) % 1000000007;
        }
        ll tmp2 = 1;
        for(ll i = 1; i <= M; i++)
        {
            tmp2 = (tmp2 * i) % 1000000007;
        }

        cout << (tmp * tmp2) % 1000000007 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<time.h>
#define M 101000
using namespace std;
char s[200];
int len,ansc=999999,ansf=-1;
int main()
{
	scanf("%s",s);
	len=strlen(s);
	for (int i=0;i<=len-1;i++)
	{
		if (s[i]=='C')
		{
			ansc=min(ansc,i);
		}
		if (s[i]=='F')
		{
			ansf=max(ansf,i);
		}
	}
	if (ansc<ansf)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}



Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, i, j, count, tmp;
    int[] a;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = sc.nextInt();
      count = 0;

      for(i = 0;i < n - 1;i++)for(j = 0;j < n - 1 - i;j++)if(a[j] > a[j + 1]){
        tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp; count++;
      }

      out.println(count);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20896
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

bool isprime(int n)
{
	if(n==1)return false;
	
	for(int i = 2;i*i <= n;i++)
	{
		if(n%i == 0)return false;
	}
	return true;
}

int main()
{
	int n,p;
	
	while(cin>>n>>p,n!=-1)
	{
		int _cou=0;
		int num = n+1;
		iv v1;
		iv v;
		while(_cou<p)
		{
			if(isprime(num)==true)
			{
				v1.PB(num);
				_cou++;
			}
			num++;
		}
		
		REP(i,p)for(int j = i;j < p;j++)
		{
			v.PB(v1[i]+v1[j]);
		}
		
		sort(ALL(v));
		
		cout << v[p-1] << endl;
		
	}
		
	return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always



int main() {
    
    
    

    
    int n;
    while (cin >> n && n) {
        string s[n];
        int cnt[n]; fill_n(cnt, n, 0);
        
        //文字列を読み込んで
        //.の数数える
        //+つける
        rep(i, n) {
            cin >> s[i];
            if (s[i][0] != '.') continue; //cnt = 0
            rep(j, SZ(s[i]) - 1) {
                cnt[i]++;
                if (s[i][j + 1] != '.') {s[i][j] = '+'; break;}
            }
        }
        
        
        //"直接の"返信に対して|でつなげる
        //自分のcnt以下がこない間
        rep(i, n) {
            int tmp = -1; //どこまで直接の返信あるか
            rep3(j, i + 1, n) {
                //break term
                if (cnt[i] >= cnt[j]) break;
                if (cnt[j] == cnt[i] + 1) tmp = j;
            }
            rep3(j, i + 1, tmp) {
                if (s[j][cnt[i]] == '.') s[j][cnt[i]] = '|';
            }
        }
        rep(i, n) rep(j, SZ(s[i])) if (s[i][j] == '.') s[i][j] = ' ';
        rep(i, n) out(s[i]);
        
    }
    
    
    
}




Measured memory_bytes: 3760
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int INF = INT_MAX / 6;

typedef struct Area {
    int left; // left 1
    int mid; // mid 0
    int right; // right 1
} Area;

vector<Area> areas;

int main(void) {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int slen = (int) S.size();

    vector<pair<char, int>> compress;
    {
        char c = S[0];
        int count = 1;
        for (int i = 1; i < slen; i++) {
            if (S[i] == c) {
                count++;
            } else {
                compress.push_back({c, count});
                c = S[i];
                count = 1;
            }
        }
        compress.push_back({c, count});
    }

    // for (auto &p : compress) {
    //     printf("%c: %d\n", p.first, p.second);
    // }
    // printf("\n");

    int ans = 0;
    int acc = 0;
    int cnt = 0;
    queue<pair<char, int>> q;
    for (auto &comp : compress) {
        if (comp.first == '0') {
            if (cnt == K) {
                chmax(ans, acc);
                while (1) {
                    auto &p = q.front();
                    acc -= p.second;
                    q.pop();
                    if (p.first == '0') {
                        break;
                    }
                }
                cnt--;
            }
            cnt++;
        }
        acc += comp.second;
        q.push(comp);
        // printf("acc: %d, cnt: %d, ans: %d\n", acc, cnt, ans);
    }
    chmax(ans, acc);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
#include <numeric>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    ll a, b, r, tmp;
    ll x;
    cin >> a >> b;
    x = a * b;
 
  /* 自然数 a > b を確認・入替 */
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    /* ユークリッドの互除法 */
    r = a % b;
    // cout << r << endl;

    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    // cout << x << endl;
    // cout << b << endl;
    cout << x/b << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main() {
  ll n; cin >> n;
  ll a[n]; //for(int i=0; i<n; i++) a[i] = i/2;
  for(int i=0; i<n; i++) cin >> a[i];
  ll b[3]; b[0] = b[1] = b[2] = 0; ll an=1;
  for(int i=0; i<n; i++) {
    ll nm = 0, id = -1;
    for(int j=0; j<3; j++) {
      if (a[i] == b[j]) nm++, id=j;
    }
    //if (a[i])
    an = an * nm % mod;
    b[id]++;
  }
  
  //ll bb = 0;
  //for(ll x:b)if (x) bb++;
  // 色1, 2, 3→選び方3, 6, 6
  //if (bb == 1) an = an * 3 % mod;
  //else if (bb == 2) an = an * 6 % mod;
  //else if (bb == 3) an = an * 6 % mod;
  cout << an << endl;
}

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

int cnt[27];

int main( )
{
    string s; cin >> s;
    int i, l = (int) s.size(), x;
    for (i = 0; i < l; i++) {
        x = s[i] - 'a';
        cnt[x]++;
        if (cnt[x] > 1) {
            cout << "no\n";
            return 0;
        }
    }
    cout << "yes\n";
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

    int N, K;
    cin >> N >> K;

    vector<bool> vec(10, false);
    rep (i, K) {
        int d;
        cin >> d;
        vec[d] = true;
    }

    while (true) {
        string s = to_string(N);
        bool flag = true;
        rep (i, s.size()) {
            if (vec[s[i] - '0']) {
                flag = false;
            }
        }

        if (flag) {
            break;
        }

        N++;
    }

    cout << N << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int com(const void *a,const void *b){
  return *(int*)b - *(int*)a;
}
int main(){
  int n,a[110],i,al=0,bo=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),com);
  for(i=0;i<n;i++){
    if(i%2==0)al+=a[i];
    else bo+=a[i];
  }
  printf("%d\n",al-bo);
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# atcoder contest 153:B
h,n = input().split()
n = int(n)
h =int(h)

nums = input().split()
res = 0

for i in range(len(nums)):
    res = res + int(nums[i])

if res >= h:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 10712
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

ll a,b;
ll gcd(ll x,ll y){
    if(y==0)
        return x;
    return gcd(y,x%y);
}
int main(){
    cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
vector<int>v[20];
vector<int>c;
//int ans[20];
int main()
{
    int n,m,x,temp;
    cin>>n>>m>>x;
    For(i,0,n-1)
    {
        cin>>temp;
        c.push_back(temp);
        For(j,0,m-1)
        {
            cin>>temp;
            v[i].push_back(temp);
        }
    }
    int tot=1<<n;
    int flag=1;
    int minx=1e9;
    For(i,0,tot-1)
    {
        flag=1;
        //For(j,0,m-1)ans[j]=0;
        vector<int>ans(m);
        temp=0;
        For(j,0,n-1)
        {
            if(i>>j&1)
            {
                temp+=c[j];
                For(k,0,m-1)ans[k]+=v[j][k];
            }
        }
        For(j,0,m-1)if(ans[j]<x)flag=0;
        if(flag)minx=min(minx,temp);
    }
    if(minx==1e9)cout<<-1<<endl;
    else cout<<minx<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio>

int box[200000];
bool red[200000];

int main(void) {
    int n,m;
    scanf("%d%d",&n,&m);

    red[0] = true;
    for(int i=0; i<n; i++)
        box[i] = 1;

    for(int i=0; i<m; i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        x--, y--;

        box[x]--, box[y]++;
        if(red[x]) red[y] = true;
        if(!box[x]) red[x] = false; 
    }
    int res=0;
    for(int i=0; i<n; i++)
        if(red[i]) res++;
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 768
n,t = map(int,input().split())
c_t = [list(map(int,input().split())) for _ in range(n)]
cost = [100000]
for i in range(n):
  if c_t[i][1] <= t:
    cost.append(c_t[i][0])
if min(cost) == 100000:
  print("TLE")
else:
  print(min(cost))

Measured memory_bytes: 9076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		int highest = 0;
		int count =0;
		for(int i = 0; i < n; i++) {
			ary[i] = sc.nextInt();
			if(ary[i] >= highest) {
				count++;
				highest = ary[i];
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23252
n = int(input())
a = list(map(int, input().split()))

def check(x):
    b = n
    r = 0
    y = 0
    D = [0]*(2*n+1)
    for i in range(n):
        D[b] += 1
        if a[i] < x:
            r += D[b]
            b += 1
        else:
            b -= 1
            r -= D[b]
        y += r
    return y

alpha = sorted(a)
l, r = 0, n
m, c = n//2, n*(n+1)//2
while True:
    if check(alpha[m]) <= c//2:
        if m == n-1:
            break
        elif check(alpha[m+1]) > c//2:
            break
        else:
            l, m = m, (m+r)//2
    else:
        m, r = (m+l)//2, m+1
        
print(alpha[m])

Measured memory_bytes: 14720
N = int(input())
v = [int(x) for x in input().split()]
v.sort()

ans = 0
for i in range(N-1):
  a = (v[i] + v[i + 1]) / 2
  ans += a
  v[i] = 0
  v[i + 1] = a

print(v[-1])

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" <<endl;
        
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else if(a == b){
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll l, a[500001];
ll ans; 
int main()
{
	cin>>s;
	s=" "+s;
	l=s.length()-1;
	for(int i=1;i<=l;i++) (s[i] == '<') ? (a[i+1] = a[i] + 1) : (a[i+1]);
	for(int i=l;i>=1;i--) (s[i] == '>') ? (a[i] = max(a[i], a[i+1]+1)) : (a[i]);
	for(int i=1;i<=l+1;i++) 
	ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7800
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
from itertools import permutations
count = 0
for i in list(permutations(range(1,n+1))):
  count += 1
  i = list(i)
  if i==p: a = count
  if i==q: b = count
print(abs(a-b))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
struct UnionFind{
public:
	vector<int> par;
	vector<int> rank;
	vector<int> s;
	int cnt;
 
	UnionFind(int n){
		rep(i,n){
			par.push_back(i);
			rank.push_back(0);
			s.push_back(1);
		}
		cnt=n;
	}
 
	int find(int x){
		if(par[x]==x) return x;
		else return par[x]=find(par[x]);
	}
 
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			s[y]+=s[x];
		}else{
			par[y]=x;
			s[x]+=s[y];
			if(rank[x]==rank[y]) rank[x]++;
		}
		cnt--;
	}

	bool same(int x,int y){
		return find(x)==find(y);
	}

	int size(int x){
		return s[find(x)];
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m,k;
	cin>>n>>m>>k;
	UnionFind uf1(n),uf2(n);
	vector<vector<int>> g(n),g2(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		uf1.unite(a,b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	rep(i,k){
		int c,d;
		cin>>c>>d;
		c--,d--;
		if(uf1.same(c,d)){
			g2[c].push_back(d);
			g2[d].push_back(c);
		}
	}
	rep(i,n){
		cout<<uf1.size(i)-g2[i].size()-g[i].size()-1<<endl;
	}
}

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

int main() {
    char c[2][3];
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> c[i][j];
        }
    }

    for(int i = 0; i < 3; ++i){
        if(c[0][i] != c[1][3-i-1]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return -1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  int n,k;
  scanf("%d %d", &n, &k);
  int l[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  qsort(l, n, sizeof(int), cmpnum);
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += l[i];
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
        if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
            count++;
        } else if (p[i - 1] < p[i] && p[i] < p[i + 1]){
            count++;
        }
    }
    cout << count << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int ans;
    if(N%2 == 0) ans = N/2;
    else ans = N/2+1;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cassert>
#include <cctype>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

struct Node {
    int value = 0;
    Node* left = nullptr;
    Node* right = nullptr;
    Node(int v, Node* l, Node* r)
        : value{v}
        , left{l}
        , right{r}
    {
    }
};

int main()
{
    string a;
    cin >> a;
    string b;
    cin >> b;

    auto parse = [](const string& str) {
        int i = 0;
        auto value = [&i, &str]() {
            assert(str[i] == '[');
            ++i;
            auto begin = i;
            while (static_cast<bool>(isdigit(str[i]))) {
                ++i;
            }
            assert(str[i] == ']');
            auto end = i - 1;
            return stoi(str.substr(static_cast<size_t>(begin),
                                   static_cast<size_t>(end - begin + 1)));
        };

        function<Node*()> p = [&p, &i, &str, &value]() {
            if (str[i + 1] == ')') {
                i += 2;
                return static_cast<Node*>(nullptr);
            }
            assert(str[i] == '(');
            ++i;
            auto l = p();
            auto v = value();
            ++i;
            auto r = p();
            ++i;
            return new Node{v, l, r};
        };
        auto ll = p();
        auto vv = value();
        ++i;
        auto rr = p();
        return new Node{vv, ll, rr};
    };

    function<void(Node*)> pp = [&pp](Node* n) {
        if (n) {
            cout << "(";
            pp(n->left);
            cout << ")";
            cout << '[' << n->value << ']';
            cout << "(";
            pp(n->right);
            cout << ")";
        }
    };

    function<Node*(Node*, Node*)> f = [&f](Node* l, Node* r) {
        auto ll = l->left && r->left ? f(l->left, r->left) : nullptr;
        auto rr = l->right && r->right ? f(l->right, r->right) : nullptr;
        return new Node{l->value + r->value, ll, rr};
    };

    auto t1 = parse(a);
    //pp(t1);
    //cout << endl;
    auto t2 = parse(b);
    //pp(t2);
    //cout << endl;
    auto r = f(t1, t2);
    pp(r);
    cout << endl;
}

Measured memory_bytes: 3248
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

typedef pair<int,int> pii;
#define fi first
#define se second

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int m[101][101] = {0};
int main() {
  int h,w;
  char c;
  while(cin>>h>>w, h||w) {
    memset(m, 0, sizeof(m));
    cin.ignore();
    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	cin>>c;
	if(c=='#')
	  m[i][j] = 0;
	if(c=='*')
	  m[i][j] = 1;
	if(c=='@')
	  m[i][j] = 2;
      }
      cin.ignore();
    }

    int ans = 0,now;
    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	if(m[i][j] != -1) {
	  queue<pii> qu;
	  now = m[i][j];
	  ans++;
	  for(qu.push(pii(j,i)); !qu.empty();) {
	    pii pos = qu.front(); qu.pop();
	    if(m[pos.se][pos.fi] == -1) continue;
	    m[pos.se][pos.fi] = -1;
	    for(int k=0; k<4; ++k) {
	      if(pos.fi+dx[k] >= 0 && pos.fi+dx[k] < w 
		 && pos.se+dy[k] >= 0 && pos.se+dy[k] < h && m[pos.se+dy[k]][pos.fi+dx[k]] == now) {
		qu.push(pii(pos.fi+dx[k], pos.se+dy[k]));
	      }
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 952
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=305;
int a[N<<1],n,dp[2][N<<1][N<<1];
bool vis[N<<1],has[N<<1];
//
inline void add(int &x,int y){
	x+=y;if(x>=MOD)x-=MOD;
}
inline int mul(int x,int y){
	ll ans=1ll*x*y;return ans%MOD;
}
int main(){
	n=getint();
	rep(i,2*n){
		a[i]=getint();
		if(a[i]>0){--a[i];has[a[i]]=true;}
	}
	int cnt=0;
	rep(i,n){
		if(a[2*i]>=0&&a[2*i+1]>=0){
			vis[a[2*i]]=true;
			vis[a[2*i+1]]=true;
		}
		else if(a[2*i]==a[2*i+1])++cnt;	
	}
	dp[0][0][0]=1;
	int p=0,q=1;
	rep(i,2*n){
		if(vis[i])continue;
		rep(j,2*n+1)rep(k,2*n+1){
			if(!dp[p][j][k])continue;
			if(has[i]){
				if(j)add(dp[q][j-1][k],mul(dp[p][j][k],j));
				add(dp[q][j][k+1],dp[p][j][k]);
			}
			else{
				if(k)add(dp[q][j][k-1],dp[p][j][k]);
				add(dp[q][j+1][k],dp[p][j][k]);
				add(dp[q][j][k+1],dp[p][j][k]);
			}
			dp[p][j][k]=0;
		}
		swap(p,q);
	}
	rep(i,cnt)dp[p][0][0]=mul(dp[p][0][0],i+1);
	printf("%d\n",dp[p][0][0]);
	return 0;
}


Measured memory_bytes: 3072