akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] size; // size of subtree, including self
    List<Integer>[] graph;
    long[] dp,ans;
    final long mod = 1000000000+7;
    long[] frac,inv; // inv[i] = the inversion of i! mod M
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        main.solve();
//        out.flush();
        System.out.println(main.solve());
    }
    long solve() throws IOException{
        long n = sc.nextLong(), k = sc.nextLong();
        if(n<=k){
            return Math.min(n,k-n);
        }
        long dif = n-k;
        long time = dif/k;
        n -= time*k;
        if(n>k) n -= k;
        return Math.min(n,k-n);
//        return 0;
    }
}



Measured memory_bytes: 21844
#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 ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;

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

  return 0;
}


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

int main() {
    int N, m;
    cin >> N >> m;
    vector<int> v(N+1, 1);
    for(int i=0; i<m; ++i) {
        int c, d;
        cin >> c >> d;
        for(int j=c; j<d; ++j) {
            v[j] = 3;
        }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
}


Measured memory_bytes: 3052
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
int main(){
 int n,m; cin >> n >> m;
if(n==m)cout<<"Yes"<<endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  double ki = 0;
  FOR(i, 1, n + 1) {
    if (i % 2 == 1)
      ki++;
  }

  cout << fixed << setprecision(8) << ki / n << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Hot Spring Trip
public class Main{

	int[][] e;
	int[][] dist;
	int INF = 1<<29;

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			e = new int[n][n];
			//0: can use 1:tochuu 2:cant use
			dist = new int[n][3];
			for(int[]ee:e)Arrays.fill(ee, INF);
			for(int[]d:dist)Arrays.fill(d, INF);
			while(m--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1, c = sc.nextInt();
				e[s][t] = e[t][s] = Math.min(e[s][t], c);
			}
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(n, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return dist[o1[0]][o1[1]] - dist[o2[0]][o2[1]];
				}
			});
			dist[0][0] = 0;
			q.add(new int[]{0, 0});
			int res = INF;
			while(!q.isEmpty()){
				int[] V = q.poll();
				int p = V[0], s = V[1];
				if(p==n-1&&s!=1){
					res = Math.min(res, dist[p][s]);
				}
				if(s==0){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][0]){
							dist[nx][0] = w; q.add(new int[]{nx, 0});
						}
						w = dist[p][s];
						if(w < dist[nx][1]){
							dist[nx][1] = w; q.add(new int[]{nx, 1});
						}
					}
				}
				else if(s==1){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
				else{
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
			}
			System.out.println(res);
		}
	}

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

Measured memory_bytes: 13000
package main

import (
	"errors"
	"fmt"
)

func main() {
	t1, t2 := scanIntPair()
	a1, a2 := scanIntPair()
	b1, b2 := scanIntPair()
	c1, c2 := a1-b1, a2-b2
	ans, err := solve(c1, c2, t1, t2)
	if err != nil {
		fmt.Println("infinity")
	} else {
		fmt.Println(ans)
	}
}

func solve(c1 int64, c2 int64, t1 int64, t2 int64) (int64, error) {
	if c1 < 0 {
		c1, c2 = -c1, -c2
	}
	forward := c1 * t1
	backward := c2 * t2
	cycle := forward + backward
	if cycle > 0 {
		return 0, nil
	} else if cycle == 0 {
		return 0, errors.New("infinity")
	} else {
		repeat := forward / -cycle
		touch := forward%-cycle == 0
		if repeat <= 0 {
			return 1, nil
		} else if touch {
			return 1 + 2*repeat - 1, nil
		} else {
			return 1 + 2*repeat, nil
		}
	}
}

func scanIntPair() (int64, int64) {
	var a, b int64
	fmt.Scanf("%d %d", &a, &b)
	return a, b
}

func scanInts(length int64) []int64 {
	ints := make([]int64, length)
	for i := range iter(0, length) {
		var x int64
		_, _ = fmt.Scan(&x)
		ints[i] = x
	}
	return ints
}

func iter(l int64, r int64) chan int64 {
	var i int64 = l
	c := make(chan int64)
	run := func() {
		for i < r {
			c <- i
			i += 1
		}
		close(c)
	}
	go run()
	return c
}

func gcd(a int64, b int64) int64 {
	x, y := a, b
	for true {
		if x%y == 0 {
			break
		}
		x, y = y, x%y
	}
	return y
}

func slice_gcd(ints []int64) int64 {
	return reduce_int(gcd, ints)
}

func lcm(a int64, b int64) int64 {
	g := gcd(a, b)
	return a * b / g
}

func slice_lcm(ints []int64) int64 {
	return reduce_int(lcm, ints)
}

func reduce_int(f func(int64, int64) int64, ints []int64) int64 {
	ans := ints[0]
	for i := range iter(1, int64(len(ints))) {
		ans = f(ans, ints[i])
	}
	return ans
}


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

int main()
{
    int a, b, diff;
    cin >> a >> b;
    diff = b - a;
    for (size_t i = 1; i < diff; i++)
    {
        a -= i;
    }
    cout << abs(a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n,m;
    int ans = 1;
    cin >> n >> m;
    if(n == 1){
        cout << m << endl;
        return 0;
    }


    for(int i = 1; i * i < m; i++){
        if(m % i == 0){
            if(n <= i){
                ans = max(ans,m/i);
            }
            if(n <= m/i){
                ans = max(ans,i);
            }
        }
    }

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

Measured memory_bytes: 256
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n; cin >> n;
    int i=0;
    int score=0,out=0;
    vi v;
    while(i<n) {
        string s; cin >> s;
        if(s=="OUT") {
            out++;
            if(out==3) {
                P(score);
                score=0;out=0;v.clear();
                i++;
            }
        }
        if(s=="HIT") {
            if(v.size()==3) score++;
            else v.push_back(1);
        }
        if(s=="HOMERUN") {
            score+=v.size()+1;
            v.clear();
        }

    }
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i=0, i##_len=(ll)(n); i<i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;



int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl a(n); REP(i, n) cin >> a[i];
	ll sum = 0;
	REP(i, n) if (i == a[a[i]-1]-1) sum++;
	cout << sum / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 1024
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
c=[0]*(w*h)
k=0
for l,i in enumerate(a):
  for j in range(i):
    c[k]=l+1
    k+=1
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
ans = list(split_list(c, w))
for i,j in enumerate(ans):
  if i%2==0:
    print(*j)
  else:
    print(*j[::-1])

Measured memory_bytes: 9492
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;


int main(){
    int N;cin >> N;
    int a[N];
    int d[N];

    int min_d = N;
    int minIndex = -1;
    int ans = 0;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }

    int arr[N];
    int cnt = 1;
    for(int i=0;i<N;i++){
        if(a[i] == cnt)cnt++;
        else ans++;
    }

    if(ans == N) ans = -1;


    cout << ans;



}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define fn(i,x) for(i=0;i<x;i++)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define vii vector<int>
#define vll vector<ll>
#define mx 1e18
#define mod 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define sii set<int>
#define sll set<ll>
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{io
int n;cin>>n;string s;ll ans=0;
cin>>s;
vector<int>a(n),b(n),c(n);int x=0,y=0,z=0;
for(int i=n-1;i>=0;i--)
{
    if(s[i]=='R')x++;
    else if(s[i]=='B')y++;
    else z++;
    a[i]=x;b[i]=y;c[i]=z;
}char cc;
for(int i=0;i<n-2;i++)
{
	for(int j=i+1;j<n-1;j++)
	{
	if(s[i]!=s[j])
	{
	   cc='R'+'B'+'G'-s[i]-s[j];
	   if(cc=='R')
	   {
	       if(s[2*j-i]=='R'&&(2*j-i<=n-1))
	   ans+=a[j+1]-1;else ans+=a[j+1];}
	   else if(cc=='B')
	   {if(s[2*j-i]=='B'&&(2*j-i<=n-1))
	       ans+=b[j+1]-1;else ans+=b[j+1];}
	   else 
	   {if(s[2*j-i]=='G'&&(2*j-i<=n-1))
	   ans+=c[j+1]-1;
	   else
	       ans+=c[j+1];}
	}
	}
}cout<<ans;
	


 
}


Measured memory_bytes: 3688
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<end
 
long long isPrime(long long n){
  long long i;
  if(n < 2LL){
    return 0LL;
  }
  else if(n == 2LL){
    return 1LL;
  }
  if(n % 2LL == 0LL){
    return 0LL;
  }
  for(i = 3LL; i * i <= n; i += 2LL){
    if(n % i == 0LL){
      return 0LL;
    }
  }
  return 1LL;
}
 
int main(void) {
	ll n;
	cin>>n;
	ll ans = 0;
	rep(i,1,n+1){
		if(i%2==0)continue;
		ll a = i;
		ll c = 0;
		rep(j,1,i+1){
			if(i%j==0)c++;
		}
		if(c==8)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
 int main(void){
     int i,m,a,b;
      while(scanf("%d %d",&a,&b)!=EOF){
           m=a+b;
        for(i=1;m>=10;i++){
                m=m/10;
        }
       printf("%d\n",i);
       }
       return 0;
 }

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int main() {
    int N; cin >> N;
    
    Graph G(N);
    for(int i = 0; i < N-1; ++i) {
        int a, b, w; cin >> a >> b >> w;
        --a, --b;
        G[a].push_back(make_pair(b, w));
        G[b].push_back(make_pair(a, w));
    }
    
    vector<int> dist(N, -1);
    queue<int> que;
    
    vector<int> color(N, 0);
    dist[0] = 0;
    que.push(0);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for(auto e : G[v]) {
            int nv = e.first;
            int w = e.second;
            if(dist[nv] != -1) continue;
            
            if(w % 2) color[nv] = 1 - color[v];
            else color[nv] = color[v];
            
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    
    for(int v = 0; v < N; ++v) cout << color[v] << endl;
}


Measured memory_bytes: 7168
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tolower(c) char(c+0x20)
#define toupper(c) char(c-0x20)
#define chartoll(c) ll(c) - ll('a')

const ll MAX_N = 100000;

int main(void){
    ll N;
    string s[MAX_N];
    map<string, ll> cnt;
    ll answer = 0; 

    cin >> N;
    rep(i, N) cin >> s[i];
    
    /*
    ll si[MAX_N];
    ll tens[10];
    tens[0] = 1;
    rep(i, 9) tens[i + 1] = 26 * tens[i];
    rep(i, N){
        ll v[10];
        si[i] = 0;
        rep(j, 10){
            v[j] = chartoll(s[i][j]);
        }
        sort(v, v+10);
        rep(j, 10){
            si[i] += tens[j] * v[j];
        }
    }
    sort(si, si+N);
    rep(i, N) cnt[si[i]] = 0;
    rep(i, N) cnt[si[i]]++;
    */

    rep(i, N) sort(all(s[i]));
    rep(i, N) cnt[s[i]] = 0;
    rep(i, N) cnt[s[i]]++;

    for(auto& kv: cnt){
        answer += (kv.second * (kv.second - 1)) / 2;
    }
    

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 18176
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string s;
    cin >> s;
    
    ll ans = 0;

    for(ll i = 0; i < s.length(); i++){
        if(s[i] == '1') ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
from collections import deque
SENIAL = 10**9
count = 0

def merge(A,left,mid,right):
    L = deque(A[left:mid])
    R = deque(A[mid:right])
    L.append(SENIAL)
    R.append(SENIAL)
    
    global count
    
    for k in range(left,right):
        count +=1
        if L[0] <= R[0]:
            A[k] = L.popleft()
 
        else:
            A[k] = R.popleft()

            
def mergeSort(A,left,right):
    if left + 1 < right:
        middle = (left + right) //2
        mergeSort(A,left,middle)
        mergeSort(A,middle,right)
        merge(A,left,middle,right)
        
input()
l = list(map(int,input().split()))
mergeSort(l,0,len(l))
print(" ".join(map(str,l)))
print(count)            
        

Measured memory_bytes: 72232
#include<stdio.h>

int main(){
    int k,s,i,j,z,count=0;

    scanf("%d %d",&k,&s);

    for(i=0;i<=k;i++){
        for(j=0;j<=k;j++){
            z = s - i - j; 
                if(z>=0 && z<=k){
                    count++;
            }
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int z(int a,int b,int c){return a>b&&a>c?a:b<c?c:b;}
int main(){
  int n,k,i,j,x,y,m[1001][1001]={},s,v,w;
  char a;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d%d %c",&x,&y,&a);y+=(a=='W')*k;
    s=1-(x/k%2!=y/k%2)*2;
    m[0][0]+=s>0;
    v=x%k+1;w=y%k+1;
    m[v][0]-=s;
    m[0][w]-=s;
    m[v][w]+=s*2;
  }
  for(i=0;i<=k;i++)for(j=0;j<k;j++)m[i][j+1]+=m[i][j];
  for(i=0;i<=k;i++)for(j=0;j<k;j++)m[j+1][i]+=m[j][i];
  v=0;for(i=0;i<k;i++)for(j=0;j<k;j++)v=z(v,m[i][j],n-m[i][j]);
  printf("%d",v);
}


Measured memory_bytes: 5644
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<int> L(N+1),R(N+1);
    REP(i,N){
        L[i+1]=gcd(L[i],A[i]);
        R[N-i-1]=gcd(R[N-i],A[N-i-1]);
    }
    int ans=0;
    REP(i,N){
        ans=max(ans,gcd(L[i],R[i+1]));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/

#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define inf              9999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//___________________________________________________________________________________________________________________
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
ll t,x,n,m,y,z,x1,x2,x3,k;
ll ar[4][4],vis[4][4];
int main()
{
    fast;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++) cin>>ar[i][j];
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        for(int j=0;j<3;j++)
        {
            for(int l=0;l<3;l++)
            {
                if(x==ar[j][l]) vis[j][l]=1;
            }
        }
    }
    bool ok=false;
    for(int i=0;i<3;i++)
    {
        if(vis[i][0] && vis[i][1] && vis[i][2]) ok=true;
        if(vis[0][i] && vis[1][i] && vis[2][i]) ok=true;
    }
    if(vis[0][0] && vis[1][1] && vis[2][2]) ok=true;
    if(vis[0][2] && vis[1][1] && vis[2][0]) ok=true;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
    	new Main().exec(args);
    }

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	Scanner sc = new Scanner(System.in);
    	String a = sc.next();
    	String s = sc.next();
    	String c = sc.next();
    	System.out.println("A"+s.substring(0, 1)+"C");
    }
}

Measured memory_bytes: 9680
N, M, X, Y = [int(_) for _ in input().split()]
xs = [int(_) for _ in input().split()]
ys = [int(_) for _ in input().split()]


xs.append(X)
ys.append(Y)

xs.sort()
ys.sort()

#print(xs, ys)

result = False

if xs[-1] >= ys[0]:
    result = True

if result:
    print("War")
else:
    print("No War")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
typedef struct node * Node;
#define NIL NULL
Node root = NIL;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k<u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y = x->parent;
  if(x->right != NIL)
    {
      return treeMinimum(x->right);
    }
  while( y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL)
    {
      y = z;
    }
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    {
      x = y->left;
    }
  else
    x = y->right;

  if(x != NIL)
    {
      x->parent = y->parent;
    }
  if(y->parent == NIL)
    {
      root = x;
    }
  else if(y == y->parent->left)
    {
      y->parent->left = x;
    }
  else
    y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  z->parent = NIL;
  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)
	{
	  x = x->left;
	}
      else
	x = x->right;

      z->parent = y;
    }
  if(y == NIL)
    {
      root = z;
    }
  else if(z->key < y->key)
    {
      y->left = z;
    }
  else
    y->right = z;
    
}

void inorder(Node u){
  if(u == NIL) return;
 inorder(u->left);
 printf(" %d",u->key);
 inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}




Measured memory_bytes: 20432
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, a, b; cin >> k >> a >> b;
    if(a <= k*(b / k)) cout << "OK" << endl;
    else cout << "NG" << endl; 
 
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b; return true;} return false;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;



//vvc<pair<ll,ll>> beto(1e3+7,vc<pair<ll,ll>>()); // pair<行先,コスト>

ll bell(ll start, ll goal, vvc<pair<ll,ll>>& beto){
    ll n = SIZE(beto);
    vc<ll> dist(n,INF);
    dist[start] = 0;
    rep(roop,n) {
        bool ch = false;
        rep(i,n){
            for (pair<ll,ll> p: beto[i]){
                if(dist[i] != INF && dist[i]+ p.second < dist[p.first]){
                    dist[p.first] = dist[i] + p.second;
                    ch = true;
                    //cout << i+1 << "->" << p.first+1 << " " << dist[p.first] << endl;
                    if(roop == n-1 && p.first == goal) return -1*INF;
                }
            }
        }
        if(!ch) break;
    }
    return dist[goal];
}

int main(){
    cout << fixed << setprecision(20);
    ll n,m; cin >> n >> m;
    vvc<pair<ll,ll>> beto(n,vc<pair<ll,ll>>());
    rep(i,m){
        ll a,b,c; cin >>a >> b >> c;
        a--; b--;
        beto[a].eb(make_pair(b,c*-1));
    }
    ll ans = bell(0,n-1,beto);
    if(ans == INF*-1) cout << "inf" << endl;
    else cout << ans*-1 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int l, r, l_max = 1, r_min = n;
    for(int i = 0; i < m; i++){
        cin >> l >> r;
        if(l > l_max) l_max = l;
        if(r < r_min) r_min = r;
    }
    int ans = r_min - l_max + 1;
    if(ans < 1) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <limits>
#include <iomanip>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class AEntranceExamination {
public:
	void solve(std::istream& in, std::ostream& out) {
        int t,x;in>>t>>x;
        out<<fixed<<setprecision(10)<<(double)t/x<<endl;
	}
};


int main() {
	AEntranceExamination solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3260
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto S = RD;
	auto A = RDA;
	
	auto dp = new long[][](N+1, S+1);
	long ans;
	foreach (i; 0..N)
	{
		dp[i][0].moda(1);
		foreach (j; 0..S)
		{
			dp[i+1][j].moda(dp[i][j]);
			if (j+A[i] > S) continue;
			dp[i+1][j+A[i]].moda(dp[i][j]);
		}
		long t = dp[i+1][S];
		t.modm(N-i);
		ans.moda(t);
	}
	debug writeln(dp);

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 74236
use proconio::input;
 
fn main() {
  input! {
    n: usize,
    vals: [isize;n]
  }
  
  let mut dp: Vec<isize> = vec![0;n];
  dp[0] = 0;
  dp[1] = (vals[0] - vals[1]).abs();
  for i in 2..n {
    dp[i] = std::cmp::min(
      dp[i-2] + (vals[i] - vals[i-2]).abs(),
      dp[i-1] + (vals[i] - vals[i-1]).abs()
    );
  }
  
  println!("{}", dp[n-1]);
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

const int MAX = 120000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int n,m;
  cin >> n >> m;
  int bound = sqrt(m) + 2;
  vector<bool> era(bound,true);
  era[0] = false;
  era[1] = false;
  for(int i=2;i<bound;i++){
    if(!era[i]) continue;
    for(int j = 2; j*i < bound ;j++) era[i*j] = false;
  }
  vector<int> prime;
  rep(i,bound) if(era[i]) prime.push_back(i);
  vector<int> count(bound,0);
  bool flag = false;
  int buf = m;
  while(buf > 1){
    int now = buf;
    for(p:prime){
      if(buf%p != 0) continue;
      count[p]++;
      buf /= p; 
    }
    if(now == buf){
      flag = true;
      break;
    }
  }
  if(flag) count.push_back(1);
  vector<int> a;
  for(c:count) if(c>0) a.push_back(c);
  COMinit();
  ll ans = 1;
  for(buf:a) ans = (ans * COM(n-1+buf,n-1)) % MOD;
  cout << ans << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int res = 0;
    vi A(n); for(auto& e : A) cin >> e, e--;
    vi B(n); for(auto& e : B) cin >> e, res += e;
    vi C(n-1); for(auto& e : C) cin >> e;

    rep(i, n-1){
        if(A[i+1] == A[i] + 1){
            res += C[A[i]];
        }
    }

    cout << res << endl;

    return 0;
}


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

int main(){
int N,A,B;
  cin>>N>>A>>B;
  
  int ans=0;
  for(int i=1; i<=N; i++){
   int c=0;
   int t=i; 
   for(int j=0; j<5; j++){
    c+=t%10;
    t/=10;
   }
   if(A<=c && c<=B){ans+=i;}  
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  vector<int> v(n);
  REP(i,n){
    cin >> v[i];
  }

  int ans = 1;
  for(int i = 1; i < n; ++i){
    bool sea = true;
    for(int j = 0; j < i; ++j){
      if(v[j] > v[i]){
        sea = false;
        break;
      }
    } 
    if(sea) ans++;
  }

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



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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	map<char,string> m;
	cin >> m['a'] >> m['b'] >> m['c'];

	char s = 'a';
	while((int)m[s].size() > 0){
		cerr << s << " " << m[s] << endl;
		char ss = m[s][0];
		m[s].erase(m[s].begin());
		s = ss;
	}
	cout << (char)(s + 'A' - 'a') << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main () {
  int a, b, c, d; cin >> a >> b >> c >> d;
  cout << (a+b<c+d ? "Right" : a+b>c+d ? "Left" : "Balanced") << endl;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

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

    int h = 1;
    int res = 0;

    while (h < B) {
        h--;
        res++;
        h += A;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int N;
    std::cin >> N;
    int a=N/100;
    int b=(N-a*100)/10;
    int c=N-a*100-b*10;
    std::string s="No";
    if(a==7||b==7||c==7){
        s="Yes";
    }
    std::cout << s << std::endl;
    return 0;
}


Measured memory_bytes: 3628
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
last=A
for m in (B,C,D,E):
    if m%10<last%10 and m%10!=0:
        last=m
ans=last
l=[A,B,C,D,E]
l.remove(last)
for m in l:
    ans+=((m+9)//10)*10
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
#define input ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define dl endl
#define ft first
#define sc second
using namespace std;
string a, b;
int cnt = 0;
int main()
{
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	input;
	cin >> a >> b;
	for (int i = 0; i < a.length(); ++i) if (a[i] != b[i]) cnt++;
	cout << cnt;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=1e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
struct node{
    int l,r;
    bool operator <(const node &a)const{
        if(l!=a.l)return l<a.l;
        return r<a.r;
    }
}a[maxn];


signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i){
        int x=read(),L=read();
        a[i]=(node){x-L,x+L};
    }
    sort(a+1,a+1+n);int ans=n,nowl=a[1].l,nowr=a[1].r;
    for(int i=2;i<=n;++i){
        if(a[i].l<nowr){
            ans--;nowr=min(nowr,a[i].r);
        }
        else nowl=a[i].l,nowr=a[i].r;
    }printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int a,b,d;
  char c;
  int ans[2] = {0};
  while(cin >> a >>c>> b >>c>> d){
    if(a == b)ans[0]++;
    else if(a*a + b*b == d*d)ans[1]++;

  }
  cout << ans[1] << endl;
  cout << ans[0] << endl;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))


int main()
{
    int tst,n,i,j,m,k;

    string s;

    cin >> s;
   int a,b;
    a = b = 0;
    n = 3;
    for(i=0;i<n;i++)
    {
        if(s[i] == 'R')a++;
        else
        {

            b = max(b,a);
            a = 0;
        }
    }
     b = max(b,a);

     cout << b << endl;
}


Measured memory_bytes: 3592
//const fi='traveling.inp';
//      fo='traveling.out';
var n,s:longint;
    a:array[0..10000] of longint;
//procedure mo;
//begin
 //       assign(input,fi);
 //       reset(input);
 //       assign(output,fo);
 //       rewrite(output);
//end;

procedure nhap;
var i:longint;
begin
        readln(n);
        for i:=1 to n do
                read(a[i]);
end;

procedure swap(a,b:longint);
var c:longint;
begin
        c:=a;
        a:=b;
        b:=c;
end;

 procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

procedure xuly;
var i:longint;
begin
        for i:=2 to n do
                s:=s+a[i]-a[i-1];
        writeln(s); 
end;


begin
        //mo;
        nhap;
        sort(1,n);
        xuly;
end.


Measured memory_bytes: 128
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c

print(Su // 2)

Measured memory_bytes: 72156
#include <stdio.h>

long abs(long p){
  return(p<0?-p:p);
}

long min(long p0,long p1){
  return(p0<p1?p0:p1);
}

int main(){
  long n,a,b;
  scanf("%ld",&n);
  scanf("%ld",&a);
  scanf("%ld",&b);
  if((a^b)&1){
    printf("%ld",(min(a+b-2,(n<<1)-a-b)+1)>>1);
  }else{
    printf("%ld",abs(a-b)>>1);
  }
  return(0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;	

const int hell = 1e9+7;

signed main(){IOS;
	int n,m; cin>>n>>m;
	vector<string>grid(n);
	for(string& i : grid) cin>>i;
	vector<vector<int>>dp(n,vector<int>(m,0));
	dp[0][0]= 1;
	for(int i=1;i<n;i++) dp[i][0] = (grid[i][0]=='.')?dp[i-1][0]:0;
	for(int i=1;i<m;i++) dp[0][i] = (grid[0][i]=='.')?dp[0][i-1]:0;
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(grid[i][j]=='.') dp[i][j] = (dp[i][j-1]+dp[i-1][j])%hell;
			else dp[i][j]=0;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    string a, b; std::cin >> a >> b;
    reverse(rng(b));
    if (a == b)
        std::cout << "YES" << "\n";
    else
        std::cout << "NO" << "\n";
}


Measured memory_bytes: 256