akhauriyash/Code-Regression huggingface dataset:
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


class WeightedUnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        set の最悪計算量は O(N) なので size 指定のほうが若干速い
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
            # 直近の親からの重み。root なら 0
            self._weights = [0 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}
            # 直近の親からの重み。root なら 0
            self._weights = {k: 0 for k in nodes}

    def unite(self, x, y, w):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :param w: x と y の重みの差; (重み y) - (重み x)
        :return:
        """
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return

        # rank が小さい方が下
        if self._ranks[rx] > self._ranks[ry]:
            # x が root
            self._parents[ry] = rx
            self._sizes[rx] += self._sizes[ry]
            # root 間の重みに変換
            self._weights[ry] = w + self._weights[x] - self._weights[y]
        else:
            # y が root
            self._parents[rx] = ry
            self._sizes[ry] += self._sizes[rx]
            # root 間の重みに変換
            self._weights[rx] = -w + self._weights[y] - self._weights[x]
            if self._ranks[rx] == self._ranks[ry]:
                self._ranks[ry] += 1

    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        root = self.find(self._parents[x])
        self._weights[x] += self._weights[self._parents[x]]
        self._parents[x] = root
        return root

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]

    def weight(self, x):
        """
        :param x:
        :return:
        """
        # 経路圧縮
        self.find(x)
        return self._weights[x]

    def diff(self, x, y):
        """
        (y の重み) - (x の重み)
        :param x:
        :param y:
        :return:
        """
        if self.find(x) == self.find(y):
            return self._weights[y] - self._weights[x]
        return float('inf')


N = int(input())
U, V, W = zip(*[list(map(int, input().split())) for _ in range(N - 1)])

uf = WeightedUnionFind(size=N + 1)
for u, v, w in zip(U, V, W):
    uf.unite(u, v, w)

for i in range(1, N + 1):
    if uf.diff(1, i) % 2 == 0:
        print('0')
    else:
        print('1')


Measured memory_bytes: 49092
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a.begin(), a.end());
    rep(i, n){
        if(b[i] == a[n - 1])cout << a[n - 2] << endl;
        else cout << a[n - 1] << endl;
    }
}


Measured memory_bytes: 3200
s = input() + "R"
v = [0 for i in range(len(s)-1)]

even = 0
odd = 0
lrpos = 0
lr = "R"

for i in range(len(s)):
    if lr != s[i]:
        if lr == "R":
            if even == odd:
                v[i-1] += even
                v[i] += odd
            else:
                v[i] += even
                v[i-1] += odd
        else:
            if even == odd:
                v[lrpos] += even
                v[lrpos-1] += odd
            else:
                v[lrpos-1] += even
                v[lrpos] += odd
        
        odd = 0
        even = 0
        lr = s[i]
        lrpos = i

    if even < odd:
        even += 1
    else:
        odd += 1
    
ans = " ".join(map(str,v))
print(ans)


Measured memory_bytes: 10492
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scn = new Scanner(System.in);
    String ans = "";
    String str = scn.next();
    char []c_str = str.toCharArray();
    for(int i = 0; i < 3; i++){
      ans += c_str[i];
    }
    System.out.print(ans);
  }
}

Measured memory_bytes: 39088
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>

#define INFTY 1<<28
#define INV (-1)

using namespace std;

/*
	ñªTõÖ
	©Â©çÈ¢êA»êÉÅàß¢Å¬ÌlðÂvfðÔ·B
*/
int BinSearch(int a[], int asize, int search, bool &bFound){
	int l = 0;
	int r = asize - 1;
	int m = 0;

	if( asize == 0 ){
		bFound = false;
		return 0;
	}
	if( search < a[l] ){
		bFound = false;
		return 0;
	}
	if( a[l] == search ){
		bFound = true;
		return 0;
	}
	if( a[r] == search )
	{
		bFound = true;
		return r;
	}
	if( a[r] < search ){
		bFound = false;
		return r;
	}
	if( asize == 2 ){
		bFound = false;
		return 0;
	}

	while( true ){
		m = (r + l)/2;

		if( a[m-1] < search && search < a[m] ){
			bFound = false;
			return m - 1;
		}else if( a[m] < search && search < a[m+1] ){
			bFound = false;
			return m;
		}else if( a[m] == search ){
			bFound = true;
			return m;
		}else if( search < a[m] ){
			r = m;
		}else{
			l = m;
		}
	}
}

inline int dist(int from, int to, int D){
	int ret = abs(to - from);
	if( ret >= (double)D/2 ){
		ret = D - ret;
	}
	return ret;
}

int main()
{
	while( true )
	{

		int ans = 0;
		int d,n,m;
		int store[100003];
		
		cin >> d;

		if( d == 0 )
			break;

		cin >> n >> m;

		for(int i = 0; i < n - 1; ++i){
			cin >> store[i];
		}
		store[n-1] = 0;
		store[n] = d;
		sort( store, store + n + 1 );

		for(int i = 0; i < m; ++i){
			int t;
			bool tb;
			cin >> t;

			int td = BinSearch( store, n + 1, t, tb );
			if( dist(store[td],t,d) == 0 ){
				continue;
			}else if( td+1 <= n ){
				ans += min(dist(store[td+1],t,d),dist(store[td],t,d));
			}else{
				ans += dist(store[td],t,d);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;

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

	vector<P> ds;
	rep(i, n)
	{
		P d;
		cin >> d.first >> d.second;
		ds.push_back(d);
	}

	const int N_MAX = 3001;
	const int T_MAX = 3000;
	
	//dp1[i+1][j] := 0からi番目の料理でj分以内に完食できる美味しさの合計の最大値
	vector<vector<int>> dp1(N_MAX, vector<int>(T_MAX, 0));

	//dp2[i][j] := i～N-1 番目の料理でj分以内に完食できる美味しさの合計の最大値
	vector<vector<int>> dp2(N_MAX, vector<int>(T_MAX, 0));
	
	rep(i, n)
	{
		P d = ds[i];

		rep(j, t)
		{
			if (j < d.first)
			{
				dp1[i + 1][j] = dp1[i][j];
			}
			else
			{
				if (dp1[i][j] < dp1[i][j - d.first] + d.second)
				{
					dp1[i + 1][j] = dp1[i][j - d.first] + d.second;
				}
				else
				{
					dp1[i + 1][j] = dp1[i][j];
				}
			}
		}
	}

	for(int i = n - 1;i>=0;i--)
	{
		P d = ds[i];

		rep(j, t)
		{
			if (j < d.first)
			{
				dp2[i][j] = dp2[i + 1][j];
			}
			else
			{
				if (dp2[i + 1][j] < dp2[i + 1][j - d.first] + d.second)
				{
					dp2[i][j] = dp2[i + 1][j - d.first] + d.second;
				}
				else
				{
					dp2[i][j] = dp2[i + 1][j];
				}
			}
		}
	}


	int answer = 0;

	rep(i, n)
	{
		int tmp1 = 0;
		rep(j, t)
		{
			int tmp2;

			//i番目の料理以外でdp
			if (i == 0)
			{
				tmp2 = dp2[1][j];
			}
			else if (i == n - 1)
			{
				tmp2 = dp1[n - 1][j];
			}
			else
			{
				//t-1分以内に料理を食べきる。
				//最初にj分使って、あとからt - 1 - j分使う。
				tmp2 = dp1[i][j] + dp2[i + 1][t - 1 - j];
			}

			tmp1 = max(tmp2, tmp1);
		}

		tmp1 += ds[i].second;

		answer = max(tmp1, answer);
	}

	cout << answer << endl;


	return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
    using namespace std;
    # define LL long long
    # define int long long
    #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    # define mo 998244353
    # define pi acos(-1)
    //vector<pair<int,int>> v;
    //int x0=INT_MAX,y0=INT_MAX;
    /*int crossprod(pair<int,int> a,pair<int,int> b,pair<int,int> c)
    {
        int x1 = a.first-b.first;
        int x2 = a.first-c.first;
        int y1 = a.second-b.second;
        int y2 = a.second-c.second;
        return x1*y2 - y1*x2;
    }
    int direction(pair<int,int> a,pair<int,int> b,pair<int,int> c) {
       int val = (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
       if (val == 0)
          return 0;     //colinear
       else if(val < 0)
          return 2;    //anti-clockwise direction
          return 1;    //clockwise direction
    }*/
   map<int,int> mp,fr;
    signed main(){
        gok

     int n;
     cin>>n;
     int a[n];
     int st=-1;
     for(int i=0;i<n;i++){
        cin>>a[i];
        if(st==-1)
            st=a[i];
      fr[a[i]]++;
     }
     fr[st]--;
     int an=0;

     for(int i=1;i<=n;i++)
     {
         an += (fr[i]*(fr[i]-1))/2;
     }

     for(int i=0;i<n;i++)
     {
         if(a[i]!=st){
         int tt = an + fr[st];
         if(fr[a[i]]>0)
         {
             tt -= (fr[a[i]]-1);
         }
         cout<<tt<<endl;
         }
         else
            cout<<an<<endl;
     }

















        return 0;
    }


Measured memory_bytes: 16640
//                                  _                 ______   ______   ______   ______
//                                 | |               |  __  | |  __  | |  __  | |____  |
//    __ _   ____    _____    _  _ | |____           | |__| | | |__| | | |__| |      | |
//  / _` | |  __| /  __  |  / _` | |  __  |          |____  | |____  | |____  |      | |
// | (_| | | |    | |  | | | (_| | | |__| |  ______   ____| |  ____| |  ____| |      | |
//  \__,_| |_|    |_|  |_|  \__,_| |______| |______| |______| |______| |______|      |_|

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'
#define REP(i, n) for(int i=0; i<n; i++)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

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

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  while(n){
    if(n % 10 == 7){
        cout<<"Yes\n";
        break;
    }
    n /= 10;
  }
  if(n == 0)
    cout<<"No\n";

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main()
{
	int n, r, p, q, i, j, k, a[50], b[50], c[50];
	while (cin >> n >> r)
	{
		if (n == 0 && r == 0) break;
		for (i = n; i >= 1; i--)
			a[n-i] = i;
		for (i = 0; i < r; i++)
		{
			cin >> p >> q;
			for (j = 0; j < p-1; j++)
				b[j] = a[j];
			for (j = 0; j < q; j++)
				c[j] = a[p+j-1];
			for (j = 0; j < q; j++)
				a[j] = c[j];
			for (j = 0; j < p-1; j++)
				a[q+j] = b[j];
		}
		cout << a[0] << endl;
	}
}

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

int main(){
  int N,suma=0,sumb=0,sum;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0;i<N;i+=2){
    suma+=vec.at(i);
  }
  for(int i=1;i<N;i+=2){
      sumb+=vec.at(i);
  }
  sum = suma - sumb;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main(){
	double w,h,x,y; cin >> w >> h >> x >> y;

	if(x == w/2 && y == h/2) cout << setprecision(11) << w*h/2 << " " << 1 << endl;
	else cout << setprecision(11) << w*h/2 << " " << 0 << endl;
}

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

int main() {
    ll N;
    cin >> N;
    typedef tuple<ll, string, ll> t;
    vector<t> r(N);
    ll p;
    string s;
    rep(i, N) {
        cin >> s >> p;
        r[i] = make_tuple(i + 1, s, p);
    }
    stable_sort(r.begin(), r.end(),
                [](const t& l, const t& r) { return get<2>(l) > get<2>(r); });
    stable_sort(r.begin(), r.end(),
                [](const t& l, const t& r) { return get<1>(l) < get<1>(r); });
    rep(i, N) cout << get<0>(r[i]) << "\n";
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
puts s=9394,
a=?+,0,1,m=9,?<,2,9,3,
[a,3,0,9]+(s=0..59).map{[a,u=4,u,u,a,3,u,6,[a,6,6,6]*(59-_1),?<,6,9,m+=1,a,u,m,u]},
[a,3,1,9]+(s=0..59).map{[a,u=5,u,u,a,3,u,6,[a,6,6,6]*(59-_1),?<,6,9,m+=1,a,u,m,u]},
s.map{|_|[a,2,2,2]+(1.._).map{[a,40+_-_1,99+_1,5,?<,3,5,5,a,2,5,2]}}

Measured memory_bytes: 14896
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main()
{
    string s;
    cin >> s;
    ll n=s.length();
    vector<vector<ll>> dp(n+1,vector<ll>(2));
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        {//a+b=0
            if(s[i]=='1'){
                dp[i+1][1]=dp[i][1]+dp[i][0];
            }
            else{
                dp[i+1][1]=dp[i][1];
                dp[i+1][0]=dp[i][0];
            }
        }
        {//a+b=1
            if(s[i]=='1'){
                dp[i+1][1]+=(dp[i][1]*2)%mod;
                dp[i+1][1]%=mod;
                dp[i+1][0]+=(dp[i][0]*2)%mod;
                dp[i+1][0]%=mod;
            }
            else{
                dp[i+1][1]+=(dp[i][1]*2)%mod;
                dp[i+1][1]%=mod;
            }
        }
    }
    ll ans=(dp[n][1]+dp[n][0])%mod;
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 5760
// 2020/07/20 Tazoe

#include <iostream>
using namespace std;

// フィボナッチ数
int fib(int n)
{
	if(n==0 || n==1)
		return 1;

	return fib(n-1)+fib(n-2);
}


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

	int x_min = 0;
	int x_max = 1;
	int y_min = 0;
	int y_max = 1;
	int c = 0;

	while(true){
		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 東
		c++;
		x_min = x_max;
		x_max = x_min+fib(c);
		y_min = y_min;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 北
		c++;
		x_max = x_max;
		x_min = x_max-fib(c);
		y_min = y_max;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 西
		c++;
		x_max = x_min;
		x_min = x_max-fib(c);
		y_max = y_max;
		y_min = y_max-fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 南
		c++;
		x_min = x_min;
		x_max = x_min+fib(c);
		y_max = y_min;
		y_min = y_max-fib(c);
	}

	return 0;
}



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

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

    int n;
    cin >> n;
    ll sum=0,i=1;
    while (i<=n && sum <= LLONG_MAX){
        if(i%3!=0 && i%5!=0) {sum+=i;}
        i++;
    }
    cout << sum;

	return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
namespace io
{
	const int N=1<<20;
	char buf[N],*t1=buf,*t2=buf;
	#ifdef cjy
	#define getc() getchar()
	#else
	#define getc() t1==t2&&(t2=(t1=buf)+fread(buf,1,N,stdin),t1==t2)?EOF:*t1++
	#endif
	inline int read()
	{
		static int an,f;an=0,f=1;
		static char ch;ch=getc();
		while(ch<48||ch>57)ch=='-'?f=-1:0,ch=getc();
		while(ch>=48&&ch<=57)an=(an<<3)+(an<<1)+(ch^48),ch=getc();
		return an*f;
	}
	char buff[N],*T=buff;
	void flush(){fwrite(buff,1,T-buff,stdout);T=buff;}
	inline void putc(char ch){if(T==buff+N)flush();*T++=ch;}
	template<typename o>
	inline void print(o x)
	{
		if(x<0)putc('-'),x=-x;
		if(!x)return putc('0'),void();
		static int st[20],tp;
		while(x)st[++tp]=x%10,x/=10;
		while(tp)putc(st[tp]^48),--tp;
	}
}
using io::read;
using io::putc;
using io::flush;
using io::print;
struct edge
{
	int nxt,to;
}e[100010];
int n,h,head[500],num,dg[500];
inline void add(int from,int to){e[++num]=edge{head[from],to};head[from]=num;++dg[from],--dg[to];}
bool vis[500];
int main()
{
	n=read(),h=read();
	for(int i=1,a,b,c,d,x,y;i<=n;++i)
	{
		a=read(),b=read(),c=read(),d=read();
		if(c==0)x=a;
		else x=c+h;
		if(d==0)y=b+h;
		else y=d;
		add(x,y);
	}
	for(int i=1;i<=h;++i)if(dg[i]<0)return printf("NO"),0;
	for(int i=h+1;i<=2*h;++i)if(dg[i]>0)return printf("NO"),0;
	queue<int>q;
	for(int i=1;i<=h;++i)if(dg[i]>0)q.push(i);
	int cnt=0;
	while(!q.empty())
	{
		int x=q.front();q.pop();
	//	printf("%d\n",x);
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x],y;i;i=e[i].nxt)y=e[i].to,++cnt,q.push(y);
	}
	if(cnt==n)printf("YES");
	else printf("NO");
	flush();
	return 0;
}

Measured memory_bytes: 5280
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
ll N,K;
vector<ll> v;
string solve(){
  string yes = "POSSIBLE", no = "IMPOSSIBLE";
  sort(all(v));
  if(v.back()<K) return no;
  ll G = 0;
  rep(i,0,N){
    G = gcd(G, v[i]);
  }
  if(K%G==0) return yes;
  else return no;
}
int main(){
  cin>>N>>K;
  v.resize(N);
  rep(i,0,N) cin>>v[i];
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>


using namespace std;

int main(int argc, char const *argv[])
{

    int N;
    string S, T;

    cin >> N >> S >> T;

    for (int i = 0; i < N; i++)
    {
        cout << S[i] << T[i];
    }

    cout << endl;

    return 0;
}


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

#define INF 0x3f3f3f3f
#define N 100010
int n, m, s, t;
vector <vector<int>> G;
struct node {
	int u, w;
	node() {}
	node (int u, int w) : u(u), w(w) {}
	bool operator < (const node &other) const {
		return w > other.w;
	}
};

int dis[N][3], used[N][3];
void BFS() {
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 3; ++j) {
			dis[i][j] = INF;
			used[i][j] = 0;		
		}
	}
	dis[s][0] = 0;	
	priority_queue <node> pq;
	pq.push(node(s, 0)); 
	while (!pq.empty()) {
		int u = pq.top().u, w = pq.top().w; pq.pop(); 
		if (used[u][w % 3]) continue;
		used[u][w % 3] = 1;
		for (auto v : G[u]) {
			if (dis[v][(w + 1) % 3] > w + 1) {
				dis[v][(w + 1) % 3] = w + 1;  
				pq.push(node(v, w + 1));  
			}
		}
	}
}

int main() {
	while (scanf("%d%d", &n, &m) != EOF) {
		G.clear(); G.resize(n + 1);
		for (int i = 1, u, v; i <= m; ++i) {
			scanf("%d%d", &u, &v);
			G[u].push_back(v);
		}
		scanf("%d%d", &s, &t);
		BFS();
		if (dis[t][0] == INF) puts("-1");
		else {
			printf("%d\n", dis[t][0] / 3);
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	string t;
	t.push_back(s[0]+1);
	cout << t << endl;

}


Measured memory_bytes: 256
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(std::string S, std::string T, long long A, long long B, std::string U) {
  if (U == S) {
    --A;
  } else {
    --B;
  }
  ANS(A << " " << B);
}

// clang-format off
int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  std::string U;
  std::cin >> U;
  solve(S, T, A, B, U);
  return 0;
}


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

using namespace std;
const int maxn = 5e5+10;

const int logo = 23;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, q;
char niz[maxn];
int dp[maxn][30];
int ne[logo + 10][maxn];

int main() {
    scanf("%s%d", niz, &q);
    n = strlen(niz);

    for (int i = 0; i < 27; i++)
        dp[n][i] = n + 1, dp[n + 1][i] = n + 1;
    for (int i = 0; i <= logo; i++)
        ne[i][n] = n + 1, ne[i][n + 1] = n + 1;

    for (int i = n - 1; i >= 0; i--) {
        dp[i][niz[i] - 'a'] = i + 1;
        for (int j = niz[i] - 'a' + 1; j < 26; j++) {
            dp[i][j] = dp[dp[i][j - 1]][j - 1];
            //printf("dp[%d][%d] == %d\n", i, j, dp[i][j]);
        }

        ne[0][i] = dp[dp[i][25]][25];
        //printf("ne[%d][%d] == %d\n", 0, i, ne[0][i]);
        for (int j = 0; j < niz[i] - 'a'; j++)
            dp[i][j] = dp[ne[0][i]][j];
    }

    for (int i = 1; i <= logo; i++)
        for (int j = 0; j <= n; j++)
            ne[i][j] = ne[i - 1][ne[i - 1][j]];

    /**
    for (int i = 0; i <= logo; i++) {
        for (int j = 0; j <= n; j++) {
            printf("%d ", ne[i][j]);
        }
        printf("\n");
    }
    **/

    while (q--) {
        int a, b;
        scanf("%d%d", &a, &b); a--, b--;

        for (int i = logo; i >= 0; i--) {
            if (ne[i][a] <= b + 1) {
                //printf("pr: %d --> %d\n", a, ne[i][a]);
                a = ne[i][a];
            }
        }
        if (a == b + 1) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

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

    if(x <= 111){
        cout << 111;
    }else if(x <= 222){
        cout << 222;
    }else if(x <= 333){
        cout << 333;
    }else if(x <= 444){
        cout << 444;
    }else if(x <= 555){
        cout << 555;
    }else if(x <= 666){
        cout << 666;
    }else if(x <= 777){
        cout << 777;
    }else if(x <= 888){
        cout << 888;
    }else{
        cout << 999;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long mod = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

int main()
{
   ios::sync_with_stdio(false);
	cin.tie(0);
	long long n,m;
	cin>>n;
    m=ceil(sqrt(n)); if(m*m>n) m--;
    if(n!=m*m)
    {
        if((m+1)*(m+1)-n<=n-m*m){
			cout <<"1 "<<m+1<<" "<<m+1<<" "<<(m+1)*(m+1)-n<<" 0 0 "<< endl;
		} else {
			cout<<"1 0 "<<m+1<<" "<<n-m*m<<" 0 "<<m<< endl;
		}
    }
    else
    {
        cout <<"0 0 "<<m<<" 0 0 "<<m<< endl;

    }

	//cout<<311114770564041497/2<<endl;
	return 0;
}/*
	long long a=0,b=0;
	for(int i=1e9;i>=1;i--)
    {

        if(n%i==0)
        {
            a = i; b=n/i; break;

        }
    }
    cout<<"0 0 0 "<<a<<" "<<b<<" "<<"0"<<endl;
}
*/


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

int main(){

    int n,tem,x;
    cin >> n;
    vector<int> sort(n);
    for(int i = 0; i< n; i++){
        cin >> sort.at(i);
    }
    for (int z = 0; z < n-1; z++){
        cout << sort.at(z) << ' ';
    }
    cout << sort.at(n-1) <<endl;

    for(int i = 1; i < n; i++){
        tem = sort.at(i);
        x = i-1;
        while(x >= 0 && sort.at(x) >= tem){
            sort.at(x+1) = sort.at(x);
            x--;
        }
        sort.at(x+1) = tem;
        
        for (int z = 0; z < n-1; z++){
            cout << sort.at(z) << ' ';
        }
        cout << sort.at(n-1) <<endl;
    }
}


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

int main(){
	while(1){
		string str;
		cin >> str;
		if(str=="0") break;
		
		int n = str.length();
		vector<int> a(n);
		for(int i=0; i<n; i++){
			a[i] = str[i]-'0';
			if(i%2!=0) a[i] = (11-a[i])%11;
		}
		
		vector<int> num(11, 0);
		vector<int> sum(n);
		sum[0] = a[0];
		num[a[0]]++;
		for(int i=1; i<n; i++){
			sum[i] = (sum[i-1]+a[i])%11;
			num[sum[i]]++;
		}
		
		int ans = num[0];
		for(int i=0; i<n-1; i++){
			num[sum[i]]--;
			if(a[i+1]!=0) ans += num[sum[i]];
		}
		cout << ans << endl;
	}
	return 0;
}

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 1e6 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n;
int f[N];
int a[N], d[N];
void upd (int pos, int x) {
	for (int i = pos; i <= n; i = (i | (i + 1)))
		f[i] += x;
}

int get (int r) {
	int res = 0;
	while (r >= 0) {
		res += f[r];
		r = (r & (r + 1)) - 1;
	}
	return res;
}
int main () {
	cin >> n;
	ll sum = 0, ans = 0;
	map < ll, ll > x;
	x[sum] = 1;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		sum += a[i];
		ans += x[sum] ++;
	}
	cout << ans;
}

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

long long A,B;

long long XOR(long long x)
{
	if(x % 4 == 0) return x;
		else if(x % 4 == 1) return 1;
		else if(x % 4 == 2) return x+1;
		else return 0;
}

int main()
{
	cin >> A >> B;
	cout << (XOR(A-1)^XOR(B)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main (){ 
    int N, Z, W; cin >> N >> Z >> W;
	vector<int> a(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	if(N == 1) cout << abs(a[0] - W) << endl;
	else cout << max(abs(a[N - 1] - a[N - 2]), abs(a[N - 1] - W)) << endl;


    
}
    

 


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

int main() {
	string s,t;cin>>s>>t;
	vector<int> v(26,1),v2(26,1);
	for(int i=0;i<s.size();i++){
		if(v[s[i]-'a']==0)continue;
		v[s[i]-'a']=0;
		if(v2[t[i]-'a']){
			v2[t[i]-'a']=0;
		}else{
			cout<<"No"<<endl;
			return 0;
		}
		for(int j=i+1;j<s.size();j++){
			if(s[i]!=s[j])continue;
			if(t[i]==t[j])continue;
			cout<<"No"<<endl;
			return 0;
		}
//		for(int j=i+1;j<s.size();j++){
//			if(t[i]!=t[j])continue;
//			v2[]
//		}


	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi l(n); rep(i, n) cin >> l[i];
  sort(all(l));

  int ans = 0;
  for (int a = 0; a < n-2; a++) {
    int right = a+2;
    for (int left = a+1; left < n-1; left++) {
      while(right < n && l[right] - l[left] < l[a]){
        right++;
      }
      right--;
      if(l[right] - l[left] < l[a]) ans += right - left;
      //printf("a: %d, l[%d] = %d, l[%d] = %d\n",a, right, l[right], left, l[left] );
      if(right == left) right++;
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
n=int(input())
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))

sum = 0
last_num = 0
for i in range(n):
  sum += li2[li1[i]-1]
  now = li1[i]
  if last_num != 0:
    if now - last_num == 1:
      sum+=li3[li1[i-1]-1]
  last_num = li1[i]
print(sum)

Measured memory_bytes: 38460
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;
void solve(void)
{
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.length()) mp[s[i]]++;
    cout << mp['+'] - mp['-'] << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3596
N, K = input().split()
n = int(N)
k = int(K)

t = n

if n % k == 0:
  print(0)
else:
  if n < k:
    a = abs(n - k)
    b = abs(a-k)
    if a < b:
      print(a)
    else:
      print(b)
  else:
  	x = n % k
  	print(k - x)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }


int main(void){
  int a, b;cin >> a >> b;
  if(a<=5) cout << 0 << endl;
  else if(a<=12) cout << b/2 << endl;
  else cout << b << endl;

  return 0;
}


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

int dp[100010][3];

int main()
{
    int n; cin >> n;
    for (int i = 0; i < 3; i++) dp[0][i] = 0;
    for (int i = 0; i < n; i++) {
        int in[3]; cin >> in[0] >> in[1] >> in[2];
        for (int j = 0; j < 3; j++) {
            dp[i + 1][j] = max(dp[i][(j+1)%3], dp[i][(j+2)%3]) + in[j];
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
    return 0;
}

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

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

    if ((1000 - n % 1000) == 1000)
        printf("0");
    else
        printf("%d", (1000 - n % 1000));
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  int ans = 0;
  rep(i,l/2) {
    if(s[i] != s[l-1-i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def read():
    N = int(input())
    As = list(map(int, input().split(' ')))
    return N, As

def fun(N, As):
    stocks = 0
    money = 1000
    prev = 201
    for n in range(N):
        curr = As[n]
        if n < N - 1:
            nex = As[n + 1]
        else:
            nex = 99
        if curr >= prev and curr >= nex:
            # 局所最大なら全部売る
            money += curr * stocks
            stocks = 0
        elif curr <= prev and curr <= nex:
            # 局所最小なら全部買う
            stocks += int(money / curr)
            money -= curr * int(money / curr)
        prev = curr
    return money

if __name__ == '__main__':
    N, As = read()
    print(fun(N, As))


Measured memory_bytes: 61860
n = int(input())

a = [0] * n

a = list(map(int, input().split()))

last = 0
cnt = 1
increase_flag = None
first_flag = True
for i in range(len(a) - 1):
    if a[i] < a[i + 1]:
        if (increase_flag is None):
            increase_flag = True
        elif not (increase_flag):
            cnt += 1
            increase_flag = None
        else:
            continue
    elif a[i] > a[i + 1]:
        if (increase_flag is None):
            increase_flag = False
        elif not (increase_flag):
            continue
        else:
            cnt += 1
            increase_flag = None

print(cnt)


Measured memory_bytes: 15020
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    if(s=="RRR")cout<<3<<endl;
    else if(s=="RRS"||s=="SRR")cout<<2<<endl;
    else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR")cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
int a[300005],b[300005];
int main()
{
    char c[300005];

    int k;
    scanf("%d",&k);
    scanf("%s",c);
    for (int i=0;i<k;i++) { a[i]=0; b[i]=0; }
    if (c[0]=='W') a[0]=1;
    if (c[k-1]=='E') b[k-1]=1;
    for(int i=1;i<k;i++) if (c[i]=='W') a[i]=a[i-1]+1; else a[i]=a[i-1];
    for(int i=k-2;i>=0;i--) if (c[i]=='E') b[i]=b[i+1]+1; else b[i]=b[i+1];
    int maxn=min(a[k-2],b[1]);
    for (int i=1;i<k-1;i++) maxn=min(maxn,a[i-1]+b[i+1]);
    printf("%d\n",maxn);
    return 0;
}


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


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

    sort(d.begin(), d.end());

    for(int i = 0; i < N - 1; i++){
        d[i + 1] = (d[i] + d[i + 1]) / 2;
    }

    cout << d[N - 1] << endl;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll x;
    ll k;
    ll d;
    cin >> x >> k >> d;
    //往復できないなら
    ll absx = abs(x);
    //ofするなら絶対往復できる
        if(k > LLONG_MAX/d){

        }else{
            if(k*d < absx){
                cout << absx-(k*d) << endl;
                return 0;
            }
        }

    //往復できるなら
    ll ans=0;

    ll mod = x %d;
    ll tmpa = x-mod;
    ll tmpb = tmpa / d;
    ll tmpbb = abs(tmpb);

    //cout << mod << " " << tmpa << " " << tmpb << " " << tmpbb << endl;

    if(tmpbb%2 == k%2 ){
        ans = abs(mod);
    }else{
        if(mod <0){
            ans = abs(mod+d);
        }else{
            ans = abs(mod-d);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

string s;
ll k;
int main(){
	cin>>s;
	cin>>k;
	int c1=0;
	string ans;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1'){
			c1++;
		}else{
			ans=s[i];
			break;
		}
	}
	if(c1>=k){
		cout<<1<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))

ans=10**9
for i in range(n-k+1):
    xl=x[i]
    xr=x[i+k-1]
    ans=min(ans,abs(xl)+xr-xl,abs(xr)+xr-xl)
print(ans)

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

const int maxn = 2e5 + 20;

int n, m, k;
int a[maxn], b[maxn];
long long sa[maxn], sb[maxn];
int ans;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
	for(int i = 1; i <= n; i++) sa[i] = sa[i - 1] + a[i];
	for(int i = 1; i <= m; i++) sb[i] = sb[i - 1] + b[i];
	for(int i = 0; i <= n; i++) {
		int j = std::upper_bound(sb, sb + m + 1, k - sa[i]) - sb;
		if(j > 0) {
			ans = std::max(ans, j - 1 + i);
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 8516
# 3文字中2文字が同じであれば条件を満たす
import sys
readline = sys.stdin.readline

S = readline().rstrip()
if len(S) == 2:
  if S[0] == S[1]:
    print(1,2)
  else:
    print(-1,-1)
  exit(0)

for i in range(len(S) - 3):
  if len(set(S[i:i + 3])) < 3:
    print(i + 1, i + 3)
    exit(0)
else:
  print(-1,-1)


Measured memory_bytes: 3188
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toLong() }

    val a4 = mutableListOf<Long>()
    val a2 = mutableListOf<Long>()
    val a = mutableListOf<Long>()

    aa.forEach {
        if (it % 4 == 0L) {
            a4.add(it)
        } else if (it % 2 == 0L) {
            a2.add(it)
        } else {
            a.add(it)
        }
    }

    if (a.size + (if (a2.size > 0) 1 else 0) <= a4.size + 1) {
        println("Yes")
    } else {
        println("No")
    }
}



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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

const int N = 1e5 + 10;
map<pair<pii,pii>, bool> dp;
int d[N];
int n;
string res = "";
bool solve(int i, int a, int b, int c) {
    if(a < 0 || b < 0 || c < 0) return 0;
    if(i == n) {
        return 1;
    }
    bool ans = 0;
    if(dp.count({{i, a}, {b, c}})) {
        return 0;
    }
    dp[{{i, a}, {b, c}}] = 1;
    if(d[i] == 1) {
        ans |= solve(i + 1, a - 1, b + 1, c);
        if(ans) {
            res += 'B';
            return 1;
        }
        ans |= solve(i + 1, a + 1, b - 1, c);
        if(ans) {
            res += 'A';
            return 1;
        }
    }
    else if(d[i] == 2) {
        ans |= solve(i + 1, a, b - 1, c + 1);
        if(ans) {
            res += 'C';
            return 1;
        }
        ans |= solve(i + 1, a, b + 1, c - 1);
        if(ans) {
            res += 'B';
            return 1;
        }
    }
    else if(d[i] == 3){
        ans |= solve(i + 1, a - 1, b, c + 1);
        if(ans) {
            res += 'C';
            return 1;
        }
        ans |= solve(i + 1, a + 1, b, c - 1);
        if(ans) {
            res += 'A';
            return 1;
        }
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = 0; i < n; i++) {
        string s; cin >> s;
        if(s == "AB") {
            d[i] = 1;
        }
        else if(s == "BC") {
            d[i] = 2;
        }
        else d[i] = 3;
    }
    bool aa = solve(0, a, b, c);
    if(aa) {
        cout << "Yes\n";
        reverse(res.begin(), res.end());
        for(auto x: res) {
            cout << x << endl;
        }
    }
    else {
        cout << "No";
        return 0;
    }

    return 0;
}



Measured memory_bytes: 20844