akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int N;
long long dap[100100], cnt;
char y[100100];
char a[11];
void v(int n){
    long long i, k=0;
    long long ans=0;
    for(i=0; i<n; i++){
        if(y[i] >= '0' && y[i] <= '9'){
            k*=10;
            k+=(y[i]-'0');
        }else{
            ans+=k;
            k=0;
        }
    }
    ans+=k;
    dap[cnt++] = ans;
}
void f(int x, int ycnt){
    if(x==N-1){
        y[ycnt] = a[x];
        v(ycnt+1);
        return;
    }
    y[ycnt] = a[x];
    y[ycnt+1] = '+';
    f(x+1, ycnt+2);
    f(x+1, ycnt+1);
}
int main(){
    int i;
    long long hap = 0;
    scanf("%s", a);
    N = strlen(a);
    f(0, 0);
    for(i=0; i<cnt; i++){
        hap += dap[i];
    }
    printf("%lld\n", hap);
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());

        for (int i = 0; i < N; i++) {
            String S = sc.nextLine();

            Stack<Integer> B = new Stack<>();
            Stack<Integer> C = new Stack<>();

            B.push(0);
            C.push(0);

            boolean flag = true;
            for (int j = 0; j < 10; j++) {
                int A = Integer.parseInt(S.split(" ")[j]);

                if (A > B.peek()) {
                    B.push(A);
                } else if (A > C.peek()) {
                    C.push(A);
                } else {
                    flag = false;
                    break;
                }
            }
            System.out.println((flag)? "YES" : "NO");
        }
    }
}

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

int main() {
	long long A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (B<A){
	    V=-V;
	    W=-W;
	    if (T*V+A-(T*W+B)<=0){
	        cout << "YES" << endl;
	        return 0;
	    }
	}
	else {
	    if (T*W+B-(T*V+A)<=0) {
	        cout << "YES" << endl;
	        return 0;
	    }
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    long double a,b,c;
    cin >> a >> b >> c;
    if(a + b + 2 * sqrt(a * b) < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 123;

int a[N];

main() {
  int n;
  scanf("%d", &n);
  set < int > s;
  for (int i = 1; i <= 10000; i++) {
    s.insert(i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s.erase(a[i]);
  }
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      ans++;
      a[i] = *s.begin();
      s.erase(s.begin());
    }
  }
  cout << ans;
}



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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define scan(n)         scanf("%d",&n)
#define pb              push_back
#define vi              vector<int>
#define ii              pair<int,int>

using namespace std;

int main(){
    int n,k;cin>>n>>k;
    set<int> st;
    while(k--){
        int d;cin>>d;
        while(d--){
            int x;cin>>x;
            st.insert(x);
        }
    }
    cout<<n-st.size()<<endl;
}


Measured memory_bytes: 3632
S = input()
for i in range(len(S)):
  if (i+1)%2==1:
    if not S[i] in ['R', 'U', 'D']:
      print('No')
      break
  else:
    if not S[i] in ['L', 'U', 'D']:
      print('No')
      break
else:
  print('Yes')

Measured memory_bytes: 38384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    D, T, S = map(int, readline().split())
    if T*S >= D:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;
ll x, y, z, l, m, n, r, q, k;

void solve() {
    cin>>n;
    ll sum=0, m = 0;
    for(int i=0;i<n;i++){
        ll num;
        cin>>num;
        sum+=num;
        m = max(m, num);
    }
    cout<<sum-m/2<<'\n';

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  for(int i = 0; i * r <= n; i++){
    for(int j = 0; j * g <= n; j++){
      if(r * i + g * j > n){
        continue;
      }
      if((n - r * i - g * j ) % b == 0){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		int S,h,m,s;
		Scanner sc = new Scanner(System.in);
		S = sc.nextInt();
		
		h = S / 3600;
		m = (S % 3600) / 60;
		s = (S % 3600) % 60;
		
		System.out.println(h+":"+m+":"+s);
	}
}

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

int main() {
  string w, t;
  int ans = 0;
  cin >> w;
  while (cin >> t, t != "END_OF_TEXT") {
    string s;
    for (auto& e : t) {
      s += tolower(e);
    }
    if (w == s) ans++;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
int a[200001];
ll sum[200001];
ll ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>a[i];
		sum[a[i]]++;
	}
	rep(i,n+1){
		ans+=sum[i]*(sum[i]-1)/2;
	}
	rep(i,n){
		ans-=sum[a[i]]*(sum[a[i]]-1)/2;
		cout<<ans+(sum[a[i]]-1)*(sum[a[i]]-2)/2<<"\n";
		ans+=sum[a[i]]*(sum[a[i]]-1)/2;
	}
	re 0;
}

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

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int dp1[3005][3005];
int dp2[3005][3005];

int main()
{
    int n,t;
    cin >> n >> t;
    int a[n],b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < t; j++){
            dp1[i][j] = 0;
            dp2[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < t; j++){
            dp1[i+1][j] = dp1[i][j];
            if(j - a[i] >= 0){
                dp1[i+1][j] = max(dp1[i+1][j],dp1[i][j-a[i]] + b[i]);
            }
        }
    }
    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < t; j++){
            dp2[i+1][j] = dp2[i+2][j];
            if(j - a[i] >= 0){
                dp2[i+1][j] = max(dp2[i+1][j],dp2[i+2][j-a[i]] + b[i]);
            }
        }
    }
    int ans = max(dp1[n][t-1],dp2[1][t-1]);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < t; j++){
            ans = max(ans,dp1[i][j] + b[i] + dp2[i+2][t-j-1]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 70784
while True:
 a, op, b = input().split()
 a = int(a)
 b = int(b)

 if op == '?':
  break

 if op == '+':
  ans = a+b
 elif op == '-':
  ans = a-b
 elif op == '*':
  ans = a*b
 else:
  ans = a/b

 print('%d' %(ans))


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

struct Edge{
    int u, v;
    int64_t cost;
    
    Edge() = default;
    Edge(int u, int v, int64_t cost) : u(u), v(v), cost(cost) {}

    bool operator<(const Edge& other) const{
        return cost < other.cost;
    }
};

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

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

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

// クラスカル法を適用してグラフの最小全域木を求める
template<typename T>
T Kruskal(vector<Edge> &es, int VertexNumber){
    T res = 0;    
    sort(es.begin(), es.end());
    int sz = es.size();
    UnionFind tree(VertexNumber);
    for(int i = 0; i < sz; ++i){
        if(!tree.same(es[i].u, es[i].v)){
            tree.unite(es[i].u, es[i].v);
            res += es[i].cost;
        }
    }
    return res;
}

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

    int n;
    cin >> n;
    vector<tuple<int, int, int>> T1, T2;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        T1.emplace_back(x, y, i);
        T2.emplace_back(y, x, i);
    }
    sort(T1.begin(), T1.end());
    sort(T2.begin(), T2.end());
    vector<Edge> es;
    for(int i = 0; i + 1 < n; ++i){
        int sx = get<0>(T1[i]), tx = get<0>(T1[i + 1]);
        int u = get<2>(T1[i]), v = get<2>(T1[i + 1]);
        es.emplace_back(u, v, tx - sx);
        int sy = get<0>(T2[i]), ty = get<0>(T2[i + 1]);
        u = get<2>(T2[i]), v = get<2>(T2[i + 1]);
        es.emplace_back(u, v, ty - sy);
    }
    UnionFind uf(n);
    cout << Kruskal<int64_t>(es, n) << endl;
}

Measured memory_bytes: 10648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9+7;

int main(){
    int n; cin >> n;
    map<int, int> ma;
    for(int i = 1; i <= n; ++i){
        int t = i;
        for(int j = 2; j * j <= t; ++j){
            int cnt = 0;
            while(t % j == 0){
                t/=j;
                cnt++;
            }
            ma[j] += cnt;
        }
        if(t != 1) ma[t]++;
    }
    ll ans = 1;
    for(auto e : ma){
        //int p = e.first;
        int q = e.second;
        //cout << p << " " << q << endl;
        ans *= (q+1);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
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<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}

unsigned GetDigit(unsigned num){
    return log10(num)+1;
}
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

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

int k,a,b;
cin >> k >> a >> b;
rep(i,b*k+1){
    if(i*k >= a && i*k <= b){
        cout << "OK" << endl;
        return 0;
    }
}
cout << "NG" << endl;


//////////////////////////////////////////////////////
return 0;}


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


int main()
{
  int n;
  cin >> n;
  map<string, int> m;
  ll ans = 0;
  rep(i, n)
  {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ans += m[s];
    m[s]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

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

  res = 1;
  ll basyo;

  if(abs(N-M) > 1)
  {
    cout << 0 << endl;
    return 0;
  }
  else if(abs(N-M) == 0)
  {
    basyo = 2;
  }
  else
  {
    basyo = 1;
  }

  //最初に配置分掛けておく
  res = basyo;
  for(ll i = N; i >= 1; --i)
  {
    res *= i;
    res %= MOD;
  }
  for(ll i = M; i >= 1; --i)
  {
    res *= i;
    res %= MOD;
  }

  cout << res << endl;

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans1,ans2,sum1,sum2;
int n,i;
long long a[100005];
int main()
{
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    if (a[1]>0)
    {
        sum1=a[1];
        ans2=a[1]+1;
        sum2=-1;
    }
    else if (a[1]==0)
    {
        sum1=1;
        ans1=ans2=1;
        sum2=-1;
    }
    else
    {  
        sum1=1;  
        ans1=abs(a[1])+1;  
        sum2=a[1];  
    }  
    for (i=2;i<=n;i++)  
    {     
        if (sum1>0)  
        {  
            if (a[i]+sum1>=0)  
            {  
                ans1+=a[i]+sum1+1;  
                sum1=-1;  
            }  
            else  
            {  
                sum1+=a[i];  
            }  
        }  
        else  
        {  
            if (a[i]+sum1<=0)  
            {  
                ans1+=abs(sum1+a[i])+1;  
                sum1=1;  
            }  
            else  
            {  
                sum1+=a[i];  
            }  
        }  
    }  
    if (sum1==0)  
    {  
        ans1++;  
    }  
    for (i=2;i<=n;i++)  
    {  
        if (sum2>0)  
        {  
            if (a[i]+sum2>=0)  
            {  
                ans2+=a[i]+sum2+1;  
                sum2=-1;  
            }  
            else  
            {  
                sum2+=a[i];  
            }  
        }  
        else  
        {  
            if (a[i]+sum2<=0)  
            {
                ans2+=abs(sum2+a[i])+1;  
                sum2=1;  
            }
            else  
				sum2+=a[i];  
        }  
    }  
    if (sum2==0)
    {
		ans2++;
    }  
    cout<<min(ans1,ans2)<<endl;  
    return 0;
}  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;


int bit[4010];
void add(int a, int w) {
for (int x = a; x <= 4010; x += (x & -x)) bit[x] += w;
}
int sum(int a) {
 int ret = 0;
for (int x = a; x > 0; x -= (x & -x)) ret += bit[x];
 return ret;
}

int main(){
    ll N; cin>>N;
    ll ans=0;
    vector<int> d(N);
    for(int i=0;i<N;i++) cin>>d.at(i);
    sort(d.begin(),d.end());

    for(int i=2;i<N;i++){
        for(int j=0;j<i-1;j++) add(d.at(i-1)+d.at(j),1);
        ll x=sum(d.at(i));
        ans+=x;
        //cout<<i<<' '<<x<<endl;
    }

    ans=((N*(N-1)*(N-2))/6)-ans;
    cout<<ans<<endl;


}

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

void answer1(int n, int a, int b) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int keta_sum = 0;
    int num = i;
    while (num > 0) {
      keta_sum += num % 10;
      num /= 10;
    }
    if (a <= keta_sum && keta_sum <= b) {
      sum += i;
    }
  }
  cout << sum << endl;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  answer1(n, a, b);

}


Measured memory_bytes: 256
// I HAVE ALREADY DONE THIS QUESTION

// LINK - https://www.codechef.com/JAN17/problems/CHEFCIRC/










#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef double LD;
typedef pair<LD, LD> PLD;
typedef pair<PLD, PLD> PPLD;

#define FOR(k,a,b) for(int k(a); k < (b); ++k)
#define FORD(k,a,b) for(int k(b-1); k >= (a); --k)
#define REP(k,a) for(int k=0; k < (a); ++k)
#define ABS(a) ((a)>0?(a):-(a))
#define EPS 1e-9
#define P45 acos(0.0)/2
#define P90 acos(0.0)

LD cross(PLD a, PLD b) { return a.first * b.second - a.second * b.first; }
LD area2(PLD a, PLD b, PLD c) { return cross(a, b) + cross(b, c) + cross(c, a); }

struct CIRCLE
{
	LD x, y, R;
	CIRCLE() {}
	CIRCLE(LD _x, LD _y, LD _R) : x(_x), y(_y), R(_R) {}
	void Read()
	{
		double _x, _y;
		scanf("%lf %lf", &_x, &_y);
		x = _x, y = _y, R = -1;
	}

	PPLD InterSection(const CIRCLE& other)
	{
		LD lx = x, ly = y, lR = R, ox = other.x, oy = other.y, oR = other.R;
		LD d = (lx - ox)*(lx - ox) + (ly - oy)*(ly - oy);
		d = sqrt(d);
		if (ABS(lR + oR - d) < EPS)
			return PPLD(PLD((x + other.x) / 2, (y + other.y) / 2), PLD(x, y));
		if (d < lR + oR)
		{
			LD a = (lR * lR - oR*oR + d*d) / (2.0*d);
			LD h = sqrt(lR*lR - a*a);
			PLD tp1(lx + a*(ox - lx) / d, ly + a*(oy - ly) / d);
			PLD p1(tp1.first + h*(oy - ly) / d, tp1.second - h*(ox - lx) / d);
			PLD p2(tp1.first - h*(oy - ly) / d, tp1.second + h*(ox - lx) / d);
			return PPLD(p1, p2);
		}
		return PPLD(PLD(x, y), PLD(x, y));
	}	
	bool IsIn(const PLD& p) const
	{
		return ABS((p.first - x)*(p.first - x) + (p.second - y)*(p.second - y)) <   R * R + EPS;
	}
};


int main(int argc, char** argv) {
#ifdef HOME
	freopen("in.txt", "rb", stdin);
	freopen("out.txt", "wb", stdout);
#endif
	int N, M;
	scanf("%d", &N);
	M = N;
	vector<CIRCLE> v(N);
	REP(i, N)
		v[i].Read();
	LD lo = 0, hi = 2000;
	while (ABS(hi - lo) > 0.000000001)
	{
		LD actR = (hi + lo) / 2;
		REP(i, N)
			v[i].R = actR;
		int mx = 0;
		REP(i, N) FOR(j,i+1,N)
		{
			PPLD ip = v[i].InterSection(v[j]);
			CIRCLE c1,c2;
			c1.x = ip.first.first, c1.y = ip.first.second, c1.R = actR;
			int db1 = 0, db2 = 0;
			REP(k, N)
			{
				if (c1.IsIn(make_pair(v[k].x, v[k].y)))
					++db1;
			}
			c2.x = ip.second.first, c2.y = ip.second.second, c2.R = actR;
			REP(k, N)
			{
				if (c2.IsIn(make_pair(v[k].x, v[k].y)))
					++db2;
			}
			mx = max<int>(max<int>(db1, db2),mx);
		}
		if (mx >= M)
			hi = actR;
		else
			lo = actR;
	}
	printf("%.10lf\n", lo);
	return 0;
}


Measured memory_bytes: 256
def div_count(a):
  i= 0
  while a%2 == 0:
    a = a/2
    i+=1
  return i
N = int(input())
numbers = list(map(int,input().split()))
count=[]
for u in range(N):
  count.append(div_count(numbers[u]))
print(min(count))

Measured memory_bytes: 3060
import sys

def solve(k, x):
  min_x = max(-1000000, x - k + 1)
  max_x = min(x + k - 1, 1000000)
  ans = [i for i in xrange(min_x, max_x + 1)]
  print " ".join(map(str,ans))


if __name__ == '__main__':

  k, x = map(int, sys.stdin.readline().strip().split(" "))
  solve(k, x)

Measured memory_bytes: 28012
def main():
    n = int(input())
    s = input()
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    ans = r*g*b

    for i in range(n-2):
        for j in range(i+1,n-1):
            if s[i] != s[j]:
                if 2*j-i < n:
                    if s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                        ans-=1

    
    print(ans)

main()

Measured memory_bytes: 9196
import sys

# sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def main():
    h, w = read_int_list()
    for i in range(h):
        l = read_str()
        print(l)
        print(l)



main()


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

typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) { 
    cin >> a[i];
  }
  ll sum = 0;
  for(int i = 0; i < n; i++) { 
    sum += a[i];
  }
  set<ll> candidates;
  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need;
    { // calc need
      vector<ll> r(n);
      for(int i = 0; i < n; i++) {
        r[i] = a[i]%x;
      }
      sort(r.begin(), r.end());
      ll tot = 0;
      for(int i = 0; i < n; i++) {
        tot += r[i];
      }
      int l = n-tot/x;
      need = 0;
      for(int i = 0; i < l; i++) {
        need += r[i];
      }
    }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,r;
    cin >> n >> r;
    if(n >= 10) cout << r << endl;
    else cout << r + 100 * (10-n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "queue"
#include "cstdio"
 
using namespace std;

long long int N, M, K, L, R;
 
class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node) return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v) return;
		if (rank[u] < rank[v]) parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v]) rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> M >> K;
	vector<vector<int>> edge(N);
	UnionFind uf(N);
	vector<int> num(N);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--, R--;
		uf.Unite(L, R);
		num[L]++;
		num[R]++;
	}
	for (int i = 0; i < K; i++) {
		cin >> L >> R;
		L--, R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int> sz(N);
	for (int i = 0; i < N; i++) {
		sz[uf.Find(i)]++;
	}
	for (int i = 0; i < N; i++) {
		int ans = sz[uf.Find(i)] - 1 - num[i];
		for (auto j : edge[i]) {
			if (uf.Check_Same(i, j)) ans--;
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 7552
import java.util.Scanner;
 
class Main {
    	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
        	while(true){
            		String str = sc.next();
             		if(str.charAt(0) == '0'){
                		break;
            		}
	            	int ans = 0;
            		for(int i = 0; i < str.length(); i++){
                		ans += (int)str.charAt(i)-48;
            		}
            		System.out.println(ans);
        	}
    	}
}

Measured memory_bytes: 17184
#include <stdio.h>
                                                                                                          
int main(void){

    char str[10];
    int tmp[10],tmp2[10];
    int i,j,k;
    while (scanf("%s",str) != EOF) {

        for(i=0;i<10;i++){
            tmp[i]  = str[i]-48;
        }   

        for(j=9;j>0;j--){
            for(i=0;i<j;i++){
                tmp2[i] = (tmp[i]+tmp[i+1])%10;
            }   

            for(k = 0;k<10;k++) {
                tmp[k] = tmp2[k];
            }   
        }   
        printf("%d\n",tmp2[0]);

    }   

    return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

char S[10],a[10]={'a','b','c','d','e','f','g','h','i','j'};

int N;

void rec(vector<char> A,int n)
{
  int i,j,k,m;
  
  m=A.size();
  

  
  if(m==N)
  {
    for(i=0;i<m;i++)
    {
      cout<<A[i];
    }
    cout<<endl;
    return ;
  }
  
  for(i=0;i<n+1;i++)
  {
    A.push_back(a[i]);
    if(i<n)rec(A,n);
    else rec(A,n+1);
    A.pop_back();
  }
  
}


int main()
{
  cin>>N;
  
  vector<char> A;
  A.push_back(a[0]);
  
  rec(A,1);
  
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

int toInt(const string &s) {
  int res = 0;
  for(int i = 0; i < s.size(); ++i) {
    res = res * 10 + (s[i]-'0');
  }
  return res;
}

map<int,int> cost;

void bfs() {
  const string s = "01234567";
  static int di[] = {0,1,0,-1};
  static int dj[] = {1,0,-1,0};
  queue<string> que;
  que.push(s);
  cost[toInt(s)] = 0;
  while(que.size()) {
    const string n = que.front();
    const int in = toInt(n);
    que.pop();
    const int p = n.find('0');
    const int pi = p / 4;
    const int pj = p % 4;
    for(int k = 0; k < 4; ++k) {
      int qi = pi + di[k];
      int qj = pj + dj[k];
      if(qi < 0 || qi >= 2) continue;
      if(qj < 0 || qj >= 4) continue;
      int q = qi * 4 + qj;
      string nn = n;
      swap(nn[p], nn[q]);
      int inn = toInt(nn);
      if(cost.count(inn)) continue;
      que.push(nn);
      cost[inn] = cost[in] + 1;
    }
  }
}

int main() {
  bfs();
  while(1) {
    string s(8, ' ');
    for(int i = 0; i < 8; ++i) {
      if(cin >> s[i]) ; else return 0;
    }
    cout << cost[toInt(s)] << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

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

Measured memory_bytes: 256
n, *A = map(int, open(0).read().split())
s = 1000
t = 0
for a0, a1 in zip(A, A[1:]):
    s += t*a0
    t = 0
    if a0 < a1:
        t = s // a0
        s -= t*a0
if t:
    s += t*a1
print(s)

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

void dfs(vector<vi> & g , vi & used , int cur){
	used[cur] = 1;
	for(int to : g[cur]){
		if(!used[to]){
			dfs(g , used , to);
		}
	}
}

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

	int n , m;
	cin >> n >> m;
	
	vector<pii> adj;
	rep(i , m){
		int u , v;
		cin >> u >> v;
		--u;
		--v;
		adj.pb({u , v});
	}
	
	int ans = 0;
	
	rep(i , m){
		vector<vi> g(n);
		rep(j , m){
			if(i != j){
				int u = adj[j].fi;
				int v = adj[j].se;
				g[u].pb(v);
				g[v].pb(u);
			}
		}
		
		vi used(n , 0);
		dfs(g , used , 0);
		rep(i , n){
			if(!used[i]){
				++ans;
				break;
			}
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
string d[2][555555];
int h[2][555555];
int r[555555];

int main() {
	cin >> n;
	cin >> d[0][0];
	int k = 1;
	for (int i = 1; i <= n; i++) {
		int a = i%2;
		int b = 1-a;
		for (int x = 0; x < 3; x++) {
			for (int y = 0; y < k; y++) {
				int z = x*k+y;
				int u = x;
				string s = "";
				for (auto c : d[b][y]) {
					if (c == 'S') {
						if (u != 0) u = 3-u;
						if (s.size() && s.back() == 'S') s.pop_back();
						else s.push_back('S');
					}
					if (c == 'R') {
						u++;
						if (u == 3) {
							u = 0;
							s.push_back('R');
						}
					}
				}
				d[a][z] = s;
				h[a][z] = h[b][y]+u*k;
				if (i == n) cout << h[a][z] << " ";
			}
		}
		k *= 3;
	}
	cout << "\n";
}


Measured memory_bytes: 43996
/*
Problem :
Algorithm :
Status :
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG printf("Passing Line %d in Function [%s].\n",__LINE__,__FUNCTION__);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 6377292 + 5;
const int BASE = 3;

int n,m;
int bin[MAXN],ans[MAXN];
char s[MAXN];

namespace Trie{
    int tot = 1;
    int trie[MAXN][3],val[MAXN],tag[MAXN];

    void Build(int k,int dep,int num){
        if(dep == n){
            val[k] = num;
            return;
        }
        for(int i = 0;i < BASE;i++){
            trie[k][i] = ++tot;
            Build(trie[k][i],dep + 1,num + i * bin[dep]);
        }
    }

    void down(int k){
        if(tag[k]){
            swap(trie[k][1],trie[k][2]);
            tag[k] = 0;
            for(int i = 0;i < BASE;i++)
                tag[trie[k][i]] ^= 1;
        }
    }

    void dfs(int k,int dep,int num){
        if(dep == n){
            ans[val[k]] = num;
            return;
        }
        down(k);
        for(int i = 0;i < BASE;i++)
            dfs(trie[k][i],dep + 1,num + i * bin[dep]);
    }

    void Add(int k,int dep){
        if(dep == n)
            return;
        down(k);
        Add(trie[k][2],dep + 1);
        swap(trie[k][0],trie[k][1]);
        swap(trie[k][0],trie[k][2]);
    }
}

 int main(){
//     freopen("data.in","r",stdin);
//     freopen("data.out","w",stdout);
    scanf("%d",&n);
    scanf("%s",s + 1);
    m = strlen(s + 1);
    bin[0] = 1;
    for(int i = 1;i <= n;i++)
        bin[i] = bin[i - 1] * BASE;
    Trie::Build(1,0,0);
    for(int i = 1;i <= m;i++){
        if(s[i] == 'S')
            Trie::tag[1] ^= 1;
        else if(s[i] == 'R')
            Trie::Add(1,0);
    }
    Trie::dfs(1,0,0);
    for(int i = 0;i < bin[n];i++)
        printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 21936
// https://www.youtube.com/watch?v=zu0-rIh4ZXM

package main

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

type Path struct {
	y1 int
	x1 int
	y2 int
	x2 int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	h := scanInt(sc)
	w := scanInt(sc)

	paths := make([]Path, 0)
	moves := make([]int, w)

	for y := 0; y < h-1; y++ {
		for x := 0; x < w; x++ {
			coins := scanInt(sc) + moves[x]
			moves[x] = coins % 2
			if moves[x] == 1 {
				paths = append(paths, Path{y, x, y + 1, x})
			}
		}
	}

	y := h - 1
	for x := 0; x < w; x++ {
		coins := scanInt(sc) + moves[x]
		if coins%2 == 1 && x < w-1 {
			moves[x+1] += coins % 2
			paths = append(paths, Path{y, x, y, x + 1})
		}
	}

	fmt.Println(len(paths))
	for _, p := range paths {
		fmt.Println(p.y1+1, p.x1+1, p.y2+1, p.x2+1)
	}
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define dbg(x) cerr << #x << " = " << x << endl;
#define dbgall(x) cerr << #x << " = "; for(auto i_ : x) cerr << i_ << " "; cerr << endl;
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

const int INF = (int) 1e9 + 10;

void run_test() {
	int N, M; cin >> N >> M;
    ll K; cin >> K;
    vi a(N), b(M);
    rep(i, N) cin >> a[i];
    rep(i, M) cin >> b[i];
    int ca = 0;
    ll sum = 0;
    rep(i, N) {
        if(sum + a[i] > K) break;
        sum += a[i];
        ca++;
    }
    int cb = 0;  
    int ans = ca;
    while(true) {
        if(cb == M) break;
        if(sum + b[cb] <= K) sum += b[cb++];
        else {
            while(ca > 0 && sum + b[cb] > K) {
                sum -= a[ca-1];
                ca--;
            }
            if(sum + b[cb] <= K) sum += b[cb++];
            else break;
        }
        ans = max(ans, ca + cb);
    }
    cout << ans << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 4756
//#pragma GCC optimize("Ofast")
	//#pragma GCC target("avx,avx2,fma")
	//#pragma GCC optimization ("unroll-loops")
	
    #include<bits/stdc++.h>
    using namespace std;
	
    #define ll long long
    #define ull unsigned long long
    #define ld long double
    #define ff first
    #define ss second
    #define null NULL
    #define MAX 1000000000  // 1x10^9
    #define all(c) (c).begin(),(c).end()
    #define eb emplace_back
    #define pb push_back
    #define pf push_front
    #define lb lower_bound   //used for sortted 
    #define ub upper_bound 
    #define m_p make_pair      
    #define mod 1000000007
    #define For(i,n) for(int i=(0);i<(n);++i)
    #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
    #define in(s3) inserter((s3), (s3).begin())  //	set_union(all(s1),all(s2),in(s3));
    typedef vector<ll> vl;
    typedef vector< vl > vvl;
    typedef pair< ll,ll> pll;
    typedef map< ll,ll> mll;
    
    //  A-65 Z-90 a-97 z-122   A-a = 32   Z-A = z-a = 35
    //	v.push_back(make_pair(min(2 * k[i], l[i]) - min(k[i], l[i]), i));      //int pos = v[i].second;
    //	floor(log10(no) + 1);                   //	to_string(no).length();             ----- length of a number
	//  llabs - long long of abs
	//  labs -long of abs
	//  sqrtf - sq root of float
	//  sqrtl - sq of long double    ( cout << fixed << setprecision(12) << sqrtl(val2) << endl; )
	//  it = find (all(vec), e);     if(it != vec.end());       it - vec.begin();
   	//	size_t found = str.find(str1);    if(found != string::npos); 	 cout<<found;
    	 
	/*	
		1. ^ is XOR and is used to to check odd occurance of number as a number XORed with itself results in zero so all even	occurrances result in zero.
		2.   & is used to check even or odd. (x & 1) ? printf("Odd") : printf("Even"); 
		3.   left shift(<<) - *         right shift(>>) - /
		4.   int a[] = { 1, 7, 2, 4, 8, 3 }; 
    		 int l = sizeof(a) / sizeof(a[0]); 
    		 sort(a, a + l);  reverse(a, a + l); accumulate(a, a + l, 0); *max_element(a, a + l);
	*/
	
	string to_string(char& x) {      
		string s(1,x);
		return s;    
	} 
	struct obj {
		ull val1;
		ull val2;
		ull pos;
	};
	bool cmp(const pair<int,int>&a,const pair<int,int>&b) {
		if(a.first==b.first)
		return a.second<b.second;
		return a.first<b.first;
	}

	int main() {
		ld d,t,s;
		cin>>d>>t>>s;
		if(t>=d/s)
		cout<<"Yes";
		else
		cout<<"No";
		return 0;
	}





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

int main()
{
  string s;cin>>s;
  int a1=s.find("KIH");
  int a2=s.find("B");
  int a3=s.find("R");
  auto ch=string::npos;
  int n=s.size();
  if(a1==ch||a2==ch||a3==ch)cout<<"NO"<<endl;
  else
  {
    bool ok=true;
    if(a1>=2||a1==1&&s.at(0)!='A')ok=false;
    if(a2-a1!=3&&a2-a1!=4)ok=false;
    if(a2-a1==4&&s.at(a2-1)!='A')ok=false;
    if(a3-a2!=1&&a3-a2!=2)ok=false;
    if(a3-a2==2&&s.at(a3-1)!='A')ok=false;
    if(a3<n-2||a3==n-2&&s.at(n-1)!='A')ok=false;
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


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

using namespace std;

int main() {
    int n, q, a, b;
    cin >> n >> q;

    vector<vector<int> > tree(n+1, vector<int>());
    vector<int> counter(n+1, 0);
    for (int i = 1; i < n; i++) {
        cin >> a >> b;
        tree[a].push_back(b);
      	tree[b].push_back(a);
    }

    int p, x;
    for (int i = 0; i < q; i++) { 
        cin >> p >> x;
        counter[p] += x;
    }

    int now;
    queue<int> qu;
    qu.push(1); 
    vector<bool> check(n+1, false);
    while(!qu.empty()) {
        now = qu.front();
        qu.pop();
        check[now] = true;
        for (int next: tree[now]) {
            if (!check[next]) {
                qu.push(next);
                counter[next] += counter[now];
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << counter[i] << " ";
    }
}

Measured memory_bytes: 15604
#include<iostream>

int main(){
    int A, B;
    std::cin >> A >> B;

    int ans = 0;
    if (A == B)ans = A + B;
    else if(A > B){
        if (A - B > 1){
            ans = A + A-1;
        }
        else ans = A + B;
    }
    else {
        if (B - A > 1){
            ans = B + B-1;
        }
        else ans = A + B;
    }

    std::cout << ans << std::endl;
}

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

int n, a[200005];

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

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int p; cin >> p;
		a[p] = i;
	}

	int consecutive = 0, res = 0;
	for (int i = 1; i <= n; ++i) {
		if (a[i] > a[i - 1]) {
			++consecutive;
		} else {
			consecutive = 1;
		}
		res = max(res, consecutive);
	}

	cout << n - res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    static constexpr ll C = -(1LL << 60);
    struct Edge { int i, c; };
    struct Vertex { ll c; };
    Graph(int n) : n(n), e(n), v(n, { C }) {}
    void add_edge(int i, int j, int c) {
        e[i].push_back({ j, c });
    }
    bool bellman_ford(ll &r) {
        v[0].c = 0;
        for (int k = 1; k < n * 2; k++) {
            for (int i = 0; i < n; i++) {
                if (v[i].c == C) continue;
                for (auto o : e[i]) {
                    ll t = v[i].c + o.c;
                    if (t > v[o.i].c) {
                        v[o.i].c = t;
                        if (k >= n && o.i == n - 1) return true;
                    }
                }
            }
        }
        r = v[n - 1].c;
        return false;
    }
    int n;
    vector<vector<Edge>> e;
    vector<Vertex> v;
};

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

    int n, m, p;
    cin >> n >> m >> p;

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c - p);
    }

    ll r;
    bool b = g.bellman_ford(r);
    cout << (b ? -1 : max(r, 0LL)) << endl;

    return 0;
}

Measured memory_bytes: 512
/*input
31415926535897932384626433832795028841971693993751058209749445923078164062862089986280
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;

void solve()
{ 
    string s;
    cin>>s;
int sum=0;
    for(i=0;i<s.size();i++)
    {
        sum+= s[i]-'0';
    }
    if(sum%9)
         cout<<"No";
     else cout<<"Yes";
}
 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  deque<int> dq;
  for (int i = 0; i < N; i++) {
    int idx = lower_bound(dq.begin(), dq.end(), A.at(i)) - dq.begin();
    if (idx == 0) dq.push_front(A.at(i));
    else dq.at(idx - 1) = A.at(i);
  }
  cout << dq.size() << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int INF = numeric_limits<int>::max();

int sum(int x)
{
    int out = 0;
    while(x) {
        out += x % 10;
        x /= 10;
    }

    return out;
}

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

    int out = INF;

    for(int a = 1; a < n; a++) {
        int b = n - a;
        out = min(out, sum(a) + sum(b));
    }

    cout << out << endl;

    return 0;
}


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

int main()
{
  int nAnum, nBnum, nCnum;
  cin >> nAnum >> nBnum >> nCnum;

  bool nRslt = false;
  for (int n = 1; n <= nBnum; n++)
    if ((nAnum * n - nCnum) % nBnum == 0)
    {
      nRslt = true;
      break;
    }

  if (nRslt)  cout << "YES" << endl;
  else        cout << "NO"  << endl;

  return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> redbox(n, 0);
    vector<int> box(n, 1);
    redbox[0] = 1;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if(redbox[x] == 1 && box[x] >= 2)
        {
            redbox[y] = 1;
        }else if(redbox[x] == 1){
            redbox[x] = 0;
            redbox[y] = 1;
        }
        box[x]--;
        box[y]++;
    }
    int count = 0;
    for (int i = 0; i < n; ++i) {
        ///cout << box[i] << " " << redbox[i] << endl;
        if(redbox[i] == 1 && box[i] >= 1)
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,ans = "aaaaaa";
  int K,rank = 0;
  cin >> s >> K;
  vector<string> v;
  for(int i = 0;i < s.size();i++){
    for(int j = 1;j <= K && i + j - 1 < s.size();j++){
      v.push_back(s.substr(i,j));
    }
  }
  sort(v.begin(),v.end());
  for(int i = 0;rank < K;i++){
    if(ans != v[i]){
      ans = v[i];
      rank++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1660