akhauriyash/Code-Regression huggingface dataset:
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };


int main()
{
	int t, n;
	int DX[6] = { 0,1,1,0,-1,-1 }, DY[6] = { 1,1,0,-1,-1,0 };
	while (cin >> t >> n&&t)
	{
		int z = 100;
		int a[200][200];
		memset(a, -1, sizeof a);
		FOR(i, n)
		{
			int x, y;
			cin >> x >> y;
			a[x+z][y+z] = -2;
		}
		pii st;
		cin >> st.first >> st.second;
		st.first += z;
		st.second += z;
		a[st.first][st.second] = t;
		queue<pii> que;
		que.push(st);
		int ans = 1;
		while (!que.empty())
		{
			pii now = que.front();
			que.pop();
			if (a[now.first][now.second] == 0)continue;
			for (int i = 0; i < 6; i++)
			{
				pii next = now;
				next.first += DX[i];
				next.second += DY[i];
				if (a[next.first][next.second] == -1)
				{
					a[next.first][next.second] = a[now.first][now.second] - 1;
					ans++;
					que.push(next);
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main() {
  
  string S1 = "AtCoder";
  string S2 = "hogehoge";
  string S3 = "Contest";
  char s1 = 'A';
  char s2 = 'x';
  char s3 = 'C';
  
  cin >> S1;
  cin >> S2;
  cin >> S3;
  
  s1 = S1.at(0);
  s2 = S2.at(0);
  s3 = S3.at(0);
  
  cout << s1 << s2 << s3 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int z=sc.nextInt();
		long w=sc.nextLong();
		ArrayList<Long> a = new ArrayList<>();
		for(int i=0; i<n; i++) {
			a.add(sc.nextLong());
		}
		if(n==1) {
			System.out.println(Math.abs( a.get(n-1)-w));
		}else {
			System.out.println( Math.max(Math.abs(a.get(n-1)-a.get(n-2)), Math.abs(a.get(n-1)-w)));
		}
		sc.close();
	}
}


Measured memory_bytes: 39640
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


N, M = map(int,input().split())
Xm = list(map(int,input().split()))
 
if N >= M:
  print(0)
  sys.exit()
  
Xm.sort()
ans = Xm[M-1]-Xm[0]
 
Li = [Xm[i+1]-Xm[i] for i in range(M-1)]
Li.sort(reverse=True)
ans -= sum(Li[0:N-1])
print(ans)

Measured memory_bytes: 16076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t H, W;
  cin >> H >> W;
  int64_t ans = 0;
  if(H %2 == 0){
    ans += (W+1)/2 * (H/2);
    ans += W/2 * (H/2);
  }
  else{
    ans += (W+1)/2 * ((H+1)/2);
    ans += W/2 * (H/2);
  }
  if(H == 1 || W == 1){
    ans = 1;
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ACookieExchanges solver = new ACookieExchanges();
    solver.solve(1, in, out);
    out.close();
  }

  static class ACookieExchanges {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();
      int cnt = 0;
      if (a == b && b == c && a % 2 == 0) {
        cnt = -1;
      }
      if (cnt == 0) {
        while (true) {
          if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
            break;
          }
          int tmpa = (b + c) / 2;
          int tmpb = (a + c) / 2;
          int tmpc = (a + b) / 2;
          a = tmpa;
          b = tmpb;
          c = tmpc;
          cnt++;
        }
      }
      out.println(cnt);
    }

  }
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  ll ans=k;
  rep(i,n-1){
    ans*=k-1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		BigDecimal A = sc.nextBigDecimal();
		BigDecimal B = sc.nextBigDecimal();
		System.out.println(A.multiply(B).setScale(0, BigDecimal.ROUND_DOWN));
	}
}

Measured memory_bytes: 37460
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] weight = new int[N];
        long[] value = new long[N];
        for(int n=0; n<N; n++){
            weight[n] = sc.nextInt();
            value[n]= sc.nextLong();
        }

        long[][] dp = new long[N+1][W+1];
        //dp[n][w] : choose items from first 'n' items, and the total weight is leq than w
        Arrays.fill(dp[0], 0);
        for(int n=1;n<=N;n++) for(int w=0; w<=W; w++){
            dp[n][w] = Math.max(dp[n-1][w], (w>0 ? dp[n][w-1] : 0));
            if(weight[n-1] <= w ) dp[n][w] = Math.max(dp[n][w], dp[n-1][w-weight[n-1]]+value[n-1]);

        }
        //for(int n=0; n<=N; n++) System.err.println(Arrays.toString(dp[n]));
        System.out.println(dp[N][W]);
    }
}


Measured memory_bytes: 138452
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

dx = [0, 1, 0, -1, 1, 1, -1, -1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
def DFS(i, j):
	global w, h
	for x in range(8):
		nx = j + dx[x]
		ny = i + dy[x]
		if 0 <= nx <= w-1 and 0 <= ny <= h-1 and c[ny][nx]==1:
			c[ny][nx] = 0
			DFS(ny, nx)

ans = []
while 1:
	w, h = MAP()
	if [w, h] == [0, 0]:
		break
	c = [LIST() for _ in range(h)]

	count = 0
	for i in range(h):
		for j in range(w):
			if c[i][j] == 1:
				c[i][j] = 0
				DFS(i, j)
				count += 1
	ans.append(count)

for i in ans:
	print(i)



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

int a, b, k, d[105], x;

int main() {

    cin >> a >> b >> k;
    for(int i=1; i<=100; i++){
        if(a%i==0 && b%i==0){
            d[x]=i;
            x++;
        }
    }
    cout << d[x-k];
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


public class AtCoder {
    static int n, a;
    static int[] x,y;
    static long[,,] dp;
    static void Main() {

        long cnt = 0;
        string[] ss = Console.ReadLine().Split(' ');
        n = int.Parse(ss[0]);
        a = int.Parse(ss[1]);
        y = new int[n];
        x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        for(int i = 0; i < n; i++) {
            y[i] = x[i] - a;
        }
        int X = Math.Max(x.Max(), a);
        dp = new long[n+1, n+1, (n * X)+1];
       for(int s = 0; s <= n*X; s++) {
            for(int k = 0; k <= n; k++) {
                for(int j = 0; j <= n ; j++) {
                    if (j == 0 && k == 0 && s == 0) {
                        dp[j, k, s] = 1;
                    }
                    else if (j >= 1 && s < x[j - 1]) {
                        dp[j, k, s] = dp[j - 1, k, s];
                    }
                    else if (j >= 1 && k >= 1 && s >= x[j - 1]) {
                        dp[j, k, s] = dp[j - 1, k, s] + dp[j - 1, k - 1, s - x[j - 1]];
                    }
                }
            }
        }

       for(int i = 1; i <= n; i++) {
            if (a*i >n*X) {
                continue;
            }
            cnt += dp[n, i, a * i];
        }
        Console.WriteLine(cnt);

    }
}




Measured memory_bytes: 51928
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int bit = 0;
        for (int i = 0; i < N; i++) {
            bit |= Integer.parseInt(sc.next());
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

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

//関数
//main関数
int main() {
    
    
    
    //入力
    string S;
    cin>>S;
    
    
    
    
    //計算
    int ans=0,count =0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='A' ||S.at(i)=='C' ||S.at(i)=='G' ||S.at(i)=='T'){
            count++;
        }else{
            count=0;
        }
        
        ans=max(ans,count);
    }
    
    //出力
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define five 100005
#define six 1000006
#define seven 10000007
#define eight 100000008
#define ll long long
#define nl '\n'
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    std::ios_base::sync_with_stdio(0);

    int w, a, b;
    cin >> w >> a >> b;
    if( a > b ) swap(a, b);

    if( (a+w) >= b ){
        cout << 0 << nl;
    }else
        cout << abs((a+w)-b) << nl;

    return 0;
}

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

int main()
{
    // cout << "Hello World!" << endl;
    ios::sync_with_stdio(false);
    long long x,y,extra=0;
    cin>>x>>y;
    if(x==1&&y==1){
        extra=400000;
    }
    
    if(x==3){
        x=100000;
    }
    else if(x==2){
        x=200000;
    }
    else if(x==1){
        x=300000;
    }
    else{
        x=0;
    }
    
    
    if(y==3){
        y=100000;
    }
    else if(y==2){
        y=200000;
    }
    else if(y==1){
        y=300000;
    }
    else{
        y=0;
    }
    
    
    cout<<x+y+extra;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int box[][] = new int[n][3];
    int x,y,h;
    boolean once = true;
    //1件先読み 理由:初期値ないかもしれないって怒られるから
    box[0][0] = sc.nextInt(); box[0][1] = sc.nextInt(); box[0][2] = sc.nextInt();
    x = box[0][0]; y = box[0][1]; h = box[0][2];
    for(int i=1; i<n; i++){
      box[i][0] = sc.nextInt();
      box[i][1] = sc.nextInt();
      box[i][2] = sc.nextInt();
      if(once && box[i][2] > 0){
        x = box[i][0]; y = box[i][1]; h = box[i][2];
        once = false;
      }
    }
    for(int cx=0; cx<=100; cx++){
      for(int cy=0; cy<=100; cy++){
        int ch = h + Math.abs(cx - x) + Math.abs(cy - y);
        boolean answer = true;
        for(int i=0; i<n; i++){
          int ch_x,ch_y,ch_h,calc_h;
          ch_x = box[i][0];
          ch_y = box[i][1];
          ch_h = box[i][2];
          calc_h = Math.max(ch - Math.abs(cx - ch_x) - Math.abs(cy - ch_y),0);
          if(ch_h != calc_h) answer = false;
        }//i
        if(answer) System.out.println(cx + " " + cy + " " + ch);
      }//cy
    }//c
  }
}


Measured memory_bytes: 22192
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
//    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const S = input[0].split(' ')[0];
    const T = input[1].split(' ')[0];

    var count = 0;
    for (var i = 0; i < 3; i++) {
        var char1 = S.charAt(i);
        var char2 = T.charAt(i);
        if (char1 === char2) {
            count++;
        }
    }

    console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200001];
vector<vector<LL>> adj;

vector<LL> ans;

vector<LL> LIS_array;
bool used[200001] = {};
void dfs(LL now){
	used[now] = 1;
	bool pop_flag = false;
	int insert_index = int(lower_bound(LIS_array.begin(),LIS_array.end(),A[now])-LIS_array.begin());
	LL prev_num;

	if(insert_index==LIS_array.size()){
		pop_flag = true;
		LIS_array.push_back(A[now]);
	}else{
		prev_num = LIS_array[insert_index];
		LIS_array[insert_index] = A[now];
	}

	ans[now] = LIS_array.size();

	// cout << now << endl;
	// for(int i=0;i<LIS_array.size();i++) cout << LIS_array[i] << " ";
	// cout << endl;

	for(LL next:adj[now]){
		if(used[next]) continue;
		//cout << now << "->" << next << endl;
		dfs(next);
		//cout << now << "<-" << next << endl;
	}

	if(pop_flag) LIS_array.pop_back();
	else LIS_array[insert_index] = prev_num;
}

void solve(){
	ans = vector<LL>(N+1);
	dfs(1);
}

int main(){
    cin >> N;
    for(int i=1;i<=N;i++) cin >> A[i];
    adj = vector<vector<LL>>(N+1);
	for(int i=0;i<=N-2;i++){
		LL u,v;cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

    solve();

    for(int i=1;i<=N;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 28428
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int a, b; cin >> a >> b;
  int ans = max(a+b,a-b);
  chmax(ans,a*b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}


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

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

    vector<int> colors(9, 0);
    int score, idx;
    rep(i, 0, n)
    {
        cin >> score;
        idx = score / 400;
        colors[min(idx, 8)] ++;
    }

    int ans = 0;
    rep(i, 0, 8)
        if (colors[i] > 0) ans++;

    if (ans == 0)
    {
        cout << int(colors[8] > 0) << ' ' << colors[8] << endl;
        return 0;
    }

    cout << ans << ' ' << ans + colors[8];
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static boolean g[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		g = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int a = Integer.parseInt(sc.next()) - 1;
			int b = Integer.parseInt(sc.next()) - 1;
			g[a][b] = g[b][a] = true;
		}
		boolean[] visited = new boolean[n];
		visited[0] = true;
		System.out.println(dfs(0,n,visited));
	}
	public static int dfs(int v, int n, boolean[] visited) {
		boolean visitedAll = true;
		for (int i = 0; i < n; i++)
			if (!visited[i])
				visitedAll = false;
		if (visitedAll)
			return 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (g[v][i] == false) continue;
			if (visited[i]) continue;
			visited[i] = true;
			ans += dfs(i, n, visited);
			visited[i] = false;
		}
		return ans;
	}
}

Measured memory_bytes: 21332
def rr(): return input().rstrip()
def rri(): return int(rr())
def rrl(): return list(map(int, rr().split()))
def rrt(): return tuple(map(int, rr().split()))
from collections import defaultdict
def mus(d=lambda: 0): return defaultdict(lambda: defaultdict(d))
def dd0(d=lambda: 0): return defaultdict(d)
def ms(x, y, d=0): return [[0]*y for i in range(x)]
def ar(x, d=0): return [d]*x
def ppm(m, n=0, x=0, y=0): print("\n".join(("\t".join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))
def ppa(a, n): print("\t".join(map(str, a[0:n])))
def ppl(a=0, x=[1]): x[0]=a or (x[0]+1); print("-"+"- -"*14+"-# "+str(x[0]-2)+" #-"+"- -"*14+"-")
def fltn(a): (i for sub in a for i in sub)
def yn(x): return "YES" if x else "NO"
from itertools import accumulate
from itertools import groupby
def grp(x): return ((i, sum(1 for _ in g)) for i, g in groupby(x))
import math
#def rnar(): return (*rrl(), rrl())
#def rn(): return (*rrl(),)
def dpp(a, b=""): print(")#| {} |#(o) ? {} ? (".format(a, b))

def read():
    a, b = rrl();
    return (a, b, rrl())
    return (0,)

def solve(n, k, arr):
    if k > len(arr):
        k = len(arr)
    dp = ar(n)
    dp[0] = 0
    for i in range(1, k):
        dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(0, i))
        #dpp("HAr2", "HA")

    for i in range(k, n):
        #dpp("HA", i)
        dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(i-k, i))

    #dpp(dp)
    ans = dp[-1]

    return ans

if __name__ == "__main__":
    #test_count = rri()
    test_count = 1
    for _ in range(test_count):
        input_data = read()
        result = solve(*input_data)
        print(result)


Measured memory_bytes: 53856
#include<iostream>

int main()
{
	char abacus[8][5];
	
	bool first=true;
	while(1)
	{
		int num;
		std::cin>>num;
		if(std::cin.eof())break;
		
		for(int c=4;c>=0;c--)
		{
			int digit=num%10;
			num/=10;
			int q=digit/5;
			int s=digit%5;
			int i=0;
			if(q==1)
			{
				abacus[0][c]=' ';
				abacus[1][c]='*';
			}
			else
			{
				abacus[0][c]='*';
				abacus[1][c]=' ';
			}
			abacus[2][c]='=';
			
			for(i=3;i<3+s;i++)
			{
				abacus[i][c]='*';
			}
			abacus[i++][c]=' ';
			for(;i<8;i++)
			{
				abacus[i][c]='*';
			}
		}
		if(first){first=false;}
		else{std::cout<<std::endl;}
		for(int i=0;i<8;i++)
		{
			for(int j=0;j<5;j++)
			{
				std::cout<<abacus[i][j];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 856
# region header
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
import copy
# @lru_cache(maxsize=None)
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
# endregion
# region input function


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


# endregion

n = inp()
cnt = 0
for i in range(n):
    a, b = inpl()
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 69536
#include<stdio.h>
#include<stdlib.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a,b,i,d[100010];
  scanf("%d %d %d",&n,&a,&b);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  if(n==1){
    printf("%d\n",abs(d[0]-b));
    return 0;
  }
  printf("%d\n",MAX(abs(d[n-1]-b),abs(d[n-2]-d[n-1])));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>ab;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		ab.push_back({ b,a });
	}

	vector<int> land(n);
	for (int i = 0; i < n; i++) {
		land[i] = i;
	}

	sort(ab.begin(), ab.end());
	int cnt = 0;

	int t = 0;

	// 終了時刻が短い者を選んでいく
	for (int i = 0; i < m; i++) {
		if (t <= ab[i].second) {
			cnt++;
			t = ab[i].first;
		}
	}

	cout << cnt << endl;


}

Measured memory_bytes: 1400
# -*- coding: utf-8 -*-
"""
Created on Wed Jan  2 09:59:01 2019

@author: Yamazaki Kenichi
"""

N,K = map(int, input().split())
h = [int(input()) for i in range(N)]

h.sort()

ans = h[K-1] - h[0]

for i in range(N-K+1):
   temp = h[K-1+i] - h[0+i]
   ans = min(ans,temp)
print(ans)


Measured memory_bytes: 7384
//abc153_e.cpp
//Sat Feb 22 18:22:56 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 23372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll h,n;
	cin >> h >> n;

	ll a[n],b[n];
	for (int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}

	ll dp[2][10010];
	for (int i=0;i<2;i++){
		for (int j=0;j<10010;j++){
			dp[i][j] = LLINF;
		}
	}

	dp[0][0] = 0;

	for (int i=0;i<n;i++){
		for (int j=0;j<h+1;j++){
			dp[(i+1)%2][j] = min(dp[i%2][j],dp[(i+1)%2][j]);
			dp[(i+1)%2][min(j+a[i],h)] = min(dp[(i+1)%2][min(j+a[i],h)],dp[(i+1)%2][j]+b[i]);
		}
//		for (int j=0;j<h+1;j++){
//			if (dp[(i+1)%2][j]==LLINF){
//				cout << "INF" << " ";
//			}else {
//				cout << dp[(i+1)%2][j] << " ";
//			}
//		}
//		printf("\n");
	}


	cout << dp[n%2][h] << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	vector<long long int>w(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> w[i];
	}
	long long int ans = 0;
	long long int box = 0;
	long long int bag = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] & 1) {
			box ^= 1;
		}
		if (w[i] & 1) {
			bag ^= 1;
		}
	}
	ans ^= ((N & 1) ^ box)&bag;
	ans ^= ((N & 1) ^ bag)&box;
	for (int i = 1; i < 29; i++) {
		vector<pair<int,int>>vv(N);
		vector<pair<int,int>>ww(N + 1);
		long long int add = 0;
		long long int ow = 0;
		for (int j = 0; j < N; j++) {
			vv[j].first = v[j] % (1 << i);
			vv[j].second = v[j];
			ww[j].first = w[j] % (1 << i);
			ww[j].second = w[j];
			if ((w[j] >> i) & 1) {
				ow ^= 1;
			}
		}
		ww[N].first = INT_MAX;
		sort(vv.begin(), vv.end());
		sort(ww.begin(), ww.end());
		int index = N;
		for (int j = 0; j < N; j++) {
			if ((vv[j].second >> i) & 1) {
				add ^= (N - ow) & 1;
			}
			else {
				add ^= ow & 1;
			}
			while (index&&ww[index - 1].first + vv[j].first >= (1LL << i)) {
				index--;
			}
			add ^= (N - index) & 1;
		}
		if (add) {
			ans ^= (add << i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8584
#include<stdio.h>
main(){
  int stu[31]={0};
  int a,b;
  for(a=1;a<29;a++){
    scanf("%d",&b);
    stu[b]=1;
  }
  for(a=1;a<31;a++){
    if(stu[a]==0){
      printf("%d\n",a);
    }
  }
  return 0;
}

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

using namespace std;
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ld long double
#define MOD 1000000007
#define endl "\n"

int gcd(int a,int b)
{
    if(a<b)
        swap(a,b);
    while(b)
    {
        int tmp=b;
        b=a%b;
        a=tmp;
    }
    return b;
}
bool isPrime(int n)
{
    if(n<2)
        return 0;
    if(n<4)
        return 1;
    if(n%2==0 || n%3==0)
        return 0;
    for(int i=5;i*i<=n;i+=6)
    {
        if(n%i==0 || n%(i+2)==0)
            return 0;
    }
    return 1;
}
int modexpo(int x,int p)
{
    int res=1;
    x=x%MOD;
    while(p)
    {
        if(p%2)
            res=res*x;
        p>>=1;
        x=x*x%MOD;
        res%=MOD;
    }
    return res;
}

int main()
{
    IOS;
    ll a,b,k;
    cin >>a>>b>>k;
    if((b+a)<=k)
    {
        cout <<0<<' '<<0<<endl;
        return 0;
    }
    ll s=a+b;
    if(a<=k)
    {
        cout <<0<<' '<< (b-(k-a)) <<endl;
    }
    else
    {
        cout <<(a-k)<<' '<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 21:49:13 2020

@author: Kanaru Sato
"""

N = int(input())
s = input()

dict = {'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15, 'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22, 'W': 23, 'X': 24, 'Y': 25, 'Z': 0}
slist = []
[slist.append(s[i]) for i in range(0,len(s))]

for i in range(0, len(s)):
    n = dict[slist[i]]
    n = (n+N)%26
    slist[i] = [k for k in dict.keys() if dict[k]==n][0]

ans = ""
for i in range(0,len(slist)):
    ans = ans+slist[i]
print(ans)

Measured memory_bytes: 3444
#include <algorithm>
#include <cstdio>
#include <functional>

using namespace std;

int main(){
    int a, b;
    while(scanf("%d %d", &a, &b) != EOF){
         a = a + b;
         int i = 0;
         while(a > 0){ a = a / 10; i++; }
         printf("%d\n", i);

    }
    return 0;

}

Measured memory_bytes: 1028
A,B,C=map(int,input().split())
if A==B and B==C and A%2==0:
	print(-1)
	exit()
else:
	count=0
	while(1):
		if A%2==1 or B%2==1 or C%2==1:
			print(count)
			exit()
		else:
			a=A//2
			b=B//2
			c=C//2
			A=b+c
			B=a+c
			C=a+b
			count+=1

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
  int k;
  cin >> k;
  cout << a[k - 1]
  << endl;
  return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vector<int> h(N);
  int pre = 0;
  int mi = INF;
  for (int i = 0; i < N; i++) {
    if (s[i] == '(')
      h[i] = pre + 1;
    else
      h[i] = pre - 1;
    chmin(mi, h[i]);
    pre = h[i];
  }
  if (mi < 0)
    for (int i = 0; i < (-mi); i++) cout << '(';
  cout << s;
  int end = h.back() - min(0, mi);
  for (int i = 0; i < end; i++) { cout << ')'; }
  cout << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

using namespace std;

void Main()
{
	int x;
	cin >> x;

	int ans = 0;
	ans += x / 500 * 1000;
	x %= 500;
	ans += x / 5 * 5;

	cout << ans << endl;
}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v) cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash{
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1>{}(p.first);
		auto h2 = hash<T2>{}(p.second);
		return h1 ^ h2;
	}
};

int fast_mod(int x, int m = MOD) {
	while(x <= m) x -= m;
	if(x < 0) x += m;
	return x;
}

int mod_add(int x, int y) {
	return fast_mod(x + y);
}

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

	string s;
	cin >> s;

	int n = sz(s);

	int cnt = 0;

	for(int i = 0 ; i < n - i - 1 ; ++i) {
		cnt += (s[i] != s[n - i - 1]);
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
#define in(A, n)                                                                                                       \
    rep(i, n) {                                                                                                        \
        cin >> f;                                                                                                      \
        A.push_back(f);                                                                                                \
    }

void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() { cin >> x; }
void solve() { print(1 - x); }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void dfs(int cur, int dep, vector<int>& ret) {
  ret.push_back(cur);
  if(dep == 9) return;
  else {
    for(int a : {3,5,7}) {
      dfs(cur * 10 + a, dep + 1, ret);
    }
  }
}

int main() {
  vector<int> v;
  dfs(0, 0, v);

  int n; cin >> n;
  int ans = 0;
  for(auto a : v) {
    if (a > n) continue;
    bool cnt[10] = {};
    while(a) {
      int digit = a % 10;
      a /= 10;
      cnt[digit] = true;
    }
    if(cnt[3] && cnt[5] && cnt[7]) ans++;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512
n = int(input())
dict = {
3 : 61,
4 : 230 ,
5 : 865 ,
6 : 3247 ,
7 : 12185 ,
8 : 45719 ,
9 : 171531 ,
10 : 643550 ,
11 : 2414454 ,
12 : 9058467 ,
13 : 33985227 ,
14 : 127504505 ,
15 : 478366600 ,
16 : 794717734 ,
17 : 733354121 ,
18 : 261943303 ,
19 : 776803305 ,
20 : 580025381 ,
21 : 51688048 ,
22 : 44657419 ,
23 : 737209731 ,
24 : 604119499 ,
25 : 159693437 ,
26 : 858533109 ,
27 : 639056669 ,
28 : 549054109 ,
29 : 996291083 ,
30 : 531294469 ,
31 : 23314687 ,
32 : 783022045 ,
33 : 855462856 ,
34 : 649970414 ,
35 : 68697295 ,
36 : 409213624 ,
37 : 604356692 ,
38 : 88638656 ,
39 : 978442997 ,
40 : 534833116 ,
41 : 763737161 ,
42 : 785892908 ,
43 : 123883652 ,
44 : 639213333 ,
45 : 181836645 ,
46 : 998121103 ,
47 : 124885216 ,
48 : 501575626 ,
49 : 39816123 ,
50 : 113468411 ,
51 : 799008836 ,
52 : 775465589 ,
53 : 256852905 ,
54 : 664630886 ,
55 : 971550783 ,
56 : 751629411 ,
57 : 51018086 ,
58 : 702530485 ,
59 : 725438992 ,
60 : 696683714 ,
61 : 792638194 ,
62 : 221791721 ,
63 : 149602322 ,
64 : 414054379 ,
65 : 986519078 ,
66 : 981760191 ,
67 : 305799096 ,
68 : 515140586 ,
69 : 406959393 ,
70 : 975058685 ,
71 : 245601370 ,
72 : 324759692 ,
73 : 673385295 ,
74 : 191483611 ,
75 : 570246669 ,
76 : 427196161 ,
77 : 781042769 ,
78 : 569725155 ,
79 : 842176273 ,
80 : 25328739 ,
81 : 847501730 ,
82 : 206282374 ,
83 : 353770801 ,
84 : 323137024 ,
85 : 371653459 ,
86 : 940737264 ,
87 : 123820509 ,
88 : 915711339 ,
89 : 847205021 ,
90 : 252858375 ,
91 : 718889563 ,
92 : 866398347 ,
93 : 738390145 ,
94 : 133009077 ,
95 : 333099663 ,
96 : 170591295 ,
97 : 329869205 ,
98 : 616680192 ,
99 : 597534442 ,
100 : 388130742 
}
print(dict[n])

Measured memory_bytes: 3188
import bisect

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

ans = 0
A.sort()
C.sort()
for b in B:
    ans += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))
print(ans)

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

int main(){
  int a,b,c,mx,rest;cin>>a>>b>>c;
  if(a>=b&&a>=c) mx=a*2,rest=b+c;
  else if(b>=a&&b>=c) mx=b*2,rest=a+c;
  else mx=c*2,rest=a+b;
  cout<<(((mx-rest)%2)?(mx-rest+3)/2:(mx-rest)/2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
map<lint,lint>M;
vector<lint> V[MAX];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S;
    cin>>S;
    if(S[0]=='R'&&S[1]=='R'&&S[2]=='R') cout<<3;
    else if((S[0]=='R'&&S[1]=='R')||(S[1]=='R'&&S[2]=='R')) cout<<2;
    else if(S[0]=='R' || S[1]=='R'||S[2]=='R') cout<<1;
    else cout<<0;
    return 0;
}


Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N,M; cin>>N>>M;
  Graph G(N);
  REP(i,M) {
    ll a,b; cin>>a>>b; a-=1; b-=1;
    G[a].PB(b); G[b].PB(a);
  }

  ll Q; cin>>Q;
  vi v(Q),d(Q),c(Q); REP(i,Q) {cin>>v[i]>>d[i]>>c[i]; v[i]-=1;}

  reverse(ALL(v));
  reverse(ALL(d));
  reverse(ALL(c));

  vvi dp(N,vi(11,INF));

  REP(i,Q) dp[v[i]][d[i]]=min(dp[v[i]][d[i]],i);
  for(ll i=9;i>=0;i--) {
    REP(j,N) {
      for(ll k:G[j]) dp[j][i]=min(dp[j][i],dp[k][i+1]);
      dp[j][i]=min(dp[j][i],dp[j][i+1]);
    }
  }

  REP(i,N) {
    if (dp[i][0]==INF) cout<<0<<endl;
    else cout<<c[dp[i][0]]<<endl;
  }
}


Measured memory_bytes: 20980
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
multiset<long long>mst;
long long a[100007];
int main(){
    long long n;
    cin>>n;
    long long x;
    for(long long i=0;i<n;++i){
        cin>>x;
        a[x]=i;
    }
    mst.insert(-1);
    mst.insert(-1);
    mst.insert(n);
    mst.insert(n);
    long long ans=0;
    set<long long>::iterator pos,nex,pre,pree;
    for(long long i=n;i;--i){
        pos=mst.upper_bound(a[i]);
        nex=next(pos);
        pre=prev(pos);
        pree=prev(pre);
        ans+=i*((*nex-*pos)*(a[i]-*pre)+(*pos-a[i])*(*pre-*pree));
        mst.insert(a[i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>

int main(void) {
	char s1[256], s2[256];
	int t1[256][2], t2[256][2];
	int t1c, t2c;
	while (scanf("%255s", s1) == 1 && s1[0] != '.') {
		int i, j;
		if (scanf("%255s", s2) != 1) return 1;

		t1c = 0;
		t1[0][0] = 0;
		for (i = 0; s1[i] != '\0'; i++) {
			if (s1[i] == '\"') {
				t1[t1c][1] = i;
				t1c++;
				t1[t1c][0] = i + 1;
			}
		}
		t1[t1c][1] = i;
		t1c++;

		t2c = 0;
		t2[0][0] = 0;
		for (i = 0; s2[i] != '\0'; i++) {
			if (s2[i] == '\"') {
				t2[t2c][1] = i;
				t2c++;
				t2[t2c][0] = i + 1;
			}
		}
		t2[t2c][1] = i;
		t2c++;

		if (t1c != t2c) {
			puts("DIFFERENT");
		} else {
			int miyukichi[2] = {0, 0};
			for (i = 0; i < t1c; i++) {
				if (t1[i][1] - t1[i][0] != t2[i][1] - t2[i][0]) {
					miyukichi[i % 2]++;
				} else {
					for (j = 0; t1[i][0] + j < t1[i][1]; j++) {
						if (s1[t1[i][0] + j] != s2[t2[i][0] + j]) {
							miyukichi[i % 2]++;
							break;
						}
					}
				}
			}
			if (miyukichi[0] == 0 && miyukichi[1] == 0) {
				puts("IDENTICAL");
			} else if (miyukichi[0] == 0 && miyukichi[1] == 1) {
				puts("CLOSE");
			} else {
				puts("DIFFERENT");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int f[100001][4]={0},a[100001][4],n,i,j,k;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
	for(i=1;i<=n;i++)
	{	
		for(j=1;j<=3;j++)
		{
			for(k=1;k<=3;k++)
				if(j!=k)
					f[i][j]=max(f[i][j],f[i-1][k]+a[i][j]);
		}
	}
	int max_=0;
	for(i=1;i<=3;i++)
		if(f[n][i]>=max_)
			max_=f[n][i];
	printf("%d",max_);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int main(){
	ll N,K;
	ll ans=0;
	cin>>N>>K;//从[ 0  ~  N] 中选
	ll sum=(1+N)*N/2;//总和
	for(ll i=K;i<=N;i++){//表示取  K  个数
		//分别求出取 k 个数的最大值、与最小值
		ll t1=(0+i-1)*i/2;//和最小
		ll t2=(N+(N-i+1))*i/2;
		ll max_n=sum-t1;
		ll min_n=sum-t2;
		ans=ans+(max_n-min_n+1)%mod;
	}
	cout<<(ans+1)%mod<<endl;
	return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;

    int  d, r;
    double f;

    d = a / b;
    r = a % b;
    f = (double) a / b;

    printf("%d %d %.5f\n", d, r, f);
}





Measured memory_bytes: 3160
#include <iostream>
#include <vector>

int abs_diff(int x, int y) {
    if (x >= y)
        return x - y;
    else
        return y - x;
}

int main() {
    int N, temp;
    std::cin >> N;
    
    std::vector<int> A;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        A.push_back(temp);
    }
    
    int max = -1;
    for (auto itr=A.begin(); itr!=A.end()-1; itr++) {
        for (auto i = std::next(itr); i!=A.end(); i++) {
            int temp_ans = abs_diff(*itr, *i);
            if (temp_ans > max)
                max = temp_ans;
        }
    }
    std::cout << max << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());

        //1: A, 2: G, 3: C, 4: T
        long[][][][] dp = new long[N + 1][5][5][5];

        dp[0][0][0][0] = 1;
        for (int n = 1; n <= N; n++) {
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    for (int k = 0; k < 5; k++) {
                        for (int l = 1; l < 5; l++) {
                            if ((j == 1 && k == 2 && l == 3)
                                    || (j == 1 && k == 3 && l == 2)
                                    || (j == 2 && k == 1 && l == 3)
                                    || (i == 1 && k == 2 && l == 3)
                                    || (i == 1 && j == 2 && l == 3)
                            ) {
                                continue;
                            }
                            dp[n][j][k][l] += dp[n - 1][i][j][k];
                            dp[n][j][k][l] %= MOD;
                        }
                    }
                }
            }
        }

        long ans = 0;
        for (int j = 1; j < 5; j++) {
            for (int k = 1; k < 5; k++) {
                for (int l = 1; l < 5; l++) {
                    ans += dp[N][j][k][l];
                    ans %= MOD;
                }
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 23892
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main()
{
    int a,i,s;
    vector < int > v;

    for(i = 0; i < 3; i++)
    {
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    s = 0;
    for(i = 0; i < 2; i++)
    {
        s = s + abs(v[i] - v[i+1]);
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256