akhauriyash/Code-Regression huggingface dataset:
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;


void solve(){
    int k; cin >> k;
    int t = 0;
    f0(i, 1e7){
        t = (t*10+7)%k;
        if(t == 0){
            cout << i+1 << nl;
            return;
        }
    }

    cout << -1 << nl;
}

int main(){
    ll t;
    //cin >> t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
 }


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <tuple>
using namespace std;
using AnsType = long long int;
using Pair = pair<AnsType, AnsType>;
const AnsType INF = 1LL << 60;

const int SIZE = 1 << 24;
struct SegTree {
  AnsType node[2 * SIZE];
  SegTree() {
    fill(node, node + 2 * SIZE, -INF);
  }
  void update(AnsType k, AnsType val) {
    k += SIZE - 1;
    node[k] = max(node[k], val);
    while(k > 0) {
      k = (k - 1) / 2;
      node[k] = max(node[2*k+1], node[2*k+2]);
    }
  }
  AnsType query(int a, int b, int l=0, int r=SIZE, int k=0) {
    if(b <= l or r <= a) return -INF;
    if(a <= l and r <= b) return node[k];
    int mid = (l + r) / 2;
    AnsType vl = query(a, b, l, mid, 2*k+1);
    AnsType vr = query(a, b, mid, r, 2*k+2);
    return max(vl, vr);
  }
};

SegTree seg;
int main() {
  AnsType N, D; cin >> N >> D;
  int A = N / 2, B = N - A;
  int ap = 1, bp = 1;
  for(int i=0; i<A; i++) ap *= 3;
  for(int i=0; i<B; i++) bp *= 3;

  vector<AnsType> X(N), Y(N);
  for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

  vector<Pair> pa, pb;
  
  for(int bit=0; bit<ap; bit++) {
    AnsType sumX = 0, sumY = 0, val = bit;
    for(int i=0; i<A; i++) {
      int idx = i, pari = val % 3;
      // bruno
      if(pari == 0) {
        sumX += X[idx]; sumY += Y[idx];
      }
      // Anna
      if(pari == 1) {
        sumX -= X[idx]; sumY -= Y[idx];
      }
      val /= 3;
    }
    pa.emplace_back(sumX, sumY);
  }
  
  for(int bit=0; bit<bp; bit++) {
    AnsType sumX = 0, sumY = 0, val = bit;
    for(int i=0; i<B; i++) {
      int idx = A + i, pari = val % 3;
      // bruno
      if(pari == 0) {
        sumX += X[idx]; sumY += Y[idx];
      }
      if(pari == 1) {
        sumX -= X[idx]; sumY -= Y[idx];
      }
      val /= 3;
    }
    pb.emplace_back(sumX, sumY);
  }

  sort(pa.begin(), pa.end());
  sort(pb.rbegin(), pb.rend());
  int il = 0, ir = 0;
  for(size_t i=0; i<pa.size(); i++) {
    AnsType CX, CY; tie(CX, CY) = pa[i];
    // fprintf(stderr, "i = %zu, CX = %lld, CY = %lld\n", i, CX, CY);
    seg.update(i, CY);
  }

  int M = pa.size();
  AnsType ans = -INF;
  for(auto e : pb) {
    AnsType CX, CY; tie(CX, CY) = e;

    // [L, R]
    AnsType L = -D - CX, R = D - CX;

    // less than L
    {
      while(il < M and pa[il].first < L) il++;
    }

    // more than R
    {
      while(ir < M and pa[ir].first <= R) ir++;
    }

    // fprintf(stderr, "CX = %lld, CY = %lld, il = %d, ir = %d, maxH = %lld\n", CX, CY, il, ir, seg.query(il, ir));
    AnsType maxH = seg.query(il, ir);
    ans = max(ans, maxH + CY);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 751416
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int PRIMES[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};

int PRIME_COUNTS = 168;

int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

void solve(int N, std::vector<int> A){
  vector<int> counts(1000001, 0);
  for(int ai = 0; ai < N; ++ai) {
    int a = A[ai];
    for(int i = 0; i < PRIME_COUNTS; ++i) {
      int n = PRIMES[i];
      if(n > A[ai]) {
        break;
      }
      if(a % n == 0) {
        counts[n] += 1;
      }
      while(a % n == 0) {
        a /= n;
      }
    }
    if(a != 1) {
      counts[a] += 1;
    }
  }
  int max = *std::max_element(counts.begin(), counts.end());
  if(max <= 1) {
    cout << "pairwise coprime" << endl;
    return;
  }
  int n = A[0];
  for(int i = 0; i < N; ++i) {
    n = GCD(n, A[i]);
  }
  if(n == 1) {
    cout << "setwise coprime" << endl;
    return;
  }
  cout << "not coprime" << endl;
}

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


Measured memory_bytes: 11176
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int p[5],k;
    for(int i = 0;i < 5;i++) cin >>p[i];
    cin >> k;
    for(int i = 0;i < 5;i++) {
        if(abs(p[(i+1)%5]-p[i]) > k) {
            cout << ":(";
            return 0;
        }
    }
    cout << "Yay!";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int N;
    double ans = 0;
    cin >> N;
    double v[N];
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    sort(v , v + N);
    ans = v[0];
    for(int i = 1; i < N; i++){
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  REP(i,N) cin >> a[i];

  vector<vector<int>> ret(H, vector<int> (W));
  int c = 0, cnt = 0;
  REP(i,H)REP(k, W) {
    int j = (i % 2) ? W - 1 - k : k;
    ret[i][j] = c;
    ++cnt;
    if(cnt == a[c]){
      ++c;
      cnt = 0;
    }
  }

  REP(i,H){
    REP(j,W){
      if(j) cout << " ";
      cout << ret[i][j] + 1;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,count=0,swap;
        n=scan.nextInt();
        int a[]=new int [n];
        for(i=0;i<n;i++){
        	a[i]=scan.nextInt();
        }
        for(i=n;i>0;i--){
        	for(j=0;j<i-1;j++){
        		if(a[j]>a[j+1]){
        			swap=a[j];
        			a[j]=a[j+1];
        			a[j+1]=swap;
        			count++;
        		}
        	}
        }
        for(i=0;i<n;i++){
        	if(i>0){
        		System.out.print(" ");
        	}
        	System.out.print(a[i]);
        }
        System.out.println("");
        System.out.println(count);
    }
}



Measured memory_bytes: 26448
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int a,b,c,d=0;
string s;
signed main()
{
	cin>>a>>b>>c;
	for(int i=min(a,b);i>-1;i--){
		if(a%i==0&&b%i==0){
			d++;
		}
		if(d==c){
			cout<<i;
			return 0;
		}
	}
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*b > c*d){
    cout<<a*b;
  }else{
    cout<<c*d;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int n,m,i,sum,sw;
  sw=0;
  sum=0;
scanf("%d %d",&n,&m);
int a[n];
  
  for(i=0;i<n;++i)
  {
  scanf("%d",&a[i]);
  sum=sum+a[i];
  }
  float cc=4*m;
  float bo=sum/cc;
  
  for(i=0;i<n;++i)
  {
  if(a[i]>=bo) {sw++;}
  }
  
  if(sw>=m) printf("Yes");
  else printf("No");
return 0;
}

Measured memory_bytes: 1732
#include "cstdio"
int n,i,ss,j,k;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		ss+=i;
		if(ss>n)break;
	}
	k=ss-n;
	for(j=1;j<=n;j++)
	if(j!=k&&j<=i)printf("%d\n",j);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int n){
    string s;
    while (n){
        int rem = (n%10+10)%10;
        s += rem+'0';
        n = (n-rem)/-10;
    }
    reverse(s.begin(),s.end());
    cout << s << "\n";
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


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

int main() {
  int N,A,B,s=0;
  cin >> N >> A >> B;
  for(int i=1;i<=N;i++){
    int ds=0,ii=i;
    bool dekasuginai = true;
    while(ii>0){
      ds+=ii%10;
      if(ds>B){
        dekasuginai = false;
        break;
      }
      ii/=10;
    }
    if(dekasuginai&&ds>=A)
      s+=i;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
//atcoder DP-1
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define endl "\n"
#define int long long
typedef long double ld;
typedef vector<vector<int> > matrix;
typedef vector<int> arr;
typedef vector<string> vs;
typedef vector<pair<int,int> > pv;
#define test() int t;cin>>t;while(t--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int bx[]={0,0,1,-1,1,-1,-1,1};
int by[]={1,-1,0,0,1,-1,1,-1};

//=================================================================//
int dp[(int) 1e6];
int n;

int solve(int pos,int h[]) {
    //base case
    if(pos==n-1) return 0;
    if(pos>=n) return INT_MAX;

    int &ans = dp[pos];
    if(ans!=-1) return ans;
    //recursive case
    int op1 = INT_MAX, op2 = INT_MAX;
    if(pos+1<n)
        op1 = abs(h[pos]-h[pos+1]) + solve(pos+1,h);
    if(pos+2<n)
        op2 = abs(h[pos]-h[pos+2]) + solve(pos+2,h);

    return ans = min(op1,op2);

}

#undef int
int main(){
#define int long long 
    fast;
    cin>>n;
    int h[n];
    memset(dp, -1, sizeof dp);
    FOR(i,0,n-1) cin>>h[i];
    cout<<solve(0,h);
    return 0;
}

Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr1 = sc.next().toCharArray();
		char[] arr2 = sc.next().toCharArray();
		int count = 0;
		for(int i = 0;i<arr1.length;i++) {
			if(arr1[i] == arr2[i])count++;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 21844
class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[x] = y: xの親がy
        # aが親なら -size(初期値-1)
        self.parents = [-1] * n

    # グループの根を探索
    def find(self, x):
        if self.parents[x] < 0:  # xが木の根の場合
            return x
        # 親へ再帰
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]

    # グループの併合
    def unite(self, x, y):
        # x, yの根を探索
        x = self.find(x)
        y = self.find(y)
        if x == y:  # 同じ木に属する場合
            return
        # 計算速度のため、小さい方の根を大きい方の根につける
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]  # サイズを加算
        self.parents[y] = x  # 親の張り替え

    # 同じグループに属するか判定
    def same(self, x, y):
        # 根を比較し同じならtrue
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]  # 負で保存してあるため

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


def resolve():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.unite(a - 1, b - 1)
    print(len(uf.roots()) - 1)

resolve()


Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();

        System.out.println(solve(N, s, t));
    }

    private static int solve(int N, String s, String t) {
        int count = 0;

        for (count = N; count>0; count--) {
            String subs = s.substring(N - count, N);
            String subt = t.substring(0, count);
            // System.err.println(subs + ", " + subt);

            if (subs.equals(subt)) {
                break;
            }
        }

        return s.length() + t.length() - count;
    }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void)
{
    int a, b, c, x;
    int counter = 0;
    
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);

    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                int total = 500*i+100*j+50*k;
                if(total == x){
                    counter++;
                }

            }
        }
    }
    printf("%d\n", counter);
    return 0;


}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int n = sc.nextInt();
		String s = sc.next();
		long bigValue = 1000000007;

		List<String> array = new ArrayList<String>();
		for(int i=0;i<n;i++){
			array.add(s.substring(i,i+1));
		}
		Collections.sort(array);
        // System.out.println(array);

		long sum =1;
		long prevA = 0;
		String prevS = array.get(0);

		for(int i=1;i<n;i++){
			String a = array.get(i);
			if(a.equals(prevS)){
				sum += 1 + prevA;
				// System.out.println("i="+i + ", sum="+sum);
			}else{
				prevA = sum;
				prevS = a;
				sum+= sum + 1;
				// System.out.println("i="+i + ", sum="+sum);
			}
			if(sum>bigValue){
				sum = sum%bigValue;
			}
		}
        System.out.println(sum%bigValue);
 
	}
}


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

int main(){
  string s; cin>>s;
  int i=s.size();

  while(i>=5){
    if(s.substr(i-5,5)=="erase")i-=5;
    else if(s.substr(i-5,5)=="dream")i-=5;
    else if(i>=6 && s.substr(i-6,6)=="eraser")i-=6;
    else if(i>=7 && s.substr(i-7,7)=="dreamer")i-=7;
    else break;
  }

  if(i==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl; 
}

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

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		boolean[][] table = new boolean[4][14];
		String mark[] = {"S","H","C","D"};

		for(int row = 0; row < 4; row++){
			for(int col = 1; col <= 13; col++){
				table[row][col] = false;
			}
		}


		try {
		   int N = Integer.parseInt(br.readLine());

		   for(int loop = 0; loop < N; loop++){

			   String input_str[] = br.readLine().split("\\s+");
			   table[get_row(input_str[0])][Integer.parseInt(input_str[1])] = true;
			}

		   for(int row = 0; row < 4; row++){
			   for(int col = 1; col <= 13; col++){
				   if(table[row][col])continue;

				   System.out.printf("%s %d\n", mark[row],col);
			   }
		   }


		} catch (NumberFormatException | IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	private static int get_row(String str){

		switch(str){
		case "S":
			return 0;
		case "H":
			return 1;
		case "C":
			return 2;
		case "D":
			return 3;
		}
		return -1; //must not reach here
	}
}


Measured memory_bytes: 24780
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define fio() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define MOD 1000000007
#define nl '\n'
#define pb push_back
#define mp make_pair

using namespace std;
const int N = 3005;
int dp[N][N];
int32_t main()
{
	fio();
	string s,t;
	cin>>s>>t;
	int sl=s.length();
	int tl=t.length();
	int m=0;
	for(int i=1;i<=sl;i++)
	{
		for(int j=1;j<=tl;j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			m=max(m,dp[i][j]);
		}
	}
	//cout<<m<<endl;
	string ans;
	int i=sl,j=tl;
	while(m>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
			m--;
			//cout<<s[i-1];
		}
		else
		{
			if(dp[i-1][j]>dp[i][j-1])
				i=i-1;
			else
				j=j-1;
		}
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    string S; cin >> S; string S2 = S+S;
    long long K; cin>>K;

    int len=1;
    for(int i=1;i<S.size();i++){if(S[i]==S[i-1])len++;}
    if(len==S.size()) cout << (len*K)/2 << endl;
    else{
        long long count=1;
        long long T=0;
        for(int i=1;i<S.size();i++){
            if(S[i]==S[i-1])count++;
            else {T+=count/2; count=1;}
        }
        T+= count/2;

        count=1;
        long long T2=0;
        for(int i=1;i<S2.size();i++){
            if(S2[i]==S2[i-1])count++;
            else {T2+=count/2; count=1;}
        }
        T2+= count/2;
        long long ans = (T2-T)*(K-1)+T;

        cout << ans << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dp[3100][3100]={0};
int main()
{

    string s, t;
    cin >> s >> t;

    FOR(i, 0, s.size()){
        FOR(j, 0, t.size()){
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string ans="";
    int si=s.size(), ti=t.size();
    while(si>0 && ti>0){
        if(dp[si][ti]==dp[si-1][ti]){
            si--;
        }else if(dp[si][ti]==dp[si][ti-1]){
            ti--;
        }else{
            ans = s[si-1] + ans;
            si--;ti--;
        }
    }

    print(ans);
    return 0;
}

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

int main(){

    string s[3];

    cin >> s[0] >> s[1] >> s[2];

    int a[3]={0,0,0};
    int n=0;
    string y="ABC";
    while(a[0]<=s[0].size()&&a[1]<=s[1].size()&&a[2]<=s[2].size()){
        int t=n;
        if(a[t]==s[t].size()){
            cout << y[t] << endl;
            return 0;
        }
        n=s[n][a[n]]-'a';
        a[t]++;
    }

    return 0;
}

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

#define ll long long int

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll num;
  string s;
  cin >> num >> s;
  ll swap_start = 0, swap_end = num - 1, sum = 0;
  for (swap_end = num - 1; swap_end >= 0 && swap_start < swap_end; swap_end--){
    if (s[swap_end] == 'R'){
      while (s[swap_start] == 'R' && swap_start < swap_end)
	swap_start++;
      if (!(swap_start < swap_end))
	break;
      swap(s[swap_start], s[swap_end]);
      sum++;
    }
  }
  cout << sum << '\n';
  return 0;
}


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

using namespace std;


int main() {
   long long int n,w;
   cin>>n>>w;
   //int q=1000000000;
   long long int a[n];
   long long int b[n];
   for(long long int i=0;i<n;i++)
   {
       cin>>a[i]>>b[i];
   }
   long long int g[n+1][w+1];
   for(long long int i=0;i<=n;i++)
   {
       for(int j=0;j<=w;j++)
       {
           if(i==0||j==0)
           {
                g[i][j]=0;
                continue;
           }
           if(a[i-1]>j)
           g[i][j]=g[i-1][j];
           else if(a[i-1]==j)
           {
               g[i][j]=max(b[i-1],g[i-1][j]);
           }
           else if(a[i-1]<j)
           {
               long long int x=j-a[i-1];
               long long int y=b[i-1]+g[i-1][x];
               //cout<<i<<" "<<j<<" "<<x<<" "<<y<<endl;
               g[i][j]=max(y,g[i-1][j]);
           }
       }
   }
   
   cout<<g[n][w]<<endl;
    return 0;
}



Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 1;
    for(int i = 0;i < N - 1;i++){
        if(S.at(i) != S.at(i + 1)){
            ans++;
        }
    }
  cout << ans;
    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		char[] ch = sc.readLine().toCharArray();
		for(char c:ch){
			String s = String.valueOf(c);
			if(c < 'a'){
				sb.append(s.toLowerCase());
			}else if(c >= 'a'){
				sb.append(s.toUpperCase());
			}
		}
		System.out.println(sb);
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define nl "\n" 


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a;
    long double b;
    cin >> a >> b;
    long double ans= b*a;
    cout << ll(ans);
    
	return 0;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    if(N==1){
        cout << "Hello World" << endl;
    }
    else{
        ll A, B;
        cin >> A >> B;
        cout << A+B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)n;i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    if((B - A == 1) or (B - A) % 2 == 1)
        cout << "Borys\n";
    else 
        cout << "Alice\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f(int n){
    if(n == 2)
        return 2;
    return f(n - 1) * n;
}
int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++)
        cin >> x[i] >> y[i];
    long double ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            int d = dx * dx + dy * dy;
            ans += sqrtl(d);
        }
    }
    ans *= 2;
    ans /= n;
    cout << fixed;
    cout << setprecision(8) << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  
  int x,y,z;
  cin >> x >> y >> z;
  
  int a,b;
  cin >> a >> b;
  int minn = min(a,b);
  a -= minn;
  b -= minn;
  
  int ans = 0;
  ans += minn * min(x+y,2*z);
  
  if(b==0){
    ans += a * min(x,2*z);
  }
  else {
    ans += b * min(y,2*z);
  }
  
  cout << ans << endl;
}


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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<string> si(N);
    for (int i=0;i<N;i++){
        cin >> si[i];
    }
    int ans = 0;
    int p = 0, q = 0, r = 0;
    for (int i=0;i<N;i++){
        if (si[i][0] == 'B' && si[i][si[i].size()-1] != 'A') p++;
        if (si[i][0] != 'B' && si[i][si[i].size()-1] == 'A') q++;
        if (si[i][0] == 'B' && si[i][si[i].size()-1] == 'A') r++;
        for (int j=0;j<si[i].size() - 1;j++){
            if (si[i][j] == 'A' && si[i][j+1] == 'B') ans++;
        }
    }
    if (r > 0) ans += r - 1;
    if (r > 0 && q > 0) ans += 1;
    if (r > 0 && p > 0) ans += 1;
    if (r > 0 && p > 1 && q > 1) ans += min(p-1,q-1);
    if (r == 0 && p > 0 && q > 0) ans += min(p,q);
    cout << ans << endl;
}

Measured memory_bytes: 768
n = int(input())
a = sorted(map(int, input().split()))
ans = []
for i in range(1, n - 1):
    # +
    if a[i] < 0:
        ans.append([a[-1], a[i]])
        a[-1] -= a[i]
    # -
    else:
        ans.append([a[0], a[i]])
        a[0] -= a[i]
ans.append([a[-1], a[0]])
print(a[-1] - a[0])
for x, y in ans:
    print(x, y)


Measured memory_bytes: 25040
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main(){
    int N;
    cin >> N;
    vector<int>a(N);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        cnt^=a[i];
    }
    for(int i = 0; i < N; i++) {
        int ans = 0;
        ans^=cnt;
        ans^=a[i];
        cout << ans << endl;
    }
}


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

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

    int n, arr[100000], dp[100000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(abs(arr[i]-arr[i-1]) + dp[i-1], abs(arr[i]-arr[i-2]) + dp[i-2]);
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 4432
#include <iostream>
using namespace std;
int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	for(int i = 0;i<3;i++)
		for(int j =0;j<2;j++)
			if(a[j]>a[j+1])
				swap(a[j],a[j+1]);
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}


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

int main() {
	
	int n,a,b;
	int ans;
	
    cin >> n >> a >> b;
	
	if(n*a < b){
		ans = n*a;
	}
	else{
		ans = b;
	}
	
	cout << ans;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
    int K, A, B; cin >> K >> A >> B;
    if ((A + K - 1) / K * K <= B) {
        cout << "OK" << '\n';
    } else {
        cout << "NG" << '\n';
    }
}

Measured memory_bytes: 3636
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val MOD = 998244353L

	val (n,m) = f.readLine().split(" ").map{it.toInt()}

	val pq = PriorityQueue<Pair<Int,Int>>(compareBy{it.first})
	val array = Array<Pair<Int,Int>>(m){
		val (a,b) = f.readLine().split(" ").map{it.toInt()}
		pq.add(Pair(a,b))
		Pair(a,b)
	}

	//combine
	val pairs = mutableListOf<Pair<Int,Int>>()
	val firstpair = pq.poll()
	var start = firstpair.first
	var end = firstpair.second

	while(!pq.isEmpty()){
		val p = pq.poll()

		if(p.first > end+1){
			pairs.add(Pair(start,end))
			start = p.first
			end = p.second
		} else {
			end = max(end,p.second)
		}
	}

	pairs.add(Pair(start,end))


	val bits = LongArray(n+1)

	fun update(ii : Int, x : Long){
		var i = ii
		while(i <= n){
			bits[i] = (bits[i] + x + MOD)%MOD
			i += (i and -i)
		}
	}

	fun psum(ii : Int): Long{
		var i = ii
		var sum : Long = 0L
		while(i > 0){
			sum = (sum + bits[i] + MOD)%MOD
			i -= (i and -i)
		}
		return sum
	}

	val dp = LongArray(n+1){0L}
	dp[1] = 1L
	update(1,1L)

	for(k in 2..n){
		for(pair in pairs){
			if(pair.first > k) continue
			dp[k] = (dp[k] + psum(k-pair.first) + MOD)%MOD
			if(k-pair.second-1 >= 1) dp[k] = ((dp[k] - psum(k-pair.second-1))%MOD + MOD)%MOD
		}
		update(k,dp[k])
	}

	println(dp[n])


}


Measured memory_bytes: 48696
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int N, t, a;
	long long x, A = 1, B = 1;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> t >> a;

		x = max((A + t - 1) / t, (B + a - 1) / a);
		
		A = x * t;
		B = x * a;
	}

	cout << A + B << endl;

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<list>
#include<map>
using namespace std ;
int n; double a[105], ans ;
int main(){
	cin>>n ; 
	for(int i=1;i<=n;++i){
		cin>>a[i] ; a[i] = 1/a[i] ; ans+=a[i] ;
	}
	cout<<1/ans<<endl ;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, a;
int main(void){
    // Your code here!
    cin >> n;
    int max = 1, min = 1000;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a > max) max = a;
        if (a < min) min = a;
    }
    cout << max - min << endl;
}


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

using namespace std;

int main() {
	int n, m;//n個，ｍ選ぶ
	cin >> n >> m;
	vector<int>sina(n);
	int i;
	for (i = 0; i < n; i++)cin >> sina[i];
	int x = 0;
	for (i = 0; i < n; i++)x += sina[i];
	auto z = ((long double)(x / (long double)(4 * m)));
	int y = 0;
	for (i = 0; i < n; i++) {
		if (z <= sina[i]) {
			y++;
		}
	}
	if (y >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		t = new int[n];
		for (int i = 0; i < n; i++)
			t[i] = scanner.nextInt();
		d = new int[m][3];
		for (int i = 0; i < m; i++)
			for (int j = 0; j < 3; j++) {
				int a = scanner.nextInt();
				d[i][j] = a;
			}
		Arrays.sort(d, new Comparator<int[]>() {

			@Override
			public int compare(int[] o1, int[] o2) {
				return o1[2] - o2[2];
			}
		});
		dp = new int[n][m];
		for (int[] dp1 : dp)
			Arrays.fill(dp1, -1);
		int ans = 0;
		for (int i = 0; i < m; i++) {
			if (d[i][0] <= t[0] && t[0] <= d[i][1]) {
				ans = slove(1, i);
				break;
			}
		}
		for (int i = m - 1; i >= 0; i--) {
			if (d[i][0] <= t[0] && t[0] <= d[i][1]) {
				ans = Math.max(ans, slove(1, i));
				break;
			}
		}
		System.out.println(ans);

	}

	private int slove(int day, int x) {
		if (day == n)
			return 0;
		if (dp[day][x] != -1)
			return dp[day][x];
		int ret = 0;
		for (int i = m - 1; i >= 0; i--) {
			if (d[i][0] <= t[day] && t[day] <= d[i][1]) {
				ret = Math.max(ret,
						slove(day + 1, i) + Math.abs(d[i][2] - d[x][2]));
				break;
			}
		}
		for (int i = 0; i < m; i++) {
			if (d[i][0] <= t[day] && t[day] <= d[i][1]) {
				ret = Math.max(ret,
						slove(day + 1, i) + Math.abs(d[i][2] - d[x][2]));
				break;
			}
		}

		return dp[day][x] = ret;
	}

	int n, m;
	int[] t;
	int[][] d, dp;
}

Measured memory_bytes: 21264
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  int n, i;
  cin>>n;
  int num[100005] = {};
  int a[n];
  for(i = 0; i<n; i++)
  {
      cin>>a[i];
      num[a[i]]++;
      if(a[i]-1>=0) num[a[i]-1]++;
      num[a[i]+1]++;
  }
  cout<<*max_element(num, num + 100005)<<endl;




return 0;
}



Measured memory_bytes: 4392
abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

n = int(input())
s = list(input())

for i, j in enumerate(s):
    num = abc.index(j)
    newnum = num+n
    s[i] = abc[newnum]

print(''.join(s))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(a-b*2,0) << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i = 0; i < 3; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        if(a[0] == 5 && a[1] == 5 && a[2] == 7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22228
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(M)]
sum = min(a) + min(b)
for i in range(M):
    calc = a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]
    sum = min(sum, calc)
print(sum)

Measured memory_bytes: 38560
//waz
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
 
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
 
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
 
int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}
 
int H, W;
 
char str[110][110];
 
int cnt[110][110];
 
int sum(int x1, int y1, int x2, int y2)
{
	x1 = max(x1, 1), x1 = min(x1, H);
	x2 = max(x2, 1), x2 = min(x2, H);
	y1 = max(y1, 1), y1 = min(y1, W);
	y2 = max(y2, 1), y2 = min(y2, W);
	if (x1 > x2) return 0;
	if (y1 > y2) return 0;
	//cerr << x1 << ", " << y1 << " and " << x2 << ", " << y2 << endl;
	return cnt[x2][y2] + cnt[x1 - 1][y1 - 1] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1];
}

int f[2][110][110][110];

int main()
{
	gii(H, W);
	for (int i = 1; i <= H; ++i)
		scanf("%s", str[i] + 1);
	int x = 0, y = 0;
	for (int i = 1; i <= H; ++i)
		for (int j = 1; j <= W; ++j)
			if (cnt[i][j] = (str[i][j] == 'o'), str[i][j] == 'E')
				x = i, y = j;
	for (int i = 1; i <= H; ++i)
		for (int j = 1; j <= W; ++j)
			cnt[i][j] += cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
	int ans = 0;
	for (int l = 0; x + l <= H; ++l)
		for (int r = 0; x - r > 0; ++r)
			for (int u = 0; y + u <= W; ++u)
				for (int d = 0; y - d > 0; ++d)
				{
					int L = l & 1;
					f[L][r][u][d] = 0;
					int left = x - r, right = x + l;
					int up = y - d, down = y + u;
					left = max(1 + l, left);
					right = min(H - r, right);
					up = max(up, 1 + u);
					down = min(down, W - d);
					if (l && l + r + x <= H) f[L][r][u][d] = max(f[L][r][u][d], f[L ^ 1][r][u][d] + sum(x + l, up, x + l, down));
					if (r && l + r <= x - 1) f[L][r][u][d] = max(f[L][r][u][d], f[L][r - 1][u][d] + sum(x - r, up, x - r, down));
					if (u && u + d + y <= W) f[L][r][u][d] = max(f[L][r][u][d], f[L][r][u - 1][d] + sum(left, y + u, right, y + u));
					if (d && u + d <= y - 1) f[L][r][u][d] = max(f[L][r][u][d], f[L][r][u][d - 1] + sum(left, y - d, right, y - d));
					//cerr << l << ", " << r << ", " << u << ", " << d << " : " << f[l][r][u][d] << endl; 
					ans = max(ans, f[L][r][u][d]);
				}
	printf("%d\n", ans);
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<char> t(q), d(q);
  rep(i, q) cin >> t[i] >> d[i];

  int l, r;
  // left side
  l = -1;
  r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int pos = mid;

    bool f = false;
    rep(i, q) {
      if (t[i] != s[pos]) continue;
      pos = pos + (d[i] == 'L' ? -1 : 1);
      if (pos < 0) f = true;
      if (!(0 <= pos && pos < n)) break;
    }

    if (f)
      l = mid;
    else
      r = mid;
  }
  int lcnt = l + 1;

  // right side
  l = -1;
  r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int pos = mid;

    bool f = false;
    rep(i, q) {
      if (t[i] != s[pos]) continue;
      pos = pos + (d[i] == 'L' ? -1 : 1);
      if (pos >= n) f = true;
      if (!(0 <= pos && pos < n)) break;
    }

    if (f)
      r = mid;
    else
      l = mid;
  }
  int rcnt = (n - (l + 1));

  cout << n - lcnt - rcnt << endl;
}


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

int N;
int main(){
  cin >> N;
  
  ll a; cin >> a;  
  ll res = a-1;
  ll k=1;
  for(int i=0;i<N-1;i++) {    
    ll a; cin >> a;
    if( k + 1 == a ){
      k = a;
    } else if( k +1 < a ) {
      res += (a-1)/(k+1);      
    }
  }
  cout << res << endl;
}


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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int process(vector<vector<int>> &ret, int pt, int base, int h, int w) {
	if (h == 1) {
	} else if (h == 2) {
		rep(y, 2) {
			ret[pt + y].push_back(base);
		}
	} else {
		vector<int> v;
		int bbase = base;
		rep(y, 3) {
			ret[pt + y].push_back(base++);
			rep(x, w - 2) {
				v.push_back(base);
				ret[pt + y].push_back(base++);
			}
			if (y < 2) ret[pt + y].push_back(base);
			else ret[pt + y].push_back(bbase);
		}
		REP(y, 3, h - 1) {
			rep(x, 3) {
				ret[pt + y].push_back(v[x * (w - 2) + (y - 3)]);
			}
		}
		return base;
	}
	return INT_MAX;
}

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

	if (N == 1) {
		cout << "Yes" << endl;
		cout << "2" << endl;
		cout << "1 1" << endl;
		cout << "1 1" << endl;
		return 0;
	}

	bool ok = false;
	int W, H;
	REP(i, 2, 10000) {
		int tmp = i * (i + 1);
		if (tmp > 2 * N) break;
		if (tmp == 2 * N) {
			ok = true;
			W = i;
			H = i + 1;
			break;
		}
	}
	if (!ok) {
		cout << "No" << endl;
		return 0;
	}

	vector<vector<int>> ret(H);
	rep(i, H) ret[i];

	int pt = 0;
	int base = 1;
	while (pt < H) {
		base = process(ret, pt, base, H - pt, W - pt);
		pt += 3;
	}

	cout << "Yes" << endl;
	cout << ret.size() << endl;
	for (auto &v : ret) {
		cout << v.size();
		for (auto &num : v) cout << " " << num;
		cout << endl;
	}

    return 0;
}


Measured memory_bytes: 3328
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!

    val nums = mutableListOf<Int>()
    var now = 1
    var count = 0
    for (i in 0 until n) {
        if (s[i] == ('0' + now)) {
            count++
        } else {
            nums.add(count)
            now = 1 - now
            count = 1
        }
    }
    if (count != 0) {
        nums.add(count)
    }

    if (nums.size % 2 == 0) {
        nums.add(0)
    }

    val cumsum = Array(n + 1) { 0 }
    for (i in 0 until nums.size) {
        cumsum[i + 1] = cumsum[i] + nums[i]
    }

    val add = 2 * k + 1
    var ans = 0
    for (i in 0 until nums.size step 2) {
        val left = i
        val right = Math.min(i + add, nums.size)
        val tmp = cumsum[right] - cumsum[left]

        ans = Math.max(ans, tmp)
    }
    println(ans)
}


Measured memory_bytes: 41120
# -*- coding:utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

#nega
total = 0
sign = -1
nega_cost = 0
for tmp in range(len(a)):
    total += a[tmp]
    if total * sign <= 0:
        nega_cost += abs(total*sign)+1
        total = sign
    sign *= -1

#posi
total = 0
sign = 1
posi_cost = 0
for tmp in range(len(a)):
    total += a[tmp]
    if total * sign <= 0:
        posi_cost += abs(total*sign)+1
        total = sign
    sign *= -1

print(min(nega_cost, posi_cost))

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

using namespace std ; 

int main () { 
	
	vector <string> str ; 
	int n  , l ; 
	string s ; 
	cin >> n >> l ;
	for ( int i = 0 ; i < n ; i ++ ) {
		cin >> s ; 
	str.push_back(s) ; }
	sort(str.begin(), str.end() ) ; 
	
	for ( auto & r : str ) 
		cout << r ;
	cout << endl ; 
	
}


Measured memory_bytes: 256
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	ll n;
	cin >> n;
	ll total1000 = n / 500;
	n = n - total1000 * 500;
	ll total5 = n / 5;
	cout << total5 * 5 + total1000 * 1000; 

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
monster = 0
for i in range(N):
    if(a[i] >= b[i]):
        monster += b[i]
    else:
        monster += a[i]
        if((b[i] - a[i]) <= a[i+1]):
            monster += b[i]-a[i]
            a[i+1] -= b[i]-a[i]
        else:
            monster += a[i+1]
            a[i+1] = 0
print(monster)

Measured memory_bytes: 18476
N, M = map ( int, input ( ).split ( ) )# N,Mを取得
#初期化
lists = [ ]
#listに要素を追加　後で並び変えるため並び替える前の順番を示すキーを第三要素に挿入しておく
for i in range ( M ):
    lists.append ( list ( map ( int, input ( ).split ( ) ) ) + [ i ] )
#第一要素に昇順で並び替えた後、第二要素で昇順に並び替える
lists.sort ( key=lambda x: x[ 1 ] )
lists.sort ( key=lambda x: x[ 0 ] )
# befは前回の第一要素　stateは第一要素での順位
bef = 0
state = 0
retstr = ''
triple = [ ]#第四要素に識別番号を追加したリストの初期化
for i in lists:
    if (i[ 0 ] != bef):
        bef = i[ 0 ]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
 
triple.sort ( key=lambda x: x[ 2 ] )#第三要素で並び替えて、元の入力に対応した式ベンツ番号の順番に戻す
for i in triple:
    print ( i[ 3 ] )#識別番号の出力

Measured memory_bytes: 43040