akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n;
bool flag;
map<int, int> mp;
vector<pair<int, int> > adj[17];

void dfs(int curr) {
    for(auto it: adj[curr]) {
        int u = it.first, v = it.second;
        if(mp.find(u) != mp.end()) {
            if(mp[u] != v) {
                flag = false;
                return;
            }
        }
        else {
            mp[u] = v;
            if(v) dfs(u);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) {
        int cnt;
        cin>>cnt;
        f(j, cnt) {
            int u, v;
            cin>>u>>v;
            u--;
            adj[i].pb({u, v});
        }
    }
    int ans = 0;
    f(mask, (1 << n)) {
        flag = true;
        mp.clear();
        f(i, n) {
            if(mask & (1 << i)) mp[i] = 1;
        }
        for(int i = 0; i < n; i++) {
            if(mask & (1 << i)) {
                dfs(i);
            } 
        }
        //cout<<mask<<' '<<flag<<endl;
        if(flag) ans = max(ans, (ll)__builtin_popcount(mask));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,k[13],s[13][13],p[13],c=0,ans=0;
  cin >> n >> m;
  rep(i,m){
    cin >> k[i];
    rep(j,k[i])cin >> s[i][j];
  }
  rep(i,m)cin >> p[i];
  rep(i,POW2(2,n)){
    rep(j,m){
      rep(l,k[j]){
        if(1==DEC(i,2,s[j][l]-1))c++;
      }
      if(c%2!=p[j]%2)goto A;
      c=0;
    }
    ans++;
    A:;
    c=0;
  }
  printf("%lld",ans);
}

Measured memory_bytes: 256
count = [0 for i in range(26)]
while True:
    try:
        str = input().lower()
    except EOFError:
        break
    for i in range(len(str)):
        for j in range(26):
            if ord(str[i])==97+j:
                count[j]+=1
                break
for i in range(26):
    print(f'{chr(97+i)} : {count[i]}')


Measured memory_bytes: 5572
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  cout << n * (n-1) / 2 << endl;
  return 0;
}


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

dif = [0] * (N-1)
for i in range(1,N): dif[i-1] = A[i] - A[i-1]

ans = 1
t = 0
i = 0
for d in dif:
    if t == 0:
        t = d
    elif d*t < 0:
        ans += 1
        t = 0
print(ans)

Measured memory_bytes: 15020
#include<cstdio>
using namespace std;
const int N=3030,P=1000000007;
int i,j,k,n,m,L,R,t,ans;
int f[2][2][N];
void Up(int &x,int y) {
	x=(x+y)%P;
}
int main() {
	scanf("%d%d",&n,&m);
	L=1;R=0;
	for (i=1;i<=n;i++) f[R][0][i]=1;
	f[R][1][0]=1;
	for (i=1;i<=m;i++) {
		L^=1;R^=1;
		for (j=0;j<=n;j++) {
			if (f[L][0][j]) {
				t=f[L][0][j];
				if (j<n) Up(f[R][0][j+1],t),Up(f[R][0][j],t);
				if (j>1) Up(f[R][0][j-1],t),Up(f[R][0][j],t);
				if (j==1) Up(f[R][1][0],t),Up(f[R][1][1],t);
				f[L][0][j]=0;
			}
			if (f[L][1][j]) {
				t=f[L][1][j];
				if (j<n) Up(f[R][1][j+1],t),Up(f[R][1][j],t);
				if (j>0) Up(f[R][1][j-1],t),Up(f[R][1][j],t);
				f[L][1][j]=0;
			}
		}
	}
	for (i=0;i<=n;i++) Up(ans,f[R][1][i]);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int p[10], c[10]; 
int main() {
	int d, g;
	cin >> d >> g;
	rep(i,d) cin >> p[i] >> c[i];
	int ans = INF;

	rep(s, 1<<d) {
		int now = 0, cnt = 0, imcomplete = 0, idx = -1;
		rep(i,d) {
			if ((s>>i) & 1) {
				now += 100 * (i+1) * p[i] + c[i];
				cnt += p[i];
			} else {
				imcomplete = 100*(i+1);
				idx = i;
			} 
		}
		if (now < g) {
			int rem = g - now;
			int pl = (rem + imcomplete -1) / imcomplete;
			if (pl > p[idx]) continue;
			cnt += pl;
		}
		
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3540
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==0||b==0)
        printf("Zero\n");
    else if(a<0&&b>0)
        printf("Zero\n");
    else if(b<0)
    {
        if(a==b)
            printf("Positive\n");
        else
        {
            int d=b-a+1;
            if(d%2==0)
                printf("Positive\n");
            else
                printf("Negative\n");
        }
    }
    else if(a>0)
        printf("Positive\n");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static int nh = 0, nw = 0;
	static int h, w, n;
	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			h = in.nextInt(); w = in.nextInt(); n = in.nextInt();
			P[] a = new P[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = new P(i+1, in.nextInt());
			}
			Arrays.sort(a, (x, y) -> y.count - x.count);

			List<Integer> list =new ArrayList<>();
			for (P p : a) {
				for (int i = 0; i < p.count; i++) {
					list.add(p.color);
				}
			}
			int c = 0;
			while (c < h*w) {
				int t = c;
				if ((c / w) % 2 == 0) {
					for (int i = t; i < t + w; i++) {
						if (i == t) {
							out.print(list.get(i));
						} else {
							out.print(" " + list.get(i));
						}
						c++;
					}
					out.print("\n");
				} else {
					for (int i = t + w - 1; i >= t; i--) {
						if (i == t + w - 1) {
							out.print(list.get(i));
						} else {
							out.print(" " + list.get(i));
						}
						c++;
					}
					out.print("\n");
				}
			}

		}
		static boolean isMoveRight() {
			return nw+1 == w ? false : true;
		}
		static boolean isMoveLeft() {
			return nw == 0 ? false : true;
		}
		static void right() {
			nw++;
		}
		static void left() {
			nw--;
		}
		static void down() {
			nh++;
		}
	}
	static class P {
		int color, count;
		P(int color, int count) {
			this.color = color;
			this.count = count;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 28116
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
    cnt = math.ceil(i / A)
    dp[0][i] = B * cnt

for i in range(1, N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1])

Measured memory_bytes: 161320
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<endl
using namespace std;

int n, m;
char a[57][57], b[57][57];

bool check(int x, int y){
	rep(i, m) rep(j, m) if(a[x + i][y + j] != b[i][j]) return false;
	return true;
}

int main() {
	SPEED;
//	freopen("input04.in", "r", stdin);
//	freopen("output04.out", "w", stdout);
	
	cin >> n >> m;
	
	rep(i, n) rep(j, n) cin >> a[i][j];
	
	rep(i, m) rep(j, m) cin >> b[i][j];
	
	rep(i, n - m + 1) rep(j, n - m + 1){
		if(a[i][j] == b[0][0]){
			if(check(i, j)){
				print("Yes");
				return 0;
			}
		}
	}
	
	print("No");
	
	return 0;
}


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

int main()
{
	LL a, b, n;
	cin >> n >> a >> b;
	LL c = 0;
	if (a > b) {
		swap(a, b);
	}

	if (a == b) {
		c = 0;
	}
	else if ((b-a)%2 == 0) {
		c = (b-a)/2;
	}
	else  {
		c = min(a-1 + 1 +(b-a)/2, n-b + 1 + (b-a)/2);
	}
	cout << c << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        mut an:[usize;n],
    }
    for j in 0..n{
        let mut l = j;
        while 0 < l  && an[l-1] > an[l] {
            an.swap(l-1,l);
            l -= 1;
        }
        for k in 0..n-1{
            print!("{} ",an[k]);
        }
        println!("{}",an[n-1]);
    }
}


Measured memory_bytes: 5028
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 200005
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;


void solve()
{
    

    lli n,sum=0;
    cin>>n;
    lli arr[n+100]={0};
    for(lli i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    for(lli i=2;i<=n;i++)
    {
        if(arr[i]>=arr[i-1])
            continue;
        else
        {
            sum=sum+(arr[i-1]-arr[i]);
            arr[i]=arr[i-1];
        }
    }

    cout<<sum;


    
}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";

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

int main(int argc, char const *argv[]) {
  string s;
  int sum;

  getline(cin, s);
  while (s != "0") {
    sum = 0;
    for (auto c : s) {
      sum += c - '0';
    }
    cout << sum << endl;
    getline(cin, s);
  }

  return 0;
}


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

using namespace std;

typedef long long               ll;
typedef long double             ld;

#define min3(a, b, c)           min((a), min((b), (c)))
#define max3(a, b, c)           max((a), max((b), (c)))
#define lcm(a,b)                (a / __gcd(a,b) ) *b
#define gcd(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)                  ((a)*(a))
#define urs(r...)               typename decay<decltype(r)>::type
#define FOR(i,a,b)              for(urs(b) i=a;i<b;i++)
#define ROF(i,a,b)              for(urs(b) i=a;i>=b;i--)
#define REP(a,b)                for(urs(b) i=a;i<b;i++)
#define pb                      push_back
#define mk                      make_pair
#define ff                      first
#define ss                      second
#define lb                      lower_bound
#define ub                      upper_bound
#define all(a)                  a.begin(),a.end()
#define vi                      vector <int> 
#define pi                      pair <int, int> 
#define SORT(v)                 sort(v.begin(), v.end());
#define FASTIO                  ios_base::sync_with_stdio(0);cin.tie(NULL);
#define PI                      acos(-1.0)
const int MOD = 1e9 + 7;

ll fast_pow (ll n, ll p)
{
    ll res=1;
    while (p>0)
    {
        if (p&1)
            res = res * n;
        p = p>>1;
        n = n * n;
    }
    return res;
}

ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    B=B%M;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

ll invMOD(ll num,ll M)
{
    return BMod(num,M-2,M);
}

#ifdef Sieve
const int pSz = 50005;
bool np[pSz + 10]; vi prime; int prime_size;
void sieve(){np[0] = np[1] = 1;prime.pb(2);
for(ll i = 4; i <= pSz; i+=2) np[i] = 1;
for(ll i = 3; i <= pSz; i+=2){if(!np[i]){prime.pb(i);
for(ll j = i * i; j <= pSz; j += (i << 1)) np[j] = 1;}}prime_size = prime.size();}
#endif

#ifdef Combi
const int nSz = 2000006;
ll F[nSz + 1], tMod = MOD;
void Factorial(){ F[0] = 1; for(int i = 1; i <= nSz; i++) F[i] = (F[i - 1] * i) % tMod; }
inline ll nCr(int n, int r) { if(n < r) return 0; return (F[n] * invMOD((F[n - r] * F[r]) % tMod, tMod)) % tMod; }
 
#endif

 
//////////////////////////////////////////////////////////////////////////////
///                           M. K. BASHAR                                 ///
///                            IUT CSE'18                                  ///
//////////////////////////////////////////////////////////////////////////////

int main()
{

    string s;
    cin >> s;
    
    int sz = s.length();

    ll ac =0, c =0;

    REP (0, sz)
    {
        if (s[i] == 'A')
            ac++;
        else if (s[i] == 'B' && i+1 < sz && s[i+1] == 'C')
            c += ac, i++;
        else
            ac = 0;
    }

    cout << c;
    return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x;
    scanf("%lld",&x);
    long long ans = 0;
    ans += 2*(x/11);
    x %= 11;
    if (x != 0) ans++;
    if (x > 6) ans++;
    printf("%lld",ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	string S;
	cin >> S;
	if (S == "RRR") {
		cout << 3 << endl;
	}
	else if (S == "SRR" || S == "RRS") {
		cout << 2 << endl;
	}
	else if (S == "SSS") {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3592
/* Author rumoisen */
/* created 2018/11/17 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

void no() { cout << "No" << endl;exit(0);}
void yes() { cout << "Yes" << endl;exit(0);}
void No() { cout << "NO" << endl;exit(0);}
void Yes() { cout << "YES" << endl;exit(0);}

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

using namespace std;

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

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

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

using Graph = vector<vector<int>>;

vector<int> BFS(vector<vector<int>> G) {
	queue<pair<int, int>> que;
	que.push(make_pair(1, -1));
	map<int, int> mp;

	vector<int> ans(G.size());

	while (!que.empty()) {
		int num = que.front().first;
		int preNum = que.front().second;
		que.pop();
		++mp[num];
		ans[num-1]=preNum;
		rep(i, G[num - 1].size()) {
			if (mp[G[num - 1][i]] == 0) {
				++mp[G[num - 1][i]];
				que.push(make_pair(G[num - 1][i], num));
			}
		}
	}
	return ans;
}

int main() {
	int N, M; cin >> N >> M;
	Graph G(N);
	rep(i, M) {
		int A, B; cin >> A >> B;
		G[A - 1].push_back(B);
		G[B - 1].push_back(A);
	}
	vector<int> ans = BFS(G);

	cout << "Yes" << endl;
	rep(i, N - 1) {
		cout << ans[i+1] << endl;
	}
}

Measured memory_bytes: 21000
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    std::vector<ll> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];
    }
    ll ans=0;
    ll x=v[0];
    for (int i = 1; i < n; ++i)
    {
        if(v[i]<x)
        {
            ans+=x-v[i];
        }
        x=max(x,v[i]);
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,m,k,arr[N];

void solve()
{
	string s1,s2;
	int a,b;
	cin>>s1>>s2>>a>>b;
	string s;
	cin>>s;
	if(s == s1)a--;
	else b--;
	cout<<a<<" "<<b;
	    
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 998244353
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "Yes" : "No" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
    int n,k;
    cin >> n >> k;
    int l[k],r[k];
    for(int i = 0; i < k; i++){
        cin >> l[i] >> r[i];
    }
    int dp[n + 5] = {};
    int pref[n + 5] = {};
    dp[1] = 1;
    pref[1] = 1;
    for(int i = 2; i <= n; i++){
        for(int j = 0; j < k; j++){
            if(i <= l[j])
                continue;

            int left = l[j];
            int right = min(r[j], i - 1);
            int val = (pref[i - left] - pref[i- right - 1] + mod) % mod;
            
            dp[i] = (dp[i] + val ) % mod;
        }
        pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
    }
    cout << dp[n] ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 6672
use std::cmp::min;

fn main() {
    let (n, m) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        let s: Vec<usize> = line.split_whitespace().map(|a|a.parse().unwrap()).collect();
        (s[0], s[1])
    };
    let mut bits = vec![0usize; m];
    let mut cost = vec![0i64; m];
    for i in 0..m {
        cost[i] = {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line);
            line.split_whitespace().next().unwrap().parse().unwrap()
        };
        bits[i] = {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line);
            line.split_whitespace().map(|a|a.parse().unwrap()).fold(0, |sum, bit: usize| sum | (1 << (bit - 1)))
        };
    };
    let inf: i64 = 1 << 48;
    let mut dp = vec![inf; 1 << n];
    dp[0] = 0;
    for i in 0..(1<<n) {
        for (&c, &b) in (&cost).iter().zip(&bits) {
            dp[i | b] = min(dp[i | b], dp[i] + c)
        }
    }
    let ret = dp[(1 << n) - 1];
    if ret == inf {
        println!("-1")
    } else {
        println!("{}", ret)
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  int count=0;
  if((int)s.size()==1){
    P(0);
    return 0;
  }
  REP(i,(int)s.size()-1){
    if(s[i]=='B' && s[i+1]=='W'){
      count++;
    }
    if(s[i]=='W' && s[i+1]=='B'){
      count++;
    }
  }
  P(count);
  return 0;
}


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

int main(){
	char enki;
	cin>>enki;
	if(enki=='A'){
		cout<<'T';
	}	else if(enki=='C'){
		cout<<'G';
	}	else if(enki=='G'){
		cout<<'C';
	}	else{
		cout<<'A';
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,i;
	cin >> a >> b;
    int d[b];
    for(i = 0;i<b;++i){
        cin >> d[i];
    }
    int sum = 0;
    for(i = 0;i<b;++i){
    	sum+=d[i];
    }
    if(sum>=a){
    cout << "Yes";
    }else{
    cout << "No";
    }
  
  
  
  
}

Measured memory_bytes: 640
a = input()
b = input()
list_a = []
list_b = []
score = 0
for n in a:
    list_a.append(n)
for m in b:
    list_b.append(m)
for i in range(0, len(list_a)):
    if list_a[i] != list_b[i]:
        score += 1
print(score)

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

int main() {
    int d, n;
    cin >> d >> n;
    if (n == 100) ++n;
    if (d == 0) cout << n << endl;
    else if (d == 1) cout << 100 * n << endl;
    else cout << 10000 * n << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int pos;
string str;

int operate(void);
int mins(int val);
int pls(int val1, int val2);
int multi(int val1, int val2);

int main(void){
    string in;
    for(int res; cin >> in, in != "."; cout << res << endl){
        res = 0;
        rep(P, 3){
            rep(Q, 3){
                rep(R, 3){
                    str = in;
                    replace(all(str), 'P', (char)(P + '0'));
                    replace(all(str), 'Q', (char)(Q + '0'));
                    replace(all(str), 'R', (char)(R + '0'));

                    pos = 0;
                    if(operate() == 2) res++;
                }
            }
        }
    }

	return 0;
}

int operate(void){
    int ret;

    if(str[pos] == '('){
        pos++;
        int a = operate();
   
        char op = str[pos];

        pos++;
        if(op == '+'){
            ret = pls(a, operate());
        }
        else ret = multi(a, operate());

        pos++;
    }
    else if(str[pos] == '-'){
        int cnt = 0;
        while(str[pos] == '-') (++cnt) %= 2, pos++;

        if(cnt) ret = mins(operate());
        else ret = operate();
    }
    else{
        ret = str[pos] - '0';
        pos++;
    }

    return ret;
}

int mins(int val){
    int ret;

    if(val == 0) ret = 2;
    else if(val == 2) ret = 0;
    else ret = val;

    return ret;
}

int pls(int val1, int val2){
    return max(val1, val2);
}

int multi(int val1, int val2){
    return min(val1, val2);
}

Measured memory_bytes: 1200
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
String num,mark="";
ArrayList<String> S=new ArrayList<String>();
ArrayList<String> H=new ArrayList<String>();
ArrayList<String> C=new ArrayList<String>();
ArrayList<String> D=new ArrayList<String>();
for(int i=0;i<4;i++){
    if(i==0)mark="S ";
    if(i==1)mark="H ";
    if(i==2)mark="C ";
    if(i==3)mark="D ";
        for(int j=0;j<13;j++){
        num=String.valueOf(j+1);
        switch(mark){
            case "S ":
                S.add(mark+num);
            break;
            
            case "H ":
                H.add(mark+num);
            break;
            
            case "C ":
                C.add(mark+num);
            break;
            
            case "D ":
                D.add(mark+num);
            break;
        }
        }
}


for(int i=0;i<n;i++){
String mark1=sc.next();
String num1=sc.next();
String str=mark1+" "+num1;
switch(mark1){
    case "S":
        S.remove(str);
    break;
    case "H":
        H.remove(str);
    break;
    case "C":
        C.remove(str);
    break;
    case "D":
        D.remove(str);
    break;
}
}

for(String i:S){
System.out.println(i);
}
for(String i:H){
System.out.println(i);
}
for(String i:C){
System.out.println(i);
}
for(String i:D){
System.out.println(i);
}

}
}


Measured memory_bytes: 26204
n, m, q = [int(i) for i in input().split(" ")]    
c = [[0 for j in range(0, n + 1)] for i in range(0, n + 1)]
s = [[0 for j in range(0, n + 1)] for i in range(0, n + 1)]

for i in range(0, m):
    l, r = [int(j) for j in input().split(" ")]
    c[1 + n - l][r] += 1

for i in range(1, n + 1):
    for j in range(1, n + 1):
        s[i][j] = c[i][j] + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1]

for i in range(0, q):
    pi, qi = [int(j) for j in input().split(" ")]
    print(s[1 + n - pi][qi])

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

const int p=1000000007;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll sum=0;
  rep(i,n) sum+=a[i];
  sum%=p;
  ll ans=0;
  rep(i,n){ans+=(sum-a[i]+p)*a[i]%p;ans%=p;}
  ans*=500000004;
  ans%=p;
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 4816
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	int n;
	cin >> n;
	map<pair<int, int>, ll> mm;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		ll p = 0;
		ll q = 1;
		bool fl = false;
		for (char c : s) {
			if (c == '.') {
				fl = true;
			} else {
				p = p * 10 + (c - '0');
				if (fl) {
					q *= 10;
				}
			}
		}
		int a = 0;
		while (p % 2 == 0) {
			p /= 2;
			++a;
		}
		while (q % 2 == 0) {
			q /= 2;
			--a;
		}

		int b = 0;
		while (p % 5 == 0) {
			p /= 5;
			++b;
		}
		while (q % 5 == 0) {
			q /= 5;
			--b;
		}
		++mm[{a, b}];
	}

	ll ans = 0;
	for (auto x : mm) {
		for (auto y : mm) {
			if (x.first.first + y.first.first >= 0 && x.first.second + y.first.second >= 0) {
				if (x.first == y.first) {
					ans += x.second * (x.second - 1) / 2;
				} else if (x.first < y.first) {
					ans += x.second * y.second;
				}
			}
		}
	}
	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
#include <cstdint>

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s == "abc")cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int INF=1000000;
int n;
int G[100][100];
int d[100];
int color[100];

void dijkstra(){
  int minv;
  for(int i=0;i<n;i++){
    d[i]=INF;
    color[i]=0;
  }
  
  color[0]=1;
  d[0]=0;
  
  while(1){
    minv=INF;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && color[i] !=2){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=2;
    
    for(int v=0;v<n;v++){
      if(color[v]!=2 &&G[u][v] !=INF){
        if(d[v]>d[u]+G[u][v]){
          d[v]=d[u]+G[u][v];
          color[v]=1;
        }
      }
    }
  }
  
  for(int i=0;i<n;i++){
    cout<<i<<" "<<d[i]<<endl;
  }
}

int main(){
  cin>>n;
  int u,k,v,c;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      G[i][j]=INF;
    }
  }
  
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v>>c;
      G[u][v]=c;
    }
  }
  
  dijkstra();
  return 0;
}

      
  


Measured memory_bytes: 3096
main=do
 s<-reverse<$>getLine
 putStrLn$if f s then"YES"else"NO"
f[]=True
f('m':'a':'e':'r':'d':s)=f s
f('r':'e':'m':'a':'e':'r':'d':s)=f s
f('e':'s':'a':'r':'e':s)=f s
f('r':'e':'s':'a':'r':'e':s)=f s
f _=False

Measured memory_bytes: 7548
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int dp[1<<10][100001];
int v[1<<18], w[1<<18];
int solve(int V, int l){
    if(V < 1 << 10){
        return dp[V][l];
    }
    return max(solve((V - 1) / 2, l), l - w[V] >= 0 ? solve((V - 1) / 2, l - w[V]) + v[V] : 0);
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n)cin >> v[i] >> w[i];
    rep(j,100001){
        if(j>=w[0])dp[0][j] = v[0];
    }
    rep(i,min(n, 1<<10) - 1){
        rep(j,100001){
            dp[i + 1][j] = max(dp[i/2][j], j - w[i + 1] >= 0 ? dp[i/2][j-w[i + 1]]+v[i + 1] : 0);
        }
    }
    int q;
    cin >> q;
    while(q--){
        int V, L;
        cin >> V >> L;
        cout << solve(V - 1, L) << "\n";
    }
}


Measured memory_bytes: 405644
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

int main (int argc, char const *argv[])
{
    int64_t A, B;

    scanf("%"PRId64"%"PRId64, &A, &B);

    if (B % A) {
        printf("%"PRId64"\n", B - A);
    } else {
        printf("%"PRId64"\n", B + A);
    }

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N,T;
int predp[3333][3333],sufdp[3333][3333];
int A[3333],B[3333];
signed main(){
	cin>>N>>T;
	rep(i,N){
		cin>>A[i]>>B[i];
	}

	rep(i,N){
		rep(j,T){
			chmax(predp[i+1][j],predp[i][j]);
			if(j+A[i]<T)chmax(predp[i+1][j+A[i]],predp[i][j]+B[i]);
		}
	}

	for(int i=N-1;i>=0;i--){
		rep(j,T){
			chmax(sufdp[i][j],sufdp[i+1][j]);
			if(j+A[i]<T)chmax(sufdp[i][j+A[i]],sufdp[i+1][j]+B[i]);
		}
	}

	int ans=0;
	rep(i,N){
		rep(j,T){
			chmax(ans,predp[i][j]+sufdp[i+1][T-1-j]+B[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 160000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {
	ll n;
	cin >> n;
	map<ll, ll> a;
	rep(i, n) {
		ll num;
		cin >> num;
		a[num] = a[num] + 1;
	}
	ll max_len = 0;
	ll max_len_second = 0;
	for (auto p : a) {
		if (p.second > 1) {
			max_len_second = max_len;
			max_len = p.first;
		}
		if (p.second > 3) {
			max_len_second = max_len;
		}
	}
	cout << max_len * max_len_second << endl;
	
	return 0;
	
}



Measured memory_bytes: 6528
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a == b && b == c){
			System.out.println(1);
		}
		else if(a == b || a == c || b == c){
			System.out.println(2);
		}
		else{
			System.out.println(3);
		}

	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
int n,s=0,tmp, nn;
  cin >> n;
  nn=n;
  for(;n!=0;){
    s+=n%10;
    n=n/10;
  }
  if(nn%s) cout <<"No";
  else cout << "Yes";
  return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  int64 K;
  cin >> K;
  auto X = divisor(K - 1);
  auto Y = divisor(K);
  for(auto &p : Y) X.emplace_back(p);
  sort(begin(X), end(X));
  X.erase(unique(begin(X), end(X)), end(X));
  int64 ret = 0;
  for(auto &p : X) {
    if(p == 1) continue;
    int64 N = K;
    while(N % p == 0) N /= p;
    ret += N - N / p * p == 1;
  }
  cout << ret << endl;
}






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

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0.0;
    rep(i, n) {
        int point = i + 1;
        double p = 1.0 / n;
        while(point < k) {
            point *= 2;
            p /= 2.0;
        }
        ans += p;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n,p;
  cin>>n>>p;
  long long cnt=0,s=1;
  if(n==1){
      cout<<p<<endl;
      return 0;
  }
  for(long long i=2;i<=sqrt(p);i++){
      while(p%i==0){
          cnt++;
          p/=i;
          if(cnt>=n){
              s*=i;
              cnt=0;
          }
      }
      cnt=0;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	int p[100000];
	int i;
	int t;
	int j = 0;
	int ans = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++){
		scanf("%d", &p[i]);
	}

	while (p[j] != '\0'){
		if (p[j] == j + 1){
			t = p[j + 1]; p[j + 1] = p[j]; p[j] = t;
			ans++;
		}
		j++;
	}
	printf("%d\n", ans);
	
	
	return 0;
}



Measured memory_bytes: 512