akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 87;
const ll MOD = 1e9 + 7;
ll f[N], fi[N];
ll qpow(ll a, ll b)
{
    ll r = 1;
    for (;b;b>>=1,a=a*a%MOD)
        if (b&1)
            r = r*a%MOD;
    return r;
}
ll c(ll n, ll k)
{
    return f[n] * fi[k] % MOD * fi[n - k] % MOD;
}
ll h(ll n, ll k)
{
    return c(n + k - 1, k);
}
int main()
{
    f[0] = f[1] = fi[0] = fi[1] = 1;
    for (int i = 2; i < N; ++i)
        f[i] = i * f[i - 1] % MOD;
    for (int i = 2; i < N; ++i)
        fi[i] = (MOD - MOD / i) * fi[MOD % i] % MOD;
    for (int i = 2; i < N; ++i)
        fi[i] = fi[i] * fi[i - 1] % MOD;
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int i = 0; i <= min(n - 1, k); ++i)
        (ans += h(n - i, i) * c(n, i)) %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i, n-1){
    if(a[i+1]<a[i]){
      b[i+1]+=a[i]-a[i+1];
      a[i+1]=a[i];
    }
  }
  ll ans=0;
  rep(i, n){
    ans+=b[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e9;

int main() {
  ll n, t, a, nt = 1, na = 1, p;
  cin >> n;

  rep(i, n) {
    cin >> t >> a;
    p = max(ceil(nt / (ld)t), ceil(na / (ld)a));
    nt = t * p;
    na = a * p;
  }

  cout << nt + na << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long x,y,num,ii,ret;
  cin >> x >> y;
  num = 0;
  ret = x;
  vector<long> vec;

  if(x<=y){
	num++;
  }
  while(true){
	if(x*2 <= y){
	  //cout << "num:" << num << "x:" << endl;
	  num++;
	  x=x*2;
	}
	else{
	  break;
	}
  }

  cout << num << endl;
  
  return 0;
}


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

int n,p;
string s;
map<string, set<int,greater<int>>> res;
map<int,int> refer;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s>>p;
		res[s].insert(p);
		refer[p]=i+1;
	}
	for(auto it=res.begin();it!=res.end();++it){
		for(auto scores=it->second.begin();scores!=it->second.end();++scores){
			cout<<refer[*scores]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import re

def match(pattern, strings):
	return re.match('^{0}'.format(pattern), strings)

def any_match(strings):
	return re.match('^dream|^erase', strings)

S = input()

i = 0
while i < len(S):
	if match('dreamer', S[i:]):
		i += len('dreamer')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('dreamer')
				i += len('dream')
				continue
	elif match('eraser', S[i:]):
		i += len('eraser')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('eraser')
				i += len('erase')
				continue
	elif match('dream', S[i:]):
		i += len('dream')
		continue
	elif match('erase', S[i:]):
		i += len('erase')
		continue
	else:
		print('NO')
		exit()

print('YES')

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int v[n+1];
	map<int,int>odd;
	map<int,int>even;
	for(int i=0; i<n; i++){
		cin>>v[i];
		if(i%2==0){odd[v[i]]++;}
		else even[v[i]]++;
	}
	vector<pair<int,int>>x;
	vector<pair<int,int>>y;
	for(auto p:odd){
		x.push_back(make_pair(p.second,p.first));
	}
	x.push_back(make_pair(0,0));
	for(auto p:even){
		y.push_back(make_pair(p.second,p.first));
	}
	y.push_back(make_pair(0,0));
	sort(x.rbegin(),x.rend());
	sort(y.rbegin(),y.rend());
	if(x[0].second!=y[0].second){
		cout<<n-x[0].first-y[0].first<<endl; 
	}
	else{
		int a=n-x[0].first-y[1].first;
		int b=n-x[1].first-y[0].first;
		cout<<min(a,b)<<endl;
	}
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

class Dice
{
public:
    Dice()
    {
        number = new int[6];
        tmp = new int[6];
    };
    ~Dice()
    {
        delete[] number;
        delete[] tmp;
    };
    void setLabel(int index, int num)
    {
        number[index] = num;
    };

    void roll(char dst)
    {
        repi(i, 6, 0)
        {
            tmp[i] = number[i];
        }
        switch (dst)
        {
        case 'E':
            setNumber(tmp[3], tmp[1], tmp[0], tmp[5], tmp[4], tmp[2]);
            break;
        case 'S':
            setNumber(tmp[4], tmp[0], tmp[2], tmp[3], tmp[5], tmp[1]);
            break;
        case 'W':
            setNumber(tmp[2], tmp[1], tmp[5], tmp[0], tmp[4], tmp[3]);
            break;
        case 'N':
            setNumber(tmp[1], tmp[5], tmp[2], tmp[3], tmp[0], tmp[4]);
            break;

        default:
            break;
        }
    };
    int showPeek()
    {
        return number[0];
    };
    int showRight()
    {
        return number[2];
    }
    int searchRight(int front, int peek)
    {
        int Ans = -1;
        repi(i, 8, 0)
        {
            if (number[1] == front && number[0] == peek)
            {
                Ans = number[2];
            }
            else if (number[2] == front && number[0] == peek)
            {
                Ans = number[4];
            }
            else if (number[4] == front && number[0] == peek)
            {
                Ans = number[3];
            }
            else if (number[3] == front && number[0] == peek)
            {
                Ans = number[1];
            }
            if (i >= 4)
            {
                roll('E');
            }
            else
            {
                roll('N');
            }
        }
        return Ans;
    }

private:
    void setNumber(int n0, int n1, int n2, int n3, int n4, int n5)
    {
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    };
    //declar variables
    int *number;
    int *tmp;
};

int main()
{
    Dice dice;
    repi(i, 6, 0)
    {
        int tmp;
        cin >> tmp;
        dice.setLabel(i, tmp);
    }
    ll q;
    cin >> q;
    repi(i, q, 0)
    {
        ll f, p;
        cin >> p >> f;
        cout << dice.searchRight(f, p) << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long int ll;

ll GCD(ll a , ll b)
{
    if(b==0)
        return a;
    else
        return GCD(b,a%b);
}
ll LCM(ll a,ll b){return (max(a,b)/GCD(a,b))*min(a,b);}

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

   ll a,b;
   cin >> a >> b;
   cout << LCM(a,b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  ll N, W;
  cin >> N >> W;
  ll v[N], w[N];
  ll V=110000;
  ll dp[N+1][V+1];
  ll const INF = 1e14;
  // dp[i+1][v]:i番目まで選んで、価値がvのときの最小の重さ
  // dp[i+1][v] = min(dp[i][v-v[i]] + w[i], dp[i][v])
  // for(int i=V; i>=0;i--) {if(dp[N][i] != INF) ans=i; break; }
  // で答えが分かる
  for(ll i=0; i<N+1; i++) for(ll j=0; j<V+1; j++) dp[i][j] = INF;
  for(ll i=0; i<N; i++) cin >> w[i] >> v[i];
  dp[0][0] = 0;
  for(ll i=0; i<N; i++){
    for(ll j=0; j<=V; j++){
      if(j-v[i] >= 0){
        ll tmp = dp[i][j];
        if(dp[i][j] > dp[i][j-v[i]] + w[i]) tmp = dp[i][j-v[i]] + w[i];
        dp[i+1][j] = tmp;
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  ll ans = 0;
  for(ll i=V; i>=0;i--) {
    if(dp[N][i] != INF && dp[N][i] <= W) {
      ans=i; 
//      cout << i << " " << dp[N][i] << endl;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long n, m; scan(n, m);
      LI xs(n); for(long &x : xs) scan(x);
      std::sort(xs.begin(), xs.end());
      long res = 0;
      for(long i = n - 1; i > n - 1 - m; --i) {
         res += xs[i];
      }
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



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

list = []
for i in range(N):
    S,P = input().split()
    S = str(S)
    P = int(P)
    list.append([i+1,S,P])

list1 = sorted(list, key=lambda x:(x[1],-x[2]))

for d in list1:
    print(d[0])


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#include <cstring>
const int MAXN = 100005;
char s[MAXN]; int n;

int main() {
    scanf("%s", s + 1), n = strlen(s + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (s[i] != s[i - 1])
            ans++;
    printf("%d", ans - 1);
    return 0;
}


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

int main(){
  int N;cin>>N;
  if(N<105)cout<<0<<endl;
  else if(N<135)cout<<1<<endl;
  else if(N<165)cout<<2<<endl;
  else if(N<189)cout<<3<<endl;
  else if(N<195)cout<<4<<endl;
  else cout<<5<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
c = 0
z = False
for aa in a:
    if aa < 0:
        c += 1
    elif aa == 0:
        z = True
if z or c % 2 ==0:
    print(sum(map(abs, a)))
else:
    ab = [abs(x) for x in a]
    ans = sum(ab) - min(ab)*2
    print(ans)

Measured memory_bytes: 14332
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

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

	const int MAX = 722, OFFSET = 540;

	for(int n, m; cin >> n >> m, n;) {
		int r;
		cin >> r;

		vector<vector<int> > cnt(m, vector<int>(MAX, 0));
		for(int i = 0; i < r; ++i) {
			int t, pc, stu, login;
			cin >> t >> pc >> stu >> login;
			--stu;

			if(login)
				++cnt[stu][t - OFFSET];
			else
				--cnt[stu][t - OFFSET];
		}

		for(int i = 0; i < m; ++i)
			for(int j = 1; j < MAX; ++j)
				cnt[i][j] += cnt[i][j - 1];

		vector<vector<int> > use_time(m, vector<int>(MAX, 0));
		
		for(int i = 0; i < m; ++i)
			for(int j = 1; j < MAX; ++j)
				use_time[i][j] = use_time[i][j - 1] + (cnt[i][j - 1] ? 1 : 0);

		int q;
		cin >> q;
		for(int i = 0; i < q; ++i) {
			int s, e, stu;
			cin >> s >> e >> stu;
			--stu;

			cout << use_time[stu][e - OFFSET] - use_time[stu][s - OFFSET] << endl;
		}
	}

	return EXIT_SUCCESS;
}

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

#define ll long long 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

void initforfac() {
/* 
	set const int N = ...; ll fac[N], inv[N];

	fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for(int i = 2; i < N; ++i) inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
	for(int i = 1; i < N; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
	for(int i = 2; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
*/
}

ll gcd(ll a, ll b) {
	return (a % b) ? gcd(b, a % b) : b;
}
ll lcm(ll a, ll b) {
	return (a * b) / gcd(a, b);
}
ll add(ll a, ll b) {
	ll x = (a + b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll sub(ll a, ll b) {
	ll x = (a - b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll mul(ll a, ll b) {
	ll x = (a * b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll power(ll a, ll b) {
	if(b == 0) return 1;
	if(b & 1) return mul(a, power(a, b - 1));
	return power(mul(a, a), b / 2);
}
ll inv(ll x) {
	return power(x, MOD - 2);
}
/*
ll C(ll n, ll r) {
	return 1ll * fac[n] * inv[r] % MOD * inv[n - r] % MOD;
}
*/
map<ll, ll> m;
void init() {
	for(ll x = 1; x <= 100; x++) {
		for(ll y = 1; y <= 100; y++) {
			for(ll z = 1; z <= 100; z++) {
				ll val = x * x + y * y + z * z + x * y + y * z + x * z;
				m[val]++;
			}
		}
	}
}

void solve() {
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) {
		if(m.find(i) == m.end()) cout << "0\n";
		else cout << m[i] << "\n";
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	init();
	int t = 1;// cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 5940
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N, A, B = ri_()
if abs(A - B) % 2 == 0:
    ans = 'Alice'
else:
    ans = 'Borys'
print(ans)

Measured memory_bytes: 64236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1e9;
struct edge
{
    int to,flow,cap;
} l[300005];
vector<int> G[300];
int cur[300],d[300],t=-1,S,T;
bool v[300];

void add(int from,int to,int cap)
{
    l[++t]=(edge) {to,0,cap};
    G[from].push_back(t);
    l[++t]=(edge) {from,0,0};
    G[to].push_back(t);
}

bool BFS()
{
    memset(v,0,sizeof(v)),v[S]=1,d[S]=0;
    queue<int> q;
    q.push(S);
    int x;
    edge e;

    while(!q.empty())
    {
        x=q.front(),q.pop();
        for(int i=G[x].size()-1; i>=0; i--)
        {
            e=l[G[x][i]];
            if(e.flow<e.cap&&!v[e.to])
                v[e.to]=1,d[e.to]=d[x]+1,q.push(e.to);
        }
    }

    return v[T];
}

int dfs(int x,int A)
{
    if(x==T||!A)
        return A;
    int flow=0,f,sz=G[x].size();
    for(int &i=cur[x]; i<sz; i++)
    {
        edge &e=l[G[x][i]];
        if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(e.cap-e.flow,A))))
        {
            A-=f,flow+=f;
            e.flow+=f,l[G[x][i]^1].flow-=f;
            if(!A)
                break;
        }
    }

    return flow;
}

int max_flow()
{
    int ans=0;
    while(BFS())
    {
        memset(cur,0,sizeof(cur));
        ans+=dfs(S,inf);
    }
    return ans;
}


int main()
{
    int H,W;
    scanf("%d%d",&H,&W);
    S=0;
    T=H+W+1;
    char a[105][105];
    for(int i=1; i<=H; i++)
        scanf("%s",a[i]+1);
        for(int i=1; i<=H; i++)
            for(int j=1; j<=W; j++)
            {
                if(a[i][j]!='.')
                    add(i,j+H,1),add(j+H,i,1);
                if(a[i][j]=='S')
                    add(S,i,inf),add(S,j+H,inf);
                else if(a[i][j]=='T')
                    add(i,T,inf),add(j+H,T,inf);
            }

    int ans=max_flow();
    if(ans>=inf)
        printf("-1");
    else
        printf("%d",ans);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W;
    cin>>H>>W;

    if(W==1 || H==1){
        cout<<1<<endl;
        return 0;
    }

    uint64_t ans=0;
    rep(i,0,H){
        if(W%2==0) ans+=W/2;
        else{
            if(i%2==0) ans+=W/2+1;
            else ans+=W/2;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000
#define INFTY 2097125
int min(int,int);
void matrixChain(void);
int n,m[N+1][N+1],p[N+1];
int main(){
  int i;
  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  matrixChain();
  printf("%d\n",m[1][n]);

  return 0;
}

void matrixChain(){
  int i,j,l,k;
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n; i++){
      j = i + l -1;
      m[i][j] = INFTY;
      for(k = i; k <= j; k++){
	m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
}

int min(int x, int y){
  if(x >= y) return y;
  else return x;
}

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

int main(void)
{
  int n,m;
  cin>>n>>m;
  vector<int>l(m);
  vector<int>r(m);
  for(int i=0;i<m;i++){
    cin>>l.at(i)>>r.at(i);
  }
  int maxl=1;
  int minr=n;
  rep(i,m){
    maxl=max(maxl,l[i]);
    minr=min(minr,r[i]);
  }
  int ans=minr-maxl+1;
  ans=max(ans,0);

  cout<<ans<<endl;
}

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

int abs(int x, int y){
    if(x < y){
      return y - x;
    }
    else{
      return x - y;
    }
  }

int main(){
  int N, T, A;
  cin >> N >> T >> A;
  double dif = 100000;
  int ans;
  for(int i = 1; i <= N;i++){
    double Hi;
    cin >> Hi;
    if(dif  > abs((T - A) / 0.006, Hi)){
      dif = abs((T - A) / 0.006, Hi);
      ans = i;
    }
  }
  cout << ans << endl;
}

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

sup = (N + 1) // 2
con = 0
ans = 0

if N < 105:
  print(ans)

else:
  for i in range(1,N + 1,2):
    for j in range(1,max(i // 2 + 1,2)):
      if i % j == 0:
        con +=1
    if con == 7:
      ans += 1
    con = 0
      
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define ln printf("\n")
const int N=1e5+50;
using namespace std;
int n,k;
int sum=0,ans;
int p[N];
int read()
{
	int s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); k=read();
	for (int i=1;i<=n;i++){
	  p[i]=read();
	}
	sort(p+1,p+n+1); ans=1<<30;
	for (int i=1;i+k-1<=n;i++)
	  ans=min(ans,p[i+k-1]-p[i]);
	out(ans);
	return 0;
}

Measured memory_bytes: 640
s = input()
 
flag = True
for i in range(len(s)):
  if i%2 == 0 and s[i] == "L":
    flag = False
  if i%2 == 1 and s[i] == "R":
    flag = False
 
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
L = [A[0]] * N
R = [A[-1]] * N
for i, a in enumerate(A[1:]):
    L[i+1] = gcd(a, L[i])
for i, a in enumerate(A[::-1][1:]):
    R[i+1] = gcd(a, R[i])
L = [0] + L
R = R[::-1] + [0]
ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n, k;
  cin >> n >> k;

  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += min(x[i], abs(k - x[i]));
  }

  cout << ans * 2 << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i=0;i<n;i++)p[i]=sc.nextInt();
        int ans = 0;
        for (int i=1;i<n-1;i++)if (!((p[i-1]>p[i]&&p[i+1]>p[i])||(p[i-1]<p[i]&&p[i+1]<p[i])))ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 35656
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();
    const BSIZE: i32 = 1001001;

    let mut x = a.clone();
    x.push(i32::min_value());
    x.sort();
    x.dedup();

    let total = (n * (n + 1) / 2) as i64;
    let mut l = 0;
    let mut r = x.len();
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut sum = vec![0; n + 1];
        for i in 0..n {
            let b = if a[i] >= x[m] { 1 } else { -1 };
            sum[i + 1] = sum[i] + b;
        }
        let mut bit = FenwickTree::new(2 * BSIZE as usize);
        let mut cnt = 0;
        for i in 0..n + 1 {
            cnt += bit.sum((BSIZE + sum[i]) as usize);
            bit.add((BSIZE + sum[i]) as usize, 1);
        }
        if cnt >= total - cnt {
            l = m;
        } else {
            r = m;
        }
    }
    println!("{}", x[l]);
}

struct FenwickTree(Vec<i64>);
#[allow(dead_code)]
impl FenwickTree {
    fn new(n: usize) -> FenwickTree {
        FenwickTree(vec![0; n + 1])
    }
    fn add(&mut self, i: usize, v: i64) {
        assert!(i > 0);
        let n = self.0.len() as i64;
        let mut i = i as i64;
        while i < n {
            self.0[i as usize] += v;
            i += i & -i;
        }
    }
    fn sum(&self, i: usize) -> i64 {
        assert!(i > 0);
        let mut i = i as i64;
        let mut r = 0;
        while i > 0 {
            r += self.0[i as usize];
            i -= i & -i;
        }
        r
    }
    fn lower_bound(&self, x: &i64) -> usize {
        let n = self.0.len();
        let mut k = 1;
        while k * 2 < n {
            k *= 2;
        }
        let mut i = 0;
        let mut x = *x;
        while k > 0 {
            if i + k < n && self.0[i + k] < x {
                x -= self.0[i + k];
                i += k;
            }
            k /= 2;
        }
        i + 1
    }
}


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

int main(){
    ll Q, H, S, D; cin >> Q >> H >> S >> D;
    ll N;  cin >> N;

    ll ans =0;
    H = min(H, 2*Q);
    S = min(S, min(2*H, 4*Q));
    D = min(min(D, 2*S), min(4*H, 8*Q));

    ans = ((N-N%2)/2)*D + (N%2)*S;
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 3596
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int h,w;cin >> h >> w;
  vector<string> pict(h);

  rep(i,h) cin >> pict[i];

  rep(i,w+2) cout << '#';
  cout << endl;
  rep(i,h) cout << '#' << pict[i] << '#' << endl;
  rep(i,w+2) cout << '#';
  cout << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<bitset>
#include<algorithm>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
const ll mod =  998244353;
const int N = 100000 + 100;
const int M = 2e6 + 1005;
int dp[N];
int w[N];
int c[] = {0,100,101,102,103,104,105};
int main()
{
    int x;
    cin>>x;
    mmt(dp,0x3f);
    dp[0] = 0;
    if(x < 100) return cout<<0,0;
    for(ll i = 1;i <= 6;++i){
        for(ll j = c[i];j<=x;++j){
            dp[j] = min(dp[j],dp[j - c[i]] + 1);
        }
    }
    if(dp[x] != INF) cout<<1;
    else cout<<0;

}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;cin>>n>>m;
    priority_queue<ll> pq;
    rep(i,n){
        ll a;cin>>a;
        pq.push(a);
    }
    rep(i,m){
        ll t = pq.top();pq.pop();
        t/=2;
        pq.push(t);
    }
    ll ans = 0;
    rep(i,n){
        ans += pq.top();pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  ll x;  cin >> x;
  ll tmp=100, cnt=0;
  while(tmp<x){
    tmp = tmp*(1.01);
    cnt += 1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3636
x, n = map(int, input().split())
P = list(map(int, input().split()))
ans_sma = x
ans_lar = x
while True:
    if ans_sma not in P:
        print(ans_sma)
        break
    elif ans_lar not in P:
        print(ans_lar)
        break
    ans_sma -= 1
    ans_lar += 1


Measured memory_bytes: 9176
// Aizu Vol-1 0154: Sum of Cards
// 2017.8.15 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 1000
int f[8][MAX + 5];
int a[8], b[8];
int m;

void calc(void)
{
	int i, j, k, s;
	memset(f, 0, sizeof(f)), f[0][0] = 1;
	for (i = 1; i <= m; i++) {
		for (j = 0; j <= MAX; j++) {
			if (!f[i - 1][j]) continue;
			for (s = j, k = b[i]; k >= 0; k--, s += a[i])
				if (s <= MAX) f[i][s] += f[i - 1][j];
		}
	}
}

int main()
{
	int g, s, i;

	while (1) {
		scanf("%d", &m); if (!m) break;
		for (i = 1; i <= m; i++) scanf("%d%d", a+i, b+i);
		calc();
		scanf("%d", &g);
		while (g-- > 0) {
			scanf("%d", &s);
			printf("%d\n", f[m][s]);
		}
	}
	return 0;
}

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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n+1), b(n);
    for (auto& e : a) cin >> e;
    for (auto& e : b) cin >> e;

    auto la = a, lb = b;
    for (int i = 0; i + 1 <= n; i++) {
        if (la[i] > lb[i]) {
            la[i] -= lb[i];
            lb[i] = 0;
        } else {
            lb[i] -= la[i];
            la[i] = 0;
        }

        if (la[i+1] > lb[i]) {
            la[i+1] -= lb[i];
        } else {
            la[i+1] = 0;
        }
    }

    auto ra = a, rb = b;
    for (int i = n; i - 1 >= 0; i--) {
        if (ra[i] > rb[i-1]) {
            ra[i] -= rb[i-1];
            rb[i-1] = 0;
        } else {
            rb[i-1] -= ra[i];
            ra[i] = 0;
        }

        if (ra[i-1] > rb[i-1]) {
            ra[i-1] -= rb[i-1];
        } else {
            ra[i-1] = 0;
        }
    }

    auto sum = accumulate(begin(a), end(a), 0ll);
    cout << max(sum - accumulate(begin(la), end(la), 0ll), sum - accumulate(begin(ra), end(ra), 0ll)) << endl;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    int ans = 0;
    int flag = 0;
    rep(i, n) {
        cin >> p[i];
        if (i + 1 == p[i] && flag == 0) {
            ans++;
            flag = 1;
        }else
            flag = 0;

    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int M = N;
  
  int count = 0;
  while (N != 0){
    count += N % 10;
    N = N / 10;
  }
  
  if (M % count == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3660
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    start, goal = (0, 0), (high - 1, width - 1)

    now_data = set()
    now_data.add(start)
    next_data = set()
    pre_data = set()
    pre_data.add(start)

    move_tada = [[-1, 0], [1, 0], [0, 1], [0, -1]]

    count = 1
    while len(now_data) > 0:
        if goal in pre_data:
            break
        count += 1
        for now_x, now_y in now_data:
            for add_x, add_y in move_tada:
                move_x, move_y = now_x + add_x, now_y + add_y
                if 0 <= move_x < high and 0 <= move_y < width:
                    if data[move_x][move_y] == '.' and (move_x, move_y) not in pre_data:
                        ok_data = (move_x, move_y)
                        pre_data.add(ok_data)
                        next_data.add(ok_data)
        now_data = next_data
        next_data = set()

    if goal in pre_data:
        white_data = 0
        for i in range(high):
            white_data += data[i].count('.')
        print(white_data - count)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 40304
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 2000 + 20;
const long long mod = 1e9 + 7;
int n;
string s;

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

    cin >> n;
    cin >> s;

    if(s[0] == 'W') {
    	cout << 0 << endl;
    	return 0;
    }

    long long res = 1, cur = 1, op = 1;
    for(int i = 1; i < 2 * n; i++) {
    	if(s[i] == s[i - 1])
    		op = 1 - op;
    	if(op)
    		cur++;
    	else {
    		res = (res * cur) % mod;
    		cur--;
    	}
    	//cout << i << ' '  << cur << ' ' << res << endl;
    }
    if(cur != 0)
    	cout << 0 << endl;
    else {
	    for(int i = 1; i <= n; i++)
	    	res = (res * i) % mod;
	    //res = (res * 2) % mod;
	    cout << res << endl;
	}
    return 0;
}











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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 2e6;
const int INF = 1e9;


void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < n - 2; ++ i) {
		if (s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C')
			++cnt;
	}
	cout << cnt;
}

int main () {
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

/*
2 4
2 3
*/

void solve() {
	int n, K;
	cin >> n >> K;
	vector<int> A(n);
	REP(n) cin >> A[i];
	vector<bool> dp(K);
	dp[0] = 0;
	for(int k = 1; k <= K; k++) {
		for(int i = 0; i < n; i++) {
			if(k - A[i] >= 0 and dp[k - A[i]] == false) {
				dp[k] = true;
				break;
			}
		}
	} 
	cout << (dp[K] ? "First\n" : "Second\n");
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9+7;
vector<vector<ll> > dp,g;
vector<bool> used;
ll dfs( int s ){
    if(used[s]) return 1;
    //if(used[s]) return (dp[s][0]+ dp[s][1] ) %mod;
    used[s] = true;
    ll res = 1;
   
    for(int i=0;i<g[s].size();i++){
	ll next = g[s][i];
	if(used[next])continue;
	dp[s][0] *= dfs(next);
	dp[s][0] %= mod;
	dp[s][1] *= dp[next][0];
	dp[s][1] %= mod;
    }
    return (dp[s][0] + dp[s][1] )%mod;
}

int main(){
    int n;
    cin>>n;
    used = vector<bool>(n,false) ;
    g = vector<vector<ll> >(n) ;
    dp = vector<vector<ll> > (n , vector<ll>(2,1 ) );
    for(int i=0;i<n-1;i++){
	int x,y;
	cin>>x>>y;
	x--,y--;
	g[x].push_back(y);
	g[y].push_back(x);
    }
    cout<<dfs(0)<<endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
int main()
{
	int a , b , ans;
	cin >> a >> b;
	ans = (a + b) % 24;
	cout << ans << endl;
	return 0;
	}

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

int main() {
  string S;
  cin >> S;
  vector<char> A;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'B' && A.size() > 0) A.pop_back();
    else if (S.at(i) == '0' || S.at(i) == '1') A.push_back(S.at(i));
  }
  for (int i = 0; i < A.size(); i++) {
    cout << A.at(i);
  }
  cout << endl;
}

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

 
int main(){
    
    ll ans=0,ans_max=0,n,h,k;
    cin>>n;
   // vector<ll> h(n);
    cin>>h;
    rep(i,n-1){
        cin>>k;
        
        if(h>=k){
           // cout<<h<<" "<<k<<endl;
            ans++;
        }
        else{
            if(ans_max<ans)ans_max=ans;
            ans=0;
        }
        h=k;
        
    }
    
    
    if(ans_max<ans)ans_max=ans;
    
    
    cout<<ans_max<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

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

#define PUTLINE cout<<__LINE__<<endl;

int main() {
	int n;
	cin>>n;
	while(n--){
		int a[5][5],res=0;
		rep(i,5)rep(j,5)cin>>a[i][j];
		rep(i,5)rep(j,5)repp(h,1,6-i)repp(w,1,6-j){
			bool ok=true;
			repp(s,i,i+h)repp(t,j,j+w)
				if(a[s][t]==0)ok=false;
			if(ok)chmax(res,h*w);
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
string s[2005];
int val[2005][2005];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n;i++)
	{
		int cur=0;
		for(int j=0;j<m;j++)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
		cur=0;
		for(int j=m-1;j>=0;j--)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
	}
	for(int j=0;j<m;j++)
	{
		int cur=0;
		for(int i=0;i<n;i++)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
		cur=0;
		for(int i=n-1;i>=0;i--)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='.')
				ans=max(ans,val[i][j]);
		}
	}
	cout<<ans+1<<"\n";
	return 0;
}


Measured memory_bytes: 19968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int L=sc.nextInt();
		String[] s=new String[N];
		
		for(int i=0;i<N;i++){
			s[i]=sc.next();
		}
		for(int i=N-1;i>=0;i--){
			for(int j=0;j<i;j++){
				if(isLarge(s[j],s[j+1],L)==1){
					String temp=s[j];
					s[j]=s[j+1];
					s[j+1]=temp;
				}
			}
		}
		
		String ans="";
		for(int i=0;i<N;i++)ans+=s[i];
		System.out.println(ans);
	}
	
	int isLarge(String s1,String s2,int L){
		for(int i=0;i<L;i++){
			if(s1.charAt(i)>s2.charAt(i))return 1;
			else if(s1.charAt(i)<s2.charAt(i))return -1;
		}
		return 0;
	}
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
const int mxN=22;
const int modd=1e9+7;
int n, total;
int dp[mxN][(1<<mxN)+2];

vector<vector<int>>adj(mxN);

int rfun(int ind, int msk){
    //deb(msk);
    //bitset<7>b(msk);cout<<b<<endl;
    if(msk==total and ind==n)return 1;
    if(ind>=n)return 0;
    if(dp[ind][msk]!=-1)return dp[ind][msk];
    int an=0;
    for(int i:adj[ind]){//dbg2(ind, i);
        if(msk&(1<<i))continue;
        an = (an+rfun(ind+1, msk^(1<<i)))%modd;
    }
    return dp[ind][msk]= an;
}

int main(){
    cin>>n;
    total=(1<<n)-1;
    memset(dp, -1, sizeof dp);
    fo(i, n){
        fo(j, n){
            int x;cin>>x;
            if(x)adj[i].push_back(j);
        }
    }
    int ans=rfun(0, 0);
    cout<<ans;
}

Measured memory_bytes: 364004
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	string S;
	cin >> N >> S;
	if (N % 2 == 1)
	{
		cout << "No";
		return 0;
	}
	vector<char>S1, S2;
	for (int i = 0; i < S.size() / 2; i++)
	{
		S1.push_back(S[i]);
		S2.push_back(S[S.size() / 2 + i]);
	}
	if (S1 == S2)cout << "Yes";
	else cout << "No";
}

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

int main(){
    int n, k;
    while(cin >> n >> k){
        if(n + k == 0)  break;
        string x[n];
        for(int i = 0; i < n; i++)  cin >> x[i];
        sort(x, x+n);

        set<int> ans;
        do{
            string tmp = "";
            for(int i = 0; i < k; i++)  tmp = tmp + x[i];
            ans.insert(stoi(tmp));
        }while(next_permutation(x, x+n));

        cout << ans.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let n = line.trim().parse::<u32>().unwrap();
    if n % 1000 == 0 {
        println!("0");
    } else {
        println!("{}", (n / 1000 + 1) * 1000 - n);
    }
}


Measured memory_bytes: 2168