akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		string []s = Console.ReadLine().Split(' ');
		int n = int.Parse(s[0]);
		int l = int.Parse(s[1]);
		int sum = 0;
		List<Tuple<int,int>>list = new List<Tuple<int,int>>();
        for(int i = 0; i < n; i++)
		{
			sum += l + i;
			list.Add(new Tuple<int, int>(Math.Abs(l + i), l + i));
		}
		list.Sort((a,b)=>(a.Item1-b.Item1));
		Console.WriteLine(sum - list[0].Item2);
    }
	
}






Measured memory_bytes: 13268
local long_str = io.read("*l")
local tmps = {"dream", "dreamer", "erase", "eraser"}

long_str = long_str:reverse()
for i = 1, #tmps do
    tmps[i] = string.reverse(tmps[i])
end

local index = 1
local is_none = false
while index < long_str:len() do
    local old_index = index
    for i = 1, #tmps do
        local tmp = tmps[i]
        if long_str:sub(index, index + string.len(tmp) - 1) == tmp then
            index = index + string.len(tmp)
            break
        end
    end
    if old_index == index then
        is_none = true
        break
    end
end
print(is_none and "NO" or "YES")

Measured memory_bytes: 640
from math import sqrt

def cal_dummy(N):
    output = 0
    for m in range(1,N):
        if N // m == N % m:
            output += m
    return output

def cal(N):
    #N == m*q+r(0 <= r < m)としてq==rのとき
    #N == (m+1)*r(0 <= r <= m-1)
    if N == 1:
        return 0
    else:
        output = 0
        for r in range(1,int(sqrt(N))+1):
            if N % r == 0:
                m = (N // r) - 1
                if (N//m) == r:
                    output += m
        return output

def main():
    N = int(input())

    print(cal(N))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d, n;
    cin >> d >> n;
    cout << (int)pow(100, d) * (n != 100 ? n : n + 1) << '\n';
}


Measured memory_bytes: 384
import re

data = input().split()
stack = []

for elem in data:
    if re.match('\d+', elem):
        stack.append(int(elem))
    else:
        a = stack.pop()
        b = stack.pop()
        if elem == "+":
            stack.append(b+a)
        elif elem == "-":
            stack.append(b-a)
        elif elem == "*":
            stack.append(b*a)

print(stack[0])

Measured memory_bytes: 7808
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
  int n;
  string s;
  n = 0;
  std::cin >> s;
  for (int i=0; i<4; ++i){
    if(s[i]=='+'){++n;}
    else if(s[i]=='-'){--n;}
  }
  std::cout << n << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }




void solve() {
    int n;
    cin >> n;
    vector<int> p(n), q(n), p2(n), q2(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    
    p2 = p; q2 = q;
    sort(all(p2)); sort(all(q2));
    
    vector<vector<int> > pp, qq;
    do {
        pp.eb(p2);
    } while (next_permutation(all(p2)));
    do {
        qq.eb(q2);
    } while (next_permutation(all(q2)));
    
    int a = 0, b = 0;
    rep(i, sz(pp)) {
        if (pp[i] == p) a = i + 1;
    }
    rep(i, sz(qq)) {
        if (qq[i] == q) b = i + 1;
    }
    
    cout << abs(a - b) << endl;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}




Measured memory_bytes: 6324
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll mod_pow(ll x, ll n, ll m) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return res;
}

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  sort(a);

  if (n % 2 == 1) {
    if (a[0] != 0) {
      outl(0);
      return;
    }
    for (int i = 2, c = 2; i < n; i += 2, c += 2) {
      if (a[i-1] != c || a[i] != c) {
        outl(0);
        return;
      }
    }
  } else {
    for (int i = 1, c = 1; i < n; i += 2, c += 2) {
      if (a[i-1] != c || a[i] != c) {
        outl(0);
        return;
      }
    }
  }

  if (n % 2 == 0) outl(mod_pow(2, n/2, MOD));
  else outl(mod_pow(2, (n-1)/2, MOD));
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

ll fac[1000007],finv[1000007],inv[1000007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<1000007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll x,y;
    cin>>x>>y;
    if(x>2*y || y>2*x || (x+y)%3){
    	cout<<0<<endl;
    }
    else{
    	ll num=(x+y)/3;
    	cout<< com(num,x-num)<<endl;
    }
    return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int f[105][105],n,m;
char s[105][105];
int main()
{int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
	}
	memset(f,127/2,sizeof(f));
	f[1][1]=(s[1][1]=='#');
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (i+1<=n)
			f[i+1][j]=min(f[i+1][j],f[i][j]+(s[i][j]!=s[i+1][j]));
			if (j+1<=m)
			f[i][j+1]=min(f[i][j+1],f[i][j]+(s[i][j]!=s[i][j+1]));
		}
	}
	printf("%d",(f[n][m]+1)/2);
}

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

int main(){
  char s[256];
  int i,j;
  int r;
  int x,y;
  int min;

  scanf("%s",s);

  r = strlen(s);

  int a[r-2];

  for(i=0; i<=r-3; i++){
    y = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
    a[i] = abs(y - 753);
  }

  for(i=0; i<=r-3; i++){
    if(a[i]<a[0]){
      a[0] = a[i];
    }
  }

  printf("%d\n",a[0]);

  return 0;
}


Measured memory_bytes: 128
s = [input(),input(),input()]
t = 0
dic = {'a':0,'b':1,'c':2}
lst = ['A', 'B', 'C']
l = len(s[0])
while l != 0:
  p = s[t][0]
  s[t] = s[t][1:]
  t = dic[p]
  l = len(s[t])

print(lst[t])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int x, y;
    cin >> x;
    vector<int> v(x + 1, 0);
    for (int i = 1; i < x; i++)
    {
        cin >> y;
        v[y]++;
    }
    for (int i = 1; i <= x; i++)
    {
        cout << v[i] << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}

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

int main(){
	int N, v;
	float vmix=0;
	float ans;
	std::vector<float> V;
	std::cin >> N;
	for(int i=0; i<N; i++){
		std::cin >> v;
		V.push_back(v);
	}
	std::sort(V.begin(), V.end());
	for(int i=0; i<N-1; i++){
		vmix = (V[0]+V[1])/2;
		V.erase(V.begin(), V.begin()+2);
		V.push_back(vmix);
		std::sort(V.begin(), V.end());
	}
	ans = V[0];
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	bool ans = false;

	FOR(i,0,100){
		FOR(j,0,100){
			if(4*i + 7*j == n)ans=true;
		}
	}

	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 2);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        a[l]++;
        a[r + 1]--;
    }
    int ans = 0;
    int now = 0;
    for (int i = 1; i <= n; i++) {
        now += a[i];
        if (now == m) ans++;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    while (t--) solve();
}

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

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

    bool flag = false;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j<= n-i; j++){
            if (10000*i + 5000*j + 1000*(n-i-j) == y) {
                cout << i << " " << j << " " << n-i-j << endl;
                flag = true;
                break;
            }
            if (flag) break;
        }
        if (flag) break;
    }
    if (!flag) cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

				if(str.equals("0")) break;

				int sum = 0;
				for(int i = 0; i < str.length(); i++) {
					sum += Integer.parseInt(str.substring(i, i + 1));
				}
				System.out.println(sum);
			}
		}
	}
}



Measured memory_bytes: 27112
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def decide_position(num_list:list, n):

    if n == 2:
        if num_list[0] < num_list[1]:
            return 1
        else:
            return 2
    else:
        first_num = num_list[0]
        sorted_num_list = sorted(num_list)
        rank_in_p = sorted_num_list.index(first_num)
        n_kaizyou = 1
        for i in range(n-1, 0, -1):
            n_kaizyou *= i

        position = rank_in_p * n_kaizyou
        num_list.remove(first_num)
        position += decide_position(num_list, n-1)

        return position



def resolve():
    n = int(input())
    p_list = list(map(int, input().split()))
    q_list = list(map(int, input().split()))

    p_rank = decide_position(p_list, n)
    q_rank = decide_position(q_list, n)

    ans_rank = abs(p_rank - q_rank)

    print(ans_rank)






if __name__ == "__main__":
    resolve()



Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int H, W;
char map[105][105];

void dfs(int x, int y, char c)
{
	if(x < 0 || x >= W || y < 0 | y >= H) return;
	if(map[x][y] != c) return;
	
	map[x][y] = '.';
	
	dfs(x-1, y, c);
	dfs(x+1, y, c);
	dfs(x, y-1, c);
	dfs(x, y+1, c);
}

int main(void)
{
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				cin >> map[x][y];
			}
		}
		
		int ans = 0;
		for(int x = 0; x < W; x++){
			for(int y = 0; y < H; y++){
				if(map[x][y] != '.'){
					dfs(x, y, map[x][y]);
					ans++;
				}
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

int main() {
    //
    string str;
    cin >> str;

    long long kekka = 0;
    for (int i = 0; i < str.size(); i++) {
        kekka += str.at(i) - '0';
    }

    if (kekka % 9 == 0) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
    long long n,k;
    
    cin >> n >> k;

    int mod;
    long long ans;

    ans = n % k;
    
    ans = min(ans, k-ans);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,greater<ll>());
	ll ans=a[0],rem=n-2,i=1;
	while(rem!=0){
		if(rem>=2){
			ans+= 2*a[i];
			i++;
			rem-=2;
		}
		else {
			ans+=a[i];
			i++;
			rem--;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


bool is_prime(ll n) {
    if (n==1) return false; 
    repr(i,2,int(sqrt(n)+1)) {
        if (n%i==0) return false;
    }
    return true;
}


int main() {
    ios_base::sync_with_stdio(false);

    int x;
    cin >> x;
    while (1) {
        if (is_prime(x)) {
            cout << x << endl;
            break;
        }
        ++x;
    }

    return 0;   
}

Measured memory_bytes: 3700
var lines = [];

var readline = require('readline')
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (x) => {
    lines.push(x);
});

rl.on('close', () => {
    var N = lines[0];
    var ans = 0
    
    if (Number(N) <= 999) { ans = 999 }
    if (Number(N) <= 888) { ans = 888 }
    if (Number(N) <= 777) { ans = 777 }
    if (Number(N) <= 666) { ans = 666 }
    if (Number(N) <= 555) { ans = 555 }
    if (Number(N) <= 444) { ans = 444 }
    if (Number(N) <= 333) { ans = 333 }
    if (Number(N) <= 222) { ans = 222 }
    if (Number(N) <= 111) { ans = 111 }

    console.log(Number(ans));
});

Measured memory_bytes: 7756
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

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

  int sq = sqrt(n) + 5, ans = 0;
  vector<bool> p(sq + 5, 1);


  for(int i = 2; i < p.size(); i++) if (p[i]) {
      int cnt = 0;
      while(n % i == 0) {
        n /= i;
        cnt++;
      }

      for(int j = 1; j <= 100; j++)
        if (j * (j + 1) / 2 <= cnt) ans++;
        else break;

      for(int j = i * i; j < p.size(); j += i) p[j] = 0;
    }
  if (n != 1) ans++;
  cout << ans << "\n";
}


Measured memory_bytes: 3848
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = [0] * N
    for i, a in enumerate(A, 1):
        ans[a - 1] = i

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 24364
fun main(arg: Array<String>) {
    val INF = 1000000007
    val (N, M) = listOfInt()
    val G = Array(N) { IntArray(N) { INF } }
    val E = Array(N) { IntArray(N) }
    repeat(N) { n -> G[n][n] = 0 }
    repeat(M) {
        val (a, b, c) = listOfInt(-1, -1, 0)
        G[a][b] = c; G[b][a] = c
        E[a][b] = c; E[b][a] = c
    }
    for (k in 0 until N)
    for (n in 0 until N)
    for (m in 0 until N)
        G[n][m] = Math.min(G[n][m], G[n][k] + G[k][m])
    val A = Array(N) { BooleanArray(N) }
    for (s in 0 until N)
    for (t in 0 until N)
    for (n in 0 until N)
    for (m in 0 until N) {
        if (s == t || n == m) continue
        if (G[s][t] == G[s][n] + E[n][m] + G[m][t]) A[n][m] = true
    }
    var ans = 0
    for (n in 0 until N)
    for (m in n until N)
        if (!A[n][m] && E[n][m] != 0) ans += 1
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map(String::toLong)
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }


Measured memory_bytes: 47820
#https://atcoder.jp/contests/agc008/submissions/15248942
import sys
import math

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
c = input()

R = c.count('R')
W = c.count('W')
left = c[:R]

ans = min(R,W)
ans = min(ans,left.count('W'))

print(ans)



Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  char S[N];
  int count = 0;
  for(int i=0;i<N;i++){
    cin >> S[i];
    if(i>=2){
      if(S[i]=='C'&&S[i-1]=='B'&&S[i-2]=='A') count += 1;
    }
  }

  cout << count << endl;

  return 0;
}

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

int main(){	
	int x,n;
	cin >> x >> n;
	vector<int> d(102);
	rep(i,n){
		int p;
		cin >> p;
		d[p] = 1;
	}
	pair<int ,int> ans(99999, -1);
	for(int i=0; i<=101; ++i){
		if(d[i] == 1) continue;
		int dif = abs(x-i);
		ans = min(ans, pair<int,int>(dif,i));
	}
	cout << ans.second << endl;
	return 0;
}




Measured memory_bytes: 3528
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)
#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

vector<string> permu_char(vector<char> v, int digit) {
    vector<string> ret;
    if (digit == 1) {
        for (auto c : v) {
            ret.push_back(string(1, c));
        }

        return ret;
    }

    vector<string> tmp;
    for (auto c : v) {
        tmp = permu_char(v, digit - 1);
        for (auto s : tmp) {
            ret.push_back(string(1, c) + s);
        }
    }

    return ret;
}

bool is_753(int n) {
    vector<bool> used(3, false);

    while (n > 0) {
        if (n % 10 == 3) {
            used[0] = true;
        } else if (n % 10 == 5) {
            used[1] = true;
        } else {
            used[2] = true;
        }

        n /= 10;
    }

    return used[0] && used[1] && used[2];
}

// --- notice ---
// intの和はllにしろ

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

    vector<char> c_753;
    c_753.push_back('3');
    c_753.push_back('5');
    c_753.push_back('7');


    int digit = (int) log10(n) + 1;
    int cnt = 0;
    // digit桁未満の753数の総数
    repext(i, 1, digit) {
        cnt += (pow(3, i) - pow(2, i) * 3 + 3);
    }

    vector<string> test = permu_char(c_753, digit);

    int tmp;
    for (auto s: test) {
        tmp = stoi(s);
        if (tmp > n) {
            break;
        }
        
        if (is_753(tmp)) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2140
n,m=map(int,input().split())
h=list(map(int,input().split()))

f=[1]*n

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    if h[a]<=h[b]:
        f[a]=0
    if h[a]>=h[b]:
        f[b]=0
ans=0

for i in f:
    ans+=i

print(ans)

Measured memory_bytes: 20100
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+5;
const int INF=1e9;

int main(){
	int N,K;
	cin>>N>>K;
	int h[MAX];
	rep(i,N)cin>>h[i];
	int dp[MAX];
	rep(i,N)dp[i]=INF;
	dp[0]=0;
	rep1(i,N-1){
		rep1(j,K){
			if(i<j)continue;
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[N-1];
}

Measured memory_bytes: 1024
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main()
{
    int x;
    std::cin >> x;
    long long i = 0;
    long long total =0;
    for(i=0;i <= x;i++){

        if(i % 3 == 0 || i % 5 == 0){
        }
        else{
            
            total += i;
        }
    
    }

        cout << total;
    


    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin>>n;
    float x[10],ans=0;
    string u[10];

    for(int i=0;i<n;i++){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY")ans+=x[i];
        else ans+=x[i]*380000;
    }

    cout<<ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int A,B;cin>>A>>B;
	cout<<max(A-2*B,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int m,d;
    cin>>m>>d;
    int ans=0;
    for(i=1;i<=m;i++){
        for(j=1;j<=d;j++){
            if(j%10>=2&&j/10>=2&&(j%10)*(j/10)==i){
                cerr<<i<<" "<<j<<endl;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A = 0;
  int B = 0;
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < b; i++) {
    A = A * 10 + a;
  }
  for (int i = 0; i < a; i++) {
    B = B * 10 + b;
  }
  if (A < B)
    cout << B << endl;
  else {
    cout << A << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) scanf("%lld",&a)
#define out(a) printf("%lld ",a)
#define loop(i,m,p) for ($$ i = m; i < p; i++)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;


int main()
{
    $$ n,k;
    in(n);
    $$ a[n];
    loop(i,0,n) in(a[i]);
    vp v;
    loop(i,0,n){
    	v.pb({a[i],(i+1)});
    }
    sort(v.begin(),v.end());
    loop(i,0,n) cout<<v[i].second<<" ";




return 0;
}


Measured memory_bytes: 3312
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let (A, B) = read!(i64, i64);
    let P = read![[i64]];

    let mut a = 0_i64;
    let mut b = 0;
    let mut c = 0;

    for p in P {
        if p <= A {
            a += 1;
        } else if p <= B {
            b += 1;
        } else {
            c += 1;
        }
    }

    println!("{}", min(min(a, b), c))
}


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

using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;

template<typename C>
i64 Size(const C& c) { return static_cast<i64>(c.size()); }

template<typename C>
void Sort(C &c) { std::sort(c.begin(), c.end()); }

template<typename C>
void SortR(C &c) { std::sort(c.rbegin(), c.rend()); }

template<typename T, typename U, typename Comp=std::less<>>
bool ChMax(T& x_max, const U& x, Comp comp={}) {
  if(comp(x_max, x)) {
    x_max = x;
    return true;
  }
  return false;
}

template<typename T, typename U, typename Comp=std::less<>>
bool ChMin(T& x_min, const U& x, Comp comp={}) {
  if(comp(x, x_min)) {
    x_min = x;
    return true;
  }
  return false;
}

struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;

  ProconInit() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(IOS_PREC);
    if (AUTOFLUSH) std::cout << std::unitbuf;
  }
} PROCON_INIT;

void solve() {
  i64 n; std::cin >> n;

  i64 sum = 0;
  for (i64 i = 1; i <= n; i++) {
    if (i % 3 == 0) continue;
    if (i % 5 == 0) continue;
    sum += i;
  }

  std::cout << sum << "\n";
}

signed main() {
  solve();

  return 0;
}


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

struct piece{
  int north,west;
  int h,w;
  piece(int north, int west, int h, int w):north(north),west(west),h(h),w(w){}
  pair<piece,piece> cut(int s){
    int x = west;
    int y = north;
    int dir = 0;

    while(s>0){
      if(dir==0){
	++x;
      }else if(dir==1){
	--y;
      }else if(dir==2){
	--x;
      }else if(dir==3){
	++y;
      }
      if( x == west + w && y == north ) dir = 1;
      if( x == west + w && y == north - h ) dir = 2;
      if( x == west && y == north - h ) dir = 3;
      if( x == west && y == north ) dir = 0;
      --s;
    }

    if( x == west || x == west + w ){
      return make_pair( piece( north, west, north-y, w), piece(north-y, west, h-(north-y), w) );
    }else{
      return make_pair( piece( north, west, h, x-west), piece(north, west+x, h, w-(x-west)) );
    }    
  }
  int getarea()const{return h * w;}
  bool operator<(const piece &t)const{
    return getarea() < t.getarea();
  }
};

int main(void)
{
  while(true){
    int n,w,d;
    cin >> n >> w >> d;
    if(n==0&&w==0&&d==0)break;

    vector<piece> vp;
    vp.push_back( piece(d,0,d,w) );
    for(int i = 0; i < n; ++i){
      int p,s;
      
      cin >> p >> s;
      --p;
      pair<piece, piece> pp = vp[p].cut( s );
      vp.erase( vp.begin() + p );
      if( pp.second < pp.first ) swap(pp.first, pp.second );
      vp.push_back( pp.first );
      vp.push_back( pp.second );
      
    }
    
    sort( vp.begin(), vp.end() );
    for(int i = 0; i < (int)vp.size(); ++i){
      if( i ) cout << ' ';
      cout << vp[i].getarea();
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;
int main(void){
    
    int a, b, c;
    vector<int> vec;

    cin >> a >> b >> c;
    vec.push_back(a);
    vec.push_back(b);
    vec.push_back(c);
    
    sort(vec.begin(), vec.end());
    if(vec[0]==5 && vec[1]==5 && vec[2]==7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b&&a){
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				cout<<'#';
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int n;
    cin >> n;
    vector<int> l(2 * n);
    for (size_t i = 0; i < 2 * n; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end());
    int ans = 0;
    for (size_t i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	ll n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i < n; i++) {
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> arr;
int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,k;
    cin>>n>>k;
    arr.resize(n);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    vector<int> ans(n,INT_MAX);
    ans[0]=0;
    ans[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++)
    {  
        //ans[i]=min(abs(arr[i]-arr[i-1])+ans[i-1],abs(arr[i]-arr[i-2])+ans[i-2]);
        for(int j=i-1;j>=i-k;j--)
        {
            if(j<0)
            break;
            ans[i]=min(ans[i],abs(arr[i]-arr[j])+ans[j]);
        }
    }
    cout<<ans[n-1];
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int count = 0;
        
        for(int i=0; i<S.length(); i++){
            if(S.charAt(i) == T.charAt(i)){
                continue;
            }else{
                count++;
            }
        }
        
        System.out.println(count);
        
    }
}


Measured memory_bytes: 41308
#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}

namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }
      catch (edge<int> x) {}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Measured memory_bytes: 35360
import math
import numpy as np

pi = np.pi
n=input()
t=n.split()
a= int(t[0])
b=int(t[1])
x=int(t[2])

if(a*a*b==x):
    print(0)
elif(x<=a*a*b/2):
    print(math.atan(a*b*b/(2*x))*180/pi)
else:
    print(math.atan((2*b-2*x/a/a)/a)*180/pi)

Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 1e6+10;

int func(ll x) {
  return x*(x+1)/2*(x+2)/3;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> dp1(MAX, INF), dp2(MAX, INF);
  dp1[0] = dp2[0] = 0;
  for (int i = 1; i < MAX; i++) {
    for (int j = 1; ; j++) {
      ll num = func(j);
      if (i-num < 0)
        break;
      chmin(dp1[i], dp1[i-num]+1);
      if (num%2)
        chmin(dp2[i], dp2[i-num]+1);
    }
  }
  int tmp;
  while (cin >> tmp && tmp)
    cout << dp1[tmp] << ' ' << dp2[tmp] << '\n';
  return 0;
}


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

int main(void){
  long long x;cin >> x;
  if(x%11 != 0 && x%11<=6)cout << (x/11)*2+1;
  else if(x%11 != 0)cout << (x/11)*2+2 << endl;
  else cout << (x/11)*2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++) 
#define ltype ll
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int n,a[200005],b[200005],c[200005],fin;
int solve(int k){
    ll md=1<<(k+1);
    rep(i,1,n) c[i]=b[i]%md;
    sort(c+1,c+n+1);
    int ans=0;
    rep(i,1,n){
        int num=a[i]%md;
        int cur=(lower_bound(c+1,c+n+1,(1<<(k+1))-num)-1-lower_bound(c+1,c+n+1,(1<<k)-num))
        +(lower_bound(c+1,c+n+1,(1<<(k+2))-num)-1-lower_bound(c+1,c+n+1,(1ll<<(k+1))+(1<<k)-num));
        ans+=cur;
    }
    return ans&1;
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,n) scanf("%d",b+i);
    rep(i,0,28) fin+=solve(i)*(1<<i);
    printf("%d",fin);
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

vector <int> g[N], gr[N];
vector<bool> used;
vector<ll> order, component;
int ans[N];

void dfs1 (ll v)
{
    used[v] = true;
    for (size_t i=0; i<g[v].size(); ++i)
        if (!used[ g[v][i] ])
            dfs1 (g[v][i]);
    order.push_back (v);
}

void dfs2 (ll v)
{
    used[v] = true;
    component.push_back (v);
    for (size_t i=0; i<gr[v].size(); ++i)
        if (!used[ gr[v][i] ])
            dfs2 (gr[v][i]);
}

main()
{
    ll n;
    cin>>n;
    ll x[n],y[n];
    vector<pair<pii,ll>>xs,ys;

    for(ll i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
        xs.push_back({{x[i],y[i]},i});
        ys.push_back({{y[i],x[i]},i});
    }

    sort(xs.begin(),xs.end());
    sort(ys.begin(),ys.end());

    //cout<<"fff"<<endl;
    //y sm, x sm
    set<pair<ll,ll>>temp;
    for(ll i=0;i<n;i++)
    {
        ll px=xs[i].first.first,py=xs[i].first.second,p=xs[i].second;

        auto low=temp.lower_bound({py,-1e9});
        if(low!=temp.begin())
        {
            low--;
            ll q=low->second;
            g[p].push_back(q);
            g[q].push_back(p);
        }
        temp.insert({py,p});
    }
    temp.clear();
    //cout<<"f1"<<endl;

    //y big, x big
    for(ll i=n-1;i>=0;i--)
    {
        ll px=xs[i].first.first,py=xs[i].first.second,p=xs[i].second;

        auto low=temp.lower_bound({py,-1e9});
        if(low!=temp.end())
        {
            ll q=low->second;
            g[p].push_back(q);
            g[q].push_back(p);
        }
        temp.insert({py,p});
    }
    temp.clear();
    //cout<<"f2"<<endl;

    //3 x sm, y sm
    for(ll i=0;i<n;i++)
    {
        ll px=ys[i].first.second,py=ys[i].first.first,p=ys[i].second;

        auto low=temp.lower_bound({px,-1e9});
        if(low!=temp.begin())
        {
            low--;
            ll q=low->second;
            g[p].push_back(q);
            g[q].push_back(p);
        }
        temp.insert({px,p});
    }
    temp.clear();

    //4 x big, y big
    for(ll i=n-1;i>=0;i--)
    {
        ll px=ys[i].first.second,py=ys[i].first.first,p=ys[i].second;

        auto low=temp.lower_bound({px,-1e9});
        if(low!=temp.end())
        {
            ll q=low->second;
            g[p].push_back(q);
            g[q].push_back(p);
        }
        temp.insert({px,p});
    }
    temp.clear();


    for(int i=0;i<n;i++)
    {
        for(int u:g[i])
        {
            gr[u].push_back(i);
        }
    }

    //cout<<"Done"<<endl;

    used.assign (n, false);
    for (ll i=0; i<n; ++i)
        if (!used[i])
            dfs1 (i);
    used.assign (n, false);
    for (ll i=0; i<n; ++i)
    {
        ll v = order[n-1-i];
        if (!used[v])
        {
            dfs2 (v);
            for(int u:component)
                ans[u]=component.size();
            component.clear();
        }
    }
    for(int i=0;i<n;i++)
        cout<<ans[i]<<' ';
}


Measured memory_bytes: 73552
def hantei(start,key):
    if( ango[start]=="?" or ango[start]==key) and len(key)==1:
        return True
    if ango[start]=="?" or ango[start]==key[0]:
        key=key[1:]
        return hantei(start+1,key)
    else:
        return False
ango=input()
key=input()
top=key[0]
ans="UNRESTORABLE"
for i in range(len(ango)-len(key)+1):
    if hantei(i,key):
        ans=ango[:(i)]+key+ango[(i+len(key)):]
for j in range(len(ans)):
    if ans[j]=="?":
        ans=ans[:j]+"a"+ans[(j+1):]
print(ans)


Measured memory_bytes: 3064
<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$a=trim(fgets($handle));
$a=explode(' ',$a);

$i=100;$last=1000000009;
$num=0;
while($i>0)
{

    $sum=0;
    for($k=0;$k<$t;$k++)
    {
        $sum+=pow(($a[$k]-$i),2);
    }
    //echo $sum."    ";
    if($sum<$last)
    {
        $last=$sum;
    }
   $i--;
}
echo $last."\n";


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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    SORT(A);
    vector<ll> S(N+1); S[0]=0; REP(i,N) S[i+1] = S[i] + A[i];
    int ans = 0;
    int r, tmp=1;
    REP(i,N){
        r = max(i+1,tmp);
        while(r<N && A[r] <= S[r]*2) r++;
        if(r == N) ans++;
        tmp = r;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
  	int count = 0;
    for (int i = 1; i <= n; i++) 
	{
      for (int j = 1; j*i < n; j++) 
	  {
          count++;   //at most for max n= 10e6 will run 10e7 ;
      }
    }  
  	cout << count << endl;
    return 0;
}
   

Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long a[100005],b[100005],x;
fill_n(b,100005,INT_MAX);
int k=0,p;
long long n;
cin>>n>>p;
for(int i=1;i<=n;i++)
cin>>a[i];
b[n-1]=abs(a[n]-a[n-1]);
b[n]=0;
for(int j=n-2;j>=1;j--)
{
for(int i=j+1;i<=n ;i++)
{
    k++;
    if(k>p)
    break;
    x=abs(a[j]-a[i])+b[i];
    if(x<=b[j])
    b[j]=x;
}
k=0;
}
cout<<b[1];
return 0;
}




Measured memory_bytes: 1792
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
import qualified Data.ByteString.Char8 as C
import Data.List (sort)
import Data.Maybe (fromJust)
 
main = putStrLn . solve . C.lines =<< C.getContents
 
solve [n,ds,m,ts] = if ans then "YES" else "NO"
    where
        toInt = fst . fromJust . C.readInt
        n' = toInt n
        m' = toInt m
        ds' = sort $ map toInt $ C.words ds
        ts' = sort $ map toInt $ C.words ts
        ans = n' >= m' && f ts' ds'
        f [] _  = True
        f _  [] = False
        f xs@(x:xxs) ys@(y:yys) | x == y = f xxs yys
                                | x >  y = f xs  yys
                                | otherwise = False

Measured memory_bytes: 65788
N, M = map(int, input().split())
d = [[float('inf') for _ in range(N + 1)] for _ in range(N + 1)]
edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c
    edges.append((a, b, c))

for i in range(1, N + 1):
    d[i][i] = 0
for k in range(1, N + 1):
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0
for edge in edges:
    if edge[2] != d[edge[0]][edge[1]]:
        ans += 1

print(ans)


Measured memory_bytes: 46700
#include <stdio.h>

#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long

int main() {
	LL N, Q;
	scanf("%lld", &N);
	LL A, S = 0;
	static LL llCnt[100001] = {0, };
	for (LL i = 0; i < N; i++) {
		scanf("%lld", &A);
		S += A;
		llCnt[A]++;
	}
	scanf("%lld", &Q);
	LL B, C;
	for (LL i = 0; i < Q; i++) {
		scanf("%lld %lld", &B, &C);
		S += ((C - B) * llCnt[B]);
		llCnt[C] += llCnt[B];
		llCnt[B] = 0;
		printf("%lld\n", S);
	}

	return 0;
}


Measured memory_bytes: 2512