akhauriyash/Code-Regression huggingface dataset:
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let x: usize = itr.next().unwrap();
    let y: usize = itr.next().unwrap();
    let a: usize = itr.next().unwrap();
    let b: usize = itr.next().unwrap();
    let c: usize = itr.next().unwrap();

    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut p: Vec<i64> = s.split_whitespace().map(|e| e.parse().unwrap()).collect();
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut q: Vec<i64> = s.split_whitespace().map(|e| e.parse().unwrap()).collect();
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let r: Vec<i64> = s.split_whitespace().map(|e| e.parse().unwrap()).collect();

    let mut d: Vec<i64> = vec![];
    p.sort();
    q.sort();
    for &e in p.iter().rev().take(x) {
        d.push(e);
    }

    for &e in q.iter().rev().take(y) {
        d.push(e);
    }

    for &e in r.iter() {
        d.push(e);
    }

    d.sort();

    println!("{}", d.iter().rev().take(x + y).sum::<i64>());
}


Measured memory_bytes: 21752
using System;
using System.Linq;

class Program
{
    static void Main()
    {
    
        var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var r = line[0];
        var c = line[1];

        int [,]table = new int[r+1, c+1];
        
        for(int i = 0; i < r; i++){
            var tline = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for(int l = 0; l < c; l++){
                table[i, l] = tline[l];
                table[r, l] += tline[l];
                table[i, c] += tline[l];
            }
            table[r, c] += table[i, c];
        }
        
        for(int i = 0; i < r+1; i++){
            for(int l = 0; l < c+1; l++){
                Console.Write(table[i, l]);
                
                if(l != c){
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 18396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,N;
    cin>>N>>A>>B;
    if(N*A<=B)
    {
        cout<<N*A<<endl;

    }
    else
    {
        cout<<B<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from math import factorial

n,m=map(int,input().split())
if abs(n-m)>=2:
    print(0)
    exit()
if n==m:
    s=factorial(n)
    print(((s**2)*2)%(10**9+7))
else:
    s=factorial(m)
    t=factorial(n)
    print((s*t)%(10**9+7))

Measured memory_bytes: 5176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main(){

    ll A, B, K;
    cin >> A >> B >> K;

    if(2 * K >= (B-A) + 1 ){
        for(ll i = A; i <= B; i++){
            cout << i << endl;
        }
    }
    else{
        for(ll i = A; i < A + K; i++){
            cout << i << endl;
        }

        for(ll i = B - K + 1; i <= B; i++){
            cout << i << endl;
        }
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int h,w,d;cin>>h>>w>>d;
    int a[h][w];
    map<int,pair<int,int>> mp;
    rep(i,h)rep(j,w){
        cin>>a[i][j];
        mp[a[i][j]]={i,j};
    }
    map<ll,ll> mp2;
    rep(i,d){
        mp2[i]=0;
        for(int j=i+d;j<=h*w;j+=d){
            ll buf=mp2[j-d];
            buf+=abs(mp[j].first-mp[j-d].first)+abs(mp[j].second-mp[j-d].second);
            mp2[j]=buf;
        }
    }
    int q;cin>>q;
    rep(i,q){
        int l,r;cin>>l>>r;
        ll res=mp2[r]-mp2[l];
        cout<<res<<endl;
    }
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int r = count(begin(s), end(s), 'R');
  int b = count(begin(s), end(s), 'B');
  cout << (r > b ? "Yes" : "No") << '\n';
}

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

signed main()
{
	int n;
	cin>>n;
	int a[n+1],b[n+1];
	
	memset(b,0,sizeof(b));
	
	for(int i=2; i<=n; i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	
	for(int i=1; i<=n; i++)
		cout<<b[i]<< endl;
	
	return 0;
}


Measured memory_bytes: 6760
N=int(input())
R=[]
for i in range(N):
    a,b=map(int,input().split())
    R.append([a,b,i])
B=[]
for i in range(N):
    c,d=map(int,input().split())
    B.append([c,d,i])

B.sort()
ans=0
chk=[0 for _ in range(N)]
for c,d,num in B:
    l=[]
    for a,b,r in R:
        if chk[r]==1:
            continue
        if a<c and b<d:
            l.append([b,r])
    if len(l)==0:
        continue
    l.sort(reverse=True)
    chk[l[0][1]]=1
    ans+=1

print(ans)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int bitcount(int x){
	int s=0;while(x) s++,x/=2;
	return s;
}
int main(){
	int i,j,n;cin>>n;int v[n][n];vi d(1<<n,0);
	for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>v[i][j];
	vvi st(n+1);
	for(i=1;i<(1<<n);i++){
		st[__builtin_popcount(i)].pb(i);
		int x=bitcount(i);
		d[i]+=(d[i^(1<<(x-1))]);
		for(j=x-2;j>=0;j--){
			if((1<<j)&i) d[i]+=v[x-1][j];
		}
	}
	for(int k=2;k<=n;k++){
		for(auto i:st[k]){
			for(j=i;j;j=(j-1)&i){
				d[i]=max(d[i],d[j]+d[i-j]);
			}
		}
	}cout<<d.back()<<endl;
//	for(i=0;i<d.size();i++) cout<<i<<' '<<d[i]<<endl;
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	int ls[26];
	bool ok = true;
	for (int i = 0; i < 26; i++)
	{
		ls[i] = -1;
	}
	for (int i = 0; i < s.length(); i++)
	{
		if (ls[s[i] - 'a'] == -1 || ls[s[i] - 'a'] == t[i] - 'a')
		{
			ls[s[i] - 'a'] = t[i] - 'a';
		}
		else
		{
			ok = false;
			break;
		}
	}
	sort(ls, ls+25);
	for (int i = 0; i < 25; i++)
	{
		if (ls[i] > 0 && ls[i] == ls[i + 1])
		{
			ok = false;
			break;
		}
	}

	if (ok)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define int long long
#define INF 100000000000
using namespace std;

/* let a b c be the current bamboo lengths. A,B,C are to be achieved. */
int dfs(int l[], int n, int a, int b, int c, int A, int B, int C, int idx){
	if(idx == n) // finally perform the extension/shortening magic
		return (a&&b&&c)?((abs(A-a)+abs(B-b)+abs(C-c))-30):INF; // subtract 30 cuz intially selecting 3 bamboos doesn't require any cost. hence subtract finally.
	int comp_a = dfs(l, n, a+l[idx], b, c, A, B, C, idx+1) + 10; // use current bamboo in array for compositional magic of a
	int comp_b = dfs(l, n, a, b+l[idx], c, A, B, C, idx+1) + 10; // same but b
	int comp_c = dfs(l, n, a, b, c+l[idx], A, B, C, idx+1) + 10;	// same but c
	int dont_use = dfs(l, n, a, b, c, A, B, C, idx+1); // don't use the current bamboo for any of a or b or c
	return min(min(comp_a, comp_b), min(comp_c, dont_use)); // return minimum of all
}

int32_t main()
{
   int n, A, B, C;
   cin >> n >> A >> B >> C;
   int l[n];
   for(int i=0; i<n; i++)
       cin >> l[i];
    int ans = dfs(l, n, 0, 0, 0, A, B, C, 0);
	cout << ans << endl;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) {
		int x = i ^ j;
		cout << log2(x & -x) + 1 << (j == n ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
static const int MAX_M = 200;
static const int MAX_N = 1000;
static const double EPS = 1e-9;

class Point{
    public:
        double x, y;
 
        Point(double x = 0, double y = 0): x(x), y(y) {}
 
        Point operator + (Point p){ return Point(x + p.x, y + p.y);}
        Point operator - (Point p){ return Point(x - p.x, y - p.y);}
        Point operator * (double a){ return Point(a * x, a * y);}
        Point operator / (double a){ return Point(x / a, y / a);}
 
        double abs(){ return sqrt(norm());}
        double norm(){ return x * x + y * y;}
 
        bool operator < (const Point &p) const{
            return x != p.x ? x < p.x : y < p.y;
        }
 
        bool operator == (const Point &p) const{
            return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
        }
};

typedef Point Vector;

int main(){
	for(;;){
		int m, n;
		Point p1[MAX_M], p2[MAX_N];
		set<Point> sa;
		cin >> m;
		if(m == 0) break;
		for(int i = 0; i < m; i++){
			cin >> p1[i].x >> p1[i].y;
			if(i == 0) continue;
			p1[i].x -= p1[0].x;
			p1[i].y -= p1[0].y;
		}
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> p2[i].x >> p2[i].y;
			sa.insert(p2[i]);
		}
		for(int i = 0; i < n; i++){
			bool flag = true;
			for(int j = 1; j < m; j++){
				if(sa.count(p2[i] + p1[j]) == 0) flag = false;
			}
			if(flag){
				cout << p2[i].x  - p1[0].x << ' ' << p2[i].y - p1[0].y << endl;
			}
		}
	}
	return 0;
}



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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

/* Pass to std::sort */
bool predication(const pair<ll, pair<ll, ll> > &a, const pair<ll, pair<ll, ll> > &b){
    return a.first < b.first;
}

int main(){
    std::ios::sync_with_stdio(false);
    ll t_sum = 0, a_sum = 0;
    ll a, b, n;
    cin >> n;
    vector<pair<ll,pair<ll, ll> > > piii;
    for(int i=0;i<n;++i)
    {
        cin >> a >> b;
        piii.push_back(make_pair(a+b, make_pair(a, b)));
    }

    sort(piii.rbegin(), piii.rend(), predication);

    for(int i=0;i<n;++i)
    {
        if((i%2) == 0)
        {
            t_sum += piii[i].second.first;
        }
        else
        {
            a_sum += piii[i].second.second;
        }
        
    }
    
    cout << t_sum - a_sum << endl;
}

Measured memory_bytes: 4980
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<set>
#include<regex>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<map>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b,sum=0;
    cin >> a >> b;
    for(int i = a; i <= b; ++i) {
        string s = to_string(i);
        if(s.at(0) == s.at(4) && s.at(1) == s.at(3))
            ++sum;
    }
    cout << sum << endl;
}

Measured memory_bytes: 512
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            char alfa = Convert.ToChar(Console.ReadLine());
            if (char.IsUpper(alfa))
            {
                Console.WriteLine('A');
            }
            else
            {
                Console.WriteLine('a');
            }
        }
    }
}


Measured memory_bytes: 25832
#include<bits/stdc++.h>
#include<unordered_set>
#define rep(i,a,b) for(ll i = a; i<b; i+= 1)
#define dep(i,a,b) for(int i = a; i>b; i--)
#define makeUnique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())
#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { std::cout << vec[fl]<< (fl == vec.size()-1?"\n":sep;)}
#define LOG_ints(vec, sep) for (int fl = 0; fl < MAXSIZE; fl++) { std::cout << vec[fl]<< sep; } std::cout << "\n"
#define all(x) (x).begin(), (x).end()
#define LSB(i) ((i) & -(i))
#define MAXSIZE 100000

using namespace std;
typedef long long ll;
typedef vector<int> vi;

void solve() {
	ll n, k;
	cin >> n >> k;
	ll c = n % k;
	cout << min(c, k - c) << endl;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t = 1;
	while (t--) {
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include "boost/multiprecision/cpp_int.hpp"
using ll = long long;
using ull = unsigned long long;
namespace mp = boost::multiprecision;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int X, t; std::cin >> X >> t;

	int ans = X - t;

	if (ans < 0)ans = 0;

	std::cout << ans;

	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
void printv(vector<T> v)
{
    for (T t : v)
    {
        cout << t << " ";
    }
    cout << '\n';
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

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

    int n, x;
    cin >> n >> x;
    vi l;
    REP(i,n){
        int t;
        cin >> t;
        l.emplace_back(t);
    }
    int p = 0;
    REP(i,n){
        p = p + l[i];
       if(p>x) {
           cout << i+1 <<endl;
           return 0;
       }
    }
    cout << n+1 <<endl;
    return 0;
}


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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;

//    cin>>t;
//    while(t--){
        ll n,k,y=1,z=1e18;
        cin>>n>>k;
        ll l1[n+1];
        for(int i=1;i<=n;i++)cin>>l1[i];
        for(int i=1;i<=n-k+1;i++){
            z=min(z,abs(l1[i])+abs(l1[i+k-1]-l1[i]));
            z=min(z,abs(l1[i+k-1])+abs(l1[i+k-1]-l1[i]));
            //cout<<abs(l1[i])+abs(l1[i+k-1]-l1[i])<<endl;
        }
        cout<<z;
    //}
}


Measured memory_bytes: 4380
from collections import defaultdict
import bisect
s = input()
t = input()

N = len(s)

set_s = set(s)
set_t = set(t)

for c in set_t:
    if c not in set_s:
        print(-1)
        exit()

# それぞれの文字のインデックスを記録
idxs = defaultdict(list)
for i in range(N):
    idxs[s[i]].append(i)


current_idx = -1 # ここ0にしているとsの1文字目にtの1文字めと同じのがある時にずれるので注意
total = 0
for c in t:
    next_idx = bisect.bisect(idxs[c], current_idx) # bisect(bisect_right)だと同じやつがある場合その右のidxになる

    if next_idx == len(idxs[c]):
        total += N
        current_idx = idxs[c][0]
    else:
        current_idx = idxs[c][next_idx]


print(total + current_idx + 1)
#print(total , current_idx , 1)

Measured memory_bytes: 8052
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{   int i,N,a[99],cnt=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<N;i++){
        if(a[i]==a[i+1]){
            if(a[i+1]!=a[i+2]){
            cnt += 1;
            }else{
                a[i+1] += 1;
                cnt +=1;
            }
        }
    }
    printf("%d",cnt);


    return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main(){
	var N int
	fmt.Scan(&N)

	var V[20] int
	var C[20] int
	
	for i:=0; i < N; i++ {
		fmt.Scan(&V[i])
	}
	for i:=0; i < N; i++ {
		fmt.Scan(&C[i])
	}
	res := 0
	for i:=0; i < N; i++ {
		if V[i]-C[i] <= 0 {
			continue
		}
		res = res + V[i]-C[i]
	}
	fmt.Println(res)
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, m;
    scanf("%d %d\n", &n, &m);
    vector<pair<long long, int> > tmp;
    for(int i = 0; i < n; ++i){
        long long a;
        cin >> a;
        tmp.push_back(make_pair(a, 1));
    }
    for(int i = 0; i < m; ++i){
        int b;
        long long c;
        cin >> b;
        cin >> c;
        tmp.push_back(make_pair(c, b));
    }
    sort(tmp.begin(), tmp.end());

    long long total = 0;
    int rest = n;
    for(int i = tmp.size() - 1; i >= 0; --i){
        auto p = tmp.at(i);
        int n_take = min(p.second, rest);
        total += p.first * n_take;
        rest -= n_take;
        if(rest <= 0){ break; }
    }
    printf("%lld\n", total);
    return 0;
}

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

template <typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) { data.assign(++sz, 0); }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return ret;
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    BinaryIndexedTree<int> bit(n);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            x--;
            bit.add(x, y);
        } else {
            x--;
            y--;
            int sum = bit.sum(y);
            if (x > 0) sum -= bit.sum(x - 1);
            cout << sum << endl;
        }
    }
}


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

int main(){
    long N;
    cin >> N;
    long A[N];
    long max=0, max2=0;
    for(long i=0; i<N; i++){
        cin >> A[i];
        if(max <= A[i]){
            max2= max;
            max = A[i];
            //cout << "max max2 " << max << " " << max2 << endl;
        }else if( max2 < A[i] ){
            max2= A[i];
        }
        if( i==1 && (max2==0) ){
            max2= A[i];
        }
    }
    for(long i=0; i<N; i++){
        if(A[i]==max){
            cout << max2 << endl;
        }else{
            cout << max << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3200
def main():
  n,k=map(int,input().split())
  s=input()
  
  A=(('L','L'),('L','R'),('R','L'),('R','R'))
  B=[]
  cnt=0
  for i in range(n-1):
    tmp=(s[i],s[i+1])
    cnt+=1
    if tmp==A[1]:
      B.append(cnt)
      cnt=0
    elif tmp==A[2]:
      B.append(cnt)
      cnt=0
  cnt+=1
  B.append(cnt)
  if len(B)//2<=k:
    unhappy=1
  else:
    unhappy=len(B)-2*k
   
  print(n-unhappy)
  
if __name__=='__main__':
  main()

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int x,y;cin>>x>>y;

  int a = y-x;
  if (x>y) a=INF;

  int b = 1 + min(abs(y+x), abs(-y+x)+1);

  cout << min(a,b) << endl;


  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
def f(n, s):
    md = 10 ** 9 + 7
    dp = [1] * n
    for i in range(n - 1):
        if s[i] == "<":
            L = dp[0]
            for dpi in range(1, n - i - 1):
                dp[dpi] = L = (dp[dpi] + L) % md
            dp = dp[:-1]
        else:
            R = dp[-1]
            for dpi in range(n - i - 2, 0, -1):
                dp[dpi] = R = (dp[dpi] + R) % md
            dp = dp[1:]
    print(dp[0])


n = int(input())
s = input()
f(n, s)


Measured memory_bytes: 41196
N, X = map(int, input().split())
x = list(map(int, input().split()))
s = [abs(X-x[i]) for i in range(N)]
def gcd(a,b):
    if b==0:return a
    return gcd(b, a%b)

if N==1:
    print(s[0])
else:
    r = gcd(s[0], s[1])
    if N==2:print(r)
    else:
        for i in range(2, N):
            r = gcd(r,s[i])
        print(r)


Measured memory_bytes: 14224
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector<s64> A = vector<s64>(200000);

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

    s64 N;
    cin >> N;

    rep (i, N) { cin >> A[i]; A[i] -= i + 1; }

    sort(A.begin(), A.begin() + N);

    s64 b = (N & 1) ? A[(N - 1) / 2] : A[N / 2];

    u64 ans = 0;
    rep (i, N)
    {
        ans += abs(b - A[i]);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <tuple>
#include <string>

#define printhere cout << "HERE\n"
#define printV(v, n)    \
    for (int i = 0; i < n; i++) \
        cout << v[i] << " ";
#define readV(v, n)     \
    for (int i = 0; i < n; i++) \
        cin >> v[i];
#define pb(v, t) v.push_back(t)
#define mp(a, b) make_pair(a, b)
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    int k;
    cin >> k;
    getchar();
    string s;
    getline(cin, s);
    if(s.length() <= k) cout << s << "\n";
    else {
        for(int i = 0; i < k; i++) cout << s[i];
        cout << "...\n";
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+5;
ll n,T,b[N],ans,f[N],tot1,tot2;
struct node
{
	ll x,y;
}a[N];
bool mycmp(node x,node y)
{
	return x.x*(y.y+1)>y.x*(x.y+1);
}
int main()
{
	scanf("%lld%lld",&n,&T);
	for(ll i=1;i<=n;i++)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x==0) b[++tot2]=y+1;
		else a[++tot1]={x,y};
	}
	sort(a+1,a+tot1+1,mycmp);
	sort(b+1,b+tot2+1);
	for(ll i=1;i<=35;i++) f[i]=T+1;
	for(ll i=1;i<=tot1;i++)
		for(ll j=35;j>=1;j--)
			f[j]=min(f[j],(f[j-1]+1)*(a[i].x+1)+a[i].y);
	for(ll i=1;i<=tot2;i++) b[i]+=b[i-1];
	for(ll i=0;i<=35;i++)
	{
		if(f[i]>T) continue;
		ll x=0;
		if(tot2) x=upper_bound(b+1,b+tot2+1,T-f[i])-(b+1);
		ans=max(ans,i+x);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  bool flag = false;
  for (int i = 1; i <= 1000; i++) {
    if (K * i >= A && K * i <= B) flag = true;
  }

  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3644
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let m: usize = sc.read();
    let k: usize = sc.read();
    let max = (1 << m) - 1;
    if k > max {
        println!("-1");
        return;
    }

    if m == 1 {
        if k == 0 {
            println!("0 0 1 1");
        } else {
            println!("-1");
        }
        return;
    }

    let mut ans = VecDeque::new();
    ans.push_back(k);
    for i in 0..(max + 1) {
        if i == k {
            continue;
        }
        ans.push_front(i);
        ans.push_back(i);
    }
    ans.push_front(k);

    for a in ans.into_iter() {
        print!("{} ", a);
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    string s,t; cin>>s>>t;
    int t1,t2; cin>>t1>>t2;
    cin>>str;
    if(str==s) cout<<t1-1<<" "<<t2;
    else cout<<t1<<" "<<t2-1;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


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

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int h, w;
            int size, curSize;
            int i, j;

            bool judge;

            while (true)
            {
                h = cin.GetInt();
                w = cin.GetInt();

                if (h == 0 && w == 0)
                    break;

                curSize = size = h * h + w * w;

                judge = false;

                do
                {
                    if (curSize == size)
                        i = h + 1;
                    else
                        i = 1;

                    do
                    {
                        j = 1;

                        while (i * i + j * j < curSize)
                        {
                            j++;
                        }

                        judge = i * i + j * j != curSize && i * i < curSize && i < j;

                        i++;
                    } while (judge);

                    i--;
                } while (i * i + j * j != curSize++ || i >= j);

                curSize--;

                Console.WriteLine("{0} {1}", i, j);
            }
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        private string[] _s;
        private int _i;
        private char[] _sep = { ' ', ',' };

        public string GetLine()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            string line;
            this._i = 0;
            do
            {
                line = Console.ReadLine();
            } while (line == "");

            this._s = line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);

            return this._s[this._i++];
        }

        public int GetInt()
        {
            return int.Parse(this.GetLine());
        }

        public long GetLong()
        {
            return long.Parse(this.GetLine());
        }

        public double GetDouble()
        {
            return double.Parse(this.GetLine());
        }
    }
}

Measured memory_bytes: 5648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ABC150D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInt();
            int N = NM[0];
            int M = NM[1];

            var A = ReadLong().Select(x => x / 2).ToArray();

            long lcm = A[0];
            for (int i = 1; i < N; i++)
            {
                lcm = Lcm(lcm, A[i]);
                if (lcm > M)
                {
                    Console.WriteLine(0);
                    return;
                }
            }

            long ans = (M / lcm + 1) / 2;
            if (Array.Exists(A, x => lcm / x % 2 == 0)) ans = 0;

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }

        static long Lcm(long a, long b)
        {
            long gcd = Gcd(a, b);

            return a / gcd * b;
        }

        /// <summary>
        /// 最大公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


Measured memory_bytes: 31452
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    //println!("token:{}",token);
    token.parse().ok().expect("failed to parse token")
}

pub fn main() {
    let n: u16 = read();
    println!("{}", n * n * n);
}


Measured memory_bytes: 4352
<?php
  
  fscanf(STDIN, "%d", $n);
  $array = str_split($n);
  $hon = [2, 4, 5, 7, 9];
  $pon = [0, 1, 6, 8];
  $bon = [3];
  $cnt = count($array);
  if(in_array($array[$cnt - 1], $hon)){
  echo "hon";
  }elseif(in_array($array[$cnt - 1], $pon)){
  echo "pon";
  }elseif(in_array($array[$cnt - 1], $bon)){
  echo "bon";
  }

Measured memory_bytes: 16032
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

 long long k,t;
 cin>>k>>t;

 long long a[t];

 for(int i=0;i<t;i++) cin>>a[i];

   sort(a,a+t);
   long long m=a[t-1];


   if(k %2 == 0){
       if(m<=k/2)
            cout<<"0"<<endl;
       else {
            long long ani = m-k/2;
            cout<<2*ani-1<<endl;
       }
   }
   else {
      if(m <= k/2+1)
      cout<<"0"<<endl;
      else {
            long long ani = m-k/2+1;
            cout<<2*ani<<endl;
      }
   }


 return 0;
 }


Measured memory_bytes: 3612
import sys
from bisect import *
input = sys.stdin.buffer.readline

INF = 10 ** 13

A, B, Q = map(int, input().split())
shrines = [-INF] + [int(input()) for _ in range(A)] + [INF]
temples = [-INF] + [int(input()) for _ in range(B)] + [INF]
queries = [int(input()) for _ in range(Q)]

for x in queries:
    s_index = bisect(shrines, x)
    t_index = bisect(temples, x)
    rs = shrines[s_index]
    rt = temples[t_index]
    ls = shrines[s_index - 1]
    lt = temples[t_index - 1]
    ans = INF
    ans = min(ans, max(rs, rt) - x)
    ans = min(ans, x - min(ls, lt))
    ans = min(ans, (rt - ls)*2 - max(rt-x, x-ls))    
    ans = min(ans, (rs - lt)*2 - max(rs-x, x-lt))
    print(ans)
    
     


Measured memory_bytes: 93696
import sys
from bisect import bisect
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.buffer.readline()[:-1]

class LCA():
	def __init__(self, adj_given, root_given):
		self.adj = adj = adj_given
		self.root = root_given
		self.n = n = len(adj)
		self.maxlog = 0
		while (1 << self.maxlog) < n:
			self.maxlog += 1
		maxlog = self.maxlog
		self.par = [[-1 for _ in range(n)] for _ in range(maxlog)]
		self.dep = [0 for _ in range(n)]
		self.num_key = [[0] for _ in range(n)]
		self.num_value = [[0] for _ in range(n)]
		self.sum_value = [[0] for _ in range(n)]
		self.first = [10**6 for _ in range(n)]
		self.first[self.root] = 0
		self.visited = 1
		self.cnt = 1
		self.dist = [0 for _ in range(n)]

	def dfs(self, x, pa, de, co, le):
		par = self.par
		dep = self.dep
		root = self.root
		
		par[0][x] = pa
		dep[x] = de

		if x != root and self.visited < n:
			self.num_key[co].append(self.cnt)
			self.num_value[co].append(self.num_value[co][-1] + 1)
			self.sum_value[co].append(self.sum_value[co][-1] + le)
			if self.first[x] == 10**6:
				self.visited += 1
				self.first[x] = self.cnt
			self.cnt += 1
			self.dist[x] = self.dist[pa] + le

		for v, c, l in adj[x]:
			if v != pa:
				self.dfs(v, x, de+1, c, l)

		if x != root and self.visited < n:
			self.num_key[co].append(self.cnt)
			self.num_value[co].append(self.num_value[co][-1] - 1)
			self.sum_value[co].append(self.sum_value[co][-1] - le)
			self.cnt += 1

		return

	def calc(self):
		root = self.root
		par = self.par
		maxlog = self.maxlog
		self.dfs(root, -1, 0, -1, 0)

		for k in range(maxlog-1):
			for v in range(n):
				if par[k][v] < 0:
					continue
				else:
					par[k+1][v] = par[k][par[k][v]]
		return

	def get_lca(self, u, v):
		par = self.par
		dep = self.dep
		maxlog = self.maxlog
		if dep[u] > dep[v]:
			u, v = v, u
		for k in range(maxlog):
			if ((dep[v] - dep[u]) >> k) & 1:
				v = par[k][v]

		if u == v:
			return u
		else:
			for k in range(maxlog-1, -1, -1):
				if par[k][u] != par[k][v]:
					u = par[k][u]
					v = par[k][v]
			return par[0][u]

n, q = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
	a, b, c, d = map(int, input().split())
	adj[a-1].append((b-1, c-1, d))
	adj[b-1].append((a-1, c-1, d))

lca = LCA(adj, 0)
lca.calc()

for _ in range(q):
	x, y, u, v = map(int, input().split())
	x, u, v = x-1, u-1, v-1
	a = lca.get_lca(u, v)
	id_u = max(bisect(lca.num_key[x], lca.first[u])-1, 0)
	id_v = max(bisect(lca.num_key[x], lca.first[v])-1, 0)
	id_a = max(bisect(lca.num_key[x], lca.first[a])-1, 0)

	dist_u = lca.dist[u] + lca.num_value[x][id_u] * y - lca.sum_value[x][id_u]
	dist_v = lca.dist[v] + lca.num_value[x][id_v] * y - lca.sum_value[x][id_v]
	dist_a = lca.dist[a] + lca.num_value[x][id_a] * y - lca.sum_value[x][id_a]
	print(dist_u + dist_v - 2 * dist_a)

Measured memory_bytes: 179016
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  string s;
  cin >> s;
  int count = 0;

  rep (i, 3) {
    if (s[i] == 'R') count++;
  }

  if (s == "RSR") count = 1;

  cout << count << endl;
}



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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define pb push_back
#define INF 1000000000000000000
#define PI 3.14159265358979323846
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 15;
int n, m;
vi s[MAXN];
int p[MAXN];
int ans = 0;
int cnt[MAXN];

void backtrack (int i) {
    if (i >= n) {

        bool ok = true;
        FOR(i, 0, m-1) {
            if (cnt[i]%2 != p[i]) {
                ok = false;
                break;
            }
        }

        if (ok) ans++;

        return;
    }

    for (int b : s[i]) cnt[b]++;
    backtrack(i+1);
    for (int b : s[i]) cnt[b]--;
    backtrack(i+1);
}

int main()
{
    FAST_IO;

    cin >> n >> m;
    FOR (i, 0, m-1) {
        int k; cin >> k;
        FOR(j, 0, k-1) {
            int sw; cin >> sw;
            sw--;
            s[sw].pb(i);
        }
    }
    FOR(i, 0, m-1) {
        cin >> p[i];
    }

    backtrack(0);

    cout << ans;

    return 0;
}


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

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

int main() {
  int64_t h;
  cin >> h;

  int count = 0;
  while(h != 1) {
    h /= 2;
    count += 1;
    // cout << h << endl;
  }

  int64_t ans = 0;
  for(int i = 0; i <= count; i++) {
    ans += pow(2, i);
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e6 + 1;
int dp[670][2001] , S;
int calc(int u , int sum){
	if(sum == S)return 1;
	if(sum > S)return 0;
	int& ret = dp[u][sum];
	if(ret+1)return ret;
	ret = 0;
	for (int i = 3; i <= S - sum; ++i){
		ret += calc(u+1 , sum+i);
		if(ret >= M)ret -= M;
	}
	return ret%M;
}
int main(){	
	cin >> S;
	memset(dp , -1 ,sizeof dp);
	cout << calc(0 , 0) << endl;
	
	
		
}	

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

int main() {
  string N;
  cin >> N;
  int x=0;
  int ans;
  
  for ( int i = 0 ; i < N.length() ; i++){
    x += N[i]-'0';
  }
  ans = stoi(N)%x;
  
  if(ans ==0){
    cout << "Yes"<< endl;
  }else{
    cout << "No"<< endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    int n = s.size();

    rep(i, n) {
        if (s == t.substr(i, n-i) + t.substr(0, i)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
template <typename X>
struct Edge{
  int from;
  int to;
  X cost;

  Edge() = default;

  Edge(int from, int to, X cost = 1) : from(from), to(to), cost(cost) {}
};

template <typename X>
class Compare {
using pi = pair<int, X>;
public:
bool operator()(const pi& a, const pi& b) {
return a.first < b.first;
};
};

template <typename X>
class Graph{
private:
  int n;
  int m;
  vector<vector<Edge<X>>> edge;
  vector<vector<X>> d;
  X inf = 1e+17;
  
public:
  Graph(int n) : n(n) {
    edge.resize(n);
  }

  Graph(int n, int m, vector<int> a, vector<int> b, vector<X> c) : n(n), m(m){
    edge.resize(n);
    rep(i,m) {
      add_edge(a[i], b[i], c[i]);
      add_edge(b[i], a[i], c[i]);
    }
  }

  void add_edge(int from, int to, X cost = 1) {
    edge[from].emplace_back(from, to, cost);
  }

  void dijkstra(int s) {
    d.resize(n);
    d[s].resize(n ,inf);
    d[s][s] = 0;
    using pi = pair<int, X>;
    //auto compare = [](const pi& a, const pi& b) -> bool { return a.second < b.second; };
    priority_queue<pi, vector<pi>, Compare<X>> pq;
    pq.emplace(s, 0);
    while( !pq.empty() ) {
      pi p = pq.top(); pq.pop();
      int v = p.first; // 頂点
      X dist = p.second; // s->vの最短距離
      if(d[s][v] < p.second) continue;
      for(auto w: edge[v]) {
	if(chmin(d[s][w.to], d[s][v] + w.cost)) {
	  pq.emplace(w.to, d[s][w.to]);
	}
      }
    }
  }

  X get_d(int u, int v) { return d[u][v]; }
  X get_inf() { return inf; }
  
};

int main()
{
  int n,m,s,t;cin >> n >> m >> s >> t;
  s--; t--;
  vector<int> u(m), v(m);
  vector<ll> a(m), b(m);
  rep(i,m) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--; v[i]--;
  }

  Graph<ll> gpen(n, m, u, v, a);
  Graph<ll> gpsn(n, m, u, v, b);

  gpen.dijkstra(s);
  gpsn.dijkstra(t);

  vector<ll> res(n);
  rep(i,n) {
    res[i] = gpen.get_d(s, i) + gpsn.get_d(t, i);
  }

  ll M = 1e+15;
  ll tmp = M;
  vector<ll> ans(n);
  for(int i = n - 1;i >= 0;--i) {
    tmp = min(tmp, res[i]);
    ans[i] = M - tmp;
  }

  rep(i,n) cout << ans[i] << "\n";
  
  
  return 0;
}


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

int main(){
    double N ;
    cin >> N ;
    vector<vector<double>> data(N,vector<double>(2,0));
    rep(i,N) cin >> data[i][0] >> data[i][1] ;
    double k = 0.0 ;
    double ans = 0.0 ;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double p = data[i][0] - data[j][0] ;
            double q = data[i][1] - data[j][1] ;
            ans += pow(p * p + q * q, 0.5) * 2 / N ; 
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 512