akhauriyash/Code-Regression huggingface dataset:
import sys
from itertools import accumulate
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *A = map(int, read().split())

    B = [0]
    B.extend(accumulate(A))
    B = [b % M for b in B]

    counter = Counter(B)
    ans = 0
    for v in counter.values():
        ans += v * (v - 1) // 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 23948
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

ll gcd(ll x, ll y){
    if (y==0) return x;
    else return gcd(y, x%y);
}

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> lgcd(N), rgcd(N);
    lgcd[0] = A[0];
    for(int i = 1; i < N; i++){
        lgcd[i] = gcd(lgcd[i-1], A[i]);
    }
    rgcd[N-1] = A[N-1];
    for(int i = N-2; i >= 0; i--){
        rgcd[i] = gcd(rgcd[i+1], A[i]);
    }

    ll ans = 0;
    rep(i,N){
        if(i == 0) ans = max(ans, rgcd[1]);
        else if (i == N-1) ans = max(ans, lgcd[N-2]);
        else ans = max(ans, gcd(lgcd[i-1], rgcd[i+1]));
    }

    cout << ans << endl;
    
}



Measured memory_bytes: 5548
#include <stdio.h>

using namespace std;

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

	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
	printf("%d\n",A[0]);
}



Measured memory_bytes: 2700
# -*- coding: utf-8 -*-
# B

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N= int(input())
A = list(map(int, input().split()))
A.sort()

ans = 1
for a in A:
    ans *= a
    if a == 0:
        print(0)
        sys.exit()
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)


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

using namespace std;

int main(){
  int k;
  cin>>k;
  
  int count=0;
  
  int curr = 7 % k;
  set<int> st;
  st.insert(curr);
  while(curr){
    curr*=10;
    curr+=7;
    curr%=k;
    if(st.find(curr) != st.end()){
      cout<<-1<<endl;
      return 0;
    }
    count++;
    st.insert(curr);
  }
  count++;
  cout<<count<<endl;
  return 0;
}

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

int main(){

    int N;
    cin >> N;

    int64_t temp;
    map<int64_t, int64_t> count;

    for (int i=0; i<N; i++){
        cin >> temp;
        count[temp]++;
    }

    int flg = 0;
    for (auto p: count){
        if (p.second > 1){
            flg = 1;
        }
    }

    if (flg == 1){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

struct edge{int to, cost;};
vector<edge> G[100000];

signed main(){ INIT;
    VAR(int, a, b, c, x);
    int cnt = 0;
    REP(i, a+1) REP(j , b+1) REP(k, c+1){
        if(500 * i + 100 * j + 50 * k == x) cnt++;
    }
    OUT(cnt);
RET;}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b){
    for(long long k=0;k<N;k++){
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(A[i][j] == b[k]){
                    A[i][j] = 0;
                }
            }
        }
    }
    string ans = "No";
    for(int i=0;i<3;i++){
        if(A[i][0] + A[i][1] + A[i][2] == 0){
            ans = "Yes";
        }
        if(A[0][i] +A[1][i] + A[2][i] == 0){
            ans = "Yes";
        }
    }
    if(A[0][0] + A[1][1] + A[2][2] == 0){
        ans = "Yes";
    }
    if(A[0][2] + A[1][1] + A[2][0] == 0){
        ans = "Yes";
    }
    cout << ans << endl;


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(std::move(A), N, std::move(b));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n,m;cin>>n>>m;
    ll a[n];
    priority_queue<ll> q;
    rep(i,0,n-1){
        cin>>a[i];
        q.push(a[i]);
    }
    ll c;
    rep(i,0,m-1){
        c=q.top();
        c=c/2;
        q.pop();
        q.push(c);
    }
    ll ans=0;
    rep(i,0,n-1){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> 
using namespace boost::multiprecision; 
using namespace std;

#define ull long long
#define ar array



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

	int128_t x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	if((x-k*d) >= 0) cout << x-k*d << "\n";
	else{
		int128_t val = x - (x/d)*d;
		int128_t rem = k - x/d;
		if(rem&1^1) {
			cout << val << "\n";
		}
		else {
			int128_t abss = abs(val-d);
			int128_t mini = min(abss,(val+d));
			cout << mini << "\n";
		}
	}	
	return 0;
}


Measured memory_bytes: 3680
// C - Exam and Wizard

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[100000];
int B[100000];

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

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

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

	ll S = 0; // 不足分の合計
	int cntS = 0; // 不足するAの数
	vector<int> E; // 超過
	for (int i=0; i<N; i++) {
		if (A[i] < B[i]) {
			S += B[i] - A[i];
			cntS++;
		}

		if (A[i] > B[i]) {
			E.push_back(A[i] - B[i]);
		}
	}

	sort(E.begin(), E.end(), greater<int>());

	ll cntE = 0; // 補正に必要な、超過しているAの数
	for (int e : E) {
		if (S <= 0) break;
		S -= e;
		cntE++;
	}

	int ans;
	if (S > 0) ans = -1;
	else ans = cntS + cntE;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4488
#include "stdio.h"
#include "string.h"

int main() {
  char s[200000];
  scanf("%s", s);
  int n= strlen(s);

  int a=200000;
  int b=0;
  for(int i=0; i<n; i++){
    if(s[i]=='A') {
      if(a>i) a = i;
    }
    else if(s[i]=='Z'){
      b = i;
    }
  }

  printf("%d", b-a+1);

  return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"strings"
)

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

	ans := make([]int, n)
	for i := 0; i < n;i++ {
		var a int
		fmt.Scan(&a)
		ans[a-1] = i+1
	}
	fmt.Println(strings.Join(arrayIntToArrayString(ans), " "))
}

func arrayIntToArrayString(arr []int) (r []string) {
	for _, v := range arr {
		r = append(r, fmt.Sprintf("%d",v ))
	}
	return
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1)
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX             100005
#define MOD             1000000007

typedef long long ll;

int main()
{
    FastRead

    ll k,n,sum=0;

    cin>>k>>n;

    vector<ll>v(n),dif;

    for(auto &it : v)
        cin>>it;

    for(ll i=1;i<n;i++)
        dif.push_back(v[i]-v[i-1]);

    dif.push_back((k-v.back())+v.front());

    sort(dif.begin(),dif.end(),greater<ll>());

    for(ll i=1;i<dif.size();i++)
        sum+=dif[i];

    cout<<sum;
}


Measured memory_bytes: 3956
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Small and Large Integers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, k;
  scanf("%d%d%d", &a, &b, &k);

  int c = a + (k - 1), d = b - (k - 1);
  if (c >= d)
    for (int i = a; i <= b; i++) printf("%d\n", i);
  else {
    for (int i = a; i <= c; i++) printf("%d\n", i);
    for (int i = d; i <= b; i++) printf("%d\n", i);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
   ll n;
   cin>>n;
   string s;
   cin>>s;
   int w=0,r=0;
   int pre[n];
   pre[0]=0;
   for(int i=0;i<n;++i)
   {
       if(!i)pre[i]=(s[i]=='R');
       else pre[i]=pre[i-1]+(s[i]=='R');
       w+=s[i]=='W';
       r+=s[i]=='R';
   }
   ll ans=min({n,r,w});
   for(int i=0;i<n;++i)
   {
    //   deb((i+1-pre[i]))
       ans=min({ans,i+1-pre[i]+pre[n-1]-pre[i]-min(i+1-pre[i],pre[n-1]-pre[i])});
   }
   cout<<ans<<endl;
}

int32_t main()
{
	IOS
	ll T = 1;
// 	cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5332
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"

signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
 
    sort(a,a+n);
    
    maxx = 1e18;
    ans = 1;
    
    for(i=0;i<n;i++)
    {
        double tempp=0.0;
        temp = maxx/ans;
        if(a[i]>temp) 
        {
            ans=-1;
            break;
        }
        ans = ans * a[i];
        
        if(ans==0) break;
        
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	typedef pair<int,int> P;
	const int N=5009;
	int head[N],nex[N],to[N],cnt;
	inline void add(int u,int v){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v;
	}

	int fa[N][N],f[N][N],n,m;
	inline void dfs1(int u,int _f,int rt){
		fa[rt][u]=_f;
		for(int i=head[u];i;i=nex[i])
			if(to[i]^_f) dfs1(to[i],u,rt);
	}
	int ans=0;
	inline void dfs2(int u,int _f,int pre){
		if(f[pre][u]==u) ans++,pre=u;//,cout<<u<<endl;
		for(int i=head[u];i;i=nex[i]) if(to[i]^_f)
			dfs2(to[i],u,pre);
	}
	inline void addedge(int u,int v){
		if(f[u][v]==v || f[v][u]==u) return;
		if(f[u][v]!=u) return addedge(f[u][v],v);
		if(f[v][u]!=v) return addedge(u,f[v][u]);

		f[u][v]=v,f[v][u]=u;
		vector<P> ext;queue<int> q;
		
		q.push(v);
		while(!q.empty()){
			int _u=q.front();q.pop();
			for(int i=head[_u];i;i=nex[i]) if(to[i]^fa[u][_u]){
				if(f[u][to[i]]==u) f[u][to[i]]=v,q.push(to[i]);
				else ext.push_back(P(to[i],v));
			}
		}
		q.push(u);
		while(!q.empty()){
			int _u=q.front();q.pop();
			for(int i=head[_u];i;i=nex[i]) if(to[i]^fa[v][_u]){
				if(f[v][to[i]]==v) f[v][to[i]]=u,q.push(to[i]);
				else ext.push_back(P(to[i],u));
			}
		}

		for(int i=0;i<ext.size();i++) addedge(ext[i].first,ext[i].second);
	}
	int main(){
		n=read<int>(),m=read<int>();
		for(int i=1;i<n;i++){
			int u=read<int>(),v=read<int>();
			add(u,v),add(v,u);
		}
		for(int i=1;i<=n;i++) dfs1(i,0,i);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++) f[i][j]=i;
		for(int i=1;i<=m;i++){
			int u=read<int>(),v=read<int>();
			addedge(u,v);
		}
		for(int i=1;i<=n;i++) dfs2(i,0,i);
		printf("%d\n",(ans-n)>>1);
		return 0;
	}
}
int main(){
#ifdef my
	freopen("edges.in","r",stdin);
	freopen("edges.out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 51380
S = input()

n = 2**(len(S)-1)
ans = 0
for i in range(n):
  bs ="0" + format(i,"0{}b".format(len(S)-1))
  res = 0
  l = []
  for j in range(len(bs)):
    if bs[j] == "1":
      l.append(int(S[res:j]))
      res = j
  l.append(int(S[res:len(S)]))
  ans += sum(l)
print(ans)  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

bool triangle(int x, int y, int z) {
	if(x+y <= z || y+z <= x || x+z <= y) return false;
	return true;
}

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int n; cin >> n;
	vector<int> a(n);
	for(auto &x: a) cin >> x;

	int ans = 0;
	for(int i = 0 ; i < n ; i++) {
		for(int j = i+1 ; j < n ; j++) {
			for(int k = j+1 ; k < n ; k++) {
				if(triangle(a[i], a[j], a[k]) && a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
					++ans;
				}
			}
		}
	}		

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

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define mn 200005
#define inf 4444444444444444444
#define mod (ll) 1000000007
#define base 31
#define fi first
#define se second
#define pii pair <int, int>
#define pb push_back
#define mp make_pair

//int t, ntest;
int n, ans;
pii edge[mn];

void input(){
	cin>>n;
	for (int i=1; i<n; i++) {
		int x, y;
		cin>>x>>y;
		if (x>y) swap(x, y);
		edge[i]=mp(x, y);
	}
}

void solve(){
	for (int i=1; i<=n; i++) ans+=(i+1)*i/2;
	for (int i=1; i<n; i++){
		ans-=edge[i].fi*(n-edge[i].se+1);
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
//	cin>>t;
//	for (ntest=1; ntest<=t; ntest++){
		input();
		solve();
//	}
}

//By: 646487264





Measured memory_bytes: 6752
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,K;cin>>N>>K;
	vector<double> exp(N);
	rep(i,N){
		double t;
		cin>>t;
		exp[i] = t*(t+1)/2 /t;
	}
	double ans = 0;
	rep(i,N-1)exp[i+1] += exp[i];
	ans = exp[K-1];
	for(int i = K; i<N; ++i){
		ans = max(ans, exp[i]-exp[i-K]);
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}

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

bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
  return a.second < b.second;
}

int digit(int n){
  int i=0;
  while(n!=0){
    n/=10;
    i++;
  }
  return i;
}

int main(){
  int i,j,cnt=0;
  int n,m;
  cin>>n>>m;
  int p[m],y[m];
  for(i=0;i<m;i++)cin>>p[i]>>y[i];
  vector<pair<pair<int,int>,int>> v;
  for(i=0;i<m;i++){
    v.push_back(pair<pair<int,int>,int>(pair<int,int>(p[i],y[i]),i));
  }
  sort(v.begin(),v.end());
  v[0].first.second=1;
  cnt=2;
  for(i=1;i<m;i++){
    if(v[i].first.first!=v[i-1].first.first)cnt=1;
    v[i].first.second=cnt++;
  }
  sort(v.begin(),v.end(),cmp);
  for(i=0;i<m;i++){
    for(j=0;j<6-digit(v[i].first.first);j++){
      cout<<0;
    }
    cout<<v[i].first.first;
    for(j=0;j<6-digit(v[i].first.second);j++){
      cout<<0;
    }
    cout<<v[i].first.second<<endl;
  }
}

Measured memory_bytes: 3572
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String s = sc.next();
        int len = s.length();

        String ans = "Yes";

        for (int i = 1; i<=len; i++){
            if (i%2 == 0 && s.charAt(i-1) == 'R') {
                ans = "No";
                break;
            }
            else if (i%2 == 1 && s.charAt(i-1) == 'L'){
                ans = "No";
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35544
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,a[maxn];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	long long ans=0;
	if(a[1]!=0)return puts("-1"),0;
	for(int i=1;i<=n;++i){
		if(a[i]-a[i-1]>1)return puts("-1"),0;
		else if(a[i]-a[i-1]==1)++ans;
		else ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0;i < H;i++){
            for (int j = 0;j < W;j++){
                if (0 < j && j < W-1 && 0 < i && i < H-1) cout << ".";
                else cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
cin>>x>>y;
if(x==2){
    if(y==2)cout <<"Yes";
    else cout << "No";
}else if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
    cout <<"Yes";
    }else  cout << "No";
}else if(x==4||x==6||x==9||x==11){
    if(y==4||y==6||y==9||y==11){
    cout <<"Yes";
    }else cout << "No";
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <assert.h>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define each(i,n) for(auto &i : n)

#define int long long

signed main() {

	int n, k;
	cin >> n >> k;

	vector<int> a(n), sum(n+1,0), sum2(n+1,0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum[i+1] = a[i] + sum[i];
		sum2[i+1] = max(a[i], 0ll) + sum2[i];
	}

	auto get = [&](int i, int j) {
		return sum[j] - sum[i];
	};
	auto get2 = [&](int i, int j) {
		return sum2[j] - sum2[i];
	};

	int ans = -1e17;
	for (int i = 0; i <= n-k; i++) {
		ans = max(ans, get2(0, i) + max(0ll, get(i, i + k)) + get2(i + k, n));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
const val MAX = 20000000000

fun main(args: Array<String>) {
    val (a, b, q) = readLine()!!.split(" ").map { it.toLong() }
    val s = mutableListOf<Long>()
    val t = mutableListOf<Long>()
    val x = mutableListOf<Long>()
    for (i in 0 until a) {
        s.add(readLine()!!.toLong())
    }
    for (i in 0 until b) {
        t.add(readLine()!!.toLong())
    }
    for (i in 0 until q) {
        x.add(readLine()!!.toLong())
    }

    s.add(MAX)
    s.add(0, -1 * MAX)
    t.add(MAX)
    t.add(0, -1 * MAX)

    for (pos in x) {
        val sNeighbors = getNeighbors(s, pos)
        val tNeighbors = getNeighbors(t, pos)
        var cost = MAX

        for (shrine in sNeighbors) {
            for (temple in tNeighbors) {
                val costTmp1 = Math.abs(shrine - pos) + Math.abs(temple - shrine)
                val costTmp2 = Math.abs(temple - pos) + Math.abs(shrine - temple)
                if (Math.min(costTmp1, costTmp2) < cost) cost = Math.min(costTmp1, costTmp2)
            }
        }

        println(cost)
    }
}

fun getNeighbors(points: MutableList<Long>, pos: Long): MutableList<Long> {
    val neighbors = mutableListOf<Long>()
    val rightIndex = points.binarySearch(pos) * -1 - 1
    val leftIndex = points.binarySearch(pos) * -1 - 2
    neighbors.addAll(listOf(points[leftIndex], points[rightIndex]))

    return neighbors
}

Measured memory_bytes: 83156
#include<stdio.h>
#include<string.h>
int n,f,t,i,j,r[7],h[105][105],num[105][105];
int rt[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};

void rot(int *t,int *f,int d)
{
	int x;
	if(d==0){x=*t;*t=7-*f;*f=x;}
	else if(d==1){*t=7-rt[*t-1][*f-1];}
	else if(d==2){x=*f;*f=7-*t;*t=x;}
	else{*t=rt[*t-1][*f-1];}
}

void drop(int y,int x)
{
	int i,j,mv[5]={0,1,0,-1,0},d[4]={f,rt[t-1][f-1],7-f,7-d[1]};
	for(i=6;i>3;i--)
		for(j=0;j<4;j++)
			if(d[j]==i&&h[y][x]>h[y+mv[j+1]][x+mv[j]])
			{
				rot(&t,&f,j);
				drop(y+mv[j+1],x+mv[j]);
				return;
			}
	h[y][x]++;
	num[y][x]=t;
}

int main()
{
	for(;scanf("%d",&n),n;)
	{
		memset(r,0,sizeof(r));
		memset(h,0,sizeof(h));
		memset(num,0,sizeof(num));
		for(;n--;)
		{
			scanf("%d%d",&t,&f);
			drop(51,51);
		}
		for(i=0;i<105;i++)
			for(j=0;j<105;j++)
				r[num[i][j]]++;
		for(i=1;i<7;i++)
			printf("%d%s",r[i],i==6?"\n":" ");
	}
	return 0;
}

Measured memory_bytes: 692
#include<iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int n, w;
int weights[100];
int values[100];

long long int dp[100][100010];


// i番目までに重さをz以下にするように選ぶときの最大の価値
long long int rec(int i, long long int z) {
    if (i < 0) {
        return 0;
    }
    if (dp[i][z] >= 0) {
        return dp[i][z];
    }
    long long int ret;
    if (weights[i] > z) {
        // i 個目のものを入れられない
        ret = rec(i - 1, z);
    } else {
        // 入れるとき
        long long int v1 = values[i] + rec(i - 1, z - weights[i]);
        // 入れないとき
        long long int v2 = rec(i - 1, z);
        ret = std::max(v1, v2);
    }
    dp[i][z] = ret;
    return ret;
}

int main() {

    for (int i = 0; i < 100; ++i) {
        for ( int j = 0; j < 100010; j++) {
            dp[i][j] = -1;
        }
    }

    cin >> n >> w;
    for (int i = 0; i < n; ++i) {
        cin >> weights[i] >> values[i];
    }

    cout << rec(n - 1, w) << endl;

    return 0;
}

Measured memory_bytes: 78464
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);

	int ans = 0;
	for(int i=0; i<1000; i++){
		int m[3];
		m[0] = i/100;
		m[1] = i/10 % 10;
		m[2] = i%10;
		int pos = 0;
		for(int j=0; j<n; j++){
			if(m[pos]==s[j]-'0') pos++;
		}
		if(pos==3) ans ++;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 3828
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


      



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var input = Reads();
            var h = input[0];
            var w = input[1];
            var s = new char[h][];
            for (int i = 0; i < h; i++)
            {
                s[i] = Console.ReadLine().ToCharArray();
            }
            bool f = true;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (s[i][j] == '#')
                    {
                        bool f1 = i + 1 < h && s[i + 1][j] == '#';
                        bool f2 = j + 1 < w && s[i][j + 1] == '#';
                        bool f3 = i - 1 >= 0 && s[i - 1][j] == '#';
                        bool f4 = j - 1 >= 0 && s[i][j - 1] == '#';
                        if (!f1 && !f2 && !f3 && !f4)
                            f = false;
                    }
                }
            }
            Console.WriteLine(f ? "Yes" : "No");
      

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    vector<int> x(k + 1, 0);
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            x[gcd(a, b)]++;
        }
    }

    int r = 0;
    for (int i = 1; i <= k; i++) {
        int s = 0;
        for (int c = 1; c <= k; c++) {
            s += gcd(i, c);
        }
        r += s * x[i];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3612
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int, ss_raw())

INF = 1 << 29

N  = int_raw()
S = raw_input()



def ans():
    Nr = S.count("R")
    if Nr*2 > N:
        return "Yes"
    else:
        return "No"


print ans()


Measured memory_bytes: 2568
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); 
		int K = sc.nextInt();  
		Integer[] A = new Integer[N+1]; 
        Arrays.fill(A, 0);
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i=0; i<N; i++){
			Integer key = sc.nextInt();
			Integer value = map.get(key);
			if (value == null) value=1;
			else value++;
			map.put(key, value);
		}
		List<Integer> values = new ArrayList<Integer>(map.values());
		Collections.sort(values);
		
		int res = 0;
		for (int i=0; i<values.size()-K; i++) {
			res += values.get(i);
		}		
		System.out.println(res);
	}
		
}


Measured memory_bytes: 100068
n=int(input())
v=list(map(int,input().split()))

evn=dict()
odd=dict()

maxevn1=0
maxevnv1=0
maxodd1=0
maxoddv1=0

maxevn2=0
maxevnv2=0
maxodd2=0
maxoddv2=0

for i in range(n):
    if i%2==0:
        if v[i] in evn:
            evn[v[i]]+=1
        else:
            evn[v[i]]=1
        if evn[v[i]]>maxevn1  and v[i]==maxevnv1:
            maxevn1=evn[v[i]]
        elif evn[v[i]]>maxevn1  and v[i]!=maxevnv1:
            maxevn2=maxevn1
            maxevnv2=maxevnv1
            maxevn1=evn[v[i]]
            maxevnv1=v[i]           
        elif evn[v[i]]>maxevn2:
            maxevn2=evn[v[i]]
            maxevnv2=v[i]           
    else:
        if v[i] in odd:
            odd[v[i]]+=1
        else:
            odd[v[i]]=1
        if odd[v[i]]>maxodd1 and v[i]==maxoddv1:
            maxodd1=odd[v[i]]
        elif odd[v[i]]>maxodd1 and v[i]!=maxoddv1:
            maxodd2=maxodd1
            maxoddv2=maxoddv1
            maxodd1=odd[v[i]]
            maxoddv1=v[i]           
        elif odd[v[i]]>maxodd2:
            maxodd2=odd[v[i]]
            maxoddv2=v[i]           

if maxevnv1!=maxoddv1:
    print(n-maxevn1-maxodd1)
else:
    kk=min(n-maxevn1-maxodd2,n-maxevn2-maxodd1)
    print(kk)
    

Measured memory_bytes: 17056
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
void con_ad(char *num);
void con_maya(char *num);
int Lcalendar[] = {366,31,29,31,30,31,30,31,31,30,31,30,31};/*Leap year Calendar*/
int Ncalendar[] = {365,31,28,31,30,31,30,31,31,30,31,30,31};/*Nomal Calendar*/
int main(){
	char str[128]={0};
	while(scanf("%s",str) , str[0] != '#'){
		int len = strlen(str);
		int p = 0;
		for(int i = 0; i < len; i++){
			if(str[i] == '.')p++;
		}
		(p == 2) ? con_ad(str) : con_maya(str);
	}
	return 0;
}
void con_ad(char *num){
	/*first phase*/
	unsigned long long int year,month,day;
	sscanf(num,"%lld.%lld.%lld",&year,&month,&day);

	unsigned long long int sum = 0;
	sum = (year-1) * 365 + ((year-1)/4) - ((year-1)/100) + ((year-1)/400);

	/*Check Leap year*/
	if(year % 4 == 0 &&(year % 400 == 0 || year % 100 != 0)){
		for(int i = 1; i <= month-1; i++){
			sum += Lcalendar[i];
		}
	}

	else{
		for(int i = 1; i <= month-1; i++){
			sum += Ncalendar[i];
		}
	}
	sum += day;
	/*2012/12/21 = 734858*/
	sum -= 734858;
	sum %= 1872000;
	/*second phase*/
	unsigned long long int ans[8]={0};

	ans[0] = sum / 144000;
	sum %= 144000;
	ans[1] = sum / 7200;
	sum %= 7200;
	ans[2] = sum / 360;
	sum %= 360;
	ans[3] = sum / 20;
	sum %= 20;
	ans[4] = sum;

	for(int i = 0; i < 4; i++)printf("%lld.",ans[i]);
	printf("%lld\n",ans[4]);

	return ;
}
void con_maya(char *num){
    unsigned long long int b,ka,t,w,ki,sum = 0;
    sscanf(num,"%lld.%lld.%lld.%lld.%lld",&b,&ka,&t,&w,&ki);
    sum = (b*144000) + (ka*7200) + (t*360) + (w*20) + ki;

    unsigned long long int year = 2012,month = 12,day = 21;
    while(sum--){
        day++;
        if(day > Ncalendar[month] + (month == 2 && (year % 400 == 0||(year % 4 == 0 && year % 100 != 0)))){
            month++;
            day = 1;
        }
        if(month > 12){
            year++;
            month = 1;
        }
    }
    printf("%lld.%lld.%lld\n",year,month,day);
	return ;
}

Measured memory_bytes: 1036
N, A, B = map(int, input().split())

ans = 0
for n in range(1, N+1):
    str_n = str(n)
    sum_digit = 0
    for i in range(len(str_n)):
        int_n = int(str_n[i])
        sum_digit += int_n
    if A <= sum_digit and sum_digit <= B:
        ans += n
        
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A * A == (B * B) + (C * C))
		cout << (B * C) / 2 << endl;
	if (B * B == (A * A) + (C * C))
		cout << (A * C) / 2 << endl;
	if (C * C == (B * B) + (A * A))
		cout << (B * A) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char x,y;
    int a,b;
    cin>>x>>y;
    switch (x)
    {
    case 'A':
        a=1;
        break;
    case 'B':
        a=2;
        break;
    case 'C':
        a=3;
        break;
    case 'D':
        a=4;
        break;
    case 'E':
        a=5;
        break;
    case 'F':
        a=6;
        break;
    }
    switch (y)
    {
    case 'A':
        b=1;
        break;
    case 'B':
        b=2;
        break;
    case 'C':
        b=3;
        break;
    case 'D':
        b=4;
        break;
    case 'E':
        b=5;
        break;
    case 'F':
        b=6;
        break;
    }
    if (a>b)
    {
        cout<<">";
    }
    else if (a<b)
    {
        cout<<"<";
    }
    else
    {
        cout<<"=";
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
cumsum_east = [0 for i in range(N+1)]
cumsum_west = [0 for i in range(N+1)]
for i in range(1,N+1):
    if S[i-1] == 'E':
        cumsum_east[i] = cumsum_east[i-1] + 1
    else:
        cumsum_east[i] = cumsum_east[i-1]
    if S[i-1] == 'W':
        cumsum_west[i] = cumsum_west[i-1] + 1
    else:
        cumsum_west[i] = cumsum_west[i-1]
cumsum_east = cumsum_east[1:]
cumsum_west = cumsum_west[1:]
ans = 1000000
for i in range(N):
    if i == 0:
        flip_num = cumsum_east[-1]-cumsum_east[0]
    elif i == N-1:
        flip_num = cumsum_west[-2]
    else:
        flip_num = cumsum_west[i-1] + cumsum_east[-1] - cumsum_east[i]
    if ans > flip_num:
        ans = flip_num
print(ans)


Measured memory_bytes: 20216
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

LL pati(LL x){
	return BIT(x+1)-1;
}

LL sum(LL x){
	return BIT(2+x)-3;
}

LL func(LL N, LL X){
	if(X<=0)return 0;
	LL res = 0;
	REP(i, 2){
		if(X<=0)break;
		--X;
		if(i==1)++res;
		if(X<sum(N-1)){
			res += func(N-1, X);
			break;	
		}
		res += pati(N-1);
		X -= sum(N-1);
	}
	return res;
}

int main(){
	LL N, X;
	cin >> N >> X;
	cout << func(N, X) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n[5];
	int tmp;
	for(int i = 0; i<5; ++i) cin >> n[i];	
	for(int i = 0; i<5; ++i) {
		for(int j = i+1; j < 5; ++j) {
			if(n[i] < n[j]){
				tmp = n[i];
				n[i] = n[j];
				n[j] = tmp;
			}
		}
	}
	for(int i = 0; i<5; ++i){
		if(i == 4) { 
			cout << n[i] << endl;;
		}else {
			cout << n[i] << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(; n > 0; n--) {
			if((n & (n-1)) == 0) {
				System.out.println(n);
				break;
			}
		}
	}

}


Measured memory_bytes: 22608
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	map<int,int> mp;
	for(int i=2;i<=n;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	for(int i=1;i<=n;i++){
		cout<<mp[i]<<endl;
	}
    return 0;
}


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

int main(){
    int x;
    cin >> x;
    if(x)cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3620
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

# = map(int,input().split())

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

# = [list(map(int,input().split())) for _ in range(XXXX)]

from math import cos
from math import radians
from math import sqrt

a,b,h,m = map(int,input().split())

m_kakudo = m /60 * 360
h_kakudo = (h*60 + m) / 720 * 360

#print(m_kakudo)
#print(h_kakudo)

if abs(m_kakudo - h_kakudo) == 0:
    print(abs(a-b))
    exit()
elif abs(m_kakudo - h_kakudo) == 180:
    print(a+b)
    exit()
elif abs(m_kakudo - h_kakudo) < 180:
    result = sqrt(a**2 + b**2 - 2*a*b*cos(radians(abs(m_kakudo - h_kakudo))))
    print(result)
    exit()
else:
    result = sqrt(a**2 + b**2 - 2*a*b*cos(radians(360 - abs(m_kakudo - h_kakudo))))
    print(result)
    exit()


Measured memory_bytes: 62472
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(n);
  VIN(a, n);
  VINT(x,n);
  ll sum=0;

  REP(i,n){
    if(i%2==0)
      sum+=a[i];
    else
      sum-=a[i];
  }

  x[0]=sum;
  //  cout<<sum<<' ';

  REP(i,n-1){
    x[i+1]=(a[i]-x[i]/2)*2;
  }
  REP(i,n){
    cout<<x[i]<<' ';
  }
    
}


Measured memory_bytes: 2048
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}

func main() {
	inputs := scanIntNums()
	A := inputs[0]
	B := inputs[1]
	C := inputs[2]
	D := inputs[3]

	for {
		A -= D
		C -= B
		if C <= 0 {
			fmt.Println("Yes")
			break
		} else if A <= 0 {
			fmt.Println("No")
			break
		}
	}
}


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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  string s, t;
  cin >> s >> t;
  map<char, int> s_mp, t_mp;
  for(int i=0; i<(int)s.size(); i++) s_mp[s[i]]++;
  for(int i=0; i<(int)t.size(); i++) t_mp[t[i]]++;
  
  for(int i=0; i<(int)t.size(); i++){
    if(s_mp[t[i]] == 0){
      cout << "-1" << endl;
      return 0;
    }
  }

  vector<vector<ll>> vec(26);
  for(int i=0; i<(int)s.size(); i++) vec[s[i]-'a'].push_back((i+1));
  for(int i=0; i<(int)s.size(); i++) vec[s[i]-'a'].push_back((i+1)+(int)s.size());//2周分つける
  
  ll ans = 0;
  ll place = 0;
  ll cnt = 0;
  for(int i=0; i<(int)t.size(); i++){
    int c = t[i] - 'a';
    place = *lower_bound(vec[c].begin(), vec[c].end(), place+1);

    // cout << " vec[" << t[i] << "]: "; print_vec(vec[c]);
    // cout << " ans: " << ans << " t[i]: " << t[i] << " c: " << c << " place: " << place << endl;
    if(place > (int)s.size()){
      place -= (int)s.size();
      cnt++;
      // cout << " yah " << endl;
    }
    ans = place + (int)s.size() * cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5680
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

void bfs(vector<vector<int>>& v, vector<int>& v2, queue<pair<int, int>>& que, int& count){
  while(!que.empty()){
    pair<int, int> a = que.front(); que.pop();
    if(v2[a.first] == -1){
      count++;
      v2[a.first] = a.second;
      for(auto m : v[a.first]){
        que.push(make_pair(m, a.first) );
      }
    }
  }
}

int main(int argc, const char * argv[]) {
  int n, m;
  cin >> n >> m;
  int count = 0;
  vector<vector<int>> v(n);
  vector<int> v2(n, -1);
  queue<pair<int, int>> que;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  que.push(make_pair(0, 0));
  bfs(v, v2, que, count);
  if(count != n){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  repd(i, 1, n){
    cout << v2[i]+1 << endl;
  }
  return 0;
}


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

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

    for(int i=0; i<n; i++){
        long val;
        cin >> val;
        h.push_back(val);
    }
    sort(h.begin(), h.end());

    long min_range = 10000000000;
    for(int i = 0; i < n-k+1; i++){
        long range = h[i+k-1] - h[i];
        min_range = min(min_range, range);
    }
    cout << min_range << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define nmax_def 2200
#define mod_def 1000000007
using namespace std;
typedef long long ll;


ll nCm_array[nmax_def][nmax_def];
void nCm(int N)
{
	ll i, j;
	for (i = 0; i < N; i++)
	{
		for (j = 0; j <= i; j++)
		{
			ll ans;
			if ((j == 0) || (j == i))
				ans = 1;
			/*else if ((j == 1) || (j == i - 1))
				ans = i;*/
			else
				ans= nCm_array[i - 1][j] + nCm_array[i - 1][j - 1];
			ans %= mod_def;
			nCm_array[i][j] = ans;
		}
	}
}

int main() {
	ll i, j;
	ll N, K;
	cin >> N >> K;
	nCm(N+10);

	for (i = 1; i <= K; i++)
	{
		ll ans;
		if (N - K + 1 >= i)
			ans = nCm_array[N - K + 1][i] * nCm_array[K - 1][i - 1];
		else
			ans = 0;
		ans %= mod_def;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 33536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


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

int main() {
	
	int n; cin >> n;
	vector<int> t(n);
	int sum = 0;
	for (int  i = 0; i < n; i++) {
		cin >> t[i];
		sum += t[i];
	}

	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int p, x; cin >> p >> x;
		int tmpSum = sum;
		tmpSum -= t[p - 1];
		tmpSum += x;
		cout << tmpSum << endl;
	}
	return 0;
}

Measured memory_bytes: 256