akhauriyash/Code-Regression huggingface dataset:
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7

#Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ここから書き始める
s = input()
a, b, c = 0, 0, 0
for i in s:
    if i == "a":
        a += 1
    elif i == "b":
        b += 1
    else:
        c += 1
maximum = max(a, b, c)
minimum = min(a, b, c)
if maximum - minimum <= 1:
    print("YES")
else:
    print("NO")




Measured memory_bytes: 5560
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i, k, n, a[200000], min;
    scanf("%d %d",&k, &n);
    for (i = 1; i <= n;i++){
        scanf("%d", &a[i]);
    }
    a[0] = a[n] - k;
    min = k;
    for (i = 1; i <= n;i++){
        if(min>k-a[i]+a[i-1]){
            min = k - a[i] + a[i - 1];
        }
    }
    printf("%d", min);

    return 0;
}


Measured memory_bytes: 896
N, Y = map(int, input().split())
if Y % 1000 != 0:
    print(-1, -1, -1)
else:
    # max(N)=2000 -> 2000**2 = 4*(10**6)
    for a in range(N+1):
        for b in range(N+1):
            c = N - a - b
            if c < 0:
                continue
            elif Y == 10000 * c + 5000 * b + 1000 * a:
                print(c, b, a)
                exit()
    print(-1, -1, -1)


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

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	priority_queue<pair<int,int>> Q;
	rep(i,n){
		int a; scanf("%d",&a);
		Q.emplace(-a,1);
	}

	rep(_,m){
		int b,c; scanf("%d%d",&b,&c);
		int b0=b;
		while(1){
			auto x=Q.top();
			int val=-x.first,num=x.second;
			if(c<=val){
				if(b<b0) Q.emplace(-c,b0-b);
				break;
			}

			if(b<=num){
				Q.pop();
				if(b<num) Q.emplace(-val,num-b);
				Q.emplace(-c,b0);
				break;
			}
			else{
				Q.pop();
				b-=num;
			}
		}
	}

	long long ans=0;
	while(!Q.empty()){
		auto x=Q.top();
		int val=-x.first,num=x.second;
		ans+=1LL*val*num;
		Q.pop();
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1400
arr = [int(x) for x in input().split()]
arr1 = [0,0,0,0,0,0,0,0,0,0,0]
arr1[arr[0]]+=1
arr1[arr[1]]+=1
arr1[arr[2]]+=1
if(arr1[5]==2 and arr1[7]==1):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	dp[1] = 0;
	for(int i=2;i<=n;i++){
		dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
		if(i >= 3){
			dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
		}
	}
	cout<<dp[n]<<endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 222;
const ll inf = 1e13;
int n,m,r;
ll g[maxn][maxn];

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

  


  cin>>n>>m>>r;

  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      g[i][j]=inf;
    }
  }
  for (int i=0; i<n; i++) {
    g[i][i]=0;
  }
  
  vector<int> v(r);
  for (int i=0; i<r; i++) {
    cin>>v[i];
    --v[i];
  }


  for (int i=0; i<m; i++) {
    int u,v; ll d; cin>>u>>v>>d;
    --u; --v;
    if (g[u][v] > d) {
      g[u][v]=g[v][u]=d;
    }
  }


  for (int k=0; k<n; k++) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  ll best = inf;

  sort(v.begin(), v.end());
  do {
    ll cur = 0;
    for (int i=0; i+1<r; i++) {
      cur += g[v[i]][v[i+1]];
    }
    best = min(cur, best);
  } while (std::next_permutation(v.begin(), v.end()));

  cout<<best<<endl;  

  return 0;
}


Measured memory_bytes: 640
// Author :: <Hitesh_Saini>
#include<bits/stdc++.h>

#define __speed() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define dbg(x) cout << "--- " << #x << " = " << x << " ---\n";
#define findmax(v) *max_element(v.begin(), v.end())
#define _sum(a) accumulate(a.begin(), a.end(), 0)
#define tt int t;for(cin>>t; t--; )
#define f0(i, n) for(i = 0; i < int(n); i++)
#define f1(i, n) for(i = 1; i<= int(n); i++)
#define all(x) x.begin(), x.end()
#define pq priority_queue
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define S second
#define ar array
#define F first

using namespace std;
using mii = map<int, int>;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int mod = 1e9+7,mxN = 2e6+5;

template<typename... Args>void print(Args... args){((cout << args << " "), ...);cout << endl;}
ll mod_pow(ll x, ll y){ll res=1;x%=mod;for(;y>0; y>>=1, x=(x*x)%mod)if(y&1)res=(res*x) % mod; return res; }ll mod_inv ( ll n ){ll ans = mod_pow ( n , mod - 2 ) ;return ans ;}ll mul(ll a, ll b){a%=mod, b%=mod;return (a*b)%mod;}ll sub(ll a,ll b){a%=mod, b%=mod;return (a-b+mod)%mod;}ll add(ll a, ll b){a%=mod, b%=mod;return (a+b)%mod;}
bool prime(ll n){if(n<2)return 0;if(n<4)return 1;if(n%2==0||n%3==0)return 0;for(ll i=5;i*i<=n;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>  
using namespace __gnu_pbds; 
#define iset tree<ll , null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define iof order_of_key
#define findat find_by_order */
ll n;
map<string, int> m;
string st;
void solve(){ //B
		cin >>  st;
		m[st]++;
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
    __speed();
    tt solve();
    print("AC x ", m["AC"], "WA x ", m["WA"],"TLE x ", m["TLE"], "RE x ", m["RE"]);
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>

#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()

using namespace std;

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

const int INF = 0x3c3c3c3c;
const ll LINF = 1ll*INF*INF*2;

const int MAX_N = 100001;
int n;
string s;
bool input[MAX_N];
vector<int> v;

int main(void) {
	cin >> s;
	n = s.size();
	for(int i=0; i<n; i++) input[i+1] = s[i]-'0';
	for(int i=1; i<n; i++) if(input[n-i] != input[i]) {printf("-1"); return 0;}
	if(input[n]) {printf("-1"); return 0;}
	if(!input[1]) {printf("-1"); return 0;}
	//10이면 5까지 , 9면 4까지

	for(int i=1; i<=n/2; i++) if(input[i]) v.push_back(i);
	int szv = sz(v);

	int cur=1;
	for(int i=1; i<szv; i++) {
		int temp = cur+1;

		while(temp<=v[i]) {
			printf("%d %d\n", cur, temp);
			temp++;
		}
		printf("%d %d\n", cur, temp);
		cur = temp;
	}
	for(int temp = cur+1; temp<=n; temp++) printf("%d %d\n", cur, temp);
}


Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>

using namespace std;


int main(){
  int N;
  int count = 0;
  int L[2001];
  cin >> N;
  for (int i=0;i<N;i++){
      cin >> L[i];
  }
  
  sort(L, L+N);
  
  for (int i =0 ; i <N-2 ;i++){
	for(int j=i+1; j<N-1; j++){
		for ( int z = j+1; z < N; z++){
			if( (L[i] < L[j]+L[z])
			    && (L[j] < L[i]+L[z])
			    && (L[z] < L[i]+L[j])){
				count++;
			}
			else {
				break;
			}
		}
	}
   }
   cout << count;
   
   return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = [0 for _ in range(n)]
    xy = [None for _ in range(n)]
    for i in range(n):
        a[i] = int(input())
        xy[i] = [None for _ in range(a[i])]
        for j in range(a[i]):
            xy[i][j] = tuple(map(int, input().split()))

    ans = 0
    for i in range(1 << n):
        m = [0 for _ in range(n)]
        p = 0
        for j in range(n):
            m[j] = (1 if i & (1 << j) else 0)
            p += (1 if i & (1 << j) else 0)
        if p < ans:
            continue
        good = True
        for j in range(n):
            if m[j]:
                for k in range(a[j]):
                    if m[xy[j][k][0]-1] != xy[j][k][1]:
                        good = False
                        break
            if not good:
                break
        if good:
            ans = p

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46572
#include <iostream>
using namespace std;
int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  if(a[0]-a[1]>0){
    a[3]=a[0]-a[1];
    a[1]=a[0];
    a[0]=a[1]-a[3];
  }
  if(a[1]-a[2]>0){
    a[3]=a[1]-a[2];
    a[2]=a[1];
    a[1]=a[2]-a[3];
  }
  if(a[0]-a[1]>0){
    a[3]=a[0]-a[1];
    a[1]=a[0];
    a[0]=a[1]-a[3];
  }
  cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
  return 0;
}

Measured memory_bytes: 3116
import math
n = int(input())
lst = [[int(j) for j in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if lst[i][0] == lst[j][0] and lst[i][1] == lst[j][1]:
            continue
        else:
            a = (lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2
        ans += math.sqrt(a)
print(ans / n)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    int max = -1;
    int min = 1001;
    for (int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        if (tmp>max)
            max = tmp;
        if (tmp<min)
            min = tmp;
    }

    cout << max - min << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var X = scan.NextInt();
        return X >= 30 ? "Yes" : "No";
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
}


Measured memory_bytes: 27520
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

dmap = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = Array.new(N + 1, -1)
dp[0] = 0

0.upto(N) do |i|
  A.each do |a|
    if i - dmap[a] >= 0 && dp[i - dmap[a]] != -1
      dp[i] = [dp[i], dp[i - dmap[a]] * 10 + a].max
    end
  end
end

p dp[N]

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    ll max = 0;
    REP(i, S.length())
    {
        ll m = 0;
        REP(j, S.length())
        {
            if (i + j >= S.length())
                break;
            if (S[i + j] == 'A' || S[i + j] == 'G' || S[i + j] == 'C' || S[i + j] == 'T')
            {
                m++;
                continue;
            }
            break;
        }
        max = std::max(m, max);
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#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;

ll n,x,y;

vector<vector<int>> graph(10001);
vector<int> counter(10001);

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

    REP(i, n-1) {
        graph[i].push_back(i+1);
        graph[i+1].push_back(i);
    }

    graph[x-1].push_back(y-1);
    graph[y-1].push_back(x-1);

    REP(j, n) {
        queue<int> que;
        vector<bool> seen(n+10);
        vector<int> d(n+10);
        que.push(j);
        d[j] = 0;
        int res = 0;
        seen[j] = true;
        while(!que.empty()){
            int c = que.front();
            que.pop();

            if( j < c) {
                counter[d[c]]++;
            }
            
            for(int k = 0; k < graph[c].size(); k++) {
                int nex = graph[c][k];
                
                if(seen[nex]) {
                    continue;
                }

                seen[nex] = true;

                que.push(nex);
                d[nex] = d[c] + 1;
            }
        }
    }

    REP(i, n-1) {
        cout << counter[i+1] << endl;
    }
}

 

Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

long[][10^^5] T;
long[10^^5] D;
bool[10^^5] M;

void main()
{
    auto nk = readln.split.to!(long[]);
    auto N = nk[0];
    auto K = nk[1];
    foreach (_; 0..N-1) {
        auto ab = readln.split.to!(long[]);
        auto a = ab[0]-1;
        auto b = ab[1]-1;
        T[a] ~= b;
        T[b] ~= a;
    }

    long r = 1;
    long[] ss = [0];
    M[0] = true;
    while (!ss.empty) {
        auto i = ss[0];
        ss = ss[1..$];
        auto ir = K - D[i];
        foreach (j; T[i]) {
            if (!M[j]) {
                ss ~= j;
                M[j] = true;
            }
            ir -= D[j];
            ++D[j];
        }
        r = (r * ir) % P;
    }
    writeln(r);
}

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

typedef long long ll;

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < (int)s.size(); ++i) {
		if (s[i] == '+')cnt++;
		else cnt--;
	}
	cout << cnt;
}


















Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto m = n * (n - 1) / 2;
		m -= n / 2;
		writeln (m);
		int r = n + !(n & 1);
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				if (i + j + 2 != r)
				{
					writeln (i + 1, " ", j + 1);
				}
			}
		}
	}
}


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

using namespace std;

int N, C;
vector<int> colors = vector<int>(3, 0);
int ans = 1e9;

vector<vector<int>> dp;

void dfs(int idx) {
  if (idx == 3) {
    int sum = dp[0][colors[0]] + dp[1][colors[1]] + dp[2][colors[2]];
    if (ans > sum) ans = sum;
    return;
  }
  for (int i = 1; i <= C; i++) {
    bool b = true;
    for (int j = 0; j < idx; j++)
      if (i == colors[j]) b = false;
    if (!b) continue;
    colors[idx] = i;
    dfs(idx + 1);
  }
}

int main() {
  cin >> N >> C;
  auto D = vector<vector<int>>(C + 1, vector<int>(C + 1, 0));
  auto board = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
  for (int i = 1; i <= C; i++)
    for (int j = 1; j <= C; j++)
      cin >> D[i][j]; // (y, x)
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      cin >> board[i][j];
  dp = vector<vector<int>>(3, vector<int>(C + 1, 0));
  for (int j = 1; j <= C; j++)
    for (int k = 1; k <= N; k++)
      for (int l = 1; l <= N; l++)
        if (board[k][l] != j) dp[(k + l) % 3][j] += D[board[k][l]][j];
  dfs(0);
  cout << ans << endl;
  return 0;
}

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

using ll = long long int;

constexpr ll mod = 1e9 + 7;

ll pow(ll x, int m)
{

    ll re = 1;

    for (int i = 0; i <= 30; ++i)
    {
        if (m & (1 << i))
            re = re * x % mod;
        x = x * x % mod;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

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

int main()
{
    int n;
    ll k;

    std::cin >> n >> k;

    std::vector<std::vector<int>> tr(n + 1);

    rep(i, n - 1)
    {
        int a, b;
        std::cin >> a >> b;
        tr[a].push_back(b);
        tr[b].push_back(a);
    }

    std::stack<int> st;

    std::vector<int> used(n + 1);

    std::vector<ll> fact(k + 1);

    fact[0] = 1;

    rep(i, k)
    {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        //std::cerr << fact[i + 1] << std::endl;
    }
  
  	if(tr[1].size()>=k){
      std::cout<<0<<std::endl;
      return 0;
    }

    ll ans = fact[k] * inv(fact[k - tr[1].size() - 1]) % mod;

    used[1] = 1;

    for (int x : tr[1])
    {
        st.push(x);
    }

    //std::cerr << "DEBUG" << std::endl;

    while (!st.empty())
    {
        int x = st.top();
        st.pop();

        //std::cerr << x << ' ' << ans << std::endl;

        used[x] = 1;
      
      	if(tr[x].size()>=k){
          std::cout<<0<<std::endl;
          return 0;
        }

        ans = (ans * fact[k - 2] % mod) * inv(fact[k - tr[x].size() - 1]) % mod;

        for (int y : tr[x])
        {
            if (!used[y])
            {
                st.push(y);
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 7672
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n, m = [int(_) for _ in input().split()]
s = input()
t = input()
a = lcm(n, m)
s_a = a // n
t_a = a // m
p = lcm(s_a, t_a)
result = True
for i in range(a//p):
    if s[(i*p)//s_a] != t[(i*p)//t_a]:
        result = False
if result:
    print(a)
else:
    print(-1)


Measured memory_bytes: 5592
#include<iostream>
int main(){
	long long sum1 = 0;
	long long sum2 = 0;
	int n;
	std::cin >> n;
	for(int i=0;i<n;++i){
		long long a, b;
		std::cin >> a >> b;
		sum1 += b;
		sum2 += a * b;
	}
	std::cout << sum1 - 1 + (sum2 - 1) / 9 << std::endl;
}


Measured memory_bytes: 256
from itertools import product

n_str = input()
n = int(n_str)
l = len(n_str)

e_list = ["3", "5", "7"]

ans = 0
for i in range(3, l + 1):
    for temp in list(product(e_list, repeat=i)):
        # print(temp)
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

Measured memory_bytes: 6260
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

struct inter
{
    int s,t,x;
}v[200001];
int d[200001];

int arbint[800001];

void update(int a,int b,int x,int st,int dr,int nod)
{
    if(st>=a && dr<=b)
    {
        arbint[nod]=min(arbint[nod],x);
        return ;
    }
    int mij=(st+dr)/2;
    if(mij>=a)
        update(a,b,x,st,mij,2*nod);
    if(mij<b)
        update(a,b,x,mij+1,dr,2*nod+1);
}


int build(int i,int st,int dr,int nod)
{
    arbint[nod]=min(arbint[nod],arbint[nod/2]);
    if(st==i && dr==i)
    {
        return arbint[nod];
    }
    int mij=(st+dr)/2;
    if(mij>=i)
        return build(i,st,mij,2*nod);
    else
        return build(i,mij+1,dr,2*nod+1);
}

int main()
{
    int n,m,i,pas,p1,p2;
    scanf("%d%d",&n,&m);
    for(i=1; i<=n; i++)
        scanf("%d%d%d",&v[i].s,&v[i].t,&v[i].x);
    for(i=1; i<=m; i++)
        scanf("%d",&d[i]);
    for(i=0; i<=4*m; i++)
        arbint[i]=INT_MAX;
    for(i=1; i<=n; i++)
    {
        pas=1<<20;
        p1=0;
        while(pas)
        {
            if(p1+pas<=m && v[i].s-v[i].x>d[p1+pas])
                p1+=pas;
            pas/=2;
        }
        p1++;
        p2=0;
        pas=1<<20;
        while(pas)
        {
            if(p2+pas<=m && d[p2+pas]<v[i].t-v[i].x)
                p2+=pas;
            pas/=2;
        }
        if(p1<=p2)
            update(p1,p2,v[i].x,1,m,1);
    }
    for(i=1; i<=m; i++)
    {
        int z=build(i,1,m,1);
        if(z==INT_MAX)
            z=-1;
        printf("%d\n",z);
    }

    return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int N,Q;
  string S;
  cin >> N >> Q;
  cin >> S;
  vector<int> l(Q),r(Q);
  for (int i=0; i<Q; i++)
  {
    cin >> l[i] >> r[i];
  }
  vector<int> sum(N+1,0);
  
  for (int i=1;i<N; i++)
  {
    sum[i+1] = sum[i];
    if (S[i-1] == 'A' && S[i] == 'C') {
      sum[i+1]++;
    }
  }
  for (int i=0; i<Q; i++) 
  {
    int ans = sum[r[i]] - sum[l[i]];
    cout << ans << endl;
  }
}

Measured memory_bytes: 2176
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
def main():
    class Tree():
        def __init__(self, n, root, connects):
            self._root = root
            self._connects = connects
            self._parents = [0] * n
            self._parents[root] = None
            self._children = [0] * n
            self._children[self._root] = connects[self._root]
            self.make_tree(self._root)

        def make_tree(self, node):
            for child in self._children[node]:
                self._parents[child] = node
                self._children[child] = [c for c in self._connects[child] if c != node]
                if self._children[child] != []:
                    self.make_tree(child)

        def parents(self, node):
            return self._parents[node]

        def children(self, node):
            return self._children[node]

    def add_subtree(i):
        for c in t.children(i):
            ans[c] += ans[i]
            add_subtree(c)

    n, q = map(int, input().split())
    G = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        G[b].append(a)
    t = Tree(n, root = 0, connects = G)
    ans = [0] * n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p - 1] += x
    add_subtree(0)
    print(' '.join(list(map(str, ans))))

if __name__ == '__main__':
    main()


Measured memory_bytes: 308448
N = int(input())
hn = list(map(int, input().split()))

dp = [0] * N

for i in range(1, N):
    if i >= 2:
        dp[i] = min(dp[i-2]+abs(hn[i]-hn[i-2]), dp[i-1]+abs(hn[i]-hn[i-1]))
    elif i == 1:
        dp[i] = abs(hn[1]-hn[0])

print(dp[-1])


Measured memory_bytes: 13980
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll lcm(ll a, ll b)
{
   return a / gcd(a, b) * b;
}

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }

    vector<int> cnt(n,0);
    rep(i,n){
        cnt[a[i]]++;
    }

    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(),cnt.end());

    int ans = 0;

    for(int i = k; i < n; i++){
        ans+=cnt[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n,0);
	for(int i=0; i<n; i++) cin>>a[i];
	
	sort(a.begin(), a.end());
	
	int dis=a[n-1]/2;
	int sum=0;
	for(int i=0; i<n-1; i++) sum+=a[i];
	
	cout << dis+sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define MAX 1e9


using namespace std;

bool sortinrev(const pair<int,int> &a,  		//for vector of pairs
               const pair<int,int> &b) 
{ 
       return (a.first < b.first); 
}

int binarySearch(int low,int high,int key,int a[]){
    int mid= low + (high-low)/2;
    while(low<=high){
        if(a[mid]<key)
            low=mid+1;
        else if(a[mid]>key)
            high=mid-1;
        else
            return mid+1;
    }
    return -1;
}

int stringToDecimal(string s){
	int ans=0;
	int base=1;
	for(int i=s.length()-1;i>=0;i--){
		ans = ans + (s[i] - '0')*base;
		base = base*2;
	}
	return ans;
}

int main(){
	double h;
	cin>>h;
	ll count=1;
	if(h==1)		cout<<count;
	else{
		h=floor(h/2);
		ll count1=0;
		ll sum=0;
		while(h!=0){
			count1++;
			sum+=pow(2,(count1-1));
			h=floor(h/2);
		}
		sum=sum*2;
		cout<<count+sum;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define ret return
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pll pair <long long ,  long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);

const int maxn = 3e5 + 30;
ll n , m , k , x[maxn] , per[maxn] , y[maxn] , ans[maxn];
bool mark[maxn];
vector <ll> edges[maxn] , cycle;

void dfs(int v) {
    mark[v] = true;
    cycle.PB(v);
    for (auto u : edges[v]) {
        if(!mark[u]) {
            dfs(u);
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        per[i] = i;
        y[i] = x[i + 1] - x[i];
    }
    cin >> m >> k;
    for (int i = 0; i < m; ++i) {
        ll pos; cin >> pos;
        pos--;
        swap(per[pos] , per[pos - 1]);
    }
    for (int i = 0; i < n - 1; ++i) {
        edges[i].PB(per[i]);
    }
    for (int i = 0; i < n - 1; ++i) {
        if(!mark[i]) {
            dfs(i);
            ll sz = cycle.size();
            ll cnt = 0;
            for (auto u : cycle) {
                ans[u] = cycle[((k + cnt) % sz)];
                cnt++;
            }
            cycle.clear();
        }
    }
    for (int i = 0; i < n - 1; ++i) {
        cout << x[i] << ".0" << endl;
        x[i + 1] = y[ans[i]] + x[i];
    }
    cout << x[n - 1] << ".0" << endl;
}

Measured memory_bytes: 26612
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val K = sc.nextLong()
    val A = Array.fill(N)(sc.nextLong())

    // 各ビット桁毎に足し算は独立できる。
    // 各ビット桁毎に, 0が多ければ1を対応させ, 1が多ければ0を対応させる.
    val BIT_COUNT_1, BIT_COUNT_0 = new Array[Int](40)

    A.foreach { A =>
      val AB = A.toBinaryString.reverse.padTo(40, '0')
      var i = 0
      while (i < AB.length) {
        AB(i) match {
          case '1' => BIT_COUNT_1(i) += 1
          case '0' => BIT_COUNT_0(i) += 1
        }
        i += 1
      }
    }

    val ziped = BIT_COUNT_0.zip(BIT_COUNT_1)
    val maxL = BIT_COUNT_0.zip(BIT_COUNT_1).takeWhile(z => z._1 > 0 || z._2 > 0).length

    var i = 0
    var KBB = ""
    val KB = K.toBinaryString
    var MAX = 0L
    while (i < KB.length) {
      KB(i) match {
        case '1' =>
          val pre = java.lang.Long.parseLong(KBB.padTo(KB.length, '0'), 2)
          val aft = java.lang.Long.parseLong(ziped.take((KB.length - i - 1) min maxL). map { bit =>
            if (bit._1 > bit._2) '1'
            else '0'
          }. reverse. mkString. padTo(1, '0'), 2)
          val X = pre + aft
          MAX = MAX max A.foldLeft(0L)((b, n) => b + (n ^ X))
        case '0' => //
      }
      KBB += KB(i)
      i += 1
    }
    MAX = MAX max A.foldLeft(0L)((b, n) => b + (n ^ K))

    println(MAX)
  }

}


Measured memory_bytes: 107456
#include<iostream>
#define ppp 1000000007
using namespace std;
int main(){
int n,i,ic,j;
long long int a[1000]={0},s=1;
cin>>n;
for(i=2;i<=n;i++){
ic=i;
for(j=2;j<=ic;j++){
if(ic%j==0){
a[j]++;
ic/=j;
j--;}
}
}
for(i=2;i<=n;i++){
s*=(a[i]+1);
if(s>=ppp){
s%=ppp;
}
}
cout<<s;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using uint = unsigned int;
using ll = long long;

int main() {
	int N;
	cin >> N;
	
	vector<pair<ll, ll>> XL(N, pair<ll, ll>());
	
	for(uint i=0; i<N; i++) {
		ll X, L;
		cin >> X >> L;
		XL[i] = make_pair(X - L, X + L);
	}
	
	sort(XL.begin(), XL.end());
	
	ll bais = XL[0].first;
	for(uint i=0; i<N; i++) { // 0 origin
		XL[i].first -= bais;
		XL[i].second -= bais;
	}
	
	ll front = 0;
	uint findx = 0;
	vector<uint> ans(N + 1);
	
	for(uint i=0; i<N; i++) {
		ll le = XL[i].first;
		ll re = XL[i].second;
		
		//cout << front << " ";
		if(front <= le) {
			ans[i+1] = ans[findx+1] + 1;
			front = re;
			findx = i;
		} else if(re <= front) {
			ans[i+1] = ans[findx+1];
			front = re;
			findx = i;
		} else {
			ans[i+1] = ans[findx+1];
		}
		
		//cout << le << " " << re << " " << ans[i+1] << " " << front << endl;
	}
	
	cout << ans[N];
	
	return 0;
}


Measured memory_bytes: 2176
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {
	static char[][] key = new char[][] {{},{'\'',',','.','!','?'},{'a','b','c','A','B','C'},{'d','e','f','D','E','F'},
										{'g','h','i','G','H','I'},{'j','k','l','J','K','L'},{'m','n','o','M','N','O'},
										{'p','q','r','s','P','Q','R','S'},{'t','u','v','T','U','V'},{'w','x','y','z','W','X','Y','Z'}};
										
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String in = sc.next();
			int  id  = -1;
			int count = 0;
			
			for(int i = 0; i < in.length(); i++) {
				int a = in.charAt(i) - '0';
				if(a != id) {
					if(id != -1 && id != 0) {
						System.out.print(key[id][count]);
					}
					id = a;
					count = 0;
				}
				else if(a == id) {
					if(a == 0) System.out.print(' ');
					count++;
				}
			}
			if(id != -1 && id != 0) {
				System.out.print(key[id][count]);
			}
			System.out.println();
		}
	}
 }

Measured memory_bytes: 26704
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b = na()

if a != 1 and b != 1:
    if a == b:
        print("Draw")
    elif a < b:
        print("Bob")
    else:
        print("Alice")
else:
    if a == b:
        print("Draw")
    elif a == 1:
        print("Alice")
    else:
        print("Bob")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define N 200010
using namespace std;
int n,d[N],e[N];
int main ()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&d[i]);
		e[i]=d[i];
	}
	sort(e+1,e+n+1);
	int u=e[n],v=e[n-1];
	for(int i=1;i<=n;i++)
	{
		if(d[i]==u)
			printf("%d\n",v);
		else
			printf("%d\n",u);
	}
	return 0;
}

Measured memory_bytes: 3072
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    string n;
    cin >> n;
    int ans = 0;
    rep(i, n.size()) {
        char s = n[i];
        int num = s - '0';
        ans = (ans + num) % 9;
    }
    if (ans == 0)cout << "Yes" << endl;
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3488
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vi ret(n, 0);
    vi ret2(n, 0);
    ll sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] != ret[i]) {
            ret2[i]++;
            sum++;
            set<int> facs = factors(i + 1);
            for (auto &f : facs) {
                ret[f - 1]++;
                ret[f - 1] %= 2;
            }
        }
    }
    cout << sum << "\n";
    for (int i = 0; i < n; ++i) {
        if (ret2[i] != 0)
            cout << i + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3200
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
		return b;
	else
	{
		return gcd(b, a % b);
	}
}
int hashe[100001],sol[100001];
void solve()
{
	int n, m,ans=0;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		hashe[a]++;
		hashe[b + 1]--;
	}
	for (int i = 1; i < 100001; i++)
	{
		sol[i] = sol[i - 1] + hashe[i];
		if (sol[i] == m)
			ans++;
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 1024
N=int(input())
L= list(map(int,input().split()))
L_sorted=sorted(L,reverse=False)#昇順
count=0
import bisect
for i in range(N):
    for j in range(i+1,N):
        a=L_sorted[i]
        b=L_sorted[j]        
        bisect.bisect_left(L_sorted,a+b)
        count+=bisect.bisect_left(L_sorted,a+b)-j-1
print(count)

Measured memory_bytes: 9288
#include<bits/stdc++.h>
using namespace std;
           ///BISMILLAHIR RAHMANIR RAHIM

int main()
{
    int l,r,d;
    cin>>l >> r>>d;
    int cnt=0;
    for(int i=l;i<=r;i++){
        if(i%d == 0){
            cnt++;

            //cout<<i<<endl;
        }


    }
    cout<<cnt<<endl;

}
/// A L H A M D U L I L L A H



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, h, m, res = -INF, cnt;
    vector<int> start;
    int m_start[55], m_end[55], l_start[55], l_end[55], d_start[55], d_end[55];
    cin>>n;
    rep(i, n){
        cin>>h>>m;
        m_start[i] = 60 * h + m;
        start.push_back(m_start[i]);
        cin>>h>>m;
        m_end[i] = 60 * h + m;

        cin>>h>>m;
        l_start[i] = 60 * h + m;
        start.push_back(l_start[i]);
        cin>>h>>m;
        l_end[i] = 60 * h + m;

        cin>>h>>m;
        d_start[i] = 60 * h + m;
        start.push_back(d_start[i]);
        cin>>h>>m;
        d_end[i] = 60 * h + m;
    }

    each(b, start){
        each(l, start){
            each(d, start){
                cnt = 0;
                rep(i, n){
                    if(
                        b >= m_start[i] && b <= m_end[i] &&
                        l >= l_start[i] && l <= l_end[i] &&
                        d >= d_start[i] && d <= d_end[i]
                    ) cnt++;
                }
                chmax(res, cnt);
            }
        }
    }
    cout<<res<<endl;
}



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

int main(void){
	ll X, K, D;
	cin >> X >> K >>D;

	ll ans;
	if (abs(X)/D>=K) {
		ans = (abs(X)/D - K)*D + abs(X)%D;
	}
	else {
		ll n = abs(X)/D;
		ll p = abs(X)%D;
		ll q = (K-n)%2;
		ans = abs(p-q*D);
	}
	cout << ans << endl;

return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = s.nextInt();
		}
		
		int alice = 0;
		int bob = 0;
		for(int i = 0;i < N;i++){
			int max = 0;
			int c = -1;
			for(int j = 0;j < N;j++){
				if(a[j] > max){
					c = j;
					max = a[j];
				}
			}
			a[c] = 0;
			if(i % 2 == 0){
				
				alice += max;
			}else{
				
				bob += max;
			}
		}
		
		System.out.println(alice - bob);
	}

}


Measured memory_bytes: 21076
#include <iostream>
#include <string>

using namespace std;

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

    long double a;
    long double div = 0;

    for (int i = 0; i < N; ++i) {
        cin >> a;
        div += 1.0 / a;
    }

    cout << (1.0 / div) << endl;

    return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
l = []
ans = 0

for i in range(1,n+1):
    for j in range(20):
        if 2**j >= k/i:
            l.append(j)
            break

for i in l:
    ans += 1/n * (1/2)**i
print(ans)

Measured memory_bytes: 9664
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,pas1,pas2,x,bo[210];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>x>>a;
	for(i=1; i<=a; i++){
		cin>>c;
		bo[c]=1;
	}
	pas1=2000;
	for(i=0; i<=200; i++){
		if(abs(x-i)<pas1&&bo[i]==0){
			pas1=abs(x-i);
			pas2=i;
		}
	}
	cout<<pas2;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 300;
int n;
char g[N][N];

void full_rotate() {
	REP(i, n) rotate(g[i], g[i]+1, g[i]+n);
}

bool symmetric() {
	REP(i, n) {
		FOR(j, i+1, n-1) {
			// DEBUG(i);
			// DEBUG(j);
			// DEBUG(g[i][j]);
			// DEBUG(g[j][i]);
			if(g[i][j] != g[j][i]) return 0;
		}
	}
	return 1;
}

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n;
    REP(i, n) REP(j, n) cin >> g[i][j];
    int ans = 0;
    REP(r, n) {
    	if(symmetric()) {
    		// cout << r << endl;
    		ans += n;
    	}
    	full_rotate();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)

int main(){
    int A,B;
    scanf("%d %d",&A,&B);
    if(A < 6)
        printf("0\n");
    else if(A < 13)
        pd(B/2);
    else
        pd(B);
    return 0;
}

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

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

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

const double Pi = acos(-1) ;

int main () {
  while(1){
    int N ;
    cin >> N ;
    if(N==0) break ;
    double pre = 0 ;
    double a[N] ;
    for(int i = 0 ; i < N ; i++){
      cin >> a[i] ;
      pre += a[i] ;
    }
    double ans = 0 ;
    for(int i = 0 ; i < N ; i++){
      ans +=(a[i]-pre/N) * (a[i]-pre/N) ;
    }
    cout <<fixed << setprecision(10) <<sqrt(ans /N)<< endl ;
  }
}


Measured memory_bytes: 3276
#include <iostream>
using namespace std;
int main() {
    string s;
    while(getline(cin,s)){
        if(s=="Sunny")
            cout<<"Cloudy"<<endl;
        else if(s=="Cloudy")
            cout<<"Rainy"<<endl;
        else if(s=="Rainy")
            cout<<"Sunny"<<endl;
    }
}

Measured memory_bytes: 256
import collections
import sys
sys.setrecursionlimit(10**7)

def dfs(u):
  for v in g[u]:
    if checked[v]==1:
      continue
    else:
      checked[v]=1
      depth2[u]=max(depth2[u],dfs(v)+1)
  return depth2[u]

n,u,v=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
depth=[0]*(n+1)
checked=[0]*(n+1)
checked[v]=1
q=collections.deque()
q.append((v,0))
while 1:
  if len(q)==0:
    break
  tu,d=q.popleft()
  checked[tu]=1
  depth[tu]=d
  for tv in g[tu]:
    if checked[tv]!=1:
      checked[tv]=1
      q.append((tv,d+1))
moves=(depth[u]-1)//2
depth2=[0]*(n+1)
checked=[0]*(n+1)
checked[v]=1
dfs(v)
checked=[0]*(n+1)
checked[u]=1
q=collections.deque()
q.append((u,0))
cand=[]
while 1:
  if len(q)==0:
    break
  tu,d=q.popleft()
  if d==moves:
    cand.append(tu)
  checked[tu]=1
  for tv in g[tu]:
    if checked[tv]!=1:
      checked[tv]=1
      q.append((tv,d+1))
md=0
for i in cand:
  md=max(md,depth2[i])
if depth[u]%2!=0:
  ans=moves+md
else:
  ans=moves+md+1
print(ans)

Measured memory_bytes: 101548
n = int(input())
A = list(map(int, input().split()))
print(*A)
for i in range(1, n):
    v = A[i]
    j = i-1
    while j>=0 and A[j]>v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
    int n;
    cin >> n;
    int tmp = n, sum = 0;
    while (1) {
        sum += tmp%10;
        tmp = (tmp-tmp%10)/10;
        if (tmp == 0) break;
    }
    if (n%sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include <cmath>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    ll mod=1000000007;
    char s[200005]={};
    scanf("%d%s",&n,s);
    int left=0;
    int right=0;
    int rrem=0;
    ll ans=1;
    for(int i=1;i<=n;i++)ans=ans*i%mod;
    if(s[0]=='W' || s[2*n-1]=='W'){
        printf("0\n");
        return 0;
    }
    REP(i,n*2){
        if(i%2==0){
            if(s[i]=='B'){
                right++;
                rrem++;
            }
            else if(s[i]=='W'){
                left++;
                if(rrem>0){
                    ans=ans*rrem%mod;
                    rrem--;
                }
                else{
                    printf("0\n");
                    return 0;
                }
            }
        }
        else if(i%2==1){
            if(s[i]=='W'){
                right++;
                rrem++;
            }
            else if(s[i]=='B'){
                left++;
                if(rrem>0){
                    ans=ans*rrem%mod;
                    rrem--;
                }
                else{
                    printf("0\n");
                    return 0;
                }
            }
        }
    }
    if(left!=right){
        printf("0\n");
        return 0;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
A,B,N = map(int,input().split())
#N=int(input())
#A = list(map(int,input().split()))
#S=str(input())
m=0
if B<=N:
    m=int(A * (B-1) / B)
    print(m)

else:
    m=int(A * N / B)
    print(m)


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

using namespace std;

bitset<4000002>s;
int n, x, sum;

int main()
{
  cin >> n;
  s[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    s = s | (s << x);
    sum += x;
  }
  int t  = (sum + 1) / 2;
  for (int i = t; i <= sum; i++)
    if (s[i]) {
      cout << i;
      return 0;
    }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int x[n], y[n];
  double p1 = 0, p2, p3, pmax = 0, tmp1 = 0, tmp2 = 0;

  for ( int i = 0; i < n; i++ ) cin >> x[i];
  for ( int i = 0; i < n; i++ ) cin >> y[i];

  for ( int i = 0; i < n; i++ ){
    p1 += fabs(x[i]-y[i]);
    tmp1 += (x[i]-y[i])*(x[i]-y[i]);
    tmp2 += pow(fabs(x[i]-y[i]), 3);
    if ( fabs(x[i]-y[i]) > pmax ) pmax = fabs(x[i]-y[i]);
  }
  p2 = sqrt(tmp1);
  p3 = pow(tmp2, 1.0/3.0);
  printf("%lf\n%lf\n%lf\n%lf\n", p1, p2, p3, pmax);

  return 0;
}


Measured memory_bytes: 3336
#include <stdio.h>
#include <iostream>
#include <stdlib.h>


#define MAX 105

using namespace std;
int L[MAX];

int main(void) {
	int N = 0;
	cin >> N;
	int data;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		//p.push_back(data);
	}
	int count = 0;
	int i, j, k, L_i, L_j, L_k;
	for (i = 0; i < N - 2; i++) {
		L_i = L[i];
		for (j = i + 1; j < N - 1; j++) {
			L_j = L[j];
			for (k = j + 1; k < N; k++) {
				L_k = L[k];
				if (i < j && j < k && L_i != L_j && L_i != L_k && L_j != L_k) {
					//三角形の条件
					if ((L_i + L_j > L_k) && (L_i + L_k > L_j) && (L_k + L_j > L_i)) {
						count++;
					}
				}

			}
		}
	}
	cout << count << endl;

	


	return 0;
}



Measured memory_bytes: 3152