akhauriyash/Code-Regression huggingface dataset:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
C = list(range(N))

def val(x):
  return B[x]

def merge(la, lb):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if val(la[ia]) < val(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d])
    right = mergeSort(x[d:])
    return merge(left,right)

C = mergeSort(C)

ans = "Yes"
t = 0
for i in range(N):
    t += A[C[i]]
    if t > B[C[i]]:
        ans = "No"

print(ans)



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

using namespace std;
using ll = long long;
int main () {

    int n;
    long long k;
    cin >> n >> k;
    vector<int> ports(n+1);
    for (int i = 1; i < n+1; ++i) {
        cin >> ports[i];
    }
    int tor =  ports[1];
    int hare = ports[ports[1]];
    while (true) {
        tor = ports[tor];
        hare = ports[ports[hare]];
        if (tor == hare) {
            break;
        }
    }
    tor = 1;
    int head = 0;
    while (tor != hare) {
        tor = ports[tor];
        hare = ports[hare];

        head++;
    }
    // cycle length
    tor = ports[tor];
    int cycle = 1;
    while (tor != hare) {
        tor = ports[tor];
        cycle++;
    }
    tor = 1;
    while (k > 0 && head > 0) {
        tor = ports[tor];
        k--;
        head--;
    }
    k = k % (ll)cycle;
    while (k > 0) {
        tor = ports[tor];
        k--;
    }
    cout << tor << endl;
    return 0;
}

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


int parent(int i){
    i /= 2;
    return i;
}

int left(int i){
    i *= 2;
    return i;
}

int right(int i){
    i = 2 * i + 1;
    return i;
}

int main(){
    int i, H;
    cin >> H;
    int key[H+1];
    for( i = 1; i <= H; i++){
        cin >> key[i];
    }

    for( i = 1; i <= H; i++){
        cout << "node " << i ;
        cout << ": key = " << key[i] << ", ";
        if(parent(i) >= 1) cout << "parent key = " << key[parent(i)] << ", ";
        if(left(i) <= H) cout << "left key = " << key[left(i)] << ", ";
        if(right(i) <= H) cout << "right key = " << key[right(i)] << ", ";
        cout << endl; 
    }

    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll n, s; cin >> n >> s;
    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    } else if (s > n) {
        cout << -1 << endl;
        return 0;
    }
    ll r = sqrt(n);
    for (ll b = 2; b <= r; b++) {
        ll m = n;
        ll ks = 0;
        while (m > 0) {
            ks += m % b;
            m /= b;
        }
        if (ks == s) {
            cout << b << endl;
            return 0;
        }
    }
    for (ll p = r; p > 0; p--) {
        ll b = (n - s) / p + 1;
        if (b == 1) continue;
        ll ks = 0;
        ll m = n;
        while (m > 0) {
            ks += m % b;
            m /= b;
        }
        if (ks == s) {
            cout << b << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 384
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in a:
        t += (1 / i)
    print(1 / t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	int a,b;
	cin>>a>>b;
	int max=a*4,min=a*2;
	if(b>=min&&b<=max&&b%2==0){
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll W, a, b;
  cin >> W >> a >> b;
  if(a > b){
    swap(a, b);
  }
  cout << max(b-a-W, 0LL) << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
 
def main():
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    A = stdin[1:]
    A = np.mod(A, 2)
    print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
    main()


Measured memory_bytes: 14548
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REPRP(i, n) for (int i = (int)(n); (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORP(i, m, n) for(int i = m; i < n+1; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const int INF = 2000000000ll;
const long double PI = acosl(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int power(int a, int b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
int perm(int N, int K){
    int x=1;
    for(int i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
int factorial(int N) {return perm(N,N);}
int comb(int N,int K) {return factorial(N)/factorial(K)/factorial(N-K);}
int hcomb(int N, int K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

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

int mystoi(string S){
    int num = 0;
    for (int i = (int) S.length()-1; i >= 0; i--){
        num += (S[i]-'0') * power(10,S.length()-1-i);
    }
    return num;
}

template<class T>
int SUM(T a) {
    int sum = 0;
    for(auto iter : a) sum += iter;
    return sum;
}

void solve(int K, int A, int B);

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int K, A, B;
    cin >> K >> A >> B;
    solve(K, A, B);
    return 0;
}

void solve(int K, int A, int B) {
    int ans = 0;
    FOR(i,A,B+1) if (i%K == 0) {
        p("OK");
        return;
    }
    p("NG");
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh submit.sh
*/


Measured memory_bytes: 3620
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {
	int N,M;
	cin >> N >> M;
	vector<int> H(N);
	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		cin>>H.at(i);
		C.at(i) = 0;
	}
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		if (H.at(A - 1) >= H.at(B - 1)) {
			C.at(B - 1) = 1;
		}
		if (H.at(A - 1) <= H.at(B - 1)) {
			C.at(A - 1) = 1;
		}
	}

	int an = 0;
	rep(i, N) {
		if (C.at(i) ==0) {
			an++;
		}
	}

	cout<< an<<endl;
}


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

int main()
{
    cin >> n;

    rep(i, 0, n)
    {
        int h;
        cin >> h;
        hs.push_back(h);
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(hs[0] - hs[1]);
    rep(i,2,n){
           dp[i] = min(dp[i-1]+abs(hs[i-1]-hs[i]), dp[i-2]+abs(hs[i-2]-hs[i]));
    }
     cout << dp[n-1] << endl;
}

Measured memory_bytes: 4148
#include<stdio.h>

int main()
{
  int a,b,c,d,e;
  scanf("%i %i %i %i %i",&a,&b,&c,&d,&e);
  int p=a-e;
  int o=b-e;
  if(c >= e && d >= e && p >= c && o >= d)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}




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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a > b){
    if( c > a||c < b ){
      cout << "No";
      return 0;
    }
  }else if (a < b){
    if(c < a || c > b){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
V = list(map(int, input().split()))

d1 = {0:0}
d2 = {0:0}
for i, v in enumerate(V):
    d = d2 if i&1 else d1
    if v not in d: d[v]=0
    d[v]+=1
    

d1 = sorted(list(d1.items()), key=lambda x:-x[1])
d2 = sorted(list(d2.items()), key=lambda x:-x[1])

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

Measured memory_bytes: 18072
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ret = 0;
	for (int i = a; i <= b; i++) {
		if (c%i == 0)ret++;
	}
	cout << ret << endl;
	return 0;
}


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

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int q; cin >> q;
  while(q--) {
    int c, a, n;
    cin >> c >> a >> n;
    int ans  =0;
    for(int i = 0; i <= c; i+=3) for(int j = 0; i + j <= c; j+=2) {
      ans = max(ans, i/3 + j/2 + min(min(c-i-j, a - j/2), n));
    }
    cout << ans << endl;
  }
  return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    string s; cin>>s;
    string div[4]={"dream","dreamer","erase","eraser"};
    reverse(s.begin(),s.end());
    rep(i,4) reverse(div[i].begin(),div[i].end());
    bool ok=true;
    for(int i=0;i<s.size();){
        bool ok2=false;
        rep(j,4){
            string d=div[j];
            if(s.substr(i,d.size())==d){
                ok2=true;
                i+=d.size();
            }
        }
        if(!ok2){
            ok=false;
            break;
        }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int n, a, b;
	cin >> n >> a >> b;
	print(min(n*a, b));





	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string s,t;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	cin>>s>>t;cout<<t<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int top,mystack[1000];

void push_mystack(int a){
    mystack[++top]=a;
}

int pop_mystack(){
    top--;
    return mystack[top+1];
}

int main() {
    int a,b;
    top=0;
    char s[100];
    while (scanf("%s",s)!=EOF){
        if (s[0]=='+'){
            a=pop_mystack();
            b=pop_mystack();
            push_mystack(a+b);
        } else if (s[0]=='-'){
            a=pop_mystack();
            b=pop_mystack();
            push_mystack(b-a);
        } else if (s[0]=='*'){
            a=pop_mystack();
            b=pop_mystack();
            push_mystack(b*a);
        } else{
            push_mystack(atoi(s));
        }
    }

    printf("%d\n",pop_mystack());
    return 0;
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< int > a(n), b(n,-1), c(n, -1);
  rep(i,0,n) {
    char c; std::cin >> c;
    a.at(i) = c == 'o';
  }
  auto check = [n] (auto a, auto b, auto c, int b0, int b1) mutable -> std::string {
    // debug(b);
    b.at(0) = b0;
    b.at(1) = b1;
    c.at(0) = a.at(0) ^ b.at(0);
    c.at(1) = a.at(1) ^ b.at(1);
    rep(i,2,n) {
      b.at(i) = b.at(i-2) ^ c.at(i-1);
      c.at(i) = a.at(i) ^ b.at(i);
    }
    std::string s(n, '$');
    std::transform(all(b), s.begin(), [](int x){ return x ? 'S' : 'W'; });
    // debug(a,b,c);
    // debug(s);
    if (
      ((b.at(n-2)^c.at(n-1)^b.at(0)) != 0) || ((b.at(n-1)^c.at(0)^b.at(1)) != 0)
    ) return std::string{};
    return s;
  };
  rep(b0,0,2) rep(b1,0,2) {
    std::string ans = check(a,b,c,b0,b1);
    if (!ans.empty()) {
      std::cout << ans << std::endl;
      return 0;
    }
    // debug(ans);
  }
  std::cout << -1 << std::endl;
  return 0;
}

Measured memory_bytes: 2792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;

const int maxn=55;
int cont[maxn];

int main() {
   int n,m;
   cin >> n >> m;
   while(m--){
       int f,t;
       cin >>f >> t;
       cont[f]++,cont[t]++;
   }
   for(int i=1; i <= n; i++){
       cout << cont[i] << endl;
   }
   return 0;
}

Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)


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

using ll=long long;
using ld= long double;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define ALL(v) v.begin(),v.end()
#define EPS 1e-10

int main(){
	int n;
	cin>>n;
	vector<ll> x(n),y(n);
	ld sumx=0,sumy=0;
	REP(i,n) {
		cin>>x[i]>>y[i];
		sumx+=x[i];
		sumy+=y[i];
	}
	sumx/=n;
	sumy/=n;
	if(n&1){cout<<"NA"<<endl;return 0;}
	bool ok=true;
	REP(i,n/2) {
		if(abs(sumx*2-(x[i]+x[i+n/2]))>EPS)ok=false;
		if(abs(sumy*2-(y[i]+y[i+n/2]))>EPS)ok=false;
	}
	if(ok)cout<<fixed<<setprecision(10)<<sumx<<" "<<sumy<<endl;
	else cout<<"NA"<<endl;
	
}


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

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

// cout<<fixed<<setprecision(10);

template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int N_MAX = 1e5;
string str[N_MAX];

ll kaijou(int k){
    if(k == 1) return 1;
    return k* kaijou(k-1);
}

int main(){
    int n, m; cin >> n >> m;
    if(n == m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n; cin >> n;
    vector<ll> c(n), s(n), f(n), res(n, 0);
    REP(i, n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    //cout << c << endl;
    REP(i, n-1){
        ll time = c[i] + s[i];
        for(int j = i+1; j<n-1; j++){
            if(time%f[j] == 0 && time >= s[j]){
                time += c[j];
            }
            else if(time >= s[j]){
                ll departure = s[j];
                while(departure < time){
                    departure += f[j];
                    //cout << departure << endl;
                }
                time += (departure - time);
                time += c[j];
            }
            else if(time%f[j] == 0){
                time += (s[j] - time);
                time += c[j];
            }
            else{
                time += (s[j] - time);
                time += c[j];
            }
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}

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


Measured memory_bytes: 256
def resolve():
    S = list(input())
    MOD = 10**9+7
    dp = [[0 for _ in range(13)] for __ in range(len(S)+1)]
    dp[0][0] = 1
    for i in range(len(S)):
        for j in range(13):
            if S[i] == "?":
                for k in range(10):
                    dp[i+1][(j*10+k)%13] += dp[i][j]
                    if dp[i+1][(j*10+k)%13] > MOD:
                        dp[i+1][(j*10+k)%13] -= MOD
            else:
                k = int(S[i])
                dp[i+1][(j*10+k)%13] += dp[i][j]
                if dp[i+1][(j*10+k)%13] > MOD:
                    dp[i+1][(j*10+k)%13] -= MOD
    print(dp[len(S)][5])

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 99748
#include<iostream>
#include<vector>
using namespace std;
long long dist[100005];
vector<pair<int,int> > G[100005];
int N,a,b,c,Q,K;
int dfs(int nod)
{
    for(auto it:G[nod])
    {
        if(!dist[it.first])
        {
            dist[it.first]=dist[nod]+it.second;
            dfs(it.first);
        }
    }
}
int main()
{
    cin>>N;
    for(int i=1;i<N;i++){cin>>a>>b>>c;G[a].push_back({b,c});G[b].push_back({a,c});}
    cin>>Q>>K;
    dist[K]=1;
    dfs(K);
    while(Q--){cin>>a>>b;cout<<dist[a]+dist[b]-2<<"\n";}
}

Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x))
                .ToArray();
            Array.Reverse(inputs);

            foreach (var itm in inputs) 
                if(itm == inputs.Last())
                Console.WriteLine(itm.ToString());
            else
                Console.Write(itm.ToString() +  " ");
        }
    }
}

Measured memory_bytes: 9596
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}

int main() {
	hurui(1e6 + 5);
	int num;
	while (cin >> num) {
		auto it = upper_bound(primes.begin(), primes.end(),num);
		cout << it - primes.begin() << endl;
	}
	return 0;
}

Measured memory_bytes: 7216
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S;
    cin >> S;

    switch(S[0])
    {
        case 'S' : cout << "Cloudy\n"; break;
        case 'C' : cout << "Rainy\n";  break;
        case 'R' : cout << "Sunny\n";  break;
    }

    return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

bool dpl[5005][5005];
bool dpr[5005][5005];

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

  int N, K;
  cin >> N >> K;
  vint a(N);
  rep(i, N) cin >> a[i];
  sort(all(a));

  memset(dpl, false, sizeof(dpl));
  dpl[0][0] = true;
  rep(i, N) rep(j, K) if(dpl[i][j]) {
    dpl[i+1][j] = dpl[i+1][min(K, j+a[i])] = true;
  }

  memset(dpr, false, sizeof(dpr));
  dpr[N][0] = true;
  for(int i = N; i > 0; i--) {
    rep(j, K) if(dpr[i][j]) {
      dpr[i-1][j] = dpr[i-1][min(K, j+a[i-1])] = true;
    }
  }

  int ans = 0;
  rep(i, N) {
    vint c;
    rep(j, K) if(dpr[i+1][j]) c.push_back(j);
    rep(j, K) {
      if(!dpl[i][j]) continue;
      auto it = lower_bound(all(c), K-a[i]-j);
      if(it == end(c)) continue;
      if(*it + j < K) {	ans++; break; }
    }
  }
  cout << N-ans << endl;

  return 0;
}


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

int main(){
  int a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 256
c1,c2,c3,c4=0,0,0,0
for i in range(3):
  a,b=map(int,input().split(" "))
  if a==1 or b==1:
    c1+=1
  if a==2 or b==2:
    c2+=1
  if a==3 or b==3:
    c3+=1
  if a==4 or b==4:
    c4+=1  
if c1<=2 and c2<=2 and c3<=2 and c4<=2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
N = gets.to_i

def e(n)
    if n > 9
        9
    else
        n
    end
end

def f(n)
    if n < 100
        0
    elsif n > 999
        900
    else
        n - 99
    end
end

def g(n)
    if n < 10000
        0
    elsif n > 99999
        90000
    else
        n - 9999
    end
end

puts e(N) + f(N) + g(N)

Measured memory_bytes: 1788
#include<stdio.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  int d;
  int a[n];
  
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

  for(i=0;i<n;i++){
    for(j=i+1;j<n;++j){
      
	d =a[i];
        a[i]=a[j];
        a[j]=d;}}

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i != n-1)printf(" ");}

  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=100005;

int n,ans; LL a[N];
map<LL,int>cnt;

inline LL Opp(LL x) {
	LL tmp=x, s=8, ret=1;
	for(int j=2;s<=tmp;j++,s=1ll*j*j*j)
		if(tmp%j==0) {
			tmp/=j;
			if(tmp%j==0)
				ret*=j,tmp/=j;
			else ret*=j*j;
			if(ret>1e10) return -1;
		}
	s=sqrt(tmp);
	if(s*s==tmp) return ret*s;
	if((ret*=tmp)>1e10) return -1;
	return ret*tmp;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		LL tmp=a[i], s=8; a[i]=1;
		for(int j=2;s<=tmp;j++,s=1ll*j*j*j) {
			while(tmp%s==0) tmp/=s;
			while(tmp%j==0) tmp/=j,a[i]*=j;
		}
		if(tmp>1) a[i]*=tmp;
		cnt[a[i]]++;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) {
		if(a[i]==1) continue;
		if(a[i]!=a[i-1]) {
			LL op=Opp(a[i]);
			ans+=max(cnt[a[i]],cnt[op]);
			cnt[a[i]]=cnt[op]=0;
		}
	}
	printf("%d\n",ans+(a[1]==1));
	return 0;
}

Measured memory_bytes: 14212
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
    int x1, y1, x2, y2, r1, r2, l, ans;
    scanf("%d%d%d", &x1, &y1, &r1);
    scanf("%d%d%d", &x2, &y2, &r2);
    l=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
    if(l>r1+r2)ans=4;
    else if(l==r1+r2)ans=3;
    else if(l>abs(r1-r2))ans=2;
    else if(l==abs(r1-r2))ans=1;
    else ans=0;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 600
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))


if __name__ == "__main__":
    N, M, Q = LI()
    LR = [[0]*(N+1) for _ in range(N+1)]
    for i in range(M):
        l, r = LI()
        LR[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(1, N+1):
            LR[i][j] += LR[i][j-1]
            LR[i][j] += LR[i-1][j]
            LR[i][j] -= LR[i-1][j-1]

    for _ in range(Q):
        p, q = LI()
        p -= 1
        result = LR[q][q] - LR[p][q] - LR[q][p] + LR[p][p]
        print(result)


Measured memory_bytes: 13376
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    priority_queue<int> a;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        a.push(k);
    }
    vector<pair<int,int>> v(m);
    for(int i=0;i<m;i++)cin>>v[i].second>>v[i].first;
    sort(All(v));
    reverse(All(v));
    int cnt=n;
    for(auto it:v){
        for(int i=0;i<min(cnt,it.second);i++){
            a.push(it.first);
        }
        cnt-=it.second;
        if(cnt<=0)break;
    }
    int res=0;
    for(int i=0;i<n;i++){
        res+=a.top();
        a.pop();
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3956
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

struct UnionFind {
    vector<int> par, value;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) {return find(x) == find(y);}
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return false;
        --cnt;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

const int MAXN = 100100;
pair<char, int> query[MAXN];

int par[MAXN], value[MAXN], cnt[MAXN];

int getPar(int v) {
    if (cnt[v]) return v;
    else return par[v] = getPar(par[v]);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    while (cin >> N >> Q) {
        if (N==0 && Q==0) break;
        memset(par, -1, sizeof(par));
        memset(cnt, 0, sizeof(cnt));
        for (int i = 1; i < N; i++) {
            int p;
            cin >> p; p--;
            par[i] = p;
        }
        cnt[0] = 1;
        for (int i = 0; i < Q; i++) {
            cin >> query[i].first >> query[i].second;
            query[i].second--;
            if (query[i].first == 'M') {
                cnt[query[i].second]++;
            }
        }
        ll ans = 0;
        for (int i = Q-1; i >= 0; i--) {
            char c = query[i].first;
            int v = query[i].second;
            if (c == 'M') cnt[v]--;
            else ans += getPar(v)+1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4732
#include<cstdio>
typedef long long ll;
const int MaxN=1<<18,mod=924844033;
int sz[MaxN];
struct edge{int to;edge*next;}E[MaxN*2],*ne=E,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
void dfs(int i,int f=0){
	sz[i]=1;
	for(edge*e=fir[i];e;e=e->next)
		if(e->to!=f)dfs(e->to,i),sz[i]+=sz[e->to];
}
ll fac[MaxN],ifac[MaxN],w[MaxN*2];
int A[MaxN*2],B[MaxN*2];
ll pw(ll a,ll n=mod-2){ll b=1;for(;n;n>>=1)n%2?b=b*a%mod:1,a=a*a%mod;return b;}
void dft(int*a,int n,bool r=0){
	*w=1;w[1]=pw(5,(mod-1)/n);
	if(r)w[1]=pw(w[1]);
	for(int i=2;i<n;i++)w[i]=w[i-1]*w[1]%mod;
	for(int i=0,j=0,t;i<n;i++){
		if(i<j)t=a[i],a[i]=a[j],a[j]=t;
		for(t=n/2;(j^=t)<t;t/=2);
	}
	for(int i=1,m=1;m<n;i++,m*=2){
		for(int j=0;j<n;j+=m<<1){
			for(int k=0,t;k<m;k++){
				t=a[j+m+k]*w[(n>>i)*k]%mod;
				a[j+m+k]=(a[j+k]+mod-t)%mod;
				(a[j+k]+=t)%=mod;
			}
		}
	}
	if(r){
		ll I=pw(n);
		for(int i=0;i<n;i++)a[i]=a[i]*I%mod;
	}
}
int main(){
	int N;scanf("%d",&N);
	for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	dfs(1);
	for(int i=*fac=1;i<=N;i++)fac[i]=fac[i-1]*i%mod;
	ifac[N]=pw(fac[N]);
	for(int i=N;i;i--)ifac[i-1]=ifac[i]*i%mod;
	for(int i=2;i<=N;i++)A[sz[i]]++,A[N-sz[i]]++;
	for(int i=0;i<=N;i++){
		A[i]=A[i]*fac[N-i]%mod;
		B[i]=ifac[i]%mod;
	}
	int n=1;while(n<=N*2)n*=2;
	dft(A,n);
	dft(B,n);
	for(int i=0;i<n;i++)A[i]=1ll*A[i]*B[i]%mod;
	dft(A,n,1);
	for(int i=1;i<=N;i++){
		int ans=(fac[N]*ifac[N-i]%mod*N%mod+mod-A[N-i])*ifac[i]%mod;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 33408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define NUM 1000000007
#define MAX 100001
#define INF LLONG_MAX
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n;
    vector<ll> x,y;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        x.pb(a);
        y.pb(b);
    }
    ll maxi1=INT_MIN,mini1=INT_MAX,maxi2=INT_MIN,mini2=INT_MAX;
    for(int i=0;i<n;i++){
        maxi1 = max(maxi1,x[i]-y[i]);
        mini1 = min(mini1,x[i]-y[i]);
        maxi2 = max(maxi2,x[i]+y[i]);
        mini2 = min(mini2,x[i]+y[i]);
    }
    cout<<max(maxi1-mini1,maxi2-mini2)<<endl;
    return 0;
}


Measured memory_bytes: 6656
//  A bug is never just a mistake. It represents something bigger. An error of thinking that makes you who you are.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 200009
const int inf = 1e9+2;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl

int n,m,k;
vector<string> grid;


int main(){
		
	ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>k;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--;y1--;x2--;y2--;
    
    rep(i,0,n){
    	string pp;
    	cin>>pp;
    	grid.pb(pp);
    }
    int dx[] = {-1,0,1,0};
    int dy[] = {0,1,0,-1};
    bool vis[n][m];
    memset(vis,0,sizeof(vis));

    queue<pii> q;
    q.push({x1,y1});
    int d[n][m];
    rep(i,0,n){
    	rep(j,0,m){
    		d[i][j] = inf;
    	}
    }
    d[x1][y1] = 0;
    vis[x1][y1] = 1;

    while(!q.empty()){
    	pii u = q.front();
    	q.pop();
    	rep(i,0,4){
    		rep(j,1,k+1){
    			pii v = {u.first+j*dx[i],u.second+j*dy[i]};
    			if(v.first<0 || v.second<0 || v.first>=n || v.second>=m)break;
    			if(d[v.first][v.second]<d[u.first][u.second]+1)break;
    			if(vis[v.first][v.second])continue;
    			if(grid[v.first][v.second]=='@')break;
    			vis[v.first][v.second]=1;
    			d[v.first][v.second]=d[u.first][u.second]+1;
    			q.push(v);
    		}
    	}
    }

    cout<<((d[x2][y2]!=inf)?d[x2][y2]:-1);

}

Measured memory_bytes: 10356
n, k = list(map(int, input().split()))

s = {i: 0 for i in range(1, n+1)}
for i in range(k):
    d = int(input())
    a = list(map(str, input().split()))

    for kasi in a:
        s[int(kasi)] = s[int(kasi)] + 1

ans_list = list(s.values())
ans = ans_list.count(0)
print(ans)


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

int main() {
  int X;
  cin >> X;
  int N;
  cin >> N;
  
  int min = INF, num, def;
  vector<int> p(102);
  rep(i,102) {p.at(i) = 0;} 
  int a;
  rep(i,N) {cin >> a; p.at(a) = 1;} 
  bool nt = false;
  rep(i,102) {
    nt = false;
    if(p.at(i)==1) continue;
    
    def = abs(i-X);
    
    if(min > def){
      min = def;
      num = i;
    }
  }
  
  cout << num << endl;
  
}


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

using namespace std;

struct interval

{
    string start;
int end;
   
 
};

bool compare(interval x,interval y)

{
    if(x.end==y.end)
    {

      return x.start<y.start;
}
 return x.end>y.end;
  }

int main() 

{
  int a[5];
  for(int i=0;i<5;i++)
  {
      cin>>a[i];
      if(a[i]==0)
     {
         cout<<i+1<<endl;
      break;}
  }
  
}

Measured memory_bytes: 3608
N,M=map(int,input().split())

graph=[[] for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
#print(graph)

queue=[1]
d=0
dist=[-1]*(N+1)
while queue:
  new_queue=set()
  for q in queue:
    if dist[q]!=-1:
      continue      
    dist[q]=d
    for v in graph[q]:
      if dist[v]==-1:
        new_queue.add(v)
        
  queue=list(new_queue)
  d+=1
#print(dist)

parent=[-1]*(N+1)
for i in range(1,N+1):
  for v in graph[i]:
    if dist[v]==dist[i]+1:
      parent[v]=i
#print(parent)

print("Yes")
for i in range(2,N+1):
  print(parent[i])

Measured memory_bytes: 37840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    int a,b;
    cin >> a >> b;
    vector<int> v(a);
    REP(i,a){cin >> v[i];}
    sort(v.begin(), v.end());
    int result=0;
    a--;
    REP(i,b){
        result += v[a - i];
    }
    cout << result << endl;
    return 0;
}

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

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

	while(a > 0 || b > 0){
		if(a > 0)
			a -= c;
		if(b > 0)
			b -= d;
		l--;
	}

	cout << l << endl;

	return 0;
}

Measured memory_bytes: 1160
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

k = 0
li = [[0]*w for i in range(h)]

for i in range(h):
  if i%2==0:
    for j in range(w):
      if a[k]!=0:
        li[i][j] = k+1
        a[k]=a[k]-1
      else:
        k = k+1
        li[i][j] = k+1
        a[k]=a[k]-1
        
  if i%2==1:
    for j in range(w)[::-1]:
      if a[k]!=0:
        li[i][j] = k+1
        a[k]=a[k]-1
      else:
        k = k+1
        li[i][j] = k+1
        a[k]=a[k]-1
for i in range(h):
  print(str(li[i]).replace("[","").replace("]","").replace(",",""))

Measured memory_bytes: 3572
import java.util.*;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(400 <= X && X <= 599){
            System.out.println(8);
        }else if(600 <= X && X <= 799){
            System.out.println(7);
        }else if(800 <= X && X <= 999){
            System.out.println(6);
        }else if(1000 <= X && X <= 1199){
            System.out.println(5);
        }else if(1200 <= X && X <= 1399){
            System.out.println(4);
        }else if(1400 <= X && X <= 1599){
            System.out.println(3);
        }else if(1600 <= X && X <= 1799){
            System.out.println(2);
        }else if(1800 <= X && X <= 1999){
            System.out.println(1);
        }
    }
}


Measured memory_bytes: 35548
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <queue>
#include <limits.h>
using namespace std;

typedef long long ll;

const int N = 21, M = 1e9 + 7;
int n, dp[N][1 << N];
vector<vector<int> > can;

int calc(int at, int mask) {
	if (at == n)
		return mask == (1 << n) - 1;
	int &res = dp[at][mask];
	if (res != -1)
		return res;
	res = 0;
	for (int w : can[at])
		if (((mask >> w) & 1) == 0)
			res = (res + calc(at + 1, mask | (1 << w))) % M;
	return res;
}

int main(int argc, char **argv) {
	scanf("%d", &n);
	can.resize(n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			int a;
			scanf("%d", &a);
			if (a == 1)
				can[i].push_back(j);
		}
	memset(dp, -1, sizeof(dp));
	printf("%d\n", calc(0, 0));
	return 0;
}


Measured memory_bytes: 172288
#include <stdio.h>
#include <stdbool.h>

int n, k, m;
int i, j;
int tmp;
int game[20000] = {0};

int main(void){
    while(true){
        scanf("%d %d %d", &n, &k, &m);
        if(n == 0 && k == 0 && m == 0) break;
        for(i = 0; i < n; i++){
            game[i] = i + 1;
        }

        tmp = m - 1;
        while(true){
            if(n == 1) break;
            for(i = tmp; i < n - 1; i++){
                game[i] = game[i + 1];
            }
            n--;
            tmp = (tmp + k - 1) % n;
        }
        printf("%d\n", game[0]);
    }

    return 0;
}



Measured memory_bytes: 1996
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

x,a = get_nums_l()

if(x < a):
    print(0)
else:
    print(10)

Measured memory_bytes: 38488
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int chi = 0;
        int s = -1;
        for(int i = 0 ; i <= 1000 && chi == 0; i++ ){
            int aa = (int)(i * 0.08);
            double bb = (int)(i * 0.1);
            if(a == aa && b == bb){
                chi = 1;
                s = i;
            }
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 35696
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10,mod=998244353;
int n,a[N],num[N],minn[N],maxx[N],now[4];
char s[N];
bool mx[N],mn[N];
long long ans=1;
int read(){
	char ch=getchar();
	int s=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=(s<<3)+(s<<1)+ch-'0';ch=getchar();}
	return s*f;
}
int main(){
	n=read();
	cin>>s+1;
	for(int i=1;i<=3*n;i++){
		if(s[i]=='R') a[i]=0;
		if(s[i]=='G') a[i]=1;
		if(s[i]=='B') a[i]=2;
	}
	for(int i=1;i<=3*n;i++){
		num[a[i]]++;
		if(!minn[num[a[i]]]) minn[num[a[i]]]=i;
		maxx[num[a[i]]]=i;
	}
	for(int i=1;i<=n;i++) mx[maxx[i]]=1,mn[minn[i]]=1;
	for(int i=1;i<=3*n;i++){
		if(mn[i]) now[1]++;
		if(mx[i]){
			ans=(ans*now[2])%mod;
			now[2]--;
		}
		if(!mn[i]&&!mx[i]){
			ans=(ans*now[1])%mod;
			now[1]--;
			now[2]++;
		}
	}
	for(int i=1;i<=n;i++) ans=(ans*i)%mod;
	cout<<ans;
}

Measured memory_bytes: 4736
#include<stdio.h>
#include <string.h>
#include<math.h>

int main(){
	int n,a,b,c,d,ans;
	
	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d==n) ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main()
{

    int N;;
    cin >> N;
    ll power = 1;
    rep(i, N){
        power = (i+1)*power%INF;
    }
    cout << power << endl;

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  int sum = 0;
  for (int i = 0; i < b; i++) sum += vec.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){

    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int brank=1;
    int pass=0;
    rep(i,n){
        if(s[i]=='a'){
            if(pass<a+b){
                pass++;
                fin("Yes");
            } else {
                fin("No");
            }
        } else if(s[i]=='b') {
            if(pass<a+b&&brank<=b){
                pass++;
                brank++;
                fin("Yes");
            } else {
                fin("No");
            }
        } else {
            fin("No");
        }
    }
    

}

Measured memory_bytes: 896