akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
int arr[101];
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	int iter, var;
	for(int i=0; i<k; ++i){
		cin >> iter;
		for(int j=0; j<iter; ++j){
			cin >> var;
			arr[var]=1;
		}
	}
	int count=0;
	for(int i=1; i<=n; ++i){
		if(arr[i]!=1){
			count++;
		}
	}
	cout << count;
}


Measured memory_bytes: 3600
N, M, = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

money = 0
items = 0
for i in range(N):
    if (items + AB[i][1] < M):
        money += AB[i][0] * AB[i][1]
        items += AB[i][1]
    else:
        j = (M - items)
        money += AB[i][0] * j
        items +=j
        # for j in range(1,AB[i][1]+1):
        #     if (items+j == M):
        #         money += AB[i][0] * j
        #         items +=j

print(money)

Measured memory_bytes: 29032
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int n;
    cin>>n;
    vector<int>list={11,31,41,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1381,1451,1471,1481,1511,1531,1571,1601};
    rep(i,n)cout<<list[i]<<" ";
    
	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int d = a / b;
		int r = a % b;
		double f = (double) a / b;

		System.out.printf(d + " " + r + " " + String.format("%.5f",f));
	}

}

Measured memory_bytes: 26332
import java.util.Scanner;
import java.lang.Math;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        sc.close();

        n = n%k;
        System.out.println(Math.min(n,Math.abs(k-n)));
    }
        
    public static int[] sort(int[] a){
        int x;
        for(int i=0;i<a.length;i++){
            x = a[i];
            for(int j=0;j<a.length;j++){
                if(x == Math.max(x,a[j])){
                    a[i]=a[j];
                    a[j]=x;
                    x=a[i];
                }
            }
        }
        return a;
    }
}

Measured memory_bytes: 23764
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [[0 for _ in range(W)] for _ in range(H)]

col = 1
cnt = 0
i = 0
j = 0
d = 1
while True:
    if cnt<A[col]:
        B[i][j] = col
        cnt += 1
    else:
        col += 1
        cnt = 0
        B[i][j] = col
        cnt += 1
    if d==1 and j<W-1:
        j += 1
    elif d==1 and j==W-1:
        i += 1
        d = -1
    elif d==-1 and j>0:
        j -= 1
    elif d==-1 and j==0:
        i += 1
        d = 1
    if i>=H:break
for i in range(H):
    print(*B[i])

Measured memory_bytes: 74660
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}
string d[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT","SUN","MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"};
int main()
{
    string x;
    cin >> x;int i=0;
    ll ans=0;
    if(x=="SUN")
        return cout << 7 << endl,0;
    for(;i<15;i++){
        if(x==d[i]){
            for(int j=i;j<15;j++){
                if(d[j]=="SUN")
                    return cout << ans << endl,0;
                ans++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    int t=0;
    int x=0;
    int y=0;
    REP(i,n){
        int a,b,c;
        cin>>a>>b>>c;
        if(abs(x-b)+abs(y-c)>a-t){
            cout<<"No"<<endl;
            cerr<<"E1"<<endl;
            return 0;
        }
        else if(((a-t)-abs(x-b)-abs(y-c))%2){
            cout<<"No"<<endl;
            cerr<<"E2"<<endl;
            return 0;
        }
        t=a;
        x=b;
        y=c;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n,m;  cin >> n >> m;
  ll ans = 0;
  if(m > 2*n){
    ans += n;
    m -= 2*n;
    ans += m/4;
  }else{
    ans += m/2;
  }
  cout << ans;
}


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

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

  if (A>=K){
	cout << K;
  }else if (A+B>=K){
    cout << A;
  }else{
    cout << 2*A+B-K;
    
  }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  string s;
  cin>>s;
  vector<int>d(26);
  rep(i,s.size()){
    d[s[i]-'a']++;
  }
  rep(i,26){
    if(d[i]==0){
      cout<<(char)(i+'a')<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 512
line = gets.chomp.split(" ")
n = line[0].to_i
m = line[1].to_i

grid = []
grid.push(("." * (m + 2)).split(""))
for i in 1..n
  tmp = gets.chomp.split("")
  tmp.unshift(".")
  tmp.push(".")
  grid.push(tmp)
end
grid.push(("." * (m + 2)).split(""))

# p grid

flag = true
for i in 1...n
  for j in 1...m
    next if grid[i][j] == '.'
    
    if grid[i-1][j] == "." && grid[i+1][j] == "." &&
      grid[i][j-1] == "." && grid[i][j+1] == "."
      flag = false
      break
    end
  end
  if !flag
    break
  end
end

if flag
  puts "Yes"
else
  puts "No"
end

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

int main() {
  string S; cin >> S;
  bool easy_to_read = true;
  for (int i = 0; i < S.size(); i++) {
    if ((i % 2 == 0 && S.at(i) == 'L') ||
        (i % 2 == 1 && S.at(i) == 'R')) {
      easy_to_read = false;
    }
  }
  if (easy_to_read) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
for i in range(n-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        exit()
for i in range(n-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Measured memory_bytes: 9232
n = int(input())
R = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(n)]
R.sort()
B.sort()
pair = []

for bx, by in B:
    tmp = [r for r in R if r[0] < bx]
    tmp.sort(key=lambda x: x[1])
    for rx, ry in tmp[::-1]:
        if ry < by:
            pair.append([[rx, ry], [bx, by]])
            R.pop(R.index([rx, ry]))
            break

print(len(pair))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc136_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;
  int N = S.size();
  vector<int> c(N, 0);

  int bnd = 0;
  int start = 0;
  int even = 0;
  int odd = 0;
  rep(i, N - 1) {
    i % 2 == 0 ? even++ : odd++;
    if (S[i] == 'R' && S[i + 1] == 'L') {
      // 境界
      bnd = i;
    } else if (S[i] == 'L' && S[i + 1] == 'R') {
      c[bnd] = bnd % 2 == 0 ? even : odd;      // Rに R..RL..L Rから偶数
      c[bnd + 1] = bnd % 2 == 0 ? odd : even;  // Lに Lから偶数
      start = i;
      even = 0;
      odd = 0;
    }
  }

  (N - 1) % 2 == 0 ? even++ : odd++;
  c[bnd] = bnd % 2 == 0 ? even : odd;
  c[bnd + 1] = bnd % 2 == 0 ? odd : even;

  rep(i, S.size()) { cout << c[i] << ' '; }
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string n; cin >> n;
  int sum = 0;
  REP(i,n.size()){
    sum += int(n[i]-48);
  }
  if(sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    
    int P, Q, R;
    vector<int> a(3);
    cin >> P >> Q >> R;

    a[0] = P;
    a[1] = Q;
    a[2] = R;
    sort(a.begin(), a.end());
    cout << a[0] + a[1] << '\n';
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int num = 0;
  for (int i = A; i <= B; i++){
    int n5 = i/10000;
    int n4 = (i-n5 * 10000)/1000;
    int n3 = (i-n5 * 10000 - n4 * 1000)/100;
    int n2 = (i-n5 * 10000 - n4 * 1000 - n3 * 100)/10;
    int n1 = (i-n5 * 10000 - n4 * 1000 - n3 * 100 - n2 * 10);
    
    if (n5 == n1 && n4 == n2) num++;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
def num_steps(steps, cache={}):
    if steps in out or steps < 0 :
        return 0
    elif steps == 0:
        return 1

    if steps in cache:
        return cache[steps]
    else:
        one = num_steps(steps-1, cache)
        two = num_steps(steps-2, cache)
        ans = one + two
        cache[steps] = ans

        return ans%mod

n, m = map(int, input().split())
out = set(int(input()) for _ in range(m))
mod = 1000000007

print(num_steps(n))



Measured memory_bytes: 116968
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, m;
    cin >> n >> m;
    vint s[m];
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int sk;
            cin >> sk;
            --sk;
            s[i].push_back(sk);
        }
    }
    vint p(m);
    rep(i, m) cin >> p[i];

    int ans = 0;
    rep(i, 1<<n) {
        int num = i;
        int on = 0;
        rep(j, m) {
            int sw = 0;
            for (int x : s[j]) if (i>>x & 1) sw++;
            if (sw%2 == p[j]) on++;
        }
        if (on == m) ans++;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int white = H * W;
	white -= H * w + (h * (W - w));
	cout << white << endl;
	return 0;
}

Measured memory_bytes: 3640
import sys
H,W =list(map(int, input().split()))
S = [list(input()) for i in range(H)]
sys.setrecursionlimit(1000000)

black_visited_flag = [[False] * W for _ in range(H)] 

other_color = {".": "#", "#":'.'}

def dfs(i,j, color):
    num = 0
    black_num = 0
    #import IPython;IPython.embed()
    if i != 0:
        if S[i-1][j] == other_color[color] and not visit_flag[i-1][j]:
            visit_flag[i-1][j] = True
            _num, _black_num = dfs(i-1, j, other_color[color])
            num += _num
            black_num += _black_num
            if other_color[color] == "#":
                black_num += 1
                black_visited_flag[i-1][j] = True
            else:
                num += 1
    if i != H-1:
        if S[i+1][j] == other_color[color] and not visit_flag[i+1][j]:
            visit_flag[i+1][j] = True
            _num, _black_num = dfs(i+1, j, other_color[color])
            num += _num
            black_num += _black_num
            if other_color[color] == "#":
                black_num += 1
                black_visited_flag[i+1][j] = True
            else:
                num += 1
    if j != 0:
        if S[i][j-1] == other_color[color] and not visit_flag[i][j-1]:
            visit_flag[i][j-1] = True
            _num, _black_num = dfs(i, j -1, other_color[color])
            num += _num
            black_num += _black_num
            if other_color[color] == "#":
                black_num += 1
                black_visited_flag[i][j-1] = True
            else:
                num += 1
    if j != W-1:
        if S[i][j+1] == other_color[color] and not visit_flag[i][j+1]:
            visit_flag[i][j+1] = True
            _num, _black_num = dfs(i, j+1, other_color[color])
            num += _num
            black_num += _black_num
            if other_color[color] == "#":
                black_num += 1
                black_visited_flag[i][j+1] = True
            else:
                num += 1
    return num, black_num



ans = 0
visit_flag = [[False] * W for _ in range(H)] 
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if black_visited_flag[i][j] or S[i][j] == ".":
            continue
        num, black_num = dfs(i,j, "#")
        ans += (num * black_num)

print(ans)
    

Measured memory_bytes: 186352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, d, sum, cnt=0;
    scanf("%d%d", &n, &d);
    int arr[n][d];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<d; j++)
            scanf("%d", &arr[i][j]);
    }
    for(int i=0; i<n-1; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            sum=0;
            for(int k=0; k<d; k++)
                sum=sum+(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
            //cout << sum << endl;
            for(int l=0; l<128; l++)
            {
                if(sum==l*l)
                {
                    cnt++;
                    break;
                }
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;
vector<vector<int>>path(100050);

int rec(vector<int> &dp, int v) {
	if (dp[v] != -1)return dp[v];
	int res = 0;
	for (int p : path[v]) {
		res = max(res, rec(dp, p) + 1);
	}
	return dp[v] = res;
}


int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		path[x].push_back(y);
	}
	vector<int>dp(n, -1);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, rec(dp, i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

const int INF = 1e+9;


int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for( int i = 0; i < M; ++i ){
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].push_back(v);
    }
    int S, T;
    cin >> S >> T;
    --S, --T;


    vector<vector<int>> d(N, vector<int>(3, INF));  // Sからの距離を3で割った数
    d[S][0] = 0;
    queue<pair<int,int>> q;
    q.push({S,0});
    while( !q.empty() ){
        auto tmp = q.front(); q.pop();
        int pos = tmp.first;
        int num = tmp.second;
        for( auto v: G[pos] ){
            int next = (num+1)%3;
            if( d[v][next] == INF ){
                d[v][next] = d[pos][num]+1;
                q.push({v,next});
            }
        }
    }
    if( d[T][0] == INF ) cout << -1 << endl;
    else cout << d[T][0]/3 << endl;


    return 0;
}

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

int n,a[100005],s[100005] = {0},w[100005];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
		s[i]  = a[i];
	}
	for(int i = 1;i < n;i++)
	{
		if(i % 2 == 0)
			s[i + 1] = s[i] + s[i + 1];
		else
			s[i + 1] = s[i] - s[i + 1];  
	}
	w[1] = s[n - 1] + a[n];
	for(int i = 2;i <= n;i++)
	{
		w[i] = (a[i - 1] - w[i - 1] / 2) * 2; 
	}
	for(int i = 1;i <= n;i++)
		cout << w[i] << " "; 
}

Measured memory_bytes: 2432
# coding: utf-8
# Your code here!
def multiple_3(num):
    if num % 3 == 0:
        print(" {}".format(num), end="")
    else:
        included_3(num)

def included_3(num):
    if "3" in str(num):
        print(" {}".format(num), end="")
        
n = int(input())
for num in range(3, n+1):
    multiple_3(num)
print()



Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int ss=3e5+5;



 
int main()
{

    int t=1;
    // cin>>t;
    while(t--)
    {
        int x;
        cin>>x;
        if(x<=599 and x>=400)
        {
            cout<<"8";
        }
        if(x<=799 and x>=600)
        {
            cout<<"7";
        }
        if(x<=999 and x>=800)
        {
            cout<<"6";
        }
        if(x<=1199 and x>=1000)
        {
            cout<<"5";
        }
        if(x<=1399 and x>=1200)
        {
            cout<<"4";
        }
        if(x<=1599 and x>=1400)
        {
            cout<<"3";
        }
        if(x<=1799 and x>=1600)
        {
            cout<<"2";
        }
        if(x<=1999 and x>=1800)
        {
            cout<<"1";
        }

    }

    return 0;
}

Measured memory_bytes: 3632
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> hs(n);
    for (auto& h : hs)
    {
        cin >> h;
    }

    vector<int64_t> dp(n, 0);
    dp[0] = 0;
    dp[1] = abs(hs[1] - hs[0]);

    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 2] + abs(hs[i - 2] - hs[i]), dp[i - 1] + abs(hs[i - 1] - hs[i]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
/*input
20 40 6

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
// #define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 250001

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(ll a, ll b) {a += b; if (a < 0) a += mod; return a;}
inline int sub(ll a, ll b) {a -= b; if (a < 0) a += mod; return a;}
inline int mul(ll a, ll b) {return (a * 1ll * b) % mod;}
inline int pwr(ll x, ll y) {
  int ans = 1 % mod;
  while (y) {
    if (y & 1) ans = mul(ans, x);
    x = mul(x, x);
    y >>= 1;
  }
  return ans;
}
inline int inv(int a) {return pwr(a, mod - 2);}


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

  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(2 * a - 1, 2 * b - 1)) << endl;

  return 0;
}

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

int n;

int main() {
    cin >> n;
    vector<int> a(n);
    map<int, lint> count;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]]++;
    }
    lint base = 0;
    for (auto e : count) {
        lint temp = e.second;
        base += temp * (temp - 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        cout << base - count[a[i]] + 1 << endl;
    }
}

Measured memory_bytes: 11520
import sys
N = int(input())
INF = 10**9+7
ans = 0

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


for i in range(N//3):
  X = N-3*(i+1) # X個のボールにi個の仕切りを入れる
  if i == 0:
    ans += 1
  else:
    # X+i_C_i
    ans += cmb(X+i,i,INF)
print(ans%INF)

Measured memory_bytes: 65336
#include<stdio.h>

int main(void) {

	int n;
	char s[51];
	int ans = 0;
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') {
			if (s[i + 1] == 'B') {
				if (s[i + 2] == 'C') {
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int res = 0x7f7f7f7f;
	res = min(res, abs(b-a) + abs(c-a));
	res = min(res, abs(c-b) + abs(a-b));
	res = min(res, abs(a-c) + abs(b-c));
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int n , k;  cin >> n >> k;
    string s;   cin >> s;

    if(s[k-1] >= 'A' and s[k-1] <= 'Z')
        s[k-1] += 32;
        cout << s;
   

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M,X;
  cin>>N>>M>>X;
  VI C(N);
  VVI A(N,VI(M));
  rep(i,N){
    cin>>C[i];
    rep(j,M) cin>>A[i][j];
  }
  ll ans=1001001001001001001;
  rep(i,(1ll<<N)){
    VI B(N);
    ll tmp=i;
    rep(j,N){
      B[j]=tmp%2;
      tmp/=2;
    }
    VL R(M);
    rep(j,N){
      if(B[j]) rep(k,M) R[k]+=A[j][k];
    }
    int F=1;
    rep(j,M) F*=(R[j]>=X);
    ll sum=0;
    rep(j,N) if(B[j]) sum+=C[j];
    if(F) ans=min(ans,sum);
  }
  if(ans==1001001001001001001){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

vector<int> KMP(const vector<ll> &target, const vector<ll> &pattern) {
    vector<int> res;
    int len_t = (int)target.size(), len_p = (int)pattern.size();

    // create table
    std::vector<int> table(len_p);
    table.at(0) = 0;
    int j = 0;
    for (int i=1; i<len_p; i++) {
        if (pattern.at(i) == pattern.at(j)) {
            table.at(i) = j;
            j++;
        } else {
            table.at(i) = j;
            j = 0;
        }
    }

    // search pattern in target
    int cur_t = 0, cur_p = 0;
    while (cur_t < len_t && cur_p < len_p) {
        if (target.at(cur_t) == pattern.at(cur_p)) {
            cur_p++; cur_t++;
        } else if (cur_p == 0) {
            cur_t++;
        } else {
            cur_p = table.at(cur_p);
        }
    }
    if (cur_p == len_p) {
        int ind = cur_t - cur_p;
        bool syuuki = true;
        int cnt0 = 1;
        for (int i=1; i<len_p; i++) {
            if (table.at(i) == 0) cnt0++;
            else if (table.at(i) != table.at(i-1) + 1) {
                syuuki = false;
                break;
            }
        }
        res.push_back(ind);
        cnt0--;
        if (len_p%cnt0 != 0) syuuki = false;
        if (syuuki) {
            ind += cnt0;
            while (ind < len_p) {
                res.push_back(ind);
                ind += cnt0;
            }
        }
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    vector<ll> b(n);
    for (int i=0; i<n; i++) {
        cin >> b.at(i);
    }
    vector<ll> xora(n), xorb(n);
    for (int i=0; i<n; i++) {
        if (i == 0) {
            xora.at(i) = (a.at(0) ^ a.at(n-1));
            xorb.at(i) = (b.at(0) ^ b.at(n-1));
        } else {
            xora.at(i) = (a.at(i) ^ a.at(i-1));
            xorb.at(i) = (b.at(i) ^ b.at(i-1));
        }
    }
    for (int i=0; i<n; i++) {
        xora.push_back(xora.at(i));
    }
    vector<int> inds = KMP(xora, xorb);
    for (int ind : inds) {
        cout << ind << " " << (a.at(ind) ^ b.at(0)) << "\n";
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 13924
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>
using namespace std;
string S;
size_t cur = 0;

int digit() {
    assert(isdigit(S[cur]));
    int n = S[cur++] - '0';
    return n;
}

int number() {
    int n = digit();
    while(cur < S.size() && isdigit(S[cur])) {
        n = n*10 + digit();
    }
    return n;
}

int expression();
int factor() {       //Factor := '(' Expression ')' | Number
    if(S[cur] != '(') return number();
    cur++;
    int n = expression();
    assert(S[cur] == ')');
    cur++;
    return n;
}

int term() {       //Term := Factor { ('*'|'/') Factor }
    int a = factor();
    while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
        char op = S[cur++];
        int b = factor();
        if(op =='*') { a *= b; } else { a /= b; }
    }
    return a;
}

int expression() {       //Expression := Term { ('+'|'-') Term}
    int a = term();
    while(cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
        char op = S[cur++];
        int b = term();
        if(op == '+') { a += b; } else { a -= b;}
    }
    return a;
}

int main() {
    int N;
    cin >> N;
    for(int i=0; i<N; i++) {
        cur = 0;
        cin >> S;
        S.resize(S.size() - 1);
        cout << expression() << endl;
    }
}


Measured memory_bytes: 3144
def main():
    n=int(input())
    m=int((2*n)**0.5)
    if m*(m+1)==n*2:
        print("Yes")
        m+=1
        print(m)
    else:
        print("No")
        exit()
    
    ans=[[m-1] for i in range(m)]
    c=1
    for i in range(m):
        for j in range(i+1,m):
            ans[i].append(c)
            ans[j].append(c)
            c+=1
    for i in ans:
        print(" ".join(map(str,i)))


if __name__ == '__main__':
    main()








Measured memory_bytes: 43740
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <string>
using namespace std;
#define lli long long int
#define MAX 100000000
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int X = B / A;
    if (C >= X)
    {
        cout << X << endl;
    }
    else
    {
        cout << C << endl;
    }
    return 0;
}

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

int main()
{
  int n;
  for(int casenum=1;cin>>n,n;casenum++)
    {
      int data[n][n];
      int cnt=1;
      int x=0,y=0;
      int dx=1,dy=-1;
      data[x][y]=cnt++;
      while(true)
	{
	  //	  	      cout<<"pos "<<x<<":"<<y<<endl;
	  if(x==n-1&&y==n-1)
	    break;
	  if(x==0||x==n-1)
	    {
	      if(y<n-1)
		y++;
	      else
		x++;
	    }
	  else if(y==0||y==n-1)
	    {
	      if(x<n-1)
		x++;
	      else
		y++;
	    }
	  //  cout<<"pos "<<x<<":"<<y<<endl;
	  data[x][y]=cnt++;
	  if(x==n-1&&y==n-1)
	    break;
	  while(x+dx>=0&&y+dy>=0&&x+dx<n&&y+dy<n)
	    {
	      x+=dx;
	      y+=dy;
	      //  cout<<"pos "<<x<<":"<<y<<endl;
	      data[x][y]=cnt++;
	      /*
	      if(x==n-1&&y==n-1)
		break;
	      */
	    }
	  swap(dx,dy);
	}


      cout<<"Case "<<casenum<<":"<<endl;
      for(int i=0;i<n;i++,cout<<endl)
	for(int j=0;j<n;j++)
	  {
	    printf("%3d",data[i][j]);
	  }
    }
}

Measured memory_bytes: 1204
S = gets.to_i

rt = Math.sqrt(S).floor

x1, y1 = 0, 0
rt**2 < S ? x2 = (rt+1) : x2 = rt
y2 = 1
x3 = x2**2 - S
y3 = x2

puts [x1,y1,x2.to_i,y2.to_i,x3.to_i,y3.to_i].join(" ")

Measured memory_bytes: 3836
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a,b;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>a>>b;
	if(a==2||b==2)
	{
	    cout<<"No";
	    return 0;
	}
	else if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
	{
	    if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)
	    {
	        cout<<"Yes";
	        return 0;
	    }
	    else
	    {
	        cout<<"No";
	        return 0;
	    }
	}
	else
	{
	    if(b==4||b==6||b==9||b==11)
	    cout<<"Yes";
	    else
	    cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x, y;
  scanf("%d%d", &x, &y);

  if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
    if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else if(x==4 || x==6 || x==9 || x==11){
    if(y==4 || y==6 || y==9 || y==11){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else if(x==2){
    if(y==2){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }
  
  return 0;
}

/*
1,3,5,7,8,10,12
4,6,9,11
2
*/


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g;
	for(g=1;g<=5;g++){
		scanf("%d",&a);
		if(a<=40){
			a=40;
		}
		s=a+s;
	}
	printf("%d\n",s/5);
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair

pair<int, int> stone[100000];

int main() {
	while (true) {
		int n, c, pos = 0;
		cin >> n;
		if (n == 0) break;

		REP(i, n) { stone[i].first = stone[i].second = 0; }

		scanf("%d", &c);
		stone[++pos] = MP(c, 1);

		FOR(i, 1, n) {
			scanf("%d", &c);

			if ((i + 1) % 2 == 1) {
				if (stone[pos].first == c) stone[pos].second++;
				else stone[++pos] = MP(c, 1);
			} else {
				if (stone[pos].first == c)
					stone[pos].second++;
				else {
					if (pos == 0) {
						stone[pos].first = c;
						stone[pos].second++;
					} else {
						stone[pos - 1].second += ++stone[pos].second;
						stone[pos].first = stone[pos].second = 0;
						pos--;
					}
				}
			}
		}

		int ans = 0;
		REP(i, pos + 1) if (stone[i].first == 0) ans += stone[i].second;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2024
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
  auto s = readln.chomp.split.map!(to!int).array;

  if (s[0] * s[1] < s[2]) writeln(s[0] * s[1]);
  else s[2].writeln;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,k,s,numA,numB,num=0;
  scanf("%d",&numA);

  int retuA[numA];

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

  scanf("%d",&numB);

  int retuB[numB];

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

  for(i = 0; i < numB; i++){
    for(j = 0; j < numA; j++){
      if(retuA[j]==retuB[i]){
	num++;
	break;
      }
    }
  }
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        String ans = "";
        for (int i=0; i<n; i++){
            ans = ans + S.charAt(i)+T.charAt(i);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 39252
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_V 10000

struct edge { int to, cost; };

int V;
vector<edge> G[MAX_V];
int d[MAX_V];//頂点sからの最短距離

//始点sから各頂点への最短距離を求める
void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
    
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


signed main(){
    cin >> V;
    REP(i,V){
        int u,k;
        cin >> u >> k;
        int v,c;
        REP(i,k){
            cin >> v >> c;
            G[u].push_back((edge){v, c});
        }
    }
    dijkstra(0);
    REP(i,V){
        cout << i << " " << d[i] << endl;
    }
}


Measured memory_bytes: 3436
# ABC79 D - Wall
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

C = floyd_warshall(C)  

cost = 0
for i in range(H):
    for a in A[i]:
        if a != -1:
            cost += C[a][1]

print(int(cost))

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (auto& e : d) cin >> e;
  int r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) r += d[i] * d[j];
  }
  cout << r << endl;
}


Measured memory_bytes: 256
n=int(input())
if n==1:
    print(1)
else:
    ans_1=1
    ans_2=2
    for _ in range(n-1):
        ans=ans_1+ans_2
        ans_2=ans_1
        ans_1=ans
        # print(f"ans_1:{ans_1}")
        # print(f"ans_2:{ans_2}")
    print(ans)

Measured memory_bytes: 2940
H,N =[int(i) for i in input().split()]
AAA = []
BBB = []
for i in range(N):
    buff = [int(i) for i in input().split()]
    AAA.append(buff[0])
    BBB.append(buff[1])

#dp[i]は体力をi減らすまでに必要な魔力の最小値
dp = [10000000000 for i in range(H+5)]
dp[0] = 0
for i in range(H+5):
    for j in range(N):
        A = AAA[j]
        B = BBB[j]
        if i-A>=0:
            dp[i]=min(dp[i],dp[i-A]+B)
        else:
            dp[i]=min(dp[i],B)

#print(dp)
print(dp[H])




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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,x,m;
    cin >> n >> x >> m;
    vector<vector<int>> dub(m, vector<int>(40, -1));
    vector<vector<ll>> dubsum(m, vector<ll>(40, 0));
    rep(i, m){
        dub[i][0] = i*i%m;
    }
    rep(i, 39){
        rep(j,m){
            dub[j][i + 1] = dub[dub[j][i]][i];
        }
    }
    rep(i,m){
        dubsum[i][0] = i;
    }
    rep(i,39){
        rep(j,m){
            dubsum[j][i+1] = dubsum[j][i] + dubsum[dub[j][i]][i];
        }
    }
    ll ans = 0;
    int bit = 0;
    int now = x;
    while(n){
        if(n & 1){
            ans += dubsum[now][bit];
            now = dub[now][bit];
        }
        ++bit;
        n >>= 1;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int MAXN = 2E5;
int a[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a, a + n);
    int med = a[n / 2];
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += abs(a[i] - med);
    }
    cout << ans << endl;
    return 0;
}


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

const int N = 200;

int score[N] = { 0 };
int a[N][3] = { { 0 } };

int main(){
	int n, m;
	cin >> n;
	for(int i = 0;i < n;++i){
		for(int j = 0;j < 3;++j){
			cin >> a[i][j];
		}
	}
	for(int k = 0;k < 3;++k){
		for(int i = 0;i < n;++i){
			m = 0;
			for(int j = 0;j < n;++j){
				if(i != j) {
					m += (a[i][k] == a[j][k]);
				}
			}
			if(!m) score[i] += a[i][k];
		}
	}
	for(int i = 0;i < n;++i){
		cout << score[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	lint n=read<lint>();
	lint m=read<lint>();

	for(int i=1;i<=m;i++)
	{
		n-=read<lint>();
		if(n<0) break;
	}

	if(n<0) puts("-1");
	else printf("%lld\n",n);

	return 0;

}


Measured memory_bytes: 3656
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
struct UnionFind {
  vi d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  int size(int x){
    return -d[root(x)];
  }
};
int main(){
  int n,m;
  cin >> n >> m;
  vector<pii> s(m);
  rep(i, m){
    int a,b; cin >> a >> b;
    s[i] = make_pair(a - 1, b - 1);
  }
  reverse(all(s));
  UnionFind tree(n);
  vector<ll> ans(m);
  ans[m - 1] = (ll)n * (n - 1) / 2;
  rep(i, m - 1){
    int x = s[i].first, y = s[i].second;
    if(tree.same(x, y)){
      ans[m - i - 2] = ans[m - i - 1];
    }else ans[m - i - 2] = ans[m - i - 1] - tree.size(x) * tree.size(y);
    tree.unite(x, y);
  }
  rep(i, m) cout << ans[i] << endl;
}

Measured memory_bytes: 5040
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int 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;
}
 
void solve()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

struct edge{
    int from,to;
    ll cost;
};
signed main(){
    int n,m; cin >> n >> m;
    vector<edge> G;
    rep(i,m){
        int a,b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        edge e={a,b,-c};
        G.pb(e);
    }
    ll dist[n];
    rep(i,n) dist[i]=1e18;
    dist[0]=0;
    ll res=0;
    bool ng=0;
    rep(i,n){
        rep(j,G.size()){
            edge e=G[j];
            if(dist[e.to]>dist[e.from]+e.cost){
                dist[e.to]=dist[e.from]+e.cost;
                if(i==n-1){
                    if(ng&&dist[n-1]!=res){
                        cout << "inf" << endl;
                        return 0;
                    }
                    if(ng) break;
                    ng=1;
                    res=dist[n-1];
                    i--;
                }
            }
        }
    }
    cout << -dist[n-1] << endl;
}



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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }

    sort(a.begin(),a.end());//小さい順にソート


    int m = a.at(0);
    int M = a.at(a.size()-1);

    int ans = 0;
        
    vector<int> count(M+1,0);//0からMの個数を格納
    for(int i=0; i<N; i++){
        int num=a.at(i);
        count.at(num) ++;
    }

    for(int i=0; i<=M; i++){
        int counti = 0;
        for(int j=i-1; j<=i+1; j++){
            if(0<=j && j<=M){
                counti += count.at(j);
            }
        }
        if(counti > ans){
            ans = counti;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc178/tasks/abc178_a
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin>>x;
    if (1==x) {
        cout<<"0\n";
    } else {
        cout<<"1\n";
    }
    return 0;
}

Measured memory_bytes: 3628