akhauriyash/Code-Regression huggingface dataset:
import sys
inf = 10**9
sys.setrecursionlimit(inf)


def connect(signs, to_room, from_room):
    signs[to_room][2].add(from_room)
    signs[from_room][2].add(to_room)
    return signs


def update(signs, to_room, from_room):
    """
    1. fromの距離を記憶
    2. fromの行き先を記憶
    3. toの来るリストにfromを追加
    4. fromの行き先にtoを追加
    5. fromの距離をto+1に変更
    6. もともとのfromの距離がinfなら
        a. fromの来るリスト(fromfrom)の行き先をfromにする
        b. fromfromの来るリストからfromを削除
        c. 1から始める
    7. fromの新しい距離がもともとのfromの行き先(fromto)の距離がより短いなら、
        a. 1から始める
    """
    # from_room_dist = signs[from_room][0]
    # from_to_rooms = signs[from_room][1]
    # signs[to_room][2].add(from_room)
    # signs[to_room][2].discard(from_room)
    signs[from_room][0] = signs[to_room][0] + 1
    signs[from_room][1] = to_room
    # signs[from_room][2].discard(to_room)
    for from_from_room in signs[from_room][2]:
        if signs[from_room][0] < signs[from_from_room][0] - 1:
            signs = update(signs, from_room, from_from_room)
    # if from_room_dist == inf:
    #     for from_from_room in signs[from_room][1]:
    #         signs[from_from_room][1].discard(from_room)
    #         signs = update(signs, from_room, from_from_room)
    for from_to_room in signs[from_room][2]:
        if from_to_room and signs[from_room][0] < signs[from_to_room][0] - 1:
            signs = update(signs, from_room, from_to_room)
        # print(signs)
    return signs


def main():
    n, m, *ab = map(int, open(0).read().split())
    ab = [ab[2 * i:2 * (i + 1)] for i in range(m)]

    to = [[] for _ in range(n)]
    for a, b in ab:
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)

    dist = [inf] * n
    pre = [None] * n
    queue = [0]
    while queue:
        v = queue.pop(0)
        for u in to[v]:
            if dist[u] != inf:
                continue
            dist[u] = dist[v] + 1
            pre[u] = v
            queue.append(u)

    pre = [i + 1 for i in pre]
    ans = '\n'.join([str(i) for i in ['Yes'] + pre[1:]])

    print(ans)
    return(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79084
N=int(input())
A=list(map(int,input().split()))
value=sum(A)
T=[0 for i in range(N)]

T[0]=value-sum([a for i,a in enumerate(A) if i%2==1 and i>=1])*2
T[1]=value-sum([a for i,a in enumerate(A) if i%2==0 and i>=2])*2

for i in range(2,N):
    T[i]=T[i-2]+(A[i-1]-A[i-2])*2
print(" ".join(list(map(str,T))))


Measured memory_bytes: 78180
#![allow(unused_imports)]
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n],
    }
    let m = 1000000007i64;
    let mod_product = |acc: i64, &value: &i64| {
        (acc * value).rem_euclid(m)
    };

    if k == n || k % 2 == 1 && a.iter().all(|v| *v <= 0) {
        a.sort_by_key(|v| -*v);
        let ans = a.iter().take(k).fold(1, mod_product);
        println!("{}", ans);
        return;
    }

    a.sort_by_key(|v| Reverse(v.abs()));
    let mut plus = Vec::new();
    let mut minus = Vec::new();
    for i in 0..n {
        if a[i] >= 0 {
            plus.push(a[i]);
        } else {
            minus.push(a[i]);
        }
    }

    let mut ppos = 0;
    let mut mpos = 0;
    let mut vals = Vec::new();
    let mut retry = false;
    while vals.len() < k {
        if vals.len() < k - 1 && ppos + 1< plus.len() && mpos + 1 < minus.len() {
            if plus[ppos] * plus[ppos+1] < minus[mpos] * minus[mpos+1] {
                vals.push(minus[mpos]);
                vals.push(minus[mpos+1]);
                mpos += 2;
            } else {
                vals.push(plus[ppos]);
                vals.push(plus[ppos+1]);
                ppos += 2;
            }
        } else if vals.len() < k - 1 && mpos + 1 < minus.len() {
            vals.push(minus[mpos]);
            vals.push(minus[mpos+1]);
            mpos += 2;
        } else if ppos < plus.len() {
            vals.push(plus[ppos]);
            ppos += 1;
        } else {
            retry = true;
            break;
        }
    }
    let ans = if !retry {
        vals.iter().fold(1, mod_product)
    } else {
        a.sort_by_key(|v| v.abs());
        assert!(a.iter().filter(|v| **v < 0).count() %2 == 0);
        a.iter().take(k).fold(1, mod_product)
    };
    println!("{}", ans);
}


Measured memory_bytes: 9840
#include<stdio.h>

int main(void){
  int n,m,i;
  scanf("%d %d",&n,&m);
  if(m==100) m+=1;
  if(n==0){
    printf("%d\n",m);
  }else if(n==1){
    printf("%d\n",m*100);
  }else{
    printf("%d\n",m*10000);
  }
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T1, typename T2>
ostream& operator << (ostream& os, const map<T1, T2>& m){
  for (const auto [k, v] : m) os << "{" << k << "," << v << "} ";
  return os;
}

int main() {
  int N; cin >> N;
  vector<LL> A(N); cin >> A;
  sort(A.rbegin(), A.rend());

  LL sum = 0;
  map<LL, LL> m;
  m[A[0]] = 1;
  for (int i = 1; i < N; ++i) {
    auto it = m.rbegin();
    auto& [k, v] = *it;
    sum += k;
    --v;
    if (v == 0) m.erase(k);
    m[A[i]] += 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 11180
def decomp(m):
    p2=0
    p5=0
    while m%2==0:
        m//=2
        p2+=1
        if p2>18:
            break
    while m%5==0:
        m//=5
        p5+=1
        if p5>18:
            break
    return p2,p5

n=int(input())
table=[[0]*20 for _ in range(20)]
ans=0
for i in range(n):
    a=float(input())
    ax=int(round(a*10**9))
    p2,p5=decomp(ax)
    if i!=0:
        for j in range(max(0,18-p2),20):
            ans+=sum(table[j][max(18-p5, 0):])
    table[p2][p5]+=1

print(ans)

Measured memory_bytes: 76780
import java.util.*;

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

    long min = (l*r)%2019;

    if(min == 0)
    {
        System.out.println(0);
        System.exit(0);
    }

    long tmp;
    /*
    if(l >= 2019){
        for(int i = 1; i<r-l+1; i++)
        {  
            tmp = (l+i)%2019;
            if(tmp==0){
                System.out.println(0);
                System.exit(0);
            }
            else if(min > tmp){
                min = tmp;
            }
        }
    }
    else{
    */
        for(int i = 0; i<r-l; i++){
            for(int j = 1; j < r-l+1; j++){
                tmp = ((l+i)*(l+j))%2019;
                if(tmp==0){
                    System.out.println(0);
                    System.exit(0);

                }
                else if(min > tmp){
                    min = tmp;
                }
            }
        }
    //}
    System.out.println(min);
  }
}

Measured memory_bytes: 23764
n = int(input())
A1 = [int(i) for i in input().split()]
A2 = [int(i) for i in input().split()]
tmp = A1[0]+sum(A2)
ans = [tmp]
for i in range(1,n):
    tmp = tmp + A1[i] - A2[i-1]
    ans.append(tmp)

print(max(ans))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e3 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int a, b, x;
signed main()
{
    a = read(), b = read(), x = read();
    int a1 = a / x;
    while (a1 * x < a) {
        a1++;
    }
    int b1 = b / x;
    writeln(b1 - a1 + 1);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
X = [0] * N
X[0] = S - 2 * sum(A[1::2])
for i in range(1, N):
    X[i] = 2 * A[i-1] - X[i-1]
print(*X)


Measured memory_bytes: 20480
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if N % 2 == 0:
        dp = [[0]*2 for _ in range(N//2 + 1)]
        for i in range(N//2):
            dp[i+1][0] = dp[i][0] + A[2*i]

            dp[i+1][1] = max(dp[i][0], dp[i][1]) + A[2*i+1]

        print(max(dp[-1]))
    else:
        dp = [[0]*3 for _ in range(N//2 + 1)]
        for i in range(N//2):
            dp[i+1][0] = dp[i][0] + A[2*i]

            dp[i+1][1] = max(dp[i][0], dp[i][1]) + A[2*i+1]

            dp[i+1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + A[2*i+2]

        print(max(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 109152
#include<cstdio>
using namespace std;
int main(void)
{
	int n,i,n1;
	long long cnt[26];
	char s[100001],t[100001];
	scanf("%d",&n);
	scanf("%s",s);
	scanf("%s",t);
	for(i=0;i<26;i++){
		cnt[i]=0;
	}
	cnt[s[0]-'a']++;
	for(i=0;i<n-1;i++){
		if(s[i]==t[n-1]){
			n1=i;
		}
	}
	for(i=1;i<=n1;i++){
		if(cnt[t[i]-'a']>0){
			  cnt[s[i]-'a']+=cnt[t[i]-'a'];
			  cnt[s[i]-'a']=cnt[s[i]-'a']%1000000007;
		}
	}
    printf("%lld\n",cnt[t[n-1]-'a']);
	return 0;
}


Measured memory_bytes: 2920
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int h,w,k; cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i,h) rep(j,w) cin >> c[i][j];

  int res = 0;
  rep(hmask,(1 << h)) {
    rep(wmask, (1 << w)) {
      int cnt = 0;
      rep(i,h) {
	rep(j,w) {
	  if((hmask >> i) & 1) continue;
	  if((wmask >> j) & 1) continue;
	  if(c[i][j] == '#') cnt++;
	}
      }
      if(k == cnt) res++;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3608
import math
A, B = map(int, input().split())

ansA = set(range(math.ceil(A/0.08), math.ceil((A+1)/0.08)))
ansB = set(range(math.ceil(B/0.10), math.ceil((B+1)/0.10)))

if ansA & ansB:
    print(min(ansA & ansB))
else:
    print(-1)


Measured memory_bytes: 38408
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
}


Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split(' ')))
X_sorted = sorted(X)
M_1st = X_sorted[int(N/2-1)]
M_2nd = X_sorted[int(N/2)]
for i in X:
    if i <=M_1st:
        print(M_2nd)
    else:
        print(M_1st)

Measured memory_bytes: 92636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;cin>>s;
	char ch=s[s.size()-1];
	if(ch=='2'||ch=='4'||ch=='5'||ch=='7'||ch=='9'){
		cout<<"hon";
		return 0;
	}
	else if(ch=='0'||ch=='1'||ch=='6'||ch=='8'){
		cout<<"pon";
		return 0;
	}
	else cout<<"bon";
	return 0;
}

Measured memory_bytes: 3600
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

# Aが条件を満たすか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()


"""
Aの要素について、全てに辺が貼られているような状態を考えて、
あるA[i][j]が、i,kを除く全てのkについて A[i][j] < A[i][k] + A[k][j]であれば、
A[i][j]は最短の経路であるといえる

"""
ans = 0
for i in range(N):
    for j in range(i+1,N):


        flag = True # i,jの間に辺があるか
        for k in range(N):
            if i == k or j == k:
                continue
            
            # i -> j 間に辺がない
            if A[i][j] == A[i][k] + A[k][j]:
                flag = False
                break
        if flag:
            ans += A[i][j]

        
print(ans)

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

int main() {
    int n; cin >> n;
    ll B[n-1]; rep(i, n-1) cin >> B[i];
    ll ans = 0;
    ll prev = 1000000;
    rep(i, n) {
        if (i==n) {
            ans += B[n-1];
        } else {
            ans += min(prev, B[i]);
            prev = B[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n, r; cin >> n >> r;
  if(n >= 10) {
    print(r);
    return 0;
  }
  cout << (r + (100 * (10 - n))) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define pb push_back
const int mod = 998244353;
const ll INF = -(ll)1e10;

int main()
{
    int n;
    cin>>n;
    vector<pii> arr(n);
    for(int i = 0; i<n; i++)
    {
        int x, y;
        cin>>x>>y;
        arr[i]={x, y};
    }
    int count  = 0 ;
    for(int i = 0; i<n; i++)
    {
        if(arr[i].ff == arr[i].ss)count++;
        else count = 0;
        if(count == 3)
        {
            cout<<"Yes"<<endl;
            return(0);
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

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

	boolean check(TreeSet<int[]> C, int[] S) {
		int[] Sl = C.lower(S);
		if (Sl != null && Sl[1] < S[1]) {
			return true;
		} else {
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	void solve(int N, int[][] S) {
		TreeSet<int[]>[] C = new TreeSet[N];
		for (int i = 0; i < N; ++i) {
			C[i] = new TreeSet<>(new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0]) {
						return Integer.compare(o1[0], o2[0]);
					} else {
						return -Integer.compare(o1[1], o2[1]);
					}
				}
			});
		}
		C[0].add(S[0]);
		int maxLen = 1;
		for (int i = 1; i < N; ++i) {
			int left = -1;
			int right = maxLen;
			while (right - left > 1) {
				int middle = (right + left) / 2;
				if (check(C[middle], S[i])) {
					left = middle;
				} else {
					right = middle;
				}
			}

			if (left + 1 == maxLen) {
				C[left + 1].add(S[i]);
				++maxLen;
				continue;
			} else {
				int[] tmp = C[left + 1].floor(S[i]);
				if (tmp != null && tmp[1] == S[i][1])
					continue;
				tmp = C[left + 1].higher(S[i]);
				while (tmp != null && S[i][1] <= tmp[1]) {
					C[left + 1].remove(tmp);
					tmp = C[left + 1].higher(S[i]);
				}
				C[left + 1].add(S[i]);
			}
		}
		System.out.println(maxLen);
	}

	int nextA(int a, int M) {
		return 36969 * (a & M) + (a >> 16);
	}

	int nextB(int b, int M) {
		return 18000 * (b & M) + (b >> 16);
	}

	int nextVal(int a, int b, int C) {
		return (C & ((a << 16) + b)) % 1000000;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			int A = sc.nextInt();
			int B = sc.nextInt();
			if (m == 0 && n == 0 && A == 0 && B == 0)
				break;
			int[][] S = new int[m + n][3];
			for (int i = 0; i < m; ++i) {
				S[i][0] = sc.nextInt();
				S[i][1] = sc.nextInt();
				S[i][2] = sc.nextInt();
			}
			int a = A, b = B, C = ~(1 << 31), M = (1 << 16) - 1;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < 3; ++j) {
					a = nextA(a, M);
					b = nextB(b, M);
					S[i + m][j] = nextVal(a, b, C);
				}
			}
			Arrays.sort(S, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0])
						return Integer.compare(o1[0], o2[0]);
					else if (o1[1] != o2[1]) {
						return -Integer.compare(o1[1], o2[1]);
					} else {
						return -Integer.compare(o1[2], o2[2]);
					}
				}
			});

			int[][] tmp = new int[m + n][2];
			for (int i = 0; i < m + n; ++i) {
				tmp[i][0] = S[i][1];
				tmp[i][1] = S[i][2];
			}
			solve(m + n, tmp);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 489104
import java.util.*;
public class Main {
    public static int max(int a, int b){return (a > b ? a : b);}
    public static int min(int a, int b){return (a < b ? a : b);}
    public static int gcd(int a, int b){return (b > 0 ? gcd(b, a % b) : a);}
    public static int lcm(int a, int b){return a / gcd(a, b) * b;}
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int A[] = new int[101010];
        int L[] = new int[101010];
        int R[] = new int[101010];
        for(int i = 1; i <= N; i++){
            A[i] = sc.nextInt();
            L[i] = 0;
            R[i] = 0;
        }
        L[1] = A[1];
        for(int i = 2; i <= N; i++)L[i] = gcd(L[i - 1], A[i]);
        R[N] = A[N];
        for(int i = N - 1; i >= 1; i--)R[i] = gcd(R[i + 1], A[i]);
        // for(int i = 1; i <= N; i++)System.out.print(L[i] + (i == N ? "\n" : " "));
        // for(int i = 1; i <= N; i++)System.out.print(R[i] + (i == N ? "\n" : " "));
        int ans = max(L[N - 1], R[2]);
        for(int i = 2; i < N; i++)ans = max(ans, gcd(L[i - 1], R[i + 1]));
        System.out.println(ans);
    }
}


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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  ll ans = 1;
  ll min_v = 2*100000;
  min_v = min(min_v, p[0]);
  ll max_v = p[0];
  for(int i=1; i<=n-1; i++){
    if (min_v >= p[i]) {
      //cout << p[i] << endl;
      min_v = min(min_v, p[i]);
      ans++;
    }else {
      max_v = p[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
C_S_F = [[int(i) for i in input().split()] for j in range(N-1)]
#print(C_S_F[1][1])

for i in range(N-1):
    #print('i={0}'.format(i))
    TIME = C_S_F[i][0] + C_S_F[i][1]
    for j in range(i,N-2):
       # print('j={0}'.format(j))
        if TIME < C_S_F[j+1][1]:
            TIME = C_S_F[j+1][1]+C_S_F[j+1][0]
        else:
            if TIME%C_S_F[j+1][2] != 0:
                TIME += C_S_F[j+1][2]-TIME%C_S_F[j+1][2]+C_S_F[j+1][0]; 
            else:
                    TIME += C_S_F[j+1][0]
    print(TIME)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0 ; i < (int)(n) ; i++)
typedef long long ll;
////////////////////////////////////////////////
int main() {
    int n;
    string c;
    cin >> n >> c;
    int r;
    r = count(c.begin(), c.end(), 'R');
    int ans = 0;
    rep(i,r){
        if (c.at(i)=='W') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

#[allow(non_snake_case)]
fn main() {
    input![S_a: String, S_b: String, S_c: String];
    let ans = ['A', 'B', 'C'];
    let mut v = vec![vec![]; 3];
    v[0] = S_a.chars().collect();
    v[1] = S_b.chars().collect();
    v[2] = S_c.chars().collect();
    let mut current = 0;
    loop {
        if v[current].len() == 0 {
            println!("{}", ans[current]);
            std::process::exit(0);
        }
        let c = v[current][0] as usize - 'a' as usize;
        v[current].remove(0);
        current = c;
    }
}


Measured memory_bytes: 2140
#include <iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long

int main() {
	int n,q,t;
	string name;
	queue<pair<string,int>> Q;//????????????????????\???
	pair<string, int> process;//?????????????????\???
	int allTime=0,time;

	//??\???
	cin>>n>>q;
	REP(i, n) {
		cin>>name>>t;
		Q.push(make_pair(name,t));
	}
	//????????\??¬????????§???
	while (!Q.empty()) {
		process=Q.front(); Q.pop();  //????????????
		time=min(process.second,q);  //q????????????????????????????????????????????????
		process.second-=time;        //?????????
		allTime+=time;               //?????????????¨????
		if(process.second>0)
			Q.push(process);//?????????????????????????????°?????\????????????
		else
			cout<<process.first<<" "<<allTime<<endl;
	}
	return 0;
}

Measured memory_bytes: 6332
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N-2):
        ans += min(B[i], B[i+1])
    ans += B[-1] + B[0]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<time.h>
typedef long long ll;
using namespace std;
double maxSum(double arr[], int n, int k)
{
    double res = 0;
    for (int i=0; i<k; i++)
       res += arr[i];
    double curr_sum = res;
    for (int i=k; i<n; i++)
    {
       curr_sum += arr[i] - arr[i-k];
       res = max(res, curr_sum);
    }

    return res;
}
int main()
{
    int n,k,i,j;
    cin>>n>>k;
    double ara[n+5];
    for(i=0;i<n;i++)
        cin>>ara[i];
    printf("%.12f\n",((double)(maxSum(ara,n,k)+k)/2.0));
    return 0;
}


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

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

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

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

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

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

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

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

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

int main(void){
    int N,K; cin >> N >> K;
    VI a(N); REP(i,N) cin >> a[i];
    ll ans = LL_INF;
    REP(i,1<<N){
        bitset<15> bit(i);
        if(bit.count() < K) continue;
        int mx = a[0];
        ll tmp = 0;
        FOR(j,1,N){
            int n = 0;
            if(bit[j] == 1){
                n = max(0, mx+1-a[j]);
                tmp += n;
            }
            chmax(mx, a[j]+n);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
// #define ll long long int
// #define ld long double
// #define pi pair<int,int>
// #define all(x) x.begin(), x.end()
// #define allr(x) x.rbegin(), x.rend()
// #define sz(x) ((int)x.size())
// #define ln(x) ((int)x.length())
// #define mp make_pair
// #define pb push_back
// #define ff first
// #define ss second
// #define endl '\n'
// #define dbg(x) cout<<#x<<": "<<x<<endl
// #define clr(x,v) memset(x, v, sizeof(x))
// #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// using namespace std;
// const double eps = 1e-9;
// const double PI = acos(-1.0);
// const ll mod = 1e9 + 7;
// const int MAXN = 1e6 + 5;

// void cp()
// {
//     int n;
//     cin >> n;
//     vector<ll> arr(n);
//     for(ll &x : arr)
//         cin >> x;
//     ll pref = 0;
//     ll sum = 0;
//     for(int i = 0; i < n; i++)
//     {
//         sum = (sum + (pref % mod * arr[i] % mod) % mod) % mod;
//         pref = (pref % mod + arr[i] % mod) % mod;
//     }
//     cout << sum;
// }

// int main()
// {
//     FASTIO;
//     int t;
//     t = 1;
//     // cin >> t;
//     while(t--)
//     {
//         cp();
//     }
//     return 0;
// }
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n; 
    vector<long long int> vec(n);
    for(int i=0;i<n;++i) cin >> vec[i];
    vector<long long int> pre(n);
    pre[0] = vec[0];
    for(int i=1;i<n;++i) pre[i] = pre[i-1] + vec[i];
    long long int res = 0;
    for(int i=1;i<n;++i){
        res = ( res%1000000007 + ((long long int)(vec[i]%1000000007)*(pre[i-1]%1000000007))%1000000007 ) % 1000000007;
    }
    cout << res << '\n';
    return 0;
}


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

using namespace std;

int main()
{
    int h,w,n;
    char a[105][105];
    set<int> x,y;
    cin >> h  >> w;
    for(int i = 0;i < h;i++)
        scanf("%s",a[i]);

    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            if(a[i][j]=='#')
            {
                x.insert(i);
                y.insert(j);
            }
        }
    }
    set<int>::iterator ix;
    set<int>::iterator iy;
    for(ix= x.begin();ix!=x.end();ix++)
    {
        for(iy=y.begin();iy!=y.end();iy++)
        {
            cout<<a[*ix][*iy];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	if(c>=a+b&&c*c-2*a*c+a*a-2*a*b+b*b-2*b*c>0) cout<<"Yes";
	else                                        cout<<"No"; 
	return 0;
}

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

using namespace std;

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

	string s, t;
	cin >> s >> t;
	int ans=t.size();
	for(int i=0; i+t.size()-1<s.size(); i++){
        string tmp=s.substr(i, t.size());
        int cnt=0;
        for(int j=0; j<t.size(); j++){
            if(tmp[j]!=t[j])
                cnt++;
        }
        ans=min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3660
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {
	int H, W;
	scanf("%d %d", &H, &W);
	string s[50];
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			bool paintable = false;
			if (s[i][j] != '#') continue;
			if (j != W - 1 && s[i][j + 1] == '#') paintable = true;
			if (j != 0     && s[i][j - 1] == '#') paintable = true;
			if (i != H - 1 && s[i + 1][j] == '#') paintable = true;
			if (i != 0     && s[i - 1][j] == '#') paintable = true;
			// cout << i << " " << j << " " << paintable << "\n";
			if (!paintable) {
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;

    int xx=abs(sx-tx),yy=abs(sy-ty);

    string go,back;
    rep(i,xx)
        go.push_back('R');
    rep(i,yy)
        go.push_back('U');

    rep(i,xx)
        back.push_back('L');
    rep(i,yy)
        back.push_back('D');

    cout<<go<<back<<"DR"<<go<<"ULUL"<<back<<"DR"<<endl;

}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}

int32_t main()
{
	c_p_c();
	int n, m; cin >> n >> m;
	map<pii, vector<pii> > adj;

	string arr[n];

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

	//int d[20][20][20][20];

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			for (int k = 0; k < n; ++k)
				for (int l = 0; l < m; ++l)
				{
					if (abs(i - k) + abs(j - l) == 1 && arr[i][j] == '.' && arr[k][l] == '.')
						adj[ {i, j}].pb({k, l});
				}

	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			map<pii, int> d;
			d[ {i, j}] = 0;
			queue<pii> q;
			q.push({i, j});

			while (!q.empty())
			{
				pii tp = q.front();
				q.pop();

				for (auto nb : adj[tp])
					if (!d.count(nb))
					{
						d[nb] = d[tp] + 1;
						ans = max(ans, d[nb]);
						q.push(nb);
					}
			}
		}
	}

	/*for (auto el : adj)
	{
		cout << el.ff.ff << ' ' << el.ff.ff << "***\n";

		for (auto n : el.ss)
			cout << n.ff << ' ' << n.ss << '\n';
	}*/

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {


  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[][] h = new int[3][N];
    for (int i = 0; i < N; i++) {
      h[0][i] = sc.nextInt();
      h[1][i] = sc.nextInt();
      h[2][i] = sc.nextInt();
    }
    int[][] dp = new int[3][N];
    dp[0][0] = h[0][0];
    dp[1][0] = h[1][0];
    dp[2][0] = h[2][0];

    for (int i = 1; i < N ; i++) {
        dp[0][i] = Math.max(
            (dp[1][i-1]+h[0][i]),
            (dp[2][i-1]+h[0][i])
        );
      dp[1][i] = Math.max(
          (dp[0][i-1]+h[1][i]),
          (dp[2][i-1]+h[1][i])
      );
      dp[2][i] = Math.max(
          (dp[1][i-1]+h[2][i]),
          (dp[0][i-1]+h[2][i])
      );
    }

    System.out.println(Math.max(Math.max(dp[0][N-1],dp[1][N-1]),dp[2][N-1]));
  }


}


Measured memory_bytes: 93684
N=int(input())
x=[]
u=[]
s=0
for i in range(N):
    A,B=input().split()
    x.append(float(A))
    u.append(B)
for i in range(N):
    a=x[i]
    if u[i]=='JPY':
        s+=a
    else:
        s+=a*380000
print(s)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

double d1,d2;
int X1,Y1,X2,Y2;
int N;
int XX[202020],YY[202020];

vector<int> LIS(vector<int>& v) {
	int i,N=v.size();
	vector<int> dp(N,1<<30),id(N);
	FOR(i,v.size()) {
		id[i] = lower_bound(dp.begin(),dp.end(),v[i]) - dp.begin();
		dp[id[i]] = v[i];
	}
	int nl = *max_element(id.begin(),id.end());
	vector<int> ret(nl+1);
	FOR(i,N) if(id[N-1-i] == nl) ret[nl--] = v[N-1-i];
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	double PI=atan(1)*4;
	d1=20-20*PI/4;
	d2=20*PI/2-20;
	
	cin>>X1>>Y1>>X2>>Y2;
	cin>>N;
	FOR(i,N) {
		cin>>XX[i]>>YY[i];
		if(XX[i]<min(X1,X2) || XX[i]>max(X1,X2) || YY[i]<min(Y1,Y2) || YY[i]>max(Y1,Y2)) i--,N--;
	}
	
	X2-=X1;
	Y2-=Y1;
	vector<pair<int,int>> V;
	FOR(i,N) {
		XX[i]-=X1;
		if(X2<0) XX[i]=-XX[i];
		YY[i]-=Y1;
		if(Y2<0) YY[i]=-YY[i];
		V.push_back({XX[i],YY[i]});
	}
	if(X2<0) X2=-X2;
	if(Y2<0) Y2=-Y2;
	
	double ret=100.0*(X2+Y2);
	if(N) {
		vector<int> V2;
		
		sort(ALL(V));
		FORR(v,V) V2.push_back(v.second);
		auto V3=LIS(V2);
		
		if(V3.size()==min(X2,Y2)+1) {
			ret+=d2-d1*(V3.size()-1);
		}
		else {
			ret-=d1*V3.size();
		}
	}
	_P("%.12lf\n",ret);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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


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

    string s;
    cin>>s;
    int n=s.size();
    ll ans=1;
    ll cnt[26]={};
    for(int i=0;i<n;i++){
        cnt[s[i]-'a']++;
    }
    ll m=n;
    for(int i=0;i<n;i++){
        m--;
        cnt[s[i]-'a']--;
        ans += m-cnt[s[i]-'a'];
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX powl(10,18)

int main(){
    int n;
    cin>>n;
    vector<ll> a(100005);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=1;
    for(int i=0;i<n;i++){
        if((MAX/ans)>=a[i]){
            ans*=a[i];
        }
        else{
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3988
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


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

static const double pi = 3.141592653589793;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }
  vector<int> ans(N, -1);
  queue<int> que;
  que.push(0);
  while (que.size()) {
    int now = que.front();
    que.pop();
    for (int node : v[now]) {
      if (ans[node] == -1) {
        ans[node] = now;
        que.push(node);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 10124
n, m = map(int, input().split())

towns = []  # List of (p, y, i)

for i in range(m):
    p, y = map(int, input().split())
    towns.append([p, y, i])

towns = sorted(towns, key=lambda tup: (tup[0], tup[1]))

p_cur = 0
x = 1
for i in range(m):
    if (towns[i][0] == p_cur):
        x += 1
    else:
        x = 1
        p_cur = towns[i][0]

    towns[i][1] = x

towns = sorted(towns, key=lambda tup: tup[2])

for i in range(m):
    print('{:06d}{:06d}'.format(towns[i][0], towns[i][1]))


Measured memory_bytes: 32408
import java.util.Scanner;

//Infinity Maze
public class Main{
	
	int[][] move = {{-1,0},{0,1},{1,0},{0,-1}};
	char[] str = {'N','E','S','W'};
	
	int h, w;
	long L;
	
	void run()  {
		Scanner sc = new Scanner(System.in);
		for(;;){
			h = sc.nextInt(); w = sc.nextInt(); L = sc.nextLong();
			if((h|w|L)==0)break;
			char[][] map = new char[h][w];
			int si = 0, sj = 0, d = 0;
			for(int i=0;i<h;i++){
				map[i] = sc.next().toCharArray();
				for(int j=0;j<w;j++){
					if(map[i][j]=='N'){
						map[i][j] = '.';
						si = i; sj = j; d = 0;
					}
					else if(map[i][j]=='E'){
						map[i][j] = '.';
						si = i; sj = j;d = 1;
					}
					else if(map[i][j]=='S'){
						map[i][j] = '.';
						si = i; sj = j;d = 2;
					}
					else if(map[i][j]=='W'){
						map[i][j] = '.';
						si = i; sj = j;d = 3;
					}
				}
			}
			long[][][] u = new long[h][w][4];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int k=0;k<4;k++)u[i][j][k] = -1;
			u[si][sj][d] = 0;
			long step = 1;
			boolean skip = false;
			while(step<=L){
				int ni = si+move[d][0], nj = sj+move[d][1];
				for(;;){
					if(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]!='#')break;
					d = (d+1)%4;
					ni = si+move[d][0]; nj = sj+move[d][1];
				}
				si = ni; sj = nj;
				if(u[ni][nj][d]==-1||skip){
					u[ni][nj][d] = step;
				}
				else{
					skip = true;
					long dif = step-u[si][sj][d];
					long x = L - step;
					x%=dif;
					step = L-x;
				}
				step++;
			}
			System.out.println((si+1)+" "+(sj+1)+" "+str[d]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int num[10];
int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
        bool ok=false;
        if(abs(a-c)<=d)
            ok=true;
        else if(abs(a-b)<=d&&abs(b-c)<=d)
            ok=true;
        else
            ok=false;
        if(ok)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}


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

int dp[2][203][203][203] , H , W , sum[203][203];

int getarea(int x1 , int y1 , int x2 , int y2){return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];}

int main(){
	cin >> H >> W; char c;
	for(int i = 1 ; i <= H ; ++i) for(int j = 1 ; j <= W ; ++j){cin >> c; sum[i][j] = c == '.';}
	for(int i = 1 ; i <= H ; ++i) for(int j = 1 ; j <= W ; ++j) sum[i][j] += sum[i][j - 1];
	for(int i = 1 ; i <= H ; ++i) for(int j = 1 ; j <= W ; ++j) sum[i][j] += sum[i - 1][j];
	for(int i = 1 ; i <= H ; ++i)
		for(int j = 1 ; j <= W ; ++j){
			int pos = H;
			for(int k = j ; k <= W ; ++k){
				while(pos >= i && getarea(i , j , pos , k) && getarea(i , j , pos , k) != (pos - i + 1) * (k - j + 1))
					--pos;
				dp[0][i][j][k] = pos;
			}
		}
	int now = 0;
	for(int i = 0 ; i <= 100 ; ++i){
		if(dp[now][1][1][W] == H){cout << i; return 0;}
		memset(dp[now ^ 1] , 0 , sizeof(dp[0]));
		for(int j = 1 ; j <= H ; ++j)
			for(int k = 1 ; k <= W ; ++k){
				int pos = k;
				for(int l = k ; l <= W ; ++l){
					if(dp[now][j][k][l] == H){dp[now ^ 1][j][k][l] = H; continue;}
					dp[now ^ 1][j][k][l] = dp[now][dp[now][j][k][l] + 1][k][l];
					while(pos + 1 < l && dp[now][j][k][pos + 1] >= dp[now][j][pos + 2][l])
						++pos;
					dp[now ^ 1][j][k][l] = max(dp[now ^ 1][j][k][l] , min(dp[now][j][k][pos] , dp[now][j][pos + 1][l]));
					if(pos + 1 < l)
						dp[now ^ 1][j][k][l] = max(dp[now ^ 1][j][k][l] , min(dp[now][j][k][pos + 1] , dp[now][j][pos + 2][l]));
				}
			}
		now ^= 1;
	}
	assert(0); return 0;
}

Measured memory_bytes: 65920
#include<stdio.h>
int main(void)
{
	int n,k,x,y,a,b,c,d;
	scanf("%d %d %d %d",&n,&k,&x,&y);
	a=n-k;
	b=k*x;
	c=a*y;
	d=b+c;
	if(n<k){
		d=n*x;
	}
	printf("%d\n",d);
	return 0;
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


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

    rep(i, x + 1) {
        int t = i;
        int k = x - i;
        if (t * 2 + k * 4 == y) {
            prt("Yes");
            return 0;
        }
    }

    prt("No");

    return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

i64 dp[100010][13];
i64 q[6][10] = {
  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  {0, 10, 7, 4, 1, 11, 8, 5, 2, 12},
  {0, 9, 5, 1, 10, 6, 2, 11, 7, 3},
  {0, 12, 11, 10, 9, 8, 7, 6, 5, 4},
  {0, 3, 6, 9, 12, 2, 5, 8, 11, 1},
  {0, 4, 8, 12, 3, 7, 11, 2, 6, 10},
};

const i64 M = 1000000007;
signed main() {
  string S;
  cin >> S;
  i64 k = 0;
  dp[0][0] = 1;
  RREP(i, S.size()) {
    char c = S[i];
    if (c == '?') {
      REP(j, 10) {
        REP(r, 13) {
          (dp[k + 1][(r + q[k % 6][j]) % 13] += dp[k][r]) %= M;
        }
      }
    } else {
      i64 d = c - '0';
      REP(r, 13) {
        (dp[k + 1][(r + q[k % 6][d]) % 13] += dp[k][r]) %= M;
      }
    }
    k += 1;
  }
  cout << dp[k][5] << endl;
}


Measured memory_bytes: 10704